Skip to content

Commit

Permalink
Allow tests to be compiled without examples (Closes #160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Spiess-Knafl committed Aug 10, 2016
1 parent bff307c commit 31b8a66
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@

set(CTEST_OUTPUT_ON_FAILURE TRUE)

file(GLOB_RECURSE test_source *.cpp)
file(GLOB test_specs *.json)

file(COPY ${CMAKE_SOURCE_DIR}/src/examples/server.key ${CMAKE_SOURCE_DIR}/src/examples/server.pem DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/src/examples/server.key ${CMAKE_SOURCE_DIR}/src/examples/server.pem DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
file(COPY ${test_specs} DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${test_specs} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

include_directories(..)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${JSONCPP_INCLUDE_DIRS})

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-server=AbstractStubServer --cpp-server-file=${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Server Stubfiles"
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/gen/stubclient.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-client=StubClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/stubclient.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Client Stubfile"
VERBATIM
)


if(HTTP_CLIENT AND HTTP_SERVER)
add_definitions(-DHTTP_TESTING)
file(COPY ${CMAKE_SOURCE_DIR}/src/examples/server.key ${CMAKE_SOURCE_DIR}/src/examples/server.pem DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/src/examples/server.key ${CMAKE_SOURCE_DIR}/src/examples/server.pem DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
list(REMOVE_ITEM test_source "${CMAKE_CURRENT_SOURCE_DIR}/testhttpserver.cpp")
endif()
Expand All @@ -25,6 +39,11 @@ endif()

if(COMPILE_STUBGEN)
add_definitions(-DSTUBGEN_TESTING)
file(GLOB test_specs *.json)
file(COPY ${test_specs} DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${test_specs} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
list(APPEND test_source "${CMAKE_BINARY_DIR}/gen/abstractstubserver.h")
list(APPEND test_source "${CMAKE_BINARY_DIR}/gen/stubclient.h")
endif()

add_executable(unit_testsuite ${test_source})
Expand All @@ -38,10 +57,8 @@ if (NOT CATCH_FOUND)
endif()

if(COMPILE_STUBGEN)
list(APPEND test_source "${CMAKE_BINARY_DIR}/gen/abstractstubserver.h")
list(APPEND test_source "${CMAKE_BINARY_DIR}/gen/stubclient.h")
target_link_libraries(unit_testsuite libjsonrpcstub)
add_dependencies(unit_testsuite common_stubs)
add_dependencies(unit_testsuite libjsonrpcstub)
endif()

add_test(client ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unit_testsuite "[client]")
Expand Down
51 changes: 51 additions & 0 deletions src/test/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"name": "sayHello",
"params": {
"name": "Peter"
},
"returns": "Hello Peter"
},
{
"name": "notifyServer"
},
{
"name": "addNumbers",
"params": [
3,
4
],
"returns": 7
},
{
"name": "addNumbers2",
"params": [
3.2,
4.1
],
"returns": 7.5
},
{
"name": "isEqual",
"params": [
"string1",
"string2"
],
"returns": false
},
{
"name": "buildObject",
"params": [
"peter",
1990
],
"returns": {
"name": "peter",
"year": 1990
}
},
{
"name" : "methodWithoutParameters",
"returns": "String"
}
]

0 comments on commit 31b8a66

Please sign in to comment.