LogLevelTest.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2021-05-02
  6. * Changed: 2021-07-16
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class LogLevelTest : public ::testing::Test
  14. {
  15. protected:
  16. LogLevelTest() = default;
  17. ~LogLevelTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(LogLevelTest, constructor_with_log_level_value_parameter)
  24. {
  25. ls_std::LogLevel logLevel{ls_std::LogLevelValue::INFO};
  26. ASSERT_EQ(ls_std::LogLevelValue::INFO, logLevel);
  27. }
  28. TEST_F(LogLevelTest, constructor_default)
  29. {
  30. ls_std::LogLevel logLevel{};
  31. ASSERT_EQ(ls_std::LogLevelValue::FATAL, logLevel);
  32. }
  33. TEST_F(LogLevelTest, operator_assign)
  34. {
  35. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  36. logLevel = ls_std::LogLevelValue::INFO;
  37. ASSERT_EQ(ls_std::LogLevelValue::INFO, logLevel);
  38. }
  39. TEST_F(LogLevelTest, operator_lessThan)
  40. {
  41. ls_std::LogLevel logLevel{}; // default is FATAL
  42. ASSERT_TRUE(logLevel < ls_std::LogLevelValue::ERR);
  43. ASSERT_TRUE(logLevel < ls_std::LogLevelValue::WARN);
  44. ASSERT_TRUE(logLevel < ls_std::LogLevelValue::INFO);
  45. ASSERT_TRUE(logLevel < ls_std::LogLevelValue::DEBUG);
  46. ASSERT_TRUE(logLevel < ls_std::LogLevelValue::TRACE);
  47. }
  48. TEST_F(LogLevelTest, operator_lessThan_not_less_than)
  49. {
  50. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  51. ASSERT_FALSE(logLevel < ls_std::LogLevelValue::ERR);
  52. }
  53. TEST_F(LogLevelTest, operator_less_than_equals)
  54. {
  55. ls_std::LogLevel logLevel{}; // default is FATAL
  56. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::FATAL);
  57. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::ERR);
  58. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::WARN);
  59. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::INFO);
  60. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::DEBUG);
  61. ASSERT_TRUE(logLevel <= ls_std::LogLevelValue::TRACE);
  62. }
  63. TEST_F(LogLevelTest, operator_less_than_equals_not_less_than_equals)
  64. {
  65. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  66. ASSERT_FALSE(logLevel <= ls_std::LogLevelValue::ERR);
  67. }
  68. TEST_F(LogLevelTest, operator_greater_than)
  69. {
  70. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  71. ASSERT_TRUE(logLevel > ls_std::LogLevelValue::ERR);
  72. }
  73. TEST_F(LogLevelTest, operator_greater_than_not_greater_than)
  74. {
  75. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  76. ASSERT_FALSE(logLevel > ls_std::LogLevelValue::DEBUG);
  77. }
  78. TEST_F(LogLevelTest, operator_greater_than_equals)
  79. {
  80. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  81. ASSERT_TRUE(logLevel >= ls_std::LogLevelValue::ERR);
  82. }
  83. TEST_F(LogLevelTest, operator_greater_than_equals_not_greater_than_equals)
  84. {
  85. ls_std::LogLevel logLevel{};
  86. ASSERT_FALSE(logLevel >= ls_std::LogLevelValue::ERR);
  87. }
  88. TEST_F(LogLevelTest, operator_equals)
  89. {
  90. ls_std::LogLevel logLevel{ls_std::LogLevelValue::DEBUG};
  91. ASSERT_TRUE(logLevel == ls_std::LogLevelValue::DEBUG);
  92. }
  93. TEST_F(LogLevelTest, operator_equals_not_equals)
  94. {
  95. ls_std::LogLevel logLevel{ls_std::LogLevelValue::TRACE};
  96. ASSERT_FALSE(logLevel == ls_std::LogLevelValue::DEBUG);
  97. }
  98. TEST_F(LogLevelTest, setLogLevel_with_log_level_value)
  99. {
  100. ls_std::LogLevel logLevel{};
  101. logLevel.setLogLevel(ls_std::LogLevelValue::INFO);
  102. ASSERT_EQ(ls_std::LogLevelValue::INFO, logLevel);
  103. }
  104. TEST_F(LogLevelTest, setLogLevel_with_string)
  105. {
  106. ls_std::LogLevel logLevel{};
  107. logLevel.setLogLevel("FATAL");
  108. ASSERT_EQ(ls_std::LogLevelValue::FATAL, logLevel);
  109. logLevel.setLogLevel("ERROR");
  110. ASSERT_EQ(ls_std::LogLevelValue::ERR, logLevel);
  111. logLevel.setLogLevel("WARN");
  112. ASSERT_EQ(ls_std::LogLevelValue::WARN, logLevel);
  113. logLevel.setLogLevel("INFO");
  114. ASSERT_EQ(ls_std::LogLevelValue::INFO, logLevel);
  115. logLevel.setLogLevel("DEBUG");
  116. ASSERT_EQ(ls_std::LogLevelValue::DEBUG, logLevel);
  117. logLevel.setLogLevel("TRACE");
  118. ASSERT_EQ(ls_std::LogLevelValue::TRACE, logLevel);
  119. }
  120. TEST_F(LogLevelTest, setLogLevel_string_no_valid_string)
  121. {
  122. ls_std::LogLevel logLevel{};
  123. EXPECT_THROW({
  124. try
  125. {
  126. logLevel.setLogLevel("This is not a valid log level!");
  127. }
  128. catch (const ls_std::IllegalArgumentException &_exception)
  129. {
  130. throw;
  131. }
  132. }, ls_std::IllegalArgumentException);
  133. }
  134. TEST_F(LogLevelTest, toString)
  135. {
  136. ls_std::LogLevel logLevel{};
  137. ASSERT_STREQ("FATAL", logLevel.toString().c_str());
  138. logLevel.setLogLevel(ls_std::LogLevelValue::ERR);
  139. ASSERT_STREQ("ERROR", logLevel.toString().c_str());
  140. logLevel.setLogLevel(ls_std::LogLevelValue::WARN);
  141. ASSERT_STREQ("WARN", logLevel.toString().c_str());
  142. logLevel.setLogLevel(ls_std::LogLevelValue::INFO);
  143. ASSERT_STREQ("INFO", logLevel.toString().c_str());
  144. logLevel.setLogLevel(ls_std::LogLevelValue::DEBUG);
  145. ASSERT_STREQ("DEBUG", logLevel.toString().c_str());
  146. logLevel.setLogLevel(ls_std::LogLevelValue::TRACE);
  147. ASSERT_STREQ("TRACE", logLevel.toString().c_str());
  148. }
  149. }