LogLevelTest.cpp 5.6 KB

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