Browse Source

Fix clang-tidy warnings inside LogLevel class

Patrick-Christopher Mattulat 1 year ago
parent
commit
865c02d164

+ 3 - 3
include/ls-std/io/logging/LogLevel.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-02-06
+ * Changed:         2023-02-22
  *
  * */
 
@@ -24,8 +24,7 @@ namespace ls::std::io
       explicit LogLevel(const ls::std::io::LogLevelValue &_value);
       LogLevel();
       ~LogLevel() override;
-
-      operator unsigned char() const;
+      ;
       ls::std::io::LogLevel &operator=(const ls::std::io::LogLevelValue &_value);
       bool operator<(const ls::std::io::LogLevelValue &_value);
       bool operator<=(const ls::std::io::LogLevelValue &_value);
@@ -33,6 +32,7 @@ namespace ls::std::io
       bool operator>=(const ls::std::io::LogLevelValue &_value);
       bool operator==(const ls::std::io::LogLevelValue &_value);
 
+      [[nodiscard]] ls::std::io::LogLevelValue getValue();
       void setLogLevel(const ls::std::io::LogLevelValue &_value);
       void setLogLevel(const ::std::string &_value);
       [[nodiscard]] ::std::string toString() const;

+ 6 - 6
source/ls-std/io/logging/LogLevel.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-02-07
+ * Changed:         2023-02-22
  *
  * */
 
@@ -22,11 +22,6 @@ ls::std::io::LogLevel::LogLevel() : ls::std::core::Class("LogLevel")
 
 ls::std::io::LogLevel::~LogLevel() = default;
 
-ls::std::io::LogLevel::operator unsigned char() const
-{
-  return this->value;
-}
-
 ls::std::io::LogLevel &ls::std::io::LogLevel::operator=(const ls::std::io::LogLevelValue &_value)
 {
   this->value = _value;
@@ -58,6 +53,11 @@ bool ls::std::io::LogLevel::operator==(const ls::std::io::LogLevelValue &_value)
   return this->value == _value;
 }
 
+ls::std::io::LogLevelValue ls::std::io::LogLevel::getValue()
+{
+  return this->value;
+}
+
 void ls::std::io::LogLevel::setLogLevel(const ls::std::io::LogLevelValue &_value)
 {
   this->value = _value;

+ 15 - 10
test/cases/io/logging/LogLevelTest.cpp

@@ -34,13 +34,13 @@ namespace
   TEST_F(LogLevelTest, constructor_with_log_level_value_parameter)
   {
     LogLevel logLevel{LogLevelValue::INFO};
-    ASSERT_EQ(LogLevelValue::INFO, logLevel);
+    ASSERT_EQ(LogLevelValue::INFO, logLevel.getValue());
   }
 
   TEST_F(LogLevelTest, constructor_default)
   {
     LogLevel logLevel{};
-    ASSERT_EQ(LogLevelValue::FATAL, logLevel);
+    ASSERT_EQ(LogLevelValue::FATAL, logLevel.getValue());
   }
 
   TEST_F(LogLevelTest, operator_assign)
@@ -48,7 +48,7 @@ namespace
     LogLevel logLevel{LogLevelValue::DEBUG};
     logLevel = LogLevelValue::INFO;
 
-    ASSERT_EQ(LogLevelValue::INFO, logLevel);
+    ASSERT_EQ(LogLevelValue::INFO, logLevel.getValue());
   }
 
   TEST_F(LogLevelTest, operator_lessThan)
@@ -122,12 +122,17 @@ namespace
     ASSERT_FALSE(logLevel == LogLevelValue::DEBUG);
   }
 
+  TEST_F(LogLevelTest, getLogLevel)
+  {
+    ASSERT_EQ(LogLevelValue::FATAL, LogLevel{}.getValue());
+  }
+
   TEST_F(LogLevelTest, setLogLevel_with_log_level_value)
   {
     LogLevel logLevel{};
     logLevel.setLogLevel(LogLevelValue::INFO);
 
-    ASSERT_EQ(LogLevelValue::INFO, logLevel);
+    ASSERT_EQ(LogLevelValue::INFO, logLevel.getValue());
   }
 
   TEST_F(LogLevelTest, setLogLevel_with_string)
@@ -135,17 +140,17 @@ namespace
     LogLevel logLevel{};
 
     logLevel.setLogLevel("FATAL");
-    ASSERT_EQ(LogLevelValue::FATAL, logLevel);
+    ASSERT_EQ(LogLevelValue::FATAL, logLevel.getValue());
     logLevel.setLogLevel("ERROR");
-    ASSERT_EQ(LogLevelValue::ERR, logLevel);
+    ASSERT_EQ(LogLevelValue::ERR, logLevel.getValue());
     logLevel.setLogLevel("WARN");
-    ASSERT_EQ(LogLevelValue::WARN, logLevel);
+    ASSERT_EQ(LogLevelValue::WARN, logLevel.getValue());
     logLevel.setLogLevel("INFO");
-    ASSERT_EQ(LogLevelValue::INFO, logLevel);
+    ASSERT_EQ(LogLevelValue::INFO, logLevel.getValue());
     logLevel.setLogLevel("DEBUG");
-    ASSERT_EQ(LogLevelValue::DEBUG, logLevel);
+    ASSERT_EQ(LogLevelValue::DEBUG, logLevel.getValue());
     logLevel.setLogLevel("TRACE");
-    ASSERT_EQ(LogLevelValue::TRACE, logLevel);
+    ASSERT_EQ(LogLevelValue::TRACE, logLevel.getValue());
   }
 
   TEST_F(LogLevelTest, setLogLevel_string_no_valid_string)

+ 2 - 2
test/cases/io/logging/LoggerTest.cpp

@@ -166,7 +166,7 @@ namespace
   TEST_F(LoggerTest, getLogLevel)
   {
     Logger logger{createFileLogger("output.log")};
-    ASSERT_EQ(LogLevelValue::INFO, logger.getLogLevel());
+    ASSERT_EQ(LogLevelValue::INFO, logger.getLogLevel().getValue());
   }
 
   TEST_F(LoggerTest, info)
@@ -203,7 +203,7 @@ namespace
     Logger logger{createFileLogger("output.log")};
     logger.setLogLevel(LogLevelValue::ERR);
 
-    ASSERT_EQ(LogLevelValue::ERR, logger.getLogLevel());
+    ASSERT_EQ(LogLevelValue::ERR, logger.getLogLevel().getValue());
   }
 
   TEST_F(LoggerTest, trace)