LogLevelTest.cpp 4.8 KB

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