diff --git a/example/example.cpp b/example/example.cpp index a02639d..0072107 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -26,11 +26,16 @@ #include struct SomeStruct { - int SomeField; - void SomeMethod1() { std::cout << "No called!" << std::endl; } - int SomeMethod2() { + int somefield; + + void SomeMethod1(const int i) { + somefield = i; std::cout << "No called!" << std::endl; - return 1; + } + + int SomeMethod2() const { + std::cout << "No called!" << std::endl; + return somefield; } }; @@ -38,42 +43,48 @@ void SomeMethod3() { std::cout << "No called!" << std::endl; } struct Long { struct LL { - int LLLField; + int field; }; - LL LLField; + LL ll; }; -int someVar = 0; +int somevar = 0; enum class Color { RED, GREEN, BLUE }; void TestCase1() { - SomeStruct someVar; - Long otherVar; - int intValue; - SomeStruct* ptrVar; - SomeStruct** ptrptrVar; + SomeStruct somevar{}; + Long othervar{}; + int intvar; + SomeStruct* ptrvar; + SomeStruct** ptrptrvar; - constexpr auto constexpr_work_fine = NAMEOF(intValue); - std::cout << constexpr_work_fine << std::endl; // intValue + constexpr auto constexpr_work_fine = NAMEOF(intvar); + std::cout << constexpr_work_fine << std::endl; // intvar - std::cout << NAMEOF(someVar) << std::endl; // someVar std::cout << NAMEOF(Color::RED) << std::endl; // RED - std::cout << NAMEOF(someVar.SomeField) << std::endl; // SomeField - std::cout << NAMEOF((&someVar)->SomeField) << std::endl; // SomeField - std::cout << NAMEOF(::someVar) << std::endl; // someVar - std::cout << NAMEOF(otherVar.LLField.LLLField) << std::endl; // LLLField - std::cout << NAMEOF(&someVar) << std::endl; // someVar - std::cout << NAMEOF(ptrVar) << std::endl; // ptrVar - std::cout << NAMEOF(*ptrVar) << std::endl; // ptrVar - std::cout << NAMEOF(ptrptrVar) << std::endl; // ptrptrVar - std::cout << NAMEOF(*ptrptrVar) << std::endl; // ptrptrVar - std::cout << NAMEOF(**ptrptrVar) << std::endl; // ptrptrVar - std::cout << NAMEOF(+intValue) << std::endl; // intValue - std::cout << NAMEOF(-intValue) << std::endl; // intValue - std::cout << NAMEOF(~intValue) << std::endl; // intValue - std::cout << NAMEOF(!intValue) << std::endl; // intValue - std::cout << NAMEOF(someVar.SomeMethod1()) << std::endl; // SomeMethod1() + + std::cout << NAMEOF(somevar) << std::endl; // somevar + std::cout << NAMEOF(somevar.somefield) << std::endl; // somefield + std::cout << NAMEOF((&somevar)->somefield) << std::endl; // somefield + std::cout << NAMEOF(::somevar) << std::endl; // somevar + std::cout << NAMEOF(&somevar) << std::endl; // somevar + + std::cout << NAMEOF(othervar.ll.field) << std::endl; // field + + std::cout << NAMEOF(ptrvar) << std::endl; // ptrvar + std::cout << NAMEOF(*ptrvar) << std::endl; // ptrvar + + std::cout << NAMEOF(ptrptrvar) << std::endl; // ptrptrvar + std::cout << NAMEOF(*ptrptrvar) << std::endl; // ptrptrvar + std::cout << NAMEOF(**ptrptrvar) << std::endl; // ptrptrvar + + std::cout << NAMEOF(+intvar) << std::endl; // intvar + std::cout << NAMEOF(-intvar) << std::endl; // intvar + std::cout << NAMEOF(~intvar) << std::endl; // intvar + std::cout << NAMEOF(!intvar) << std::endl; // intvar + + std::cout << NAMEOF(somevar.SomeMethod1) << std::endl; // SomeMethod1 std::cout << NAMEOF(&SomeStruct::SomeMethod2) << std::endl; // SomeMethod2 std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3 @@ -82,20 +93,14 @@ void TestCase1() { std::cout << NAMEOF(Long::LL) << std::endl; // LL std::cout << NAMEOF(volatile const int) << std::endl; // const volatile int - // If no RTTI, use NAMEOF_TYPE(). -#if !defined(__GXX_RTTI) && !defined(_CPPRTTI) && !defined(__RTTI) && !defined(__INTEL_RTTI__) - std::cout << NAMEOF_TYPE(int[]) << std::endl; // int[] - std::cout << NAMEOF_TYPE(SomeStruct) << std::endl; // SomeStruct - std::cout << NAMEOF_TYPE(Long::LL) << std::endl; // LL - std::cout << NAMEOF_TYPE(volatile const int) << std::endl; // const volatile int -#endif - - std::cout << NAMEOF_FULL(someVar.SomeField) << std::endl; // someVar.SomeField + std::cout << NAMEOF_FULL(somevar.somefield) << std::endl; // somevar.somefield std::cout << NAMEOF_FULL(&SomeStruct::SomeMethod2) << std::endl; // &SomeStruct::SomeMethod2 + std::cout << NAMEOF_FULL(Long::LL) << std::endl; // Long::LL + std::cout << NAMEOF_FULL(std::string) << std::endl; // std::string } void TestCase2() { - auto div = [](int x, int y) { + const auto div = [](int x, int y) { if (y == 0) { throw std::invalid_argument(std::string(NAMEOF(y)).append(" should not be zero!")); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4a51b03..db08d9f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include) add_executable(${PROJECT_NAME}_test test.cpp) add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test) -add_executable(${PROJECT_NAME}_test_no_rtti test_no_rtti.cpp) +add_executable(${PROJECT_NAME}_test_no_rtti test.cpp) if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) target_compile_options(${PROJECT_NAME}_test_no_rtti PUBLIC -fno-rtti) elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") diff --git a/test/test.cpp b/test/test.cpp index 1cdf16a..e7dc816 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -22,19 +22,25 @@ // SOFTWARE. #define CATCH_CONFIG_MAIN - #include + #include + #include #include #include struct SomeStruct { - int SomeField; - void SomeMethod1() { std::cout << "No called!" << std::endl; } - int SomeMethod2() { + int somefield; + + void SomeMethod1(const int i) { + somefield = i; std::cout << "No called!" << std::endl; - return 1; + } + + int SomeMethod2() const { + std::cout << "No called!" << std::endl; + return somefield; } }; @@ -42,26 +48,26 @@ void SomeMethod3() { std::cout << "No called!" << std::endl; } struct Long { struct LL { - int LLLField; + int field; }; - LL LLField; + LL ll; }; -int someVar = 0; +int somevar = 0; enum class Color { RED, GREEN, BLUE }; TEST_CASE("constexpr") { - SomeStruct someVar; + SomeStruct somevar{}; SECTION("NAMEOF") { - constexpr auto n = NAMEOF(someVar); - REQUIRE(std::strcmp(n, "someVar") == 0); + constexpr auto n = NAMEOF(somevar); + REQUIRE(std::strcmp(n, "somevar") == 0); } SECTION("NAMEOF_FULL") { - constexpr auto n = NAMEOF_FULL((&someVar)->SomeField); - REQUIRE(std::strcmp(n, "(&someVar)->SomeField") == 0); + constexpr auto n = NAMEOF_FULL((&somevar)->somefield); + REQUIRE(std::strcmp(n, "(&somevar)->somefield") == 0); } SECTION("NAMEOF_TYPE") { @@ -76,52 +82,47 @@ TEST_CASE("constexpr") { } TEST_CASE("NAMEOF") { - SomeStruct someVar; - Long otherVar; - int intValue; - SomeStruct* ptrVar; - SomeStruct** ptrptrVar; + SomeStruct somevar{}; + Long othervar{}; + int intvar; + SomeStruct* ptrvar; + SomeStruct** ptrptrvar; SECTION("NAMEOF_VARIABLE") { - REQUIRE(std::strcmp(NAMEOF(someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(someVar.SomeField), "SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF((&someVar)->SomeField), "SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF(::someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(otherVar.LLField.LLLField), "LLLField") == 0); - REQUIRE(std::strcmp(NAMEOF(&someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(*ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(*ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(**ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(+intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(-intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(~intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(!intValue), "intValue") == 0); + REQUIRE(std::strcmp(NAMEOF(somevar), "somevar") == 0); + REQUIRE(std::strcmp(NAMEOF(&somevar), "somevar") == 0); + REQUIRE(std::strcmp(NAMEOF(somevar.somefield), "somefield") == 0); + REQUIRE(std::strcmp(NAMEOF((&somevar)->somefield), "somefield") == 0); + REQUIRE(std::strcmp(NAMEOF(::somevar), "somevar") == 0); + + REQUIRE(std::strcmp(NAMEOF(othervar.ll.field), "field") == 0); + + REQUIRE(std::strcmp(NAMEOF(ptrvar), "ptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF(*ptrvar), "ptrvar") == 0); + + REQUIRE(std::strcmp(NAMEOF(ptrptrvar), "ptrptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF(*ptrptrvar), "ptrptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF(**ptrptrvar), "ptrptrvar") == 0); + + REQUIRE(std::strcmp(NAMEOF(+intvar), "intvar") == 0); + REQUIRE(std::strcmp(NAMEOF(-intvar), "intvar") == 0); + REQUIRE(std::strcmp(NAMEOF(~intvar), "intvar") == 0); + REQUIRE(std::strcmp(NAMEOF(!intvar), "intvar") == 0); } SECTION("NAMEOF_TYPE") { REQUIRE(std::strcmp(NAMEOF(int[]), "int[]") == 0); - REQUIRE(std::strcmp(NAMEOF(int[]), NAMEOF_TYPE(int[])) == 0); - REQUIRE(std::strcmp(NAMEOF(int), "int") == 0); - REQUIRE(std::strcmp(NAMEOF(int), NAMEOF_TYPE(int)) == 0); - REQUIRE(std::strcmp(NAMEOF(const volatile int[]), "const volatile int[]") == 0); - REQUIRE(std::strcmp(NAMEOF(const volatile int[]), NAMEOF_TYPE(const volatile int[])) == 0); - REQUIRE(std::strcmp(NAMEOF(std::string), "string") == 0); - REQUIRE(std::strcmp(NAMEOF(std::string), NAMEOF_TYPE(std::string)) == 0); REQUIRE(std::strcmp(NAMEOF(SomeStruct), "SomeStruct") == 0); - REQUIRE(std::strcmp(NAMEOF(SomeStruct), NAMEOF_TYPE(SomeStruct)) == 0); - REQUIRE(std::strcmp(NAMEOF(Long::LL), "LL") == 0); - REQUIRE(std::strcmp(NAMEOF(Long::LL), NAMEOF_TYPE(Long::LL)) == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(Color), "Color") == 0); } SECTION("NAMEOF_FUNCTION") { - REQUIRE(std::strcmp(NAMEOF(someVar.SomeMethod1()), "SomeMethod1()") == 0); + REQUIRE(std::strcmp(NAMEOF(somevar.SomeMethod1), "SomeMethod1") == 0); REQUIRE(std::strcmp(NAMEOF(&SomeStruct::SomeMethod2), "SomeMethod2") == 0); REQUIRE(std::strcmp(NAMEOF(SomeMethod3), "SomeMethod3") == 0); } @@ -133,53 +134,48 @@ TEST_CASE("NAMEOF") { } TEST_CASE("NAMEOF_FULL") { - SomeStruct someVar; - Long otherVar; - int intValue; - SomeStruct* ptrVar; - SomeStruct** ptrptrVar; + SomeStruct somevar{}; + Long othervar{}; + int intvar; + SomeStruct* ptrvar; + SomeStruct** ptrptrvar; SECTION("NAMEOF_VARIABLE_FULL") { - REQUIRE(std::strcmp(NAMEOF_FULL(someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(someVar.SomeField), "someVar.SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL((&someVar)->SomeField), "(&someVar)->SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(::someVar), "::someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(otherVar.LLField.LLLField), "otherVar.LLField.LLLField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(&someVar), "&someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(*ptrVar), "*ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(*ptrptrVar), "*ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(**ptrptrVar), "**ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(+intValue), "+intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(-intValue), "-intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(~intValue), "~intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(!intValue), "!intValue") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(somevar), "somevar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(&somevar), "&somevar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(somevar.somefield), "somevar.somefield") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL((&somevar)->somefield), "(&somevar)->somefield") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(::somevar), "::somevar") == 0); + + REQUIRE(std::strcmp(NAMEOF_FULL(othervar.ll.field), "othervar.ll.field") == 0); + + REQUIRE(std::strcmp(NAMEOF_FULL(ptrvar), "ptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(*ptrvar), "*ptrvar") == 0); + + REQUIRE(std::strcmp(NAMEOF_FULL(ptrptrvar), "ptrptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(*ptrptrvar), "*ptrptrvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(**ptrptrvar), "**ptrptrvar") == 0); + + REQUIRE(std::strcmp(NAMEOF_FULL(+intvar), "+intvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(-intvar), "-intvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(~intvar), "~intvar") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(!intvar), "!intvar") == 0); } SECTION("NAMEOF_TYPE_FULL") { REQUIRE(std::strcmp(NAMEOF_FULL(int[]), "int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(int[]), NAMEOF_TYPE_FULL(int[])) == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(int), "int") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(int), NAMEOF_TYPE_FULL(int)) == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(const volatile int[]), "const volatile int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(const volatile int[]), NAMEOF_TYPE_FULL(const volatile int[])) == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(std::string), "std::string") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(std::string), NAMEOF_TYPE_FULL(std::string)) == 0); REQUIRE(std::strcmp(NAMEOF_FULL(SomeStruct), "SomeStruct") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(SomeStruct), NAMEOF_TYPE_FULL(SomeStruct)) == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(Long::LL), "Long::LL") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(Long::LL), NAMEOF_TYPE_FULL(Long::LL)) == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(Color), "Color") == 0); } SECTION("NAMEOF_FUNCTION_FULL") { - REQUIRE(std::strcmp(NAMEOF_FULL(someVar.SomeMethod1()), "someVar.SomeMethod1()") == 0); + REQUIRE(std::strcmp(NAMEOF_FULL(somevar.SomeMethod1), "somevar.SomeMethod1") == 0); REQUIRE(std::strcmp(NAMEOF_FULL(&SomeStruct::SomeMethod2), "&SomeStruct::SomeMethod2") == 0); REQUIRE(std::strcmp(NAMEOF_FULL(SomeMethod3), "SomeMethod3") == 0); } diff --git a/test/test_no_rtti.cpp b/test/test_no_rtti.cpp deleted file mode 100644 index 86db2b4..0000000 --- a/test/test_no_rtti.cpp +++ /dev/null @@ -1,172 +0,0 @@ -// nameof() c++11 test_no_rtti -// -// Licensed under the MIT License . -// Copyright (c) 2018 Daniil Goncharov . -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#if defined(__GXX_RTTI) || defined(_CPPRTTI) || defined(__RTTI) || defined(__INTEL_RTTI__) -#error "need test case with no rtti" -#endif - -#define CATCH_CONFIG_MAIN - -#include -#include -#include -#include -#include - -struct SomeStruct { - int SomeField; - void SomeMethod1() { std::cout << "No called!" << std::endl; } - int SomeMethod2() { - std::cout << "No called!" << std::endl; - return 1; - } -}; - -void SomeMethod3() { std::cout << "No called!" << std::endl; } - -struct Long { - struct LL { - int LLLField; - }; - LL LLField; -}; - -int someVar = 0; - -enum class Color { RED, GREEN, BLUE }; - -TEST_CASE("constexpr") { - SomeStruct someVar; - - SECTION("NAMEOF") { - constexpr auto n = NAMEOF(someVar); - REQUIRE(std::strcmp(n, "someVar") == 0); - } - - SECTION("NAMEOF_FULL") { - constexpr auto n = NAMEOF_FULL((&someVar)->SomeField); - REQUIRE(std::strcmp(n, "(&someVar)->SomeField") == 0); - } - - SECTION("NAMEOF_TYPE") { - constexpr auto n = NAMEOF_TYPE(std::string); - REQUIRE(std::strcmp(n, "string") == 0); - } - - SECTION("NAMEOF_TYPE_FULL") { - constexpr auto n = NAMEOF_TYPE_FULL(std::string); - REQUIRE(std::strcmp(n, "std::string") == 0); - } -} - -TEST_CASE("NAMEOF") { - SomeStruct someVar; - Long otherVar; - int intValue; - SomeStruct* ptrVar; - SomeStruct** ptrptrVar; - - SECTION("NAMEOF_VARIABLE") { - REQUIRE(std::strcmp(NAMEOF(someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(someVar.SomeField), "SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF((&someVar)->SomeField), "SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF(::someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(otherVar.LLField.LLLField), "LLLField") == 0); - REQUIRE(std::strcmp(NAMEOF(&someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF(ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(*ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(*ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(**ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF(+intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(-intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(~intValue), "intValue") == 0); - REQUIRE(std::strcmp(NAMEOF(!intValue), "intValue") == 0); - } - - SECTION("NAMEOF_TYPE") { - REQUIRE(std::strcmp(NAMEOF_TYPE(int[]), "int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE(int), "int") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE(const volatile int[]), "const volatile int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE(std::string), "string") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE(SomeStruct), "SomeStruct") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE(Long::LL), "LL") == 0); - } - - SECTION("NAMEOF_FUNCTION") { - REQUIRE(std::strcmp(NAMEOF(someVar.SomeMethod1()), "SomeMethod1()") == 0); - REQUIRE(std::strcmp(NAMEOF(&SomeStruct::SomeMethod2), "SomeMethod2") == 0); - REQUIRE(std::strcmp(NAMEOF(SomeMethod3), "SomeMethod3") == 0); - } - - SECTION("NAMEOF_ENUM") { - REQUIRE(std::strcmp(NAMEOF(Color::RED), "RED") == 0); - REQUIRE(std::strcmp(NAMEOF(Color::BLUE), "BLUE") == 0); - } -} - -TEST_CASE("NAMEOF_FULL") { - SomeStruct someVar; - Long otherVar; - int intValue; - SomeStruct* ptrVar; - SomeStruct** ptrptrVar; - - SECTION("NAMEOF_VARIABLE_FULL") { - REQUIRE(std::strcmp(NAMEOF_FULL(someVar), "someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(someVar.SomeField), "someVar.SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL((&someVar)->SomeField), "(&someVar)->SomeField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(::someVar), "::someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(otherVar.LLField.LLLField), "otherVar.LLField.LLLField") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(&someVar), "&someVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(ptrVar), "ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(*ptrVar), "*ptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(ptrptrVar), "ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(*ptrptrVar), "*ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(**ptrptrVar), "**ptrptrVar") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(+intValue), "+intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(-intValue), "-intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(~intValue), "~intValue") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(!intValue), "!intValue") == 0); - - } - - SECTION("NAMEOF_TYPE_FULL") { - REQUIRE(std::strcmp(NAMEOF_TYPE_FULL(int[]), "int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE_FULL(const volatile int[]), "const volatile int[]") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE_FULL(std::string), "std::string") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE_FULL(SomeStruct), "SomeStruct") == 0); - REQUIRE(std::strcmp(NAMEOF_TYPE_FULL(Long::LL), "Long::LL") == 0); - } - - SECTION("NAMEOF_FUNCTION_FULL") { - REQUIRE(std::strcmp(NAMEOF_FULL(someVar.SomeMethod1()), "someVar.SomeMethod1()") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(&SomeStruct::SomeMethod2), "&SomeStruct::SomeMethod2") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(SomeMethod3), "SomeMethod3") == 0); - } - - SECTION("NAMEOF_ENUM_FULL") { - REQUIRE(std::strcmp(NAMEOF_FULL(Color::RED), "Color::RED") == 0); - REQUIRE(std::strcmp(NAMEOF_FULL(Color::BLUE), "Color::BLUE") == 0); - } -}