mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
comparison operators for level: gtest, std::find, == operator, !=operator
This commit is contained in:
parent
b53cd95361
commit
13cc398f06
@ -33,8 +33,12 @@ struct LEVELS {
|
||||
LEVELS(const LEVELS &other): value(other.value), text(other.text.c_str()) {}
|
||||
LEVELS(int id, const char *idtext) : value(id), text(idtext) {}
|
||||
|
||||
friend bool operator==(const LEVELS &lhs, const LEVELS &rhs) {
|
||||
return (lhs.value == rhs.value && lhs.text == rhs.text);
|
||||
bool operator==(const LEVELS &rhs) const {
|
||||
return (value == rhs.value && text == rhs.text);
|
||||
}
|
||||
|
||||
bool operator!=(const LEVELS &rhs) const {
|
||||
return (value != rhs.value || text != rhs.text);
|
||||
}
|
||||
|
||||
const int value;
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
const std::string log_directory = "./";
|
||||
const std::string t_info = "test INFO ";
|
||||
@ -112,6 +114,24 @@ TEST(Initialization, No_Logger_Initialized___Expecting_LOG_calls_to_be_Still_OKi
|
||||
}
|
||||
#endif // #ifdef G3_DYNAMIC_LOGGING
|
||||
|
||||
TEST(Basics, Levels) {
|
||||
std::vector<LEVELS> levels = {INFO, WARNING, FATAL};
|
||||
auto info = INFO;
|
||||
auto warning = WARNING;
|
||||
|
||||
auto found_info = std::find(levels.begin(), levels.end(), info);
|
||||
EXPECT_TRUE(found_info != levels.end());
|
||||
|
||||
auto found_warning = std::find(levels.begin(), levels.end(), WARNING);
|
||||
EXPECT_TRUE(found_warning != levels.end());
|
||||
|
||||
auto not_found_debug = std::find(levels.begin(), levels.end(), DEBUG);
|
||||
EXPECT_FALSE(not_found_debug!= levels.end());
|
||||
EXPECT_NE(INFO, WARNING);
|
||||
EXPECT_EQ(info, INFO);
|
||||
EXPECT_TRUE(INFO == INFO);
|
||||
EXPECT_FALSE(info == WARNING);
|
||||
}
|
||||
|
||||
TEST(Basics, Shutdown) {
|
||||
std::string file_content;
|
||||
|
Loading…
Reference in New Issue
Block a user