|
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 <vector> |
|
17 #include <algorithm> |
|
18 #include <list> |
|
19 #include <deque> |
|
20 #include <queue> |
|
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 QueueTest : public CPPUNIT_NS::TestCase |
|
33 { |
|
34 CPPUNIT_TEST_SUITE(QueueTest); |
|
35 CPPUNIT_TEST(pqueue1); |
|
36 CPPUNIT_TEST(queue1); |
|
37 CPPUNIT_TEST(queue_cov); |
|
38 CPPUNIT_TEST(pqueue_cov1); |
|
39 CPPUNIT_TEST(pqueue_cov2); |
|
40 CPPUNIT_TEST_SUITE_END(); |
|
41 |
|
42 protected: |
|
43 void pqueue1(); |
|
44 void queue1(); |
|
45 void queue_cov(); |
|
46 void pqueue_cov1(); |
|
47 void pqueue_cov2(); |
|
48 }; |
|
49 |
|
50 CPPUNIT_TEST_SUITE_REGISTRATION(QueueTest); |
|
51 |
|
52 // |
|
53 // tests implementation |
|
54 // |
|
55 void QueueTest::pqueue1() |
|
56 { |
|
57 priority_queue<int, deque<int>, less<int> > q; |
|
58 q.push(42); |
|
59 q.push(101); |
|
60 q.push(69); |
|
61 |
|
62 CPPUNIT_ASSERT( q.top()==101 ); |
|
63 q.pop(); |
|
64 CPPUNIT_ASSERT( q.top()==69 ); |
|
65 q.pop(); |
|
66 CPPUNIT_ASSERT( q.top()==42 ); |
|
67 q.pop(); |
|
68 |
|
69 CPPUNIT_ASSERT(q.empty()); |
|
70 } |
|
71 void QueueTest::queue1() |
|
72 { |
|
73 queue<int, list<int> > q; |
|
74 q.push(42); |
|
75 q.push(101); |
|
76 q.push(69); |
|
77 |
|
78 CPPUNIT_ASSERT( q.front()==42 ); |
|
79 q.pop(); |
|
80 CPPUNIT_ASSERT( q.front()==101 ); |
|
81 q.pop(); |
|
82 CPPUNIT_ASSERT( q.front()==69 ); |
|
83 q.pop(); |
|
84 |
|
85 CPPUNIT_ASSERT(q.empty()); |
|
86 } |
|
87 void QueueTest::queue_cov() |
|
88 { |
|
89 __UHEAP_MARK; |
|
90 { |
|
91 queue<int, list<int> > q; |
|
92 q.push(42); |
|
93 q.push(101); |
|
94 q.push(69); |
|
95 |
|
96 CPPUNIT_ASSERT( q.size()==3 ); |
|
97 q.pop(); |
|
98 CPPUNIT_ASSERT( q.size()==2 ); |
|
99 q.pop(); |
|
100 CPPUNIT_ASSERT( q.size()==1 ); |
|
101 q.pop(); |
|
102 |
|
103 CPPUNIT_ASSERT(q.empty()); |
|
104 } |
|
105 { |
|
106 queue<int, list<int> > q; |
|
107 q.push(42); |
|
108 q.push(101); |
|
109 q.push(69); |
|
110 CPPUNIT_ASSERT(q.back() == 69); |
|
111 } |
|
112 { |
|
113 queue<int> myqueue; |
|
114 queue<int> const& cv = myqueue; |
|
115 myqueue.push(77); |
|
116 myqueue.push(16); |
|
117 CPPUNIT_ASSERT(cv.front() == 77); |
|
118 CPPUNIT_ASSERT(cv.back() == 16); |
|
119 } |
|
120 __UHEAP_MARKEND; |
|
121 } |
|
122 void QueueTest::pqueue_cov1() |
|
123 { |
|
124 __UHEAP_MARK; |
|
125 { |
|
126 priority_queue<int> pq; |
|
127 pq.push(42); |
|
128 pq.push(101); |
|
129 pq.push(69); |
|
130 |
|
131 CPPUNIT_ASSERT( pq.size()==3 ); |
|
132 pq.pop(); |
|
133 CPPUNIT_ASSERT( pq.size()==2 ); |
|
134 pq.pop(); |
|
135 CPPUNIT_ASSERT( pq.size()==1 ); |
|
136 pq.pop(); |
|
137 CPPUNIT_ASSERT(pq.empty()); |
|
138 } |
|
139 { |
|
140 queue<int> myqueue; |
|
141 queue<int> myqueue1; |
|
142 bool flag; |
|
143 |
|
144 myqueue.push(77); |
|
145 myqueue.push(16); |
|
146 myqueue1.push(77); |
|
147 myqueue1.push(17); |
|
148 flag = myqueue < myqueue1; |
|
149 CPPUNIT_ASSERT(flag == true); |
|
150 } |
|
151 { |
|
152 queue<int> myqueue; |
|
153 queue<int> myqueue1; |
|
154 bool flag; |
|
155 |
|
156 myqueue.push(77); |
|
157 myqueue.push(16); |
|
158 myqueue1.push(77); |
|
159 myqueue1.push(16); |
|
160 flag = (myqueue == myqueue1); |
|
161 CPPUNIT_ASSERT(flag == true); |
|
162 } |
|
163 __UHEAP_MARKEND; |
|
164 } |
|
165 void QueueTest::pqueue_cov2() |
|
166 { |
|
167 __UHEAP_MARK; |
|
168 int myints[]= {10,60,50,20}; |
|
169 priority_queue<int> first; |
|
170 priority_queue<int> second (myints,myints+3); |
|
171 priority_queue< int, vector<int>, greater<int> > third (myints,myints+3); |
|
172 CPPUNIT_ASSERT(first.empty() == true); |
|
173 CPPUNIT_ASSERT(second.size() == 3); |
|
174 CPPUNIT_ASSERT(third.top() == 10); |
|
175 third.pop(); |
|
176 CPPUNIT_ASSERT(third.top() == 50); |
|
177 third.pop(); |
|
178 CPPUNIT_ASSERT(third.top() == 60); |
|
179 __UHEAP_MARKEND; |
|
180 } |