Home | History | Annotate | Download | only in unit
      1 #include <cstdio> //size_t and STLport macros
      2 
      3 #include "cppunit/cppunit_proxy.h"
      4 
      5 //
      6 // TestCase class
      7 //
      8 class MoveConstructorTest : public CPPUNIT_NS::TestCase
      9 {
     10   CPPUNIT_TEST_SUITE(MoveConstructorTest);
     11   CPPUNIT_TEST(move_construct_test);
     12   CPPUNIT_TEST(deque_test);
     13   CPPUNIT_TEST(vector_test);
     14   CPPUNIT_TEST(move_traits);
     15 #if !defined (STLPORT) || defined (_STLP_NO_MOVE_SEMANTIC) || \
     16     defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) || \
     17     (defined (__BORLANDC__) && (__BORLANDC__ < 0x564))
     18   CPPUNIT_IGNORE;
     19 #  endif
     20   CPPUNIT_TEST(movable_declaration)
     21   CPPUNIT_TEST(movable_declaration_assoc)
     22   CPPUNIT_TEST(movable_declaration_hash)
     23 #if defined (__BORLANDC__)
     24   CPPUNIT_STOP_IGNORE;
     25   CPPUNIT_TEST(nb_destructor_calls);
     26 #endif
     27   CPPUNIT_TEST_SUITE_END();
     28 
     29 protected:
     30   void move_construct_test();
     31   void deque_test();
     32   void vector_test();
     33   void move_traits();
     34   void movable_declaration();
     35   void movable_declaration_assoc();
     36   void movable_declaration_hash();
     37   void nb_destructor_calls();
     38 
     39   /*
     40   template <class _Container>
     41   void standard_test1(_Container const& ref_cont) {
     42     vector<_Container> vec_cont(1, ref_cont);
     43     typedef typename _Container::value_type value_type;
     44     value_type *pvalue = &(*vec_cont.front().begin());
     45     size_t cur_capacity= vec_cont.capacity();
     46     //force reallocation
     47     while (cur_capacity == vec_cont.capacity()) {
     48       vec_cont.push_back(ref_cont);
     49     }
     50     bool b=( (pvalue==(&(*vec_cont.front().begin()))) );
     51     CPPUNIT_ASSERT(b);
     52   }
     53   */
     54 
     55 private:
     56   void move_traits_vec();
     57   void move_traits_vec_complete();
     58   void move_traits_deq();
     59   void move_traits_deq_complete();
     60 };
     61 
     62 struct MovableStruct {
     63   MovableStruct() { ++nb_dft_construct_call; }
     64   MovableStruct(MovableStruct const&) { ++nb_cpy_construct_call; }
     65 #if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
     66 #  if defined (_STLP_USE_NAMESPACES)
     67   MovableStruct(std::__move_source<MovableStruct>)
     68 #  else
     69   MovableStruct(__move_source<MovableStruct>)
     70 #  endif
     71   { ++nb_mv_construct_call; }
     72 #endif
     73   ~MovableStruct() { ++nb_destruct_call; }
     74 
     75   MovableStruct& operator = (const MovableStruct&) {
     76     ++nb_assignment_call;
     77     return *this;
     78   }
     79 
     80   static void reset() {
     81     nb_dft_construct_call = nb_cpy_construct_call = nb_mv_construct_call = 0;
     82     nb_assignment_call = 0;
     83     nb_destruct_call = 0;
     84   }
     85 
     86   static size_t nb_dft_construct_call;
     87   static size_t nb_cpy_construct_call;
     88   static size_t nb_mv_construct_call;
     89   static size_t nb_assignment_call;
     90   static size_t nb_destruct_call;
     91 
     92   //Dummy data just to control struct sizeof
     93   //As node allocator implementation align memory blocks on 2 * sizeof(void*)
     94   //we give MovableStruct the same size in order to have expected allocation
     95   //and not more
     96   void* dummy_data[2];
     97 };
     98