Преглед на файлове

Add convenience bash script to run examples

- Both server and client are launched by the script
- Server is lauched in background killed at "normal" exit
- Secure echo server test is added to ctest
Viktor Kopp преди 5 години
родител
ревизия
ec1f319ad7

+ 9 - 1
examples/CMakeLists.txt

@@ -1,5 +1,13 @@
+add_subdirectory("examples_common")
+
 add_subdirectory("addressbook")
 add_subdirectory("addressbookserver")
+message(STATUS "CLIENT: ${CLIENT_EXEC_PATH}")
+message(STATUS "SERVER: ${SERVER_EXEC_PATH}")
+configure_file(client_server_driver.sh.in addressbook_driver.sh @ONLY)
+
 add_subdirectory("simplechat")
 add_subdirectory("simplechatserver")
-add_subdirectory("examples_common")
+message(STATUS "CLIENT: ${CLIENT_EXEC_PATH}")
+message(STATUS "SERVER: ${SERVER_EXEC_PATH}")
+configure_file(client_server_driver.sh.in simplechat_driver.sh @ONLY)

+ 2 - 0
examples/addressbook/CMakeLists.txt

@@ -35,3 +35,5 @@ add_executable(${TARGET} ${SOURCES} resources.qrc)
 add_dependencies(${TARGET} ${QtProtobuf_GENERATED} examples_common)
 target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
 target_link_libraries(${TARGET} examples_common QtProtobufProject::QtProtobuf QtProtobufProject::QtGrpc ${QtProtobuf_GENERATED} Qt5::Quick Qt5::Qml)
+
+set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 1 - 0
examples/addressbookserver/CMakeLists.txt

@@ -20,3 +20,4 @@ if(MSVC)
    target_compile_definitions(${TARGET} PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
 endif()
 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/cert.pem ${CMAKE_CURRENT_SOURCE_DIR}/key.pem DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+set(SERVER_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 24 - 0
examples/client_server_driver.sh.in

@@ -0,0 +1,24 @@
+#! /bin/bash
+
+# go to server dir to make sure that certificates are successfuly loaded
+SERVER_DIR=$(dirname "@SERVER_EXEC_PATH@")
+cd $SERVER_DIR
+
+echo "SERVER: @SERVER_EXEC_PATH@ & sleep 0.2"
+# start server and detach console 
+"@SERVER_EXEC_PATH@" &
+# give server time to initialize
+sleep 0.5
+
+# run client provided in $1
+echo "CLIENT: @CLIENT_EXEC_PATH@"
+"@CLIENT_EXEC_PATH@"
+
+EXIT_CODE=$?
+
+echo "SERVER PID: $!"
+# kill background server process
+[[ @SERVER_EXEC_PATH@ ]] && kill $!
+
+exit $EXIT_CODE
+

+ 2 - 0
examples/simplechat/CMakeLists.txt

@@ -32,3 +32,5 @@ add_executable(${TARGET} ${SOURCES} resources.qrc)
 add_dependencies(${TARGET} ${QtProtobuf_GENERATED} examples_common)
 target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
 target_link_libraries(${TARGET} examples_common QtProtobufProject::QtProtobuf QtProtobufProject::QtGrpc ${QtProtobuf_GENERATED} Qt5::Quick Qt5::Qml)
+
+set(CLIENT_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 1 - 0
examples/simplechatserver/CMakeLists.txt

@@ -20,3 +20,4 @@ if(MSVC)
    target_compile_definitions(${TARGET} PRIVATE _WIN32_WINNT=0x600 _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
 endif()
 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/cert.pem ${CMAKE_CURRENT_SOURCE_DIR}/key.pem DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+set(SERVER_EXEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} PARENT_SCOPE)

+ 4 - 0
tests/test_grpc/CMakeLists.txt

@@ -27,3 +27,7 @@ add_subdirectory(secureechoserver)
 add_test(NAME qtgrpc_echo_test
          COMMAND test_driver.sh ./tests/test_grpc/qtgrpc_test ./tests/test_grpc/echoserver/echoserver
 )
+
+add_test(NAME qtgrpc_secure_test
+         COMMAND test_driver.sh ./tests/test_grpc/qtgrpc_secure_test ./tests/test_grpc/echoserver/secureechoserver
+)