SystemTimeTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-15
  6. * Changed: 2023-05-18
  7. *
  8. * */
  9. #include <gmock/gmock.h>
  10. #include <gtest/gtest.h>
  11. #include <ls-std-time-test.hpp>
  12. #include <ls-std/ls-std-core.hpp>
  13. #include <ls-std/ls-std-time.hpp>
  14. #include <memory>
  15. using ls::std::core::IllegalArgumentException;
  16. using ls::std::time::DateParameter;
  17. using ls::std::time::SystemTime;
  18. using ls::std::time::SystemTimeParameter;
  19. using std::make_shared;
  20. using std::shared_ptr;
  21. using test::time::MockClock;
  22. using testing::AtLeast;
  23. using testing::Return;
  24. using testing::Test;
  25. namespace
  26. {
  27. class SystemTimeTest : public Test
  28. {
  29. public:
  30. SystemTimeTest() = default;
  31. ~SystemTimeTest() override = default;
  32. };
  33. TEST_F(SystemTimeTest, constructor)
  34. {
  35. EXPECT_THROW(
  36. {
  37. try
  38. {
  39. SystemTime systemTime{nullptr};
  40. }
  41. catch (const IllegalArgumentException &_exception)
  42. {
  43. throw;
  44. }
  45. },
  46. IllegalArgumentException);
  47. }
  48. TEST_F(SystemTimeTest, getClassName)
  49. {
  50. ASSERT_STREQ("SystemTime", SystemTime{}.getClassName().c_str());
  51. }
  52. TEST_F(SystemTimeTest, setTime)
  53. {
  54. auto parameter = make_shared<SystemTimeParameter>();
  55. auto posixClock = make_shared<MockClock>();
  56. parameter->setClock(posixClock);
  57. auto birthday = DateParameter(1990, 10, 26, 11, 25, 00);
  58. EXPECT_CALL(*posixClock, setTime(birthday)).Times(AtLeast(1));
  59. ON_CALL(*posixClock, setTime(birthday)).WillByDefault(Return(true));
  60. ASSERT_TRUE(SystemTime{parameter}.set(birthday));
  61. }
  62. }