os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsgdrawablegeneric.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsgdrawablegeneric.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,295 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +/**
1.19 + @file
1.20 + @test
1.21 + @internalComponent - Graphics Resource API Conformance Test Suite
1.22 +*/
1.23 +#include "tsgdrawablegeneric.h"
1.24 +
1.25 +/**
1.26 +Construct the CTsgDrawableGeneric tests; set whether the tests are being used as conformance
1.27 +tests or OOM tests.
1.28 +
1.29 +@param TBool ETrue to run the conformance tests, EFalse to run the OOM tests.
1.30 + */
1.31 +CTSgDrawableGeneric::CTSgDrawableGeneric(TBool aConformanceTests) :
1.32 + CTSgTestStepBase(aConformanceTests)
1.33 + {
1.34 + INFO_PRINTF1(_L("Graphics resource component test - RSgDrawable Generic Tests.\r\n"));
1.35 + }
1.36 +
1.37 +CTSgDrawableGeneric::~CTSgDrawableGeneric()
1.38 + {
1.39 + }
1.40 +
1.41 +/**
1.42 +Overrides of base class pure virtual
1.43 +Our implementation only gets called if the base class doTestStepPreambleL() did
1.44 +not leave. That being the case, the current test result value will be EPass.
1.45 +@leave Gets system wide error code
1.46 +@return TVerdict code
1.47 +*/
1.48 +TVerdict CTSgDrawableGeneric::doTestStepL()
1.49 + {
1.50 + SetTestStepID(_L("GRAPHICS-RESOURCE-0013"));
1.51 + INFO_PRINTF1(_L("Opening an image in RSgDrawable.\r\n"));
1.52 + TestOpenImageAsDrawableL();
1.53 + RecordTestResultL();
1.54 +
1.55 + SetTestStepID(_L("GRAPHICS-RESOURCE-0014"));
1.56 + INFO_PRINTF1(_L("Retrieving drawable id of an RSgDrawable object.\r\n"));
1.57 + TestGetDrawableDrawableIdL();
1.58 + RecordTestResultL();
1.59 +
1.60 + SetTestStepID(_L("GRAPHICS-RESOURCE-0032"));
1.61 + INFO_PRINTF1(_L("RSgDrawable::Open() with invalid parameters.\r\n"));
1.62 + TestOpenDrawableInvalidL();
1.63 + RecordTestResultL();
1.64 +
1.65 + SetTestStepID(_L("GRAPHICS-RESOURCE-0033"));
1.66 + INFO_PRINTF1(_L("Releasing reference to the image in RSgDrawable without first opening it.\r\n"));
1.67 + TestCloseDrawableWithoutOpenL();
1.68 + RecordTestResultL();
1.69 +
1.70 +#ifdef _DEBUG
1.71 + SetTestStepID(_L("GRAPHICS-RESOURCE-0080"));
1.72 + INFO_PRINTF1(_L("RSgDrawable generic panic test - Open() when the driver is not initialised.\r\n"));
1.73 + TestPanicDrawableOpenNoDriverL();
1.74 + RecordTestResultL();
1.75 +#else
1.76 + INFO_PRINTF1(_L("Warning: Skipping the panic tests in release build. \r\n"));
1.77 +#endif
1.78 +
1.79 + return TestStepResult();
1.80 + }
1.81 +
1.82 +
1.83 +/**
1.84 +@SYMTestCaseID GRAPHICS-RESOURCE-0013
1.85 +@SYMTestCaseDesc Opens an RSgImage as an RSgDrawable.
1.86 +@SYMPREQ PREQ2637
1.87 +@SYMFssID RSgImage::Id()
1.88 + RSgDrawable::Open(const TSgDrawableId&)
1.89 +@SYMTestPriority High
1.90 +@SYMTestType UT
1.91 +@SYMTestPurpose To ensure an RSgDrawable object can reference an image.
1.92 +@SYMTestActions Initialise the graphics resource component. Create an image. Declare an
1.93 + RSgDrawable object. Call Open() on the object with the resource ID of the
1.94 + image. These tests are repeated in a seperate thread and seperate process.
1.95 +@SYMTestExpectedResults The function should return KErrNone. The RSgDrawable now references an
1.96 + image. The same should occur in the seperate thread and seperate process.
1.97 + */
1.98 +void CTSgDrawableGeneric::TestOpenImageAsDrawableL()
1.99 + {
1.100 + TestOpenDriverL();
1.101 + RSgImage image;
1.102 + CreateImageL(image);
1.103 + CleanupClosePushL(image);
1.104 + const TSgDrawableId id = image.Id();
1.105 + TSgImageInfo imageinfo;
1.106 + image.GetInfo(imageinfo);
1.107 +
1.108 + //opening an image as a drawable in the current thread
1.109 + RSgImage image2;
1.110 + TEST(image2.IsNull());
1.111 + CheckErrorL(KErrNone, image2.Open(id), (TText8*)__FILE__, __LINE__);
1.112 + TEST(!image2.IsNull());
1.113 + image2.Close();
1.114 + if (iEnableConformanceTests)
1.115 + {
1.116 + //opening an image as a drawable in another thread in the same process
1.117 + TSgThreadTestInfo threadInfo(id, imageinfo, ESgresSecondThreadOpenDrawable);
1.118 + TInt testResult = 0;
1.119 + TRAPD(err, testResult=CreateSecondThreadAndDoTestL(threadInfo));
1.120 + TEST(err == KErrNone);
1.121 + TEST(testResult >= 0);
1.122 + TEST(testResult & EFirstTestPassed);
1.123 + TEST(testResult & ESecondTestPassed);
1.124 + TEST(testResult & EThirdTestPassed);
1.125 +
1.126 + //opening an image as drawbale in a different process
1.127 + TSgProcessTestInfo processInfo(id, imageinfo, ESgresSecondProcessOpenDrawable);
1.128 + TRAP(err, testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo));
1.129 + TEST(err == KErrNone);
1.130 + TEST(testResult >= 0);
1.131 + TEST(testResult & EFirstTestPassed);
1.132 + TEST(testResult & ESecondTestPassed);
1.133 + TEST(testResult & EThirdTestPassed);
1.134 + }
1.135 +
1.136 + CleanupStack::PopAndDestroy();
1.137 + TestCloseDriver();
1.138 + }
1.139 +
1.140 +/**
1.141 +@SYMTestCaseID GRAPHICS-RESOURCE-0014
1.142 +@SYMTestCaseDesc Retrieves drawable id of an RSgDrawable.
1.143 +@SYMPREQ PREQ2637
1.144 +@SYMFssID RSgImage::Id()
1.145 + RSgDrawable::Open(const TSgDrawableId&)
1.146 + RSgDrawable::Id()
1.147 +@SYMTestPriority Critical
1.148 +@SYMTestType UT
1.149 +@SYMTestPurpose To ensure the globally unique drawable id of the RSgDrawable object can be retrieved.
1.150 +@SYMTestActions Initialise the graphics resource component. Create an image. Call Id() on the image.
1.151 + Construct an RSgDrawable object and open an image in it. Call Id() on the
1.152 + RSgDrawable object. Compare the two ids.
1.153 +@SYMTestExpectedResults The two drawable ids should be identical.
1.154 + */
1.155 +void CTSgDrawableGeneric::TestGetDrawableDrawableIdL()
1.156 + {
1.157 + TestOpenDriverL();
1.158 + RSgImage image;
1.159 + CreateImageL(image);
1.160 + CleanupClosePushL(image);
1.161 + TSgDrawableId id1 = image.Id();
1.162 + TEST(id1 != KSgNullDrawableId);
1.163 +
1.164 + RSgDrawable drawable;
1.165 + TEST(KErrNone == drawable.Open(id1));
1.166 + TSgDrawableId id2 = drawable.Id();
1.167 + TEST(id2 != KSgNullDrawableId);
1.168 + TEST(id1 == id2);
1.169 +
1.170 + drawable.Close();
1.171 + CleanupStack::PopAndDestroy();
1.172 + TestCloseDriver();
1.173 + }
1.174 +
1.175 +
1.176 +/**
1.177 +@SYMTestCaseID GRAPHICS-RESOURCE-0032
1.178 +@SYMTestCaseDesc Calls RSgDrawable::Open() with invalid parameters.
1.179 +@SYMPREQ PREQ2637
1.180 +@SYMFssID RSgImage::Id()
1.181 + RSgDrawable::Open(const TSgDrawableId&)
1.182 +@SYMTestPriority Medium
1.183 +@SYMTestType UT
1.184 +@SYMTestPurpose To check the correct error codes are returned if Open() uses invalid parameters.
1.185 +@SYMTestActions Initialise the graphics resource component. Create an image. Declare an RSgDrawable
1.186 + object. Call Open() with:
1.187 + 1. null drawable id
1.188 + 2. a non-existing
1.189 + 3. valid drawable id
1.190 + 4. on a RSgDrawable handle that is not null
1.191 + Do the same tests in a second thread in the same process and in a second process.
1.192 +@SYMTestExpectedResults The function should return:
1.193 + 1. KErrArgument
1.194 + 2. KErrNotFound
1.195 + 3. KErrNone
1.196 + 4. KErrInUse
1.197 + */
1.198 +void CTSgDrawableGeneric::TestOpenDrawableInvalidL()
1.199 + {
1.200 + TestOpenDriverL();
1.201 + //same thread
1.202 + // null drawable id
1.203 + RSgDrawable drawable;
1.204 + CheckErrorL(KErrArgument, drawable.Open(KSgNullDrawableId), (TText8*)__FILE__, __LINE__);
1.205 + drawable.Close();
1.206 +
1.207 + // non-existing drawable id
1.208 + TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
1.209 + CheckErrorL(KErrNotFound, drawable.Open(fakeid), (TText8*)__FILE__, __LINE__);
1.210 + drawable.Close();
1.211 +
1.212 + //create a valid image
1.213 + TSgImageInfo info;
1.214 + info.iSizeInPixels = TSize(8, 8);
1.215 + info.iUsage = ESgUsageBitOpenVgImage;
1.216 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.217 +
1.218 + RSgImage image;
1.219 + CheckErrorL(KErrNone, image.Create(info, KCrossImageData, KCrossImageDataStride), (TText8*)__FILE__, __LINE__);
1.220 + CleanupClosePushL(image);
1.221 + const TSgDrawableId id = image.Id();
1.222 +
1.223 + // open an image - should succeed
1.224 + TEST(KErrNone == drawable.Open(id));
1.225 +
1.226 + // open on a non-null RSgDrawable handle
1.227 + TEST(KErrInUse == drawable.Open(id));
1.228 + drawable.Close();
1.229 +
1.230 + if (iEnableConformanceTests)
1.231 + {
1.232 + //different thread in the same process
1.233 + TSgThreadTestInfo threadInfo(id, info, ESgresSecondThreadOpenDrawableInvalid);
1.234 + TInt testResult = 0;
1.235 + TRAPD(err, testResult = CreateSecondThreadAndDoTestL(threadInfo));
1.236 + TEST(err == KErrNone);
1.237 + TEST(testResult >= 0);
1.238 + TEST(testResult & EFirstTestPassed);
1.239 + TEST(testResult & ESecondTestPassed);
1.240 + TEST(testResult & EThirdTestPassed);
1.241 + TEST(testResult & EFourthTestPassed);
1.242 +
1.243 + //different process
1.244 + TSgProcessTestInfo processInfo(id, info, ESgresSecondProcessOpenDrawableInvalid);
1.245 + TRAP(err, testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo));
1.246 + TEST(err == KErrNone);
1.247 + TEST(testResult >= 0);
1.248 + TEST(testResult & EFirstTestPassed);
1.249 + TEST(testResult & ESecondTestPassed);
1.250 + TEST(testResult & EThirdTestPassed);
1.251 + TEST(testResult & EFourthTestPassed);
1.252 + }
1.253 + CleanupStack::PopAndDestroy(&image);
1.254 + TestCloseDriver();
1.255 + }
1.256 +
1.257 +/**
1.258 +@SYMTestCaseID GRAPHICS-RESOURCE-0033
1.259 +@SYMTestCaseDesc Closes RSgDrawable without first opening it.
1.260 +@SYMPREQ PREQ2637
1.261 +@SYMFssID RSgDrawable::Close()
1.262 +@SYMTestPriority Low
1.263 +@SYMTestType UT
1.264 +@SYMTestPurpose To check the function does nothing if Open() was not called.
1.265 +@SYMTestActions Initialise the graphics resource component. Declare an RSgDrawable object. Call Close().
1.266 +@SYMTestExpectedResults The function should not panic or return any error.
1.267 + */
1.268 +void CTSgDrawableGeneric::TestCloseDrawableWithoutOpenL()
1.269 + {
1.270 + TestOpenDriverL();
1.271 + RSgDrawable drawable;
1.272 + drawable.Close();
1.273 + drawable.Close();
1.274 + drawable.Close();
1.275 + TestCloseDriver();
1.276 + }
1.277 +
1.278 +/**
1.279 +@SYMTestCaseID GRAPHICS-RESOURCE-0080
1.280 +@SYMTestCaseDesc Calls RSgDrawable::Open() when the driver was not initialised.
1.281 +@SYMPREQ PREQ2637
1.282 +@SYMFssID RSgImage::Open()
1.283 +@SYMTestPriority Low
1.284 +@SYMTestType UT
1.285 +@SYMTestPurpose To ensure calling RSgDrawable::Open() with an uninitialised driver will cause a panic.
1.286 +@SYMTestActions Do not Initialise the graphics resource component and call RSgDrawable::Open() in a second thread.
1.287 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 1 (ESgPanicNoDriver).
1.288 + */
1.289 +void CTSgDrawableGeneric::TestPanicDrawableOpenNoDriverL()
1.290 + {
1.291 + TSgImageInfo info;
1.292 + TSgThreadTestInfo threadInfo(KSgNullDrawableId, info, ESgresSecondThreadPanicDrawableOpenNoDriver);
1.293 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.294 + _LIT(KTestName, "TestPanicDrawableOpenNoDriverL");
1.295 + CreateSecondThreadAndCheckPanicL(threadInfo, 1, exitCategoryName, KTestName);
1.296 + }
1.297 +
1.298 +