|
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 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <Stiftestinterface.h> |
|
25 #include<iostream> |
|
26 #include<algorithm> |
|
27 #include<vector> |
|
28 #include<iostream> |
|
29 #include<ostream> |
|
30 #include<iterator> |
|
31 #include<numeric> |
|
32 #include <queue> |
|
33 #include <deque> |
|
34 #include <stack> |
|
35 #include<list> |
|
36 #include <string> |
|
37 |
|
38 #include<functional> |
|
39 |
|
40 #include <locale> |
|
41 #include <numeric> |
|
42 #include <valarray> |
|
43 #include<fstream> |
|
44 |
|
45 #include<list> |
|
46 #include<string> |
|
47 #include<cstring> |
|
48 #include<vector> |
|
49 #include<iterator> |
|
50 |
|
51 #include<ios> |
|
52 #include<algorithm> |
|
53 #include <numeric> |
|
54 #include<functional> |
|
55 #include <locale> |
|
56 #include<iostream> |
|
57 #include<memory> |
|
58 #include<complex> |
|
59 #include<map> |
|
60 //#include<set> |
|
61 #include<exception> |
|
62 // #include<bitset> |
|
63 |
|
64 #include <stl/char_traits.h> // fpos |
|
65 #include "tstl_3.h" |
|
66 |
|
67 |
|
68 using namespace std; |
|
69 #define STDCPP_OOM FALSE// TRUE for OOM testing |
|
70 |
|
71 // ============================ MEMBER FUNCTIONS =============================== |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // Ctstl_3::Delete |
|
75 // Delete here all resources allocated and opened from test methods. |
|
76 // Called from destructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void Ctstl_3::Delete() |
|
80 { |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // Ctstl_3::RunMethodL |
|
86 // Run specified method. Contains also table of test mothods and their names. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 TInt Ctstl_3::RunMethodL( |
|
90 CStifItemParser& aItem ) |
|
91 { |
|
92 |
|
93 static TStifFunctionInfo const KFunctions[] = |
|
94 { |
|
95 // Copy this line for every implemented function. |
|
96 // First string is the function name used in TestScripter script file. |
|
97 // Second is the actual implementation member function. |
|
98 ENTRY( "Includes", Ctstl_3::Includes ), |
|
99 ENTRY( "innerproduct", Ctstl_3::innerproduct ), |
|
100 ENTRY( "inplacemerge", Ctstl_3::inplacemerge ), |
|
101 ENTRY( "Queue", Ctstl_3::Queue ), |
|
102 ENTRY( "Pqueue", Ctstl_3::Pqueue ), |
|
103 ENTRY( "stablesortL", Ctstl_3::stablesortL ), |
|
104 ENTRY( "Stack", Ctstl_3::Stack ), |
|
105 ENTRY( "string1_testL", Ctstl_3::string1_testL ), |
|
106 ENTRY("Setintersection", Ctstl_3::Setintersection ), |
|
107 ENTRY("Setsymdifference", Ctstl_3::Setsymdifference ), |
|
108 ENTRY("Setunion", Ctstl_3::Setunion ), |
|
109 ENTRY("HeapL", Ctstl_3::HeapL ), |
|
110 ENTRY("Swapranges", Ctstl_3::Swapranges ), |
|
111 ENTRY("Partialsums", Ctstl_3::Partialsums ), |
|
112 ENTRY("Unarynegate", Ctstl_3::Unarynegate ), |
|
113 ENTRY("Not2", Ctstl_3::Not2), |
|
114 ENTRY("GettemporarybufferL", Ctstl_3::GettemporarybufferL), |
|
115 ENTRY("Pair", Ctstl_3::Pair), |
|
116 ENTRY("Lexicographicalcompare", Ctstl_3::Lexicographicalcompare ), |
|
117 ENTRY("Mismatch", Ctstl_3::Mismatch ), |
|
118 ENTRY("Compare_fun", Ctstl_3::Compare_fun ), |
|
119 ENTRY("Copy_fun", Ctstl_3::Copy_fun ), |
|
120 ENTRY("Copybackward_fun", Ctstl_3::Copybackward_fun ), |
|
121 ENTRY("mergeL", Ctstl_3::mergeL ), |
|
122 ENTRY("allocatoradd", Ctstl_3::allocatoradd ), |
|
123 ENTRY("alldeall", Ctstl_3::alldeall ), |
|
124 ENTRY("allcons", Ctstl_3::allcons ), |
|
125 ENTRY("allrebind", Ctstl_3::allrebind ), |
|
126 ENTRY("allmaxsize", Ctstl_3::allmaxsize ), |
|
127 |
|
128 }; |
|
129 |
|
130 const TInt count = sizeof( KFunctions ) / |
|
131 sizeof( TStifFunctionInfo ); |
|
132 |
|
133 return RunInternalL( KFunctions, count, aItem ); |
|
134 |
|
135 } |
|
136 |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // Ctstl_3::ExampleL |
|
140 // Example test method function. |
|
141 // (other items were commented in a header). |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 |
|
145 bool myfunction (int i, int j) { return i<j; } |
|
146 |
|
147 |
|
148 TInt Ctstl_3::Includes( CStifItemParser& aItem ) |
|
149 { |
|
150 int failures =0; |
|
151 try |
|
152 { |
|
153 |
|
154 |
|
155 int container1[] = {5,10,15,20,25,30,35,40,45,50}; |
|
156 int container2[] = {40,30,20,10}; |
|
157 int container3[]={100,200,300,400,10,20,30,40}; |
|
158 sort (container1,container1+10); |
|
159 sort (container2,container2+4); |
|
160 sort(container3,container3+8); |
|
161 /* |
|
162 if(!includes(container1,container1+10,container3,container3+8)) |
|
163 |
|
164 |
|
165 if ( includes(container1,container1+10,container2,container2+4) ) |
|
166 |
|
167 if ( includes(container1,container1+10,container2,container2+4, myfunction) ) |
|
168 |
|
169 return KErrNone; |
|
170 return KErrGeneral; |
|
171 */ |
|
172 // cout<<""; |
|
173 #if STDCPP_OOM |
|
174 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
175 #endif |
|
176 |
|
177 if(includes(container1,container1+10,container3,container3+8)) |
|
178 failures++; |
|
179 |
|
180 |
|
181 if ( !includes(container1,container1+10,container2,container2+4) ) |
|
182 failures++; |
|
183 |
|
184 if ( !includes(container1,container1+10,container2,container2+4, myfunction) ) |
|
185 failures++; |
|
186 |
|
187 #if STDCPP_OOM |
|
188 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
189 #endif |
|
190 // #if STDCPP_OOM |
|
191 //failures++; |
|
192 // #endif |
|
193 } |
|
194 |
|
195 catch(bad_alloc&) |
|
196 { |
|
197 //do nothing |
|
198 } |
|
199 catch(...) |
|
200 { |
|
201 failures++; |
|
202 |
|
203 } |
|
204 |
|
205 if(failures ) |
|
206 return KErrGeneral; |
|
207 return KErrNone; |
|
208 } |
|
209 // vector<int> myvector (8,10); |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // Ctstl_3::innerproduct |
|
213 // Example test method function. |
|
214 // (other items were commented in a header). |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 TInt Ctstl_3::innerproduct( CStifItemParser& aItem ) |
|
218 { |
|
219 |
|
220 int failures=0; |
|
221 try |
|
222 { |
|
223 |
|
224 |
|
225 typedef vector < int > intArray; |
|
226 typedef ostream_iterator < int, char, char_traits<char> > |
|
227 FloatOstreamIt; |
|
228 |
|
229 |
|
230 |
|
231 FloatOstreamIt itOstream(cout," "); |
|
232 |
|
233 // Initialize the arrays |
|
234 intArray rgF1, rgF2; |
|
235 for (int i=1; i<=5; i++) { |
|
236 rgF1.push_back(i); |
|
237 rgF2.push_back(i*i); |
|
238 }; |
|
239 |
|
240 // Print the arrays |
|
241 |
|
242 copy(rgF1.begin(),rgF1.end(),itOstream); |
|
243 |
|
244 copy(rgF2.begin(),rgF2.end(),itOstream); |
|
245 // cout<<""; |
|
246 #if STDCPP_OOM |
|
247 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
248 #endif |
|
249 // Compute the inner_product of the arrays. This is the |
|
250 // sum of the products (S.O.P) of the corresponding elements |
|
251 |
|
252 int ip1 = inner_product(rgF1.begin(),rgF1.end(),rgF2.begin(),0); |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 int ip2 = inner_product(rgF1.begin(),rgF1.end(),rgF2.begin(),1,multiplies<int>(),plus<int>()); |
|
258 #if STDCPP_OOM |
|
259 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
260 #endif |
|
261 /* if(ip1==225) |
|
262 if(ip2==86400) |
|
263 return KErrNone; |
|
264 return KErrGeneral;*/ |
|
265 |
|
266 // Compute the inner_product of the arrays. This is the |
|
267 // product of the sums (P.O.S.) of the corresponding elements |
|
268 |
|
269 if(ip1!=225) |
|
270 failures++; |
|
271 if(ip2!=86400) |
|
272 failures++; |
|
273 |
|
274 //#if STDCPP_OOM |
|
275 //failures++; |
|
276 // #endif |
|
277 } |
|
278 |
|
279 |
|
280 catch(bad_alloc&) |
|
281 { |
|
282 //do nothing |
|
283 } |
|
284 catch(...) |
|
285 { |
|
286 failures++; |
|
287 |
|
288 } |
|
289 |
|
290 if(failures ) |
|
291 return KErrGeneral; |
|
292 return KErrNone; |
|
293 } |
|
294 |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // Ctstl_3::inplacemerge |
|
298 // Example test method function. |
|
299 // (other items were commented in a header). |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TInt Ctstl_3::inplacemerge( CStifItemParser& aItem ) |
|
303 { |
|
304 int failures=0; |
|
305 try |
|
306 { |
|
307 |
|
308 |
|
309 int first[] = {5,10,15,20,25}; |
|
310 int second[] = {50,40,30,20,10}; |
|
311 vector<int> v(10); |
|
312 vector<int>::iterator it; |
|
313 int a[10]; |
|
314 sort (first,first+5); |
|
315 sort (second,second+5); |
|
316 |
|
317 copy (first,first+5,v.begin()); |
|
318 copy (second,second+5,v.begin()+5); |
|
319 // cout<<""; |
|
320 #if STDCPP_OOM |
|
321 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
322 #endif |
|
323 inplace_merge(v.begin(),v.begin()+5,v.end()); |
|
324 #if STDCPP_OOM |
|
325 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
326 #endif |
|
327 for (it=v.begin(); it!=v.end(); ++it) |
|
328 { |
|
329 static int i; |
|
330 a[i]=*it; |
|
331 i++; |
|
332 } |
|
333 /* |
|
334 if(a[0]==5) |
|
335 if(a[1]==10) |
|
336 if(a[2]==10) |
|
337 if(a[3]==15) |
|
338 if(a[4]==20) |
|
339 if(a[5]==20) |
|
340 if(a[6]==25) |
|
341 if(a[7]==30) |
|
342 if(a[8]==40) |
|
343 if(a[9]==50) |
|
344 return KErrNone; |
|
345 return KErrGeneral; |
|
346 */ |
|
347 |
|
348 if(a[0]!=5) |
|
349 if(a[1]!=10) |
|
350 if(a[2]!=10) |
|
351 if(a[3]!=15) |
|
352 if(a[4]!=20) |
|
353 if(a[5]!=20) |
|
354 if(a[6]!=25) |
|
355 if(a[7]!=30) |
|
356 if(a[8]!=40) |
|
357 if(a[9]!=50) |
|
358 failures++; |
|
359 //#if STDCPP_OOM |
|
360 //failures++; |
|
361 // #endif |
|
362 } |
|
363 |
|
364 catch(bad_alloc&) |
|
365 { |
|
366 //do nothing |
|
367 } |
|
368 catch(...) |
|
369 { |
|
370 failures++; |
|
371 |
|
372 } |
|
373 |
|
374 if(failures ) |
|
375 return KErrGeneral; |
|
376 return KErrNone; |
|
377 } |
|
378 // ----------------------------------------------------------------------------- |
|
379 // Ctstl_3::Queue |
|
380 // Queue test method function. |
|
381 // (other items were commented in a header). |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TInt Ctstl_3::Queue( CStifItemParser& aItem ) |
|
385 { |
|
386 |
|
387 int failures=0; |
|
388 try |
|
389 { |
|
390 |
|
391 |
|
392 int arr[3]; |
|
393 // cout<<""; |
|
394 #if STDCPP_OOM |
|
395 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
396 #endif |
|
397 queue<int,list<int> > q; |
|
398 |
|
399 |
|
400 q.push(1); |
|
401 arr[0]=q.back(); |
|
402 if(q.size()!=1) |
|
403 failures++; |
|
404 if(q.back()!=1) |
|
405 failures++; |
|
406 if(arr[0]!=1) |
|
407 failures++; |
|
408 |
|
409 |
|
410 |
|
411 q.push(2); |
|
412 arr[1]=q.back(); |
|
413 if(q.size()!=2) |
|
414 failures++; |
|
415 if(q.back()!=2) |
|
416 failures++; |
|
417 if(arr[1]!=2) |
|
418 failures++; |
|
419 |
|
420 |
|
421 |
|
422 q.push(3); |
|
423 arr[2]=q.back(); |
|
424 if(q.size()!=3) |
|
425 failures++; |
|
426 if(q.back()!=3) |
|
427 failures++; |
|
428 if(arr[2]!=3) |
|
429 failures++; |
|
430 |
|
431 |
|
432 q.pop(); |
|
433 if(q.size()!=2) |
|
434 failures++; |
|
435 if(q.back()!=3) |
|
436 failures++; |
|
437 if(q.front()!=2) |
|
438 failures++; |
|
439 |
|
440 q.pop(); |
|
441 q.pop(); |
|
442 #if STDCPP_OOM |
|
443 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
444 #endif |
|
445 if(!q.empty()) |
|
446 failures++; |
|
447 |
|
448 /* |
|
449 if(failures) |
|
450 return KErrGeneral; |
|
451 return KErrNone; |
|
452 */ |
|
453 |
|
454 |
|
455 //#if STDCPP_OOM |
|
456 //failures++; |
|
457 // #endif |
|
458 |
|
459 |
|
460 } |
|
461 |
|
462 catch(bad_alloc&) |
|
463 { |
|
464 //do nothing |
|
465 } |
|
466 catch(...) |
|
467 { |
|
468 failures++; |
|
469 |
|
470 } |
|
471 |
|
472 if(failures ) |
|
473 return KErrGeneral; |
|
474 return KErrNone; |
|
475 } |
|
476 |
|
477 // ----------------------------------------------------------------------------- |
|
478 // Ctstl_3::PQueue |
|
479 // PQueue test method function. |
|
480 // (other items were commented in a header). |
|
481 // ----------------------------------------------------------------------------- |
|
482 // |
|
483 |
|
484 TInt Ctstl_3::Pqueue( CStifItemParser& aItem ) |
|
485 { |
|
486 |
|
487 int failures=0; |
|
488 |
|
489 try |
|
490 { |
|
491 |
|
492 |
|
493 int arr[3]; |
|
494 |
|
495 typedef deque<int> d; |
|
496 // cout<<""; |
|
497 #if STDCPP_OOM |
|
498 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
499 #endif |
|
500 priority_queue<int, d, less<int> > q; |
|
501 |
|
502 |
|
503 |
|
504 q.push(1); |
|
505 arr[0]=q.top(); |
|
506 if(q.size()!=1) |
|
507 failures++; |
|
508 if(q.top()!=1) |
|
509 failures++; |
|
510 if(arr[0]!=1) |
|
511 failures++; |
|
512 |
|
513 |
|
514 |
|
515 q.push(2); |
|
516 arr[1]=q.top(); |
|
517 if(q.size()!=2) |
|
518 failures++; |
|
519 if(q.top()!=2) |
|
520 failures++; |
|
521 if(arr[1]!=2) |
|
522 failures++; |
|
523 |
|
524 |
|
525 |
|
526 q.push(3); |
|
527 arr[2]=q.top(); |
|
528 if(q.size()!=3) |
|
529 failures++; |
|
530 if(q.top()!=3) |
|
531 failures++; |
|
532 if(arr[2]!=3) |
|
533 failures++; |
|
534 |
|
535 |
|
536 q.pop(); |
|
537 if(q.size()!=2) |
|
538 failures++; |
|
539 |
|
540 if(q.top()!=2) |
|
541 failures++; |
|
542 |
|
543 q.pop(); |
|
544 q.pop(); |
|
545 |
|
546 if(!q.empty()) |
|
547 failures++; |
|
548 #if STDCPP_OOM |
|
549 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
550 #endif |
|
551 /* |
|
552 if(failures) |
|
553 return KErrGeneral; |
|
554 return KErrNone; |
|
555 |
|
556 */ |
|
557 //#if STDCPP_OOM |
|
558 //failures++; |
|
559 // #endif |
|
560 |
|
561 |
|
562 |
|
563 } |
|
564 |
|
565 catch(bad_alloc&) |
|
566 { |
|
567 //do nothing |
|
568 } |
|
569 catch(...) |
|
570 { |
|
571 failures++; |
|
572 |
|
573 } |
|
574 |
|
575 if(failures ) |
|
576 return KErrGeneral; |
|
577 return KErrNone; |
|
578 } |
|
579 |
|
580 // ----------------------------------------------------------------------------- |
|
581 // Ctstl_3::ExampleL |
|
582 // Example test method function. |
|
583 // (other items were commented in a header). |
|
584 // ----------------------------------------------------------------------------- |
|
585 // |
|
586 |
|
587 |
|
588 bool UDgreater (int elem1, int elem2 ) |
|
589 { |
|
590 return elem1 > elem2; |
|
591 } |
|
592 |
|
593 |
|
594 TInt Ctstl_3::stablesortL( CStifItemParser& aItem ) |
|
595 { |
|
596 int failures=0; |
|
597 try |
|
598 { |
|
599 |
|
600 |
|
601 vector <int> v1; |
|
602 vector <int>::iterator Iter1; |
|
603 |
|
604 int i,a1[12],a2[12],a3[12]; |
|
605 for ( i = 0 ; i <= 5 ; i++ ) |
|
606 { |
|
607 v1.push_back( 2 * i ); |
|
608 } |
|
609 |
|
610 for ( i = 0 ; i <= 5 ; i++ ) |
|
611 { |
|
612 v1.push_back( 2 * i ); |
|
613 } |
|
614 |
|
615 // cout<<""; |
|
616 #if STDCPP_OOM |
|
617 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
618 #endif |
|
619 stable_sort(v1.begin( ), v1.end( ) ); |
|
620 #if STDCPP_OOM |
|
621 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
622 #endif |
|
623 |
|
624 for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) |
|
625 |
|
626 { |
|
627 static int i; |
|
628 a1[i] = *Iter1; |
|
629 i++; |
|
630 } |
|
631 |
|
632 |
|
633 |
|
634 #if STDCPP_OOM |
|
635 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
636 #endif |
|
637 // To sort in descending order, specify binary predicate |
|
638 stable_sort(v1.begin( ), v1.end( ), greater<int>( ) ); |
|
639 #if STDCPP_OOM |
|
640 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
641 #endif |
|
642 for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) |
|
643 { |
|
644 static int i; |
|
645 a2[i]=*Iter1; |
|
646 i++; |
|
647 } |
|
648 |
|
649 #if STDCPP_OOM |
|
650 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
651 #endif |
|
652 // A user-defined (UD) binary predicate can also be used |
|
653 stable_sort(v1.begin( ), v1.end( ), UDgreater ); |
|
654 #if STDCPP_OOM |
|
655 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
656 #endif |
|
657 for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) |
|
658 |
|
659 |
|
660 { |
|
661 static int i; |
|
662 a3[i]=*Iter1; |
|
663 i++; |
|
664 } |
|
665 |
|
666 |
|
667 /* |
|
668 if(a1[0]==0) |
|
669 if(a1[1]==0) |
|
670 if(a1[2]==2) |
|
671 if(a1[3]==2) |
|
672 if(a1[4]==4) |
|
673 if(a1[5]==4) |
|
674 if(a1[6]==6) |
|
675 if(a1[7]==6) |
|
676 if(a1[8]==8) |
|
677 if(a1[9]==8) |
|
678 if(a1[10]==10) |
|
679 if(a1[11]==10) |
|
680 if(a2[0]==a3[0]==10) |
|
681 if(a2[1]==a3[1]==10) |
|
682 if(a2[2]==a3[2]==8) |
|
683 if(a2[3]==a3[3]==8) |
|
684 if(a2[4]==a3[4]==6) |
|
685 if(a2[5]==a3[5]==6) |
|
686 if(a2[6]==a3[6]==4) |
|
687 if(a2[7]==a3[7]==4) |
|
688 if(a2[8]==a3[8]==2) |
|
689 if(a2[9]==a3[9]==2) |
|
690 if(a2[10]==0) |
|
691 if(a3[10]==0) |
|
692 if(a2[11]==0 ) |
|
693 if(a3[11]==0) |
|
694 return KErrNone; |
|
695 return KErrGeneral; |
|
696 */ |
|
697 |
|
698 |
|
699 if(a1[0]!=0) |
|
700 if(a1[1]!=0) |
|
701 if(a1[2]!=2) |
|
702 if(a1[3]!=2) |
|
703 if(a1[4]!=4) |
|
704 if(a1[5]!=4) |
|
705 if(a1[6]!=6) |
|
706 if(a1[7]!=6) |
|
707 if(a1[8]!=8) |
|
708 if(a1[9]!=8) |
|
709 if(a1[10]!=10) |
|
710 if(a1[11]!=10) |
|
711 if(a2[0]!=a3[0]!=10) |
|
712 if(a2[1]!=a3[1]!=10) |
|
713 failures++; |
|
714 |
|
715 //#if STDCPP_OOM |
|
716 //failures++; |
|
717 // #endif |
|
718 |
|
719 } |
|
720 |
|
721 catch(bad_alloc&) |
|
722 { |
|
723 //do nothing |
|
724 } |
|
725 catch(...) |
|
726 { |
|
727 failures++; |
|
728 |
|
729 } |
|
730 |
|
731 if(failures ) |
|
732 return KErrGeneral; |
|
733 return KErrNone; |
|
734 } |
|
735 |
|
736 // ----------------------------------------------------------------------------- |
|
737 // Ctstl_3::ExampleL |
|
738 // Example test method function. |
|
739 // (other items were commented in a header). |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 TInt Ctstl_3::Stack( CStifItemParser& aItem ) |
|
743 { |
|
744 |
|
745 |
|
746 //__UHEAP_MARK; |
|
747 int failures=0,i=0; |
|
748 try |
|
749 { |
|
750 |
|
751 int arr[3]; |
|
752 // cout<<""; |
|
753 #if STDCPP_OOM |
|
754 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
755 #endif |
|
756 stack<int, deque<int> > s; |
|
757 |
|
758 |
|
759 s.push(1); |
|
760 if(s.size()!=1) |
|
761 failures++; |
|
762 arr[0] = s.top(); |
|
763 |
|
764 s.push(2); |
|
765 if(s.size()!=2) |
|
766 failures++; |
|
767 arr[1] = s.top(); |
|
768 |
|
769 s.push(3); |
|
770 if(s.size()!=3) |
|
771 failures++; |
|
772 arr[2] = s.top(); |
|
773 |
|
774 |
|
775 s.pop(); |
|
776 |
|
777 if(s.size()!=2) |
|
778 failures++; |
|
779 if(s.top()!=2) |
|
780 failures++; |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 if(1!=arr[0]) |
|
789 failures++; |
|
790 if(2!=arr[1]) |
|
791 failures++; |
|
792 |
|
793 #if STDCPP_OOM |
|
794 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
795 #endif |
|
796 /* |
|
797 if(failures) |
|
798 |
|
799 return KErrGeneral; |
|
800 return KErrNone; |
|
801 */ |
|
802 //__UHEAP_MARKEND; |
|
803 |
|
804 //#if STDCPP_OOM |
|
805 //failures++; |
|
806 // #endif |
|
807 } |
|
808 |
|
809 |
|
810 catch(std::bad_alloc&) |
|
811 { |
|
812 //do nothing |
|
813 } |
|
814 catch(...) |
|
815 { |
|
816 failures++; |
|
817 |
|
818 } |
|
819 |
|
820 if(failures ) |
|
821 return KErrGeneral; |
|
822 return KErrNone; |
|
823 } |
|
824 |
|
825 |
|
826 |
|
827 // ----------------------------------------------------------------------------- |
|
828 // Ctstl_3::string1_testL |
|
829 // Example test method function. |
|
830 // (other items were commented in a header). |
|
831 // ----------------------------------------------------------------------------- |
|
832 // |
|
833 TInt Ctstl_3::string1_testL( CStifItemParser& /*aItem*/ ) |
|
834 { |
|
835 |
|
836 |
|
837 //__UHEAP_MARK; |
|
838 int failures=0; |
|
839 try |
|
840 { |
|
841 |
|
842 |
|
843 char* array = "Hello, World!"; |
|
844 // cout<<""; |
|
845 #if STDCPP_OOM |
|
846 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
847 #endif |
|
848 std::string v(array); |
|
849 int i; |
|
850 |
|
851 if(v.compare("Hello, World!")) |
|
852 failures++; |
|
853 |
|
854 v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last. |
|
855 for(i = 0; i < v.size(); i++) |
|
856 |
|
857 if('H'!=v[0]) |
|
858 failures++; |
|
859 else if('!'!=v[1]) |
|
860 failures++; |
|
861 |
|
862 |
|
863 v.insert(1, (char*)array); |
|
864 v.erase(v.begin()); // Erase first element. |
|
865 v.erase(v.end() - 1); // Erase last element. |
|
866 if(v.compare("Hello, World!")) |
|
867 failures++; |
|
868 v.clear(); // Erase all. |
|
869 |
|
870 #if STDCPP_OOM |
|
871 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
872 #endif |
|
873 /* |
|
874 if(failures) |
|
875 return KErrGeneral; |
|
876 else |
|
877 return KErrNone; |
|
878 */ |
|
879 //#if STDCPP_OOM |
|
880 //failures++; |
|
881 // #endif |
|
882 |
|
883 // __UHEAP_MARKEND; |
|
884 |
|
885 } |
|
886 |
|
887 |
|
888 catch(bad_alloc&) |
|
889 { |
|
890 //do nothing |
|
891 } |
|
892 catch(...) |
|
893 { |
|
894 failures++; |
|
895 |
|
896 } |
|
897 |
|
898 if(failures ) |
|
899 return KErrGeneral; |
|
900 return KErrNone; |
|
901 } |
|
902 |
|
903 |
|
904 |
|
905 string func( const string& par ) |
|
906 { |
|
907 string tmp( par ); |
|
908 |
|
909 return tmp; |
|
910 } |
|
911 |
|
912 |
|
913 //#if defined (_STLP_PTHREADS) |
|
914 void *f( void * ) |
|
915 //#elif defined (_STLP_WIN32THREADS) |
|
916 //DWORD __stdcall f (void *) |
|
917 //#endif |
|
918 { |
|
919 string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" ); |
|
920 |
|
921 for ( int i = 0; i < 2000000; ++i ) { |
|
922 string sx = func( s ); |
|
923 } |
|
924 |
|
925 return KErrNone; |
|
926 } |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 TInt Ctstl_3::Setintersection(CStifItemParser& aItem) |
|
933 { |
|
934 int failures=0; |
|
935 try{ |
|
936 //__UHEAP_MARK; |
|
937 |
|
938 int first[] = {5,10,15,20,25}; |
|
939 int second[] = {50,40,30,20,10}; |
|
940 int output[10]; |
|
941 vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 |
|
942 vector<int>::iterator it; |
|
943 |
|
944 sort (first,first+5); // 5 10 15 20 25 |
|
945 sort (second,second+5); // 10 20 30 40 50 |
|
946 // cout<<""; |
|
947 #if STDCPP_OOM |
|
948 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
949 #endif |
|
950 it=set_intersection (first, first+5, second, second+5, v.begin()); |
|
951 #if STDCPP_OOM |
|
952 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
953 #endif // 10 20 0 0 0 0 0 0 0 0 |
|
954 |
|
955 for(it=v.begin();it!=v.end();++it) |
|
956 { |
|
957 |
|
958 static int i; |
|
959 output[i] = *it; |
|
960 i++; |
|
961 |
|
962 } |
|
963 /* |
|
964 if(output[0]==10) |
|
965 if(output[1]==20) |
|
966 if(output[2]==0) |
|
967 return KErrNone; |
|
968 return KErrGeneral; |
|
969 |
|
970 */ |
|
971 |
|
972 if(output[0]!=10) |
|
973 failures++; |
|
974 if(output[1]!=20) |
|
975 failures++; |
|
976 if(output[2]!=0) |
|
977 failures++; |
|
978 |
|
979 //#if STDCPP_OOM |
|
980 //failures++; |
|
981 // #endif |
|
982 } |
|
983 |
|
984 catch(bad_alloc&) |
|
985 { |
|
986 //do nothing |
|
987 } |
|
988 catch(...) |
|
989 { |
|
990 failures++; |
|
991 |
|
992 } |
|
993 |
|
994 if(failures ) |
|
995 return KErrGeneral; |
|
996 return KErrNone; |
|
997 } |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 TInt Ctstl_3::Setsymdifference(CStifItemParser& aItem) |
|
1003 {int failures=0; |
|
1004 try{ |
|
1005 |
|
1006 //__UHEAP_MARK; |
|
1007 |
|
1008 int first[] = {5,10,15,20,25}; |
|
1009 int second[] = {50,40,30,20,10}; |
|
1010 int output[10]; |
|
1011 vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 |
|
1012 vector<int>::iterator it; |
|
1013 |
|
1014 sort (first,first+5); // 5 10 15 20 25 |
|
1015 sort (second,second+5); // 10 20 30 40 50 |
|
1016 // cout<<""; |
|
1017 #if STDCPP_OOM |
|
1018 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1019 #endif |
|
1020 it=set_symmetric_difference(first, first+5, second, second+5, v.begin()); |
|
1021 #if STDCPP_OOM |
|
1022 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1023 #endif |
|
1024 for(it=v.begin();it!=v.end();++it) |
|
1025 { |
|
1026 |
|
1027 static int i; |
|
1028 output[i] = *it; |
|
1029 i++; |
|
1030 |
|
1031 } |
|
1032 |
|
1033 |
|
1034 /* |
|
1035 if(output[0]==5) |
|
1036 if(output[1]==15) |
|
1037 if(output[2]==25) |
|
1038 if(output[3]==30) |
|
1039 if(output[4]==40) |
|
1040 if(output[5]==50) |
|
1041 return KErrNone; |
|
1042 return KErrGeneral; |
|
1043 */// __UHEAP_MARKEND; |
|
1044 |
|
1045 |
|
1046 if(output[0]!=5) |
|
1047 failures++; |
|
1048 if(output[1]!=15) |
|
1049 failures++; |
|
1050 if(output[2]!=25) |
|
1051 failures++; |
|
1052 if(output[3]!=30) |
|
1053 failures++; |
|
1054 if(output[4]!=40) |
|
1055 failures++; |
|
1056 if(output[5]!=50) |
|
1057 failures++; |
|
1058 |
|
1059 //#if STDCPP_OOM |
|
1060 //failures++; |
|
1061 // #endif |
|
1062 } |
|
1063 |
|
1064 catch(bad_alloc&) |
|
1065 { |
|
1066 //do nothing |
|
1067 } |
|
1068 catch(...) |
|
1069 { |
|
1070 failures++; |
|
1071 |
|
1072 } |
|
1073 |
|
1074 if(failures ) |
|
1075 return KErrGeneral; |
|
1076 return KErrNone; |
|
1077 } |
|
1078 |
|
1079 TInt Ctstl_3::Setunion(CStifItemParser& aItem) |
|
1080 { |
|
1081 int failures=0; |
|
1082 |
|
1083 //__UHEAP_MARK; |
|
1084 try{ |
|
1085 int first[] = {5,10,15,20,25}; |
|
1086 int second[] = {50,40,30,20,10}; |
|
1087 int output[10]; |
|
1088 vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 |
|
1089 vector<int>::iterator it; |
|
1090 |
|
1091 sort (first,first+5); // 5 10 15 20 25 |
|
1092 sort (second,second+5); // 10 20 30 40 50 |
|
1093 // cout<<""; |
|
1094 #if STDCPP_OOM |
|
1095 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1096 #endif |
|
1097 it=set_union(first, first+5, second, second+5, v.begin()); |
|
1098 #if STDCPP_OOM |
|
1099 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1100 #endif |
|
1101 for(it=v.begin();it!=v.end();++it) |
|
1102 { |
|
1103 |
|
1104 static int i; |
|
1105 output[i] = *it; |
|
1106 i++; |
|
1107 |
|
1108 }/* |
|
1109 if(output[0]==5) |
|
1110 if(output[1]==10) |
|
1111 if(output[2]==15) |
|
1112 if(output[3]==20) |
|
1113 if(output[4]==25) |
|
1114 if(output[5]==30) |
|
1115 if(output[6]==40) |
|
1116 if(output[7]==50) |
|
1117 return KErrNone; |
|
1118 return KErrGeneral;*/ |
|
1119 //__UHEAP_MARKEND; |
|
1120 |
|
1121 if(output[0]!=5) |
|
1122 failures++; |
|
1123 |
|
1124 if(output[1]!=10) |
|
1125 failures++; |
|
1126 |
|
1127 if(output[2]!=15) |
|
1128 failures++; |
|
1129 if(output[3]!=20) |
|
1130 failures++; |
|
1131 if(output[4]!=25) |
|
1132 failures++; |
|
1133 if(output[5]!=30) |
|
1134 failures++; |
|
1135 if(output[6]!=40) |
|
1136 failures++; |
|
1137 if(output[7]!=50) |
|
1138 failures++; |
|
1139 |
|
1140 |
|
1141 //#if STDCPP_OOM |
|
1142 //failures++; |
|
1143 // #endif |
|
1144 } |
|
1145 catch(bad_alloc&) |
|
1146 { |
|
1147 //do nothing |
|
1148 } |
|
1149 catch(...) |
|
1150 { |
|
1151 failures++; |
|
1152 |
|
1153 } |
|
1154 |
|
1155 if(failures ) |
|
1156 return KErrGeneral; |
|
1157 return KErrNone; |
|
1158 } |
|
1159 |
|
1160 |
|
1161 |
|
1162 TInt Ctstl_3::HeapL(CStifItemParser& aItem) |
|
1163 { |
|
1164 |
|
1165 |
|
1166 //__UHEAP_MARK; |
|
1167 |
|
1168 |
|
1169 int failures=0; |
|
1170 try{ |
|
1171 int myints[] = {10,20,30,5,15}; |
|
1172 |
|
1173 vector<int> v(myints,myints+5); |
|
1174 |
|
1175 // vector<int>::iterator it; |
|
1176 // cout<<""; |
|
1177 #if STDCPP_OOM |
|
1178 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1179 #endif |
|
1180 make_heap(v.begin(),v.end()); //make_heap |
|
1181 |
|
1182 if(v.front()!=30) |
|
1183 failures++; |
|
1184 |
|
1185 pop_heap(v.begin(),v.end()); //pop_heap |
|
1186 v.pop_back(); //pop_back |
|
1187 |
|
1188 |
|
1189 if(v.front()!=20) |
|
1190 failures++; |
|
1191 |
|
1192 v.push_back(99); //push_back |
|
1193 |
|
1194 |
|
1195 push_heap(v.begin(),v.end()); //push heap |
|
1196 |
|
1197 if(v.front()!=99) |
|
1198 failures++; |
|
1199 |
|
1200 |
|
1201 sort_heap(v.begin(),v.end()); //sort_heap |
|
1202 |
|
1203 #if STDCPP_OOM |
|
1204 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1205 #endif |
|
1206 if(v[0]!=5) |
|
1207 failures++; |
|
1208 if(v[1]!=10) |
|
1209 failures++; |
|
1210 if(v[2]!=15) |
|
1211 failures++; |
|
1212 if(v[3]!=20) |
|
1213 failures++; |
|
1214 if(v[4]!=99) |
|
1215 failures++; |
|
1216 |
|
1217 |
|
1218 /* |
|
1219 if(failures) |
|
1220 return KErrGeneral; |
|
1221 return KErrNone; |
|
1222 */ |
|
1223 //#if STDCPP_OOM |
|
1224 //failures++; |
|
1225 // #endif |
|
1226 |
|
1227 //__UHEAP_MARKEND; |
|
1228 |
|
1229 } |
|
1230 |
|
1231 catch(bad_alloc&) |
|
1232 { |
|
1233 //do nothing |
|
1234 } |
|
1235 catch(...) |
|
1236 { |
|
1237 failures++; |
|
1238 |
|
1239 } |
|
1240 |
|
1241 if(failures ) |
|
1242 return KErrGeneral; |
|
1243 return KErrNone; |
|
1244 } |
|
1245 |
|
1246 |
|
1247 TInt Ctstl_3::Swapranges(CStifItemParser& aItem) |
|
1248 { |
|
1249 int failures=0; |
|
1250 // __UHEAP_MARK; |
|
1251 try{ |
|
1252 |
|
1253 vector<int> first (5,10); // first: 10 10 10 10 10 |
|
1254 vector<int> second (5,33); // second: 33 33 33 33 33 |
|
1255 vector<int>::iterator it; |
|
1256 int output[5]; |
|
1257 // cout<<""; |
|
1258 #if STDCPP_OOM |
|
1259 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1260 #endif |
|
1261 swap_ranges(first.begin()+1, first.end()-1, second.begin()); |
|
1262 #if STDCPP_OOM |
|
1263 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1264 #endif |
|
1265 |
|
1266 |
|
1267 // print out results of swap: |
|
1268 for (it=first.begin(); it!=first.end(); ++it) |
|
1269 |
|
1270 |
|
1271 { |
|
1272 static int i; |
|
1273 output[i] = *it; |
|
1274 i++; |
|
1275 } |
|
1276 |
|
1277 |
|
1278 /* |
|
1279 if(output[0]==10) |
|
1280 if(output[1]==33) |
|
1281 if(output[2]==33) |
|
1282 if(output[3]==33) |
|
1283 if(output[4]==10) |
|
1284 return KErrNone; |
|
1285 return KErrGeneral; |
|
1286 */ |
|
1287 if(output[0]!=10) |
|
1288 failures++; |
|
1289 if(output[1]!=33) |
|
1290 failures++; |
|
1291 if(output[2]!=33) |
|
1292 failures++; |
|
1293 |
|
1294 if(output[3]!=33) |
|
1295 failures++; |
|
1296 if(output[4]!=10) |
|
1297 failures++; |
|
1298 |
|
1299 //#if STDCPP_OOM |
|
1300 //failures++; |
|
1301 // #endif |
|
1302 |
|
1303 //__UHEAP_MARKEND; |
|
1304 |
|
1305 } |
|
1306 |
|
1307 catch(bad_alloc&) |
|
1308 { |
|
1309 //do nothing |
|
1310 } |
|
1311 catch(...) |
|
1312 { |
|
1313 failures++; |
|
1314 |
|
1315 } |
|
1316 |
|
1317 if(failures ) |
|
1318 return KErrGeneral; |
|
1319 return KErrNone; |
|
1320 } |
|
1321 |
|
1322 |
|
1323 TInt Ctstl_3::Partialsums(CStifItemParser& aItem) |
|
1324 { |
|
1325 int failures=0; |
|
1326 //__UHEAP_MARK; |
|
1327 try{ |
|
1328 |
|
1329 vector<int> V1( 10 ), V2( 10 ); |
|
1330 vector<int>::iterator VIter1, VIterend; |
|
1331 |
|
1332 int sum =1; |
|
1333 int i=2 ; |
|
1334 list <int> L1; |
|
1335 list <int>::iterator LIter1, LIterend; |
|
1336 |
|
1337 int t; |
|
1338 for ( t = 1 ; t <= 10 ; t++ ) |
|
1339 { |
|
1340 L1.push_back( t ); |
|
1341 } |
|
1342 |
|
1343 // cout<<""; |
|
1344 #if STDCPP_OOM |
|
1345 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1346 #endif |
|
1347 // The first member function for the partial sums of |
|
1348 // elements in a list output to a vector |
|
1349 VIterend = partial_sum ( L1.begin ( ) , L1.end ( ) , |
|
1350 V1.begin ( ) ); |
|
1351 #if STDCPP_OOM |
|
1352 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1353 #endif |
|
1354 for ( VIter1 = V1.begin( ) ; VIter1 != VIterend ; VIter1++ ) |
|
1355 |
|
1356 { |
|
1357 |
|
1358 if(sum!=*VIter1) |
|
1359 failures++; |
|
1360 sum = sum+i; |
|
1361 i++; |
|
1362 |
|
1363 } |
|
1364 |
|
1365 /* |
|
1366 if(failures) |
|
1367 return KErrGeneral; |
|
1368 return KErrNone; |
|
1369 */ |
|
1370 |
|
1371 //#if STDCPP_OOM |
|
1372 //failures++; |
|
1373 // #endif |
|
1374 |
|
1375 //__UHEAP_MARKEND; |
|
1376 |
|
1377 } |
|
1378 |
|
1379 catch(bad_alloc&) |
|
1380 { |
|
1381 //do nothing |
|
1382 } |
|
1383 catch(...) |
|
1384 { |
|
1385 failures++; |
|
1386 |
|
1387 } |
|
1388 |
|
1389 if(failures ) |
|
1390 return KErrGeneral; |
|
1391 return KErrNone; |
|
1392 } |
|
1393 |
|
1394 |
|
1395 TInt Ctstl_3::Unarynegate(CStifItemParser& aItem) |
|
1396 { |
|
1397 int failures=0; |
|
1398 // __UHEAP_MARK; |
|
1399 try{ |
|
1400 vector <int> v1; |
|
1401 |
|
1402 //vector <int>::iterator Iter; |
|
1403 |
|
1404 int i; |
|
1405 for ( i = 0 ; i <= 7 ; i++ ) |
|
1406 { |
|
1407 v1.push_back( 5 * i ); |
|
1408 } |
|
1409 |
|
1410 |
|
1411 |
|
1412 int result2; |
|
1413 int result3; |
|
1414 // Use the negator to count the elements less than or equal to 10 |
|
1415 // cout<<""; |
|
1416 #if STDCPP_OOM |
|
1417 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1418 #endif |
|
1419 result2 = count_if( v1.begin( ), v1.end( ),unary_negate<binder2nd <greater<int> > >( bind2nd( greater<int>( ),10 ) ) ); |
|
1420 #if STDCPP_OOM |
|
1421 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1422 #endif |
|
1423 result3 = count_if( v1.begin( ), v1.end( ),not1(bind2nd( greater<int>( ), 10) ) ); |
|
1424 |
|
1425 |
|
1426 |
|
1427 /* |
|
1428 if(result2 == 3) |
|
1429 if(result3 == 3) |
|
1430 return KErrNone; |
|
1431 return KErrGeneral; |
|
1432 */ |
|
1433 if(result2 != 3) |
|
1434 failures++; |
|
1435 if(result3 != 3) |
|
1436 failures++; |
|
1437 |
|
1438 |
|
1439 //__UHEAP_MARKEND; |
|
1440 //#if STDCPP_OOM |
|
1441 //failures++; |
|
1442 // #endif |
|
1443 } |
|
1444 |
|
1445 catch(bad_alloc&) |
|
1446 { |
|
1447 //do nothing |
|
1448 } |
|
1449 catch(...) |
|
1450 { |
|
1451 failures++; |
|
1452 |
|
1453 } |
|
1454 |
|
1455 if(failures ) |
|
1456 return KErrGeneral; |
|
1457 return KErrNone; |
|
1458 } |
|
1459 |
|
1460 |
|
1461 TInt Ctstl_3::Not2(CStifItemParser& aItem) |
|
1462 { |
|
1463 int failures=0; |
|
1464 //__UHEAP_MARK; |
|
1465 try{ |
|
1466 vector <int> v1; |
|
1467 vector <int>::iterator Iter1; |
|
1468 int output[7]; |
|
1469 //int i; |
|
1470 v1.push_back( 6262 ); |
|
1471 v1.push_back( 6262 ); |
|
1472 v1.push_back( 18467 ); |
|
1473 v1.push_back( 6334 ); |
|
1474 v1.push_back( 26500 ); |
|
1475 v1.push_back( 19169); |
|
1476 v1.push_back(41); |
|
1477 |
|
1478 |
|
1479 |
|
1480 // cout<<""; |
|
1481 #if STDCPP_OOM |
|
1482 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1483 #endif |
|
1484 |
|
1485 // To sort in descending order, |
|
1486 // use the binary_negate helper function not2 |
|
1487 sort( v1.begin( ), v1.end( ), not2(less<int>( ) ) ); |
|
1488 |
|
1489 #if STDCPP_OOM |
|
1490 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1491 #endif |
|
1492 |
|
1493 for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) |
|
1494 { |
|
1495 static int i; |
|
1496 output[i] = *Iter1; |
|
1497 i++; |
|
1498 } |
|
1499 |
|
1500 /* |
|
1501 if(output[0]==26500) |
|
1502 if(output[1]==19169) |
|
1503 if(output[2]== 18467) |
|
1504 if(output[3]== 6334) |
|
1505 if(output[4]== 6262) |
|
1506 if(output[5]== 6262) |
|
1507 if(output[6]== 41) |
|
1508 |
|
1509 return KErrNone; |
|
1510 return KErrGeneral; |
|
1511 */ |
|
1512 |
|
1513 |
|
1514 if(output[0]!=26500) |
|
1515 failures++; |
|
1516 if(output[1]!=19169) |
|
1517 failures++; |
|
1518 if(output[2]!= 18467) |
|
1519 failures++; |
|
1520 if(output[3]!= 6334) |
|
1521 failures++; |
|
1522 if(output[4]!= 6262) |
|
1523 failures++; |
|
1524 if(output[5]!= 6262) |
|
1525 failures++; |
|
1526 if(output[6]!= 41) |
|
1527 failures++; |
|
1528 |
|
1529 //#if STDCPP_OOM |
|
1530 //failures++; |
|
1531 // #endif |
|
1532 |
|
1533 //__UHEAP_MARKEND; |
|
1534 |
|
1535 } |
|
1536 |
|
1537 catch(bad_alloc&) |
|
1538 { |
|
1539 //do nothing |
|
1540 } |
|
1541 catch(...) |
|
1542 { |
|
1543 failures++; |
|
1544 |
|
1545 } |
|
1546 |
|
1547 if(failures ) |
|
1548 return KErrGeneral; |
|
1549 return KErrNone; |
|
1550 } |
|
1551 |
|
1552 |
|
1553 |
|
1554 TInt Ctstl_3::GettemporarybufferL(CStifItemParser& aItem) |
|
1555 { |
|
1556 int failures=0; |
|
1557 //__UHEAP_MARK; |
|
1558 try{ |
|
1559 // Create an array of ints |
|
1560 int intArray [ ] = { 10, 20, 30, 40, 100, 200, 300, 1000, 2000 }; |
|
1561 int count = sizeof ( intArray ) / sizeof ( int ); |
|
1562 |
|
1563 |
|
1564 pair<int *, ptrdiff_t> resultPair; |
|
1565 // cout<<""; |
|
1566 #if STDCPP_OOM |
|
1567 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1568 #endif |
|
1569 resultPair = get_temporary_buffer<int>( count ); |
|
1570 #if STDCPP_M |
|
1571 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1572 #endif |
|
1573 |
|
1574 int* tempBuffer = resultPair.first; |
|
1575 |
|
1576 return_temporary_buffer(tempBuffer); |
|
1577 /* |
|
1578 if(count==9) |
|
1579 if(resultPair.second == 9) |
|
1580 return KErrNone; |
|
1581 return KErrGeneral; |
|
1582 */ |
|
1583 if(count!=9) |
|
1584 failures++; |
|
1585 #if STDCPP_OOM |
|
1586 if(resultPair.second!=0) |
|
1587 #else |
|
1588 if(resultPair.second!=9) |
|
1589 #endif |
|
1590 failures++; |
|
1591 |
|
1592 |
|
1593 //#if STDCPP_OOM |
|
1594 //failures++; |
|
1595 // #endif |
|
1596 // __UHEAP_MARKEND; |
|
1597 |
|
1598 } |
|
1599 |
|
1600 catch(bad_alloc&) |
|
1601 { |
|
1602 //do nothing |
|
1603 } |
|
1604 catch(...) |
|
1605 { |
|
1606 failures++; |
|
1607 |
|
1608 } |
|
1609 |
|
1610 if(failures ) |
|
1611 return KErrGeneral; |
|
1612 return KErrNone; |
|
1613 } |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 TInt Ctstl_3::Pair(CStifItemParser& aItem) |
|
1619 { |
|
1620 |
|
1621 //__UHEAP_MARK; |
|
1622 |
|
1623 int failures=0; |
|
1624 try{ |
|
1625 |
|
1626 // cout<<""; |
|
1627 #if STDCPP_OOM |
|
1628 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1629 #endif |
|
1630 typedef struct pair<int, float> PAIR_IF; |
|
1631 |
|
1632 PAIR_IF A(10,3.14f); |
|
1633 PAIR_IF B(18,3.14f); |
|
1634 PAIR_IF C(10,6.28f); |
|
1635 PAIR_IF D(10,3.14f); |
|
1636 |
|
1637 #if STDCPP_OOM |
|
1638 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1639 #endif |
|
1640 |
|
1641 if (A==D) |
|
1642 |
|
1643 if (B!=C) |
|
1644 |
|
1645 if (A>C) |
|
1646 failures++; |
|
1647 |
|
1648 |
|
1649 if (A>=C) |
|
1650 failures++; |
|
1651 |
|
1652 |
|
1653 /* |
|
1654 if(failures) |
|
1655 return KErrGeneral; |
|
1656 return KErrNone; |
|
1657 */ |
|
1658 //#if STDCPP_OOM |
|
1659 //failures++; |
|
1660 // #endif |
|
1661 |
|
1662 |
|
1663 //__UHEAP_MARKEND; |
|
1664 |
|
1665 } |
|
1666 |
|
1667 |
|
1668 catch(bad_alloc&) |
|
1669 { |
|
1670 //do nothing |
|
1671 } |
|
1672 catch(...) |
|
1673 { |
|
1674 failures++; |
|
1675 |
|
1676 } |
|
1677 |
|
1678 if(failures ) |
|
1679 return KErrGeneral; |
|
1680 return KErrNone; |
|
1681 } |
|
1682 |
|
1683 |
|
1684 |
|
1685 bool twice ( int elem1, int elem2 ) |
|
1686 { |
|
1687 return 2 * elem1 < elem2; |
|
1688 } |
|
1689 |
|
1690 |
|
1691 TInt Ctstl_3::Lexicographicalcompare(CStifItemParser& aItem) |
|
1692 { |
|
1693 |
|
1694 //__UHEAP_MARK; |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 int failures=0; |
|
1700 |
|
1701 try |
|
1702 { |
|
1703 |
|
1704 vector <int> v1, v2; |
|
1705 list <int> L1; |
|
1706 vector <int>::iterator Iter1, Iter2; |
|
1707 list <int>::iterator L1_Iter, L1_inIter; |
|
1708 |
|
1709 int i; |
|
1710 for ( i = 0 ; i <= 5 ; i++ ) |
|
1711 { |
|
1712 v1.push_back( 5 * i ); |
|
1713 } |
|
1714 int ii; |
|
1715 for ( ii = 0 ; ii <= 6 ; ii++ ) |
|
1716 { |
|
1717 L1.push_back( 5 * ii ); |
|
1718 } |
|
1719 |
|
1720 int iii; |
|
1721 for ( iii = 0 ; iii <= 5 ; iii++ ) |
|
1722 { |
|
1723 v2.push_back( 10 * iii ); |
|
1724 } |
|
1725 |
|
1726 |
|
1727 // Self lexicographical_comparison of v1 under identity |
|
1728 bool result1; |
|
1729 // cout<<""; |
|
1730 #if STDCPP_OOM |
|
1731 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1732 #endif |
|
1733 |
|
1734 result1 = lexicographical_compare (v1.begin( ), v1.end( ), v1.begin( ), v1.end( ) ); |
|
1735 |
|
1736 |
|
1737 |
|
1738 // lexicographical_comparison of v1 and L2 under identity |
|
1739 bool result2; |
|
1740 result2 = lexicographical_compare (v1.begin( ), v1.end( ), L1.begin( ), L1.end( ) ); |
|
1741 |
|
1742 |
|
1743 |
|
1744 bool result3; |
|
1745 result3 = lexicographical_compare (v1.begin( ), v1.end( ), v2.begin( ), v2.end( ), twice ); |
|
1746 #if STDCPP_OOM |
|
1747 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1748 #endif |
|
1749 /* |
|
1750 if (!result1) |
|
1751 if ( result2 ) |
|
1752 if (!result3 ) |
|
1753 |
|
1754 return KErrNone; |
|
1755 return KErrGeneral; |
|
1756 |
|
1757 */ |
|
1758 |
|
1759 if(result1) |
|
1760 failures++; |
|
1761 if(!result2) |
|
1762 failures++; |
|
1763 if(result3) |
|
1764 failures++; |
|
1765 |
|
1766 //#if STDCPP_OOM |
|
1767 //failures++; |
|
1768 // #endif |
|
1769 |
|
1770 // __UHEAP_MARKEND; |
|
1771 |
|
1772 } |
|
1773 catch(bad_alloc&) |
|
1774 { |
|
1775 //do nothing |
|
1776 } |
|
1777 catch(...) |
|
1778 { |
|
1779 failures++; |
|
1780 |
|
1781 } |
|
1782 |
|
1783 if(failures ) |
|
1784 return KErrGeneral; |
|
1785 return KErrNone; |
|
1786 } |
|
1787 |
|
1788 //Mismatch |
|
1789 |
|
1790 bool mypredicate (int i, int j) { |
|
1791 return (i==j); |
|
1792 } |
|
1793 |
|
1794 |
|
1795 |
|
1796 TInt Ctstl_3::Mismatch(CStifItemParser& aItem) |
|
1797 { |
|
1798 |
|
1799 // __UHEAP_MARK; |
|
1800 |
|
1801 |
|
1802 int failures=0; |
|
1803 try{ |
|
1804 |
|
1805 vector<int> myvector; |
|
1806 for (int i=1; i<6; i++) myvector.push_back (i*10); // myvector: 10 20 30 40 50 |
|
1807 |
|
1808 int myints[] = {10,20,80,320,1024}; // myints: 10 20 80 320 1024 |
|
1809 |
|
1810 pair<vector<int>::iterator,int*> mypair; |
|
1811 // cout<<""; |
|
1812 #if STDCPP_OOM |
|
1813 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1814 #endif |
|
1815 // using default comparison: |
|
1816 mypair = mismatch (myvector.begin(), myvector.end(), myints); |
|
1817 // cout<<""; |
|
1818 #if STDCPP_OOM |
|
1819 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1820 #endif |
|
1821 if(*mypair.first != 30) |
|
1822 failures++; |
|
1823 |
|
1824 if(*mypair.second != 80) |
|
1825 failures++; |
|
1826 |
|
1827 |
|
1828 mypair.first++; |
|
1829 mypair.second++; |
|
1830 #if STDCPP_OOM |
|
1831 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1832 #endif |
|
1833 // using predicate comparison: |
|
1834 mypair = mismatch (mypair.first, myvector.end(), mypair.second, mypredicate); |
|
1835 #if STDCPP_OOM |
|
1836 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1837 #endif |
|
1838 if(*mypair.first != 40) |
|
1839 failures++; |
|
1840 if(*mypair.second != 320) |
|
1841 failures++; |
|
1842 /* |
|
1843 if(failures) |
|
1844 return KErrGeneral; |
|
1845 return KErrNone; |
|
1846 */ |
|
1847 //#if STDCPP_OOM |
|
1848 //failures++; |
|
1849 // #endif |
|
1850 |
|
1851 // __UHEAP_MARKEND; |
|
1852 |
|
1853 } |
|
1854 |
|
1855 catch(bad_alloc&) |
|
1856 { |
|
1857 //do nothing |
|
1858 } |
|
1859 catch(...) |
|
1860 { |
|
1861 failures++; |
|
1862 |
|
1863 } |
|
1864 |
|
1865 if(failures ) |
|
1866 return KErrGeneral; |
|
1867 return KErrNone; |
|
1868 } |
|
1869 |
|
1870 |
|
1871 TInt Ctstl_3::Compare_fun(CStifItemParser& aItem) |
|
1872 |
|
1873 { |
|
1874 int failures=0; |
|
1875 //__UHEAP_MARK; |
|
1876 try |
|
1877 { |
|
1878 |
|
1879 |
|
1880 string str1 ("green apple"); |
|
1881 string str2 ("red apple"); |
|
1882 // cout<<""; |
|
1883 #if STDCPP_OOM |
|
1884 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1885 #endif |
|
1886 if (str1.compare("str2") == 0) |
|
1887 failures++; |
|
1888 |
|
1889 if (str1.compare(6,5,"apple") != 0) |
|
1890 failures++; |
|
1891 |
|
1892 if (str2.compare(str2.size()-5,5,"apple") != 0) |
|
1893 |
|
1894 failures++; |
|
1895 |
|
1896 |
|
1897 if (str1.compare(6,5,str2,4,5) != 0) |
|
1898 failures++; |
|
1899 #if STDCPP_OOM |
|
1900 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1901 #endif |
|
1902 /* |
|
1903 if(failures) |
|
1904 |
|
1905 return KErrGeneral; |
|
1906 return KErrNone; |
|
1907 */ |
|
1908 //__UHEAP_MARKEND; |
|
1909 //#if STDCPP_OOM |
|
1910 //failures++; |
|
1911 // #endif |
|
1912 } |
|
1913 |
|
1914 catch(bad_alloc&) |
|
1915 { |
|
1916 //do nothing |
|
1917 } |
|
1918 catch(...) |
|
1919 { |
|
1920 failures++; |
|
1921 |
|
1922 } |
|
1923 |
|
1924 if(failures ) |
|
1925 return KErrGeneral; |
|
1926 return KErrNone; |
|
1927 } |
|
1928 |
|
1929 |
|
1930 |
|
1931 TInt Ctstl_3::Copy_fun(CStifItemParser& aItem) |
|
1932 |
|
1933 { |
|
1934 int failures=0; |
|
1935 // __UHEAP_MARK; |
|
1936 try |
|
1937 { |
|
1938 int myints[]={10,20,30,40,50,60,70}; |
|
1939 vector<int> myvector; |
|
1940 vector<int>::iterator it; |
|
1941 int a[7]; |
|
1942 |
|
1943 myvector.resize(7); |
|
1944 // cout<<""; |
|
1945 #if STDCPP_OOM |
|
1946 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
1947 #endif |
|
1948 copy ( myints, myints+7, myvector.begin() ); |
|
1949 #if STDCPP_OOM |
|
1950 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
1951 #endif |
|
1952 for (it=myvector.begin(); it!=myvector.end(); ++it) |
|
1953 { |
|
1954 static int i; |
|
1955 a[i] = *it; |
|
1956 i++; |
|
1957 } |
|
1958 /* |
|
1959 if(a[0]==10) |
|
1960 if(a[1]==20) |
|
1961 if(a[2]==30) |
|
1962 if(a[3]==40) |
|
1963 if(a[4]==50) |
|
1964 if(a[5]==60) |
|
1965 if(a[6]==70) |
|
1966 return KErrNone; |
|
1967 return KErrGeneral;*/ |
|
1968 |
|
1969 if(a[0]!=10) |
|
1970 failures++; |
|
1971 if(a[1]!=20) |
|
1972 failures++; |
|
1973 |
|
1974 if(a[2]!=30) |
|
1975 failures++; |
|
1976 if(a[3]!=40) |
|
1977 failures++; |
|
1978 if(a[4]!=50) |
|
1979 failures++; |
|
1980 if(a[5]!=60) |
|
1981 failures++; |
|
1982 if(a[6]!=70) |
|
1983 failures++; |
|
1984 |
|
1985 |
|
1986 //__UHEAP_MARKEND; |
|
1987 //#if STDCPP_OOM |
|
1988 //failures++; |
|
1989 // #endif |
|
1990 } |
|
1991 |
|
1992 |
|
1993 catch(bad_alloc&) |
|
1994 { |
|
1995 //do nothing |
|
1996 } |
|
1997 catch(...) |
|
1998 { |
|
1999 failures++; |
|
2000 |
|
2001 } |
|
2002 |
|
2003 if(failures ) |
|
2004 return KErrGeneral; |
|
2005 return KErrNone; |
|
2006 } |
|
2007 |
|
2008 TInt Ctstl_3::Copybackward_fun(CStifItemParser& aItem) |
|
2009 |
|
2010 { |
|
2011 |
|
2012 int failures=0; |
|
2013 |
|
2014 //__UHEAP_MARK; |
|
2015 try{ |
|
2016 |
|
2017 vector<int> myvector; |
|
2018 vector<int>::iterator it; |
|
2019 int a[11]; |
|
2020 // set some values: |
|
2021 for (int i=1; i<=5; i++) |
|
2022 myvector.push_back(i*10); // myvector: 10 20 30 40 50 |
|
2023 |
|
2024 myvector.resize(myvector.size()+6); // allocate space for 6 more elements |
|
2025 // cout<<""; |
|
2026 #if STDCPP_OOM |
|
2027 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2028 #endif |
|
2029 copy_backward ( myvector.begin(), myvector.begin()+5, myvector.end() ); |
|
2030 #if STDCPP_OOM |
|
2031 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2032 #endif |
|
2033 |
|
2034 for (it=myvector.begin(); it!=myvector.end(); ++it) |
|
2035 { |
|
2036 static int i; |
|
2037 a[i] = *it; |
|
2038 i++; |
|
2039 } |
|
2040 /* |
|
2041 if(a[0]==10) |
|
2042 if(a[1]==20) |
|
2043 if(a[2]==30) |
|
2044 if(a[3]==40) |
|
2045 if(a[4]==50) |
|
2046 |
|
2047 if(a[6]==10) |
|
2048 if(a[7]==20) |
|
2049 if(a[8]==30) |
|
2050 if(a[9]==40) |
|
2051 if(a[10]==50) |
|
2052 |
|
2053 return KErrNone; |
|
2054 else |
|
2055 |
|
2056 return KErrGeneral; |
|
2057 */ |
|
2058 // __UHEAP_MARKEND; |
|
2059 |
|
2060 if(a[0]!=10) |
|
2061 failures++; |
|
2062 |
|
2063 if(a[1]!=20) |
|
2064 failures++; |
|
2065 if(a[2]!=30) |
|
2066 failures++; |
|
2067 if(a[3]!=40) |
|
2068 failures++; |
|
2069 if(a[4]!=50) |
|
2070 failures++; |
|
2071 |
|
2072 if(a[6]!=10) |
|
2073 failures++; |
|
2074 if(a[7]!=20) |
|
2075 failures++; |
|
2076 if(a[8]!=30) |
|
2077 failures++; |
|
2078 if(a[9]!=40) |
|
2079 failures++; |
|
2080 if(a[10]!=50) |
|
2081 failures++; |
|
2082 //#if STDCPP_OOM |
|
2083 //failures++; |
|
2084 // #endif |
|
2085 } |
|
2086 |
|
2087 catch(bad_alloc&) |
|
2088 { |
|
2089 //do nothing |
|
2090 } |
|
2091 catch(...) |
|
2092 { |
|
2093 failures++; |
|
2094 |
|
2095 } |
|
2096 |
|
2097 if(failures ) |
|
2098 return KErrGeneral; |
|
2099 return KErrNone; |
|
2100 } |
|
2101 |
|
2102 |
|
2103 TInt Ctstl_3::mergeL(CStifItemParser& aItem) |
|
2104 |
|
2105 { |
|
2106 int failures=0; |
|
2107 try |
|
2108 { |
|
2109 int a[4]; |
|
2110 |
|
2111 list <int> c1, c2; |
|
2112 list <int>::iterator c2_Iter ; |
|
2113 |
|
2114 // __UHEAP_MARK; |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 c1.push_back( 3 ); |
|
2121 c1.push_back( 6 ); |
|
2122 c2.push_back( 2 ); |
|
2123 c2.push_back( 4 ); |
|
2124 |
|
2125 // cout<<""; |
|
2126 #if STDCPP_OOM |
|
2127 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2128 #endif |
|
2129 |
|
2130 c2.merge( c1 ); // Merge c1 into c2 in (default) ascending order |
|
2131 |
|
2132 #if STDCPP_OOM |
|
2133 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2134 #endif |
|
2135 c2.sort( greater<int>( ) ); |
|
2136 for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ ) |
|
2137 |
|
2138 { |
|
2139 static int i; |
|
2140 a[i]= *c2_Iter; |
|
2141 i++; |
|
2142 } |
|
2143 |
|
2144 // __UHEAP_MARKEND; |
|
2145 |
|
2146 /* if(a[0]==6) |
|
2147 if(a[1]==4) |
|
2148 if(a[2]==3) |
|
2149 if(a[3]==2) |
|
2150 |
|
2151 |
|
2152 |
|
2153 return KErrNone; |
|
2154 |
|
2155 return KErrGeneral; |
|
2156 */ |
|
2157 |
|
2158 |
|
2159 if(a[0]!=6) |
|
2160 |
|
2161 failures++; |
|
2162 |
|
2163 if(a[1]!=4) |
|
2164 failures++; |
|
2165 if(a[2]!=3) |
|
2166 failures++; |
|
2167 if(a[3]!=2) |
|
2168 failures++; |
|
2169 |
|
2170 //#if STDCPP_OOM |
|
2171 //failures++; |
|
2172 // #endif |
|
2173 |
|
2174 |
|
2175 } |
|
2176 |
|
2177 catch(bad_alloc&) |
|
2178 { |
|
2179 //do nothing |
|
2180 } |
|
2181 catch(...) |
|
2182 { |
|
2183 failures++; |
|
2184 |
|
2185 } |
|
2186 |
|
2187 if(failures ) |
|
2188 return KErrGeneral; |
|
2189 return KErrNone; |
|
2190 } |
|
2191 |
|
2192 TInt Ctstl_3::allocatoradd(CStifItemParser& aItem) |
|
2193 |
|
2194 { |
|
2195 int failures = 0; |
|
2196 |
|
2197 // __UHEAP_MARK; |
|
2198 try{ |
|
2199 vector <int> v1; |
|
2200 vector <int>::iterator v1Iter; |
|
2201 vector <int>:: allocator_type v1Alloc; |
|
2202 |
|
2203 int i; |
|
2204 for ( i = 1 ; i <= 7 ; i++ ) |
|
2205 { |
|
2206 v1.push_back( 2 * i ); |
|
2207 } |
|
2208 |
|
2209 // cout<<""; |
|
2210 #if STDCPP_OOM |
|
2211 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2212 #endif |
|
2213 |
|
2214 allocator<int>::const_pointer v1Ptr; |
|
2215 |
|
2216 |
|
2217 const int k = 8; |
|
2218 v1Ptr = v1Alloc.address( k ); |
|
2219 #if STDCPP_OOM |
|
2220 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2221 #endif |
|
2222 |
|
2223 /* |
|
2224 if( *v1Ptr == 8) |
|
2225 // __UHEAP_MARKEND; |
|
2226 |
|
2227 return KErrNone; |
|
2228 |
|
2229 return KErrGeneral; |
|
2230 */ |
|
2231 |
|
2232 |
|
2233 if(*v1Ptr!=8) |
|
2234 failures++; |
|
2235 |
|
2236 |
|
2237 //#if STDCPP_OOM |
|
2238 //failures++; |
|
2239 // #endif |
|
2240 |
|
2241 |
|
2242 } |
|
2243 |
|
2244 catch(bad_alloc&) |
|
2245 { |
|
2246 //do nothing |
|
2247 } |
|
2248 catch(...) |
|
2249 { |
|
2250 failures++; |
|
2251 |
|
2252 } |
|
2253 |
|
2254 if(failures ) |
|
2255 return KErrGeneral; |
|
2256 return KErrNone; |
|
2257 } |
|
2258 |
|
2259 |
|
2260 |
|
2261 TInt Ctstl_3::alldeall(CStifItemParser& aItem) |
|
2262 |
|
2263 |
|
2264 { |
|
2265 |
|
2266 //__UHEAP_MARK; |
|
2267 |
|
2268 int failures =0; |
|
2269 |
|
2270 try{ |
|
2271 |
|
2272 |
|
2273 allocator<int> v1Alloc; |
|
2274 |
|
2275 allocator<int>::pointer aPtr; |
|
2276 |
|
2277 aPtr = v1Alloc.allocate ( 5 ); |
|
2278 |
|
2279 int i; |
|
2280 for ( i = 0 ; i < 5 ; i++ ) |
|
2281 { |
|
2282 aPtr[ i ] = i; |
|
2283 } |
|
2284 |
|
2285 if(aPtr[0] != 0) |
|
2286 failures++; |
|
2287 // cout<<""; |
|
2288 #if STDCPP_OOM |
|
2289 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2290 #endif |
|
2291 v1Alloc.deallocate( aPtr, 5 ); |
|
2292 #if STDCPP_OOM |
|
2293 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2294 #endif |
|
2295 |
|
2296 if(aPtr[0] == 0) |
|
2297 failures++; |
|
2298 |
|
2299 |
|
2300 //__UHEAP_MARKEND; |
|
2301 /* |
|
2302 if (failures) |
|
2303 return KErrGeneral; |
|
2304 else |
|
2305 return KErrNone; |
|
2306 |
|
2307 */ |
|
2308 |
|
2309 //#if STDCPP_OOM |
|
2310 //failures++; |
|
2311 // #endif |
|
2312 } |
|
2313 |
|
2314 catch(bad_alloc&) |
|
2315 { |
|
2316 //do nothing |
|
2317 } |
|
2318 catch(...) |
|
2319 { |
|
2320 failures++; |
|
2321 |
|
2322 } |
|
2323 |
|
2324 if(failures ) |
|
2325 return KErrGeneral; |
|
2326 return KErrNone; |
|
2327 } |
|
2328 |
|
2329 |
|
2330 TInt Ctstl_3::allcons(CStifItemParser& aItem) |
|
2331 { |
|
2332 |
|
2333 |
|
2334 // __UHEAP_MARK; |
|
2335 |
|
2336 int output[7],failures = 0; |
|
2337 try{ |
|
2338 vector <int> v1; |
|
2339 vector <int>::iterator v1Iter; |
|
2340 vector <int>:: allocator_type v1Alloc; |
|
2341 |
|
2342 int i; |
|
2343 for ( i = 1 ; i <= 7 ; i++ ) |
|
2344 { |
|
2345 v1.push_back( 3 * i ); |
|
2346 } |
|
2347 |
|
2348 for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ ) |
|
2349 |
|
2350 { |
|
2351 static int i; |
|
2352 output[i] = *v1Iter; |
|
2353 i++; |
|
2354 |
|
2355 } |
|
2356 |
|
2357 |
|
2358 if(output[1] != 6) |
|
2359 failures++; |
|
2360 |
|
2361 |
|
2362 allocator<int>::pointer v1PtrA; |
|
2363 int kA = 6, kB = 7; |
|
2364 v1PtrA = v1Alloc.address( *find( v1.begin( ), v1.end( ), kA ) ); |
|
2365 v1Alloc.destroy ( v1PtrA ); |
|
2366 // cout<<""; |
|
2367 #if STDCPP_OOM |
|
2368 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2369 #endif |
|
2370 v1Alloc.construct ( v1PtrA , kB ); |
|
2371 #if STDCPP_OOM |
|
2372 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2373 #endif |
|
2374 for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ ) |
|
2375 |
|
2376 { |
|
2377 static int i; |
|
2378 output[i] = *v1Iter; |
|
2379 i++; |
|
2380 |
|
2381 } |
|
2382 |
|
2383 if(output[1] != 7) |
|
2384 failures++; |
|
2385 |
|
2386 |
|
2387 // __UHEAP_MARKEND; |
|
2388 |
|
2389 /* if(failures) |
|
2390 return KErrGeneral; |
|
2391 return KErrNone; |
|
2392 */ |
|
2393 |
|
2394 //#if STDCPP_OOM |
|
2395 //failures++; |
|
2396 // #endif |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 } |
|
2403 catch(bad_alloc&) |
|
2404 { |
|
2405 //do nothing |
|
2406 } |
|
2407 catch(...) |
|
2408 { |
|
2409 failures++; |
|
2410 |
|
2411 } |
|
2412 |
|
2413 if(failures ) |
|
2414 return KErrGeneral; |
|
2415 return KErrNone; |
|
2416 } |
|
2417 |
|
2418 TInt Ctstl_3::allrebind(CStifItemParser& aItem) |
|
2419 { |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 // __UHEAP_MARK; |
|
2425 int failures =0; |
|
2426 try{ |
|
2427 |
|
2428 typedef vector<int>::allocator_type IntAlloc; |
|
2429 |
|
2430 IntAlloc v1Iter; |
|
2431 vector<int> v1; |
|
2432 // cout<<""; |
|
2433 #if STDCPP_OOM |
|
2434 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2435 #endif |
|
2436 IntAlloc::rebind<char>::other::pointer pszC = IntAlloc::rebind<char>::other(v1.get_allocator()).allocate(1, (void *)0); |
|
2437 #if STDCPP_OOM |
|
2438 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2439 #endif |
|
2440 int * pInt = v1Iter.allocate(10); |
|
2441 |
|
2442 |
|
2443 |
|
2444 // __UHEAP_MARKEND; |
|
2445 |
|
2446 /* if(failures) |
|
2447 return KErrGeneral; |
|
2448 return KErrNone; |
|
2449 */ |
|
2450 |
|
2451 //#if STDCPP_OOM |
|
2452 //failures++; |
|
2453 // #endif |
|
2454 |
|
2455 } |
|
2456 |
|
2457 catch(bad_alloc&) |
|
2458 { |
|
2459 //do nothing |
|
2460 } |
|
2461 catch(...) |
|
2462 { |
|
2463 failures++; |
|
2464 |
|
2465 } |
|
2466 |
|
2467 if(failures ) |
|
2468 return KErrGeneral; |
|
2469 return KErrNone; |
|
2470 } |
|
2471 |
|
2472 |
|
2473 TInt Ctstl_3::allmaxsize(CStifItemParser& aItem) |
|
2474 |
|
2475 {int failures=0; |
|
2476 |
|
2477 |
|
2478 try{ |
|
2479 vector <int> v1; |
|
2480 vector <int>::iterator v1Iter; |
|
2481 vector <int>:: allocator_type v1Alloc; |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 allocator<int>::size_type v1size; |
|
2487 // cout<<""; |
|
2488 #if STDCPP_OOM |
|
2489 User::__DbgSetAllocFail(FALSE,RHeap::EDeterministic,1); |
|
2490 #endif |
|
2491 v1size = v1Alloc.max_size( ); |
|
2492 #if STDCPP_OOM |
|
2493 User::__DbgSetAllocFail(FALSE,RHeap::ENone,1); |
|
2494 #endif |
|
2495 /*if(v1size == 1073741823) |
|
2496 return KErrNone; |
|
2497 else |
|
2498 return KErrGeneral;*/ |
|
2499 |
|
2500 |
|
2501 if(v1size != 1073741823) |
|
2502 failures++; |
|
2503 |
|
2504 |
|
2505 //#if STDCPP_OOM |
|
2506 //failures++; |
|
2507 // #endif |
|
2508 |
|
2509 } |
|
2510 |
|
2511 |
|
2512 catch(bad_alloc&) |
|
2513 { |
|
2514 //do nothing |
|
2515 } |
|
2516 catch(...) |
|
2517 { |
|
2518 failures++; |
|
2519 |
|
2520 } |
|
2521 |
|
2522 if(failures ) |
|
2523 return KErrGeneral; |
|
2524 return KErrNone; |
|
2525 } |
|
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 // ----------------------------------------------------------------------------- |
|
2531 // Ctstl_3::?member_function |
|
2532 // ?implementation_description |
|
2533 // (other items were commented in a header). |
|
2534 // ----------------------------------------------------------------------------- |
|
2535 // |
|
2536 /* |
|
2537 TInt Ctstl_3::?member_function( |
|
2538 CItemParser& aItem ) |
|
2539 { |
|
2540 |
|
2541 ?code |
|
2542 |
|
2543 } |
|
2544 */ |
|
2545 |
|
2546 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
2547 // None |
|
2548 |
|
2549 // End of File |
|
2550 |
|
2551 // End of File |