/////////////////////////////////////////////////////////////////////////////// // Unit Test for Loki // // Copyright Terje Slettebų and Pavel Vozenilek 2002. // // Permission to use, copy, modify, and distribute this software for any // purpose is hereby granted without fee, provided that this copyright and // permissions notice appear in all copies and derivatives. // // This software is provided "as is" without express or implied warranty. // // Last update: September 16, 2002 /////////////////////////////////////////////////////////////////////////////// #ifndef SMARTPTRTEST_H #define SMARTPTRTEST_H #include "UnitTest.h" #include using namespace Loki; /////////////////////////////////////////////////////////////////////////////// // SmartPtrTest /////////////////////////////////////////////////////////////////////////////// class TestClass { public: TestClass() : references(1) { ++instances; } ~TestClass() { --instances; } void AddRef() { ++references; } void Release() { --references; if (references <= 0) delete this; } TestClass* Clone() { return new TestClass(*this); } public: static int instances; int references; }; int TestClass::instances = 0; class SmartPtrTest : public Test { public: SmartPtrTest() : Test("SmartPtr.h") {} virtual void execute(TestResult &result) { printName(result); using namespace Loki; { SmartPtr p = new TestClass; } bool test1=TestClass::instances == 0; { p0 p(new TestClass); } { p1 p(new TestClass); } { p2 p(new TestClass); p2 pp(p); } { p3 p(new TestClass); } { p4 p(new TestClass); } { p5 p(new TestClass); } { p6 p(new TestClass); } { p7 p(new TestClass); } { p8 p(new TestClass); } { p9 p(new TestClass); } { p10 p(new TestClass); } { p11 p(new TestClass); } { p12 p(new TestClass); } { p13 p(new TestClass); } { p14 p(new TestClass); } { p15 p(new TestClass); } { p16 p(new TestClass); } { p17 p(new TestClass); } { p18 p(new TestClass); } { p19 p(new TestClass); } { p20 p(new TestClass); } { p21 p(new TestClass); } { p22 p(new TestClass); } { p23 p(new TestClass); } { p24 p(new TestClass); } { p25 p(new TestClass); } { p26 p(new TestClass); } { p27 p(new TestClass); } { p28 p(new TestClass); } { p29 p(new TestClass); } { p30 p(new TestClass); } { p31 p(new TestClass); } { p40 p(new TestClass); } { p41 p(new TestClass); } { p42 p(new TestClass); } { p43 p(new TestClass); } { p44 p(new TestClass); } { p45 p(new TestClass); } { p46 p(new TestClass); } { p47 p(new TestClass); } { p48 p(new TestClass); } { p49 p(new TestClass); } { p50 p(new TestClass); } { p51 p(new TestClass); } { p52 p(new TestClass); } { p53 p(new TestClass); } { p54 p(new TestClass); } { p55 p(new TestClass); } { p56 p(new TestClass); } { p57 p(new TestClass); } { p58 p(new TestClass); } { p59 p(new TestClass); } { p60 p(new TestClass); } { p61 p(new TestClass); } { p62 p(new TestClass); } { p63 p(new TestClass); } { p64 p(new TestClass); } { p65 p(new TestClass); } { p66 p(new TestClass); } { p67 p(new TestClass); } { p68 p(new TestClass); } { p69 p(new TestClass); } { p70 p(new TestClass); } { p71 p(new TestClass); } { p72 p(new TestClass); } { p73 p(new TestClass); } { p74 p(new TestClass); } { p75 p(new TestClass); } { p76 p(new TestClass); } { p77 p(new TestClass); } { p78 p(new TestClass); } { p79 p(new TestClass); } { p80 p(new TestClass); } { p81 p(new TestClass); } { p82 p(new TestClass); } { p83 p(new TestClass); } { p84 p(new TestClass); } { p85 p(new TestClass); } { p86 p(new TestClass); } { p87 p(new TestClass); } { p88 p(new TestClass); } { p89 p(new TestClass); } { p90 p(new TestClass); } { p91 p(new TestClass); } { p92 p(new TestClass); } { p93 p(new TestClass); } { p94 p(new TestClass); } { p95 p(new TestClass); } { p96 p(new TestClass); } { p97 p(new TestClass); } { p98 p(new TestClass); } { p99 p(new TestClass); } { p100 p(new TestClass); } { p101 p(new TestClass); } { p102 p(new TestClass); } { p103 p(new TestClass); } bool test2=TestClass::instances==0; bool r=test1 && test2; testAssert("SmartPtr",r,result); std::cout << '\n'; } private: typedef SmartPtr p0; typedef SmartPtr p1; typedef SmartPtr::RefCountedMT, DisallowConversion, AssertCheck, DefaultSPStorage> p2; typedef SmartPtr p3; typedef SmartPtr p4; typedef SmartPtr p5; typedef SmartPtr p6; typedef SmartPtr p7; typedef SmartPtr p8; typedef SmartPtr p9; typedef SmartPtr::RefCountedMT, AllowConversion, AssertCheck, DefaultSPStorage> p10; typedef SmartPtr p11; typedef SmartPtr p12; typedef SmartPtr p13; typedef SmartPtr p14; typedef SmartPtr p15; typedef SmartPtr p16; typedef SmartPtr p17; typedef SmartPtr::RefCountedMT, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p18; typedef SmartPtr p19; typedef SmartPtr p20; typedef SmartPtr p21; typedef SmartPtr p22; typedef SmartPtr p23; typedef SmartPtr p24; typedef SmartPtr p25; typedef SmartPtr::RefCountedMT, AllowConversion, AssertCheckStrict, DefaultSPStorage> p26; typedef SmartPtr p27; typedef SmartPtr p28; typedef SmartPtr p29; typedef SmartPtr p30; typedef SmartPtr p31; typedef SmartPtr p40; typedef SmartPtr p41; typedef SmartPtr::RefCountedMT, AllowConversion, RejectNullStatic, DefaultSPStorage> p42; typedef SmartPtr p43; typedef SmartPtr p44; typedef SmartPtr p45; typedef SmartPtr p46; typedef SmartPtr p47; typedef SmartPtr p48; typedef SmartPtr p49; typedef SmartPtr::RefCountedMT, DisallowConversion, RejectNullStatic, DefaultSPStorage> p50; typedef SmartPtr p51; typedef SmartPtr p52; typedef SmartPtr p53; typedef SmartPtr p54; typedef SmartPtr p55; typedef SmartPtr p56; typedef SmartPtr p57; typedef SmartPtr::RefCountedMT, AllowConversion, RejectNull, DefaultSPStorage> p58; typedef SmartPtr p59; typedef SmartPtr p60; typedef SmartPtr p61; typedef SmartPtr p62; typedef SmartPtr p63; typedef SmartPtr p64; typedef SmartPtr p65; typedef SmartPtr::RefCountedMT, DisallowConversion, RejectNull, DefaultSPStorage> p66; typedef SmartPtr p67; typedef SmartPtr p68; typedef SmartPtr p69; typedef SmartPtr p70; typedef SmartPtr p71; typedef SmartPtr p72; typedef SmartPtr p73; typedef SmartPtr::RefCountedMT, AllowConversion, RejectNullStrict, DefaultSPStorage> p74; typedef SmartPtr p75; typedef SmartPtr p76; typedef SmartPtr p77; typedef SmartPtr p78; typedef SmartPtr p79; typedef SmartPtr p80; typedef SmartPtr p81; typedef SmartPtr::RefCountedMT, DisallowConversion, RejectNullStrict, DefaultSPStorage> p82; typedef SmartPtr p83; typedef SmartPtr p84; typedef SmartPtr p85; typedef SmartPtr p86; typedef SmartPtr p87; typedef SmartPtr p88; typedef SmartPtr p89; typedef SmartPtr::RefCountedMT, AllowConversion, NoCheck, DefaultSPStorage> p90; typedef SmartPtr p91; typedef SmartPtr p92; typedef SmartPtr p93; typedef SmartPtr p94; typedef SmartPtr p95; typedef SmartPtr p96; typedef SmartPtr p97; typedef SmartPtr::RefCountedMT, DisallowConversion, NoCheck, DefaultSPStorage> p98; typedef SmartPtr p99; typedef SmartPtr p100; typedef SmartPtr p101; typedef SmartPtr p102; typedef SmartPtr p103; } smartPtrTest; #ifndef SMARTPTR_CPP # define SMARTPTR_CPP # include "../../src/SmartPtr.cpp" #endif #endif