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 <vector>
|
|
18 |
#include <list>
|
|
19 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
20 |
# include <slist>
|
|
21 |
#endif
|
|
22 |
#include <deque>
|
|
23 |
#include <set>
|
|
24 |
#include <iterator>
|
|
25 |
|
|
26 |
#include "cppunit/cppunit_proxy.h"
|
|
27 |
|
|
28 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
|
29 |
using namespace std;
|
|
30 |
#endif
|
|
31 |
|
|
32 |
//
|
|
33 |
// TestCase class
|
|
34 |
//
|
|
35 |
class PtrSpecTest : public CPPUNIT_NS::TestCase
|
|
36 |
{
|
|
37 |
CPPUNIT_TEST_SUITE(PtrSpecTest);
|
|
38 |
#if (defined (__DMC__) && defined (_STLP_DEBUG))
|
|
39 |
CPPUNIT_IGNORE;
|
|
40 |
#endif
|
|
41 |
CPPUNIT_TEST(ptr_specialization_test);
|
|
42 |
CPPUNIT_TEST_SUITE_END();
|
|
43 |
|
|
44 |
protected:
|
|
45 |
// this seems to be compile only test but...
|
|
46 |
void ptr_specialization_test();
|
|
47 |
|
|
48 |
template <class _Tp>
|
|
49 |
struct unary_pred {
|
|
50 |
bool operator () (_Tp *__ptr) const {
|
|
51 |
return *__ptr == 0;
|
|
52 |
}
|
|
53 |
};
|
|
54 |
|
|
55 |
template <class _Tp>
|
|
56 |
struct binary_pred {
|
|
57 |
bool operator () (_Tp *__first, _Tp *__second) const {
|
|
58 |
return *__first < *__second;
|
|
59 |
}
|
|
60 |
};
|
|
61 |
};
|
|
62 |
|
|
63 |
CPPUNIT_TEST_SUITE_REGISTRATION(PtrSpecTest);
|
|
64 |
|
|
65 |
#define TEST_INSTANCIATE_CONTAINER(cont) \
|
|
66 |
template class cont<int*>; \
|
|
67 |
template class cont<int const*>; \
|
|
68 |
template class cont<int volatile*>; \
|
|
69 |
template class cont<int const volatile*>
|
|
70 |
|
|
71 |
#if !defined(_MSC_VER) || (_MSC_VER > 1200) // excluding MSVC 6.0
|
|
72 |
TEST_INSTANCIATE_CONTAINER(vector);
|
|
73 |
TEST_INSTANCIATE_CONTAINER(list);
|
|
74 |
# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
75 |
TEST_INSTANCIATE_CONTAINER(slist);
|
|
76 |
# endif
|
|
77 |
TEST_INSTANCIATE_CONTAINER(deque);
|
|
78 |
TEST_INSTANCIATE_CONTAINER(set);
|
|
79 |
TEST_INSTANCIATE_CONTAINER(multiset);
|
|
80 |
#endif
|
|
81 |
|
|
82 |
//Function to test pointer to function support:
|
|
83 |
void FTypeInstance() {}
|
|
84 |
|
|
85 |
//Class to test pointer to member method support:
|
|
86 |
class AClass {
|
|
87 |
public:
|
|
88 |
void func() {}
|
|
89 |
};
|
|
90 |
|
|
91 |
//
|
|
92 |
// tests implementation
|
|
93 |
//
|
|
94 |
void PtrSpecTest::ptr_specialization_test()
|
|
95 |
{
|
|
96 |
# if !(defined (__DMC__) && defined (_STLP_DEBUG))
|
|
97 |
int *int_array[] = {0, 0, 0};
|
|
98 |
int const* cint_array[] = {0, 0, 0};
|
|
99 |
|
|
100 |
{
|
|
101 |
vector<void*> void_vect;
|
|
102 |
deque<void*> void_deque;
|
|
103 |
list<void*> void_list;
|
|
104 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
105 |
slist<void*> void_slist;
|
|
106 |
#endif
|
|
107 |
}
|
|
108 |
|
|
109 |
{
|
|
110 |
typedef void (*FType)();
|
|
111 |
vector<FType> func_vector;
|
|
112 |
func_vector.push_back(&FTypeInstance);
|
|
113 |
}
|
|
114 |
|
|
115 |
#if !defined(__GNUC__) || (__GNUC__ > 2)
|
|
116 |
{
|
|
117 |
typedef void (AClass::*MFType)();
|
|
118 |
vector<MFType> mem_func_vector;
|
|
119 |
mem_func_vector.push_back(&AClass::func);
|
|
120 |
}
|
|
121 |
#endif
|
|
122 |
|
|
123 |
vector<int*> pint_vect;
|
|
124 |
vector<int*> pint_vect2;
|
|
125 |
vector<int const*> pcint_vect;
|
|
126 |
list<int*> pint_list;
|
|
127 |
list<int*> pint_list2;
|
|
128 |
list<int const*> pcint_list;
|
|
129 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
130 |
slist<int*> pint_slist;
|
|
131 |
slist<int*> pint_slist2;
|
|
132 |
slist<int const*> pcint_slist;
|
|
133 |
#endif
|
|
134 |
deque<int*> pint_deque;
|
|
135 |
deque<int*> pint_deque2;
|
|
136 |
deque<int const*> pcint_deque;
|
|
137 |
|
|
138 |
#ifdef _STLP_MEMBER_TEMPLATES
|
|
139 |
vector<int*> pint_vect_from_list(pint_list.begin(), pint_list.end());
|
|
140 |
#endif
|
|
141 |
pint_vect.insert(pint_vect.end(), pint_vect2.begin(), pint_vect2.end());
|
|
142 |
pint_vect.insert(pint_vect.end(), int_array, int_array + 3);
|
|
143 |
pint_vect2.insert(pint_vect2.end(), int_array, int_array + 3);
|
|
144 |
pcint_vect.insert(pcint_vect.end(), int_array, int_array + 3);
|
|
145 |
pcint_vect.insert(pcint_vect.end(), cint_array, cint_array + 3);
|
|
146 |
#if !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES)
|
|
147 |
pcint_vect.insert(pcint_vect.end(), pint_vect2.begin(), pint_vect2.end());
|
|
148 |
#endif
|
|
149 |
pcint_vect.insert(pcint_vect.end(), int_array, int_array + 3);
|
|
150 |
#ifdef _STLP_MEMBER_TEMPLATES
|
|
151 |
pint_vect.insert(pint_vect.end(), pint_list.begin(), pint_list.end());
|
|
152 |
pcint_vect.insert(pcint_vect.end(), pint_list.begin(), pint_list.end());
|
|
153 |
pcint_vect.insert(pcint_vect.end(), pcint_list.begin(), pcint_list.end());
|
|
154 |
pint_vect.assign(pint_list.begin(), pint_list.end());
|
|
155 |
pcint_vect.assign(pint_list.begin(), pint_list.end());
|
|
156 |
#endif
|
|
157 |
pint_vect.assign(int_array, int_array + 3);
|
|
158 |
pcint_vect.assign(int_array, int_array + 3);
|
|
159 |
pcint_vect.assign(cint_array, cint_array + 3);
|
|
160 |
copy(int_array, int_array + 3, back_inserter(pint_vect));
|
|
161 |
|
|
162 |
#ifdef _STLP_MEMBER_TEMPLATES
|
|
163 |
pint_list.sort(binary_pred<int>());
|
|
164 |
pcint_list.sort(binary_pred<int const>());
|
|
165 |
pint_list.unique(binary_pred<int>());
|
|
166 |
pcint_list.unique(binary_pred<int const>());
|
|
167 |
pint_list.merge(pint_list, binary_pred<int>());
|
|
168 |
pcint_list.merge(pcint_list, binary_pred<int const>());
|
|
169 |
pint_list.remove_if(unary_pred<int>());
|
|
170 |
pcint_list.remove_if(unary_pred<int const>());
|
|
171 |
#endif
|
|
172 |
|
|
173 |
copy(int_array, int_array + 3, back_inserter(pint_list));
|
|
174 |
copy(int_array, int_array + 3, back_inserter(pint_list2));
|
|
175 |
pint_list.insert(pint_list.end(), pint_list2.begin(), pint_list2.end());
|
|
176 |
#ifdef _STLP_MEMBER_TEMPLATES
|
|
177 |
pcint_list.insert(pcint_list.end(), pint_list.begin(), pint_list.end());
|
|
178 |
#endif
|
|
179 |
#if !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES)
|
|
180 |
pint_list.insert(pint_list.end(), pint_vect.begin(), pint_vect.end());
|
|
181 |
pcint_list.insert(pcint_list.end(), pint_vect.begin(), pint_vect.end());
|
|
182 |
pcint_list.insert(pcint_list.end(), pcint_vect.begin(), pcint_vect.end());
|
|
183 |
list<int*> pint_list_from_vect(pint_vect.begin(), pint_vect.end());
|
|
184 |
pint_list.assign(pint_vect.begin(), pint_vect.end());
|
|
185 |
pcint_list.assign(pint_vect.begin(), pint_vect.end());
|
|
186 |
#endif
|
|
187 |
pint_list.insert(pint_list.begin(), int_array, int_array + 3);
|
|
188 |
pint_list.insert(pint_list.end(), int_array, int_array + 3);
|
|
189 |
pcint_list.insert(pcint_list.end(), int_array, int_array + 3);
|
|
190 |
pcint_list.insert(pcint_list.end(), cint_array, cint_array + 3);
|
|
191 |
pint_list.assign(int_array, int_array + 3);
|
|
192 |
pcint_list.assign(int_array, int_array + 3);
|
|
193 |
pcint_list.assign(cint_array, cint_array + 3);
|
|
194 |
//pint_list.assign(pcint_vect.begin(), pcint_vect.end());
|
|
195 |
|
|
196 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
197 |
copy(int_array, int_array + 3, front_inserter(pint_slist));
|
|
198 |
copy(int_array, int_array + 3, front_inserter(pint_slist2));
|
|
199 |
pint_slist.insert(pint_slist.end(), pint_slist2.begin(), pint_slist2.end());
|
|
200 |
# if defined (_STLP_MEMBER_TEMPLATES)
|
|
201 |
pcint_slist.insert(pcint_slist.end(), pint_slist.begin(), pint_slist.end());
|
|
202 |
# endif
|
|
203 |
# if !defined (_STLP_DEBUG) || defined (_STLP_MEMBER_TEMPLATES)
|
|
204 |
pint_slist.insert(pint_slist.end(), pint_vect.begin(), pint_vect.end());
|
|
205 |
pcint_slist.insert(pcint_slist.end(), pint_vect.begin(), pint_vect.end());
|
|
206 |
pcint_slist.insert(pcint_slist.end(), pcint_vect.begin(), pcint_vect.end());
|
|
207 |
slist<int*> pint_slist_from_vect(pint_vect.begin(), pint_vect.end());
|
|
208 |
pint_slist.assign(pint_vect.begin(), pint_vect.end());
|
|
209 |
pcint_slist.assign(pint_vect.begin(), pint_vect.end());
|
|
210 |
# endif
|
|
211 |
pint_slist.insert(pint_slist.end(), int_array, int_array + 3);
|
|
212 |
pcint_slist.insert(pcint_slist.end(), int_array, int_array + 3);
|
|
213 |
pcint_slist.insert(pcint_slist.end(), cint_array, cint_array + 3);
|
|
214 |
pint_slist.assign(int_array, int_array + 3);
|
|
215 |
pcint_slist.assign(int_array, int_array + 3);
|
|
216 |
pcint_slist.assign(cint_array, cint_array + 3);
|
|
217 |
//pint_slist.assign(pcint_vect.begin(), pcint_vect.end());
|
|
218 |
#endif
|
|
219 |
|
|
220 |
copy(int_array, int_array + 3, back_inserter(pint_deque));
|
|
221 |
copy(int_array, int_array + 3, back_inserter(pint_deque2));
|
|
222 |
pint_deque.insert(pint_deque.end(), pint_deque2.begin(), pint_deque2.end());
|
|
223 |
#ifdef _STLP_MEMBER_TEMPLATES
|
|
224 |
pcint_deque.insert(pcint_deque.end(), pint_deque.begin(), pint_deque.end());
|
|
225 |
#endif
|
|
226 |
#if !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES)
|
|
227 |
pint_deque.insert(pint_deque.end(), pint_vect.begin(), pint_vect.end());
|
|
228 |
pcint_deque.insert(pcint_deque.end(), pint_vect.begin(), pint_vect.end());
|
|
229 |
pcint_deque.insert(pcint_deque.end(), pcint_vect.begin(), pcint_vect.end());
|
|
230 |
deque<int*> pint_deque_from_vect(pint_vect.begin(), pint_vect.end());
|
|
231 |
pint_deque.assign(pint_vect.begin(), pint_vect.end());
|
|
232 |
pcint_deque.assign(pint_vect.begin(), pint_vect.end());
|
|
233 |
#endif
|
|
234 |
pint_deque.insert(pint_deque.end(), int_array, int_array + 3);
|
|
235 |
pcint_deque.insert(pcint_deque.end(), int_array, int_array + 3);
|
|
236 |
pcint_deque.insert(pcint_deque.end(), cint_array, cint_array + 3);
|
|
237 |
pint_deque.assign(int_array, int_array + 3);
|
|
238 |
pcint_deque.assign(int_array, int_array + 3);
|
|
239 |
pcint_deque.assign(cint_array, cint_array + 3);
|
|
240 |
# endif /* __DMC__ */
|
|
241 |
}
|