sl@0
|
1 |
// Copyright (c) 2008-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 "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 |
// Overview:
|
sl@0
|
15 |
// Test methods of the LManagedX and LCleanedupX classes.
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "emanaged.h"
|
sl@0
|
21 |
#include <e32base.h>
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
#include <e32def.h>
|
sl@0
|
24 |
#include <e32cmn.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
extern RTest test;
|
sl@0
|
28 |
|
sl@0
|
29 |
template<TInt Value>
|
sl@0
|
30 |
class CTracker : public CBase
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
enum TConstructionMode { ENonleavingConstructor, EConstructorLeaves};
|
sl@0
|
34 |
|
sl@0
|
35 |
static CTracker* NewL()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
CTracker* ptr = new(ELeave) CTracker;
|
sl@0
|
38 |
ptr->ConstructL();
|
sl@0
|
39 |
return ptr;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
CTracker():iData(NULL)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
test.Printf(_L(" CTracker - %x\n"), this);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
void ConstructL()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
test.Printf(_L(" CTracker::ConstructL - %x\n"), this);
|
sl@0
|
49 |
iData = new(ELeave) TInt(Value);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
public:
|
sl@0
|
52 |
virtual ~CTracker()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
test.Printf(_L(" ~CTracker - %x\n"), this);
|
sl@0
|
55 |
if(iData)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
delete iData;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
virtual void MemFunc()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
test.Printf(_L(" CTracker::MemFunc - %x\n"), this);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
static void StaticMemberRef(const CTracker& aTracker)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
test.Printf(_L(" CTracker::StaticMemberRef - %x\n"), &aTracker);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
static void StaticMemberPtr(CTracker* aTracker)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
test.Printf(_L(" CTracker::StaticMemberPtr - %x\n"), aTracker);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
private:
|
sl@0
|
77 |
TInt* iData;
|
sl@0
|
78 |
};
|
sl@0
|
79 |
|
sl@0
|
80 |
namespace Log
|
sl@0
|
81 |
{
|
sl@0
|
82 |
|
sl@0
|
83 |
class RLoggerNew
|
sl@0
|
84 |
{
|
sl@0
|
85 |
public:
|
sl@0
|
86 |
RLoggerNew()
|
sl@0
|
87 |
: iData(NULL)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
test.Printf(_L(" RLoggerNew - %x\n"), this);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
RLoggerNew(TInt* aData)
|
sl@0
|
93 |
: iData(aData)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
test.Printf(_L(" RLoggerNew - %x ptr %x -> val %d\n"), this, aData, *iData);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
RLoggerNew(TInt aValue)
|
sl@0
|
99 |
: iData(new(ELeave) TInt(aValue))
|
sl@0
|
100 |
{
|
sl@0
|
101 |
test.Printf(_L(" RLoggerNew - %x value %d\n"), this, *iData);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
void OpenL(TInt aValue)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
iData = new(ELeave) TInt(aValue);
|
sl@0
|
107 |
test.Printf(_L(" RLoggerNew::OpenL(TInt aValue) - %x value %d\n"), this, *iData);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
RLoggerNew(const RLoggerNew& aLogger)
|
sl@0
|
111 |
: iData(aLogger.iData)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
test.Printf(_L(" RLoggerNew::RLoggerNew(const RLoggerNew&) - %x (copy)\n"), this);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
RLoggerNew& operator=(const RLoggerNew& aLogger)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
iData = aLogger.iData;
|
sl@0
|
120 |
|
sl@0
|
121 |
test.Printf(_L(" RLoggerNew::operator=(const RLoggerNew&) - %x copy from %x val %d\n"), this, &aLogger, *aLogger.iData);
|
sl@0
|
122 |
return *this;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
|
sl@0
|
126 |
~RLoggerNew()
|
sl@0
|
127 |
{
|
sl@0
|
128 |
test.Printf(_L(" ~RLoggerNew - %x\n"), this);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
|
sl@0
|
132 |
void Close()
|
sl@0
|
133 |
{
|
sl@0
|
134 |
test.Printf(_L(" RLoggerNew::Close - %x\n"), this);
|
sl@0
|
135 |
|
sl@0
|
136 |
// Open or non-NULL initializing constructor not called or
|
sl@0
|
137 |
// cleanup function already called
|
sl@0
|
138 |
|
sl@0
|
139 |
__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
|
sl@0
|
140 |
delete iData;
|
sl@0
|
141 |
iData = NULL;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
|
sl@0
|
145 |
void Release()
|
sl@0
|
146 |
{
|
sl@0
|
147 |
test.Printf(_L(" RLoggerNew::Release - %x\n"), this);
|
sl@0
|
148 |
|
sl@0
|
149 |
// Open or non-NULL initializing constructor not called or
|
sl@0
|
150 |
// cleanup function already called
|
sl@0
|
151 |
|
sl@0
|
152 |
__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
|
sl@0
|
153 |
delete iData;
|
sl@0
|
154 |
iData = NULL;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
|
sl@0
|
158 |
void Destroy()
|
sl@0
|
159 |
{
|
sl@0
|
160 |
test.Printf(_L(" RLoggerNew::Destroy - %x\n"), this);
|
sl@0
|
161 |
|
sl@0
|
162 |
// Open or non-NULL initializing constructor not called or
|
sl@0
|
163 |
// cleanup function already called
|
sl@0
|
164 |
|
sl@0
|
165 |
__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
|
sl@0
|
166 |
delete iData;
|
sl@0
|
167 |
iData = NULL;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
void Free()
|
sl@0
|
172 |
{
|
sl@0
|
173 |
test.Printf(_L(" RLoggerNew::Free - %x\n"), this);
|
sl@0
|
174 |
|
sl@0
|
175 |
// Open or non-NULL initializing constructor not called or
|
sl@0
|
176 |
// cleanup function already called
|
sl@0
|
177 |
|
sl@0
|
178 |
__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
|
sl@0
|
179 |
delete iData;
|
sl@0
|
180 |
iData = NULL;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
void MemFunc()
|
sl@0
|
184 |
{
|
sl@0
|
185 |
test.Printf(_L(" RLoggerNew::MemFunc - %x %x\n"), this, iData);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
static void StaticMemberRef(const RLoggerNew& aTracker)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
test.Printf(_L(" RLoggerNew::StaticMemberRef - %x\n"), &aTracker);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
static void StaticMemberPtr(RLoggerNew* aTracker)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
test.Printf(_L(" RLoggerNew::StaticMemberPtr - %x\n"), aTracker);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
static void Cleanup(TAny* aRLoggerNew)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
static_cast<RLoggerNew*>(aRLoggerNew)->Close();
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
TInt* GetData() const
|
sl@0
|
204 |
{
|
sl@0
|
205 |
return iData;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
protected:
|
sl@0
|
209 |
TInt* iData;
|
sl@0
|
210 |
};
|
sl@0
|
211 |
|
sl@0
|
212 |
|
sl@0
|
213 |
DEFINE_CLEANUP_FUNCTION(RLoggerNew, Release);
|
sl@0
|
214 |
}//namespace Log
|
sl@0
|
215 |
|
sl@0
|
216 |
|
sl@0
|
217 |
|
sl@0
|
218 |
using Log::RLoggerNew;
|
sl@0
|
219 |
|
sl@0
|
220 |
//------------------------------------------
|
sl@0
|
221 |
//LCleanedupPtr tests here
|
sl@0
|
222 |
//------------------
|
sl@0
|
223 |
template<TInt Value>
|
sl@0
|
224 |
void TestLCleanedupPtrGenerateL()
|
sl@0
|
225 |
{
|
sl@0
|
226 |
__UHEAP_MARK;
|
sl@0
|
227 |
|
sl@0
|
228 |
{
|
sl@0
|
229 |
LCleanedupPtr<CTracker<Value> > tracker(CTracker<Value>::NewL());
|
sl@0
|
230 |
|
sl@0
|
231 |
tracker->MemFunc();
|
sl@0
|
232 |
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
__UHEAP_MARKEND;
|
sl@0
|
236 |
test.Printf(_L("__UHEAP_MARKEND - OK\n"));
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
template<TInt Value>
|
sl@0
|
240 |
void GenerateLCleanedupPtrTestL()
|
sl@0
|
241 |
{
|
sl@0
|
242 |
TestLCleanedupPtrGenerateL<Value>();
|
sl@0
|
243 |
GenerateLCleanedupPtrTestL<Value - 1>();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
template<>
|
sl@0
|
247 |
void GenerateLCleanedupPtrTestL<0>()
|
sl@0
|
248 |
{
|
sl@0
|
249 |
TestLCleanedupPtrGenerateL<0>();
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
|
sl@0
|
253 |
//-------------------------------------------
|
sl@0
|
254 |
//LCleanedupArray tests here
|
sl@0
|
255 |
//-----------------
|
sl@0
|
256 |
template<TInt Value>
|
sl@0
|
257 |
void TestLCleanedupArrayGenerateL()
|
sl@0
|
258 |
{
|
sl@0
|
259 |
__UHEAP_MARK;
|
sl@0
|
260 |
|
sl@0
|
261 |
{
|
sl@0
|
262 |
LCleanedupArray<CTracker<Value> > tracker(new(ELeave) CTracker<Value>[Value]);
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
__UHEAP_MARKEND;
|
sl@0
|
266 |
test.Printf(_L("__UHEAP_MARKEND - OK\n"));
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
template<TInt Value>
|
sl@0
|
270 |
void GenerateLCleanedupArrayTestL()
|
sl@0
|
271 |
{
|
sl@0
|
272 |
TestLCleanedupArrayGenerateL<Value>();
|
sl@0
|
273 |
GenerateLCleanedupArrayTestL<Value - 1>();
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
template<>
|
sl@0
|
277 |
void GenerateLCleanedupArrayTestL<0>()
|
sl@0
|
278 |
{
|
sl@0
|
279 |
TestLCleanedupArrayGenerateL<0>();
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
//-----------------------------------
|
sl@0
|
283 |
//LCleanedupGuard Tests Here
|
sl@0
|
284 |
//---------------------------
|
sl@0
|
285 |
template<TInt Value>
|
sl@0
|
286 |
void TestLCleanedupGuardTestGenerateL()
|
sl@0
|
287 |
{
|
sl@0
|
288 |
__UHEAP_MARK;
|
sl@0
|
289 |
|
sl@0
|
290 |
{
|
sl@0
|
291 |
RLoggerNew logger(Value);
|
sl@0
|
292 |
LCleanedupGuard cleanGuard(RLoggerNew::Cleanup, &logger);
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
__UHEAP_MARKEND;
|
sl@0
|
296 |
test.Printf(_L("__UHEAP_MARKEND - OK\n"));
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
template<TInt Value>
|
sl@0
|
300 |
void GenerateLCleanedupGuardTestL()
|
sl@0
|
301 |
{
|
sl@0
|
302 |
TestLCleanedupGuardTestGenerateL<Value>();
|
sl@0
|
303 |
GenerateLCleanedupGuardTestL<Value - 1>();
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
template<>
|
sl@0
|
307 |
void GenerateLCleanedupGuardTestL<0>()
|
sl@0
|
308 |
{
|
sl@0
|
309 |
TestLCleanedupGuardTestGenerateL<0>();
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
//----------------------------------------
|
sl@0
|
313 |
//LCleanedupHandle Tests Here
|
sl@0
|
314 |
//-----------------------
|
sl@0
|
315 |
|
sl@0
|
316 |
template<TInt Value>
|
sl@0
|
317 |
void TestLCleanedupHandleGenerateL()
|
sl@0
|
318 |
{
|
sl@0
|
319 |
__UHEAP_MARK;
|
sl@0
|
320 |
|
sl@0
|
321 |
{
|
sl@0
|
322 |
LCleanedupHandle<RLoggerNew> logger(Value);
|
sl@0
|
323 |
}
|
sl@0
|
324 |
|
sl@0
|
325 |
__UHEAP_MARKEND;
|
sl@0
|
326 |
test.Printf(_L("__UHEAP_MARKEND - OK\n"));
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
template<TInt Value>
|
sl@0
|
330 |
void GenerateLCleanedupHandleTestL()
|
sl@0
|
331 |
{
|
sl@0
|
332 |
TestLCleanedupHandleGenerateL<Value>();
|
sl@0
|
333 |
GenerateLCleanedupHandleTestL<Value - 1>();
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
template<>
|
sl@0
|
337 |
void GenerateLCleanedupHandleTestL<0>()
|
sl@0
|
338 |
{
|
sl@0
|
339 |
TestLCleanedupHandleGenerateL<0>();
|
sl@0
|
340 |
}
|
sl@0
|
341 |
//------------------------------------------
|
sl@0
|
342 |
//LCleanedupRef Tests Here
|
sl@0
|
343 |
//-------------------------
|
sl@0
|
344 |
|
sl@0
|
345 |
template<TInt Value>
|
sl@0
|
346 |
void TestLCleanedupRefGenerateL()
|
sl@0
|
347 |
{
|
sl@0
|
348 |
__UHEAP_MARK;
|
sl@0
|
349 |
|
sl@0
|
350 |
{
|
sl@0
|
351 |
RLoggerNew logger;
|
sl@0
|
352 |
logger.OpenL(Value);
|
sl@0
|
353 |
LCleanedupRef<RLoggerNew> rlog(logger);
|
sl@0
|
354 |
rlog.ReleaseResource();
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
__UHEAP_MARKEND;
|
sl@0
|
358 |
test.Printf(_L("__UHEAP_MARKEND - OK\n"));
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
template<TInt Value>
|
sl@0
|
362 |
void GenerateLCleanedupRefTestL()
|
sl@0
|
363 |
{
|
sl@0
|
364 |
TestLCleanedupRefGenerateL<Value>();
|
sl@0
|
365 |
GenerateLCleanedupRefTestL<Value - 1>();
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
template<>
|
sl@0
|
369 |
void GenerateLCleanedupRefTestL<0>()
|
sl@0
|
370 |
{
|
sl@0
|
371 |
TestLCleanedupRefGenerateL<0>();
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
/**
|
sl@0
|
375 |
@SYMTestCaseID BASESRVCS-EUSERHL-UT-4071
|
sl@0
|
376 |
@SYMTestCaseDesc Tests multiple defined symbols of ManagedPopCleanupStackItem method
|
sl@0
|
377 |
and also does stress testing of the template classes.
|
sl@0
|
378 |
Tests All the different Templated Class such as
|
sl@0
|
379 |
LCleanedupRef,LCleanedupGuard,LCleanedupHandle,LCleanedupArray and LCleanedupPtr
|
sl@0
|
380 |
for performance as well by explicit instantiation of the templated class using recurrsion.
|
sl@0
|
381 |
@SYMTestPriority High
|
sl@0
|
382 |
@SYMTestActions Creates multiple instances of LCleanedupArray,LCleanedupPtr and LCleanedupRef etc
|
sl@0
|
383 |
Verifies that the objects are automatically cleaned up when they go
|
sl@0
|
384 |
out of scope
|
sl@0
|
385 |
@SYMTestExpectedResults All memory allocated for the LXXX objects
|
sl@0
|
386 |
is automatically freed when they go out of scope and there are no
|
sl@0
|
387 |
errors on multiple definition of ManagedPopCleanupStackItem is produced.
|
sl@0
|
388 |
@SYMREQ DEF137572
|
sl@0
|
389 |
*/
|
sl@0
|
390 |
|
sl@0
|
391 |
TInt TExtendedTestL()
|
sl@0
|
392 |
{
|
sl@0
|
393 |
//------------
|
sl@0
|
394 |
TRAPD(status, GenerateLCleanedupPtrTestL<64>());
|
sl@0
|
395 |
if (status != KErrNone)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
test.Printf(_L("LCleanedupPtr; leave code: %d\n"), status);
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
TRAPD(status1,GenerateLCleanedupArrayTestL<64>());
|
sl@0
|
401 |
if(status1 !=KErrNone)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
test.Printf(_L("LCleanedupArray completed;leave code:%d\n"),status1);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
TRAPD(status2,GenerateLCleanedupGuardTestL<64>());
|
sl@0
|
407 |
if(status2 !=KErrNone)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
test.Printf(_L("LCleanedupGuard completed;leave code:%d\n"),status2);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
TRAPD(status3,GenerateLCleanedupHandleTestL<64>());
|
sl@0
|
413 |
if(status3 !=KErrNone)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
test.Printf(_L("LCleanedupHandle completed;leave code:%d\n"),status3);
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
TRAPD(status4,GenerateLCleanedupRefTestL<64>());
|
sl@0
|
419 |
if(status4 !=KErrNone)
|
sl@0
|
420 |
{
|
sl@0
|
421 |
test.Printf(_L("LCleanedupRef completed;leave code:%d\n"),status4);
|
sl@0
|
422 |
}
|
sl@0
|
423 |
return status;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
|
sl@0
|
427 |
|