From 89f1022430491b51863fc12695a501da03caa918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:06:26 +0100 Subject: [PATCH] Fix magic enum range --- nano/core_test/CMakeLists.txt | 1 + nano/core_test/enums.cpp | 23 +++++++++++++++++++++++ nano/lib/magic_enum.hpp | 3 +++ nano/lib/stats_enums.hpp | 10 ++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 nano/core_test/enums.cpp create mode 100644 nano/lib/magic_enum.hpp diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index f3bb8451..9ea52c41 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable( distributed_work.cpp election.cpp election_scheduler.cpp + enums.cpp epochs.cpp frontiers_confirmation.cpp gap_cache.cpp diff --git a/nano/core_test/enums.cpp b/nano/core_test/enums.cpp new file mode 100644 index 00000000..ae60532e --- /dev/null +++ b/nano/core_test/enums.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +#include + +TEST (enums, stat_type) +{ + ASSERT_FALSE (nano::to_string (static_cast (0)).empty ()); + ASSERT_FALSE (nano::to_string (nano::stat::type::_last).empty ()); +} + +TEST (enums, stat_detail) +{ + ASSERT_FALSE (nano::to_string (static_cast (0)).empty ()); + ASSERT_FALSE (nano::to_string (nano::stat::detail::_last).empty ()); +} + +TEST (enums, stat_dir) +{ + ASSERT_FALSE (nano::to_string (static_cast (0)).empty ()); + ASSERT_FALSE (nano::to_string (nano::stat::dir::_last).empty ()); +} \ No newline at end of file diff --git a/nano/lib/magic_enum.hpp b/nano/lib/magic_enum.hpp new file mode 100644 index 00000000..3d82e22f --- /dev/null +++ b/nano/lib/magic_enum.hpp @@ -0,0 +1,3 @@ +#define MAGIC_ENUM_RANGE_MIN 0 +#define MAGIC_ENUM_RANGE_MAX 256 +#include \ No newline at end of file diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index d5e0cced..f58bcaf8 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano::stat { @@ -37,6 +37,8 @@ enum class type : uint8_t bootstrap_server, active, backlog, + + _last // Must be the last enum }; /** Optional detail type */ @@ -250,13 +252,17 @@ enum class detail : uint8_t // backlog activated, + + _last // Must be the last enum }; /** Direction of the stat. If the direction is irrelevant, use in */ enum class dir : uint8_t { in, - out + out, + + _last // Must be the last enum }; }