|
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 // Tests APIs related to CGridImg,CGridLay and MGridTable classes |
|
15 // for tables with INDEFINITE row boundaries\n |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 |
|
25 #include <f32file.h> |
|
26 #include <s32file.h> |
|
27 |
|
28 #include "TCoGridStep.h" |
|
29 |
|
30 |
|
31 /** |
|
32 Constructor |
|
33 */ |
|
34 CTestCoeGridAppUi::CTestCoeGridAppUi(CTmsTestStep* aStep) : |
|
35 CTestCoeAppUi(aStep) |
|
36 {} |
|
37 |
|
38 /** |
|
39 Destructor |
|
40 */ |
|
41 CTestCoeGridAppUi::~CTestCoeGridAppUi() |
|
42 { |
|
43 RemoveFromStack(iGridWin); |
|
44 delete iGridWin; |
|
45 delete iGridImg; |
|
46 delete iGridLay; |
|
47 delete iTestCellImg; |
|
48 delete iTestLabelImg; |
|
49 delete iGridTable; |
|
50 delete iZoomFactor; |
|
51 } |
|
52 /** |
|
53 Auxiliary Function for T-CoGridStep-RunTestStepL.\n |
|
54 Handles the following Key Events\n |
|
55 1. Ctrl+ e - Exits the application\n |
|
56 2. Ctrl+ t - Toggles the Title Lines\n |
|
57 3. Ctrl+ r - Resets the grid to its default layout and sets the cursor position to the cell at the top of the window\n |
|
58 4. Ctrl+ m - Sets the zoom factor \n |
|
59 5. Ctrl+ p - Paginates the Grid \n |
|
60 6. Ctrl+ i - Inserts columns \n |
|
61 7. Ctrl+ d - Deletes columns \n |
|
62 8. Ctrl+ c - Changes the grid colour settings\n |
|
63 9. Shift+m - Sets the zoom factor\n |
|
64 |
|
65 @return TKeyResponse indicating whether the key event has been handled or not.\n |
|
66 |
|
67 */ |
|
68 TKeyResponse CTestCoeGridAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
69 { |
|
70 if (aType==EEventKey) |
|
71 { |
|
72 if ((aKeyEvent.iModifiers&EAllStdModifiers)==EModifierCtrl) |
|
73 { |
|
74 switch (aKeyEvent.iCode) |
|
75 { |
|
76 case CTRL('e'): |
|
77 SaveL(); |
|
78 iCoeEnv->Flush(); |
|
79 CBaActiveScheduler::Exit(); |
|
80 break; |
|
81 case CTRL('t'): |
|
82 iGridWin->GridLay()->ToggleTitleLinesL(); |
|
83 break; |
|
84 case CTRL('r'): |
|
85 iGridWin->GridLay()->SetGridToDefault(); |
|
86 iUndoColors=EFalse; |
|
87 iUndoColors =~iUndoColors; |
|
88 ChangeColors(iUndoColors); |
|
89 iGridWin->DrawNow(); |
|
90 iGridWin->SetCursorPosL(iGridWin->GridLay()->VisibleRange().iFrom); |
|
91 break; |
|
92 case CTRL('m'): |
|
93 { |
|
94 TInt zoomFactor=iZoomFactor->ZoomFactor(); |
|
95 zoomFactor=(zoomFactor<(TZoomFactor::EZoomOneToOne*4)) |
|
96 ? zoomFactor*2 : TZoomFactor::EZoomOneToOne/4; |
|
97 SetZoomFactorL(zoomFactor); |
|
98 break; |
|
99 } |
|
100 case CTRL('p'): |
|
101 iGridWin->GridLay()->SetPageSizeInTwipsL |
|
102 (TSize(EPageWidthInTwips,EPageHeightInTwips)); |
|
103 |
|
104 iGridWin->GridLay()->PaginateL(); |
|
105 iGridWin->DrawNow(); |
|
106 break; |
|
107 case CTRL('c'): |
|
108 { |
|
109 iUndoColors = ~iUndoColors; |
|
110 ChangeColors(iUndoColors); |
|
111 iGridWin->DrawNow(); |
|
112 } |
|
113 break; |
|
114 case CTRL('i'): |
|
115 case CTRL('d'): |
|
116 { |
|
117 TInt noOfCols=(aKeyEvent.iCode==CTRL('i')) ? 1 : -1; |
|
118 iGridLay->InsertDeleteColumns(iGridLay->VisibleRange().iFrom.iCol, |
|
119 noOfCols,CGridLay::EAdjustGridRange); |
|
120 iGridWin->DrawNow(); |
|
121 } |
|
122 break; |
|
123 case CTRL('z'): |
|
124 { |
|
125 iGridTable->iZeroRows=!iGridTable->iZeroRows; |
|
126 iGridImg->ResetReferencePoints(); |
|
127 iGridLay->ResetVisibleToCell(); |
|
128 iGridWin->DrawNow(); |
|
129 } |
|
130 break; |
|
131 default: |
|
132 break; |
|
133 } |
|
134 } |
|
135 else if ((aKeyEvent.iModifiers&EAllStdModifiers)==EModifierShift) |
|
136 { |
|
137 switch (User::LowerCase(aKeyEvent.iCode)) |
|
138 { |
|
139 case 'm': |
|
140 { |
|
141 TInt zoomFactor=iZoomFactor->ZoomFactor(); |
|
142 zoomFactor=(zoomFactor>(TZoomFactor::EZoomOneToOne/4)) |
|
143 ? zoomFactor/2 : TZoomFactor::EZoomOneToOne*4; |
|
144 SetZoomFactorL(zoomFactor); |
|
145 break; |
|
146 } |
|
147 default: |
|
148 break; |
|
149 } |
|
150 } |
|
151 } |
|
152 return EKeyWasConsumed; |
|
153 } |
|
154 /** |
|
155 Second Phase constructor for the CTestCoeGridAppUi class.\n |
|
156 Gets the current zoom factor.\n |
|
157 Sets the grid cell settings like font and zoom factor.\n |
|
158 Constructs a GridTable. It is an interface providing row and column info.\n |
|
159 Initializes a GridLay passing the gridtable and null gridimage. \n |
|
160 The GridLay object is used to handle the layout of a grid, |
|
161 and controls how columns, rows and selections appear.\n |
|
162 Initializes a GridImage with gridcell settings which is used to draw cell contents.\n |
|
163 A Grid Window is formed containing using GridTable,GridLay and GridImage objects.\n |
|
164 The GridWindow offers handlers to pointer and key events.\n |
|
165 Sets the current cursor position and activates the Grid Window.\n |
|
166 */ |
|
167 void CTestCoeGridAppUi::ConstructL() |
|
168 { |
|
169 CTestCoeAppUi::ConstructL(); |
|
170 |
|
171 iUndoColors = EFalse; |
|
172 CGraphicsDevice* device=iCoeEnv->ScreenDevice(); |
|
173 //iCoeEnv->WsSession().SetAutoFlush(ETrue); |
|
174 iZoomFactor = new(ELeave) TZoomFactor(device); |
|
175 User::Heap().Check(); |
|
176 |
|
177 const CFont* font = iCoeEnv->NormalFont(); |
|
178 iTestCellImg = new(ELeave) CTestCellImg(font); |
|
179 |
|
180 TFontSpec fontSpec(_L("Swiss"),240); |
|
181 iTestLabelImg = new(ELeave) CTestLabelImg(fontSpec,iZoomFactor); |
|
182 iTestLabelImg->ConstructL(); |
|
183 User::Heap().Check(); |
|
184 |
|
185 iGridLay = new(ELeave) CGridLay(iZoomFactor); |
|
186 iGridImg = CGridImg::NewL(device,iTestCellImg,iGridLay); |
|
187 iGridImg->SetGridLabelImg(iTestLabelImg); |
|
188 iGridTable = new(ELeave) CTestGridTable(); |
|
189 iGridLay->ConstructL(iGridTable,iGridImg,ENoCols); |
|
190 |
|
191 iGridWin = CGridWin::NewL(NULL,iGridLay,iGridImg); |
|
192 AddToStackL(iGridWin); |
|
193 |
|
194 // |
|
195 iGridWin->SetRect((TRect(10,10,630,230))); |
|
196 iGridWin->ActivateL(); |
|
197 iGridWin->DrawNow(); |
|
198 // |
|
199 iGridLay->SetMinRowHeightInPixels(15); // If ENoRows is not used, a minRowHeight is recommended |
|
200 iGridLay->SetColumnBursting(ETrue); |
|
201 iGridLay->SetRowPermanentlySelectedL(ETrue); |
|
202 iGridLay->SetColumnSelectionDisabled(ETrue); |
|
203 iGridLay->SetCursorVisible(EFalse); |
|
204 iGridLay->SetHighlightVisible(EFalse); |
|
205 iGridLay->SetGridLabelSeparators(EFalse); |
|
206 iGridLay->SetAutoClearGridCells(EFalse); |
|
207 |
|
208 LoadL(); // Get Persistent data |
|
209 User::Heap().Check(); |
|
210 iGridWin->ActivateL(); |
|
211 User::Heap().Check(); |
|
212 |
|
213 AutoTestManager().StartAutoTest(); |
|
214 |
|
215 } |
|
216 /** |
|
217 Auxiliary function for T-CoGridStep-RunTestStepL.\n |
|
218 Creates a File Store and returns the pointer.\n |
|
219 |
|
220 @return FileStore pointer used for storing persistant data.\n |
|
221 |
|
222 */ |
|
223 CFileStore* CTestCoeGridAppUi::CreateStoreLC(RFile &aFile) |
|
224 { |
|
225 CFileStore *store=CDirectFileStore::NewLC(aFile); |
|
226 TUid uid; |
|
227 uid.iUid=TUint32('G'|('R'<<8)|('D'<<16)); |
|
228 store->SetTypeL(TUidType(KDirectFileStoreLayoutUid,uid)); |
|
229 return(store); |
|
230 } |
|
231 /** |
|
232 Auxiliary function for T-CoGridStep-RunTestStepL.\n |
|
233 Loads the GridLay settings and cursor position from dat file TGRID0.DAT.\n |
|
234 */ |
|
235 void CTestCoeGridAppUi::LoadL() |
|
236 { |
|
237 RFile file; |
|
238 TInt err=(file.Open(iCoeEnv->FsSession(),_L("C:\\data\\TCOGRD.DAT"), |
|
239 EFileRead|EFileShareReadersOnly)); |
|
240 if (err==KErrNotFound || err==KErrPathNotFound) |
|
241 return; // Use default settings |
|
242 User::LeaveIfError(err); |
|
243 |
|
244 CFileStore *store=CDirectFileStore::FromLC(file); |
|
245 TStreamId root=store->Root(); |
|
246 RStoreReadStream source; |
|
247 source.OpenLC(*store,root); |
|
248 source >> *(iGridWin->GridLay()); |
|
249 TCellRef cursorPos; |
|
250 source >> cursorPos; |
|
251 // TInt visibleFromCol=iGridWin->GridLay()->VisibleRange().iFrom.iCol; |
|
252 // iGridWin->SetCursorPosL(TCellRef(cursorPos.iRow,visibleFromCol)); |
|
253 |
|
254 iGridWin->SetCursorPosL(iGridWin->GridLay()->VisibleRange().iFrom); |
|
255 |
|
256 CleanupStack::PopAndDestroy(2); // stream+store |
|
257 } |
|
258 /** |
|
259 Auxiliary function for T-CoGridStep-RunTestStepL.\n |
|
260 Stores the current grid settings to a Dat File.\n |
|
261 Saves the current cursor postion.\n |
|
262 */ |
|
263 void CTestCoeGridAppUi::SaveL() |
|
264 { |
|
265 RFs fsSession=iCoeEnv->FsSession(); |
|
266 RFile file; |
|
267 TInt err=fsSession.MkDir(_L("C:\\data\\")); |
|
268 if (err!=KErrAlreadyExists) |
|
269 User::LeaveIfError(err); |
|
270 User::LeaveIfError(file.Replace(fsSession,_L("C:\\data\\TCOGRD.DAT"),EFileRead|EFileWrite)); |
|
271 |
|
272 CFileStore *store=CreateStoreLC(file); |
|
273 RStoreWriteStream source; |
|
274 TStreamId root = source.CreateLC(*store); |
|
275 source << *(iGridWin->GridLay()); |
|
276 source << iGridWin->CursorPos(); |
|
277 store->SetRootL(root); |
|
278 CleanupStack::PopAndDestroy(2); |
|
279 } |
|
280 /** |
|
281 Auxiliary function for T-CoGridStep-RunTestStepL.\n |
|
282 Sets the zoom factor depending on the argument.\n |
|
283 To Redraw the grid table again, the procedure followed is as follows\n |
|
284 Recalculates the internal maps that map row and column numbers to heights and widths respectively.\n |
|
285 Resets the reference points.\n |
|
286 The reference points are the mainpoint and the titlepoint.\n |
|
287 Resets the row and column numbers visible at the bottom, and to the right, of the visible area of the grid.\n |
|
288 */ |
|
289 void CTestCoeGridAppUi::SetZoomFactorL(TInt aZoomFactor) |
|
290 { |
|
291 iZoomFactor->SetZoomFactor(aZoomFactor); |
|
292 TEST(aZoomFactor == iZoomFactor->ZoomFactor()); |
|
293 iTestLabelImg->NotifyGraphicsDeviceMapChangeL(); |
|
294 iGridWin->GridLay()->RecalcPixelSparseMaps(); |
|
295 iGridWin->GridImg()->ResetReferencePoints(); |
|
296 iGridWin->GridLay()->ResetVisibleToCell(); |
|
297 iGridWin->DrawNow(); |
|
298 } |
|
299 |
|
300 /** |
|
301 Auxiliary function for T-CoGridStep-RunTestStepL.\n |
|
302 Sets the Grid colours depending on the argument.\n |
|
303 If Reset is enabled, the default colours will be enabled.\n |
|
304 Foreground to RGB value(0,0,0) , Background to RGB value(255,255,255) and Lines to (170,170,170).\n |
|
305 If Reset is not enabled, Sets the following combination\n |
|
306 Forground to Blue, Background to Yellow, Colour of lines to Yellow and Label separators |
|
307 to Green.\n |
|
308 */ |
|
309 void CTestCoeGridAppUi::ChangeColors(TBool aReset) |
|
310 { |
|
311 if (aReset) |
|
312 { |
|
313 TGridColors gridColors; |
|
314 iGridLay->SetGridColors(gridColors); |
|
315 } |
|
316 else |
|
317 { |
|
318 TGridColors newGridColors(KRgbBlue, KRgbYellow, KRgbRed, KRgbGreen); |
|
319 iGridLay->SetGridColors(newGridColors); |
|
320 } |
|
321 iUndoColors = aReset; |
|
322 } |
|
323 /** |
|
324 @SYMTestCaseID UIF-CoGridStep-RunTestStepL |
|
325 |
|
326 @SYMPREQ |
|
327 |
|
328 @SYMTestCaseDesc |
|
329 Tests different functionalities of Grid Window |
|
330 |
|
331 @SYMTestPriority High |
|
332 |
|
333 @SYMTestStatus Implemented |
|
334 |
|
335 @SYMTestActions \n |
|
336 The following tests are performed \n |
|
337 1. Setting grid with its default settings.\n |
|
338 2. Simulating right arrow key event.\n |
|
339 3. Simulating down arrow key event.\n |
|
340 4. Change Color Settings. \n |
|
341 5. Setting zoom in factor. \n |
|
342 6. Setting zoom out factor.\n |
|
343 7. Toggle Title Lines. \n |
|
344 8. Scroll Right.\n |
|
345 9. Scroll Left.\n |
|
346 7. Paginate the Grid. \n |
|
347 |
|
348 |
|
349 @SYMTestExpectedResults The test pass if the events are handled without exceptions / panic / crashes\n |
|
350 |
|
351 */ |
|
352 void CTestCoeGridAppUi::RunTestStepL(TInt aNumStep) |
|
353 { |
|
354 TKeyEvent theKeyEvent; |
|
355 Mem::FillZ(&theKeyEvent, sizeof(TKeyEvent)); |
|
356 TEventCode theType=EEventKey; |
|
357 |
|
358 |
|
359 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
360 |
|
361 switch(aNumStep) |
|
362 { |
|
363 case 1: |
|
364 SetTestStepID(_L("UIF-CoGridStep-RunTestStepL")); |
|
365 theKeyEvent.iModifiers = EModifierCtrl; |
|
366 theKeyEvent.iCode=CTRL('r'); |
|
367 INFO_PRINTF1(_L("Set grid to default")); |
|
368 HandleKeyEventL(theKeyEvent,theType); |
|
369 break; |
|
370 case 2: case 3: case 4: |
|
371 INFO_PRINTF1(_L("Move cursor right")); |
|
372 theKeyEvent.iCode = EKeyRightArrow; |
|
373 iGridWin->OfferKeyEventL(theKeyEvent,theType); |
|
374 break; |
|
375 case 5: case 6: |
|
376 INFO_PRINTF1(_L("Move cursor down")); |
|
377 theKeyEvent.iCode = EKeyDownArrow; |
|
378 iGridWin->OfferKeyEventL(theKeyEvent,theType); |
|
379 break; |
|
380 case 7: case 8: |
|
381 INFO_PRINTF1(_L("Change color")); |
|
382 theKeyEvent.iModifiers=EModifierCtrl; |
|
383 theKeyEvent.iCode = CTRL('c'); |
|
384 HandleKeyEventL(theKeyEvent,theType); |
|
385 break; |
|
386 case 9: case 10: |
|
387 INFO_PRINTF1(_L("Zoom in")); |
|
388 theKeyEvent.iModifiers=EModifierCtrl; |
|
389 theKeyEvent.iCode = CTRL('m'); |
|
390 HandleKeyEventL(theKeyEvent,theType); |
|
391 break; |
|
392 case 11: case 12: |
|
393 INFO_PRINTF1(_L("Zoom out")); |
|
394 theKeyEvent.iModifiers=EModifierShift; |
|
395 theKeyEvent.iCode = 'm'; |
|
396 HandleKeyEventL(theKeyEvent,theType); |
|
397 break; |
|
398 case 13: |
|
399 INFO_PRINTF1(_L("Toggle title lines")); |
|
400 theKeyEvent.iModifiers=EModifierCtrl; |
|
401 theKeyEvent.iCode = CTRL('t'); |
|
402 HandleKeyEventL(theKeyEvent,theType); |
|
403 break; |
|
404 case 14: |
|
405 INFO_PRINTF1(_L("Scroll right")); |
|
406 theKeyEvent.iModifiers=EModifierCtrl; |
|
407 theKeyEvent.iCode = EKeyRightArrow; |
|
408 iGridWin->OfferKeyEventL(theKeyEvent,theType); |
|
409 break; |
|
410 case 15: |
|
411 INFO_PRINTF1(_L("Scroll left")); |
|
412 theKeyEvent.iModifiers=EModifierCtrl; |
|
413 theKeyEvent.iCode = EKeyLeftArrow; |
|
414 iGridWin->OfferKeyEventL(theKeyEvent,theType); |
|
415 break; |
|
416 case 16: |
|
417 INFO_PRINTF1(_L("Toggle title lines")); |
|
418 theKeyEvent.iModifiers=EModifierCtrl; |
|
419 theKeyEvent.iCode = CTRL('t'); |
|
420 HandleKeyEventL(theKeyEvent,theType); |
|
421 break; |
|
422 case 17: |
|
423 INFO_PRINTF1(_L("Paginate")); |
|
424 theKeyEvent.iModifiers=EModifierCtrl; |
|
425 theKeyEvent.iCode = CTRL('p'); |
|
426 HandleKeyEventL(theKeyEvent,theType); |
|
427 break; |
|
428 case 18: |
|
429 INFO_PRINTF1(_L("Set grid to default")); |
|
430 theKeyEvent.iModifiers=EModifierCtrl; |
|
431 theKeyEvent.iCode = CTRL('r'); |
|
432 HandleKeyEventL(theKeyEvent,theType); |
|
433 RecordTestResultL(); |
|
434 CloseTMSGraphicsStep(); |
|
435 break; |
|
436 case 19: |
|
437 SaveL(); |
|
438 iCoeEnv->Flush(); |
|
439 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
440 break; |
|
441 |
|
442 } |
|
443 } |
|
444 |
|
445 /** |
|
446 Constructs the CTCoGrid Test application.\n |
|
447 Initializes the AppUi object.\n |
|
448 Sets the AppUi object as the default AppUi for the application.\n |
|
449 |
|
450 */ |
|
451 void CTCoGridStep::ConstructAppL(CCoeEnv* aCoe) |
|
452 { // runs inside a TRAP harness |
|
453 aCoe->ConstructL(); |
|
454 CTestCoeGridAppUi* appUi=new(ELeave) CTestCoeGridAppUi(this); |
|
455 appUi->ConstructL(); |
|
456 aCoe->SetAppUi(appUi); |
|
457 } |
|
458 |
|
459 |
|
460 CTCoGridStep::~CTCoGridStep() |
|
461 /** |
|
462 Destructor |
|
463 */ |
|
464 { |
|
465 } |
|
466 |
|
467 CTCoGridStep::CTCoGridStep() |
|
468 /** |
|
469 Constructor |
|
470 */ |
|
471 { |
|
472 // Call base class method to set up the human readable name for logging |
|
473 SetTestStepName(KTCoGridStep); |
|
474 } |
|
475 /** |
|
476 Entry Function for the CTCoGrid Test Step.\n |
|
477 Initializes a control environment for the application.\n |
|
478 Starts the application.\n |
|
479 |
|
480 @return : Test execution results indicating whether the test step has passed or failed.\n |
|
481 |
|
482 */ |
|
483 TVerdict CTCoGridStep::doTestStepL() |
|
484 { |
|
485 INFO_PRINTF1(_L("Test Started")); |
|
486 |
|
487 PreallocateHALBuffer(); |
|
488 |
|
489 __UHEAP_MARK; |
|
490 |
|
491 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
492 TRAPD(err,ConstructAppL(coe)); |
|
493 if (!err) |
|
494 coe->ExecuteD(); |
|
495 else |
|
496 { |
|
497 SetTestStepResult(EFail); |
|
498 delete coe; |
|
499 } |
|
500 |
|
501 __UHEAP_MARKEND; |
|
502 |
|
503 INFO_PRINTF1(_L("Test Finished")); |
|
504 return TestStepResult(); |
|
505 } |
|
506 |