|
1 // Copyright (c) 2006-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 "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 // test code for RTextBuf - DEF015702 |
|
15 // |
|
16 // |
|
17 |
|
18 #include <bamatch.h> |
|
19 #include <e32test.h> |
|
20 |
|
21 LOCAL_D RTest test(_L("RTextBuf")); |
|
22 |
|
23 const TInt KErrSimulated = -100001; |
|
24 _LIT(KThreadName,"newThread"); |
|
25 |
|
26 void PanicFuncL() |
|
27 { |
|
28 RTextBuf buf; |
|
29 CleanupClosePushL(buf); |
|
30 buf.SetMaxLengthL(0); |
|
31 CleanupStack::PopAndDestroy(); |
|
32 } |
|
33 |
|
34 TInt ThreadFunc(TAny*) |
|
35 { |
|
36 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
37 TRAPD(err, PanicFuncL()); |
|
38 delete trapCleanup; |
|
39 return err; |
|
40 } |
|
41 |
|
42 /** |
|
43 @SYMTestCaseID SYSLIB-BAFL-UT-1795 |
|
44 @SYMTestCaseDesc Testing panic on RTextBuf class(JustInTimeDebug is disabled) |
|
45 @SYMTestPriority Low |
|
46 @SYMTestActions Test that panics, when the condition inside __ASSERT is made false, by passing 0 as parameter to SetMaxLengthL function |
|
47 @SYMTestExpectedResults Tests must panic |
|
48 @SYMREQ REQ0000 |
|
49 */ |
|
50 void PanicTest() |
|
51 { |
|
52 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-1795 ")); |
|
53 TRequestStatus threadStatus; |
|
54 RThread thread; |
|
55 TInt rc; |
|
56 TBool jit; |
|
57 jit = User::JustInTime(); |
|
58 User::SetJustInTime(EFalse); |
|
59 |
|
60 rc = thread.Create(KThreadName, ThreadFunc, |
|
61 KDefaultStackSize, KMinHeapSize, KMinHeapSize*4,NULL); |
|
62 test(KErrNone == rc); |
|
63 |
|
64 thread.Logon(threadStatus); |
|
65 thread.Resume(); |
|
66 |
|
67 User::WaitForRequest(threadStatus); |
|
68 User::SetJustInTime(jit); |
|
69 |
|
70 test(thread.ExitType() == EExitPanic); |
|
71 thread.Close(); |
|
72 } |
|
73 |
|
74 /* |
|
75 |
|
76 @SYMTestCaseID SYSLIB-BAFL-CT-0466 |
|
77 @SYMTestCaseDesc Tests for Defect number DEF015702 |
|
78 @SYMTestPriority High |
|
79 @SYMTestActions Tests for clean completion even after Leave |
|
80 @SYMTestExpectedResults Test must not fail |
|
81 @SYMREQ REQ0000 |
|
82 */ |
|
83 void DEF015702() |
|
84 /** |
|
85 * Test DEF015702. |
|
86 * RTextBuf is not safe. |
|
87 * RTextBuf has a destructor; but the destructor will not be called if a leave occurs |
|
88 * (if the RTextBuf is on the stack). |
|
89 */ |
|
90 { |
|
91 test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0466 Testing fix for defect DEF015702 ")); |
|
92 |
|
93 RTextBuf buf; |
|
94 |
|
95 CleanupClosePushL(buf); |
|
96 |
|
97 buf.SetMaxLengthL(20); |
|
98 //Test that raises a panic |
|
99 PanicTest(); |
|
100 buf.SetText(_L("0123456789")); |
|
101 |
|
102 // Simulate a problem with calling of User::Leave(KErrSimulated). |
|
103 // There should be no "Panic ALLOC" in epocwind.out file. |
|
104 //And te test should be completed with OK. |
|
105 User::Leave(KErrSimulated); |
|
106 } |
|
107 |
|
108 |
|
109 void DoE32MainL() |
|
110 { |
|
111 // |
|
112 __UHEAP_MARK; |
|
113 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
114 TRAPD(error, DEF015702()); |
|
115 delete trapCleanup; |
|
116 #ifdef _DEBUG |
|
117 TUint32 badCell = __UHEAP_MARKEND; |
|
118 #endif |
|
119 if(error == KErrSimulated) |
|
120 { |
|
121 #ifdef _DEBUG |
|
122 if(badCell == 0) |
|
123 #endif |
|
124 { |
|
125 test.End(); |
|
126 User::After(3000000); |
|
127 } |
|
128 } |
|
129 // |
|
130 } |
|
131 |
|
132 |
|
133 TInt E32Main() |
|
134 { |
|
135 __UHEAP_MARK; |
|
136 |
|
137 test.Title(); |
|
138 |
|
139 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
140 TRAPD(error, DoE32MainL()); |
|
141 |
|
142 delete trapCleanup; |
|
143 |
|
144 test.Close(); |
|
145 |
|
146 __UHEAP_MARKEND; |
|
147 |
|
148 return error; |
|
149 } |