X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-IntrusivePtr.cpp;h=9e838a7824cddd552172d1f806dab140ad090361;hb=e3df4b163e5570d4fdafdfe5380404a9027e7462;hp=3e9a40313d131b159367c8f40644f9317c2fa752;hpb=cc65bde541ab67726116d802dc87895e35032f41;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp b/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp index 3e9a403..9e838a7 100644 --- a/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp +++ b/automated-tests/src/dali/utc-Dali-IntrusivePtr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,24 +15,23 @@ * */ +#include +#include +#include #include -#include -#include -#include using namespace Dali; namespace { - const int REPEAT = 1000; -size_t g_creationCount = 0; -size_t g_destructionCount = 0; -size_t g_creationCountSubclass = 0; -size_t g_destructionCountSubclass = 0; -size_t g_creationCountUnrelated = 0; +size_t g_creationCount = 0; +size_t g_destructionCount = 0; +size_t g_creationCountSubclass = 0; +size_t g_destructionCountSubclass = 0; +size_t g_creationCountUnrelated = 0; size_t g_destructionCountUnrelated = 0; class Counted : public RefObject @@ -91,14 +90,13 @@ public: TestObject& Assign(const TestObject& testObject) { RefObject::operator=(testObject); - data = testObject.data; + data = testObject.data; return *this; } int data; }; - } // Anonymous namespace /** @@ -106,36 +104,36 @@ public: */ int UtcDaliIntrusivePtrIntrusivePtr(void) { - tet_infoline( "Testing Dali::IntrusivePtr::IntrusivePtr()" ); + tet_infoline("Testing Dali::IntrusivePtr::IntrusivePtr()"); g_creationCount = g_destructionCount = 0; IntrusivePtr counted; - DALI_TEST_EQUALS( g_creationCount, 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); // Test the pointer is null - DALI_TEST_EQUALS( counted.Get(), (Counted*) 0, TEST_LOCATION ); - DALI_TEST_EQUALS( &(*counted), (Counted*) 0, TEST_LOCATION ); + DALI_TEST_EQUALS(counted.Get(), (Counted*)0, TEST_LOCATION); + DALI_TEST_EQUALS(&(*counted), (Counted*)0, TEST_LOCATION); // Check destruction of the null smart pointer does nothing: counted = IntrusivePtr(); - DALI_TEST_EQUALS( g_creationCount, 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrIntrusivePtrTP(void) { - tet_infoline( "Testing Dali::IntrusivePtr::IntrusivePtr(T*)" ); + tet_infoline("Testing Dali::IntrusivePtr::IntrusivePtr(T*)"); g_creationCount = g_destructionCount = 0; - IntrusivePtr counted( new Counted ); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + IntrusivePtr counted(new Counted); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); counted = 0; - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 1u, TEST_LOCATION); END_TEST; } @@ -144,30 +142,30 @@ int UtcDaliIntrusivePtrIntrusivePtrTP(void) int UtcDaliIntrusivePtrIntrusivePtrIntrusivePtrUP(void) { - tet_infoline( "Testing Dali::IntrusivePtr::IntrusivePtr(IntrusivePtr const &)" ); + tet_infoline("Testing Dali::IntrusivePtr::IntrusivePtr(IntrusivePtr const &)"); g_creationCount = g_destructionCount = g_creationCountSubclass = g_destructionCountSubclass = 0; - IntrusivePtr countedSubclass( new CountedSubclass ); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_creationCountSubclass, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCountSubclass, 0u, TEST_LOCATION ); + IntrusivePtr countedSubclass(new CountedSubclass); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_creationCountSubclass, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCountSubclass, 0u, TEST_LOCATION); - IntrusivePtr counted( countedSubclass ); - DALI_TEST_EQUALS( counted->ReferenceCount(), 2, TEST_LOCATION ); + IntrusivePtr counted(countedSubclass); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2, TEST_LOCATION); // Make loads more references: - std::vector< IntrusivePtr > intrusivePtrs; - for( int i = 0; i < REPEAT; ++i ) + std::vector > intrusivePtrs; + for(int i = 0; i < REPEAT; ++i) { - intrusivePtrs.push_back( IntrusivePtr( countedSubclass ) ); + intrusivePtrs.push_back(IntrusivePtr(countedSubclass)); } - DALI_TEST_EQUALS( counted->ReferenceCount(), 2 + REPEAT, TEST_LOCATION ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2 + REPEAT, TEST_LOCATION); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_creationCountSubclass, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_creationCountSubclass, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); END_TEST; } @@ -177,312 +175,305 @@ int UtcDaliIntrusivePtrIntrusivePtrIntrusivePtrUP(void) int UtcDaliIntrusivePtrIntrusivePtrIntrusivePtrP(void) { - tet_infoline( "Testing Dali::IntrusivePtr::IntrusivePtr(IntrusivePtr const &)" ); + tet_infoline("Testing Dali::IntrusivePtr::IntrusivePtr(IntrusivePtr const &)"); // Pass a pointer to a constructed second object: // Pass a pointer to null: g_creationCount = g_destructionCount = 0; - IntrusivePtr counted( new Counted ); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); - DALI_TEST_EQUALS( counted->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr counted(new Counted); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(counted->ReferenceCount(), 1, TEST_LOCATION); - IntrusivePtr counted2( counted ); - DALI_TEST_EQUALS( counted->ReferenceCount(), 2, TEST_LOCATION ); - DALI_TEST_EQUALS( counted.Get(), counted2.Get(), TEST_LOCATION ); + IntrusivePtr counted2(counted); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2, TEST_LOCATION); + DALI_TEST_EQUALS(counted.Get(), counted2.Get(), TEST_LOCATION); // Make loads more references: - std::vector< IntrusivePtr > intrusivePtrs; - for( int i = 0; i < REPEAT; ++i ) + std::vector > intrusivePtrs; + for(int i = 0; i < REPEAT; ++i) { - intrusivePtrs.push_back( IntrusivePtr( counted ) ); + intrusivePtrs.push_back(IntrusivePtr(counted)); } - DALI_TEST_EQUALS( counted->ReferenceCount(), 2 + REPEAT, TEST_LOCATION ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2 + REPEAT, TEST_LOCATION); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); intrusivePtrs.clear(); - DALI_TEST_EQUALS( counted->ReferenceCount(), 2, TEST_LOCATION ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2, TEST_LOCATION); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 0u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); counted.Reset(); - DALI_TEST_EQUALS( counted2->ReferenceCount(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS(counted2->ReferenceCount(), 1, TEST_LOCATION); counted2.Reset(); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 1u, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrGetP(void) { - tet_infoline( "Testing Dali::IntrusivePtr::Get()" ); + tet_infoline("Testing Dali::IntrusivePtr::Get()"); - IntrusivePtr counted( new Counted ); - DALI_TEST_CHECK( counted.Get() != 0 ); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( counted->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr counted(new Counted); + DALI_TEST_CHECK(counted.Get() != 0); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(counted->ReferenceCount(), 1, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrGetN(void) { - tet_infoline( "Testing Dali::IntrusivePtr::Get()" ); + tet_infoline("Testing Dali::IntrusivePtr::Get()"); g_creationCount = 0; - IntrusivePtr counted( 0 ); - DALI_TEST_CHECK( counted.Get() == 0 ); - DALI_TEST_EQUALS( g_creationCount, 0u, TEST_LOCATION ); + IntrusivePtr counted(0); + DALI_TEST_CHECK(counted.Get() == 0); + DALI_TEST_EQUALS(g_creationCount, 0u, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrArrowOperatorP(void) { - tet_infoline( "Positive Test for Dali::IntrusivePtr::operator->()" ); + tet_infoline("Positive Test for Dali::IntrusivePtr::operator->()"); - IntrusivePtr counted( new Counted ); - DALI_TEST_CHECK( (counted.operator->()) != 0 ); - DALI_TEST_EQUALS( counted->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr counted(new Counted); + DALI_TEST_CHECK((counted.operator->()) != 0); + DALI_TEST_EQUALS(counted->ReferenceCount(), 1, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrArrowOperatorN(void) { - tet_infoline( "Negative Test for Dali::IntrusivePtr::operator->()" ); + tet_infoline("Negative Test for Dali::IntrusivePtr::operator->()"); IntrusivePtr counted; - DALI_TEST_CHECK( (counted.operator->()) == 0 ); + DALI_TEST_CHECK((counted.operator->()) == 0); END_TEST; } int UtcDaliIntrusivePtrIndirectionOperatorP(void) { - tet_infoline( "Positive Test for Dali::IntrusivePtr::operator*()" ); + tet_infoline("Positive Test for Dali::IntrusivePtr::operator*()"); - IntrusivePtr counted( new Counted ); - DALI_TEST_CHECK( &(counted.operator*()) != 0 ); - DALI_TEST_EQUALS( (*counted).ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr counted(new Counted); + DALI_TEST_CHECK(&(counted.operator*()) != 0); + DALI_TEST_EQUALS((*counted).ReferenceCount(), 1, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrIndirectionOperatorN(void) { - tet_infoline( "Negative Test for Dali::IntrusivePtr::operator*()" ); + tet_infoline("Negative Test for Dali::IntrusivePtr::operator*()"); IntrusivePtr counted; - DALI_TEST_CHECK( &(counted.operator*()) == 0 ); + DALI_TEST_CHECK(&(counted.operator*()) == 0); END_TEST; } int UtcDaliIntrusivePtrResetP(void) { - tet_infoline( "Positive Test for Dali::IntrusivePtr::Reset()" ); + tet_infoline("Positive Test for Dali::IntrusivePtr::Reset()"); - IntrusivePtr counted( new Counted ); - DALI_TEST_CHECK( counted.Get() != 0 ); + IntrusivePtr counted(new Counted); + DALI_TEST_CHECK(counted.Get() != 0); counted.Reset(); - DALI_TEST_CHECK( counted.Get() == 0 ); + DALI_TEST_CHECK(counted.Get() == 0); END_TEST; } int UtcDaliIntrusivePtrResetN(void) { - tet_infoline( "Negative Test for Dali::IntrusivePtr::Reset()" ); + tet_infoline("Negative Test for Dali::IntrusivePtr::Reset()"); IntrusivePtr counted; - Counted* firstGet = counted.Get(); + Counted* firstGet = counted.Get(); counted.Reset(); - DALI_TEST_EQUALS( counted.Get(), firstGet, TEST_LOCATION ); + DALI_TEST_EQUALS(counted.Get(), firstGet, TEST_LOCATION); END_TEST; } int UtcDaliIntrusivePtrResetTP(void) { - tet_infoline( "Positive Test for Dali::IntrusivePtr::Reset(T*)" ); + tet_infoline("Positive Test for Dali::IntrusivePtr::Reset(T*)"); g_creationCount = g_destructionCount = 0; - IntrusivePtr counted( new Counted ); + IntrusivePtr counted(new Counted); - IntrusivePtr counted2( new Counted ); + IntrusivePtr counted2(new Counted); - DALI_TEST_EQUALS( counted->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( counted2->ReferenceCount(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(counted2->ReferenceCount(), 1, TEST_LOCATION); - counted.Reset( counted2.Get() ); + counted.Reset(counted2.Get()); - DALI_TEST_EQUALS( counted->ReferenceCount(), 2, TEST_LOCATION ); - DALI_TEST_EQUALS( counted2->ReferenceCount(), 2, TEST_LOCATION ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2, TEST_LOCATION); + DALI_TEST_EQUALS(counted2->ReferenceCount(), 2, TEST_LOCATION); - DALI_TEST_EQUALS( counted.Get(), counted2.Get(), TEST_LOCATION ); + DALI_TEST_EQUALS(counted.Get(), counted2.Get(), TEST_LOCATION); - DALI_TEST_EQUALS( g_creationCount, 2u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_creationCount, 2u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 1u, TEST_LOCATION); - counted2.Reset( (Counted*) 0 ); - counted.Reset( counted2.Get() ); - DALI_TEST_EQUALS( g_destructionCount, 2u, TEST_LOCATION ); + counted2.Reset((Counted*)0); + counted.Reset(counted2.Get()); + DALI_TEST_EQUALS(g_destructionCount, 2u, TEST_LOCATION); // Check that reseting nulls is harmless: - counted2.Reset( counted.Get() ); - counted.Reset( counted2.Get() ); + counted2.Reset(counted.Get()); + counted.Reset(counted2.Get()); - DALI_TEST_EQUALS( g_destructionCount, 2u, TEST_LOCATION ); + DALI_TEST_EQUALS(g_destructionCount, 2u, TEST_LOCATION); END_TEST; } - int UtcDaliIntrusivePtrResetTN(void) { - tet_infoline( "Negative Test for Dali::IntrusivePtr::Reset(T*)" ); + tet_infoline("Negative Test for Dali::IntrusivePtr::Reset(T*)"); g_creationCount = g_destructionCount = 0; - IntrusivePtr counted( new Counted ); + IntrusivePtr counted(new Counted); - counted.Reset( (Counted*) 0 ); + counted.Reset((Counted*)0); - DALI_TEST_EQUALS( counted.Get(), (Counted*) 0, TEST_LOCATION ); - DALI_TEST_EQUALS( g_creationCount, 1u, TEST_LOCATION ); - DALI_TEST_EQUALS( g_destructionCount, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS(counted.Get(), (Counted*)0, TEST_LOCATION); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 1u, TEST_LOCATION); END_TEST; } - - -int UtcDaliIntrusivePtrOperatorBooleanTypeP(void) +int UtcDaliIntrusivePtrOperatorBoolP(void) { - tet_infoline( "Positive Test for Dali::IntrusivePtr::operator Booleantype()" ); + tet_infoline("Positive Test for Dali::IntrusivePtr::operator bool()"); - IntrusivePtr counted( new Counted ); - DALI_TEST_CHECK( counted.operator BooleanType() != 0 ); - DALI_TEST_CHECK( counted ); - - typedef void (IntrusivePtr::*BoolIdiomFunc)() const; - BoolIdiomFunc func = static_cast( counted.operator BooleanType() ); - ((counted).*func)(); // purely for test coverage + IntrusivePtr counted(new Counted); + DALI_TEST_CHECK(counted.operator bool() == true); + DALI_TEST_CHECK(counted); counted.Reset(); - DALI_TEST_CHECK( counted.operator BooleanType() == 0 ); + DALI_TEST_CHECK(counted.operator bool() == false); END_TEST; } -int UtcDaliIntrusivePtrOperatorBooleanTypeN(void) +int UtcDaliIntrusivePtrOperatorBoolN(void) { - tet_infoline( "Negative Test for Dali::IntrusivePtr::operator Booleantype()" ); + tet_infoline("Negative Test for Dali::IntrusivePtr::operator bool()"); IntrusivePtr counted; - DALI_TEST_CHECK( counted.operator BooleanType() == 0 ); - DALI_TEST_CHECK( !counted ); + DALI_TEST_CHECK(counted.operator bool() == false); + DALI_TEST_CHECK(!counted); END_TEST; } /** Equality of two different types*/ int UtcDaliIntrusivePtrOperatorEqualTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator ==(T, U)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator ==(T, U)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator==( counted1, countedSubclass1 ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( operator==( counted2, countedSubclass2 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(operator==(counted1, countedSubclass1), false, TEST_LOCATION); + DALI_TEST_EQUALS(operator==(counted2, countedSubclass2), true, TEST_LOCATION); END_TEST; } /** Inequality of two different types*/ int UtcDaliIntrusivePtrOperatorNotEqualTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator !=(T, U)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator !=(T, U)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator!=( counted1, countedSubclass1 ), true, TEST_LOCATION ); - DALI_TEST_EQUALS( operator!=( counted2, countedSubclass2 ), false, TEST_LOCATION ); + DALI_TEST_EQUALS(operator!=(counted1, countedSubclass1), true, TEST_LOCATION); + DALI_TEST_EQUALS(operator!=(counted2, countedSubclass2), false, TEST_LOCATION); END_TEST; } /** Equality of two different types where right hand side is a raw pointer */ int UtcDaliIntrusivePtrOperatorEqualRightPointerTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator ==(T, U*)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator ==(T, U*)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator==( counted1, countedSubclass1.Get() ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( operator==( counted2, countedSubclass2.Get() ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(operator==(counted1, countedSubclass1.Get()), false, TEST_LOCATION); + DALI_TEST_EQUALS(operator==(counted2, countedSubclass2.Get()), true, TEST_LOCATION); END_TEST; } /** Inequality of two different types where the right hand side is a raw pointer */ int UtcDaliIntrusivePtrOperatorNotEqualRightPointerTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator !=(T, U*)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator !=(T, U*)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator!=( counted1, countedSubclass1.Get() ), true, TEST_LOCATION ); - DALI_TEST_EQUALS( operator!=( counted2, countedSubclass2.Get() ), false, TEST_LOCATION ); + DALI_TEST_EQUALS(operator!=(counted1, countedSubclass1.Get()), true, TEST_LOCATION); + DALI_TEST_EQUALS(operator!=(counted2, countedSubclass2.Get()), false, TEST_LOCATION); END_TEST; } /** Equality of two different types where left hand side is a raw pointer */ int UtcDaliIntrusivePtrOperatorEqualLeftPointerTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator ==(T*, U)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator ==(T*, U)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator==( counted1.Get(), countedSubclass1 ), false, TEST_LOCATION ); - DALI_TEST_EQUALS( operator==( counted2.Get(), countedSubclass2 ), true, TEST_LOCATION ); + DALI_TEST_EQUALS(operator==(counted1.Get(), countedSubclass1), false, TEST_LOCATION); + DALI_TEST_EQUALS(operator==(counted2.Get(), countedSubclass2), true, TEST_LOCATION); END_TEST; } /** Inequality of two different types where the left hand side is a raw pointer */ int UtcDaliIntrusivePtrOperatorNotEqualLeftPointerTU(void) { - tet_infoline( "Test for Dali::IntrusivePtr::operator !=(T*, U)" ); + tet_infoline("Test for Dali::IntrusivePtr::operator !=(T*, U)"); - IntrusivePtr counted1( new Counted ); - IntrusivePtr countedSubclass1( new CountedSubclass ); - IntrusivePtr countedSubclass2( new CountedSubclass ); - IntrusivePtr counted2( countedSubclass2 ); + IntrusivePtr counted1(new Counted); + IntrusivePtr countedSubclass1(new CountedSubclass); + IntrusivePtr countedSubclass2(new CountedSubclass); + IntrusivePtr counted2(countedSubclass2); - DALI_TEST_EQUALS( operator!=( counted1.Get(), countedSubclass1 ), true, TEST_LOCATION ); - DALI_TEST_EQUALS( operator!=( counted2.Get(), countedSubclass2 ), false, TEST_LOCATION ); + DALI_TEST_EQUALS(operator!=(counted1.Get(), countedSubclass1), true, TEST_LOCATION); + DALI_TEST_EQUALS(operator!=(counted2.Get(), countedSubclass2), false, TEST_LOCATION); END_TEST; } @@ -491,102 +482,153 @@ int UtcDaliRefObjectCopyConstructor(void) tet_infoline("Test for Dali::RefObject(const RefObject&)"); { - IntrusivePtr testPtr( new TestObject ); - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr testPtr(new TestObject); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); - const TestObject& testObject=*testPtr.Get(); + const TestObject& testObject = *testPtr.Get(); { - IntrusivePtr testPtr2( new TestObject(testObject) ); - DALI_TEST_EQUALS( testPtr2->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr testPtr2(new TestObject(testObject)); + DALI_TEST_EQUALS(testPtr2->ReferenceCount(), 1, TEST_LOCATION); } - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); } END_TEST; } - int UtcDaliRefObjectAssignmentOperator(void) { tet_infoline("Test for Dali::RefObject::operator=(const RefObject&)"); { - IntrusivePtr testPtr( new TestObject ); - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr testPtr(new TestObject); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); - const TestObject& testObject=*testPtr.Get(); + const TestObject& testObject = *testPtr.Get(); { - IntrusivePtr testPtr2( new TestObject() ); - testPtr->data = 33; + IntrusivePtr testPtr2(new TestObject()); + testPtr->data = 33; IntrusivePtr testPtr3 = testPtr2; - DALI_TEST_EQUALS( testPtr2->ReferenceCount(), 2, TEST_LOCATION ); - DALI_TEST_EQUALS( testPtr2->data, 201, TEST_LOCATION ); + DALI_TEST_EQUALS(testPtr2->ReferenceCount(), 2, TEST_LOCATION); + DALI_TEST_EQUALS(testPtr2->data, 201, TEST_LOCATION); TestObject& testObject2 = *testPtr2.Get(); - testObject2 = testObject; + testObject2 = testObject; - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( testPtr2->ReferenceCount(), 2, TEST_LOCATION ); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(testPtr2->ReferenceCount(), 2, TEST_LOCATION); } - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); } + END_TEST; } -int UtcDaliIntrusivePtrMoveConstructor(void) +int UtcDaliRefObjectAssignmentOperatorToNull(void) { - IntrusivePtr testPtr( new TestObject ); - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( testPtr->data, 201, TEST_LOCATION ); + tet_infoline("Testing Dali::IntrusivePtr = nullptr"); + + g_creationCount = g_destructionCount = 0; - IntrusivePtr movePtr = std::move( testPtr ); - DALI_TEST_EQUALS( movePtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( movePtr->data, 201, TEST_LOCATION ); - DALI_TEST_CHECK( !testPtr ); + IntrusivePtr counted(new Counted); - IntrusivePtr anotherTestPtr( new TestObject ); - DALI_TEST_EQUALS( anotherTestPtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( anotherTestPtr->data, 201, TEST_LOCATION ); - IntrusivePtr anotherMovePtr = std::move( anotherTestPtr ); - DALI_TEST_EQUALS( anotherMovePtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( anotherMovePtr->data, 201, TEST_LOCATION ); - DALI_TEST_CHECK( !anotherTestPtr.Get() ); + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); - IntrusivePtr countedSubclass( new CountedSubclass ); - DALI_TEST_EQUALS( countedSubclass->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr counted2 = counted; + DALI_TEST_EQUALS(g_creationCount, 1u, TEST_LOCATION); + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); - IntrusivePtr countedMovePtr = std::move( countedSubclass ); - DALI_TEST_EQUALS( countedMovePtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_CHECK( !countedSubclass ); + DALI_TEST_EQUALS(counted->ReferenceCount(), 2, TEST_LOCATION); + + counted2 = nullptr; + DALI_TEST_EQUALS(g_destructionCount, 0u, TEST_LOCATION); + DALI_TEST_EQUALS(counted->ReferenceCount(), 1, TEST_LOCATION); + + counted = nullptr; + DALI_TEST_EQUALS(g_destructionCount, 1u, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliIntrusivePtrMoveConstructor(void) +{ + IntrusivePtr testPtr(new TestObject); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(testPtr->data, 201, TEST_LOCATION); + + IntrusivePtr movePtr = std::move(testPtr); + DALI_TEST_EQUALS(movePtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(movePtr->data, 201, TEST_LOCATION); + DALI_TEST_CHECK(!testPtr); + + IntrusivePtr anotherTestPtr(new TestObject); + DALI_TEST_EQUALS(anotherTestPtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(anotherTestPtr->data, 201, TEST_LOCATION); + IntrusivePtr anotherMovePtr = std::move(anotherTestPtr); + DALI_TEST_EQUALS(anotherMovePtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(anotherMovePtr->data, 201, TEST_LOCATION); + DALI_TEST_CHECK(!anotherTestPtr.Get()); + + IntrusivePtr countedSubclass(new CountedSubclass); + DALI_TEST_EQUALS(countedSubclass->ReferenceCount(), 1, TEST_LOCATION); + + IntrusivePtr countedMovePtr = std::move(countedSubclass); + DALI_TEST_EQUALS(countedMovePtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_CHECK(!countedSubclass); END_TEST; } int UtcDaliIntrusivePtrMoveAssignment(void) { - IntrusivePtr testPtr( new TestObject ); - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( testPtr->data, 201, TEST_LOCATION ); + IntrusivePtr testPtr(new TestObject); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(testPtr->data, 201, TEST_LOCATION); - IntrusivePtr secondPtr( testPtr ); - DALI_TEST_EQUALS( testPtr->ReferenceCount(), 2, TEST_LOCATION ); + IntrusivePtr secondPtr(testPtr); + DALI_TEST_EQUALS(testPtr->ReferenceCount(), 2, TEST_LOCATION); IntrusivePtr thirdPtr; - testPtr = std::move( thirdPtr ); - DALI_TEST_EQUALS( secondPtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_EQUALS( secondPtr->data, 201, TEST_LOCATION ); - DALI_TEST_CHECK( !testPtr.Get() ); + testPtr = std::move(thirdPtr); + DALI_TEST_EQUALS(secondPtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(secondPtr->data, 201, TEST_LOCATION); + DALI_TEST_CHECK(!testPtr.Get()); - IntrusivePtr fourthPtr( new TestObject ); - testPtr = std::move( fourthPtr ); - DALI_TEST_CHECK( !fourthPtr.Get() ); + IntrusivePtr fourthPtr(new TestObject); + testPtr = std::move(fourthPtr); + DALI_TEST_CHECK(!fourthPtr.Get()); - IntrusivePtr countedSubclassPtr( new CountedSubclass ); - DALI_TEST_EQUALS( countedSubclassPtr->ReferenceCount(), 1, TEST_LOCATION ); + IntrusivePtr countedSubclassPtr(new CountedSubclass); + DALI_TEST_EQUALS(countedSubclassPtr->ReferenceCount(), 1, TEST_LOCATION); IntrusivePtr countedMovePtr; - countedMovePtr = std::move( countedSubclassPtr ); - DALI_TEST_EQUALS( countedMovePtr->ReferenceCount(), 1, TEST_LOCATION ); - DALI_TEST_CHECK( !countedSubclassPtr ); + countedMovePtr = std::move(countedSubclassPtr); + DALI_TEST_EQUALS(countedMovePtr->ReferenceCount(), 1, TEST_LOCATION); + DALI_TEST_CHECK(!countedSubclassPtr); + + END_TEST; +} + +/** Equality with nullptr */ +int UtcDaliIntrusivePtrOperatorEqualWithNullptr(void) +{ + tet_infoline("Test for Dali::IntrusivePtr::operator == nullptr"); + + IntrusivePtr counted1(new Counted); + + // counted1 is not nullptr. + DALI_TEST_CHECK(!(counted1 == nullptr)); + DALI_TEST_CHECK(!(nullptr == counted1)); + DALI_TEST_CHECK(counted1 != nullptr); + DALI_TEST_CHECK(nullptr != counted1); + + counted1 = nullptr; + + // counted1 is nullptr. + DALI_TEST_CHECK(counted1 == nullptr); + DALI_TEST_CHECK(nullptr == counted1); + DALI_TEST_CHECK(!(counted1 != nullptr)); + DALI_TEST_CHECK(!(nullptr != counted1)); END_TEST; }