Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\t_circ.cpp
16 // Test methods of CCirBuffer and CCirBuf template class.
18 // CCirBuffer, CCirBuf.
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
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:
45 // Assumptions/Requirement/Pre-requisites:
46 // Failures and causes:
47 // Base Port information:
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;}
68 LOCAL_D RTest test(_L("T_CIRC"));
69 LOCAL_D TText8* theCharArray=(TText8*)"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!\xA3$%^&*()\0";
71 LOCAL_C void TestInt()
73 // Test with unsigned integers
77 CCirBuf<TInt>* cbInt=new CCirBuf<TInt>;
78 TRAPD(ret,cbInt->SetLengthL(5));
87 TInt numbers[]={7,8,9,10,11,12,13,14,15};
88 TInt* numBuf=new TInt[10];
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);
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);
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);
117 LOCAL_C void TestClass()
123 CCirBuf<VTester>* cbInt=new CCirBuf<VTester>;
124 TRAPD(ret,cbInt->SetLengthL(5));
132 VTester dummy(0xffff);
133 VTester numbers[]={7,8,9,10,11,12,13,14,15};
134 VTester* numBuf=new VTester[10];
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);
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);
163 LOCAL_C void TestText()
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));
178 test(cbInt->Add(theCharArray,arraySize)==arraySize);
179 test(cbInt->Add(theCharArray+i)==1);
180 test(cbInt->Remove(buf,arraySize)==arraySize);
182 TRAP(ret,cbInt->SetLengthL(arraySize*60));
187 test(cbInt->Add(theCharArray,arraySize)==arraySize);
188 for (i=0;i<arraySize;i++)
189 test(cbInt->Add(theCharArray+i)==1);
192 Mem::FillZ(buf,arraySize);
193 test(cbInt->Remove(buf,arraySize)==arraySize);
194 test(Mem::Compare(buf,arraySize,theCharArray,arraySize)==KErrNone);
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));
216 test(cbInt->Add(theCharArray,arraySize)==arraySize);
217 test(cbInt->Add(theCharArray+i)==1);
218 test(cbInt->Remove(buf,arraySize)==arraySize);
220 TRAP(ret,cbInt->SetLengthL(arraySize*60));
225 test(cbInt->Add(theCharArray,arraySize)==arraySize);
226 for (i=0;i<arraySize;i++)
227 test(cbInt->Add(theCharArray+i)==1);
230 Mem::FillZ(buf,arraySize);
231 test(cbInt->Remove(buf,arraySize)==arraySize);
232 test(Mem::Compare(buf,arraySize,theCharArray,arraySize)==KErrNone);
239 LOCAL_C void TestRemove()
241 // Show remove bug (fixed in rel 050)
245 CCirBuf<TInt>* cbInt=new CCirBuf<TInt>; TRAPD(ret,cbInt->SetLengthL(5));
247 TInt numbers[]={1,2,3,4,5};
248 TInt* result=new TInt[5];
250 test(cbInt->Add(numbers,5)==5);
251 test(cbInt->Remove(result,2)==2);
254 test(cbInt->Remove(result,3)==3);
273 test.Start(_L("Testing with built in Type"));
276 test.Next(_L("Testing with concrete data type"));
279 test.Next(_L("Testing with text"));
282 test.Next(_L("Testing character buffer"));
285 test.Next(_L("Testing Remove"));