Преглед изворни кода

Introduce os module to library

This module contains a runtime library loader prototype.
Patrick-Christopher Mattulat пре 2 година
родитељ
комит
91be368a5c

+ 53 - 0
CMakeLists.txt

@@ -18,6 +18,7 @@ set(MODULE_NAME_CORE ls_std_core)
 set(MODULE_NAME_ENCODING ls_std_encoding)
 set(MODULE_NAME_EVENT ls_std_event)
 set(MODULE_NAME_IO ls_std_io)
+set(MODULE_NAME_OS ls_std_os)
 set(MODULE_NAME_TIME ls_std_time)
 
 set(GOOGLE_TEST_MODULE googletest-1.11.0)
@@ -177,6 +178,9 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StandardOutputWriter.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StorableFile.cpp)
 
+set(SOURCE_FILES_OS
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/os/library/RuntimeLibraryLoader.cpp)
+
 set(SOURCE_FILES_TIME
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/time/Date.cpp)
 
@@ -253,6 +257,9 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/TestDataFactory.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/XmlParserTestWrapper.cpp)
 
+    set(TEST_FILES_OS
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/os/library/RuntimeLibraryLoaderTest.cpp)
+
     set(TEST_FILES_SERIALIZATION
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
 
@@ -313,6 +320,15 @@ if (${LS_STD_BUILD_WITH_TESTS})
     add_executable(${MODULE_NAME_IO}_test ${TEST_FILES_IO})
 endif ()
 
+##########################################################
+# Build Tests (os)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_TESTS})
+    message("${MODULE_NAME_OS}: Building tests...")
+    add_executable(${MODULE_NAME_OS}_test ${TEST_FILES_OS})
+endif ()
+
 ##########################################################
 # Build Tests (time)
 ##########################################################
@@ -334,6 +350,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${TEST_FILES_ENCODING}
             ${TEST_FILES_EVENT}
             ${TEST_FILES_IO}
+            ${TEST_FILES_OS}
             ${TEST_FILES_SERIALIZATION}
             ${TEST_FILES_TIME})
 endif ()
@@ -461,6 +478,28 @@ if (${LS_STD_BUILD_MODULE})
     set_target_properties("${MODULE_NAME_IO}" PROPERTIES DEBUG_POSTFIX "_d")
 endif ()
 
+##########################################################
+# Build Library (os)
+##########################################################
+
+message("${PROJECT_NAME}: Building ${MODULE_NAME_OS} library version ${PROJECT_VERSION}...")
+
+if (${LS_STD_BUILD_STATIC})
+    add_library("${MODULE_NAME_OS}" STATIC ${SOURCE_FILES_OS})
+    set_target_properties("${MODULE_NAME_OS}" PROPERTIES DEBUG_POSTFIX "_d")
+endif ()
+
+if (${LS_STD_BUILD_SHARED})
+    add_library("${MODULE_NAME_OS}" SHARED ${SOURCE_FILES_OS})
+    target_link_libraries("${MODULE_NAME_OS}" ${MODULE_NAME_CORE})
+    set_target_properties("${MODULE_NAME_OS}" PROPERTIES DEBUG_POSTFIX "_d")
+endif ()
+
+if (${LS_STD_BUILD_MODULE})
+    add_library("${MODULE_NAME_OS}" MODULE ${SOURCE_FILES_OS})
+    set_target_properties("${MODULE_NAME_OS}" PROPERTIES DEBUG_POSTFIX "_d")
+endif ()
+
 ##########################################################
 # Build Library (time)
 ##########################################################
@@ -560,6 +599,19 @@ if (${LS_STD_BUILD_WITH_TESTS})
             "${MODULE_NAME_CORE}")
 endif ()
 
+##########################################################
+# Linking (os)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_TESTS})
+    message("${MODULE_NAME_OS}: Linking libraries for test application...")
+    target_link_libraries(${MODULE_NAME_OS}_test
+            gtest
+            gmock
+            gtest_main
+            "${MODULE_NAME_OS}")
+endif ()
+
 ##########################################################
 # Linking (time)
 ##########################################################
@@ -589,5 +641,6 @@ if (${LS_STD_BUILD_WITH_TESTS})
             "${MODULE_NAME_ENCODING}"
             "${MODULE_NAME_EVENT}"
             "${MODULE_NAME_IO}"
+            "${MODULE_NAME_OS}"
             "${MODULE_NAME_TIME}")
 endif ()

+ 16 - 0
include/ls_std/ls_std_os.hpp

@@ -0,0 +1,16 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-09-06
+ * Changed:         2022-09-06
+ *
+ * */
+
+#ifndef LS_STD_LS_STD_OS_HPP
+#define LS_STD_LS_STD_OS_HPP
+
+#include <ls_std/os/library/RuntimeLibraryLoader.hpp>
+#include <ls_std/os/library/RuntimeLibraryLoaderParameter.hpp>
+
+#endif

+ 30 - 0
include/ls_std/os/library/RuntimeLibraryLoader.hpp

@@ -0,0 +1,30 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-09-06
+ * Changed:         2022-09-06
+ *
+ * */
+
+#ifndef LS_STD_RUNTIME_LIBRARY_LOADER_HPP
+#define LS_STD_RUNTIME_LIBRARY_LOADER_HPP
+
+#include "RuntimeLibraryLoaderParameter.hpp"
+
+namespace ls::std::os
+{
+  class RuntimeLibraryLoader
+  {
+    public:
+
+      explicit RuntimeLibraryLoader(ls::std::os::RuntimeLibraryLoaderParameter _parameter);
+      ~RuntimeLibraryLoader() = default;
+
+    private:
+
+      ls::std::os::RuntimeLibraryLoaderParameter parameter{};
+  };
+}
+
+#endif

+ 23 - 0
include/ls_std/os/library/RuntimeLibraryLoaderParameter.hpp

@@ -0,0 +1,23 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-09-06
+ * Changed:         2022-09-06
+ *
+ * */
+
+#ifndef LS_STD_RUNTIME_LIBRARY_LOADER_PARAMETER_HPP
+#define LS_STD_RUNTIME_LIBRARY_LOADER_PARAMETER_HPP
+
+#include <string>
+
+namespace ls::std::os
+{
+  struct RuntimeLibraryLoaderParameter
+  {
+    ::std::string path{};
+  };
+}
+
+#endif

+ 21 - 0
source/ls_std/os/library/RuntimeLibraryLoader.cpp

@@ -0,0 +1,21 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-09-06
+ * Changed:         2022-09-06
+ *
+ * */
+
+#include <ls_std/os/library/RuntimeLibraryLoader.hpp>
+#include <ls_std/core/exception/IllegalArgumentException.hpp>
+
+ls::std::os::RuntimeLibraryLoader::RuntimeLibraryLoader(ls::std::os::RuntimeLibraryLoaderParameter _parameter) : parameter(::std::move(_parameter))
+{
+  if (this->parameter.path.empty())
+  {
+    throw ls::std::core::IllegalArgumentException{};
+  }
+}
+
+

+ 43 - 0
test/cases/os/library/RuntimeLibraryLoaderTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-09-06
+ * Changed:         2022-09-06
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std_os.hpp>
+#include <ls_std/ls_std_core.hpp>
+
+namespace
+{
+  class RuntimeLibraryLoaderTest : public ::testing::Test
+  {
+    protected:
+
+      RuntimeLibraryLoaderTest() = default;
+      ~RuntimeLibraryLoaderTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(RuntimeLibraryLoaderTest, constructor_empty_path_parameter)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls::std::os::RuntimeLibraryLoader(ls::std::os::RuntimeLibraryLoaderParameter{});
+                   }
+                   catch (const ls::std::core::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls::std::core::IllegalArgumentException);
+  }
+}