sl@0
|
1 |
// Copyright (c) 2002-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32test.h>
|
sl@0
|
17 |
#include <f32file.h>
|
sl@0
|
18 |
#include <s32file.h>
|
sl@0
|
19 |
#include <bautils.h>
|
sl@0
|
20 |
#include <hal.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#include "DowngradePath.h"
|
sl@0
|
23 |
#include "../EcomTestUtils/EcomTestUtils.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
/* test stuff */
|
sl@0
|
27 |
|
sl@0
|
28 |
RTest test(_L("EComServer: RDowngradePath test"));
|
sl@0
|
29 |
|
sl@0
|
30 |
// flag to indicate when OOM testing is in progress
|
sl@0
|
31 |
TBool OomTest = EFalse;
|
sl@0
|
32 |
|
sl@0
|
33 |
// globals
|
sl@0
|
34 |
typedef RArray<TLanguage> Languages;
|
sl@0
|
35 |
LOCAL_D RFs TheFs;
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
// --------------------------------------------------------------
|
sl@0
|
39 |
// Begin: General helper functions & macros
|
sl@0
|
40 |
// --------------------------------------------------------------
|
sl@0
|
41 |
|
sl@0
|
42 |
/** Test boolean result. */
|
sl@0
|
43 |
#define TEST1(stmt) test(stmt)
|
sl@0
|
44 |
|
sl@0
|
45 |
/** Print formatted string to output. */
|
sl@0
|
46 |
#define TEST_PRINTF test.Printf
|
sl@0
|
47 |
|
sl@0
|
48 |
/** Start next test. */
|
sl@0
|
49 |
#define TEST_NEXT(title) \
|
sl@0
|
50 |
{\
|
sl@0
|
51 |
if (!OomTest)\
|
sl@0
|
52 |
test.Next(title);\
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
// Used for supressing warning in OOM tests
|
sl@0
|
56 |
#define __UNUSED_VAR(var) var = var
|
sl@0
|
57 |
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
Conditionally test given statement.
|
sl@0
|
60 |
if OOM testing is in progress then the error code is compared against KErrNoMemory.
|
sl@0
|
61 |
If it matches then the code leaves with that error, otherwise the boolean result
|
sl@0
|
62 |
of the statement will be tested.
|
sl@0
|
63 |
*/
|
sl@0
|
64 |
#define TEST2(err, stmt) \
|
sl@0
|
65 |
{\
|
sl@0
|
66 |
if (OomTest && err==KErrNoMemory) \
|
sl@0
|
67 |
{\
|
sl@0
|
68 |
User::LeaveNoMemory();\
|
sl@0
|
69 |
}\
|
sl@0
|
70 |
else\
|
sl@0
|
71 |
{\
|
sl@0
|
72 |
test(stmt);\
|
sl@0
|
73 |
}\
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
@SYMTestCaseID SYSLIB-ECOM-CT-1857
|
sl@0
|
78 |
@SYMTestCaseDesc Test RDowngradePath under OOM conditions.
|
sl@0
|
79 |
@SYMTestPriority High
|
sl@0
|
80 |
@SYMTestActions Test the use of RDowngradePath under OOM conditions.
|
sl@0
|
81 |
@SYMTestExpectedResults No panics caused by leaking code.
|
sl@0
|
82 |
@SYMDEF DEF090862
|
sl@0
|
83 |
*/
|
sl@0
|
84 |
typedef void (*FuncPtr8L) ();
|
sl@0
|
85 |
static void DoOOMTestL(FuncPtr8L aTestFunctionL)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
OomTest = ETrue;
|
sl@0
|
88 |
|
sl@0
|
89 |
TInt err = KErrNone;
|
sl@0
|
90 |
TInt tryCount = 0;
|
sl@0
|
91 |
RThread thread;
|
sl@0
|
92 |
|
sl@0
|
93 |
do
|
sl@0
|
94 |
{
|
sl@0
|
95 |
__UHEAP_MARK;
|
sl@0
|
96 |
|
sl@0
|
97 |
// find out the number of open handles
|
sl@0
|
98 |
TInt startProcessHandleCount = 0;
|
sl@0
|
99 |
TInt startThreadHandleCount = 0;
|
sl@0
|
100 |
thread.HandleCount(startProcessHandleCount, startThreadHandleCount);
|
sl@0
|
101 |
|
sl@0
|
102 |
__UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount);
|
sl@0
|
103 |
|
sl@0
|
104 |
TRAP(err, aTestFunctionL());
|
sl@0
|
105 |
RDowngradePath::Reset();
|
sl@0
|
106 |
__UHEAP_SETFAIL(RHeap::ENone, 0);
|
sl@0
|
107 |
|
sl@0
|
108 |
// check that no handles have leaked
|
sl@0
|
109 |
TInt endProcessHandleCount = 0;
|
sl@0
|
110 |
TInt endThreadHandleCount = 0;
|
sl@0
|
111 |
thread.HandleCount(endProcessHandleCount, endThreadHandleCount);
|
sl@0
|
112 |
TEST1(startProcessHandleCount == endProcessHandleCount);
|
sl@0
|
113 |
TEST1(startThreadHandleCount == endThreadHandleCount);
|
sl@0
|
114 |
|
sl@0
|
115 |
__UHEAP_MARKEND;
|
sl@0
|
116 |
} while(err == KErrNoMemory);
|
sl@0
|
117 |
|
sl@0
|
118 |
thread.Close();
|
sl@0
|
119 |
|
sl@0
|
120 |
TEST1(err==KErrNone);
|
sl@0
|
121 |
|
sl@0
|
122 |
OomTest = EFalse;
|
sl@0
|
123 |
TEST_PRINTF(_L("- succeeded at heap failure rate of %i\n"), tryCount);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
@SYMTestCaseID SYSLIB-ECOM-CT-0656
|
sl@0
|
128 |
@SYMTestCaseDesc Tests for RDowngradePath::HasChangedL() function
|
sl@0
|
129 |
@SYMTestPriority Medium
|
sl@0
|
130 |
@SYMTestActions Tests for downgradepath consistency
|
sl@0
|
131 |
@SYMTestExpectedResults The test must not fail.
|
sl@0
|
132 |
@SYMREQ REQ0000
|
sl@0
|
133 |
*/
|
sl@0
|
134 |
LOCAL_C void TestDowngradePathL()
|
sl@0
|
135 |
{
|
sl@0
|
136 |
//we need to make sure that at start of the test the language is set to English
|
sl@0
|
137 |
EComTestUtils::SwitchToLanguageL(static_cast<TLanguage>(ELangEnglish));
|
sl@0
|
138 |
|
sl@0
|
139 |
//the first time this is call should return language has changed
|
sl@0
|
140 |
TInt error;
|
sl@0
|
141 |
TBool hasLanguageChanged=EFalse;
|
sl@0
|
142 |
TRAP(error,hasLanguageChanged=RDowngradePath::HasChangedL(TheFs));
|
sl@0
|
143 |
if (error==KErrNoMemory)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
User::LeaveNoMemory();
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
TEST1(hasLanguageChanged);
|
sl@0
|
149 |
|
sl@0
|
150 |
//if second time called and no language changed yet,it should return false
|
sl@0
|
151 |
TRAP(error,hasLanguageChanged=RDowngradePath::HasChangedL(TheFs));
|
sl@0
|
152 |
if (error==KErrNoMemory)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
User::LeaveNoMemory();
|
sl@0
|
155 |
}
|
sl@0
|
156 |
TEST1(!hasLanguageChanged);
|
sl@0
|
157 |
|
sl@0
|
158 |
//now switch to another language, this will change the language downgrade path
|
sl@0
|
159 |
EComTestUtils::SwitchToLanguageL(static_cast<TLanguage>(ELangFrench));
|
sl@0
|
160 |
|
sl@0
|
161 |
//this should detect language has changed now
|
sl@0
|
162 |
TRAP(error,hasLanguageChanged=RDowngradePath::HasChangedL(TheFs));
|
sl@0
|
163 |
if (error==KErrNoMemory)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
User::LeaveNoMemory();
|
sl@0
|
166 |
}
|
sl@0
|
167 |
TEST1(hasLanguageChanged);
|
sl@0
|
168 |
|
sl@0
|
169 |
//and finally call that function again it should return no language changed yet.
|
sl@0
|
170 |
TRAP(error,hasLanguageChanged=RDowngradePath::HasChangedL(TheFs));
|
sl@0
|
171 |
if (error==KErrNoMemory)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
User::LeaveNoMemory();
|
sl@0
|
174 |
}
|
sl@0
|
175 |
TEST1(!hasLanguageChanged);
|
sl@0
|
176 |
|
sl@0
|
177 |
//reset the cached language settings
|
sl@0
|
178 |
RDowngradePath::Reset();
|
sl@0
|
179 |
//and finally when tests are completed switch back to English
|
sl@0
|
180 |
EComTestUtils::SwitchToLanguageL(static_cast<TLanguage>(ELangEnglish));
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
Run all RDowngradePath tests.
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
LOCAL_C void RunTestsL()
|
sl@0
|
187 |
{
|
sl@0
|
188 |
TEST_NEXT(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-0656"));
|
sl@0
|
189 |
TestDowngradePathL();
|
sl@0
|
190 |
|
sl@0
|
191 |
TEST_NEXT(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1857 Test RDowngradePath in OOM conditions. "));
|
sl@0
|
192 |
DoOOMTestL(TestDowngradePathL);
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Executable entry point.
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
GLDEF_C TInt E32Main()
|
sl@0
|
199 |
{
|
sl@0
|
200 |
__UHEAP_MARK;
|
sl@0
|
201 |
|
sl@0
|
202 |
test.Title();
|
sl@0
|
203 |
test.Start(_L("Running tests..."));
|
sl@0
|
204 |
|
sl@0
|
205 |
test(TheFs.Connect() == KErrNone);
|
sl@0
|
206 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
207 |
|
sl@0
|
208 |
TRAPD(err, RunTestsL());
|
sl@0
|
209 |
|
sl@0
|
210 |
delete cleanup;
|
sl@0
|
211 |
TheFs.Close();
|
sl@0
|
212 |
|
sl@0
|
213 |
// check for errors
|
sl@0
|
214 |
test(err == KErrNone);
|
sl@0
|
215 |
|
sl@0
|
216 |
test.End();
|
sl@0
|
217 |
test.Close();
|
sl@0
|
218 |
|
sl@0
|
219 |
__UHEAP_MARKEND;
|
sl@0
|
220 |
return(0);
|
sl@0
|
221 |
}
|