Update contrib.
1 // Copyright (c) 2004-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "TScdvTest.h"
20 GLREF_C TInt ByteSize(TDisplayMode aDisplayMode,TInt aWidth);
22 //===================================================================
23 //In order to test multiple screens creation process on the Emulator,
24 //you have to extend your epoc.ini file with the following lines
28 //===================================================================
30 CTScdv::CTScdv(CTestStep* aStep) :
36 //The method calculates the memory (in bytes) needed for a screen
37 //device with aSize size and aDisplayMode mode.
38 inline TInt CTScdv::ByteSize(const TSize& aSize, TDisplayMode aDisplayMode)
40 return ::ByteSize(aDisplayMode,aSize.iWidth) * aSize.iHeight;
43 //The method creates a screen device for aScreenNo screen number .
44 //Possible leaving error codes: KErrNoMemory.
45 //Return result: ETrue - the device was created successfully, EFalse - not supported.
46 //Successfully created device will be pushed on the cleanup stack.
47 TBool CTScdv::CreateScreenDeviceLC(TInt aScreenNo,
48 TDisplayMode aDisplayMode,
49 CFbsDrawDevice*& aScreenDevice)
51 __ASSERT_ALWAYS(aScreenDevice == NULL, User::Invariant());
53 TRAPD(err, aScreenDevice = CFbsDrawDevice::NewScreenDeviceL(aScreenNo, aDisplayMode));
56 CleanupStack::PushL(aScreenDevice);
61 if(err != KErrNotSupported)
63 User::LeaveIfError(err);
69 //The method initializes aScreenDevice screen device and allocates.
70 //a block of memory for it.
71 //Possible leaving error codes: KErrNoMemory.
72 //The allocated bock of memory will be pushed on the cleanup stack.
73 TAny* CTScdv::InitScreenDeviceLC(CFbsDrawDevice* aScreenDevice,
74 TDisplayMode aDisplayMode)
76 __ASSERT_ALWAYS(aScreenDevice != NULL, User::Invariant());
78 TSize size = aScreenDevice->SizeInPixels();
79 TInt bytesToAllocate=ByteSize(size, aDisplayMode);
80 const TInt bytesRequire=bytesToAllocate;
81 TUint8* devMemory = new TUint8[bytesToAllocate];
86 devMemory=new TUint8[bytesToAllocate];
87 } while (devMemory==NULL && bytesToAllocate>0);
90 _LIT(KLog1,"Not enought memory!! Allocated %d (0x%x) bytes when %d (0x%x) bytes required.");
91 INFO_PRINTF5(KLog1,bytesToAllocate,bytesToAllocate,bytesRequire,bytesRequire);
92 _LIT(KLog2,"Display Mode: %S, Screen Size: %d,%d");
93 INFO_PRINTF4(KLog2,&ColorModeName(aDisplayMode),size.iWidth,size.iHeight);
97 _LIT(KLog,"Failed to Allocate memory!! %d (0x%x) bytes required, Display Mode: %S, Screen Size: %d,%d");
98 INFO_PRINTF6(KLog,bytesRequire,bytesRequire,&ColorModeName(aDisplayMode),size.iWidth,size.iHeight);
99 User::Leave(KErrNoMemory);
102 CleanupStack::PushL(devMemory);
104 aScreenDevice->SetUserDisplayMode(aDisplayMode);
105 aScreenDevice->SetAutoUpdate(EFalse);
106 aScreenDevice->SetBits(devMemory);
110 //Mutltiple screen devices creation test
111 void CTScdv::TestScreenDeviceCreationL()
113 TDisplayMode mode[] = { EColor256, EColor4K, EColor64K, EColor16,
114 EColor16MU, EColor16MA, EColor16MAP };
116 const TInt KTestedDevCnt = 2;
118 for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));++ii)
121 CFbsDrawDevice* dev[KTestedDevCnt];
122 Mem::FillZ(dev, sizeof(dev));
124 for(cnt=0;cnt<KTestedDevCnt;++cnt)
126 TBool res = CreateScreenDeviceLC(cnt, mode[ii], dev[cnt]);
129 InitScreenDeviceLC(dev[cnt], mode[ii]);
130 _LIT(KLog,"Created Screen Device with mode %S on screen %d");
131 INFO_PRINTF3(KLog,&ColorModeName(mode[ii]),cnt);
133 CleanupStack::PopAndDestroy(2,dev[cnt]);
137 _LIT(KLog,"No support for display mode %S on screen %d");
138 const TDesC* name=&ColorModeName(mode[ii]);
139 INFO_PRINTF3(KLog, name, cnt);
140 RDebug::Print(KLog, name, cnt);
147 //Bitmap device creation test
148 void CTScdv::TestBitmapDeviceCreationL()
150 TDisplayMode mode[] = {EColor256, EColor4K, EColor16M, EColor16MU, EColor16MA, EColor16MAP, EColor64K,
151 EGray256, EGray16, EGray4, EGray2, EColor16};
152 for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));++ii)
156 TUint8* bitmapMem = new (ELeave) TUint8[ByteSize(size, mode[ii])];
157 CleanupStack::PushL(bitmapMem);
158 CFbsDrawDevice* bitmapDev = CFbsDrawDevice::NewBitmapDeviceL(size, mode[ii], ByteSize(size, mode[ii]) / size.iHeight);
159 CleanupStack::PushL(bitmapDev);
161 bitmapDev->SetAutoUpdate(EFalse);
162 bitmapDev->SetBits(bitmapMem);
164 CleanupStack::PopAndDestroy(2);//bitmapMem, bitmapDev
168 void CTScdv::RunTestCaseL(TInt aCurTestCase)
170 ((CTScdvStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
174 INFO_PRINTF1(_L("Mutiple screen devices creation test"));
176 @SYMTestCaseID GRAPHICS-SCREENDRIVER-0033
178 ((CTScdvStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0033"));
179 TestScreenDeviceCreationL();
182 INFO_PRINTF1(_L("Bitmap device creation test"));
184 @SYMTestCaseID GRAPHICS-SCREENDRIVER-0034
186 ((CTScdvStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0034"));
187 TestBitmapDeviceCreationL();
190 ((CTScdvStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
191 ((CTScdvStep*)iStep)->CloseTMSGraphicsStep();
195 ((CTScdvStep*)iStep)->RecordTestResultL();
199 __CONSTRUCT_STEP__(Scdv)
202 void CTScdvStep::TestSetupL()
205 HAL::Get(HALData::EDisplayColors, temp);//force HAL memory allocation