genericopenlibs/cppstdlib/stl/test/unit/insert_test.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <deque>
       
    18 #include <vector>
       
    19 #include <algorithm>
       
    20 
       
    21 #include "cppunit/cppunit_proxy.h"
       
    22 
       
    23 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
       
    24 using namespace std;
       
    25 #endif
       
    26 
       
    27 //
       
    28 // TestCase class
       
    29 //
       
    30 class InsertTest : public CPPUNIT_NS::TestCase
       
    31 {
       
    32   CPPUNIT_TEST_SUITE(InsertTest);
       
    33   CPPUNIT_TEST(insert1);
       
    34   CPPUNIT_TEST(insert2);
       
    35   CPPUNIT_TEST_SUITE_END();
       
    36 
       
    37 protected:
       
    38   void insert1();
       
    39   void insert2();
       
    40 };
       
    41 
       
    42 CPPUNIT_TEST_SUITE_REGISTRATION(InsertTest);
       
    43 
       
    44 //
       
    45 // tests implementation
       
    46 //
       
    47 void InsertTest::insert1()
       
    48 {
       
    49   char const* array1 [] = { "laurie", "jennifer", "leisa" };
       
    50   char const* array2 [] = { "amanda", "saskia", "carrie" };
       
    51 
       
    52   deque<char const*> names(array1, array1 + 3);
       
    53   deque<char const*>::iterator i = names.begin() + 2;
       
    54 
       
    55   insert_iterator<deque <char const*> > itd(names, i);
       
    56   itd = copy(array2, array2 + 3, insert_iterator<deque <char const*> >(names, i));
       
    57 
       
    58   CPPUNIT_ASSERT( !strcmp(names[0], "laurie") );
       
    59   CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") );
       
    60   CPPUNIT_ASSERT( !strcmp(names[2], "amanda") );
       
    61   CPPUNIT_ASSERT( !strcmp(names[3], "saskia") );
       
    62   CPPUNIT_ASSERT( !strcmp(names[4], "carrie") );
       
    63   CPPUNIT_ASSERT( !strcmp(names[5], "leisa") );
       
    64 
       
    65   copy(array1, array1 + 3, itd);
       
    66   CPPUNIT_ASSERT( !strcmp(names[5], "laurie") );
       
    67   CPPUNIT_ASSERT( !strcmp(names[6], "jennifer") );
       
    68   CPPUNIT_ASSERT( !strcmp(names[7], "leisa") );
       
    69   CPPUNIT_ASSERT( !strcmp(names[8], "leisa") );
       
    70 }
       
    71 void InsertTest::insert2()
       
    72 {
       
    73   char const* array1 [] = { "laurie", "jennifer", "leisa" };
       
    74   char const* array2 [] = { "amanda", "saskia", "carrie" };
       
    75 
       
    76   deque<char const*> names(array1, array1 + 3);
       
    77   deque<char const*>::iterator i = names.begin() + 2;
       
    78   copy(array2, array2 + 3, inserter(names, i));
       
    79 
       
    80   CPPUNIT_ASSERT( !strcmp(names[0], "laurie") );
       
    81   CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") );
       
    82   CPPUNIT_ASSERT( !strcmp(names[2], "amanda") );
       
    83   CPPUNIT_ASSERT( !strcmp(names[3], "saskia") );
       
    84   CPPUNIT_ASSERT( !strcmp(names[4], "carrie") );
       
    85   CPPUNIT_ASSERT( !strcmp(names[5], "leisa") );
       
    86 }