aboutsummaryrefslogtreecommitdiff
path: root/test/unit/binsert_test.cpp
blob: e085a5ce07e3853ccd135b3f0d1dc7f529843ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <vector>
#include <algorithm>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class BinsertTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(BinsertTest);
  CPPUNIT_TEST(binsert1);
  CPPUNIT_TEST(binsert2);
  CPPUNIT_TEST_SUITE_END();

protected:
  void binsert1();
  void binsert2();
};

CPPUNIT_TEST_SUITE_REGISTRATION(BinsertTest);

//
// tests implementation
//
void BinsertTest::binsert1()
{
  const char* array [] = { "laurie", "jennifer", "leisa" };
  vector<const char*> names;
  back_insert_iterator<vector<const char*> > bit(names);
  bit = copy(array, array + 3, bit);

  CPPUNIT_ASSERT(!strcmp(names[0],array[0]));
  CPPUNIT_ASSERT(!strcmp(names[1],array[1]));
  CPPUNIT_ASSERT(!strcmp(names[2],array[2]));

  copy(array, array + 3, bit);
  CPPUNIT_ASSERT(!strcmp(names[3],array[0]));
  CPPUNIT_ASSERT(!strcmp(names[4],array[1]));
  CPPUNIT_ASSERT(!strcmp(names[5],array[2]));
}
void BinsertTest::binsert2()
{
  const char* array [] = { "laurie", "jennifer", "leisa" };
  vector<const char*> names;
  copy(array, array + 3, back_inserter(names));
  CPPUNIT_ASSERT(!strcmp(names[0],array[0]));
  CPPUNIT_ASSERT(!strcmp(names[1],array[1]));
  CPPUNIT_ASSERT(!strcmp(names[2],array[2]));
}