os/graphics/windowing/windowserver/test/tauto/TBITMAP.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-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
// Test the window server bitmap class
sl@0
    15
// Test the window server bitmap class
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @test
sl@0
    22
 @internalComponent - Internal Symbian test code
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "TBITMAP.H"
sl@0
    26
sl@0
    27
//
sl@0
    28
sl@0
    29
CTBitmap::CTBitmap(CTestStep* aStep):
sl@0
    30
	CTWsGraphicsBase(aStep)
sl@0
    31
	{
sl@0
    32
	}
sl@0
    33
sl@0
    34
CTBitmap::~CTBitmap()
sl@0
    35
	{
sl@0
    36
	delete iBitmap1;
sl@0
    37
	delete iBitmap2;
sl@0
    38
	}
sl@0
    39
sl@0
    40
void CTBitmap::ConstructL()
sl@0
    41
	{
sl@0
    42
	}
sl@0
    43
sl@0
    44
void CTBitmap::BasicTestsL()
sl@0
    45
	{
sl@0
    46
	iBitmap1=new(ELeave) CWsBitmap(TheClient->iWs);
sl@0
    47
	iBitmap2=new(ELeave) CWsBitmap(TheClient->iWs);
sl@0
    48
	User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
sl@0
    49
// Re-create should close previous Create
sl@0
    50
	User::LeaveIfError(iBitmap1->Create(TSize(20,10),EGray4));
sl@0
    51
	User::LeaveIfError(iBitmap2->Duplicate(iBitmap1->Handle()));
sl@0
    52
	TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
sl@0
    53
		
sl@0
    54
	TInt err=iBitmap2->Load(_L("NOTEXIST.XXX"),0);
sl@0
    55
	TEST(err==KErrNotFound || err==KErrPathNotFound);
sl@0
    56
	if (err!=KErrNotFound && err!=KErrPathNotFound)
sl@0
    57
		INFO_PRINTF4(_L("Bitmap2->Load(_L(NOTEXIST.XXX),0) return value - Expected: %d or %d , Actual: %d"), KErrNotFound, KErrPathNotFound, err);		
sl@0
    58
	
sl@0
    59
	TInt retVal = iBitmap2->Handle();
sl@0
    60
	TEST(retVal==0);
sl@0
    61
	if (retVal!=0)
sl@0
    62
		INFO_PRINTF3(_L("iBitmap2->Handle() return value - Expected: %d , Actual: %d"), 0, retVal);		
sl@0
    63
sl@0
    64
	RFs fs;
sl@0
    65
	User::LeaveIfError(fs.Connect());
sl@0
    66
	fs.SetNotifyUser(EFalse);
sl@0
    67
	TInt ret=fs.MkDir(SAVE_BITMAP_NAME);
sl@0
    68
	if (ret!=KErrNone && ret!=KErrAlreadyExists && ret!=KErrPathNotFound)
sl@0
    69
		User::Leave(ret);
sl@0
    70
	fs.Close();
sl@0
    71
//
sl@0
    72
	retVal = iBitmap1->Save(SAVE_BITMAP_NAME);
sl@0
    73
	TEST(retVal==KErrNone);
sl@0
    74
	if (retVal!=KErrNone)
sl@0
    75
		INFO_PRINTF3(_L("iBitmap1->Save(SAVE_BITMAP_NAME) return value - Expected: %d , Actual: %d"), KErrNone, retVal);		
sl@0
    76
	
sl@0
    77
	retVal = iBitmap2->Load(SAVE_BITMAP_NAME,0);
sl@0
    78
	TEST(retVal==KErrNone);
sl@0
    79
	if (retVal!=KErrNone)
sl@0
    80
		INFO_PRINTF3(_L("iBitmap2->Load(SAVE_BITMAP_NAME,0) return value - Expected: %d , Actual: %d"), KErrNone, retVal);		
sl@0
    81
	
sl@0
    82
	TEST(iBitmap1->SizeInPixels()==iBitmap2->SizeInPixels());
sl@0
    83
	}
sl@0
    84
	
sl@0
    85
	
sl@0
    86
void CTBitmap::TestFixForPDEF098889L()
sl@0
    87
	{
sl@0
    88
	TRequestStatus status;
sl@0
    89
	TThreadParams params;
sl@0
    90
	params.iScreenNr = TheClient->iWs.GetFocusScreen();
sl@0
    91
sl@0
    92
	RThread thread1;
sl@0
    93
	params.iFunction = Function1PDEF098889L;
sl@0
    94
	TEST(thread1.Create(_L("PDEF098889_1"), ThreadFunction, 0x1000, NULL, &params)==KErrNone);
sl@0
    95
	thread1.Logon(status);
sl@0
    96
	thread1.Resume();
sl@0
    97
	User::WaitForRequest(status);
sl@0
    98
	TEST(status==KErrNone);
sl@0
    99
	TEST(thread1.ExitType()==EExitKill);
sl@0
   100
	thread1.Close();
sl@0
   101
sl@0
   102
	RThread thread2;
sl@0
   103
	params.iFunction = Function2PDEF098889L;
sl@0
   104
	TEST(thread2.Create(_L("PDEF098889_2"), ThreadFunction, 0x1000, NULL, &params)==KErrNone);
sl@0
   105
	thread2.Logon(status);
sl@0
   106
	thread2.Resume();
sl@0
   107
	User::WaitForRequest(status);
sl@0
   108
	TEST(status==KErrNone);
sl@0
   109
	TEST(thread2.ExitType()==EExitKill);
sl@0
   110
	thread2.Close();
sl@0
   111
	}
sl@0
   112
sl@0
   113
TInt CTBitmap::ThreadFunction(TAny* aParams)
sl@0
   114
	{
sl@0
   115
	CTrapCleanup *trap = CTrapCleanup::New();
sl@0
   116
	__ASSERT_ALWAYS(trap, User::Invariant());
sl@0
   117
	RWsSession session;
sl@0
   118
	TInt err = session.Connect();
sl@0
   119
	if (err == KErrNone)
sl@0
   120
		{
sl@0
   121
		CWsScreenDevice *device = new CWsScreenDevice(session);
sl@0
   122
		if (device)
sl@0
   123
			{
sl@0
   124
			err = device->Construct(static_cast<TThreadParams*>(aParams)->iScreenNr);
sl@0
   125
			if (err == KErrNone)
sl@0
   126
				{
sl@0
   127
				TRAP(err, static_cast<TThreadParams*>(aParams)->iFunction(session, *device));	
sl@0
   128
				}
sl@0
   129
			delete device;
sl@0
   130
			}
sl@0
   131
		else
sl@0
   132
			err = KErrNoMemory;
sl@0
   133
		session.Close();
sl@0
   134
		}
sl@0
   135
	delete trap;
sl@0
   136
	return err;
sl@0
   137
	}
sl@0
   138
sl@0
   139
void CTBitmap::Function1PDEF098889L(RWsSession& aSession, CWsScreenDevice& aDevice)
sl@0
   140
	{
sl@0
   141
	CWindowGc *gc;
sl@0
   142
	User::LeaveIfError(aDevice.CreateContext(gc));
sl@0
   143
	CleanupStack::PushL(gc);
sl@0
   144
	RWindowGroup group(aSession);
sl@0
   145
	User::LeaveIfError(group.Construct(1, EFalse));
sl@0
   146
	CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
sl@0
   147
	CleanupStack::PushL(bitmap);
sl@0
   148
	User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
sl@0
   149
	RWindow window(aSession);
sl@0
   150
	User::LeaveIfError(window.Construct(group, 2));
sl@0
   151
	window.SetExtent(TPoint(0,0), TSize(32, 32));
sl@0
   152
	User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
sl@0
   153
	window.Activate();
sl@0
   154
	window.BeginRedraw();
sl@0
   155
	gc->Activate(window);
sl@0
   156
	gc->BitBlt(TPoint(0, 0), bitmap);
sl@0
   157
	gc->Deactivate();
sl@0
   158
	window.EndRedraw();
sl@0
   159
	CleanupStack::PopAndDestroy(bitmap);
sl@0
   160
	aSession.Flush();
sl@0
   161
	CleanupStack::PopAndDestroy(gc);
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CTBitmap::Function2PDEF098889L(RWsSession& aSession, CWsScreenDevice& /*aDevice*/) 
sl@0
   165
	{
sl@0
   166
	RWindowGroup group(aSession);
sl@0
   167
	User::LeaveIfError(group.Construct(1, EFalse));
sl@0
   168
	CWsBitmap *bitmap = new(ELeave) CWsBitmap(aSession);
sl@0
   169
	CleanupStack::PushL(bitmap);
sl@0
   170
	User::LeaveIfError(bitmap->Create(TSize(32, 32), EGray256));
sl@0
   171
	RWindow window(aSession);
sl@0
   172
	User::LeaveIfError(window.Construct(group, 2));
sl@0
   173
	window.SetExtent(TPoint(0,0), TSize(32, 32));
sl@0
   174
	User::LeaveIfError(window.SetRequiredDisplayMode(EColor64K));
sl@0
   175
	User::LeaveIfError(window.SetTransparencyWsBitmap(*bitmap));
sl@0
   176
	window.Activate();
sl@0
   177
	CleanupStack::PopAndDestroy(bitmap);
sl@0
   178
	aSession.Flush();
sl@0
   179
	}
sl@0
   180
sl@0
   181
void CTBitmap::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0
   182
	{
sl@0
   183
	((CTBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   184
	switch(++iTest->iState)
sl@0
   185
		{
sl@0
   186
/**
sl@0
   187
@SYMTestCaseID		GRAPHICS-WSERV-0201
sl@0
   188
sl@0
   189
@SYMDEF             DEF081259
sl@0
   190
sl@0
   191
@SYMTestCaseDesc    Test basic bitmap functionality
sl@0
   192
sl@0
   193
@SYMTestPriority    High
sl@0
   194
sl@0
   195
@SYMTestStatus      Implemented
sl@0
   196
sl@0
   197
@SYMTestActions     Test that bitmaps can be loaded, copied and saved
sl@0
   198
					correctly
sl@0
   199
sl@0
   200
@SYMTestExpectedResults The bitmaps are manipulated withotu error
sl@0
   201
*/	 
sl@0
   202
		case 1:
sl@0
   203
			((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0201"));
sl@0
   204
			iTest->LogSubTest(_L("Bitmap1"));
sl@0
   205
			BasicTestsL();
sl@0
   206
			break;
sl@0
   207
		case 2:
sl@0
   208
/**
sl@0
   209
@SYMTestCaseID		GRAPHICS-WSERV-0532
sl@0
   210
*/
sl@0
   211
			((CTBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0532"));
sl@0
   212
			if (TransparencySupportedL()==KErrNotSupported)
sl@0
   213
				return;
sl@0
   214
			iTest->LogSubTest(_L("Test fix for PDEF098889"));
sl@0
   215
			TestFixForPDEF098889L();
sl@0
   216
			break; 
sl@0
   217
		default:
sl@0
   218
			((CTBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   219
			((CTBitmapStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   220
			TestComplete();
sl@0
   221
			break;
sl@0
   222
		}
sl@0
   223
	((CTBitmapStep*)iStep)->RecordTestResultL();
sl@0
   224
	}
sl@0
   225
	
sl@0
   226
__WS_CONSTRUCT_STEP__(Bitmap)