Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / util / regression / rand / assoc / detail / constructor_destructor_fn_imps.hpp
blobc6b02b61a170cbed7556f487ad5734241b05852b
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file constructor_destructor_fn_imps.hpp
44 * Containsert a random regression test for a specific container type.
47 PB_DS_CLASS_T_DEC
48 PB_DS_CLASS_C_DEC::
49 container_rand_regression_test(unsigned long seed, size_t n, size_t m,
50 double tp, double ip, double ep, double cp,
51 double mp, bool disp)
52 : m_seed((seed == 0) ? twister_rand_gen::get_time_determined_seed() : seed),
53 m_n(n), m_m(m), m_tp(tp), m_ip(ip), m_ep(ep), m_cp(cp), m_mp(mp),
54 m_disp(disp), m_p_c(NULL)
55 { }
57 PB_DS_CLASS_T_DEC
58 PB_DS_CLASS_C_DEC::
59 ~container_rand_regression_test()
60 { }
62 PB_DS_CLASS_T_DEC
63 bool
64 PB_DS_CLASS_C_DEC::
65 default_constructor()
67 PB_DS_TRACE("default_constructor");
68 bool done = true;
69 m_alloc.set_throw_prob(m_tp);
71 try
73 m_p_c = new Cntnr;
75 catch(__gnu_cxx::forced_exception_error&)
77 done = false;
80 if (m_p_c != NULL)
81 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
82 return done;
85 PB_DS_CLASS_T_DEC
86 void
87 PB_DS_CLASS_C_DEC::
88 swap()
90 PB_DS_TRACE("swap");
91 m_alloc.set_throw_prob(0);
92 Cntnr* p_c = new Cntnr;
93 m_alloc.set_throw_prob(1);
94 p_c->swap(*m_p_c);
95 std::swap(p_c, m_p_c);
96 delete p_c;
97 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
100 PB_DS_CLASS_T_DEC
101 bool
102 PB_DS_CLASS_C_DEC::
103 copy_constructor()
105 PB_DS_TRACE("copy_constructor");
106 bool done = true;
107 Cntnr* p_c = NULL;
108 m_alloc.set_throw_prob(m_tp);
109 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
113 p_c = new Cntnr(*m_p_c);
114 std::swap(p_c, m_p_c);
116 catch(__gnu_cxx::forced_exception_error& )
118 done = false;
121 delete p_c;
122 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
123 return done;
126 PB_DS_CLASS_T_DEC
127 bool
128 PB_DS_CLASS_C_DEC::
129 assignment_operator()
131 PB_DS_TRACE("assignment operator");
132 bool done = true;
133 Cntnr* p_c = NULL;
134 m_alloc.set_throw_prob(m_tp);
135 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
139 p_c = new Cntnr();
140 * p_c =* m_p_c;
141 std::swap(p_c, m_p_c);
143 catch(__gnu_cxx::forced_exception_error& )
145 done = false;
148 delete p_c;
149 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
150 return done;
153 PB_DS_CLASS_T_DEC
154 bool
155 PB_DS_CLASS_C_DEC::
156 it_constructor()
158 PB_DS_TRACE("it_constructor");
159 return it_constructor_imp(typename Cntnr::container_category());
162 PB_DS_CLASS_T_DEC
163 bool
164 PB_DS_CLASS_C_DEC::
165 it_constructor_imp(__gnu_pbds::cc_hash_tag)
167 bool done = true;
168 Cntnr* p_c = NULL;
169 m_alloc.set_throw_prob(m_tp);
170 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
174 switch(get_next_sub_op(8))
176 case 0:
177 p_c = new Cntnr(m_p_c->get_hash_fn());
178 m_native_c.clear();
179 break;
180 case 1:
181 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn());
182 m_native_c.clear();
183 break;
184 case 2:
185 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
186 m_p_c->get_comb_hash_fn());
187 m_native_c.clear();
188 break;
189 case 3:
190 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
191 m_p_c->get_comb_hash_fn(),
192 m_p_c->get_resize_policy());
193 m_native_c.clear();
194 break;
195 case 4:
196 p_c = new Cntnr(m_p_c->begin(), m_p_c->end());
197 break;
198 case 5:
199 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn());
200 break;
201 case 6:
202 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
203 m_p_c->get_eq_fn());
204 break;
205 case 7:
206 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
207 m_p_c->get_eq_fn(), m_p_c->get_comb_hash_fn());
208 break;
209 case 8:
210 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
211 m_p_c->get_eq_fn(), m_p_c->get_comb_hash_fn(),
212 m_p_c->get_resize_policy());
213 break;
214 default:
215 PB_DS_THROW_IF_FAILED(false, "", m_p_c, & m_native_c);
217 std::swap(p_c, m_p_c);
219 catch (__gnu_cxx::forced_exception_error&)
221 done = false;
224 delete p_c;
225 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
226 return done;
229 PB_DS_CLASS_T_DEC
230 bool
231 PB_DS_CLASS_C_DEC::
232 it_constructor_imp(__gnu_pbds::gp_hash_tag)
234 bool done = true;
235 Cntnr* p_c = NULL;
236 m_alloc.set_throw_prob(m_tp);
237 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
241 switch(get_next_sub_op(11))
243 case 0:
244 p_c = new Cntnr(m_p_c->get_hash_fn());
245 m_native_c.clear();
246 break;
247 case 1:
248 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn());
249 m_native_c.clear();
250 break;
251 case 2:
252 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
253 m_p_c->get_comb_probe_fn());
254 m_native_c.clear();
255 break;
256 case 3:
257 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
258 m_p_c->get_comb_probe_fn());
259 m_native_c.clear();
260 break;
261 case 4:
262 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
263 m_p_c->get_comb_probe_fn(), m_p_c->get_probe_fn());
264 m_native_c.clear();
265 break;
266 case 5:
267 p_c = new Cntnr(m_p_c->get_hash_fn(), m_p_c->get_eq_fn(),
268 m_p_c->get_comb_probe_fn(), m_p_c->get_probe_fn(),
269 m_p_c->get_resize_policy());
270 m_native_c.clear();
271 break;
272 case 6:
273 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn());
274 break;
275 case 7:
276 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
277 m_p_c->get_eq_fn());
278 break;
279 case 8:
280 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
281 m_p_c->get_eq_fn(), m_p_c->get_comb_probe_fn());
282 break;
283 case 9:
284 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
285 m_p_c->get_eq_fn(), m_p_c->get_comb_probe_fn());
286 break;
287 case 10:
288 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
289 m_p_c->get_eq_fn(), m_p_c->get_comb_probe_fn(),
290 m_p_c->get_probe_fn());
291 break;
292 case 11:
293 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_hash_fn(),
294 m_p_c->get_eq_fn(), m_p_c->get_comb_probe_fn(),
295 m_p_c->get_probe_fn(), m_p_c->get_resize_policy());
296 break;
297 default:
298 PB_DS_THROW_IF_FAILED(false, "", m_p_c, & m_native_c);
300 std::swap(p_c, m_p_c);
302 catch (__gnu_cxx::forced_exception_error&)
304 done = false;
307 delete p_c;
308 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
309 return done;
312 PB_DS_CLASS_T_DEC
313 bool
314 PB_DS_CLASS_C_DEC::
315 it_constructor_imp(__gnu_pbds::tree_tag)
317 bool done = true;
318 Cntnr* p_c = NULL;
319 m_alloc.set_throw_prob(m_tp);
320 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
324 switch(get_next_sub_op(2))
326 case 0:
327 p_c = new Cntnr(m_p_c->get_cmp_fn());
328 m_native_c.clear();
329 break;
330 case 1:
331 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_cmp_fn());
332 break;
333 default:
334 PB_DS_THROW_IF_FAILED(false, "", m_p_c, &m_native_c);
336 std::swap(p_c, m_p_c);
338 catch (__gnu_cxx::forced_exception_error&)
340 done = false;
343 delete p_c;
344 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
345 return done;
348 PB_DS_CLASS_T_DEC
349 bool
350 PB_DS_CLASS_C_DEC::
351 it_constructor_imp(__gnu_pbds::list_update_tag)
353 bool done = true;
354 Cntnr* p_c = NULL;
355 m_alloc.set_throw_prob(m_tp);
356 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
360 p_c = new Cntnr(m_p_c->begin(), m_p_c->end());
361 std::swap(p_c, m_p_c);
363 catch (__gnu_cxx::forced_exception_error&)
365 done = false;
368 delete p_c;
369 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
370 return done;
373 PB_DS_CLASS_T_DEC
374 bool
375 PB_DS_CLASS_C_DEC::
376 it_constructor_imp(__gnu_pbds::pat_trie_tag)
378 bool done = true;
379 Cntnr* p_c = NULL;
380 m_alloc.set_throw_prob(m_tp);
381 typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size());
385 switch(get_next_sub_op(2))
387 case 0:
388 p_c = new Cntnr(m_p_c->get_e_access_traits());
389 m_native_c.clear();
390 break;
391 case 1:
392 p_c = new Cntnr(m_p_c->begin(), m_p_c->end(),
393 m_p_c->get_e_access_traits());
394 break;
395 default:
396 PB_DS_THROW_IF_FAILED(false, "", m_p_c, & m_native_c);
399 std::swap(p_c, m_p_c);
401 catch (__gnu_cxx::forced_exception_error&)
403 done = false;
406 delete p_c;
407 PB_DS_COND_COMPARE(*m_p_c, m_native_c);
408 return done;