|
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 |
|
18 |
|
19 // STLport regression testsuite component. |
|
20 // To compile as a separate example, please #define MAIN. |
|
21 |
|
22 #include <iostream> |
|
23 #include <vector> |
|
24 #include <algorithm> |
|
25 |
|
26 #ifdef MAIN |
|
27 #define vec6_test main |
|
28 #endif |
|
29 |
|
30 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES) |
|
31 using namespace std; |
|
32 #endif |
|
33 int vec6_test(int, char**) |
|
34 { |
|
35 int failures=0; |
|
36 cout<<"Results of vec6_test:"<<endl; |
|
37 int array [] = { 1, 4, 9, 16, 25, 36 }; |
|
38 |
|
39 vector<int> v(array, array + 6); |
|
40 int i; |
|
41 for(i = 0; i < v.size(); i++) |
|
42 cout << "v[" << i << "] = " << v[i] << endl; |
|
43 cout << endl; |
|
44 |
|
45 if(1!=v[0]) |
|
46 failures++; |
|
47 else if(4!=v[1]) |
|
48 failures++; |
|
49 else if(9!=v[2]) |
|
50 failures++; |
|
51 else if(16!=v[3]) |
|
52 failures++; |
|
53 else if(25!=v[4]) |
|
54 failures++; |
|
55 else if(36!=v[5]) |
|
56 failures++; |
|
57 |
|
58 v.erase(v.begin()); // Erase first element. |
|
59 for(i = 0; i < v.size(); i++) |
|
60 cout << "v[" << i << "] = " << v[i] << endl; |
|
61 cout << endl; |
|
62 |
|
63 if(4!=v[0]) |
|
64 failures++; |
|
65 else if(9!=v[1]) |
|
66 failures++; |
|
67 else if(16!=v[2]) |
|
68 failures++; |
|
69 else if(25!=v[3]) |
|
70 failures++; |
|
71 else if(36!=v[4]) |
|
72 failures++; |
|
73 |
|
74 |
|
75 v.erase(v.end() - 1); // Erase last element. |
|
76 for(i = 0; i < v.size(); i++) |
|
77 cout << "v[" << i << "] = " << v[i] << endl; |
|
78 cout << endl; |
|
79 |
|
80 |
|
81 if(4!=v[0]) |
|
82 failures++; |
|
83 else if(9!=v[1]) |
|
84 failures++; |
|
85 else if(16!=v[2]) |
|
86 failures++; |
|
87 else if(25!=v[3]) |
|
88 failures++; |
|
89 |
|
90 v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last. |
|
91 for(i = 0; i < v.size(); i++) |
|
92 cout << "v[" << i << "] = " << v[i] << endl; |
|
93 cout << endl; |
|
94 /* |
|
95 v.erase(v.begin(), v.end()); // Erase all. |
|
96 */ |
|
97 |
|
98 if(4!=v[0]) |
|
99 failures++; |
|
100 else if(25!=v[1]) |
|
101 failures++; |
|
102 |
|
103 |
|
104 if(failures) |
|
105 return 1; |
|
106 else |
|
107 return 0; |
|
108 } |
|
109 |
|
110 /*Results of vec6_test: |
|
111 v[0] = 1 |
|
112 v[1] = 4 |
|
113 v[2] = 9 |
|
114 v[3] = 16 |
|
115 v[4] = 25 |
|
116 v[5] = 36 |
|
117 |
|
118 v[0] = 4 |
|
119 v[1] = 9 |
|
120 v[2] = 16 |
|
121 v[3] = 25 |
|
122 v[4] = 36 |
|
123 |
|
124 v[0] = 4 |
|
125 v[1] = 9 |
|
126 v[2] = 16 |
|
127 v[3] = 25 |
|
128 |
|
129 v[0] = 4 |
|
130 v[1] = 25 |
|
131 */ |