Skip to content

Commit

Permalink
style: linter testRTTypes.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarDuran committed Nov 27, 2024
1 parent 3460daf commit e9d56f8
Showing 1 changed file with 88 additions and 77 deletions.
165 changes: 88 additions & 77 deletions src/coreComponents/codingUtilities/tests/testRTTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,64 @@
#include "dataRepository/Group.hpp"
#include "dataRepository/Wrapper.hpp"

// TPL includes
#include <gtest/gtest.h>

// TPL includes
#include <conduit.hpp>

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<Derived*>(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<Derived*>(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<Derived&>(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&>(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.";

}


Expand All @@ -85,40 +93,40 @@ class WrapperMock : public ::testing::Test
void testDynamicCastWithPointer( )
{
{
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;
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<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.";
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<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.";
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<Wrapper< T >&>(defived_reference);
ASSERT_EQ(&derived, &defived_reference) << "Expected successful cast from Derived to Derived.";
}
}


private:
Expand All @@ -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<int>(); // 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();
}

0 comments on commit e9d56f8

Please sign in to comment.