|
1 // Copyright (c) 2005-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 |
|
22 #include <f32file.h> |
|
23 #include <bautils.h> |
|
24 #include <gdi.h> |
|
25 #include <gulcolor.h> |
|
26 #include <gulutil.h> |
|
27 #include <eikenv.h> |
|
28 #include "T_ColorStep.h" |
|
29 #include <centralrepository.h> |
|
30 |
|
31 // these constants are also defined in cone\src\CoeDataStorage.cpp |
|
32 const TUint KUidSystemColorRepository=0x10272619; |
|
33 const TUint KSystemColorRepositoryKey=0; |
|
34 |
|
35 // |
|
36 // CSimpleColorControl |
|
37 // |
|
38 |
|
39 void CSimpleColorControl::ConstructL() |
|
40 { |
|
41 CreateWindowL(); |
|
42 Window().SetShadowDisabled(ETrue); |
|
43 SetExtentToWholeScreen(); |
|
44 ActivateL(); |
|
45 } |
|
46 |
|
47 void CSimpleColorControl::Draw(const TRect&) const |
|
48 { |
|
49 CWindowGc& gc = SystemGc(); |
|
50 gc.Clear(Rect()); |
|
51 } |
|
52 |
|
53 |
|
54 // |
|
55 // CTestColorUi |
|
56 // |
|
57 |
|
58 CTestColorUi::CTestColorUi(CT_ColorStep& aStep) |
|
59 : CTestAppUi(&aStep, KNullDesC), iColorStep(aStep) |
|
60 { |
|
61 } |
|
62 |
|
63 void CTestColorUi::ConstructL() |
|
64 { |
|
65 CTestAppUi::ConstructL(); |
|
66 iControl = new(ELeave) CSimpleColorControl; |
|
67 AddToStackL(iControl, ECoeStackPriorityDefault, ECoeStackFlagOwnershipTransfered); |
|
68 iControl->ConstructL(); |
|
69 iTestResult = CAutoTestManager::EPass; |
|
70 |
|
71 AutoTestManager().StartAutoTest(); |
|
72 } |
|
73 |
|
74 CTestColorUi::~CTestColorUi() |
|
75 { |
|
76 delete iColorList; |
|
77 } |
|
78 |
|
79 |
|
80 void CTestColorUi::RunTestStepL(TInt aStep) |
|
81 { |
|
82 TRAPD(err, DoRunTestStepL(aStep)); |
|
83 if(err == KLeaveExit) |
|
84 { |
|
85 User::Leave(err); |
|
86 } |
|
87 else if(err != KErrNone) |
|
88 { |
|
89 // Don't propagate this error since leaving stops the test :O( |
|
90 INFO_PRINTF3(_L(" Test step %d failed: %d"), aStep, err); |
|
91 iTestResult = CAutoTestManager::EFailed; |
|
92 } |
|
93 } |
|
94 |
|
95 void CTestColorUi::DoRunTestStepL(TInt aStep) |
|
96 { |
|
97 switch(aStep) |
|
98 { |
|
99 case CT_ColorStep::ETestColorArray: |
|
100 SetTestStepID(_L("UIF-egul-TestColorArray")); |
|
101 INFO_PRINTF1(_L("Test CColorArray")); |
|
102 iColorStep.TestColorArrayL(); |
|
103 RecordTestResultL(); |
|
104 break; |
|
105 case CT_ColorStep::ETestColorList: |
|
106 SetTestStepID(_L("UIF-egul-TestColorList")); |
|
107 INFO_PRINTF1(_L("Test CColorList")); |
|
108 iColorList = iColorStep.TestColorListLC(); |
|
109 CleanupStack::Pop(iColorList); |
|
110 RecordTestResultL(); |
|
111 break; |
|
112 case CT_ColorStep::ETestColorUtils: |
|
113 SetTestStepID(_L("UIF-egul-TestColorUtils")); |
|
114 INFO_PRINTF1(_L("Test ColorUtils")); |
|
115 iColorStep.TestColorUtilsL(*iColorList); |
|
116 RecordTestResultL(); |
|
117 break; |
|
118 case CT_ColorStep::ETestColorOom: |
|
119 SetTestStepID(_L("UIF-egul-TestColorOom")); |
|
120 INFO_PRINTF1(_L("Repeat tests in low memory")); |
|
121 iColorStep.TestColorOomL(); |
|
122 RecordTestResultL(); |
|
123 break; |
|
124 case CT_ColorStep::ETestFileLength: |
|
125 SetTestStepID(_L("UIF-egul-FileLengthTestL")); |
|
126 INFO_PRINTF1(_L("Test access zero length file")); |
|
127 iColorStep.FileLengthTestL(); |
|
128 RecordTestResultL(); |
|
129 break; |
|
130 case CT_ColorStep::ETestFileCorrupt: |
|
131 SetTestStepID(_L("UIF-egul-CorruptFileTest")); |
|
132 INFO_PRINTF1(_L("Test access corrupt file")); |
|
133 iColorStep.CorruptFileTestL(); |
|
134 RecordTestResultL(); |
|
135 CloseTMSGraphicsStep(); |
|
136 break; |
|
137 default: |
|
138 iColorStep.SetTestStepResult((iTestResult==CAutoTestManager::EPass) ? EPass : EFail); |
|
139 AutoTestManager().FinishAllTestCases(iTestResult); |
|
140 break; |
|
141 } |
|
142 } |
|
143 |
|
144 /** |
|
145 @SYMTestCaseID UIF-egul-TestColorArray |
|
146 |
|
147 @SYMPREQ |
|
148 |
|
149 @SYMTestCaseDesc |
|
150 Test basic functionality of the CColorArray class. |
|
151 |
|
152 @SYMTestPriority High |
|
153 |
|
154 @SYMTestStatus Implemented |
|
155 |
|
156 @SYMTestActions |
|
157 Create a new CColorList object. |
|
158 Add some logical colors to it. |
|
159 Check that the presence of the colors may be detected. |
|
160 Check that the values of the logical colors may be retrieved. |
|
161 |
|
162 @SYMTestExpectedResults |
|
163 Logical colors may be stored in, and retrieved from, a CColorArray object. |
|
164 |
|
165 */ |
|
166 void CT_ColorStep::TestColorArrayL() |
|
167 { |
|
168 CColorArray* array=CColorArray::NewL(); |
|
169 TEST(array!=NULL); |
|
170 delete array; |
|
171 array=0; |
|
172 array=CColorArray::NewLC(); |
|
173 TEST(array!=NULL); |
|
174 TEST(array->Contains(101)==EFalse); |
|
175 TEST(array->Count()==0); |
|
176 array->AddL(101,KRgbWhite); |
|
177 array->AddL(102,KRgbBlack); |
|
178 array->AddL(104,KRgbDarkBlue); |
|
179 array->AddL(103,KRgbGreen); |
|
180 TEST(array->Count()==4); |
|
181 TEST(array->Contains(101)); |
|
182 TEST(!array->Contains(105)); |
|
183 TEST(array->Color(102)==KRgbBlack); |
|
184 TEST(array->Color(103)==KRgbGreen); |
|
185 array->SetColor(104,KRgbYellow); |
|
186 TEST(array->Color(104)==KRgbYellow); |
|
187 TEST(array->Contains(104)); |
|
188 array->Remove(102); |
|
189 array->Remove(104); |
|
190 TEST(array->Count()==2); |
|
191 TEST(array->Contains(101)); |
|
192 TEST(array->Contains(103)); |
|
193 TEST(!array->Contains(104)); |
|
194 array->Reset(); |
|
195 TEST(array->Count()==0); |
|
196 CleanupStack::PopAndDestroy(); // array |
|
197 } |
|
198 |
|
199 /** |
|
200 @SYMTestCaseID UIF-egul-TestColorList |
|
201 |
|
202 @SYMPREQ |
|
203 |
|
204 @SYMTestCaseDesc |
|
205 Test basic functionality of the CColorList class. |
|
206 |
|
207 @SYMTestPriority High |
|
208 |
|
209 @SYMTestStatus Implemented |
|
210 |
|
211 @SYMTestActions |
|
212 Create a new CColorList object. |
|
213 Add some logical colors to it. |
|
214 Check that the presence of the colors may be detected. |
|
215 Check that the values of the logical colors may be retrieved. |
|
216 Add some CColorArray objects to it. |
|
217 Check that the presence of the color arrays may be detected. |
|
218 Check that the values of the colors in the color arrays may be retrieved. |
|
219 |
|
220 @SYMTestExpectedResults |
|
221 Logical colors and color arrays may be stored in, and retrieved from, |
|
222 a CColorList object. |
|
223 |
|
224 */ |
|
225 CColorList* CT_ColorStep::TestColorListLC() |
|
226 { |
|
227 CArrayFix<TRgb>* rgbs=new(ELeave) CArrayFixFlat<TRgb>(3); |
|
228 CleanupStack::PushL(rgbs); |
|
229 rgbs->AppendL(KRgbWhite); |
|
230 rgbs->AppendL(KRgbGray); |
|
231 rgbs->AppendL(KRgbCyan); |
|
232 rgbs->AppendL(KRgbDarkRed); |
|
233 CColorList* list=CColorList::NewL(rgbs); |
|
234 CleanupStack::Pop(); // rgbs |
|
235 CleanupStack::PushL(list); |
|
236 TEST(list->Color(TLogicalColor(0))==KRgbWhite); |
|
237 CColorArray* array=CColorArray::NewLC(); |
|
238 array->AddL(200,KRgbDarkMagenta); |
|
239 array->AddL(201,KRgbDarkCyan); |
|
240 array->AddL(202,KRgbDarkMagenta); |
|
241 list->AddColorArrayL(TUid::Uid(KEikCustomColorsArrayValue),array); |
|
242 CleanupStack::Pop(); // array |
|
243 |
|
244 array=CColorArray::NewLC(); |
|
245 array->AddL(300,KRgbDarkGray); |
|
246 array->AddL(301,KRgbRed); |
|
247 list->AddColorArrayL(TUid::Uid(1001),array); |
|
248 CleanupStack::Pop(); // array |
|
249 |
|
250 TEST(list->ContainsColorArray(TUid::Uid(KEikCustomColorsArrayValue))); |
|
251 TEST(!list->ContainsColorArray(TUid::Uid(1005))); |
|
252 TEST(list->ContainsColorArray(TUid::Uid(1001))); |
|
253 array=list->ColorArray(TUid::Uid(KEikCustomColorsArrayValue)); |
|
254 TEST(array->Count()==3); |
|
255 TEST(list->Color(TUid::Uid(1001),300)==KRgbDarkGray); |
|
256 TEST(list->Color(TUid::Uid(KEikCustomColorsArrayValue),201)==KRgbDarkCyan); |
|
257 array=list->ColorArray(TUid::Uid(1001)); |
|
258 TEST(array->Count()==2); |
|
259 |
|
260 list->DeleteColorArray(TUid::Uid(1001)); |
|
261 TEST(list->ContainsColorArray(TUid::Uid(KEikCustomColorsArrayValue))); |
|
262 TEST(!list->ContainsColorArray(TUid::Uid(1005))); |
|
263 TEST(!list->ContainsColorArray(TUid::Uid(1001))); |
|
264 |
|
265 list->SetColor(TLogicalColor(1),KRgbBlack); |
|
266 TEST(list->Color(TLogicalColor(0))==KRgbWhite); |
|
267 TEST(list->Color(TLogicalColor(1))==KRgbBlack); |
|
268 |
|
269 return list; |
|
270 } |
|
271 |
|
272 /** |
|
273 @SYMTestCaseID UIF-egul-TestColorUtils |
|
274 |
|
275 @SYMPREQ |
|
276 |
|
277 @SYMTestCaseDesc |
|
278 Test basic functionality of the ColorUtils class. |
|
279 |
|
280 @SYMTestPriority High |
|
281 |
|
282 @SYMTestStatus Implemented |
|
283 |
|
284 @SYMTestActions |
|
285 Remove the current color scheme file. |
|
286 Check that an attempt to read the color scheme returns a NULL CColorList object. |
|
287 Create a new color scheme file from a supplied CColorList. |
|
288 Check that an attempt to read the new color scheme returns a CColorList object |
|
289 containing the expected colors and color arrays. |
|
290 Restore the original color scheme file. |
|
291 |
|
292 @SYMTestExpectedResults |
|
293 The system color scheme may be changed. |
|
294 |
|
295 */ |
|
296 void CT_ColorStep::TestColorUtilsL(CColorList& aColorList) |
|
297 { |
|
298 RFs& fs = iFs; |
|
299 // if (BaflUtils::FileExists(fs,????KColorSchemeFile)) |
|
300 // { |
|
301 // if (BaflUtils::FileExists(fs,KColorSchemeFileOriginalRenamed)) |
|
302 // { |
|
303 // User::LeaveIfError(fs.Delete(KColorSchemeFileOriginalRenamed)); |
|
304 // } |
|
305 // User::LeaveIfError(fs.Rename(KColorSchemeFile,KColorSchemeFileOriginalRenamed)); |
|
306 // } |
|
307 CColorList* list=ColorUtils::CreateSystemColorListL(fs); |
|
308 delete list; |
|
309 ColorUtils::UpdateSystemColorListL(fs,aColorList); |
|
310 list=ColorUtils::CreateSystemColorListL(fs); |
|
311 CleanupStack::PushL(list); |
|
312 TEST(list->Color(TLogicalColor(0))==KRgbWhite); |
|
313 TEST(list->ContainsColorArray(TUid::Uid(KEikCustomColorsArrayValue))); |
|
314 TEST(!list->ContainsColorArray(TUid::Uid(1005))); |
|
315 TEST(!list->ContainsColorArray(TUid::Uid(1001))); |
|
316 CColorArray* array=list->ColorArray(TUid::Uid(KEikCustomColorsArrayValue)); |
|
317 TEST(array->Count()==3); |
|
318 TEST(list->Color(TUid::Uid(KEikCustomColorsArrayValue),201)==KRgbDarkCyan); |
|
319 CleanupStack::PopAndDestroy(list); |
|
320 //restore original file |
|
321 // User::LeaveIfError(fs.Delete(KColorSchemeFile)); |
|
322 // if (BaflUtils::FileExists(fs,KColorSchemeFileOriginalRenamed)) |
|
323 // { |
|
324 // User::LeaveIfError(fs.Rename(KColorSchemeFileOriginalRenamed,KColorSchemeFile)); |
|
325 // } |
|
326 } |
|
327 |
|
328 void CT_ColorStep::DoOomTestsL() |
|
329 { |
|
330 TestColorArrayL(); |
|
331 CColorList* list=TestColorListLC(); |
|
332 TestColorUtilsL(*list); |
|
333 CleanupStack::PopAndDestroy(list); |
|
334 } |
|
335 |
|
336 /** |
|
337 @SYMTestCaseID UIF-egul-TestColorOom |
|
338 |
|
339 @SYMPREQ |
|
340 |
|
341 @SYMTestCaseDesc |
|
342 Test basic functionality of the CColorArray, CColorList and ColorUtils classes under low memory conditions. |
|
343 |
|
344 @SYMTestPriority High |
|
345 |
|
346 @SYMTestStatus Implemented |
|
347 |
|
348 @SYMTestActions |
|
349 Perform the CT_ColScm_TestColorArray, CT_ColScm_TestColorList, and CT_ColScm_TestColorUtils test cases |
|
350 under low memory conditions, where each memory allocation is made to fail once. |
|
351 |
|
352 @SYMTestExpectedResults |
|
353 All methods should report KErrNoMemory if they cannot allocate sufficient memory to complete. |
|
354 All methods should recover gracefully from low memory situations and subsequently succeed when sufficient |
|
355 memory is available. |
|
356 |
|
357 */ |
|
358 void CT_ColorStep::TestColorOomL() |
|
359 { |
|
360 TInt err=KErrNoMemory; |
|
361 for (TInt ii=0;err==KErrNoMemory;ii++) |
|
362 { |
|
363 __UHEAP_FAILNEXT(ii); |
|
364 __UHEAP_MARK; |
|
365 TRAP(err,DoOomTestsL()); |
|
366 __UHEAP_MARKEND; |
|
367 } |
|
368 __UHEAP_SETFAIL(RHeap::ENone,0); |
|
369 User::LeaveIfError(err); |
|
370 } |
|
371 |
|
372 void CT_ColorStep::SetSystemColorSchemeL(const TDesC8& aBuffer) |
|
373 { // static |
|
374 CRepository* const repository=CRepository::NewL(TUid::Uid(KUidSystemColorRepository)); |
|
375 CleanupStack::PushL(repository); |
|
376 User::LeaveIfError(repository->Set(KSystemColorRepositoryKey, aBuffer)); |
|
377 CleanupStack::PopAndDestroy(repository); |
|
378 } |
|
379 |
|
380 /** |
|
381 @SYMTestCaseID UIF-egul-FileLengthTestL |
|
382 |
|
383 @SYMPREQ DEF043427 |
|
384 |
|
385 @SYMTestCaseDesc |
|
386 Color scheme file should be checked for zero length.\n |
|
387 |
|
388 @SYMTestPriority High |
|
389 |
|
390 @SYMTestStatus Implemented |
|
391 |
|
392 @SYMTestActions |
|
393 Open the color scheme file in write mode and set its length as zero.\n |
|
394 API Calls: |
|
395 static CColorList* ColorUtils::CreateSystemColorListL(RFs& aFs);\n |
|
396 |
|
397 @SYMTestExpectedResults |
|
398 If the file length is zero then it should be deleted and the \n |
|
399 CreateSystemColorListL should return NULL.\n |
|
400 |
|
401 */ |
|
402 void CT_ColorStep::FileLengthTestL() |
|
403 { |
|
404 SetSystemColorSchemeL(KNullDesC8); |
|
405 |
|
406 CColorList* colorlist=NULL; |
|
407 TRAPD(err,colorlist=ColorUtils::CreateSystemColorListL(iFs)); |
|
408 |
|
409 TEST(err == KErrNone); |
|
410 TEST(colorlist == NULL); |
|
411 } |
|
412 |
|
413 /** |
|
414 @SYMTestCaseID UIF-egul-CorruptFileTest |
|
415 |
|
416 @SYMPREQ DEF043427 |
|
417 |
|
418 @SYMTestCaseDesc |
|
419 Color scheme file length should be set to abnormal value.\n |
|
420 |
|
421 @SYMTestPriority High |
|
422 |
|
423 @SYMTestStatus Implemented |
|
424 |
|
425 @SYMTestActions |
|
426 Open the color scheme file in write mode and set its length as half.\n |
|
427 the actual file length. |
|
428 |
|
429 API Calls: |
|
430 static CColorList* ColorUtils::CreateSystemColorListL(RFs& aFs);\n |
|
431 |
|
432 @SYMTestExpectedResults |
|
433 CreateSystemColorListL should return NULL and delete the file. |
|
434 |
|
435 */ |
|
436 void CT_ColorStep::CorruptFileTestL() |
|
437 { |
|
438 SetSystemColorSchemeL(_L8("blah blah some rubbish binary data\xab\xcd\xef")); |
|
439 |
|
440 CColorList* colorlist=NULL; |
|
441 TRAPD(err,colorlist=ColorUtils::CreateSystemColorListL(iFs)); |
|
442 |
|
443 TEST(err == KErrNone); |
|
444 TEST(colorlist == NULL); |
|
445 } |
|
446 |
|
447 |
|
448 CT_ColorStep::~CT_ColorStep() |
|
449 /** |
|
450 Destructor |
|
451 */ |
|
452 { |
|
453 iFs.Close(); |
|
454 } |
|
455 |
|
456 CT_ColorStep::CT_ColorStep() |
|
457 /** |
|
458 Constructor |
|
459 */ |
|
460 { |
|
461 // Call base class method to set up the human readable name for logging |
|
462 SetTestStepName(KT_ColorStep); |
|
463 } |
|
464 |
|
465 |
|
466 void CT_ColorStep::ConstructAppL(CEikonEnv* aCoeEnv) |
|
467 { |
|
468 /** CEikonEnv will install a CEikEnvDataStorage object instance to access the EikSrv data cage. |
|
469 Using the system colour scheme from EikSrv for these tests causes problems in the rest of the system, |
|
470 (e.g. Shell app panics with EEgulPanicLogicalColorNotFound) because these tests set up a non-standard |
|
471 colour scheme. |
|
472 |
|
473 So, here we remove the CEikEnvDataStorage object and install a test data storage object |
|
474 that stores the colour scheme file in c:\\EGulTest\\, keeping it out of the way of everything else. |
|
475 */ |
|
476 aCoeEnv->ConstructL(); |
|
477 CTestColorUi* appUi=new(ELeave) CTestColorUi(*this); |
|
478 appUi->ConstructL(); |
|
479 aCoeEnv->SetAppUi(appUi); |
|
480 } |
|
481 |
|
482 TVerdict CT_ColorStep::doTestStepL() |
|
483 { |
|
484 INFO_PRINTF1(_L("Test Started")); |
|
485 |
|
486 PreallocateHALBuffer(); |
|
487 |
|
488 __UHEAP_MARK; |
|
489 |
|
490 User::LeaveIfError(iFs.Connect()); |
|
491 CEikonEnv* coe=new(ELeave) CEikonEnv; |
|
492 TRAPD(err,ConstructAppL(coe)); |
|
493 if (!err) |
|
494 coe->ExecuteD(); |
|
495 else |
|
496 { |
|
497 SetTestStepResult(EFail); |
|
498 delete coe; |
|
499 } |
|
500 |
|
501 INFO_PRINTF1(_L("Test Finished")); |
|
502 |
|
503 __UHEAP_MARKEND; |
|
504 return TestStepResult(); |
|
505 } |
|
506 |
|
507 |