6 #include "cppunit/cppunit_proxy.h"
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
15 class CopyTest : public CPPUNIT_NS::TestCase
17 CPPUNIT_TEST_SUITE(CopyTest);
18 CPPUNIT_TEST(copy_array);
19 CPPUNIT_TEST(copy_volatile);
20 CPPUNIT_TEST(copy_vector);
21 CPPUNIT_TEST(copy_insert);
22 CPPUNIT_TEST(copy_back);
23 CPPUNIT_TEST(copy_back_array);
24 CPPUNIT_TEST_SUITE_END();
32 void copy_back_array();
35 CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest);
38 // tests implementation
40 void CopyTest::copy_array()
42 char string[23] = "A string to be copied.";
44 copy(string, string + 23, result);
45 CPPUNIT_ASSERT(!strncmp(string, result, 23));
48 void CopyTest::copy_volatile()
51 int a[] = {0, 1, 2, 3, 4, 5};
52 const size_t size = sizeof(a) / sizeof(a[0]);
53 volatile int va[size];
54 copy(a, a + size, va);
55 for (size_t i = 0; i != size; ++i) {
56 CPPUNIT_ASSERT( a[i] == va[i] );
61 const int a[] = {0, 1, 2, 3, 4, 5};
62 const size_t size = sizeof(a) / sizeof(a[0]);
63 volatile int va[size];
64 copy(a, a + size, va);
65 for (size_t i = 0; i != size; ++i) {
66 CPPUNIT_ASSERT( a[i] == va[i] );
70 // Following code can be activated to check that it doesn't compiled
73 int a[] = {0, 1, 2, 3, 4, 5};
74 const size_t size = sizeof(a) / sizeof(a[0]);
75 const volatile int va[size] = {5, 4, 3, 2, 1, 0};
76 copy(a, a + size, va);
77 for (size_t i = 0; i != size; ++i) {
78 CPPUNIT_ASSERT( a[i] == va[i] );
84 void CopyTest::copy_vector()
87 for (int i = 0; (size_t)i < v1.size(); ++i)
90 vector<int> v2(v1.size());
91 copy(v1.begin(), v1.end(), v2.begin());
93 CPPUNIT_ASSERT( v2 == v1 );
96 void CopyTest::copy_insert() {
98 for (int loc = 0; (size_t)loc < v1.size(); ++loc)
101 insert_iterator<vector<int> > i(v2, v2.begin());
102 copy(v1.begin(), v1.end(), i);
104 CPPUNIT_ASSERT( v2 == v1 );
107 void CopyTest::copy_back()
110 for (int i = 0; (size_t)i < v1.size(); ++i)
112 vector<int> v2(v1.size());
113 copy_backward(v1.begin(), v1.end(), v2.end());
115 CPPUNIT_ASSERT( v2 == v1 );
118 void CopyTest::copy_back_array()
120 int numbers[5] = { 1, 2, 3, 4, 5 };
123 copy_backward(numbers, numbers + 5, (int*)result + 5);
124 CPPUNIT_ASSERT(result[0]==numbers[0]);
125 CPPUNIT_ASSERT(result[1]==numbers[1]);
126 CPPUNIT_ASSERT(result[2]==numbers[2]);
127 CPPUNIT_ASSERT(result[3]==numbers[3]);
128 CPPUNIT_ASSERT(result[4]==numbers[4]);