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