|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <algorithm> |
|
17 #include <list> |
|
18 #include <queue> |
|
19 #include <deque> |
|
20 #include <stack> |
|
21 #include <e32std.h> |
|
22 |
|
23 #include "cppunit/cppunit_proxy.h" |
|
24 |
|
25 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) |
|
26 using namespace std; |
|
27 #endif |
|
28 |
|
29 // |
|
30 // TestCase class |
|
31 // |
|
32 class StackTest : public CPPUNIT_NS::TestCase |
|
33 { |
|
34 CPPUNIT_TEST_SUITE(StackTest); |
|
35 CPPUNIT_TEST(stack1); |
|
36 CPPUNIT_TEST(stack2); |
|
37 CPPUNIT_TEST(stack_cov); |
|
38 CPPUNIT_TEST(stack_excep); |
|
39 CPPUNIT_TEST_SUITE_END(); |
|
40 |
|
41 protected: |
|
42 void stack1(); |
|
43 void stack2(); |
|
44 void stack_cov(); |
|
45 void stack_excep(); |
|
46 }; |
|
47 |
|
48 CPPUNIT_TEST_SUITE_REGISTRATION(StackTest); |
|
49 |
|
50 // |
|
51 // tests implementation |
|
52 // |
|
53 void StackTest::stack1() |
|
54 { |
|
55 stack<int, deque<int> > s; |
|
56 s.push(42); |
|
57 s.push(101); |
|
58 s.push(69); |
|
59 CPPUNIT_ASSERT(s.top()==69); |
|
60 s.pop(); |
|
61 CPPUNIT_ASSERT(s.top()==101); |
|
62 s.pop(); |
|
63 CPPUNIT_ASSERT(s.top()==42); |
|
64 s.pop(); |
|
65 CPPUNIT_ASSERT(s.empty()); |
|
66 } |
|
67 void StackTest::stack2() |
|
68 { |
|
69 stack<int, list<int> > s; |
|
70 s.push(42); |
|
71 s.push(101); |
|
72 s.push(69); |
|
73 CPPUNIT_ASSERT(s.top()==69); |
|
74 s.pop(); |
|
75 CPPUNIT_ASSERT(s.top()==101); |
|
76 s.pop(); |
|
77 CPPUNIT_ASSERT(s.top()==42); |
|
78 s.pop(); |
|
79 CPPUNIT_ASSERT(s.empty()); |
|
80 } |
|
81 void StackTest::stack_cov() |
|
82 { |
|
83 __UHEAP_MARK; |
|
84 { |
|
85 typedef stack<char> Mystack; |
|
86 Mystack c1,c2; |
|
87 |
|
88 c1.push('a'); |
|
89 c1.push('b'); |
|
90 c1.push('c'); |
|
91 |
|
92 c2.push('a'); |
|
93 c2.push('b'); |
|
94 c2.push('d'); |
|
95 |
|
96 CPPUNIT_ASSERT( (c1<c2) == true); |
|
97 CPPUNIT_ASSERT( (c1<=c2) == true); |
|
98 CPPUNIT_ASSERT( (c1==c2) == false); |
|
99 CPPUNIT_ASSERT( (c1>c2) == false); |
|
100 CPPUNIT_ASSERT( (c1>=c2) == false); |
|
101 CPPUNIT_ASSERT( (c1!=c2) == true); |
|
102 |
|
103 CPPUNIT_ASSERT( c1.size() == 3); |
|
104 c1.pop(); |
|
105 CPPUNIT_ASSERT( c1.size() == 2); |
|
106 |
|
107 } |
|
108 __UHEAP_MARKEND; |
|
109 } |
|
110 void StackTest::stack_excep() |
|
111 { |
|
112 __UHEAP_MARK; |
|
113 typedef stack<char> Mystack; |
|
114 Mystack c1; |
|
115 c1.push('a'); |
|
116 c1.push('b'); |
|
117 c1.push('c'); |
|
118 |
|
119 c1.pop(); |
|
120 c1.pop(); |
|
121 c1.pop(); |
|
122 |
|
123 CPPUNIT_ASSERT( c1.size() == 0); |
|
124 #if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) |
|
125 try |
|
126 { |
|
127 c1.pop(); |
|
128 } |
|
129 catch(...) |
|
130 { |
|
131 CPPUNIT_ASSERT( 0 ); |
|
132 } |
|
133 CPPUNIT_ASSERT( 1 ); |
|
134 #endif |
|
135 __UHEAP_MARKEND; |
|
136 } |