mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 08:34:47 +08:00
add linux gcc test ci
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
name: Ubuntu 22.04 (gcc)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_by_gcc:
|
||||
strategy:
|
||||
matrix:
|
||||
mode: [Debug, Release]
|
||||
ssl: [OFF]
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get install openssl
|
||||
sudo apt-get install libssl-dev
|
||||
|
||||
- name: Configure CMake
|
||||
run: CXX=g++ CC=gcc cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.mode}} -DCINATRA_ENABLE_SSL=${{matrix.ssl}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}
|
||||
|
||||
- name: Test
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest -C ${{matrix.mode}} -j `nproc` -V
|
||||
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(rest_rpc)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
#the thread library of the system.
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include(cmake/build.cmake)
|
||||
include(cmake/develop.cmake)
|
||||
|
||||
message(STATUS "---->: " ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if (BUILD_UNIT_TESTS)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
endif ()
|
||||
if (BUILD_EXAMPLES)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)
|
||||
endif ()
|
||||
@@ -0,0 +1,8 @@
|
||||
# Compile Standard
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11")
|
||||
|
||||
# Build Type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||
@@ -0,0 +1,24 @@
|
||||
# extra
|
||||
option(BUILD_EXAMPLES "Build examples" ON)
|
||||
|
||||
# unit test
|
||||
option(BUILD_UNIT_TESTS "Build unit tests" ON)
|
||||
if(BUILD_UNIT_TESTS)
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
SET(ENABLE_SSL OFF)
|
||||
SET(ENABLE_JAVA OFF)
|
||||
|
||||
add_definitions(-DMSGPACK_NO_BOOST)
|
||||
|
||||
if (ENABLE_SSL)
|
||||
add_definitions(-DCINATRA_ENABLE_SSL)
|
||||
message(STATUS "Use SSL")
|
||||
find_package(Boost COMPONENTS system filesystem REQUIRED)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JAVA)
|
||||
find_package(JNI REQUIRED)
|
||||
message(STATUS "Use Java")
|
||||
endif()
|
||||
@@ -1,26 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(example)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11")
|
||||
|
||||
SET(ENABLE_SSL OFF)
|
||||
SET(ENABLE_JAVA OFF)
|
||||
|
||||
add_definitions(-DMSGPACK_NO_BOOST)
|
||||
if (ENABLE_SSL)
|
||||
add_definitions(-DCINATRA_ENABLE_SSL)
|
||||
message(STATUS "Use SSL")
|
||||
find_package(Boost COMPONENTS system filesystem REQUIRED)
|
||||
endif()
|
||||
|
||||
if (ENABLE_JAVA)
|
||||
find_package(JNI REQUIRED)
|
||||
message(STATUS "Use Java")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
"/usr/local/include"
|
||||
"../include"
|
||||
"../thirdparty/msgpack-c/include"
|
||||
"../thirdparty/asio")
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
project(test_rest_rpc)
|
||||
set(project_name test_rest_rpc)
|
||||
|
||||
include_directories(
|
||||
"../thirdparty/msgpack-c/include"
|
||||
"../thirdparty/asio"
|
||||
)
|
||||
|
||||
add_executable(${project_name}
|
||||
test_rest_rpc.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_test(NAME ${project_name} COMMAND test_rest_rpc)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
|
||||
#include "doctest/doctest.h"
|
||||
|
||||
// doctest comments
|
||||
// 'function' : must be 'attribute' - see issue #182
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007)
|
||||
int main(int argc, char** argv) { return doctest::Context(argc, argv).run(); }
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_POP
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <rest_rpc.hpp>
|
||||
#include "doctest/doctest.h"
|
||||
|
||||
using namespace rest_rpc;
|
||||
using namespace rpc_service;
|
||||
|
||||
struct dummy {
|
||||
int add(rpc_conn conn, int a, int b) {
|
||||
// auto shared_conn = conn.lock();
|
||||
// if (shared_conn) {
|
||||
// shared_conn->set_user_data(std::string("aa"));
|
||||
// auto s = conn.lock()->get_user_data<std::string>();
|
||||
// std::cout << s << '\n'; // aa
|
||||
// }
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("test_sync_add") {
|
||||
rpc_server server(9000, std::thread::hardware_concurrency());
|
||||
dummy d;
|
||||
server.register_handler("add", &dummy::add, &d);
|
||||
server.async_run();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
|
||||
rpc_client client("127.0.0.1", 9000);
|
||||
bool r = client.connect();
|
||||
CHECK(r);
|
||||
auto result = client.call<int>("add", 1, 2);
|
||||
CHECK_EQ(result, 3);
|
||||
}
|
||||
Reference in New Issue
Block a user