31
|
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 <algorithm>
|
|
18 |
#include <cstring>
|
|
19 |
#include <vector>
|
|
20 |
#include <iterator>
|
|
21 |
|
|
22 |
#include "cppunit/cppunit_proxy.h"
|
|
23 |
|
|
24 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
|
25 |
using namespace std;
|
|
26 |
#endif
|
|
27 |
|
|
28 |
//
|
|
29 |
// TestCase class
|
|
30 |
//
|
|
31 |
class CopyTest : public CPPUNIT_NS::TestCase
|
|
32 |
{
|
|
33 |
CPPUNIT_TEST_SUITE(CopyTest);
|
|
34 |
CPPUNIT_TEST(copy_array);
|
|
35 |
CPPUNIT_TEST(copy_vector);
|
|
36 |
CPPUNIT_TEST(copy_insert);
|
|
37 |
CPPUNIT_TEST(copy_back);
|
|
38 |
CPPUNIT_TEST(copy_back_array);
|
|
39 |
CPPUNIT_TEST_SUITE_END();
|
|
40 |
|
|
41 |
protected:
|
|
42 |
void copy_array();
|
|
43 |
void copy_vector();
|
|
44 |
void copy_insert();
|
|
45 |
void copy_back();
|
|
46 |
void copy_back_array();
|
|
47 |
};
|
|
48 |
|
|
49 |
CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest);
|
|
50 |
|
|
51 |
//
|
|
52 |
// tests implementation
|
|
53 |
//
|
|
54 |
void CopyTest::copy_array()
|
|
55 |
{
|
|
56 |
char string[23] = "A string to be copied.";
|
|
57 |
char result[23];
|
|
58 |
copy(string, string + 23, result);
|
|
59 |
CPPUNIT_ASSERT(!strncmp(string, result, 23));
|
|
60 |
}
|
|
61 |
|
|
62 |
void CopyTest::copy_vector()
|
|
63 |
{
|
|
64 |
vector<int> v1(10);
|
|
65 |
for (int i = 0; (size_t)i < v1.size(); ++i)
|
|
66 |
v1[i] = i;
|
|
67 |
|
|
68 |
vector<int> v2(v1.size());
|
|
69 |
copy(v1.begin(), v1.end(), v2.begin());
|
|
70 |
|
|
71 |
CPPUNIT_ASSERT( v2 == v1 );
|
|
72 |
}
|
|
73 |
|
|
74 |
void CopyTest::copy_insert() {
|
|
75 |
vector<int> v1(10);
|
|
76 |
for (int loc = 0; (size_t)loc < v1.size(); ++loc)
|
|
77 |
v1[loc] = loc;
|
|
78 |
vector<int> v2;
|
|
79 |
insert_iterator<vector<int> > i(v2, v2.begin());
|
|
80 |
copy(v1.begin(), v1.end(), i);
|
|
81 |
|
|
82 |
CPPUNIT_ASSERT( v2 == v1 );
|
|
83 |
}
|
|
84 |
|
|
85 |
void CopyTest::copy_back()
|
|
86 |
{
|
|
87 |
vector<int> v1(10);
|
|
88 |
for (int i = 0; (size_t)i < v1.size(); ++i)
|
|
89 |
v1[i] = i;
|
|
90 |
vector<int> v2(v1.size());
|
|
91 |
copy_backward(v1.begin(), v1.end(), v2.end());
|
|
92 |
|
|
93 |
CPPUNIT_ASSERT( v2 == v1 );
|
|
94 |
}
|
|
95 |
|
|
96 |
void CopyTest::copy_back_array()
|
|
97 |
{
|
|
98 |
int numbers[5] = { 1, 2, 3, 4, 5 };
|
|
99 |
|
|
100 |
int result[5];
|
|
101 |
copy_backward(numbers, numbers + 5, (int*)result + 5);
|
|
102 |
CPPUNIT_ASSERT(result[0]==numbers[0]);
|
|
103 |
CPPUNIT_ASSERT(result[1]==numbers[1]);
|
|
104 |
CPPUNIT_ASSERT(result[2]==numbers[2]);
|
|
105 |
CPPUNIT_ASSERT(result[3]==numbers[3]);
|
|
106 |
CPPUNIT_ASSERT(result[4]==numbers[4]);
|
|
107 |
}
|