Home | History | Annotate | Download | only in unit
      1 #include <memory>
      2 
      3 #include "cppunit/cppunit_proxy.h"
      4 
      5 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
      6 using namespace std;
      7 #endif
      8 
      9 //
     10 // TestCase class
     11 //
     12 class MemoryTest : public CPPUNIT_NS::TestCase
     13 {
     14   CPPUNIT_TEST_SUITE(MemoryTest);
     15 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1310)
     16   CPPUNIT_IGNORE;
     17 #endif
     18   CPPUNIT_TEST(auto_ptr_test);
     19   CPPUNIT_TEST_SUITE_END();
     20 
     21 protected:
     22   void auto_ptr_test();
     23 };
     24 
     25 CPPUNIT_TEST_SUITE_REGISTRATION(MemoryTest);
     26 
     27 #if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1310)
     28 auto_ptr<int> CreateAutoPtr(int val)
     29 { return auto_ptr<int>(new int(val)); }
     30 
     31 bool CheckEquality(auto_ptr<int> pint, int val)
     32 { return *pint == val; }
     33 #endif
     34 
     35 //
     36 // tests implementation
     37 //
     38 void MemoryTest::auto_ptr_test()
     39 {
     40 #if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1310)
     41   {
     42     auto_ptr<int> pint(new int(1));
     43     CPPUNIT_ASSERT( *pint == 1 );
     44     *pint = 2;
     45     CPPUNIT_ASSERT( *pint == 2 );
     46   }
     47 
     48   {
     49     auto_ptr<int> pint(CreateAutoPtr(3));
     50     CPPUNIT_ASSERT( *pint == 3 );
     51     CPPUNIT_ASSERT( CheckEquality(pint, 3) );
     52   }
     53 
     54   {
     55     auto_ptr<const int> pint(new int(2));
     56     CPPUNIT_ASSERT( *pint == 2 );
     57   }
     58   {
     59     auto_ptr<volatile int> pint(new int(2));
     60     CPPUNIT_ASSERT( *pint == 2 );
     61   }
     62   {
     63     auto_ptr<const volatile int> pint(new int(2));
     64     CPPUNIT_ASSERT( *pint == 2 );
     65   }
     66 #endif
     67 }
     68