1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresource/test/tsgdriver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,397 @@
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 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include "tsgdriver.h"
1.26 +
1.27 +CTSgDriver::CTSgDriver()
1.28 + {
1.29 + INFO_PRINTF1(_L("Graphics resource component test - SgDriver Tests.\r\n"));
1.30 + }
1.31 +
1.32 +CTSgDriver::~CTSgDriver()
1.33 + {
1.34 + }
1.35 +
1.36 +/**
1.37 +Overrides of base class pure virtual
1.38 +Our implementation only gets called if the base class doTestStepPreambleL() did
1.39 +not leave. That being the case, the current test result value will be EPass.
1.40 +@leave Gets system wide error code
1.41 +@return TVerdict code
1.42 +*/
1.43 +TVerdict CTSgDriver::doTestStepL()
1.44 + {
1.45 + SetTestStepID(_L("GRAPHICS-RESOURCE-0001"));
1.46 + INFO_PRINTF1(_L("Graphics resource component initialization and shutdown.\r\n"));
1.47 + TestInitializationAndShutdown();
1.48 + RecordTestResultL();
1.49 +
1.50 + SetTestStepID(_L("GRAPHICS-RESOURCE-0002"));
1.51 + INFO_PRINTF1(_L("Graphics resource component shutdown multiple time.\r\n"));
1.52 + TestInitializeShutdownManyTimes();
1.53 + RecordTestResultL();
1.54 +
1.55 + SetTestStepID(_L("GRAPHICS-RESOURCE-0022"));
1.56 + INFO_PRINTF1(_L("Shutting down an uninitialised driver.\r\n"));
1.57 + TestShutdownUninitialized();
1.58 + RecordTestResultL();
1.59 +
1.60 +#ifdef _DEBUG
1.61 + SetTestStepID(_L("GRAPHICS-RESOURCE-0078"));
1.62 + INFO_PRINTF1(_L("SgDriver panic test - private heap memory leak.\r\n"));
1.63 + TestDriverMemoryLeakL();
1.64 + RecordTestResultL();
1.65 +#ifndef __WINS__
1.66 + SetTestStepID(_L("GRAPHICS-RESOURCE-0023"));
1.67 + INFO_PRINTF1(_L("Shutting down without closing all resources.\r\n"));
1.68 + TestShutdownMemoryLeakL();
1.69 + RecordTestResultL();
1.70 +#endif
1.71 + SetTestStepID(_L("GRAPHICS-RESOURCE-0079"));
1.72 + INFO_PRINTF1(_L("SgDriver panic test - ResourceCount() without initialising the driver.\r\n"));
1.73 + TestPanicResourceCountNoDriverL();
1.74 + RecordTestResultL();
1.75 +
1.76 + SetTestStepID(_L("GRAPHICS-RESOURCE-0090"));
1.77 + INFO_PRINTF1(_L("SgDriver panic test - AllocMarkStart() without initialising the driver.\r\n"));
1.78 + TestPanicAllocMarkStartNoDriverL();
1.79 + RecordTestResultL();
1.80 +
1.81 + SetTestStepID(_L("GRAPHICS-RESOURCE-0091"));
1.82 + INFO_PRINTF1(_L("SgDriver panic test - AllocMarkEnd() without initialising the driver.\r\n"));
1.83 + TestPanicAllocMarkEndNoDriverL();
1.84 + RecordTestResultL();
1.85 +
1.86 + SetTestStepID(_L("GRAPHICS-RESOURCE-0092"));
1.87 + INFO_PRINTF1(_L("SgDriver panic test - SetAllocFail() without initialising the driver.\r\n"));
1.88 + TestPanicSetAllocFailNoDriverL();
1.89 + RecordTestResultL();
1.90 +#else
1.91 + INFO_PRINTF1(_L("Warning: Skipping the panic tests. \r\n"));
1.92 +#endif
1.93 + return TestStepResult();
1.94 + }
1.95 +
1.96 +
1.97 +/**
1.98 +@SYMTestCaseID GRAPHICS-RESOURCE-0001
1.99 +@SYMTestCaseDesc Initialises and shuts down the graphics resource driver.
1.100 +@SYMPREQ PREQ39
1.101 +@SYMREQ REQ8809
1.102 +@SYMREQ REQ9175
1.103 +@SYMREQ REQ9224
1.104 +@SYMREQ REQ9233
1.105 +@SYMREQ REQ9234
1.106 +@SYMFssID SgDriver::Open()\n
1.107 + RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)\n
1.108 + SgDriver::Close()\n
1.109 + SgDriver::ResourceCount()\n
1.110 +@SYMTestPriority Critical
1.111 +@SYMTestType Unit Test
1.112 +@SYMTestPurpose To ensure the graphics resource driver can be initialised successfully
1.113 +@SYMTestActions Call SgDriver::Open() to start the graphics resource driver, then try
1.114 + to call RSgImage::Create(). Call SgDriver::Open() the second time
1.115 + and then call RSgImage::Create() again. Close the driver and call
1.116 + RSgImage::Create(). Close the driver.
1.117 +@SYMTestExpectedResults RSgImage::Create() should return:\n
1.118 + \t 1. KErrNone \n
1.119 + \t 2. KErrNone \n
1.120 + \t 3. KErrNone \n
1.121 + SgDriver::Open() should return KErrNone both times.
1.122 +@SYMTestStatus Implemented
1.123 + */
1.124 +void CTSgDriver::TestInitializationAndShutdown()
1.125 + {
1.126 + __UHEAP_MARK;
1.127 +
1.128 + TSgImageInfo info;
1.129 + info.iSizeInPixels = TSize(8, 8);
1.130 + info.iUsage = ESgUsageDirectGdiSource;
1.131 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.132 + info.iCpuAccess = ESgCpuAccessReadWrite;
1.133 + info.iShareable = ETrue;
1.134 +
1.135 + RSgImage image;
1.136 + TEST(KErrNone == SgDriver::Open());
1.137 + TEST(KErrNone == image.Create(info, KImageData, 16));
1.138 + TEST(0 < SgDriver::ResourceCount());
1.139 + image.Close();
1.140 +
1.141 + TEST(KErrNone == SgDriver::Open());
1.142 + TEST(KErrNone == image.Create(info, KImageData, 16));
1.143 + image.Close();
1.144 +
1.145 + SgDriver::Close();
1.146 + TEST(KErrNone == image.Create(info, KImageData, 16));
1.147 + image.Close();
1.148 +
1.149 + TEST(0 == SgDriver::ResourceCount());
1.150 + SgDriver::Close();
1.151 +
1.152 + __UHEAP_MARKEND;
1.153 + }
1.154 +
1.155 +
1.156 +/**
1.157 +@SYMTestCaseID GRAPHICS-RESOURCE-0002
1.158 +@SYMTestCaseDesc Shuts down graphics resource driver multiple times.
1.159 +@SYMPREQ PREQ39
1.160 +@SYMREQ REQ8809
1.161 +@SYMREQ REQ9175
1.162 +@SYMREQ REQ9224
1.163 +@SYMREQ REQ9233
1.164 +@SYMREQ REQ9234
1.165 +@SYMFssID SgDriver::Open()\n
1.166 + SgDriver::Close()\n
1.167 + SgDriver::ResourceCount()\n
1.168 + RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
1.169 +@SYMTestPriority Critical
1.170 +@SYMTestType Unit Test
1.171 +@SYMTestPurpose To ensure the graphics resource driver could be shut down multiple times.
1.172 +@SYMTestActions Initialise the graphics resource driver. Create an image then close it.
1.173 + Shutdown the driver twice. Open and driver and create an image. Close the
1.174 + image and shutdown the driver.
1.175 +@SYMTestExpectedResults The graphics resource driver is successfully shut down. The calls to
1.176 + RSgImage::Create() should return:\n
1.177 + \t 1. KErrNone\n
1.178 + \t 2. KErrNone\n
1.179 +@SYMTestStatus Implemented
1.180 + */
1.181 +void CTSgDriver::TestInitializeShutdownManyTimes()
1.182 + {
1.183 + __UHEAP_MARK;
1.184 +
1.185 + TEST(KErrNone == SgDriver::Open());
1.186 +
1.187 + TSgImageInfo info;
1.188 + info.iSizeInPixels = TSize(8, 8);
1.189 + info.iUsage = ESgUsageDirectGdiSource;
1.190 + info.iPixelFormat = EUidPixelFormatRGB_565;
1.191 + info.iCpuAccess = ESgCpuAccessReadWrite;
1.192 + info.iShareable = ETrue;
1.193 +
1.194 + RSgImage image;
1.195 +
1.196 + TEST(KErrNone == image.Create(info, KImageData, 16));
1.197 + image.Close();
1.198 +
1.199 + SgDriver::Close();
1.200 + SgDriver::Close();
1.201 +
1.202 + TEST(KErrNone == SgDriver::Open());
1.203 + TEST(KErrNone == image.Create(info, KImageData, 16));
1.204 + image.Close();
1.205 +
1.206 + TEST(0 == SgDriver::ResourceCount());
1.207 + SgDriver::Close();
1.208 +
1.209 + __UHEAP_MARKEND;
1.210 + }
1.211 +
1.212 +
1.213 +/**
1.214 +@SYMTestCaseID GRAPHICS-RESOURCE-0022
1.215 +@SYMTestCaseDesc Shuts down an uninitialised driver.
1.216 +@SYMPREQ PREQ39
1.217 +@SYMREQ REQ8809
1.218 +@SYMREQ REQ9175
1.219 +@SYMFssID SgDriver::Close()
1.220 +@SYMTestPriority Critical
1.221 +@SYMTestType Unit Test
1.222 +@SYMTestPurpose To ensure invalid Close() calls on the driver will cause no errors.
1.223 +@SYMTestActions Call SgDriver::Close() several times without calling SgDriver::Open().
1.224 +@SYMTestExpectedResults No errors should be returned.
1.225 +@SYMTestStatus Implemented
1.226 + */
1.227 +void CTSgDriver::TestShutdownUninitialized()
1.228 + {
1.229 + __UHEAP_MARK;
1.230 +
1.231 + SgDriver::Close();
1.232 + SgDriver::Close();
1.233 + SgDriver::Close();
1.234 +
1.235 + __UHEAP_MARKEND;
1.236 + }
1.237 +
1.238 +/**
1.239 +@SYMTestCaseID GRAPHICS-RESOURCE-0023
1.240 +@SYMTestCaseDesc Shuts down the driver without closing all resources.
1.241 +@SYMPREQ PREQ39
1.242 +@SYMREQ REQ8809
1.243 +@SYMREQ REQ9175
1.244 +@SYMREQ REQ9224
1.245 +@SYMREQ REQ9233
1.246 +@SYMREQ REQ9234
1.247 +@SYMFssID SgDriver::Open()\n
1.248 + RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)\n
1.249 + SgDriver::Close()
1.250 +@SYMTestPriority Critical
1.251 +@SYMTestType Unit Test
1.252 +@SYMTestPurpose To ensure calling Close() without closing all resources will cause a panic.
1.253 +@SYMTestActions Initialise the graphics resource component and create an image in a second thread.
1.254 + Try to shutdown the component.
1.255 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 1(ESgPanicUnclosedResources).
1.256 +@SYMTestStatus Implemented
1.257 + */
1.258 +void CTSgDriver::TestShutdownMemoryLeakL()
1.259 + {
1.260 + TestOpenDriverL();
1.261 + //run the test in another process
1.262 + TSgImageInfo info;
1.263 + TSgresTestInfo processInfo = {KSgNullDrawableId, info, 0, ESgresSecondProcessPanicDriverUnclosedResources, ETrue};
1.264 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.265 + _LIT(KTestName, "TestShutdownMemoryLeakL");
1.266 + CreateSecondProcessAndCheckPanicL(processInfo, 1, exitCategoryName, KTestName);
1.267 + TestCloseDriver();
1.268 + }
1.269 +
1.270 +/**
1.271 +@SYMTestCaseID GRAPHICS-RESOURCE-0078
1.272 +@SYMTestCaseDesc Calls SgDriver::AllocMarkEnd() without shutting down all the resources.
1.273 +@SYMPREQ PREQ39
1.274 +@SYMREQ REQ8809
1.275 +@SYMREQ REQ9175
1.276 +@SYMREQ REQ9224
1.277 +@SYMREQ REQ9233
1.278 +@SYMREQ REQ9234
1.279 +@SYMFssID SgDriver::AllocMarkStart()\n
1.280 + SgDriver::AllocMarkEnd()
1.281 +@SYMTestPriority Critical
1.282 +@SYMTestType Unit Test
1.283 +@SYMTestPurpose To ensure calling SgDriver::AllocMarkEnd() without closing all resources will cause a panic.
1.284 +@SYMTestActions Initialise the graphics resource component in a second process and call SgDriver::AllocMarkStart().
1.285 + Create an image and call SgDriver::AllocMarkEnd().
1.286 +@SYMTestExpectedResults The function should panic in the second process with panic code SGRES-ADAPTER 0.
1.287 +@SYMTestStatus Implemented
1.288 + */
1.289 +void CTSgDriver::TestDriverMemoryLeakL()
1.290 + {
1.291 + TestOpenDriverL();
1.292 + //run the test in another process
1.293 + TSgImageInfo info;
1.294 + TSgresTestInfo processInfo = {KSgNullDrawableId, info, 0, ESgresSecondProcessPanicMemoryLeak, ETrue};
1.295 + TExitCategoryName exitCategoryName(_L("SGALLOC"));
1.296 + _LIT(KTestName, "TestDriverMemoryLeakL");
1.297 + CreateSecondProcessAndCheckPanicL(processInfo, 0, exitCategoryName, KTestName);
1.298 + TestCloseDriver();
1.299 + }
1.300 +
1.301 +
1.302 +/**
1.303 +@SYMTestCaseID GRAPHICS-RESOURCE-0079
1.304 +@SYMTestCaseDesc Calls SgDriver::ResourceCount() without initialising the driver.
1.305 +@SYMPREQ PREQ39
1.306 +@SYMREQ REQ8809
1.307 +@SYMREQ REQ9175
1.308 +@SYMFssID SgDriver::ResourceCount())\n
1.309 +@SYMTestPriority Critical
1.310 +@SYMTestType Unit Test
1.311 +@SYMTestPurpose To ensure calling SgDriver::ResourceCount() without initialising
1.312 + the driver first will cause a panic in the debug mode.
1.313 +@SYMTestActions Do not Initialise the graphics resource component and call
1.314 + SgDriver::ResourceCount() in a second thread.
1.315 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver).
1.316 +@SYMTestStatus Implemented
1.317 + */
1.318 +void CTSgDriver::TestPanicResourceCountNoDriverL()
1.319 + {
1.320 + TSgImageInfo info;
1.321 + TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicResourceCountNoDriver, ETrue};
1.322 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.323 + _LIT(KTestName, "TestPanicResourceCountNoDriverL");
1.324 + CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
1.325 + }
1.326 +
1.327 +/**
1.328 +@SYMTestCaseID GRAPHICS-RESOURCE-0090
1.329 +@SYMTestCaseDesc Calls SgDriver::AllocMarkStart() without initialising the driver.
1.330 +@SYMPREQ PREQ39
1.331 +@SYMREQ REQ8809
1.332 +@SYMREQ REQ9175
1.333 +@SYMFssID SgDriver::AllocMarkStart())\n
1.334 +@SYMTestPriority Critical
1.335 +@SYMTestType Unit Test
1.336 +@SYMTestPurpose To ensure calling SgDriver::AllocMarkStart() without initialising
1.337 + the driver first will cause a panic in the debug mode.
1.338 +@SYMTestActions Do not Initialise the graphics resource component and call
1.339 + SgDriver::AllocMarkStart() in a second thread.
1.340 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver).
1.341 +@SYMTestStatus Implemented
1.342 + */
1.343 +void CTSgDriver::TestPanicAllocMarkStartNoDriverL()
1.344 + {
1.345 + TSgImageInfo info;
1.346 + TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicAllocMarkStartNoDriver, ETrue};
1.347 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.348 + _LIT(KTestName, "TestPanicAllocMarkStartNoDriverL");
1.349 + CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
1.350 + }
1.351 +
1.352 +/**
1.353 +@SYMTestCaseID GRAPHICS-RESOURCE-0091
1.354 +@SYMTestCaseDesc Calls SgDriver::AllocMarkEnd() without initialising the driver.
1.355 +@SYMPREQ PREQ39
1.356 +@SYMREQ REQ8809
1.357 +@SYMREQ REQ9175
1.358 +@SYMFssID SgDriver::AllocMarkEnd())\n
1.359 +@SYMTestPriority Critical
1.360 +@SYMTestType Unit Test
1.361 +@SYMTestPurpose To ensure calling SgDriver::AllocMarkEnd() without initialising
1.362 + the driver first will cause a panic in the debug mode.
1.363 +@SYMTestActions Do not Initialise the graphics resource component and call
1.364 + SgDriver::AllocMarkEnd() in a second thread.
1.365 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver).
1.366 +@SYMTestStatus Implemented
1.367 + */
1.368 +void CTSgDriver::TestPanicAllocMarkEndNoDriverL()
1.369 + {
1.370 + TSgImageInfo info;
1.371 + TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicAllocMarkEndNoDriver, ETrue};
1.372 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.373 + _LIT(KTestName, "TestPanicAllocMarkEndNoDriverL");
1.374 + CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
1.375 + }
1.376 +
1.377 +/**
1.378 +@SYMTestCaseID GRAPHICS-RESOURCE-0092
1.379 +@SYMTestCaseDesc Calls SgDriver::SetAllocFail() without initialising the driver.
1.380 +@SYMPREQ PREQ39
1.381 +@SYMREQ REQ8809
1.382 +@SYMREQ REQ9175
1.383 +@SYMFssID SgDriver::SetAllocFail())\n
1.384 +@SYMTestPriority Critical
1.385 +@SYMTestType Unit Test
1.386 +@SYMTestPurpose To ensure calling SgDriver::SetAllocFail() without initialising
1.387 + the driver first will cause a panic in the debug mode.
1.388 +@SYMTestActions Do not Initialise the graphics resource component and call
1.389 + SgDriver::SetAllocFail() in a second thread.
1.390 +@SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver).
1.391 +@SYMTestStatus Implemented
1.392 + */
1.393 +void CTSgDriver::TestPanicSetAllocFailNoDriverL()
1.394 + {
1.395 + TSgImageInfo info;
1.396 + TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicSetAllocFailNoDriver, ETrue};
1.397 + TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
1.398 + _LIT(KTestName, "TestPanicSetAllocFailNoDriverL");
1.399 + CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
1.400 + }