Home | History | Annotate | Download | only in unit
      1 #include <vector>
      2 #include <algorithm>
      3 
      4 #include "cppunit/cppunit_proxy.h"
      5 
      6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
      7 using namespace std;
      8 #endif
      9 
     10 //
     11 // TestCase class
     12 //
     13 class BinsertTest : public CPPUNIT_NS::TestCase
     14 {
     15   CPPUNIT_TEST_SUITE(BinsertTest);
     16   CPPUNIT_TEST(binsert1);
     17   CPPUNIT_TEST(binsert2);
     18   CPPUNIT_TEST_SUITE_END();
     19 
     20 protected:
     21   void binsert1();
     22   void binsert2();
     23 };
     24 
     25 CPPUNIT_TEST_SUITE_REGISTRATION(BinsertTest);
     26 
     27 //
     28 // tests implementation
     29 //
     30 void BinsertTest::binsert1()
     31 {
     32   const char* array [] = { "laurie", "jennifer", "leisa" };
     33   vector<const char*> names;
     34   back_insert_iterator<vector<const char*> > bit(names);
     35   bit = copy(array, array + 3, bit);
     36 
     37   CPPUNIT_ASSERT(!strcmp(names[0],array[0]));
     38   CPPUNIT_ASSERT(!strcmp(names[1],array[1]));
     39   CPPUNIT_ASSERT(!strcmp(names[2],array[2]));
     40 
     41   copy(array, array + 3, bit);
     42   CPPUNIT_ASSERT(!strcmp(names[3],array[0]));
     43   CPPUNIT_ASSERT(!strcmp(names[4],array[1]));
     44   CPPUNIT_ASSERT(!strcmp(names[5],array[2]));
     45 }
     46 void BinsertTest::binsert2()
     47 {
     48   const char* array [] = { "laurie", "jennifer", "leisa" };
     49   vector<const char*> names;
     50   copy(array, array + 3, back_inserter(names));
     51   CPPUNIT_ASSERT(!strcmp(names[0],array[0]));
     52   CPPUNIT_ASSERT(!strcmp(names[1],array[1]));
     53   CPPUNIT_ASSERT(!strcmp(names[2],array[2]));
     54 }
     55