Skip to content

Commit

Permalink
PARSE TESTS WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 26, 2024
1 parent 8375c6f commit f2e2ff4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_executable(
ipc.cpp
ledger.cpp
locks.cpp
logger.cpp
logging.cpp
message.cpp
message_deserializer.cpp
memory_pool.cpp
Expand Down
16 changes: 0 additions & 16 deletions nano/core_test/logger.cpp

This file was deleted.

50 changes: 50 additions & 0 deletions nano/core_test/logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <nano/lib/logging.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>

using namespace std::chrono_literals;

TEST (log_parse, parse_level)
{
ASSERT_EQ (nano::log::parse_level ("error"), nano::log::level::error);
ASSERT_EQ (nano::log::parse_level ("off"), nano::log::level::off);
ASSERT_THROW (nano::log::parse_level ("invalid"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_level (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_level ("_error"), std::invalid_argument);
}

TEST (log_parse, parse_type)
{
ASSERT_EQ (nano::log::parse_type ("node"), nano::log::type::node);
ASSERT_THROW (nano::log::parse_type ("invalid"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_type (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_type ("_node"), std::invalid_argument);
}

TEST (log_parse, parse_detail)
{
ASSERT_EQ (nano::log::parse_detail ("all"), nano::log::detail::all);
ASSERT_EQ (nano::log::parse_detail ("process_confirmed"), nano::log::detail::process_confirmed);
ASSERT_THROW (nano::log::parse_detail ("invalid"), std::invalid_argument);
ASSERT_THROW (nano::log::parse_detail (""), std::invalid_argument);
ASSERT_THROW (nano::log::parse_detail ("_all"), std::invalid_argument);
}

TEST (log_parse, parse_logger_id)
{
ASSERT_EQ (nano::log_config::parse_logger_id ("node"), std::make_pair (nano::log::type::node, nano::log::detail::all));
ASSERT_EQ (nano::log_config::parse_logger_id ("node::all"), std::make_pair (nano::log::type::node, nano::log::detail::all));
ASSERT_EQ (nano::log_config::parse_logger_id ("node::process_confirmed"), std::make_pair (nano::log::type::node, nano::log::detail::process_confirmed));
ASSERT_THROW (nano::log_config::parse_logger_id ("node::invalid"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("node::"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("node::_all"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("node::_process_confirmed"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("invalid"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("invalid."), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("invalid._all"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("invalid._process_confirmed"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("::"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id ("::all"), std::invalid_argument);
ASSERT_THROW (nano::log_config::parse_logger_id (""), std::invalid_argument);
}
2 changes: 0 additions & 2 deletions nano/lib/logging_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ enum class level

enum class type
{
all = 0, // reserved

generic,
init,
config,
Expand Down

0 comments on commit f2e2ff4

Please sign in to comment.