os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdicontext.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "tdirectgdicontext.h"
sl@0
    17
#include <s32mem.h>
sl@0
    18
sl@0
    19
#include <graphics/directgdicontext.h>
sl@0
    20
sl@0
    21
sl@0
    22
_LIT16(KAbcd,"Abcd efgh ijkl mnop");
sl@0
    23
sl@0
    24
CTDirectGdiContext::CTDirectGdiContext()
sl@0
    25
	{
sl@0
    26
	SetTestStepName(KTDirectGdiContextStep);
sl@0
    27
	}
sl@0
    28
sl@0
    29
CTDirectGdiContext::~CTDirectGdiContext()
sl@0
    30
	{
sl@0
    31
	if(iFont)
sl@0
    32
		{
sl@0
    33
		ReleaseFont(iFont);		
sl@0
    34
		}	
sl@0
    35
	}
sl@0
    36
sl@0
    37
/**
sl@0
    38
@SYMTestCaseID
sl@0
    39
	GRAPHICS-DIRECTGDI-CONTEXT-0001
sl@0
    40
sl@0
    41
@SYMTestPriority
sl@0
    42
	Critical
sl@0
    43
sl@0
    44
@SYMPREQ
sl@0
    45
	PREQ39
sl@0
    46
sl@0
    47
@SYMREQ
sl@0
    48
	REQ9195
sl@0
    49
	REQ9201 
sl@0
    50
	REQ9202 
sl@0
    51
	REQ9222 
sl@0
    52
	REQ9223 
sl@0
    53
	REQ9236 
sl@0
    54
	REQ9237
sl@0
    55
sl@0
    56
@SYMTestCaseDesc
sl@0
    57
	Use case - Single context and single target.
sl@0
    58
sl@0
    59
@SYMTestActions		
sl@0
    60
	Single context is created and activated on a single target.
sl@0
    61
	Then some draw operations are done.
sl@0
    62
sl@0
    63
@SYMTestExpectedResults
sl@0
    64
	It should be able to draw using the correct context and target.
sl@0
    65
	
sl@0
    66
@SYMTestStatus 		
sl@0
    67
	Implemented
sl@0
    68
*/
sl@0
    69
void CTDirectGdiContext::OneContextOneTarget()
sl@0
    70
	{		
sl@0
    71
	_LIT(KTestName, "Context-OneContextOneTarget"); 
sl@0
    72
	if(!iRunningOomTests)
sl@0
    73
		{
sl@0
    74
		INFO_PRINTF1(KTestName);
sl@0
    75
		}
sl@0
    76
	ResetGc();		
sl@0
    77
	
sl@0
    78
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
    79
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
    80
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
    81
	TESTNOERROR(iGc->GetError());
sl@0
    82
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
sl@0
    83
	}
sl@0
    84
sl@0
    85
/**
sl@0
    86
@SYMTestCaseID		
sl@0
    87
	GRAPHICS-DIRECTGDI-CONTEXT-0002
sl@0
    88
sl@0
    89
@SYMTestPriority
sl@0
    90
	Critical
sl@0
    91
sl@0
    92
@SYMPREQ
sl@0
    93
	PREQ39
sl@0
    94
sl@0
    95
@SYMREQ
sl@0
    96
	REQ9195
sl@0
    97
	REQ9201 
sl@0
    98
	REQ9202 
sl@0
    99
	REQ9222 
sl@0
   100
	REQ9223 
sl@0
   101
	REQ9236 
sl@0
   102
	REQ9237
sl@0
   103
sl@0
   104
@SYMTestCaseDesc
sl@0
   105
	Use case - Draw to two separate targets using a single context. 	
sl@0
   106
sl@0
   107
@SYMTestActions		
sl@0
   108
	Test that a single context can be activated on two different targets.
sl@0
   109
	- A single context is created and activated on a target then a green circle is drawn. 
sl@0
   110
	- The same context then activated on a second target and a red circle is drawn.  
sl@0
   111
sl@0
   112
@SYMTestExpectedResults
sl@0
   113
	It should be able to draw using the correct context and target and context should 
sl@0
   114
	be able to switch between the targets. The first target should have a green circle 
sl@0
   115
	only drawn on it, the second target should have a red circle only drawn on it.
sl@0
   116
sl@0
   117
@SYMTestStatus 		
sl@0
   118
	Implemented
sl@0
   119
*/
sl@0
   120
void CTDirectGdiContext::OneContextTwoTargets()
sl@0
   121
	{	
sl@0
   122
	TBuf<KTestCaseLength> testCaseNameA;
sl@0
   123
	TBuf<KTestCaseLength> testCaseNameB;
sl@0
   124
	_LIT(KTestCase, "Context-OneContextTwoTargets");
sl@0
   125
	testCaseNameA.Append(KTestCase);
sl@0
   126
	testCaseNameB.Append(KTestCase);
sl@0
   127
	if(iCaseNum == EOneContextTwoTargets_SamePixelType)
sl@0
   128
		{
sl@0
   129
		testCaseNameA.Append(KSamePixelType);
sl@0
   130
		testCaseNameB.Append(KSamePixelType);
sl@0
   131
		}
sl@0
   132
	else
sl@0
   133
		{
sl@0
   134
		testCaseNameA.Append(KDifferentPixelType);
sl@0
   135
		testCaseNameB.Append(KDifferentPixelType);
sl@0
   136
		}
sl@0
   137
	testCaseNameA.Append(KTarget1);
sl@0
   138
	testCaseNameB.Append(KTarget2);
sl@0
   139
	if(!iRunningOomTests)
sl@0
   140
		{
sl@0
   141
		INFO_PRINTF1(KTestCase);
sl@0
   142
		}
sl@0
   143
	ResetGc();
sl@0
   144
	iGc->SetPenColor(TRgb(0, 255, 0));
sl@0
   145
	TEST(iGc->PenColor() == TRgb(0, 255, 0));
sl@0
   146
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   147
	TESTNOERROR(iGc->GetError());
sl@0
   148
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));
sl@0
   149
	
sl@0
   150
	iGdiTarget2->Activate(iGc);
sl@0
   151
	
sl@0
   152
	ResetGc();
sl@0
   153
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   154
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   155
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   156
	TESTNOERROR(iGc->GetError());
sl@0
   157
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
sl@0
   158
	}
sl@0
   159
sl@0
   160
/**
sl@0
   161
@SYMTestCaseID		
sl@0
   162
	GRAPHICS-DIRECTGDI-CONTEXT-0003
sl@0
   163
sl@0
   164
@SYMTestPriority
sl@0
   165
	Critical
sl@0
   166
sl@0
   167
@SYMPREQ
sl@0
   168
	PREQ39
sl@0
   169
sl@0
   170
@SYMREQ
sl@0
   171
	REQ9195
sl@0
   172
	REQ9201 
sl@0
   173
	REQ9202 
sl@0
   174
	REQ9222 
sl@0
   175
	REQ9223 
sl@0
   176
	REQ9236 
sl@0
   177
	REQ9237
sl@0
   178
sl@0
   179
@SYMTestCaseDesc
sl@0
   180
	Use case - draw to a single target using two different contexts.
sl@0
   181
sl@0
   182
@SYMTestActions	
sl@0
   183
	Test context's creation and activation when drawing using two different contexts to a single target.
sl@0
   184
	- Activate the first context on the target and draw a red circle.
sl@0
   185
	- Write out the contents of the target.
sl@0
   186
	- Activate the second context on the target, clear it and draw a smaller black circle.
sl@0
   187
	- Write out the contents of the target.
sl@0
   188
sl@0
   189
@SYMTestExpectedResults
sl@0
   190
	It should be able to draw using the correct context and target. The first image written out
sl@0
   191
	should contain a red circle, the second image written out should contain a smaller black circle.
sl@0
   192
	
sl@0
   193
@SYMTestStatus 		
sl@0
   194
	Implemented
sl@0
   195
*/
sl@0
   196
void CTDirectGdiContext::TwoContextsOneTarget()
sl@0
   197
	{	
sl@0
   198
	TBuf<KTestCaseLength> testCaseNameA;
sl@0
   199
	TBuf<KTestCaseLength> testCaseNameB;
sl@0
   200
	_LIT(KTestCase, "Context-TwoContextsOneTarget");
sl@0
   201
	testCaseNameA.Append(KTestCase);
sl@0
   202
	testCaseNameB.Append(KTestCase);
sl@0
   203
	testCaseNameA.Append(KContext1);
sl@0
   204
	testCaseNameB.Append(KContext2);
sl@0
   205
	
sl@0
   206
	if(!iRunningOomTests)
sl@0
   207
		{
sl@0
   208
		INFO_PRINTF1(KTestCase);
sl@0
   209
		}
sl@0
   210
	iGdiTarget->Activate(iGc);
sl@0
   211
	ResetGc();
sl@0
   212
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   213
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   214
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   215
	TESTNOERROR(iGc->GetError());
sl@0
   216
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
sl@0
   217
		
sl@0
   218
	iGdiTarget->Activate(iGc2);
sl@0
   219
	iGc2->Reset();
sl@0
   220
	iGc2->Clear();
sl@0
   221
	iGc2->SetPenColor(TRgb(0, 0, 0));
sl@0
   222
	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
sl@0
   223
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   224
	TESTNOERROR(iGc2->GetError());	
sl@0
   225
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB)));
sl@0
   226
	}
sl@0
   227
sl@0
   228
/**
sl@0
   229
@SYMTestCaseID		
sl@0
   230
	GRAPHICS-DIRECTGDI-CONTEXT-0004
sl@0
   231
sl@0
   232
@SYMTestPriority
sl@0
   233
	Critical
sl@0
   234
sl@0
   235
@SYMPREQ
sl@0
   236
	PREQ39
sl@0
   237
sl@0
   238
@SYMREQ
sl@0
   239
	REQ9195
sl@0
   240
	REQ9201 
sl@0
   241
	REQ9202 
sl@0
   242
	REQ9222 
sl@0
   243
	REQ9223 
sl@0
   244
	REQ9236 
sl@0
   245
	REQ9237
sl@0
   246
sl@0
   247
@SYMTestCaseDesc
sl@0
   248
	Use case - Two contexts and two targets, but there is no sharing
sl@0
   249
sl@0
   250
@SYMTestActions		
sl@0
   251
	Two contexts are created and activated on two different targets. There is no sharing between the contexts and targets, they
sl@0
   252
	are completely isolated.
sl@0
   253
	Then some draw operations are done. 
sl@0
   254
sl@0
   255
@SYMTestExpectedResults
sl@0
   256
	It should be able to draw using the correct context and target.
sl@0
   257
	
sl@0
   258
@SYMTestStatus 		
sl@0
   259
	Implemented
sl@0
   260
*/
sl@0
   261
void CTDirectGdiContext::TwoContextsTwoTargets_WithoutSharingL()
sl@0
   262
	{	
sl@0
   263
	TBuf<KTestCaseLength> testCaseNameA;
sl@0
   264
	TBuf<KTestCaseLength> testCaseNameB;
sl@0
   265
	_LIT(KTestCase, "Context-TwoContextsTwoTargets_NotSharing");
sl@0
   266
	testCaseNameA.Append(KTestCase);
sl@0
   267
	testCaseNameB.Append(KTestCase);
sl@0
   268
	if(iCaseNum == ETwoContextsTwoTargets_WithoutSharing_SamePixelType)
sl@0
   269
		{
sl@0
   270
		testCaseNameA.Append(KSamePixelType);
sl@0
   271
		testCaseNameB.Append(KSamePixelType);
sl@0
   272
		}
sl@0
   273
	else
sl@0
   274
		{
sl@0
   275
		testCaseNameA.Append(KDifferentPixelType);
sl@0
   276
		testCaseNameB.Append(KDifferentPixelType);
sl@0
   277
		}
sl@0
   278
	testCaseNameA.Append(KTarget1);
sl@0
   279
	testCaseNameB.Append(KTarget2);
sl@0
   280
	
sl@0
   281
	if(!iRunningOomTests)
sl@0
   282
		{
sl@0
   283
		INFO_PRINTF1(KTestCase);
sl@0
   284
		}
sl@0
   285
	iGdiTarget->Activate(iGc);
sl@0
   286
	ResetGc();
sl@0
   287
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   288
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   289
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   290
	TESTNOERROR(iGc->GetError());
sl@0
   291
sl@0
   292
	iGdiTarget2->Activate(iGc2);
sl@0
   293
	iGc2->Reset();
sl@0
   294
	iGc2->Clear();
sl@0
   295
	iGc2->SetPenColor(TRgb(0, 255, 0));
sl@0
   296
	TEST(iGc2->PenColor() == TRgb(0, 255, 0));
sl@0
   297
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   298
	TESTNOERROR(iGc2->GetError());	
sl@0
   299
	
sl@0
   300
	// Draw to both again twice to make sure that context switching works.
sl@0
   301
	iGc->DrawEllipse(TRect(0,0,60,60));
sl@0
   302
	TESTNOERROR(iGc->GetError());
sl@0
   303
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   304
	TESTNOERROR(iGc2->GetError());
sl@0
   305
	
sl@0
   306
	iGc->DrawEllipse(TRect(0,0,60,60));
sl@0
   307
	TESTNOERROR(iGc->GetError());
sl@0
   308
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   309
	TESTNOERROR(iGc2->GetError());
sl@0
   310
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));
sl@0
   311
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
sl@0
   312
	}
sl@0
   313
sl@0
   314
/**
sl@0
   315
@SYMTestCaseID		
sl@0
   316
	GRAPHICS-DIRECTGDI-CONTEXT-0005
sl@0
   317
sl@0
   318
@SYMTestPriority
sl@0
   319
	Critical
sl@0
   320
sl@0
   321
@SYMPREQ
sl@0
   322
	PREQ39
sl@0
   323
sl@0
   324
@SYMREQ
sl@0
   325
	REQ9195
sl@0
   326
	REQ9201 
sl@0
   327
	REQ9202 
sl@0
   328
	REQ9222 
sl@0
   329
	REQ9223 
sl@0
   330
	REQ9236 
sl@0
   331
	REQ9237
sl@0
   332
sl@0
   333
@SYMTestCaseDesc
sl@0
   334
	Use case - Draw using two contexts and two targets, swapping the targets over half way through the test.
sl@0
   335
sl@0
   336
@SYMTestActions
sl@0
   337
	Test that a context can draw to a target that has been previously drawn to using a different context.		
sl@0
   338
	Two contexts are created and activated on two different targets. Then some draw operations are done, 
sl@0
   339
	a red circle is drawn on the first target and a black circle is drawn on the second target.
sl@0
   340
	Then these contexts are activated on the opposite targets. There is sharing between the contexts 
sl@0
   341
	and targets (contexts are activated on each other's targets).
sl@0
   342
	Then again some draw operations are done, the targets are cleared and a red circle is drawn on each target.
sl@0
   343
 
sl@0
   344
sl@0
   345
@SYMTestExpectedResults
sl@0
   346
	It should be able to draw using the correct context and target and context should be able to switch between 
sl@0
   347
	the targets. 
sl@0
   348
	The target 1 drawn to with context 1 should show a red circle, 
sl@0
   349
	target 2 drawn to with context2 should show a black circle, 
sl@0
   350
	target 1 drawn to with context 2 should show a red circle,
sl@0
   351
	target 2 drawn to with context 1 should show a red circle. 
sl@0
   352
	
sl@0
   353
@SYMTestStatus 		
sl@0
   354
	Implemented
sl@0
   355
*/
sl@0
   356
void CTDirectGdiContext::TwoContextsTwoTargets_WithSharingL()
sl@0
   357
	{	
sl@0
   358
	TBuf<KTestCaseLength> testCaseNameA;
sl@0
   359
	TBuf<KTestCaseLength> testCaseNameB;
sl@0
   360
	TBuf<KTestCaseLength> testCaseNameAB;
sl@0
   361
	TBuf<KTestCaseLength> testCaseNameBA;
sl@0
   362
sl@0
   363
	_LIT(KTestCase, "Context-TwoContextsTwoTargets_Sharing");
sl@0
   364
	testCaseNameA.Append(KTestCase);
sl@0
   365
	testCaseNameB.Append(KTestCase);
sl@0
   366
	testCaseNameAB.Append(KTestCase);
sl@0
   367
	testCaseNameBA.Append(KTestCase);
sl@0
   368
sl@0
   369
	if(iCaseNum == ETwoContextsTwoTargets_WithSharing_SamePixelType)
sl@0
   370
		{
sl@0
   371
		testCaseNameA.Append(KSamePixelType);
sl@0
   372
		testCaseNameB.Append(KSamePixelType);
sl@0
   373
		testCaseNameAB.Append(KSamePixelType);
sl@0
   374
		testCaseNameBA.Append(KSamePixelType);
sl@0
   375
		}
sl@0
   376
	else
sl@0
   377
		{
sl@0
   378
		testCaseNameA.Append(KDifferentPixelType);
sl@0
   379
		testCaseNameB.Append(KDifferentPixelType);
sl@0
   380
		testCaseNameAB.Append(KDifferentPixelType);
sl@0
   381
		testCaseNameBA.Append(KDifferentPixelType);
sl@0
   382
		}
sl@0
   383
	testCaseNameA.Append(KContext1);
sl@0
   384
	testCaseNameA.Append(KTarget1);
sl@0
   385
	testCaseNameB.Append(KContext2);
sl@0
   386
	testCaseNameB.Append(KTarget2);
sl@0
   387
	testCaseNameAB.Append(KContext1);
sl@0
   388
	testCaseNameAB.Append(KTarget2);
sl@0
   389
	testCaseNameBA.Append(KContext2);
sl@0
   390
	testCaseNameBA.Append(KTarget1);
sl@0
   391
	
sl@0
   392
	if(!iRunningOomTests)
sl@0
   393
		{
sl@0
   394
		INFO_PRINTF1(KTestCase);
sl@0
   395
		}
sl@0
   396
	iGdiTarget->Activate(iGc);
sl@0
   397
	ResetGc();
sl@0
   398
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   399
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   400
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   401
	TESTNOERROR(iGc->GetError());
sl@0
   402
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
sl@0
   403
	
sl@0
   404
	iGdiTarget2->Activate(iGc2);
sl@0
   405
	iGc2->Reset();
sl@0
   406
	iGc2->Clear();
sl@0
   407
	iGc2->SetPenColor(TRgb(0, 0, 0));
sl@0
   408
	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
sl@0
   409
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   410
	TESTNOERROR(iGc2->GetError());	
sl@0
   411
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB),iGdiTarget2));
sl@0
   412
	
sl@0
   413
	iGdiTarget->Activate(iGc2);
sl@0
   414
	iGdiTarget2->Activate(iGc);
sl@0
   415
sl@0
   416
	ResetGc();
sl@0
   417
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   418
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   419
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   420
	TESTNOERROR(iGc->GetError());
sl@0
   421
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameAB),iGdiTarget2));
sl@0
   422
	
sl@0
   423
	iGc2->Reset();
sl@0
   424
	iGc2->Clear();
sl@0
   425
	iGc2->SetPenColor(TRgb(255, 0, 0));
sl@0
   426
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   427
	iGc2->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   428
	TESTNOERROR(iGc2->GetError());
sl@0
   429
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameBA)));	
sl@0
   430
	}
sl@0
   431
sl@0
   432
/**
sl@0
   433
@SYMTestCaseID		
sl@0
   434
	GRAPHICS-DIRECTGDI-CONTEXT-0006
sl@0
   435
sl@0
   436
@SYMTestPriority
sl@0
   437
	Critical
sl@0
   438
sl@0
   439
@SYMPREQ
sl@0
   440
	PREQ39
sl@0
   441
sl@0
   442
@SYMREQ
sl@0
   443
	REQ9195
sl@0
   444
	REQ9201 
sl@0
   445
	REQ9202 
sl@0
   446
	REQ9222 
sl@0
   447
	REQ9223 
sl@0
   448
	REQ9236 
sl@0
   449
	REQ9237
sl@0
   450
sl@0
   451
@SYMTestCaseDesc
sl@0
   452
	Use case - Single context and single target, but calling activate twice.
sl@0
   453
sl@0
   454
@SYMTestActions		
sl@0
   455
	Single context is created and activated twice on the same target, just to prove that there is no affect of calling
sl@0
   456
	Activate() twice on the same target by the same context, in succession.
sl@0
   457
sl@0
   458
@SYMTestExpectedResults
sl@0
   459
	It should be able to draw using the correct context and target.
sl@0
   460
	
sl@0
   461
@SYMTestStatus 		
sl@0
   462
	Implemented
sl@0
   463
*/
sl@0
   464
void CTDirectGdiContext::OneContextOneTarget_TwiceActivateL()
sl@0
   465
	{	
sl@0
   466
	_LIT(KTestName, "Context-OneContextOneTargetTwiceActivate");
sl@0
   467
	if(!iRunningOomTests)
sl@0
   468
		{
sl@0
   469
		INFO_PRINTF1(KTestName);
sl@0
   470
		}
sl@0
   471
	_LIT(KTestNameA, "Context-OneContextOneTarget_TwiceActivateA"); 
sl@0
   472
	_LIT(KTestNameB, "Context-OneContextOneTarget_TwiceActivateB"); 
sl@0
   473
	ResetGc();
sl@0
   474
	iGc->SetPenColor(TRgb(255, 0, 0));
sl@0
   475
	TEST(iGc->PenColor() == TRgb(255, 0, 0));
sl@0
   476
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   477
	TESTNOERROR(iGc->GetError());
sl@0
   478
	TEST(KErrNone == WriteTargetOutput(iTestParams, TPtrC(KTestNameA)));	
sl@0
   479
	
sl@0
   480
	iGdiTarget->Activate(iGc);
sl@0
   481
	
sl@0
   482
	ResetGc();
sl@0
   483
	iGc->SetPenColor(TRgb(0, 0, 255));
sl@0
   484
	TEST(iGc->PenColor() == TRgb(0, 0, 255));
sl@0
   485
	iGc->DrawEllipse(TRect(0, 0, 60, 60));
sl@0
   486
	TESTNOERROR(iGc->GetError());
sl@0
   487
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestNameB)));
sl@0
   488
	}
sl@0
   489
sl@0
   490
LOCAL_C void ContextReset(TAny* aPtr)
sl@0
   491
	{
sl@0
   492
	CTContextBase* gc = reinterpret_cast <CTContextBase*> (aPtr);
sl@0
   493
	gc->Reset();
sl@0
   494
	}
sl@0
   495
sl@0
   496
/**
sl@0
   497
@SYMTestCaseID
sl@0
   498
	GRAPHICS-DIRECTGDI-CONTEXT-0007
sl@0
   499
sl@0
   500
@SYMTestPriority
sl@0
   501
	Critical
sl@0
   502
sl@0
   503
@SYMPREQ
sl@0
   504
	PREQ39
sl@0
   505
sl@0
   506
@SYMREQ
sl@0
   507
	REQ9195 
sl@0
   508
	REQ9201 
sl@0
   509
	REQ9202 
sl@0
   510
	REQ9222 
sl@0
   511
	REQ9223 
sl@0
   512
	REQ9236 
sl@0
   513
	REQ9237
sl@0
   514
sl@0
   515
@SYMTestStatus
sl@0
   516
	Complete
sl@0
   517
sl@0
   518
@SYMTestCaseDesc
sl@0
   519
	Externalize and internalize a context.
sl@0
   520
sl@0
   521
@SYMTestActions
sl@0
   522
	Test the use case where we:
sl@0
   523
	Create a new GC for the purpose of the test.
sl@0
   524
	Set Pen and Brush colour non-default colours.
sl@0
   525
	Set the Pen and Brush styles to non-default styles.
sl@0
   526
	Set the clipping regions.
sl@0
   527
	Set a font (DirectGdi only, BitGdi causes the font to be cached and UHEAP failures occur).
sl@0
   528
	Set the origin and the internal drawing position to non-defaults.
sl@0
   529
	Externalise.
sl@0
   530
	Reset the context, and set the state to other values.
sl@0
   531
	Internalise.
sl@0
   532
	Draw a line from the current internal drawing position.
sl@0
   533
	Draw a rectangle using current pen and brush styles/colours/size.
sl@0
   534
	Destroy the temporary GC and reinstate the original.
sl@0
   535
sl@0
   536
@SYMTestStatus 
sl@0
   537
	Implemented
sl@0
   538
 */
sl@0
   539
void CTDirectGdiContext::ExternalizeInternalizeTestL()
sl@0
   540
	{
sl@0
   541
	__UHEAP_MARK;
sl@0
   542
	_LIT(KTestName, "Context-ExternalizeInternalize"); 	
sl@0
   543
	if(!iRunningOomTests)
sl@0
   544
		{
sl@0
   545
		INFO_PRINTF1(KTestName);
sl@0
   546
		}
sl@0
   547
	const TInt width = iGdiTarget->SizeInPixels().iWidth;
sl@0
   548
	const TInt height = iGdiTarget->SizeInPixels().iHeight;
sl@0
   549
sl@0
   550
	// For this test, create a temporary GC which we can delete later.
sl@0
   551
	// This is to avoid UHEAP mismatches if we used the original iGc.
sl@0
   552
	// Set this to be iGc for this test.	
sl@0
   553
	CTContextBase *oldGc = iGc;
sl@0
   554
	iGc = NULL;
sl@0
   555
	CleanupStack::PushL(oldGc);
sl@0
   556
	TESTNOERRORL(iGdiTarget->CreateContext(iGc));
sl@0
   557
	ResetGc();
sl@0
   558
sl@0
   559
	// Create some clipping regions. These should not be externalised/internalised.
sl@0
   560
	RRegion clippingRegion(2);
sl@0
   561
	clippingRegion.AddRect(TRect(width*3/10,0,width*7/10,height));
sl@0
   562
	clippingRegion.AddRect(TRect(0,height*3/10,width,height*7/10));
sl@0
   563
	CleanupClosePushL(clippingRegion);
sl@0
   564
	iGc->SetClippingRegion(clippingRegion);
sl@0
   565
	CleanupStack::PushL(TCleanupItem(ContextReset, iGc));
sl@0
   566
sl@0
   567
	// Create a bitmap to use as a brush pattern
sl@0
   568
	CFbsBitmap* pattern = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, TSize(100,100));
sl@0
   569
	CleanupStack::PushL(pattern);
sl@0
   570
sl@0
   571
	// Set non-default state.
sl@0
   572
	iGc->SetOrigin(TPoint(10,10));
sl@0
   573
	iGc->SetPenSize(TSize(3,3));
sl@0
   574
	iGc->SetPenColor(TRgb(255,0,255));
sl@0
   575
	iGc->SetPenStyle(DirectGdi::EDashedPen);
sl@0
   576
	iGc->SetBrushColor(TRgb(0,255,0));
sl@0
   577
	iGc->SetBrushPattern(*pattern);
sl@0
   578
	iGc->SetBrushStyle(DirectGdi::EPatternedBrush);
sl@0
   579
	iGc->SetBrushOrigin(TPoint(3, 3));
sl@0
   580
	iGc->MoveTo(TPoint(10, height/2));
sl@0
   581
	iGc->SetDrawMode(DirectGdi::EDrawModePEN);
sl@0
   582
sl@0
   583
	if (iUseDirectGdi)
sl@0
   584
		{
sl@0
   585
		// Internalizing/externalizing a font in BitGdi will cause the font to be cached and 
sl@0
   586
		// memory UHEAP mismatch occurs, so only do it for DirectGdi. We wont draw any text in the image.
sl@0
   587
		TESTL(iFont != NULL);
sl@0
   588
		iGc->SetFont(iFont);
sl@0
   589
		}
sl@0
   590
sl@0
   591
	// create buffer for save/restore
sl@0
   592
	CBufFlat* buf = NULL;
sl@0
   593
	TRAPD(err, buf=CBufFlat::NewL(512));
sl@0
   594
	if(KErrNone != err)
sl@0
   595
		{
sl@0
   596
		iGc->ResetClippingRegion();
sl@0
   597
		User::LeaveIfError(err);
sl@0
   598
		}
sl@0
   599
	CleanupStack::PushL(buf);
sl@0
   600
sl@0
   601
	// save and then restore
sl@0
   602
	RBufWriteStream ws(*buf,0);
sl@0
   603
	iGc->ExternalizeL(ws);
sl@0
   604
	ws.Close();
sl@0
   605
sl@0
   606
	// Make some modifications to iGc.
sl@0
   607
	// The clipping regions should be persistant even after the Internalize().
sl@0
   608
	iGc->Reset();
sl@0
   609
	iGc->ResetClippingRegion();
sl@0
   610
	iGc->ResetFont();
sl@0
   611
	iGc->SetPenColor(TRgb(0,0,0));
sl@0
   612
	RRegion tempClippingRegion(1);
sl@0
   613
	tempClippingRegion.AddRect(TRect(width/10, height/10, width*9/10, height*9/10));
sl@0
   614
	iGc->SetClippingRegion(tempClippingRegion);	
sl@0
   615
	CleanupClosePushL(tempClippingRegion);
sl@0
   616
sl@0
   617
	// Internalise the state.
sl@0
   618
	RBufReadStream rs(*buf,0);
sl@0
   619
	iGc->InternalizeL(rs);
sl@0
   620
	rs.Close();
sl@0
   621
sl@0
   622
	// Draw using the newly internalised context.
sl@0
   623
	// We don't draw any text as we don't internalize/externalize text for BitGdi.
sl@0
   624
	iGc->Clear();
sl@0
   625
	iGc->DrawRect(TRect(width/4, height/4, width*3/4, height*3/4));
sl@0
   626
	iGc->DrawLineTo(TPoint(width, height/2));
sl@0
   627
	TESTNOERROR(iGc->GetError());
sl@0
   628
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName)));
sl@0
   629
sl@0
   630
	CleanupStack::PopAndDestroy(5);
sl@0
   631
	CleanupStack::Pop(1, oldGc);
sl@0
   632
sl@0
   633
	// Destroy the temporary Gc and reinstate the original one.
sl@0
   634
	iGdiTarget->Activate(oldGc);
sl@0
   635
	delete iGc;
sl@0
   636
	iGc = oldGc;
sl@0
   637
	__UHEAP_MARKEND;
sl@0
   638
	}
sl@0
   639
sl@0
   640
/**
sl@0
   641
@SYMTestCaseID		
sl@0
   642
	GRAPHICS-DIRECTGDI-CONTEXT-0008
sl@0
   643
sl@0
   644
@SYMTestPriority
sl@0
   645
	Critical
sl@0
   646
sl@0
   647
@SYMPREQ
sl@0
   648
	PREQ39
sl@0
   649
sl@0
   650
@SYMREQ
sl@0
   651
	REQ9195
sl@0
   652
	REQ9201 
sl@0
   653
	REQ9202 
sl@0
   654
	REQ9222 
sl@0
   655
	REQ9223 
sl@0
   656
	REQ9236 
sl@0
   657
	REQ9237
sl@0
   658
sl@0
   659
@SYMTestCaseDesc
sl@0
   660
	Use case - two contexts and one target. 
sl@0
   661
  
sl@0
   662
@SYMTestActions		
sl@0
   663
	Two contexts are created and activated on the same target.
sl@0
   664
	Then some draw operations are done. 
sl@0
   665
	CopySettings() is called to copy settings from first context to the second one.
sl@0
   666
	Then again some draw operations are done to verify that settings have been copied properly.
sl@0
   667
sl@0
   668
@SYMTestExpectedResults
sl@0
   669
	It should be able to draw using the correct settings of context and target.
sl@0
   670
	
sl@0
   671
@SYMTestStatus 		
sl@0
   672
	Implemented
sl@0
   673
*/
sl@0
   674
void CTDirectGdiContext::TestCopySettings()
sl@0
   675
	{	
sl@0
   676
	TBuf<KTestCaseLength> testCaseNameA;
sl@0
   677
	TBuf<KTestCaseLength> testCaseNameB;
sl@0
   678
	_LIT(KTestCase, "Context-CopySettings");
sl@0
   679
	if(!iRunningOomTests)
sl@0
   680
		{
sl@0
   681
		INFO_PRINTF1(KTestCase);
sl@0
   682
		}
sl@0
   683
	testCaseNameA.Append(KTestCase);
sl@0
   684
	testCaseNameB.Append(KTestCase);
sl@0
   685
	testCaseNameA.Append(KContext1);
sl@0
   686
	testCaseNameB.Append(KContext2);	
sl@0
   687
sl@0
   688
	// Draw to the first graphics context
sl@0
   689
	iGdiTarget->Activate(iGc);
sl@0
   690
	ResetGc();		
sl@0
   691
	iGc->SetPenColor(KRgbRed);
sl@0
   692
	iGc->SetPenSize(TSize(3,3));
sl@0
   693
	iGc->SetBrushColor(KRgbYellow);
sl@0
   694
	iGc->SetBrushStyle(DirectGdi::ESolidBrush);
sl@0
   695
	iGc->SetTextShadowColor(KRgbGreen);
sl@0
   696
	TEST(iGc->PenColor() == KRgbRed);
sl@0
   697
	
sl@0
   698
	// Do some drawing
sl@0
   699
	iGc->DrawEllipse(TRect(5, 5, 50, 50));	
sl@0
   700
	iGc->SetFont(iFont);	
sl@0
   701
	iGc->SetStrikethroughStyle(DirectGdi::EStrikethroughOn);
sl@0
   702
	iGc->SetCharJustification(10, 10);
sl@0
   703
	iGc->SetWordJustification(20, 20);
sl@0
   704
	iGc->DrawText(KAbcd, NULL, TPoint(10, 100));
sl@0
   705
	TESTNOERROR(iGc->GetError());
sl@0
   706
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameA)));	
sl@0
   707
		
sl@0
   708
	// Activate the second context and reset the context settings
sl@0
   709
	iGdiTarget->Activate(iGc2);
sl@0
   710
	iGc2->Reset();
sl@0
   711
	iGc2->Clear();
sl@0
   712
	TEST(iGc2->PenColor() == TRgb(0, 0, 0));
sl@0
   713
	// Copy the settings from the first context to the second one
sl@0
   714
	iGc2->CopySettings(*iGc);
sl@0
   715
	TEST(iGc2->PenColor() == TRgb(255, 0, 0));
sl@0
   716
	
sl@0
   717
	// Do some drawing, the ellipse is drawn deliberately smaller this time,
sl@0
   718
	// the text should look the same as before 
sl@0
   719
	iGc2->DrawEllipse(TRect(0, 0, 30, 30));
sl@0
   720
	iGc->DrawText(KAbcd, NULL, TPoint(10, 100));
sl@0
   721
	TESTNOERROR(iGc2->GetError());	
sl@0
   722
	TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(testCaseNameB)));
sl@0
   723
	
sl@0
   724
	// Test that the settings from iGc have been copied to iGc2
sl@0
   725
	TEST(iGc->PenColor() == iGc2->PenColor());
sl@0
   726
	TEST(iGc->BrushColor() == iGc2->BrushColor());
sl@0
   727
	TEST(iGc->TextShadowColor() == iGc2->TextShadowColor());
sl@0
   728
	
sl@0
   729
	iGc->ResetFont();
sl@0
   730
	iGc2->ResetFont();
sl@0
   731
	
sl@0
   732
	// Force a cleanup of the pen array when testing the SW version of DirectGdi, 
sl@0
   733
	// if this is not done the OOM tests fail when running this test.
sl@0
   734
	iGc->SetPenSize(TSize(1,1));
sl@0
   735
	iGc2->SetPenSize(TSize(1,1));
sl@0
   736
	}
sl@0
   737
sl@0
   738
/** 
sl@0
   739
Override of base class pure virtual
sl@0
   740
Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
   741
not leave. That being the case, the current test result value will be EPass.
sl@0
   742
@leave Gets system wide error code
sl@0
   743
@return TVerdict code
sl@0
   744
*/	
sl@0
   745
TVerdict CTDirectGdiContext::doTestStepL()
sl@0
   746
	{			
sl@0
   747
	// Test for each pixel format
sl@0
   748
	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
sl@0
   749
		{	
sl@0
   750
		iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
sl@0
   751
		for(iCaseNum = EOneContextOneTarget; iCaseNum < ELast; ++iCaseNum)
sl@0
   752
			{			
sl@0
   753
			SetTargetL(iTestParams.iTargetPixelFormat, static_cast<TContextTestCase>(iCaseNum));							
sl@0
   754
			
sl@0
   755
			// Create fonts outside of the OOM tests to avoid cached fonts being included
sl@0
   756
			iFont = GetFont();
sl@0
   757
			User::LeaveIfNull(iFont);					
sl@0
   758
	
sl@0
   759
			RunTestsL();
sl@0
   760
			// only run OOM tests for one target pixel format to prevent duplication of tests
sl@0
   761
			if (targetPixelFormatIndex == 0)
sl@0
   762
				{
sl@0
   763
				RunOomTestsL();  //from base class
sl@0
   764
				}		
sl@0
   765
			if(iFont)
sl@0
   766
				{
sl@0
   767
				ReleaseFont(iFont);
sl@0
   768
				iFont = NULL;
sl@0
   769
				}			
sl@0
   770
			}
sl@0
   771
		}
sl@0
   772
	CloseTMSGraphicsStep();
sl@0
   773
	return TestStepResult();
sl@0
   774
	}
sl@0
   775
sl@0
   776
/**
sl@0
   777
Override of base class virtual
sl@0
   778
@leave Gets system wide error code
sl@0
   779
@return - TVerdict code
sl@0
   780
*/
sl@0
   781
TVerdict CTDirectGdiContext::doTestStepPreambleL()
sl@0
   782
	{			
sl@0
   783
	CTDirectGdiStepBase::doTestStepPreambleL();	
sl@0
   784
	return TestStepResult();
sl@0
   785
	}
sl@0
   786
sl@0
   787
/**
sl@0
   788
Override of base class pure virtual
sl@0
   789
Lists the tests to be run
sl@0
   790
*/
sl@0
   791
void CTDirectGdiContext::RunTestsL()
sl@0
   792
	{
sl@0
   793
	SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   794
	switch(iCaseNum)
sl@0
   795
		{
sl@0
   796
		case EOneContextOneTarget:
sl@0
   797
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0001"));
sl@0
   798
			OneContextOneTarget();
sl@0
   799
			if (!iRunningOomTests)
sl@0
   800
				{
sl@0
   801
				RecordTestResultL();
sl@0
   802
				SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0007"));
sl@0
   803
				ExternalizeInternalizeTestL();
sl@0
   804
				}
sl@0
   805
			break;
sl@0
   806
		case EOneContextTwoTargets_SamePixelType:
sl@0
   807
		case EOneContextTwoTargets_DifferentPixelType:
sl@0
   808
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0002"));
sl@0
   809
			OneContextTwoTargets();
sl@0
   810
			break;
sl@0
   811
		case ETwoContextsOneTarget:
sl@0
   812
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0003"));
sl@0
   813
			TwoContextsOneTarget();			
sl@0
   814
			RecordTestResultL();
sl@0
   815
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0008"));
sl@0
   816
			TestCopySettings();			
sl@0
   817
			break;
sl@0
   818
		case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
sl@0
   819
		case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
sl@0
   820
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0004"));
sl@0
   821
			TwoContextsTwoTargets_WithoutSharingL();
sl@0
   822
			break;
sl@0
   823
		case ETwoContextsTwoTargets_WithSharing_SamePixelType:
sl@0
   824
		case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
sl@0
   825
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0005"));
sl@0
   826
			TwoContextsTwoTargets_WithSharingL();
sl@0
   827
			break;
sl@0
   828
		case EOneContextOneTarget_TwiceActivate:
sl@0
   829
			SetTestStepID(_L("GRAPHICS-DIRECTGDI-CONTEXT-0006"));
sl@0
   830
			OneContextOneTarget_TwiceActivateL();
sl@0
   831
			break;				
sl@0
   832
		}
sl@0
   833
	RecordTestResultL();
sl@0
   834
	
sl@0
   835
	}