From e9d56f8c73bccaf2b5292c30d145118e6d275594 Mon Sep 17 00:00:00 2001 From: Omar Duran Date: Tue, 26 Nov 2024 17:47:32 -0800 Subject: [PATCH] style: linter testRTTypes.cpp --- .../codingUtilities/tests/testRTTypes.cpp | 165 ++++++++++-------- 1 file changed, 88 insertions(+), 77 deletions(-) diff --git a/src/coreComponents/codingUtilities/tests/testRTTypes.cpp b/src/coreComponents/codingUtilities/tests/testRTTypes.cpp index 8dbdb251c9..bf7aef678f 100644 --- a/src/coreComponents/codingUtilities/tests/testRTTypes.cpp +++ b/src/coreComponents/codingUtilities/tests/testRTTypes.cpp @@ -17,56 +17,64 @@ #include "dataRepository/Group.hpp" #include "dataRepository/Wrapper.hpp" -// TPL includes #include + +// TPL includes #include using namespace geos; using namespace dataRepository; // Mock classes to test dynamic casting -class Base { +class Base +{ public: - virtual ~Base() = default; // Needed for RTTI + virtual ~Base() = default; // Needed for RTTI }; -class Derived final : public Base { +class Derived final : public Base +{ public: - void show() { - std::cout << "Derived class method." << std::endl; - } + void show() + { + std::cout << "Derived class method." << std::endl; + } }; // Test for dynamicCast with pointer -TEST(DynamicCastTests, Pointer_Casting_Success) { - Base* base = new Derived(); - Derived* derived = geos::dynamicCast(base); - ASSERT_NE(derived, nullptr) << "Expected successful cast from Base to Derived."; - delete base; // Clean up allocated memory +TEST( DynamicCastTests, Pointer_Casting_Success ) +{ + Base * base = new Derived(); + Derived * derived = geos::dynamicCast< Derived * >( base ); + ASSERT_NE( derived, nullptr ) << "Expected successful cast from Base to Derived."; + delete base; // Clean up allocated memory } -TEST(DynamicCastTests, Pointer_Casting_Failure) { - Base* base = new Base(); - Derived* derived = geos::dynamicCast(base); - ASSERT_EQ(derived, nullptr) << "Expected nullptr due to failed cast from Base to Derived."; - delete base; // Clean up allocated memory +TEST( DynamicCastTests, Pointer_Casting_Failure ) +{ + Base * base = new Base(); + Derived * derived = geos::dynamicCast< Derived * >( base ); + ASSERT_EQ( derived, nullptr ) << "Expected nullptr due to failed cast from Base to Derived."; + delete base; // Clean up allocated memory } // Test for dynamicCast with reference -TEST(DynamicCastTests, Reference_Casting_Success) { - Derived derived; - Base& base_ref = derived; - Derived& derived_ref = geos::dynamicCast(base_ref); - ASSERT_EQ(&derived_ref, &derived) << "Expected successful cast from Base to Derived."; +TEST( DynamicCastTests, Reference_Casting_Success ) +{ + Derived derived; + Base & base_ref = derived; + Derived & derived_ref = geos::dynamicCast< Derived & >( base_ref ); + ASSERT_EQ( &derived_ref, &derived ) << "Expected successful cast from Base to Derived."; } -TEST(DynamicCastTests, Reference_Casting_Failure) { - Base base; - Base& base_ref = base; - - Base& derived_base_ref = geos::dynamicCast(base_ref); - ASSERT_EQ(&derived_base_ref, &base) << "Expected successful cast from Base to Base."; - +TEST( DynamicCastTests, Reference_Casting_Failure ) +{ + Base base; + Base & base_ref = base; + + Base & derived_base_ref = geos::dynamicCast< Base & >( base_ref ); + ASSERT_EQ( &derived_base_ref, &base ) << "Expected successful cast from Base to Base."; + } @@ -85,40 +93,40 @@ class WrapperMock : public ::testing::Test void testDynamicCastWithPointer( ) { { - WrapperBase* base_pointer = &m_wrapperBase; - Wrapper< T >* derived = geos::dynamicCast*>(base_pointer); - ASSERT_NE(derived, nullptr) << "Expected successful cast from Base to Derived."; + WrapperBase * base_pointer = &m_wrapperBase; + Wrapper< T > * derived = geos::dynamicCast< Wrapper< T > * >( base_pointer ); + ASSERT_NE( derived, nullptr ) << "Expected successful cast from Base to Derived."; } - { - WrapperBase* base_pointer = &m_wrapperBase; - WrapperBase* derived = geos::dynamicCast(base_pointer); - ASSERT_NE(derived, nullptr) << "Expected successful cast from Base to Base."; - } { - Wrapper< T >* defived_pointer = &m_wrapper; - Wrapper< T >* derived = geos::dynamicCast*>(defived_pointer); - ASSERT_NE(derived, nullptr) << "Expected successful cast from Derived to Derived."; + WrapperBase * base_pointer = &m_wrapperBase; + WrapperBase * derived = geos::dynamicCast< WrapperBase * >( base_pointer ); + ASSERT_NE( derived, nullptr ) << "Expected successful cast from Base to Base."; + } + { + Wrapper< T > * defived_pointer = &m_wrapper; + Wrapper< T > * derived = geos::dynamicCast< Wrapper< T > * >( defived_pointer ); + ASSERT_NE( derived, nullptr ) << "Expected successful cast from Derived to Derived."; } } - -void testDynamicCastWithReference( ) -{ + + void testDynamicCastWithReference( ) { - WrapperBase& base_reference = m_wrapperBase; - Wrapper< T >& derived = geos::dynamicCast&>(base_reference); - ASSERT_EQ(&derived, &base_reference) << "Expected successful cast from Base to Derived."; - } { - WrapperBase& base_reference = m_wrapperBase; - WrapperBase& derived = geos::dynamicCast(base_reference); - ASSERT_EQ(&derived, &base_reference) << "Expected successful cast from Base to Base."; + WrapperBase & base_reference = m_wrapperBase; + Wrapper< T > & derived = geos::dynamicCast< Wrapper< T > & >( base_reference ); + ASSERT_EQ( &derived, &base_reference ) << "Expected successful cast from Base to Derived."; + } + { + WrapperBase & base_reference = m_wrapperBase; + WrapperBase & derived = geos::dynamicCast< WrapperBase & >( base_reference ); + ASSERT_EQ( &derived, &base_reference ) << "Expected successful cast from Base to Base."; + } + { + Wrapper< T > & defived_reference = m_wrapper; + Wrapper< T > & derived = geos::dynamicCast< Wrapper< T > & >( defived_reference ); + ASSERT_EQ( &derived, &defived_reference ) << "Expected successful cast from Derived to Derived."; } - { - Wrapper< T >& defived_reference = m_wrapper; - Wrapper< T >& derived = geos::dynamicCast&>(defived_reference); - ASSERT_EQ(&derived, &defived_reference) << "Expected successful cast from Derived to Derived."; } -} private: @@ -142,33 +150,36 @@ TYPED_TEST( WrapperMock, DynamicCastWithReference ) } // Test Regex constructor -TEST(RegexTests, Constructor) { - geos::Regex regex("^[0-9]+$", "Input must be a number."); - ASSERT_EQ(regex.m_regexStr, "^[0-9]+$") << "Regex string is incorrect."; - ASSERT_EQ(regex.m_formatDescription, "Input must be a number.") << "Format description is incorrect."; +TEST( RegexTests, Constructor ) +{ + geos::Regex regex( "^[0-9]+$", "Input must be a number." ); + ASSERT_EQ( regex.m_regexStr, "^[0-9]+$" ) << "Regex string is incorrect."; + ASSERT_EQ( regex.m_formatDescription, "Input must be a number." ) << "Format description is incorrect."; } -TEST(RtTypesTests, GetTypeName) { - { - std::type_index typeIndex(typeid(Base)); - auto typeName = geos::rtTypes::getTypeName(typeIndex); - EXPECT_EQ(typeName, std::string("Base")); // Expected Base - } - { - std::type_index typeIndex(typeid(Derived)); - auto typeName = geos::rtTypes::getTypeName(typeIndex); - EXPECT_EQ(typeName, std::string("Derived")); // Expected Derived - } +TEST( RtTypesTests, GetTypeName ) +{ + { + std::type_index typeIndex( typeid(Base)); + auto typeName = geos::rtTypes::getTypeName( typeIndex ); + EXPECT_EQ( typeName, std::string( "Base" )); // Expected Base + } + { + std::type_index typeIndex( typeid(Derived)); + auto typeName = geos::rtTypes::getTypeName( typeIndex ); + EXPECT_EQ( typeName, std::string( "Derived" )); // Expected Derived + } } // Additional tests to validate the functionality of getTypeRegex -TEST(RtTypesTests, GetTypeRegex_Default) { - geos::Regex regex = geos::rtTypes::getTypeRegex(); // Assuming int has a default regex defined - ASSERT_NE(regex.m_regexStr.empty(), true) << "Expected non-empty regex for int."; +TEST( RtTypesTests, GetTypeRegex_Default ) +{ + geos::Regex regex = geos::rtTypes::getTypeRegex< int >(); // Assuming int has a default regex defined + ASSERT_NE( regex.m_regexStr.empty(), true ) << "Expected non-empty regex for int."; } -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main( int argc, char * *argv ) +{ + testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS(); } -