author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-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 the License "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 |
// e32test\buffer\t_circ.cpp |
|
15 |
// Overview: |
|
16 |
// Test methods of CCirBuffer and CCirBuf template class. |
|
17 |
// API Information: |
|
18 |
// CCirBuffer, CCirBuf. |
|
19 |
// Details: |
|
20 |
// - Create a circular buffer, add integers to the circular buffer and check that |
|
21 |
// they are added as specified. |
|
22 |
// - Verify Remove and Add work as expected. |
|
23 |
// - Check that all the added objects are removed. |
|
24 |
// - Create a circular buffer, add concrete data type object one, many at a time to the |
|
25 |
// circular buffer and check that they are added as specified. |
|
26 |
// - Remove the concrete data type object one, many at a time from the circular buffer |
|
27 |
// and check that they are removed as expected. |
|
28 |
// - Check that all the added objects are removed. |
|
29 |
// - Create a circular buffer, add 8-bit unsigned character object one, many at a time |
|
30 |
// to the circular buffer and check that they are added as specified. |
|
31 |
// - Remove multiple 8-bit unsigned character objects from the circular buffer and |
|
32 |
// check the added and removed objects are same. |
|
33 |
// - Create a circular buffer of unsigned integers, add single, multiple objects to the |
|
34 |
// buffer and check that they are added as specified. |
|
35 |
// - Remove multiple objects from the circular buffer and check the added and removed |
|
36 |
// objects are same. |
|
37 |
// - Create a circular buffer, add multiple signed integer objects to it, remove |
|
38 |
// the objects and verify that the added objects are removed. |
|
39 |
// - Create a circular buffer, add integers to the circular buffer and check that |
|
40 |
// they are added as specified. |
|
41 |
// - Verify Remove works as expected. |
|
42 |
// - Test whether the heap has been corrupted by all the tests. |
|
43 |
// Platforms/Drives/Compatibility: |
|
44 |
// All |
|
45 |
// Assumptions/Requirement/Pre-requisites: |
|
46 |
// Failures and causes: |
|
47 |
// Base Port information: |
|
48 |
// |
|
49 |
// |
|
50 |
||
51 |
#include <e32test.h> |
|
52 |
||
53 |
class VTester |
|
54 |
{ |
|
55 |
public: |
|
56 |
VTester(){a=b=c=d=0;} |
|
57 |
VTester(TInt anInt){a=b=c=d=anInt;} |
|
58 |
VTester& operator=(TInt anInt){a=b=c=d=anInt;return *this;} |
|
59 |
TBool operator==(const VTester& aVal) const{if (a==aVal.a && b==aVal.b && c==aVal.c && d==aVal.d) return 1; else return 0;} |
|
60 |
TBool operator==(const TInt& aVal) const{if (a==aVal && b==aVal && c==aVal && d==aVal) return 1; else return 0;} |
|
61 |
public: |
|
62 |
TInt a; |
|
63 |
TInt b; |
|
64 |
TInt c; |
|
65 |
TInt d; |
|
66 |
}; |
|
67 |
||
68 |
LOCAL_D RTest test(_L("T_CIRC")); |
|
69 |
LOCAL_D TText8* theCharArray=(TText8*)"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!\xA3$%^&*()\0"; |
|
70 |
||
71 |
LOCAL_C void TestInt() |
|
72 |
// |
|
73 |
// Test with unsigned integers |
|
74 |
// |
|
75 |
{ |
|
76 |
||
77 |
CCirBuf<TInt>* cbInt=new CCirBuf<TInt>; |
|
78 |
TRAPD(ret,cbInt->SetLengthL(5)); |
|
79 |
test(ret==KErrNone); |
|
80 |
TInt one(1); |
|
81 |
TInt two(2); |
|
82 |
TInt three(3); |
|
83 |
TInt four(4); |
|
84 |
TInt five(5); |
|
85 |
TInt six(6); |
|
86 |
TInt dummy; |
|
87 |
TInt numbers[]={7,8,9,10,11,12,13,14,15}; |
|
88 |
TInt* numBuf=new TInt[10]; |
|
89 |
test(numBuf!=NULL); |
|
90 |
test(cbInt->Add(&one)==1); |
|
91 |
test(cbInt->Add(&two)==1); |
|
92 |
test(cbInt->Add(&three)==1); |
|
93 |
test(cbInt->Add(&four)==1); |
|
94 |
test(cbInt->Add(&five)==1); |
|
95 |
one=two=three=four=0; |
|
96 |
test(cbInt->Add(&six)==0); |
|
97 |
test(cbInt->Remove(&one)==1); |
|
98 |
test(cbInt->Add(&six)==1); |
|
99 |
test(cbInt->Add(&dummy)==0); |
|
100 |
test(cbInt->Remove(&two)==1); |
|
101 |
test(cbInt->Remove(&three)==1); |
|
102 |
test(cbInt->Remove(&four)==1); |
|
103 |
test(one==1); |
|
104 |
test(two==2); |
|
105 |
test(three==3); |
|
106 |
test(four==4); |
|
107 |
test(cbInt->Add(numbers,6)==3); |
|
108 |
test(cbInt->Add(numbers,3)==0); |
|
109 |
test(cbInt->Remove(numBuf,7)==5); |
|
110 |
test(cbInt->Remove(numBuf,5)==0); |
|
111 |
for(TInt j(0);j<5;j++) |
|
112 |
test(numBuf[j]==j+5); |
|
113 |
delete [] numBuf; |
|
114 |
delete cbInt; |
|
115 |
} |
|
116 |
||
117 |
LOCAL_C void TestClass() |
|
118 |
// |
|
119 |
// Test with objects |
|
120 |
// |
|
121 |
{ |
|
122 |
||
123 |
CCirBuf<VTester>* cbInt=new CCirBuf<VTester>; |
|
124 |
TRAPD(ret,cbInt->SetLengthL(5)); |
|
125 |
test(ret==KErrNone); |
|
126 |
VTester one(1); |
|
127 |
VTester two(2); |
|
128 |
VTester three(3); |
|
129 |
VTester four(4); |
|
130 |
VTester five(5); |
|
131 |
VTester six(6); |
|
132 |
VTester dummy(0xffff); |
|
133 |
VTester numbers[]={7,8,9,10,11,12,13,14,15}; |
|
134 |
VTester* numBuf=new VTester[10]; |
|
135 |
test(numBuf!=NULL); |
|
136 |
test(cbInt->Add(&one)==1); |
|
137 |
test(cbInt->Add(&two)==1); |
|
138 |
test(cbInt->Add(&three)==1); |
|
139 |
test(cbInt->Add(&four)==1); |
|
140 |
test(cbInt->Add(&five)==1); |
|
141 |
one=two=three=four=0; |
|
142 |
test(cbInt->Add(&six)==0); |
|
143 |
test(cbInt->Remove(&one)==1); |
|
144 |
test(cbInt->Add(&six)==1); |
|
145 |
test(cbInt->Add(&dummy)==0); |
|
146 |
test(cbInt->Remove(&two)==1); |
|
147 |
test(cbInt->Remove(&three)==1); |
|
148 |
test(cbInt->Remove(&four)==1); |
|
149 |
test(one==1); |
|
150 |
test(two==2); |
|
151 |
test(three==3); |
|
152 |
test(four==4); |
|
153 |
test(cbInt->Add(numbers,6)==3); |
|
154 |
test(cbInt->Add(numbers,3)==0); |
|
155 |
test(cbInt->Remove(numBuf,7)==5); |
|
156 |
test(cbInt->Remove(numBuf,5)==0); |
|
157 |
for(TInt j(0);j<5;j++) |
|
158 |
test(numBuf[j]==j+5); |
|
159 |
delete [] numBuf; |
|
160 |
delete cbInt; |
|
161 |
} |
|
162 |
||
163 |
LOCAL_C void TestText() |
|
164 |
// |
|
165 |
// Test with text |
|
166 |
// |
|
167 |
{ |
|
168 |
||
169 |
TInt i,j; |
|
170 |
TInt arraySize=User::StringLength(theCharArray); |
|
171 |
TText8* buf=new TText8[arraySize+1]; |
|
172 |
Mem::FillZ(buf,arraySize); |
|
173 |
CCirBuf<TText8>* cbInt=new CCirBuf<TText8>; |
|
174 |
TRAPD(ret,cbInt->SetLengthL(arraySize+11)); |
|
175 |
test(ret==KErrNone); |
|
176 |
for (i=0;i<10;i++) |
|
177 |
{ |
|
178 |
test(cbInt->Add(theCharArray,arraySize)==arraySize); |
|
179 |
test(cbInt->Add(theCharArray+i)==1); |
|
180 |
test(cbInt->Remove(buf,arraySize)==arraySize); |
|
181 |
} |
|
182 |
TRAP(ret,cbInt->SetLengthL(arraySize*60)); |
|
183 |
test(ret==KErrNone); |
|
184 |
for (j=0;j<10;j++) |
|
185 |
{ |
|
186 |
for (i=0;i<9;i++) |
|
187 |
test(cbInt->Add(theCharArray,arraySize)==arraySize); |
|
188 |
for (i=0;i<arraySize;i++) |
|
189 |
test(cbInt->Add(theCharArray+i)==1); |
|
190 |
for (i=0;i<5;i++) |
|
191 |
{ |
|
192 |
Mem::FillZ(buf,arraySize); |
|
193 |
test(cbInt->Remove(buf,arraySize)==arraySize); |
|
194 |
test(Mem::Compare(buf,arraySize,theCharArray,arraySize)==KErrNone); |
|
195 |
} |
|
196 |
} |
|
197 |
delete [] buf; |
|
198 |
delete cbInt; |
|
199 |
} |
|
200 |
||
201 |
void TestBuf() |
|
202 |
// |
|
203 |
// Test with buffers |
|
204 |
// |
|
205 |
{ |
|
206 |
||
207 |
TInt i,j; |
|
208 |
TInt arraySize=User::StringLength(theCharArray); |
|
209 |
TText8* buf=new TText8[arraySize+1]; |
|
210 |
Mem::FillZ(buf,arraySize); |
|
211 |
CCirBuffer* cbInt=new CCirBuffer; |
|
212 |
TRAPD(ret,cbInt->SetLengthL(arraySize+11)); |
|
213 |
test(ret==KErrNone); |
|
214 |
for (i=0;i<10;i++) |
|
215 |
{ |
|
216 |
test(cbInt->Add(theCharArray,arraySize)==arraySize); |
|
217 |
test(cbInt->Add(theCharArray+i)==1); |
|
218 |
test(cbInt->Remove(buf,arraySize)==arraySize); |
|
219 |
} |
|
220 |
TRAP(ret,cbInt->SetLengthL(arraySize*60)); |
|
221 |
test(ret==KErrNone); |
|
222 |
for (j=0;j<10;j++) |
|
223 |
{ |
|
224 |
for (i=0;i<9;i++) |
|
225 |
test(cbInt->Add(theCharArray,arraySize)==arraySize); |
|
226 |
for (i=0;i<arraySize;i++) |
|
227 |
test(cbInt->Add(theCharArray+i)==1); |
|
228 |
for (i=0;i<5;i++) |
|
229 |
{ |
|
230 |
Mem::FillZ(buf,arraySize); |
|
231 |
test(cbInt->Remove(buf,arraySize)==arraySize); |
|
232 |
test(Mem::Compare(buf,arraySize,theCharArray,arraySize)==KErrNone); |
|
233 |
} |
|
234 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
// Test Reset, Put and Get |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
TInt count = cbInt->Count(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
test(count>0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
cbInt->Reset(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
count = cbInt->Count(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
test(count==0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
TUint index = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
// Put 100 integers to the circular buffer. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
TUint numberOfObjects= 100; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
for(index=1;index<=numberOfObjects; index++) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
TInt result= cbInt->Put(index); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
User::LeaveIfError(result); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
count = cbInt->Count(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
test(count==100); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
// Get 50 integers from the circular buffer. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
for(index=1;index<=(numberOfObjects/2); index++) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
TUint cb = cbInt->Get(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
test(cb==index); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
count = cbInt->Count(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
test(count==50); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
|
0 | 263 |
delete [] buf; |
264 |
delete cbInt; |
|
265 |
} |
|
266 |
||
267 |
LOCAL_C void TestRemove() |
|
268 |
// |
|
269 |
// Show remove bug (fixed in rel 050) |
|
270 |
// |
|
271 |
{ |
|
272 |
||
273 |
CCirBuf<TInt>* cbInt=new CCirBuf<TInt>; TRAPD(ret,cbInt->SetLengthL(5)); |
|
274 |
test(ret==KErrNone); |
|
275 |
TInt numbers[]={1,2,3,4,5}; |
|
276 |
TInt* result=new TInt[5]; |
|
277 |
||
278 |
test(cbInt->Add(numbers,5)==5); |
|
279 |
test(cbInt->Remove(result,2)==2); |
|
280 |
test(result[0]==1); |
|
281 |
test(result[1]==2); |
|
282 |
test(cbInt->Remove(result,3)==3); |
|
283 |
test(result[0]==3); |
|
284 |
test(result[1]==4); |
|
285 |
test(result[2]==5); |
|
286 |
||
287 |
delete [] result; |
|
288 |
delete cbInt; |
|
289 |
} |
|
290 |
||
291 |
||
292 |
TInt E32Main() |
|
293 |
// |
|
294 |
// Test CCirBuf<T> |
|
295 |
// |
|
296 |
{ |
|
297 |
||
298 |
test.Title(); |
|
299 |
__UHEAP_MARK; |
|
300 |
// |
|
301 |
test.Start(_L("Testing with built in Type")); |
|
302 |
TestInt(); |
|
303 |
// |
|
304 |
test.Next(_L("Testing with concrete data type")); |
|
305 |
TestClass(); |
|
306 |
// |
|
307 |
test.Next(_L("Testing with text")); |
|
308 |
TestText(); |
|
309 |
// |
|
310 |
test.Next(_L("Testing character buffer")); |
|
311 |
TestBuf(); |
|
312 |
// |
|
313 |
test.Next(_L("Testing Remove")); |
|
314 |
TestRemove(); |
|
315 |
||
316 |
__UHEAP_MARKEND; |
|
317 |
test.End(); |
|
318 |
return(KErrNone); |
|
319 |
} |
|
320 |