Home | History | Annotate | Download | only in unit
      1 #include <deque>
      2 #include <vector>
      3 #include <algorithm>
      4 
      5 #include "cppunit/cppunit_proxy.h"
      6 
      7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
      8 using namespace std;
      9 #endif
     10 
     11 //
     12 // TestCase class
     13 //
     14 class InsertTest : public CPPUNIT_NS::TestCase
     15 {
     16   CPPUNIT_TEST_SUITE(InsertTest);
     17   CPPUNIT_TEST(insert1);
     18   CPPUNIT_TEST(insert2);
     19   CPPUNIT_TEST_SUITE_END();
     20 
     21 protected:
     22   void insert1();
     23   void insert2();
     24 };
     25 
     26 CPPUNIT_TEST_SUITE_REGISTRATION(InsertTest);
     27 
     28 //
     29 // tests implementation
     30 //
     31 void InsertTest::insert1()
     32 {
     33   char const* array1 [] = { "laurie", "jennifer", "leisa" };
     34   char const* array2 [] = { "amanda", "saskia", "carrie" };
     35 
     36   deque<char const*> names(array1, array1 + 3);
     37   deque<char const*>::iterator i = names.begin() + 2;
     38 
     39   insert_iterator<deque <char const*> > itd(names, i);
     40   itd = copy(array2, array2 + 3, insert_iterator<deque <char const*> >(names, i));
     41 
     42   CPPUNIT_ASSERT( !strcmp(names[0], "laurie") );
     43   CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") );
     44   CPPUNIT_ASSERT( !strcmp(names[2], "amanda") );
     45   CPPUNIT_ASSERT( !strcmp(names[3], "saskia") );
     46   CPPUNIT_ASSERT( !strcmp(names[4], "carrie") );
     47   CPPUNIT_ASSERT( !strcmp(names[5], "leisa") );
     48 
     49   copy(array1, array1 + 3, itd);
     50   CPPUNIT_ASSERT( !strcmp(names[5], "laurie") );
     51   CPPUNIT_ASSERT( !strcmp(names[6], "jennifer") );
     52   CPPUNIT_ASSERT( !strcmp(names[7], "leisa") );
     53   CPPUNIT_ASSERT( !strcmp(names[8], "leisa") );
     54 }
     55 void InsertTest::insert2()
     56 {
     57   char const* array1 [] = { "laurie", "jennifer", "leisa" };
     58   char const* array2 [] = { "amanda", "saskia", "carrie" };
     59 
     60   deque<char const*> names(array1, array1 + 3);
     61   deque<char const*>::iterator i = names.begin() + 2;
     62   copy(array2, array2 + 3, inserter(names, i));
     63 
     64   CPPUNIT_ASSERT( !strcmp(names[0], "laurie") );
     65   CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") );
     66   CPPUNIT_ASSERT( !strcmp(names[2], "amanda") );
     67   CPPUNIT_ASSERT( !strcmp(names[3], "saskia") );
     68   CPPUNIT_ASSERT( !strcmp(names[4], "carrie") );
     69   CPPUNIT_ASSERT( !strcmp(names[5], "leisa") );
     70 }
     71