Browse Source

Fix system time related tests in time module

Patrick-Christopher 1 year ago
parent
commit
73ac52b48b

+ 12 - 6
CMakeLists.txt

@@ -262,11 +262,17 @@ set(SOURCE_FILES_TIME
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/SystemTimeParameter.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/Date.cpp)
 
+set(SOURCE_FILES_LINUX_TIME)
+set(SOURCE_FILES_WINDOWS_TIME)
+
 if (UNIX OR APPLE)
+    message("${MODULE_NAME_TIME}: Add UNIX files for time module...")
     set(SOURCE_FILES_LINUX_TIME
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/PosixClock.cpp)
-else ()
-    set(SOURCE_FILES_LINUX_TIME)
+else (WIN32)
+    message("${MODULE_NAME_TIME}: Add Windows files for time module...")
+    set(SOURCE_FILES_WINDOWS_TIME
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/WindowsClock.cpp)
 endif ()
 
 set(SOURCE_FILES_TIME_JNI
@@ -393,7 +399,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeParameterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/time/system-time/MockPosixClock.cpp)
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/time/system-time/MockClock.cpp)
 endif ()
 
 ####################################################################################################################
@@ -635,18 +641,18 @@ endif ()
 message("${PROJECT_NAME}: Building ${MODULE_NAME_TIME} library version ${PROJECT_VERSION}...")
 
 if (${LS_STD_BUILD_STATIC})
-    add_library("${MODULE_NAME_TIME}" STATIC ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME})
+    add_library("${MODULE_NAME_TIME}" STATIC ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME} ${SOURCE_FILES_WINDOWS_TIME})
     set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "-d")
 endif ()
 
 if (${LS_STD_BUILD_SHARED})
     if (${LS_STD_BUILD_WITH_JNI})
         message("${MODULE_NAME_TIME}: building with JNI...")
-        add_library("${MODULE_NAME_TIME}" SHARED ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME} ${SOURCE_FILES_TIME_JNI})
+        add_library("${MODULE_NAME_TIME}" SHARED ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME} ${SOURCE_FILES_WINDOWS_TIME} ${SOURCE_FILES_TIME_JNI})
         target_link_libraries("${MODULE_NAME_TIME}" ${MODULE_NAME_CORE})
         set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "-d")
     else ()
-        add_library("${MODULE_NAME_TIME}" SHARED ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME})
+        add_library("${MODULE_NAME_TIME}" SHARED ${SOURCE_FILES_TIME} ${SOURCE_FILES_LINUX_TIME} ${SOURCE_FILES_WINDOWS_TIME})
         target_link_libraries("${MODULE_NAME_TIME}" ${MODULE_NAME_CORE})
         set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "-d")
     endif ()

+ 4 - 1
include/ls-std/ls-std-time.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-16
- * Changed:         2023-03-31
+ * Changed:         2023-04-01
  *
  * */
 
@@ -19,6 +19,9 @@
 #endif
 #include <ls-std/time/system-time/SystemTime.hpp>
 #include <ls-std/time/system-time/SystemTimeParameter.hpp>
+#ifdef _WIN32
+  #include <ls-std/time/system-time/WindowsClock.hpp>
+#endif
 
 #include <ls-std/time/type/DateParameterTypes.hpp>
 

+ 3 - 1
include/ls-std/time/common/DateParameterMapper.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-31
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
@@ -23,7 +23,9 @@ namespace ls::std::time
       DateParameterMapper();
       ~DateParameterMapper();
 
+#if defined(unix) || defined(__APPLE__)
       [[nodiscard]] static ls::std::time::type::UnixTimestamp toUnixTimestamp(const ls::std::time::DateParameter &_dateParameter);
+#endif
   };
 }
 

+ 2 - 3
include/ls-std/time/system-time/PosixClock.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
@@ -12,12 +12,11 @@
 
 #include "IClock.hpp"
 #include <cstdint>
-#include <ls-std/os/dynamic-goal.hpp>
 #include <ls-std/time/type/DateParameterTypes.hpp>
 
 namespace ls::std::time
 {
-  class LS_STD_DYNAMIC_GOAL PosixClock : public ls::std::time::IClock
+  class PosixClock : public ls::std::time::IClock
   {
     public:
 

+ 29 - 0
include/ls-std/time/system-time/WindowsClock.hpp

@@ -0,0 +1,29 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-04-01
+* Changed:         2023-04-01
+*
+* */
+
+#ifndef LS_STD_WINDOW_CLOCK_HPP
+#define LS_STD_WINDOW_CLOCK_HPP
+
+#include "IClock.hpp"
+#include <ls-std/os/dynamic-goal.hpp>
+
+namespace ls::std::time
+{
+  class LS_STD_DYNAMIC_GOAL WindowsClock : public ls::std::time::IClock
+  {
+    public:
+
+      WindowsClock();
+      ~WindowsClock() noexcept override;
+
+      [[nodiscard]] bool setTime(const ls::std::time::DateParameter &_dateParameter) override;
+  };
+}
+
+#endif

+ 6 - 2
source/ls-std/time/common/DateParameterMapper.cpp

@@ -3,11 +3,13 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-31
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
-#include <ctime>
+#if defined(unix) || defined(__APPLE__)
+  #include <ctime>
+#endif
 #include <ls-std/time/common/DateParameterMapper.hpp>
 
 using ls::std::time::DateParameter;
@@ -18,6 +20,7 @@ DateParameterMapper::DateParameterMapper() = default;
 
 DateParameterMapper::~DateParameterMapper() = default;
 
+#if defined(unix) || defined(__APPLE__)
 UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_dateParameter)
 {
   time_t rawTime{};
@@ -33,3 +36,4 @@ UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_datePar
 
   return (UnixTimestamp) mktime(timeInfo);
 }
+#endif

+ 13 - 2
source/ls-std/time/system-time/SystemTime.cpp

@@ -3,23 +3,31 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
 #include <ls-std/core/Class.hpp>
 #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
-#include <ls-std/time/system-time/PosixClock.hpp>
+#if defined(unix) || defined(__APPLE__)
+  #include <ls-std/time/system-time/PosixClock.hpp>
+#endif
 #include <ls-std/time/system-time/SystemTime.hpp>
 #include <ls-std/time/system-time/SystemTimeParameter.hpp>
+#ifdef _WIN32
+  #include <ls-std/time/system-time/WindowsClock.hpp>
+#endif
 #include <memory>
 
 using ls::std::core::Class;
 using ls::std::core::NullPointerArgumentEvaluator;
 using ls::std::time::DateParameter;
+#if defined(unix) || defined(__APPLE__)
 using ls::std::time::PosixClock;
+#endif
 using ls::std::time::SystemTime;
 using ls::std::time::SystemTimeParameter;
+using ls::std::time::WindowsClock;
 using ls::std::time::type::UnixTimestamp;
 using std::make_shared;
 using std::shared_ptr;
@@ -49,4 +57,7 @@ void SystemTime::_generateParameter()
 #if defined(unix) || defined(__APPLE__)
   this->parameter->setClock(make_shared<PosixClock>());
 #endif
+#ifdef _WIN32
+  this->parameter->setClock(make_shared<WindowsClock>());
+#endif
 }

+ 22 - 0
source/ls-std/time/system-time/WindowsClock.cpp

@@ -0,0 +1,22 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-04-01
+* Changed:         2023-04-01
+*
+* */
+
+#include <ls-std/time/system-time/WindowsClock.hpp>
+
+using ls::std::time::DateParameter;
+using ls::std::time::WindowsClock;
+
+WindowsClock::WindowsClock() = default;
+
+WindowsClock::~WindowsClock() noexcept = default;
+
+bool WindowsClock::setTime(const DateParameter &_dateParameter)
+{
+  return true; // TODO: implement
+}

+ 8 - 6
test/cases/time/common/DateParameterMapperTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-31
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
@@ -22,12 +22,13 @@ using testing::Values;
 
 namespace
 {
-  class DateParameterMapperTest : public TestWithParam<pair<UnixTimestamp, DateParameter>>
+#if defined(unix) || defined(__APPLE__)
+  class DateParameterMapperTest_Unix : public TestWithParam<pair<UnixTimestamp, DateParameter>>
   {
     public:
 
-      DateParameterMapperTest() = default;
-      ~DateParameterMapperTest() override = default;
+      DateParameterMapperTest_Unix() = default;
+      ~DateParameterMapperTest_Unix() override = default;
 
       static vector<pair<UnixTimestamp, DateParameter>> getTestParameterList()
       {
@@ -39,7 +40,7 @@ namespace
       }
   };
 
-  TEST_P(DateParameterMapperTest, toUnixTimestamp)
+  TEST_P(DateParameterMapperTest_Unix, toUnixTimestamp)
   {
     DateParameter dateParameter = GetParam().second;
     UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(dateParameter);
@@ -47,5 +48,6 @@ namespace
     ASSERT_EQ(GetParam().first, timestamp);
   }
 
-  INSTANTIATE_TEST_SUITE_P(toUnixTimestamp, DateParameterMapperTest, Values(DateParameterMapperTest::getTestParameterList().at(0), DateParameterMapperTest::getTestParameterList().at(1)));
+  INSTANTIATE_TEST_SUITE_P(toUnixTimestamp, DateParameterMapperTest_Unix, Values(DateParameterMapperTest_Unix::getTestParameterList().at(0), DateParameterMapperTest_Unix::getTestParameterList().at(1)));
+#endif
 }

+ 17 - 4
test/cases/time/system-time/SystemTimeParameterTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
@@ -12,8 +12,13 @@
 #include <memory>
 
 using ls::std::time::IClock;
+#if defined(unix) || defined(__APPLE__)
 using ls::std::time::PosixClock;
+#endif
 using ls::std::time::SystemTimeParameter;
+#ifdef _WIN32
+using ls::std::time::WindowsClock;
+#endif
 using std::make_shared;
 using std::shared_ptr;
 using testing::Test;
@@ -36,9 +41,17 @@ namespace
   TEST_F(SystemTimeParameterTest, setClock)
   {
     SystemTimeParameter parameter{};
-    shared_ptr<IClock> posixClock = make_shared<PosixClock>();
-    parameter.setClock(posixClock);
+    shared_ptr<IClock> clock{};
 
-    ASSERT_TRUE(parameter.getClock() == posixClock);
+#if defined(unix) || defined(__APPLE__)
+    clock = make_shared<PosixClock>();
+#endif
+#ifdef _WIN32
+    clock = make_shared<WindowsClock>();
+#endif
+
+    parameter.setClock(clock);
+
+    ASSERT_TRUE(parameter.getClock() == clock);
   }
 }

+ 3 - 3
test/cases/time/system-time/SystemTimeTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
@@ -20,7 +20,7 @@ using ls::std::time::SystemTime;
 using ls::std::time::SystemTimeParameter;
 using std::make_shared;
 using std::shared_ptr;
-using test::time::MockPosixClock;
+using test::time::MockClock;
 using testing::AtLeast;
 using testing::Return;
 using testing::Test;
@@ -59,7 +59,7 @@ namespace
   TEST_F(SystemTimeTest, setTime)
   {
     shared_ptr<SystemTimeParameter> parameter = make_shared<SystemTimeParameter>();
-    shared_ptr<MockPosixClock> posixClock = make_shared<MockPosixClock>();
+    shared_ptr<MockClock> posixClock = make_shared<MockClock>();
     parameter->setClock(posixClock);
     DateParameter birthday = DateParameter(1990, 10, 26, 11, 25, 00);
 

+ 16 - 0
test/classes/time/system-time/MockClock.cpp

@@ -0,0 +1,16 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-15
+* Changed:         2023-04-01
+*
+* */
+
+#include "MockClock.hpp"
+
+using test::time::MockClock;
+
+MockClock::MockClock() = default;
+
+MockClock::~MockClock() noexcept = default;

+ 6 - 6
test/classes/time/system-time/MockPosixClock.hpp → test/classes/time/system-time/MockClock.hpp

@@ -3,12 +3,12 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-31
+* Changed:         2023-04-01
 *
 * */
 
-#ifndef LS_STD_MOCK_POSIX_CLOCK_HPP
-#define LS_STD_MOCK_POSIX_CLOCK_HPP
+#ifndef LS_STD_MOCK_CLOCK_HPP
+#define LS_STD_MOCK_CLOCK_HPP
 
 #include <gmock/gmock.h>
 #include <ls-std/time/common/DateParameter.hpp>
@@ -16,12 +16,12 @@
 
 namespace test::time
 {
-  class MockPosixClock : public ls::std::time::IClock
+  class MockClock : public ls::std::time::IClock
   {
     public:
 
-      MockPosixClock();
-      ~MockPosixClock() noexcept override;
+      MockClock();
+      ~MockClock() noexcept override;
 
       MOCK_METHOD(bool, setTime, (const ls::std::time::DateParameter &_dateParameter), (override));
   };

+ 0 - 16
test/classes/time/system-time/MockPosixClock.cpp

@@ -1,16 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-03-15
-* Changed:         2023-03-15
-*
-* */
-
-#include "MockPosixClock.hpp"
-
-using test::time::MockPosixClock;
-
-MockPosixClock::MockPosixClock() = default;
-
-MockPosixClock::~MockPosixClock() noexcept = default;

+ 2 - 2
test/ls-std-time-test.hpp

@@ -3,13 +3,13 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-04-01
 *
 * */
 
 #ifndef LS_STD_LS_STD_TIME_TEST_HPP
 #define LS_STD_LS_STD_TIME_TEST_HPP
 
-#include <classes/time/system-time/MockPosixClock.hpp>
+#include <classes/time/system-time/MockClock.hpp>
 
 #endif