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\system\t_cobj.cpp |
|
15 |
// Overview: |
|
16 |
// Test CObject, CObjectIx, CObjectCon, CObjectConIx classes |
|
17 |
// API Information: |
|
18 |
// CObject, CObjectIx, CObjectCon, CObjectConIx |
|
19 |
// Details: |
|
20 |
// - Test the CObjectIx class by adding and removing CObject objects |
|
21 |
// in the same order, in reverse order and in random order. |
|
22 |
// - Test adding many CObject objects to a CObjectConIx and test that |
|
23 |
// the returned handle is as expected. |
|
24 |
// - Perform a speed test on CObjectCon for both named and unnamed |
|
25 |
// objects. |
|
26 |
// - Check that the CObject, CObjectCon, CObjectIx and CObjectConIx methods |
|
27 |
// are in the DLL by calling each one. |
|
28 |
// - Test the CObject, CObjectCon, CObjectIx and CObjectConIx methods and |
|
29 |
// verify the results are as expected. |
|
30 |
// - Test all the objects together: create two containers, find objects by |
|
31 |
// name in a variety of ways, delete objects and verify the results are |
|
32 |
// as expected. |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
// - Test panic functions by behaving badly |
0 | 34 |
// Platforms/Drives/Compatibility: |
35 |
// All. |
|
36 |
// Assumptions/Requirement/Pre-requisites: |
|
37 |
// Failures and causes: |
|
38 |
// Base Port information: |
|
39 |
// |
|
40 |
// |
|
41 |
||
42 |
#include <e32std.h> |
|
43 |
#include <e32std_private.h> |
|
44 |
#include <e32base.h> |
|
45 |
#include <e32base_private.h> |
|
46 |
#include <e32test.h> |
|
47 |
#include <e32svr.h> |
|
48 |
#include <e32ver.h> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
#include <e32panic.h> |
0 | 50 |
#include "../misc/prbs.h" |
51 |
||
52 |
struct TCObjectDump |
|
53 |
{ |
|
54 |
TInt iAccessCount; |
|
55 |
CObject* iOwner; |
|
56 |
CObjectCon* iContainer; |
|
57 |
HBufC* iName; |
|
58 |
}; |
|
59 |
||
60 |
void CObject::__DbgTest(void* pCObjectDump) const |
|
61 |
{ |
|
62 |
((TCObjectDump*)pCObjectDump)->iAccessCount=iAccessCount; |
|
63 |
((TCObjectDump*)pCObjectDump)->iOwner=iOwner; |
|
64 |
((TCObjectDump*)pCObjectDump)->iContainer=iContainer; |
|
65 |
((TCObjectDump*)pCObjectDump)->iName=iName; |
|
66 |
} |
|
67 |
||
68 |
LOCAL_D RTest test(_L("T_COBJ")); |
|
69 |
LOCAL_D TName gName; |
|
70 |
LOCAL_D TName gName1; |
|
71 |
LOCAL_D TName gName2; |
|
72 |
LOCAL_D TFullName gFullName; |
|
73 |
LOCAL_D TFullName gFullName1; |
|
74 |
LOCAL_D TFullName gFullName2; |
|
75 |
||
76 |
class RTestHeap : public RAllocator |
|
77 |
{ |
|
78 |
public: |
|
79 |
enum TOp {EOpNone=0, EOpAlloc=1, EOpFree=2, EOpReAlloc=3}; |
|
80 |
||
81 |
struct TOpInfo |
|
82 |
{ |
|
83 |
TInt iOp; |
|
84 |
TAny* iPtrArg; |
|
85 |
TInt iIntArg; |
|
86 |
TAny* iResult; |
|
87 |
}; |
|
88 |
public: |
|
89 |
static RTestHeap* Install(); |
|
90 |
void Uninstall(); |
|
91 |
TInt GetLastOp(TOpInfo& aInfo); |
|
92 |
virtual TAny* Alloc(TInt aSize); |
|
93 |
virtual void Free(TAny* aPtr); |
|
94 |
virtual TAny* ReAlloc(TAny* aPtr, TInt aSize, TInt aMode); |
|
95 |
virtual TInt AllocLen(const TAny* aCell) const; |
|
96 |
virtual TInt Compress(); |
|
97 |
virtual void Reset(); |
|
98 |
virtual TInt AllocSize(TInt& aTotalAllocSize) const; |
|
99 |
virtual TInt Available(TInt& aBiggestBlock) const; |
|
100 |
virtual TInt DebugFunction(TInt aFunc, TAny* a1, TAny* a2); |
|
101 |
public: |
|
102 |
RAllocator* iA; |
|
103 |
TOpInfo iLastOp; |
|
104 |
}; |
|
105 |
||
106 |
RTestHeap* RTestHeap::Install() |
|
107 |
{ |
|
108 |
RTestHeap* p = new RTestHeap; |
|
109 |
test(p!=0); |
|
110 |
p->iA = &User::Heap(); |
|
111 |
p->iLastOp.iOp = EOpNone; |
|
112 |
User::SwitchHeap(p); |
|
113 |
return p; |
|
114 |
} |
|
115 |
||
116 |
void RTestHeap::Uninstall() |
|
117 |
{ |
|
118 |
User::SwitchHeap(iA); |
|
119 |
delete this; |
|
120 |
} |
|
121 |
||
122 |
TInt RTestHeap::GetLastOp(RTestHeap::TOpInfo& aInfo) |
|
123 |
{ |
|
124 |
memcpy(&aInfo, &iLastOp, sizeof(TOpInfo)); |
|
125 |
iLastOp.iOp = EOpNone; |
|
126 |
return (aInfo.iOp == EOpNone) ? KErrNotFound : KErrNone; |
|
127 |
} |
|
128 |
||
129 |
TAny* RTestHeap::Alloc(TInt aSize) |
|
130 |
{ |
|
131 |
TAny* p = iA->Alloc(aSize); |
|
132 |
iLastOp.iOp = EOpAlloc; |
|
133 |
iLastOp.iPtrArg = 0; |
|
134 |
iLastOp.iIntArg = aSize; |
|
135 |
iLastOp.iResult = p; |
|
136 |
return p; |
|
137 |
} |
|
138 |
||
139 |
void RTestHeap::Free(TAny* aPtr) |
|
140 |
{ |
|
141 |
iLastOp.iOp = EOpFree; |
|
142 |
iLastOp.iPtrArg = aPtr; |
|
143 |
iLastOp.iIntArg = 0; |
|
144 |
iLastOp.iResult = 0; |
|
145 |
iA->Free(aPtr); |
|
146 |
} |
|
147 |
||
148 |
TAny* RTestHeap::ReAlloc(TAny* aPtr, TInt aSize, TInt aMode=0) |
|
149 |
{ |
|
150 |
TAny* p = iA->ReAlloc(aPtr,aSize,aMode); |
|
151 |
iLastOp.iOp = EOpReAlloc; |
|
152 |
iLastOp.iPtrArg = aPtr; |
|
153 |
iLastOp.iIntArg = aSize; |
|
154 |
iLastOp.iResult = p; |
|
155 |
return p; |
|
156 |
} |
|
157 |
||
158 |
TInt RTestHeap::AllocLen(const TAny* aCell) const |
|
159 |
{ |
|
160 |
TInt l = iA->AllocLen(aCell); |
|
161 |
return l; |
|
162 |
} |
|
163 |
||
164 |
TInt RTestHeap::Compress() |
|
165 |
{ |
|
166 |
TInt l = iA->Compress(); |
|
167 |
return l; |
|
168 |
} |
|
169 |
||
170 |
void RTestHeap::Reset() |
|
171 |
{ |
|
172 |
iA->Reset(); |
|
173 |
} |
|
174 |
||
175 |
TInt RTestHeap::AllocSize(TInt& aTotalAllocSize) const |
|
176 |
{ |
|
177 |
TInt s; |
|
178 |
TInt r = iA->AllocSize(s); |
|
179 |
aTotalAllocSize = s; |
|
180 |
return r; |
|
181 |
} |
|
182 |
||
183 |
TInt RTestHeap::Available(TInt& aBiggestBlock) const |
|
184 |
{ |
|
185 |
TInt s; |
|
186 |
TInt r = iA->Available(s); |
|
187 |
aBiggestBlock = s; |
|
188 |
return r; |
|
189 |
} |
|
190 |
||
191 |
TInt RTestHeap::DebugFunction(TInt aFunc, TAny* a1=NULL, TAny* a2=NULL) |
|
192 |
{ |
|
193 |
TInt r = iA->DebugFunction(aFunc, a1, a2); |
|
194 |
return r; |
|
195 |
} |
|
196 |
||
197 |
||
198 |
||
199 |
||
200 |
class TestCObjects |
|
201 |
{ |
|
202 |
public: |
|
203 |
void Test1(void); |
|
204 |
void Test2(void); |
|
205 |
void Test3(void); |
|
206 |
void Test4(void); |
|
207 |
void Test5(void); |
|
208 |
void Test6(void); |
|
209 |
void Test7(void); |
|
210 |
void Test8(void); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
void Test9(void); |
0 | 212 |
private: |
213 |
static void GetObjName(TName& aDest,const CObject& aObj); |
|
214 |
static void GetObjFullName(TFullName& aDest,const CObject& aObj); |
|
215 |
}; |
|
216 |
||
217 |
||
218 |
GLDEF_C void TestCObjects::Test1(void) |
|
219 |
{ |
|
220 |
// Check CObject methods are in the DLL |
|
221 |
CObject* pCObject=new CObject; |
|
222 |
CObject* temp=new CObject; |
|
223 |
||
224 |
pCObject->Open(); |
|
225 |
pCObject->Close(); |
|
226 |
gName=pCObject->Name(); |
|
227 |
TPtrC aDesR(_S("a name")); |
|
228 |
pCObject->SetName(&aDesR); |
|
229 |
pCObject->SetNameL(&aDesR); |
|
230 |
gFullName=pCObject->FullName(); |
|
231 |
pCObject->Owner(); |
|
232 |
pCObject->SetOwner(temp); |
|
233 |
pCObject->Close(); // deletes object when iAccessCount==0 |
|
234 |
temp->Close(); |
|
235 |
} |
|
236 |
||
237 |
GLDEF_C void TestCObjects::Test2(void) |
|
238 |
{ |
|
239 |
// Check CObjectCon methods are in the DLL |
|
240 |
CObjectCon* pCObjectCon=CObjectCon::NewL(); |
|
241 |
CObject* pCObject=new CObject; |
|
242 |
TInt aFindHandle=0; |
|
243 |
||
244 |
pCObjectCon->AddL(pCObject); |
|
245 |
pCObjectCon->At(aFindHandle); |
|
246 |
User::ValidateName(_L("a name")); |
|
247 |
pCObjectCon->CheckUniqueFullName(pCObject, _L("a name")); |
|
248 |
pCObjectCon->FindByName(aFindHandle, _L("a name"), gName); |
|
249 |
pCObjectCon->FindByFullName(aFindHandle, _L("a Name"), gFullName); |
|
250 |
pCObjectCon->UniqueID(); |
|
251 |
pCObjectCon->Count(); |
|
252 |
pCObjectCon->Remove(pCObject); |
|
253 |
pCObject->Close(); |
|
254 |
delete pCObjectCon; |
|
255 |
} |
|
256 |
||
257 |
GLDEF_C void TestCObjects::Test3(void) |
|
258 |
{ |
|
259 |
// Check the CObjectIx methods are in the DLL |
|
260 |
CObjectIx* pCObjectIx=CObjectIx::NewL(); |
|
261 |
pCObjectIx->Count(); |
|
262 |
test(pCObjectIx->At(0)==NULL); |
|
263 |
delete pCObjectIx; |
|
264 |
pCObjectIx=CObjectIx::NewL(); |
|
265 |
test(pCObjectIx->Count()==0); |
|
266 |
CObjectConIx* pCObjectConIx=CObjectConIx::NewL(); |
|
267 |
delete pCObjectConIx; |
|
268 |
pCObjectConIx=CObjectConIx::NewL(); |
|
269 |
CObjectCon* pCObjectCon=pCObjectConIx->CreateL(); |
|
270 |
test(pCObjectCon->Count()==0); |
|
271 |
CObject* pCObject= new CObject; |
|
272 |
test(pCObject!=NULL); |
|
273 |
||
274 |
TInt find; |
|
275 |
TName name; |
|
276 |
TInt r=pCObjectCon->FindByName(find,_L("Name"),name); |
|
277 |
test(r==KErrNotFound); |
|
278 |
TFullName fullName; |
|
279 |
r=pCObjectCon->FindByFullName(find,_L("Full Name"),fullName); |
|
280 |
test(r==KErrNotFound); |
|
281 |
||
282 |
||
283 |
pCObjectCon->AddL(pCObject); |
|
284 |
test(pCObjectCon->Count()==1); |
|
285 |
test(pCObjectIx->Count(pCObject)==0); |
|
286 |
pCObjectIx->AddL(pCObject); |
|
287 |
test(pCObjectIx->Count(pCObject)==1); |
|
288 |
pCObjectIx->Count(); |
|
289 |
pCObjectIx->At(0, 0); |
|
290 |
pCObjectIx->At(0); |
|
291 |
// pCObjectIx->Remove(0); |
|
292 |
delete pCObjectIx; |
|
293 |
delete pCObjectConIx; |
|
294 |
// delete pCObjectCon; |
|
295 |
// pCObject->Close(); |
|
296 |
} |
|
297 |
||
298 |
GLDEF_C void TestCObjects::Test4(void) |
|
299 |
{ |
|
300 |
// Check CObjectConIx methods are in the DLL |
|
301 |
CObjectConIx* pCObjectConIx=CObjectConIx::NewL(); |
|
302 |
CObjectCon* pCObjectCon=pCObjectConIx->CreateL(); |
|
303 |
pCObjectConIx->Lookup(0); |
|
304 |
pCObjectConIx->Remove(pCObjectCon); |
|
305 |
delete pCObjectConIx; |
|
306 |
} |
|
307 |
||
308 |
GLDEF_C void TestCObjects::Test5(void) |
|
309 |
{ |
|
310 |
// Test the methods of the CObject class |
|
311 |
TCObjectDump CObjectDump; |
|
312 |
CObject* a=new CObject; |
|
313 |
CObject* b=new CObject; |
|
314 |
a->__DbgTest(&CObjectDump); |
|
315 |
test(CObjectDump.iAccessCount==1 && CObjectDump.iOwner==NULL && CObjectDump.iContainer==NULL); |
|
316 |
a->Open(); |
|
317 |
a->__DbgTest(&CObjectDump); |
|
318 |
test(CObjectDump.iAccessCount==2); |
|
319 |
a->Close(); |
|
320 |
a->__DbgTest(&CObjectDump); |
|
321 |
test(CObjectDump.iAccessCount==1); |
|
322 |
TPtrC aDesR(_L("aName")); |
|
323 |
a->SetName(&aDesR); |
|
324 |
gName=a->Name(); |
|
325 |
test(gName==_L("aName")); |
|
326 |
gFullName=a->FullName(); |
|
327 |
test(gFullName==_L("aName")); |
|
328 |
TPtrC aDesR2(_L("Owner")); |
|
329 |
b->SetName(&aDesR2); |
|
330 |
a->SetOwner(b); |
|
331 |
test(a->Owner()==b); |
|
332 |
gFullName=a->FullName(); |
|
333 |
test(gFullName==_L("Owner::aName")); |
|
334 |
a->Close(); // Calls the destructor via the call to delete |
|
335 |
// To Do: set iContainer to something then call Close() |
|
336 |
} |
|
337 |
||
338 |
||
339 |
GLDEF_C void TestCObjects::Test6(void) |
|
340 |
{ |
|
341 |
// Test the methods of CObjectCon |
|
342 |
TCObjectDump dump1, dump2; |
|
343 |
TInt aFindHandle=0; |
|
344 |
CObject *pObj1=new CObject, |
|
345 |
*pObj2=new CObject, |
|
346 |
*pObj3=new CObject, |
|
347 |
*temp; |
|
348 |
CObjectCon* pCon=CObjectCon::NewL(); |
|
349 |
||
350 |
test(User::ValidateName(_L("xxx*xxx"))==KErrBadName); |
|
351 |
test(User::ValidateName(_L("xxx?xxx"))==KErrBadName); |
|
352 |
test(User::ValidateName(_L("xxx:xxx"))==KErrBadName); |
|
353 |
test(User::ValidateName(_L("xxxxxxx"))==KErrNone); |
|
354 |
||
355 |
TPtrC name1(_S("Obj1")), name2(_S("Obj2")), name3(_S("Owner")); |
|
356 |
pObj1->SetName(&name1); |
|
357 |
pObj2->SetName(&name2); |
|
358 |
pObj3->SetName(&name3); |
|
359 |
||
360 |
test(pCon->Count()==0); |
|
361 |
pCon->AddL(pObj1); |
|
362 |
test(pCon->Count()==1); |
|
363 |
pCon->AddL(pObj2); |
|
364 |
test(pCon->Count()==2); |
|
365 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
test((*pCon)[0]==pObj1); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
test((*pCon)[1]==pObj2); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
|
0 | 369 |
aFindHandle=0; |
370 |
test(pCon->FindByName(aFindHandle, _L("xxx"), gName)==KErrNotFound); |
|
371 |
aFindHandle=0; |
|
372 |
GetObjName(gName1,*pObj1); |
|
373 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNone); |
|
374 |
test(aFindHandle==0); |
|
375 |
aFindHandle=2; |
|
376 |
GetObjName(gName1,*pObj1); |
|
377 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNotFound); |
|
378 |
aFindHandle=0; |
|
379 |
GetObjName(gName1,*pObj2); |
|
380 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNone); |
|
381 |
test(aFindHandle==1); |
|
382 |
||
383 |
aFindHandle=0; |
|
384 |
test(pCon->FindByFullName(aFindHandle, _L("xxx"), gFullName)==KErrNotFound); |
|
385 |
aFindHandle=0; |
|
386 |
GetObjName(gName1,*pObj1); |
|
387 |
test(pCon->FindByFullName(aFindHandle, gName1, gFullName)==KErrNone); |
|
388 |
test(aFindHandle==0); |
|
389 |
GetObjName(gName1,*pObj2); |
|
390 |
test(pCon->FindByFullName(aFindHandle, gName1, gFullName)==KErrNone); |
|
391 |
test(aFindHandle==1); |
|
392 |
||
393 |
pObj1->SetOwner(pObj3); |
|
394 |
pObj2->SetOwner(pObj3); |
|
395 |
aFindHandle=0; |
|
396 |
test(pCon->FindByFullName(aFindHandle, _L("xxx"), gFullName)==KErrNotFound); |
|
397 |
aFindHandle=0; |
|
398 |
GetObjFullName(gFullName1,*pObj1); |
|
399 |
test(pCon->FindByFullName(aFindHandle, gFullName1, gFullName)==KErrNone); |
|
400 |
test(aFindHandle==0); |
|
401 |
GetObjFullName(gFullName1,*pObj2); |
|
402 |
test(pCon->FindByFullName(aFindHandle, gFullName1, gFullName)==KErrNone); |
|
403 |
test(aFindHandle==1); |
|
404 |
||
405 |
||
406 |
test(pCon->CheckUniqueFullName(pObj3, _L("aname"))==KErrNone); |
|
407 |
GetObjName(gName1,*pObj1); |
|
408 |
test(pCon->CheckUniqueFullName(pObj3, gName1)==KErrAlreadyExists); |
|
409 |
pCon->Remove(pObj1); |
|
410 |
test(pCon->CheckUniqueFullName(pObj3, gName1)==KErrNone); |
|
411 |
test(pCon->Count()==1); |
|
412 |
pCon->AddL(pObj3); |
|
413 |
test(pCon->Count()==2); |
|
414 |
aFindHandle=0; |
|
415 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNotFound); |
|
416 |
aFindHandle=0; |
|
417 |
GetObjFullName(gFullName1,*pObj1); |
|
418 |
test(pCon->FindByFullName(aFindHandle, gFullName1, gFullName)==KErrNotFound); |
|
419 |
aFindHandle=0; |
|
420 |
GetObjName(gName1,*pObj2); |
|
421 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNone); |
|
422 |
test(aFindHandle==0); |
|
423 |
GetObjFullName(gFullName1,*pObj2); |
|
424 |
test(pCon->FindByFullName(aFindHandle, gFullName1, gFullName)==KErrNone); |
|
425 |
test(aFindHandle==0); |
|
426 |
GetObjName(gName1,*pObj3); |
|
427 |
test(pCon->FindByName(aFindHandle, gName1, gName)==KErrNone); |
|
428 |
test(aFindHandle==1); |
|
429 |
aFindHandle=0; |
|
430 |
test(pCon->FindByFullName(aFindHandle, _L("Owner"), gFullName)==KErrNone); |
|
431 |
test(aFindHandle==1); |
|
432 |
||
433 |
||
434 |
pObj2->__DbgTest(&dump1); |
|
435 |
temp=pCon->At(0); |
|
436 |
temp->__DbgTest(&dump2); |
|
437 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
438 |
dump1.iName==dump2.iName &&dump1.iContainer==dump2.iContainer); |
|
439 |
pObj3->__DbgTest(&dump1); |
|
440 |
temp=pCon->At(1); |
|
441 |
temp->__DbgTest(&dump2); |
|
442 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
443 |
dump1.iName==dump2.iName &&dump1.iContainer==dump2.iContainer); |
|
444 |
||
445 |
pCon->Remove(pObj2); |
|
446 |
pCon->Remove(pObj3); |
|
447 |
test(pCon->Count()==0); |
|
448 |
delete pCon; |
|
449 |
||
450 |
// Test expansion and shrinking |
|
451 |
__UHEAP_MARK; |
|
452 |
pCon=CObjectCon::NewL(); |
|
453 |
CObject** obj = new CObject*[2048]; |
|
454 |
test(obj!=0); |
|
455 |
TInt i; |
|
456 |
for (i=0; i<2048; ++i) |
|
457 |
{ |
|
458 |
obj[i] = new CObject; |
|
459 |
test(obj[i] != 0); |
|
460 |
} |
|
461 |
||
462 |
RTestHeap* h = RTestHeap::Install(); |
|
463 |
||
464 |
const TInt xov_values[] = {0,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048}; |
|
465 |
const TInt xov2_values[] = {1472, 960, 704, 448, 320, 192, 128, 96, 64, 48, 32, 24, 16, 12, 8, 6, 0}; |
|
466 |
const TInt* xov_ptr = xov_values; |
|
467 |
const TInt* xov2_ptr = xov2_values; |
|
468 |
TInt sz = 0; |
|
469 |
TInt xov = 0; |
|
470 |
TAny* ptr = 0; |
|
471 |
for (i=1; i<=2048; ++i) |
|
472 |
{ |
|
473 |
pCon->AddL(obj[i-1]); |
|
474 |
test(pCon->Count()==i); |
|
475 |
RTestHeap::TOpInfo opi; |
|
476 |
TInt r = h->GetLastOp(opi); |
|
477 |
if (i*4 <= sz) |
|
478 |
{ |
|
479 |
test(r==KErrNotFound); |
|
480 |
continue; |
|
481 |
} |
|
482 |
test(r==KErrNone); |
|
483 |
test.Printf(_L("Realloc at %d -> %d\n"), i, opi.iIntArg); |
|
484 |
test(i-1 == xov); |
|
485 |
test(opi.iOp == RTestHeap::EOpReAlloc); |
|
486 |
test(opi.iPtrArg == ptr); |
|
487 |
// recalc xov |
|
488 |
xov = *++xov_ptr; |
|
489 |
test(opi.iIntArg == xov*4); |
|
490 |
sz = xov*4; |
|
491 |
test(opi.iResult != 0); |
|
492 |
ptr = opi.iResult; |
|
493 |
} |
|
494 |
||
495 |
xov = *xov2_ptr; |
|
496 |
for (i=2047; i>=0; --i) |
|
497 |
{ |
|
498 |
pCon->Remove(obj[i]); |
|
499 |
test(pCon->Count()==i); |
|
500 |
RTestHeap::TOpInfo opi; |
|
501 |
TInt r = h->GetLastOp(opi); |
|
502 |
if (i>xov) |
|
503 |
{ |
|
504 |
test(r==KErrNotFound); |
|
505 |
continue; |
|
506 |
} |
|
507 |
test(r==KErrNone); |
|
508 |
test.Printf(_L("Realloc at %d -> %d\n"), i, opi.iIntArg); |
|
509 |
test(i == xov); |
|
510 |
if (i==0) |
|
511 |
{ |
|
512 |
test(opi.iOp == RTestHeap::EOpReAlloc || opi.iOp == RTestHeap::EOpFree); |
|
513 |
} |
|
514 |
else |
|
515 |
{ |
|
516 |
test(opi.iOp = RTestHeap::EOpReAlloc); |
|
517 |
test(opi.iResult == ptr); |
|
518 |
} |
|
519 |
test(opi.iPtrArg == ptr); |
|
520 |
// recalc xov |
|
521 |
xov = *++xov2_ptr; |
|
522 |
sz = *--xov_ptr; |
|
523 |
test(opi.iIntArg == sz*4); |
|
524 |
} |
|
525 |
||
526 |
delete pCon; |
|
527 |
for (i=0; i<2048; ++i) |
|
528 |
obj[i]->Close(); |
|
529 |
delete[] obj; |
|
530 |
h->Uninstall(); |
|
531 |
__UHEAP_MARKEND; |
|
532 |
} |
|
533 |
||
534 |
||
535 |
GLDEF_C void TestCObjects::Test7(void) |
|
536 |
{ |
|
537 |
// Test the methods of CObjectIx |
|
538 |
||
539 |
// Before an object can be added to a ConIx it first has to be added to a container because the |
|
540 |
// CObjectIx::Add method references theObject->iContainer->iName. But theObject->iContainer field |
|
541 |
// is only set (within the CObjectCon::Add method) IF the container has first been created by the |
|
542 |
// CObjectConIx::Create method, otherwise it is NULL and adding it to a CObjectIx will fail. |
|
543 |
CObjectIx *pIx=CObjectIx::NewL(); |
|
544 |
CObjectConIx *pConIx=CObjectConIx::NewL(); |
|
545 |
CObjectCon *pCon1=pConIx->CreateL(), |
|
546 |
*pCon2=pConIx->CreateL(); |
|
547 |
CObject *pObj1=new CObject, |
|
548 |
*pObj2=new CObject, |
|
549 |
*pObj3=new CObject, |
|
550 |
*temp; |
|
551 |
TInt aHandle1, aHandle2, aHandle3; |
|
552 |
TCObjectDump dump1, dump2; |
|
553 |
TPtrC name1(_S("Obj1")), name2(_S("Obj2")), name3(_S("Obj3")); |
|
554 |
||
555 |
// Create two containers with Obj1 and Obj2 in the first and Obj3 in the second |
|
556 |
pObj1->SetName(&name1); |
|
557 |
pObj2->SetName(&name2); |
|
558 |
pObj3->SetName(&name3); |
|
559 |
pCon1->AddL(pObj1); |
|
560 |
pCon1->AddL(pObj2); |
|
561 |
pCon2->AddL(pObj3); |
|
562 |
aHandle1=pIx->AddL(pObj1); |
|
563 |
aHandle2=pIx->AddL(pObj2); |
|
564 |
aHandle3=pIx->AddL(pObj3); |
|
565 |
// At(TInt aHandle) |
|
566 |
pObj1->__DbgTest(&dump1); |
|
567 |
temp=pIx->At(aHandle1); |
|
568 |
temp->__DbgTest(&dump2); |
|
569 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
570 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
571 |
pObj2->__DbgTest(&dump1); |
|
572 |
temp=pIx->At(aHandle2); |
|
573 |
temp->__DbgTest(&dump2); |
|
574 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
575 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
576 |
pObj3->__DbgTest(&dump1); |
|
577 |
temp=pIx->At(aHandle3); |
|
578 |
temp->__DbgTest(&dump2); |
|
579 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
580 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
581 |
// At(TInt aHandle, TInt aUniqueID); |
|
582 |
pObj1->__DbgTest(&dump1); |
|
583 |
temp=pIx->At(aHandle1, 1); |
|
584 |
temp->__DbgTest(&dump2); |
|
585 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
586 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
587 |
pObj2->__DbgTest(&dump1); |
|
588 |
temp=pIx->At(aHandle2, 1); |
|
589 |
temp->__DbgTest(&dump2); |
|
590 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
591 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
592 |
pObj3->__DbgTest(&dump1); |
|
593 |
temp=pIx->At(aHandle3, 2); |
|
594 |
temp->__DbgTest(&dump2); |
|
595 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
596 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
597 |
// Remove(Tint aHandle) |
|
598 |
pIx->Remove(aHandle2); |
|
599 |
pObj1->__DbgTest(&dump1); |
|
600 |
temp=pIx->At(aHandle1); |
|
601 |
temp->__DbgTest(&dump2); |
|
602 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
603 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
604 |
pObj3->__DbgTest(&dump1); |
|
605 |
temp=pIx->At(aHandle3); |
|
606 |
temp->__DbgTest(&dump2); |
|
607 |
test(dump1.iAccessCount==dump2.iAccessCount && dump1.iOwner==dump2.iOwner && |
|
608 |
dump1.iContainer==dump2.iContainer && dump1.iName==dump2.iName); |
|
609 |
pIx->Remove(aHandle1); |
|
610 |
pIx->Remove(aHandle3); |
|
611 |
// pIx->Remove(aHandle3); this will cause a crash |
|
612 |
||
613 |
// Removing an object from a CObjectIx calls the objects close method hence in this case |
|
614 |
// deleting it |
|
615 |
//delete pCon1; // The destructor for a container deletes its contained objects |
|
616 |
//delete pCon2; |
|
617 |
delete pConIx; // The CObjectConIx destructor deletes its containers |
|
618 |
delete pIx; // The CObjectIx destructor calls close on all its objects |
|
619 |
} |
|
620 |
||
621 |
GLDEF_C void TestCObjects::Test8(void) |
|
622 |
{ |
|
623 |
// Test all objects together |
|
624 |
CObjectIx *pIx=CObjectIx::NewL(); |
|
625 |
CObjectConIx *pConIx=CObjectConIx::NewL(); |
|
626 |
CObjectCon *pCon1=pConIx->CreateL(), |
|
627 |
*pCon2=pConIx->CreateL(); |
|
628 |
CObject *pObj1=new CObject, |
|
629 |
*pObj2=new CObject, |
|
630 |
*pObj3=new CObject, |
|
631 |
*pObj4=new CObject, |
|
632 |
*pObj5=new CObject, |
|
633 |
*temp; |
|
634 |
TInt tempHandle; |
|
635 |
TPtrC name1(_S("Obj1")), name2(_S("Obj2")), name3(_S("Obj3")), name4(_S("Obj4")), name5(_S("Obj5")); |
|
636 |
||
637 |
// Create two containers with Obj1,Obj2, Obj3 in the first and Obj4 and Obj5 in the second |
|
638 |
// Obj1 owns Obj2 which owns Obj3 |
|
639 |
pObj1->SetName(&name1); |
|
640 |
pObj2->SetName(&name2); |
|
641 |
pObj2->SetOwner(pObj1); |
|
642 |
pObj3->SetName(&name3); |
|
643 |
pObj3->SetOwner(pObj2); |
|
644 |
pObj4->SetName(&name4); |
|
645 |
pObj5->SetName(&name5); |
|
646 |
pCon1->AddL(pObj1); |
|
647 |
pCon1->AddL(pObj2); |
|
648 |
pCon1->AddL(pObj3); |
|
649 |
pCon2->AddL(pObj4); |
|
650 |
pCon2->AddL(pObj5); |
|
651 |
pIx->AddL(pObj1); |
|
652 |
pIx->AddL(pObj2); |
|
653 |
pIx->AddL(pObj3); |
|
654 |
pIx->AddL(pObj4); |
|
655 |
pIx->AddL(pObj5); |
|
656 |
||
657 |
||
658 |
tempHandle=0; |
|
659 |
GetObjName(gName1,*pObj1); |
|
660 |
pCon1->FindByName(tempHandle, gName1, gName); |
|
661 |
temp=pCon1->At(tempHandle); |
|
662 |
GetObjName(gName2,*temp); |
|
663 |
test(gName2==gName1); |
|
664 |
tempHandle=0; |
|
665 |
GetObjFullName(gFullName1,*pObj1); |
|
666 |
pCon1->FindByFullName(tempHandle, gFullName1, gFullName); |
|
667 |
temp=pCon1->At(tempHandle); |
|
668 |
GetObjName(gName2,*temp); |
|
669 |
test(gName2==gName1); |
|
670 |
||
671 |
tempHandle=0; |
|
672 |
GetObjName(gName1,*pObj2); |
|
673 |
pCon1->FindByName(tempHandle, gName1, gName); |
|
674 |
temp=pCon1->At(tempHandle); |
|
675 |
GetObjName(gName2,*temp); |
|
676 |
test(gName2==gName1); |
|
677 |
tempHandle=0; |
|
678 |
GetObjFullName(gFullName1,*pObj2); |
|
679 |
pCon1->FindByFullName(tempHandle, gFullName1, gFullName); |
|
680 |
temp=pCon1->At(tempHandle); |
|
681 |
GetObjName(gName2,*temp); |
|
682 |
test(gName2==gName1); |
|
683 |
||
684 |
tempHandle=0; |
|
685 |
GetObjName(gName1,*pObj3); |
|
686 |
pCon1->FindByName(tempHandle, gName1, gName); |
|
687 |
temp=pCon1->At(tempHandle); |
|
688 |
GetObjName(gName2,*temp); |
|
689 |
test(gName2==gName1); |
|
690 |
tempHandle=0; |
|
691 |
GetObjFullName(gFullName1,*pObj3); |
|
692 |
pCon1->FindByFullName(tempHandle, gFullName1, gFullName); |
|
693 |
temp=pCon1->At(tempHandle); |
|
694 |
GetObjName(gName2,*temp); |
|
695 |
test(gName2==gName1); |
|
696 |
||
697 |
tempHandle=0; |
|
698 |
GetObjName(gName1,*pObj4); |
|
699 |
pCon2->FindByName(tempHandle, gName1, gName); |
|
700 |
temp=pCon2->At(tempHandle); |
|
701 |
GetObjName(gName2,*temp); |
|
702 |
test(gName2==gName1); |
|
703 |
tempHandle=0; |
|
704 |
GetObjFullName(gFullName1,*pObj4); |
|
705 |
pCon2->FindByFullName(tempHandle, gFullName1, gFullName); |
|
706 |
temp=pCon2->At(tempHandle); |
|
707 |
GetObjName(gName2,*temp); |
|
708 |
test(gName1==gName2); |
|
709 |
||
710 |
tempHandle=0; |
|
711 |
GetObjName(gName1,*pObj5); |
|
712 |
pCon2->FindByName(tempHandle, gName1, gName); |
|
713 |
temp=pCon2->At(tempHandle); |
|
714 |
GetObjName(gName2,*temp); |
|
715 |
test(gName2==gName1); |
|
716 |
tempHandle=0; |
|
717 |
GetObjFullName(gFullName1,*pObj5); |
|
718 |
pCon2->FindByFullName(tempHandle, gFullName1, gFullName); |
|
719 |
temp=pCon2->At(tempHandle); |
|
720 |
GetObjName(gName2,*temp); |
|
721 |
test(gName2==gName1); |
|
722 |
||
723 |
||
724 |
tempHandle=0; |
|
725 |
test(pCon1->FindByName(tempHandle, _L("*1"), gName)==KErrNone); |
|
726 |
GetObjName(gName1,*pObj1); |
|
727 |
test(gName==gName1); |
|
728 |
tempHandle=0; |
|
729 |
test(pCon1->FindByFullName(tempHandle, _L("*::*"), gFullName)==KErrNone); |
|
730 |
GetObjFullName(gFullName1,*pObj2); |
|
731 |
test(gFullName==gFullName1); |
|
732 |
GetObjName(gName1,*pObj3); |
|
733 |
for(tempHandle=0;gName!=gName1;pCon1->FindByName(tempHandle, _L("????"),gName)) {}; |
|
734 |
test(gName==gName1); |
|
735 |
||
736 |
||
737 |
pObj1->Close(); // Deletes it and removes it from its container |
|
738 |
pObj3->Close(); |
|
739 |
tempHandle=0; |
|
740 |
test(pCon1->FindByName(tempHandle, _L("Obj1"), gName)==KErrNotFound); |
|
741 |
tempHandle=0; |
|
742 |
test(pCon1->FindByName(tempHandle, _L("Obj3"), gName)==KErrNotFound); |
|
743 |
tempHandle=0; |
|
744 |
GetObjName(gName1,*pObj2); |
|
745 |
test(pCon1->FindByName(tempHandle, gName1, gName)==KErrNone); |
|
746 |
test(gName==gName1); |
|
747 |
tempHandle=0; |
|
748 |
//CObject* x=new CObject; |
|
749 |
//x->SetName(_L("xxxx")); |
|
750 |
//pCon1->FindByFullName(tempHandle, pObj2->FullName(), aFullName); |
|
751 |
// FullName is set to Xxxx::Obj2 |
|
752 |
||
753 |
} |
|
754 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
TInt PanicCObjectConIndexOutOfRangeFn(TAny* aCObjectCon) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
(*pCObjectCon)[1]; // no objects added to the container |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
return KErrNone; // should not come here |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
TInt PanicCObjectConFindIndexOutOfRangeFn(TAny* aCObjectCon) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
TInt aFindHandle=1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
pCObjectCon->At(aFindHandle); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
return KErrNone; // should not come here |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
TInt PanicCObjectConFindBadHandleFn(TAny* aCObjectCon) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
TInt aFindHandle=KMaxTInt; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
pCObjectCon->At(aFindHandle); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
return KErrNone; // should not come here |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
TInt PanicCObjectIxIndexOutOfRangeFn(TAny* aCObjectIx) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
CObjectIx* pCObjectIx=(CObjectIx*)aCObjectIx; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
(*pCObjectIx)[1]; // no objects added to the container |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
return KErrNone; // should not come here |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
785 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
void StartPanicTest(TInt aPanicType) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
CObjectCon* pCObjectCon=CObjectCon::NewL(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
CObjectIx* pCObjectIx=CObjectIx::NewL(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
790 |
RThread thread; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
TRequestStatus status; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
TInt r=KErrNone; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
switch (aPanicType) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
795 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
796 |
case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
797 |
r=thread.Create(_L("PanicCObjectIxIndexOutOfRangeThread"),PanicCObjectIxIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectIx); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
798 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
r=thread.Create(_L("PanicCObjectConFindBadHandleThread"),PanicCObjectConFindBadHandleFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
801 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
802 |
case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
803 |
r=thread.Create(_L("PanicCObjectConFindIndexOutOfRangeThread"),PanicCObjectConFindIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
804 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
806 |
r=thread.Create(_L("PanicCObjectConIndexOutOfRangeThread"),PanicCObjectConIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
808 |
default: |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
809 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
810 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
811 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
812 |
test (r==KErrNone); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
813 |
thread.SetPriority(EPriorityMore); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
thread.Logon(status); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
815 |
thread.Resume(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
816 |
User::WaitForRequest(status); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
817 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
818 |
test(status.Int() != KErrNone); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
819 |
test(thread.ExitType()==EExitPanic); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
820 |
test(thread.ExitCategory()==_L("E32USER-CBase")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
821 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
switch (aPanicType) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
823 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
test(thread.ExitReason()==EArrayIndexOutOfRange); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
827 |
case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
828 |
test(thread.ExitReason()==EObjFindBadHandle); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
829 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
830 |
case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
test(thread.ExitReason()==EObjFindIndexOutOfRange); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
833 |
case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
test(thread.ExitReason()==EArrayIndexOutOfRange); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
835 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
836 |
default: |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
837 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
838 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
839 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
CLOSE_AND_WAIT(thread); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
delete pCObjectCon; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
delete pCObjectIx; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
843 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
844 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
845 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
846 |
GLDEF_C void TestCObjects::Test9(void) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
848 |
// Disable JIT debugging. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
849 |
TBool justInTime=User::JustInTime(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
850 |
User::SetJustInTime(EFalse); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
851 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
852 |
test.Next(_L("test PanicCObjectConFindBadHandle")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
853 |
StartPanicTest(EObjFindBadHandle); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
854 |
test.Next(_L("test PanicCObjectConFindIndexOutOfRange")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
855 |
StartPanicTest(EObjFindIndexOutOfRange); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
856 |
test.Next(_L("test PanicCObjectConIndexOutOfRange")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
857 |
StartPanicTest(EArrayIndexOutOfRange); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
test.Next(_L("test PanicCObjectIxIndexOutOfRange")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
StartPanicTest(0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
860 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
861 |
// Put JIT debugging back to previous status. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
862 |
User::SetJustInTime(justInTime); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
863 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
864 |
test.End(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
865 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
866 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
867 |
|
0 | 868 |
GLDEF_C void TestCObjects::GetObjName(TName& aDest,const CObject& aObj) |
869 |
// |
|
870 |
// Utility function to reduce stack usage in functions, and so get rid of __chkstk errors |
|
871 |
// |
|
872 |
{ |
|
873 |
aDest=aObj.Name(); |
|
874 |
} |
|
875 |
||
876 |
GLDEF_C void TestCObjects::GetObjFullName(TFullName& aDest,const CObject& aObj) |
|
877 |
// |
|
878 |
// Utility function to reduce stack usage in functions, and so get rid of __chkstk errors |
|
879 |
// |
|
880 |
{ |
|
881 |
aDest=aObj.FullName(); |
|
882 |
} |
|
883 |
||
884 |
void testHandles() |
|
885 |
||
886 |
{ |
|
887 |
||
888 |
CObjectConIx* myConIx=CObjectConIx::NewL(); |
|
889 |
CObjectCon* myCon= myConIx->CreateL(); |
|
890 |
CObjectIx* myIx=CObjectIx::NewL(); |
|
891 |
test(myCon->UniqueID()!=0); |
|
892 |
||
893 |
for (TInt i=0;i<0x4006; i++) |
|
894 |
{ |
|
895 |
CObject* myObj=new CObject; |
|
896 |
myCon->AddL(myObj); |
|
897 |
TInt handle=myIx->AddL(myObj); |
|
898 |
if ((handle&0xffff0000)==0x3fff0000) |
|
899 |
test.Printf(_L("Created biggest handle\n")); |
|
900 |
test (handle!=0); |
|
901 |
myIx->Remove(handle); |
|
902 |
} |
|
903 |
delete myIx; |
|
904 |
delete myConIx; |
|
905 |
} |
|
906 |
||
907 |
void testSpeed() |
|
908 |
||
909 |
{ |
|
910 |
||
911 |
const TInt numObjects=0x600; |
|
912 |
CObjectConIx* myConIx=CObjectConIx::NewL(); |
|
913 |
CObjectCon* myCon= myConIx->CreateL(); |
|
914 |
// CObjectIx* myIx=CObjectIx::NewL(); |
|
915 |
TTime start; |
|
916 |
TTime end; |
|
917 |
TInt64 diff; |
|
918 |
TInt i; |
|
919 |
||
920 |
start.HomeTime(); |
|
921 |
for (i=0;i<numObjects; i++) |
|
922 |
{ |
|
923 |
CObject* myObj=new CObject; |
|
924 |
TName name; |
|
925 |
name.Format(_L("CObject%d"),i); |
|
926 |
myObj->SetName(&name); |
|
927 |
myCon->AddL(myObj); |
|
928 |
} |
|
929 |
end.HomeTime(); |
|
930 |
diff=(end.Int64()-start.Int64())/100000; |
|
931 |
test.Printf(_L("Time for 0x%08x named objects = %d tenths of secs\n"),numObjects,I64INT(diff)); |
|
932 |
||
933 |
// If run as a manual test (when enhancements to RTEST arrive) |
|
934 |
// test.Printf(_L("Press a key to continue with these spammy tests\n")); |
|
935 |
// test.Getch(); |
|
936 |
||
937 |
const TInt numObjects2=0x600; |
|
938 |
// CObjectConIx* myConIx2=CObjectConIx::NewL(); |
|
939 |
CObjectCon* myCon2= myConIx->CreateL(); |
|
940 |
// CObjectIx* myIx2=CObjectIx::NewL(); |
|
941 |
||
942 |
start.HomeTime(); |
|
943 |
for (i=0;i<numObjects2; i++) |
|
944 |
{ |
|
945 |
CObject* myObj=new CObject; |
|
946 |
TName name; |
|
947 |
name.Format(_L("CObject%d"),i); |
|
948 |
myCon2->AddL(myObj); |
|
949 |
} |
|
950 |
end.HomeTime(); |
|
951 |
diff=(end.Int64()-start.Int64())/100000; |
|
952 |
test.Printf(_L("Time for 0x%08x unnamed objects = %d tenths of secs\n"),numObjects2,I64INT(diff)); |
|
953 |
||
954 |
||
955 |
// If run as a manual test (when enhancements to RTEST arrive) |
|
956 |
// test.Printf(_L("Press a key to continue with these spammy tests\n")); |
|
957 |
// test.Getch(); |
|
958 |
||
959 |
// delete myIx; |
|
960 |
// delete myConIx; |
|
961 |
} |
|
962 |
||
963 |
||
964 |
||
965 |
const TInt KObjectIndexMask=0x7fff; |
|
966 |
||
967 |
//Tests CObjectIx class |
|
968 |
class TestCObjectIx |
|
969 |
{ |
|
970 |
public: |
|
971 |
void StartL(void); |
|
972 |
~TestCObjectIx(); |
|
973 |
private: |
|
974 |
void Test1(TInt aSize); |
|
975 |
void Test2(TInt aSize); |
|
976 |
void Test3(TInt aSize, TBool aPerformanceTest); |
|
977 |
inline TInt Index(TInt aHandle) {return(aHandle&KObjectIndexMask);} |
|
978 |
||
979 |
private: |
|
980 |
struct COBjAndHandle |
|
981 |
{ |
|
982 |
CObject* iObject; |
|
983 |
TInt iHandle; |
|
984 |
}; |
|
985 |
||
986 |
CObjectConIx* iMyConIx; |
|
987 |
CObjectCon* iMyCon; |
|
988 |
CObjectIx* iMyIx; |
|
989 |
TUint iSeed[2]; |
|
990 |
COBjAndHandle* iObjAndHandle; |
|
991 |
}; |
|
992 |
||
993 |
const TInt KMaxTestObjects = (1<<11); |
|
994 |
||
995 |
//Runs all tests (methods) of the class |
|
996 |
void TestCObjectIx::StartL(void) |
|
997 |
{ |
|
998 |
TInt i; |
|
999 |
iMyConIx=CObjectConIx::NewL(); |
|
1000 |
iMyCon= iMyConIx->CreateL(); |
|
1001 |
iObjAndHandle = (COBjAndHandle*) User::AllocL(KMaxTestObjects * sizeof(COBjAndHandle)); |
|
1002 |
||
1003 |
test.Title(); |
|
1004 |
test.Start(_L("Test CObjectIx")); |
|
1005 |
||
1006 |
test.Next(_L("Add and remove objects in the same order...")); |
|
1007 |
TUint32 startTime = User::NTickCount(); |
|
1008 |
for (i=1;i<2000;i=i+10) Test1(i); |
|
1009 |
test.Printf(_L("...done in %d msec\n"), User::NTickCount()-startTime); |
|
1010 |
||
1011 |
test.Next(_L("Add and remove objects in the reverse order...")); |
|
1012 |
startTime = User::NTickCount(); |
|
1013 |
for (i=1;i<2000;i=i+10) Test2(i); |
|
1014 |
test.Printf(_L("...done in %d msec\n"), User::NTickCount()-startTime); |
|
1015 |
||
1016 |
test.Next(_L("Add and remove objects in random order...")); |
|
1017 |
iSeed[0]=User::TickCount(); |
|
1018 |
test.Printf(_L("The initial seed for the random function is: S0=%xh S1=%xh\n"), iSeed[0], iSeed[1]); |
|
1019 |
for (i=2;i<=KMaxTestObjects/2; i<<=1) |
|
1020 |
Test3(i-1, EFalse); |
|
1021 |
||
1022 |
test.Next(_L("Add and remove objects in random order - performance test...")); |
|
1023 |
iSeed[0]=0; |
|
1024 |
iSeed[1]=1; |
|
1025 |
startTime = User::NTickCount(); |
|
1026 |
for (i=2;i<=KMaxTestObjects; i<<=1) |
|
1027 |
Test3(i-1, ETrue); |
|
1028 |
test.Printf(_L("...done in %d msec\n"), User::NTickCount()-startTime); |
|
1029 |
test.Printf(_L("CAUTION: Test changed in May 2005. Comparison of timings with those before then are not valid.\n")); |
|
1030 |
||
1031 |
test.End(); |
|
1032 |
} |
|
1033 |
||
1034 |
TestCObjectIx::~TestCObjectIx() |
|
1035 |
{ |
|
1036 |
delete iMyConIx; |
|
1037 |
delete [] iObjAndHandle; |
|
1038 |
} |
|
1039 |
||
1040 |
//Adds a number of CObjects to CObjectIx, then removes them in the same order. |
|
1041 |
void TestCObjectIx::Test1(TInt aSize) |
|
1042 |
{ |
|
1043 |
TInt i; |
|
1044 |
iMyIx=CObjectIx::NewL(); |
|
1045 |
||
1046 |
for (i=0; i<aSize; i++) //Add |
|
1047 |
{ |
|
1048 |
if( (iObjAndHandle[i].iObject = new CObject) == NULL) User::Leave(KErrNoMemory); |
|
1049 |
iMyCon->AddL(iObjAndHandle[i].iObject); |
|
1050 |
iObjAndHandle[i].iHandle = iMyIx->AddL(iObjAndHandle[i].iObject); |
|
1051 |
} |
|
1052 |
||
1053 |
for (i=0; i<aSize; i++) //Remove |
|
1054 |
iMyIx->Remove(iObjAndHandle[i].iHandle); |
|
1055 |
||
1056 |
delete iMyIx; |
|
1057 |
iMyIx=0; |
|
1058 |
} |
|
1059 |
||
1060 |
||
1061 |
//Adds a number of CObjects to CObjectIx, then removes them in the reverse order. |
|
1062 |
void TestCObjectIx::Test2(TInt aSize) |
|
1063 |
{ |
|
1064 |
TInt i; |
|
1065 |
iMyIx=CObjectIx::NewL(); |
|
1066 |
||
1067 |
for (i=0; i<aSize; i++) //Add |
|
1068 |
{ |
|
1069 |
if( (iObjAndHandle[i].iObject = new CObject) == NULL) User::Leave(KErrNoMemory); |
|
1070 |
iMyCon->AddL(iObjAndHandle[i].iObject); |
|
1071 |
iObjAndHandle[i].iHandle = iMyIx->AddL(iObjAndHandle[i].iObject); |
|
1072 |
} |
|
1073 |
||
1074 |
for (i=aSize-1; i>=aSize; i--) //Remove |
|
1075 |
iMyIx->Remove(iObjAndHandle[i].iHandle); |
|
1076 |
||
1077 |
delete iMyIx; |
|
1078 |
iMyIx=0; |
|
1079 |
} |
|
1080 |
||
1081 |
||
1082 |
//Adds and removes random number of CObjects to/from CObjectIx. |
|
1083 |
void TestCObjectIx::Test3(TInt aSize, TBool aPerformanceTest) |
|
1084 |
{ |
|
1085 |
TInt index, x; |
|
1086 |
if(!aPerformanceTest) |
|
1087 |
test.Printf(_L("Testing size %d.The seeds are: S0=%xh S1=%xh\n"), aSize, iSeed[0], iSeed[1]); |
|
1088 |
||
1089 |
//---Create & init the objects we need |
|
1090 |
for (x=0; x<aSize; x++) iObjAndHandle[x].iObject = NULL; //initialize the array |
|
1091 |
iMyIx=CObjectIx::NewL(); |
|
1092 |
||
1093 |
for (x = 0; x<100; x++) |
|
1094 |
{ |
|
1095 |
||
1096 |
//---Add the random number of objects (in random order)--- |
|
1097 |
TInt toAdd=Random(iSeed)%(aSize-iMyIx->ActiveCount()+1); |
|
1098 |
//test.Printf(_L("Adding %d objects\n"), toAdd ); |
|
1099 |
while (toAdd--) |
|
1100 |
{ |
|
1101 |
index=Random(iSeed)%aSize; |
|
1102 |
while (iObjAndHandle[index].iObject) //Find the next NULL pointer |
|
1103 |
{ ++index; if(index>=aSize) index=0; } |
|
1104 |
if( (iObjAndHandle[index].iObject = new CObject) == NULL) User::Leave(KErrNoMemory); |
|
1105 |
iMyCon->AddL(iObjAndHandle[index].iObject); |
|
1106 |
iObjAndHandle[index].iHandle = iMyIx->AddL(iObjAndHandle[index].iObject); |
|
1107 |
//test.Printf(_L("%d(%d) "), index,iObjAndHandle[index].iHandle & 0x7fff ); |
|
1108 |
} |
|
1109 |
//test.Printf(_L("\n")); |
|
1110 |
||
1111 |
||
1112 |
//---Remove the random number of objects (in random order)--- |
|
1113 |
TInt toRemove=Random(iSeed)%(iMyIx->ActiveCount()+1); |
|
1114 |
//test.Printf(_L("Removing %d objects: "), toRemove ); |
|
1115 |
while (toRemove--) |
|
1116 |
{ |
|
1117 |
index=Random(iSeed)%aSize; |
|
1118 |
while (!iObjAndHandle[index].iObject) //Find the next non-NULL pointer |
|
1119 |
{ ++index; if(index>=aSize) index=0; } |
|
1120 |
//test.Printf(_L("%d(%d) "), index,iObjAndHandle[index].iHandle & 0x7fff ); |
|
1121 |
iMyIx->Remove(iObjAndHandle[index].iHandle); |
|
1122 |
iObjAndHandle[index].iObject=NULL; |
|
1123 |
} |
|
1124 |
//test.Printf(_L("\n")); |
|
1125 |
||
1126 |
||
1127 |
//---Test data consistency--- |
|
1128 |
if(aPerformanceTest) continue; |
|
1129 |
||
1130 |
TInt objNum=0; |
|
1131 |
for (index=0;index<aSize;index++) |
|
1132 |
{ |
|
1133 |
if (iObjAndHandle[index].iObject) |
|
1134 |
{ |
|
1135 |
objNum++; |
|
1136 |
//Test At(TInt aHandle) method |
|
1137 |
test(iObjAndHandle[index].iObject == iMyIx->At(iObjAndHandle[index].iHandle)); |
|
1138 |
//Test Count(CObject* aObject) method |
|
1139 |
test(1==iMyIx->Count(iObjAndHandle[index].iObject)); |
|
1140 |
//Test At(CObject* aObject) method |
|
1141 |
test(iObjAndHandle[index].iHandle==iMyIx->At(iObjAndHandle[index].iObject)); |
|
1142 |
//Test operator[](TInt index) method |
|
1143 |
test(iObjAndHandle[index].iObject==(*iMyIx)[Index(iObjAndHandle[index].iHandle)]); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
||
1147 |
test (objNum==iMyIx->ActiveCount()); |
|
1148 |
//test.Printf(_L("%d objects in array\n"), objNum); |
|
1149 |
} |
|
1150 |
||
1151 |
delete iMyIx; |
|
1152 |
iMyIx=NULL; |
|
1153 |
} |
|
1154 |
||
1155 |
// Test that things work when the unique ID of the object container grows larger |
|
1156 |
// than 15 bits |
|
1157 |
void TestCObjectConIxL(void) |
|
1158 |
{ |
|
1159 |
const TInt KCObjectConLimit = 65535; |
|
1160 |
_LIT(KAnyMatch, "*"); |
|
1161 |
||
1162 |
__UHEAP_MARK; |
|
1163 |
||
1164 |
CObjectConIx* conIx = CObjectConIx::NewL(); |
|
1165 |
CObjectIx* ix = CObjectIx::NewL(); |
|
1166 |
TInt i; |
|
1167 |
||
1168 |
test.Next(_L("Test repeated add/remove of object containers")); |
|
1169 |
for (i = 0 ; i < KCObjectConLimit * 2 ; ++i) |
|
1170 |
{ |
|
1171 |
CObjectCon* con = conIx->CreateL(); |
|
1172 |
CObject* obj = new (ELeave) CObject(); |
|
1173 |
con->AddL(obj); |
|
1174 |
||
1175 |
TInt handle = ix->AddL(obj); |
|
1176 |
test(ix->At(handle) == obj); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1177 |
test(ix->AtL(handle) == obj); |
0 | 1178 |
test(ix->At(handle, con->UniqueID()) == obj); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
test(ix->AtL(handle, con->UniqueID()) == obj); |
0 | 1180 |
|
1181 |
TName name; |
|
1182 |
TInt findHandle = 0; |
|
1183 |
test(con->FindByName(findHandle, KAnyMatch, name) == KErrNone); |
|
1184 |
test(con->AtL(findHandle) == obj); |
|
1185 |
test(con->At(findHandle) == obj); |
|
1186 |
test(conIx->Lookup(findHandle) == con); |
|
1187 |
test(con->FindByName(findHandle, KAnyMatch, name) == KErrNotFound); |
|
1188 |
||
1189 |
TFullName fullName; |
|
1190 |
findHandle = 0; |
|
1191 |
test(con->FindByFullName(findHandle, KAnyMatch, fullName) == KErrNone); |
|
1192 |
test(con->AtL(findHandle) == obj); |
|
1193 |
test(con->At(findHandle) == obj); |
|
1194 |
test(conIx->Lookup(findHandle) == con); |
|
1195 |
test(con->FindByFullName(findHandle, KAnyMatch, fullName) == KErrNotFound); |
|
1196 |
||
1197 |
ix->Remove(handle); |
|
1198 |
conIx->Remove(con); |
|
1199 |
} |
|
1200 |
||
1201 |
test.Next(_L("Test adding maximum possible number of object containers")); |
|
1202 |
RPointerArray<CObjectCon> cons; |
|
1203 |
for (i = 0 ; i < KCObjectConLimit ; ++i) |
|
1204 |
{ |
|
1205 |
CObjectCon* con = conIx->CreateL(); |
|
1206 |
cons.AppendL(con); |
|
1207 |
} |
|
1208 |
TRAPD(err, conIx->CreateL()); |
|
1209 |
test(err == KErrOverflow); |
|
1210 |
||
1211 |
test.Next(_L("Test unique IDs are really unique after ID value has wrapped")); |
|
1212 |
for (i = 100 ; i < KCObjectConLimit ; ++i) |
|
1213 |
{ |
|
1214 |
CObjectCon* con = cons[i]; |
|
1215 |
conIx->Remove(con); |
|
1216 |
} |
|
1217 |
for (i = 100 ; i < 200 ; ++i) |
|
1218 |
{ |
|
1219 |
CObjectCon* con = conIx->CreateL(); |
|
1220 |
cons[i] = con; |
|
1221 |
} |
|
1222 |
for (i = 0 ; i < 200 ; ++i) |
|
1223 |
{ |
|
1224 |
TName name; |
|
1225 |
TInt findHandle = 0; |
|
1226 |
CObjectCon* con = cons[i]; |
|
1227 |
||
1228 |
CObject* obj = new (ELeave) CObject(); |
|
1229 |
con->AddL(obj); |
|
1230 |
||
1231 |
test(con->FindByName(findHandle, KAnyMatch, name) == KErrNone); |
|
1232 |
test(conIx->Lookup(findHandle) == con); |
|
1233 |
||
1234 |
obj->Close(); |
|
1235 |
} |
|
1236 |
for (i = 0 ; i < 200 ; ++i) |
|
1237 |
{ |
|
1238 |
CObjectCon* con = cons[i]; |
|
1239 |
conIx->Remove(con); |
|
1240 |
} |
|
1241 |
cons.Close(); |
|
1242 |
||
1243 |
delete ix; |
|
1244 |
delete conIx; |
|
1245 |
||
1246 |
__UHEAP_MARKEND; |
|
1247 |
} |
|
1248 |
||
1249 |
GLDEF_C TInt E32Main() |
|
1250 |
{ |
|
1251 |
||
1252 |
CTrapCleanup* trapHandler=CTrapCleanup::New(); |
|
1253 |
test(trapHandler!=NULL); |
|
1254 |
||
1255 |
test.Title(); |
|
1256 |
test.Start(_L("TEST METHODS ARE IN THE DLL")); |
|
1257 |
||
1258 |
__UHEAP_MARK; |
|
1259 |
||
1260 |
TestCObjectIx* TCobjectIx = new TestCObjectIx; |
|
1261 |
TRAPD(ret, TCobjectIx->StartL()); |
|
1262 |
test(KErrNone == ret); |
|
1263 |
delete TCobjectIx; |
|
1264 |
||
1265 |
__UHEAP_MARKEND; |
|
1266 |
||
1267 |
test.Next(_L("Generate lots of handles")); |
|
1268 |
testHandles(); |
|
1269 |
||
1270 |
test.Next(_L("Test CObjectCon is fast enough")); |
|
1271 |
testSpeed(); |
|
1272 |
||
1273 |
TestCObjects T; |
|
1274 |
test.Next(_L("CObject methods")); |
|
1275 |
T.Test1(); |
|
1276 |
test.Next(_L("CObjectCon methods")); |
|
1277 |
T.Test2(); |
|
1278 |
test.Next(_L("CObjectIx methods")); |
|
1279 |
T.Test3(); |
|
1280 |
test.Next(_L("CObjectConIx methods")); |
|
1281 |
T.Test4(); |
|
1282 |
test.Next(_L("TEST THE METHODS")); |
|
1283 |
test.Next(_L("CObject")); |
|
1284 |
T.Test5(); |
|
1285 |
test.Next(_L("CObjectCon")); |
|
1286 |
T.Test6(); |
|
1287 |
test.Next(_L("CObjectIx")); |
|
1288 |
T.Test7(); |
|
1289 |
||
1290 |
////////////////////////////// |
|
1291 |
// PROPER TESTING STARTS HERE |
|
1292 |
////////////////////////////// |
|
1293 |
test.Next(_L("All objects")); |
|
1294 |
T.Test8(); |
|
1295 |
||
1296 |
test.Next(_L("CObjectConIx")); |
|
1297 |
TRAPD(err, TestCObjectConIxL()); |
|
1298 |
if (err != KErrNone) |
|
1299 |
test.Printf(_L("TestCObjectConIxL left with %d\n"), err); |
|
1300 |
test(err == KErrNone); |
|
1301 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
//Test Panics |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
test.Start(_L("Test Panic functions")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
T.Test9(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
|
0 | 1306 |
test.End(); |
1307 |
||
1308 |
delete trapHandler; |
|
1309 |
return(KErrNone); |
|
1310 |
} |