DateParameterMapperTest.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-31
  6. * Changed: 2023-04-01
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-time.hpp>
  11. #include <utility>
  12. #include <vector>
  13. #ifdef _WIN32
  14. #include <windows.h>
  15. #endif
  16. using ls::std::time::DateParameter;
  17. using ls::std::time::DateParameterMapper;
  18. using ls::std::time::type::UnixTimestamp;
  19. using std::pair;
  20. using std::vector;
  21. using testing::TestWithParam;
  22. using testing::Values;
  23. namespace
  24. {
  25. #if defined(unix) || defined(__APPLE__)
  26. class DateParameterMapperTest_Unix : public TestWithParam<pair<UnixTimestamp, DateParameter>>
  27. {
  28. public:
  29. DateParameterMapperTest_Unix() = default;
  30. ~DateParameterMapperTest_Unix() override = default;
  31. static vector<pair<UnixTimestamp, DateParameter>> getTestParameterList()
  32. {
  33. vector<pair<UnixTimestamp, DateParameter>> testParameterList{};
  34. testParameterList.emplace_back(656936700, DateParameter{1990, 10, 26, 11, 25, 00});
  35. testParameterList.emplace_back(612694320, DateParameter{1989, 6, 1, 10, 52, 00});
  36. return testParameterList;
  37. }
  38. };
  39. TEST_P(DateParameterMapperTest_Unix, toUnixTimestamp)
  40. {
  41. DateParameter dateParameter = GetParam().second;
  42. UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(dateParameter);
  43. ASSERT_EQ(GetParam().first, timestamp);
  44. }
  45. INSTANTIATE_TEST_SUITE_P(toUnixTimestamp, DateParameterMapperTest_Unix, Values(DateParameterMapperTest_Unix::getTestParameterList().at(0), DateParameterMapperTest_Unix::getTestParameterList().at(1)));
  46. #endif
  47. #ifdef _WIN32
  48. class DateParameterMapperTest_Windows : public TestWithParam<DateParameter>
  49. {
  50. public:
  51. DateParameterMapperTest_Windows() = default;
  52. ~DateParameterMapperTest_Windows() override = default;
  53. static vector<DateParameter> getTestParameterList()
  54. {
  55. vector<DateParameter> testParameterList{};
  56. testParameterList.emplace_back(1990, 10, 26, 11, 25, 00);
  57. testParameterList.emplace_back(1989, 6, 1, 10, 52, 00);
  58. return testParameterList;
  59. }
  60. };
  61. TEST_P(DateParameterMapperTest_Windows, toWindowsSystemTime)
  62. {
  63. DateParameter dateParameter = GetParam();
  64. SYSTEMTIME systemTime = DateParameterMapper::toWindowsSystemTime(dateParameter);
  65. ASSERT_EQ(systemTime.wYear, GetParam().getYear());
  66. ASSERT_EQ(systemTime.wMonth, GetParam().getMonth());
  67. ASSERT_EQ(systemTime.wDayOfWeek, 0);
  68. ASSERT_EQ(systemTime.wDay, GetParam().getDay());
  69. ASSERT_EQ(systemTime.wHour, GetParam().getHour());
  70. ASSERT_EQ(systemTime.wMinute, GetParam().getMinute());
  71. ASSERT_EQ(systemTime.wSecond, GetParam().getSecond());
  72. ASSERT_EQ(systemTime.wMilliseconds, 0);
  73. }
  74. INSTANTIATE_TEST_SUITE_P(toWindowsSystemTime, DateParameterMapperTest_Windows, Values(DateParameterMapperTest_Windows::getTestParameterList().at(0), DateParameterMapperTest_Windows::getTestParameterList().at(1)));
  75. #endif
  76. }