瀏覽代碼

Add dedicated integration test for network module

Patrick-Christopher Mattulat 2 年之前
父節點
當前提交
0f09ddd5d4
共有 2 個文件被更改,包括 133 次插入13 次删除
  1. 66 13
      CMakeLists.txt
  2. 67 0
      test/cases/network/socket/SocketIT.cpp

+ 66 - 13
CMakeLists.txt

@@ -27,7 +27,8 @@ set(GOOGLE_TEST_MODULE googletest-1.11.0)
 # Options
 ##########################################################
 
-option(LS_STD_BUILD_WITH_TESTS "Build project with tests..." OFF)
+option(LS_STD_BUILD_WITH_TESTS "Build project with unit tests..." OFF)
+option(LS_STD_BUILD_WITH_IT "Build project with integration tests..." OFF)
 option(LS_STD_BUILD_WITH_SUPPORTED_COMPILER "Build project with supported compiler only..." ON)
 option(LS_STD_BUILD_STATIC "Build ls_std static library..." ON)
 option(LS_STD_BUILD_SHARED "Build ls_std shared library..." OFF)
@@ -111,7 +112,7 @@ endif ()
 
 message("${PROJECT_NAME}: Adding include directories...")
 
-if (${LS_STD_BUILD_WITH_TESTS})
+if (${LS_STD_BUILD_WITH_TESTS} OR ${LS_STD_BUILD_WITH_IT})
     include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test)
     include_directories(${CMAKE_CURRENT_LIST_DIR}/test/lib/${GOOGLE_TEST_MODULE}/googletest/include)
     include_directories(${CMAKE_CURRENT_LIST_DIR}/test/lib/${GOOGLE_TEST_MODULE}/googlemock/include)
@@ -211,7 +212,7 @@ set(SOURCE_FILES_TIME
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
-# Test Files Modularization
+# Unit Test Files Modularization
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
@@ -298,13 +299,13 @@ endif ()
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
-# Test Suite Builds
+# Unit Test Suite Builds
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
 
 ##########################################################
-# Build Tests (boxing)
+# Build Unit Tests (boxing)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -313,7 +314,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (core)
+# Build Unit Tests (core)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -322,7 +323,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (encoding)
+# Build Unit Tests (encoding)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -331,7 +332,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (event)
+# Build Unit Tests (event)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -340,7 +341,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (io)
+# Build Unit Tests (io)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -349,7 +350,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (network)
+# Build Unit Tests (network)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -358,7 +359,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (time)
+# Build Unit Tests (time)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -367,7 +368,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 endif ()
 
 ##########################################################
-# Build Tests (all)
+# Build Unit Tests (all)
 ##########################################################
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -383,6 +384,36 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${TEST_FILES_TIME})
 endif ()
 
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+# Integration Test Files Modularization
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+
+if (${LS_STD_BUILD_WITH_IT})
+    set(IT_FILES_NETWORK
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/network/socket/SocketIT.cpp)
+endif()
+
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+# Integration Test Suite Builds
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+
+##########################################################
+# Build Integration Tests (network)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_IT})
+    message("${MODULE_NAME_NETWORK}: Building integration tests...")
+    add_executable(${MODULE_NAME_NETWORK}_it ${IT_FILES_NETWORK})
+endif ()
+
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
@@ -553,7 +584,7 @@ endif ()
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
-# Test Suite: Linking
+# Unit Test Suite: Linking
 ####################################################################################################################
 ####################################################################################################################
 ####################################################################################################################
@@ -673,3 +704,25 @@ if (${LS_STD_BUILD_WITH_TESTS})
             "${MODULE_NAME_NETWORK}"
             "${MODULE_NAME_TIME}")
 endif ()
+
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+# Integration Test Suite: Linking
+####################################################################################################################
+####################################################################################################################
+####################################################################################################################
+
+##########################################################
+# Linking (network)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_IT})
+    message("${MODULE_NAME_NETWORK}: Linking libraries for integration test application...")
+    target_link_libraries(${MODULE_NAME_NETWORK}_it
+            gtest
+            gmock
+            gtest_main
+            "${MODULE_NAME_NETWORK}"
+            "${MODULE_NAME_CORE}")
+endif ()

+ 67 - 0
test/cases/network/socket/SocketIT.cpp

@@ -0,0 +1,67 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-12-27
+ * Changed:         2022-12-27
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std_network.hpp>
+
+using namespace ls::std::network;
+
+namespace
+{
+  class SocketIT : public ::testing::Test
+  {
+    protected:
+
+      SocketIT() = default;
+      ~SocketIT() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(SocketIT, local_server_client)
+  {
+    // create server parameter
+
+    SocketParameter serverParameter{};
+    serverParameter.protocolFamilyType = PROTOCOL_FAMILY_TYPE_IPV4; // TODO: add library prefix to constant value
+    serverParameter.socketAddress.protocolType = PROTOCOL_TYPE_TCP; // TODO: add library prefix to constant value
+    serverParameter.socketAddress.port = 5099;
+    serverParameter.queueSize = 5;
+
+    // create client parameter
+
+    SocketParameter clientParameter{};
+    clientParameter.protocolFamilyType = PROTOCOL_FAMILY_TYPE_IPV4;
+    clientParameter.socketAddress.protocolType = PROTOCOL_TYPE_TCP;
+    clientParameter.socketAddress.ipAddress = "127.0.0.1";
+    clientParameter.socketAddress.port = 5099;
+
+    // start server
+
+    Socket serverSocket{serverParameter};
+
+    ASSERT_TRUE(serverSocket.bind());
+    ASSERT_TRUE(serverSocket.listen());
+
+    // start client
+
+    Socket clientSocket{clientParameter};
+
+    ASSERT_TRUE(clientSocket.connect());
+
+    // close sockets
+
+    ASSERT_TRUE(clientSocket.close());
+    ASSERT_TRUE(serverSocket.close());
+  }
+}