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