From cc172a494f250cbb6f1fa3af340469fb03dfbdf5 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 5 Jan 2024 12:21:16 -0600 Subject: [PATCH] replace macro with anonymous namespace function --- .../dEnumsTests/MagicEnumTests.cpp | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/dCommonTests/dEnumsTests/MagicEnumTests.cpp b/tests/dCommonTests/dEnumsTests/MagicEnumTests.cpp index 2ad92914b..0ca2e2ea9 100644 --- a/tests/dCommonTests/dEnumsTests/MagicEnumTests.cpp +++ b/tests/dCommonTests/dEnumsTests/MagicEnumTests.cpp @@ -116,27 +116,30 @@ TEST(MagicEnumTest, eGameMessageTypeTest) { delete Game::logger; } -#define ASSERT_EARRAY_SORTED(EARRAY_VAR)\ - for (int i = 0; i < EARRAY_VAR->size(); i++) {\ - const auto entryCurr = EARRAY_VAR->at(i).first;\ - LOG_EARRAY(EARRAY_VAR, i, entryCurr);\ - const auto entryNext = EARRAY_VAR->at(++i).first;\ - LOG_EARRAY(EARRAY_VAR, i, entryNext);\ - ASSERT_TRUE(entryCurr < entryNext);\ - };\ - -#define LOG_EARRAY(EARRAY_VAR, INDICE, ENTRY)\ - LOG(#EARRAY_VAR"[%i] = %i, %s", INDICE, ENTRY, magic_enum::enum_name(ENTRY).data()); +#define LOG_EARRAY(EARRAY_VAR, INDICE, ENTRY) LOG(#EARRAY_VAR"[%i] = %i, %s", INDICE, ENTRY, magic_enum::enum_name(ENTRY).data()); + +namespace { + template + void AssertEnumArraySorted(const T& eArray) { + for (int i = 0; i < eArray->size(); ++i) { + const auto entryCurr = eArray->at(i).first; + LOG_EARRAY(eArray, i, entryCurr); + const auto entryNext = eArray->at(++i).first; + LOG_EARRAY(eArray, i, entryNext); + ASSERT_TRUE(entryCurr < entryNext); + } + } +} // Test that the magic enum arrays are pre-sorted TEST(MagicEnumTest, ArraysAreSorted) { Game::logger = new Logger("./MagicEnumTest_ArraysAreSorted.log", true, true); constexpr auto wmArray = &magic_enum::enum_entries(); - ASSERT_EARRAY_SORTED(wmArray); + AssertEnumArraySorted(wmArray); constexpr auto gmArray = &magic_enum::enum_entries(); - ASSERT_EARRAY_SORTED(gmArray); + AssertEnumArraySorted(gmArray); delete Game::logger; }