os/graphics/graphicstest/graphicstestharness/src/GraphicsTestUtilsServer.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) 2005-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
// GraphicsTestUtilsServer implementation
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @test
sl@0
    21
 @internalComponent - Internal Symbian test code 
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include <e32std.h>
sl@0
    25
sl@0
    26
#include "GraphicsTestUtilsServer.h"
sl@0
    27
#include "GraphicsTestUtils.h"
sl@0
    28
sl@0
    29
typedef TUint8 TWipeItems;
sl@0
    30
sl@0
    31
inline CShutdown::CShutdown()
sl@0
    32
	:CTimer(-1)
sl@0
    33
	{CActiveScheduler::Add(this);}
sl@0
    34
inline void CShutdown::ConstructL()
sl@0
    35
	{CTimer::ConstructL();}
sl@0
    36
inline void CShutdown::Start()
sl@0
    37
	{After(KMyShutdownDelay);}
sl@0
    38
sl@0
    39
inline CSmlTestUtilsServer::CSmlTestUtilsServer()
sl@0
    40
	:CServer2(0,ESharableSessions)
sl@0
    41
	{}
sl@0
    42
sl@0
    43
inline CSmlTestUtilsSession::CSmlTestUtilsSession()
sl@0
    44
	{}
sl@0
    45
inline CSmlTestUtilsServer& CSmlTestUtilsSession::Server()
sl@0
    46
	{return *static_cast<CSmlTestUtilsServer*>(const_cast<CServer2*>(CSession2::Server()));}
sl@0
    47
sl@0
    48
sl@0
    49
void PanicClient(const RMessage2& aMessage,TTestPanic aPanic)
sl@0
    50
//
sl@0
    51
// RMessage::Panic() also completes the message. This is:
sl@0
    52
// (a) important for efficient cleanup within the kernel
sl@0
    53
// (b) a problem if the message is completed a second time
sl@0
    54
//
sl@0
    55
	{
sl@0
    56
	_LIT(KPanic,"TestServer");
sl@0
    57
 	aMessage.Panic(KPanic,aPanic);
sl@0
    58
	}
sl@0
    59
sl@0
    60
void CSmlTestUtilsSession::CreateL()
sl@0
    61
//
sl@0
    62
// 2nd phase construct for sessions - called by the CServer framework
sl@0
    63
//
sl@0
    64
	{
sl@0
    65
	Server().AddSession();
sl@0
    66
	User::LeaveIfError(iFs.Connect());
sl@0
    67
	iFileMan = CFileMan::NewL(iFs);
sl@0
    68
	}
sl@0
    69
sl@0
    70
CSmlTestUtilsSession::~CSmlTestUtilsSession()
sl@0
    71
	{
sl@0
    72
	Server().DropSession();
sl@0
    73
	iFs.Close();
sl@0
    74
	delete iFileMan;
sl@0
    75
	}
sl@0
    76
sl@0
    77
sl@0
    78
void CSmlTestUtilsSession::ServiceL(const RMessage2& aMessage)
sl@0
    79
//
sl@0
    80
// Entry point for when a new message is received
sl@0
    81
//
sl@0
    82
	{
sl@0
    83
	TInt result = KErrNone;
sl@0
    84
sl@0
    85
	switch (aMessage.Function())
sl@0
    86
		{
sl@0
    87
	case ECreateDir:
sl@0
    88
		result = DoCreateDirectoryL(aMessage);
sl@0
    89
		break;
sl@0
    90
	case ERenameDir:
sl@0
    91
		result = DoRenameDirectoryL(aMessage);
sl@0
    92
		break;
sl@0
    93
	case EDeleteDir:
sl@0
    94
		result = DoDeleteDirectoryL(aMessage);
sl@0
    95
		break;
sl@0
    96
	case ECreateFile:
sl@0
    97
		result = DoCreateFileL(aMessage);
sl@0
    98
		break;
sl@0
    99
	case EDeleteFile:
sl@0
   100
		result = DoDeleteFileL(aMessage);
sl@0
   101
		break;
sl@0
   102
	case EDeleteFileUsingWildcard:
sl@0
   103
		result = DoDeleteFileUsingWildcardL(aMessage);
sl@0
   104
		break;
sl@0
   105
	case ECopyFile:
sl@0
   106
		result = DoCopyFileL(aMessage);
sl@0
   107
		break;
sl@0
   108
	case EReplaceFile:
sl@0
   109
		result = DoReplaceFileL(aMessage);
sl@0
   110
		break;
sl@0
   111
	case EIsFilePresent:
sl@0
   112
		result = DoIsFilePresentL(aMessage);
sl@0
   113
		break;
sl@0
   114
	case ESetReadOnly:
sl@0
   115
		result = DoSetReadOnlyL(aMessage);
sl@0
   116
		break;
sl@0
   117
	case EGetAttributes:
sl@0
   118
		result = DoGetAttL( aMessage );
sl@0
   119
		break;
sl@0
   120
	case ESetAttributes:
sl@0
   121
		result = DoSetAttL( aMessage );
sl@0
   122
		break;		
sl@0
   123
	case ECopyDirectory:
sl@0
   124
		result = DoCopyDirectoryL(aMessage);
sl@0
   125
		break;
sl@0
   126
	case EChangeFilePermission:
sl@0
   127
		result = DoChangeFilePermissionL(aMessage);
sl@0
   128
		break;	
sl@0
   129
	default:
sl@0
   130
		PanicClient(aMessage,ETestPanicIllegalFunction);
sl@0
   131
		break;
sl@0
   132
		}
sl@0
   133
	aMessage.Complete(result);
sl@0
   134
	}
sl@0
   135
sl@0
   136
TInt CSmlTestUtilsSession::DoCreateDirectoryL(const RMessage2& aMessage)
sl@0
   137
	{
sl@0
   138
	TBuf<255> path;
sl@0
   139
	aMessage.ReadL(0, path);
sl@0
   140
	TInt ret = iFs.MkDirAll(path);
sl@0
   141
	return ret;
sl@0
   142
	}
sl@0
   143
	
sl@0
   144
TInt CSmlTestUtilsSession::DoRenameDirectoryL(const RMessage2& aMessage)
sl@0
   145
	{
sl@0
   146
	TBuf<100> srcpath;
sl@0
   147
	aMessage.ReadL(0, srcpath);
sl@0
   148
	TBuf<100> destpath;
sl@0
   149
	aMessage.ReadL(1, destpath);
sl@0
   150
	TInt ret = iFs.Rename(srcpath, destpath);
sl@0
   151
	
sl@0
   152
	return ret;	
sl@0
   153
	}
sl@0
   154
	
sl@0
   155
TInt CSmlTestUtilsSession::DoDeleteDirectoryL(const RMessage2& aMessage)
sl@0
   156
	{
sl@0
   157
	TBuf<255> path;
sl@0
   158
	aMessage.ReadL(0, path);
sl@0
   159
	TInt ret = iFs.RmDir(path);
sl@0
   160
	return ret;
sl@0
   161
	}
sl@0
   162
	
sl@0
   163
TInt CSmlTestUtilsSession::DoCreateFileL(const RMessage2& aMessage)
sl@0
   164
	{
sl@0
   165
	TBuf<100> path;
sl@0
   166
	aMessage.ReadL(0, path);
sl@0
   167
	RFile file;
sl@0
   168
	CleanupClosePushL(file);
sl@0
   169
	TInt ret = file.Create(iFs, path, EFileRead);
sl@0
   170
	CleanupStack::PopAndDestroy(&file);
sl@0
   171
	return ret;
sl@0
   172
	}
sl@0
   173
	
sl@0
   174
	
sl@0
   175
TInt CSmlTestUtilsSession::DoDeleteFileL(const RMessage2& aMessage)
sl@0
   176
	{
sl@0
   177
	TBuf<100> path;
sl@0
   178
	aMessage.ReadL(0, path);
sl@0
   179
	TInt ret = iFs.Delete(path);
sl@0
   180
	return ret;	
sl@0
   181
	}
sl@0
   182
sl@0
   183
TInt CSmlTestUtilsSession::DoDeleteFileUsingWildcardL(const RMessage2& aMessage)
sl@0
   184
	{
sl@0
   185
	TBuf<100> path;
sl@0
   186
	aMessage.ReadL(0, path);
sl@0
   187
	TInt ret = iFileMan->Delete(path);
sl@0
   188
	return ret;	
sl@0
   189
	}
sl@0
   190
sl@0
   191
TInt CSmlTestUtilsSession::DoCopyFileL(const RMessage2& aMessage)
sl@0
   192
	{
sl@0
   193
	TBuf<100> srcpath;
sl@0
   194
	aMessage.ReadL(0, srcpath);
sl@0
   195
	
sl@0
   196
	TBuf<100> destpath;
sl@0
   197
	aMessage.ReadL(1, destpath);
sl@0
   198
	
sl@0
   199
	TInt ret = iFileMan->Copy(srcpath,destpath);
sl@0
   200
	return ret;	
sl@0
   201
	}
sl@0
   202
sl@0
   203
TInt CSmlTestUtilsSession::DoReplaceFileL(const RMessage2& aMessage)
sl@0
   204
	{
sl@0
   205
	TBuf<100> srcpath;
sl@0
   206
	aMessage.ReadL(0, srcpath);
sl@0
   207
	TUint lFileMode;
sl@0
   208
	TPckgBuf<TUint> temp;
sl@0
   209
	aMessage.ReadL(1, temp);
sl@0
   210
	
sl@0
   211
	lFileMode=temp();
sl@0
   212
	RFile file;
sl@0
   213
	
sl@0
   214
	TInt ret = file.Replace(iFs,srcpath,lFileMode);
sl@0
   215
	return ret;	
sl@0
   216
	}
sl@0
   217
sl@0
   218
TInt CSmlTestUtilsSession::DoIsFilePresentL(const RMessage2& aMessage)
sl@0
   219
	{
sl@0
   220
	TFileName srcpath;
sl@0
   221
	aMessage.ReadL(0, srcpath);
sl@0
   222
sl@0
   223
	TEntry entry;
sl@0
   224
	TInt err = iFs.Entry(srcpath, entry);
sl@0
   225
	if (err == KErrNotFound)
sl@0
   226
		{
sl@0
   227
		aMessage.WriteL(1,TPckgBuf<TBool>(EFalse));
sl@0
   228
		}
sl@0
   229
	else
sl@0
   230
		{
sl@0
   231
		aMessage.WriteL(1,TPckgBuf<TBool>(ETrue));
sl@0
   232
		}
sl@0
   233
sl@0
   234
	return KErrNone;
sl@0
   235
	}
sl@0
   236
sl@0
   237
TInt CSmlTestUtilsSession::DoSetReadOnlyL(const RMessage2& aMessage)
sl@0
   238
	{
sl@0
   239
	TBuf<100> srcpath;
sl@0
   240
	aMessage.ReadL(0, srcpath);
sl@0
   241
	TUint attMask;
sl@0
   242
	TPckgBuf<TUint> temp;
sl@0
   243
	aMessage.ReadL(1, temp);
sl@0
   244
	
sl@0
   245
	attMask=temp();
sl@0
   246
	TInt ret = iFs.SetAtt(srcpath,attMask,KEntryAttReadOnly);
sl@0
   247
	return ret;	
sl@0
   248
	}
sl@0
   249
	
sl@0
   250
TInt CSmlTestUtilsSession::DoGetAttL( const RMessage2& aMessage )
sl@0
   251
	{
sl@0
   252
	
sl@0
   253
	TFileName nameBuf;
sl@0
   254
	TUint attributes = 0;
sl@0
   255
	
sl@0
   256
	aMessage.ReadL( 0, nameBuf );
sl@0
   257
	
sl@0
   258
	TInt err = iFs.Att( nameBuf, attributes );	
sl@0
   259
	
sl@0
   260
	if ( KErrNone == err )
sl@0
   261
		{
sl@0
   262
		aMessage.WriteL( 1, TPckgBuf<TInt>(attributes) );
sl@0
   263
		}
sl@0
   264
	
sl@0
   265
	
sl@0
   266
	return err;
sl@0
   267
	}
sl@0
   268
sl@0
   269
sl@0
   270
TInt CSmlTestUtilsSession::DoSetAttL( const RMessage2& aMessage )
sl@0
   271
	{
sl@0
   272
	
sl@0
   273
	TFileName nameBuf;
sl@0
   274
	aMessage.ReadL( 0, nameBuf );
sl@0
   275
	
sl@0
   276
	TUint setAttMask = *(TUint*)aMessage.Ptr1();
sl@0
   277
	TUint clearAttMask = *(TUint*)aMessage.Ptr2();
sl@0
   278
	
sl@0
   279
	TInt err = iFs.SetAtt( nameBuf, setAttMask, clearAttMask );
sl@0
   280
	
sl@0
   281
	
sl@0
   282
	return err;
sl@0
   283
	}
sl@0
   284
	
sl@0
   285
void CSmlTestUtilsSession::ServiceError(const RMessage2& aMessage,TInt aError)
sl@0
   286
//
sl@0
   287
// Handle an error from CMySession::ServiceL()
sl@0
   288
// A bad descriptor error implies a badly programmed client, so panic it;
sl@0
   289
// otherwise use the default handling (report the error to the client)
sl@0
   290
//
sl@0
   291
	{
sl@0
   292
	if (aError==KErrBadDescriptor)
sl@0
   293
		PanicClient(aMessage,ETestPanicBadDescriptor);
sl@0
   294
	CSession2::ServiceError(aMessage,aError);
sl@0
   295
	}
sl@0
   296
sl@0
   297
sl@0
   298
TInt CSmlTestUtilsSession::DoCopyDirectoryL(const RMessage2& aMessage)
sl@0
   299
	{
sl@0
   300
	TBuf<100> source;
sl@0
   301
	aMessage.ReadL(0, source);
sl@0
   302
	
sl@0
   303
	TBuf<100> target;
sl@0
   304
	aMessage.ReadL(1, target);
sl@0
   305
	
sl@0
   306
	TInt ret = iFileMan->Copy(source,target, CFileMan::ERecurse);
sl@0
   307
	return ret;		
sl@0
   308
	}
sl@0
   309
sl@0
   310
sl@0
   311
void CShutdown::RunL()
sl@0
   312
//
sl@0
   313
// Initiate server exit when the timer expires
sl@0
   314
//
sl@0
   315
	{
sl@0
   316
	CActiveScheduler::Stop();
sl@0
   317
	}
sl@0
   318
sl@0
   319
CServer2* CSmlTestUtilsServer::NewLC()
sl@0
   320
	{
sl@0
   321
	CSmlTestUtilsServer* self=new(ELeave) CSmlTestUtilsServer;
sl@0
   322
	CleanupStack::PushL(self);
sl@0
   323
	self->ConstructL();
sl@0
   324
	return self;
sl@0
   325
	}
sl@0
   326
sl@0
   327
void CSmlTestUtilsServer::ConstructL()
sl@0
   328
//
sl@0
   329
// 2nd phase construction - ensure the timer and server objects are running
sl@0
   330
//
sl@0
   331
	{
sl@0
   332
	StartL(KTestServerName);
sl@0
   333
	iShutdown.ConstructL();
sl@0
   334
	// ensure that the server still exits even if the 1st client fails to connect
sl@0
   335
	iShutdown.Start();
sl@0
   336
	}
sl@0
   337
sl@0
   338
sl@0
   339
CSession2* CSmlTestUtilsServer::NewSessionL(const TVersion&,const RMessage2&) const
sl@0
   340
//
sl@0
   341
// Cretae a new client session. This should really check the version number.
sl@0
   342
//
sl@0
   343
	{
sl@0
   344
	return new(ELeave) CSmlTestUtilsSession();
sl@0
   345
	}
sl@0
   346
sl@0
   347
void CSmlTestUtilsServer::AddSession()
sl@0
   348
//
sl@0
   349
// A new session is being created
sl@0
   350
// Cancel the shutdown timer if it was running
sl@0
   351
//
sl@0
   352
	{
sl@0
   353
	++iSessionCount;
sl@0
   354
	iShutdown.Cancel();
sl@0
   355
	}
sl@0
   356
sl@0
   357
void CSmlTestUtilsServer::DropSession()
sl@0
   358
//
sl@0
   359
// A session is being destroyed
sl@0
   360
// Start the shutdown timer if it is the last session.
sl@0
   361
//
sl@0
   362
	{
sl@0
   363
	if (--iSessionCount==0)
sl@0
   364
		iShutdown.Start();
sl@0
   365
	}
sl@0
   366
	
sl@0
   367
sl@0
   368
sl@0
   369
sl@0
   370
sl@0
   371
sl@0
   372
//Given the name of a read-only file, this functions clears the read-only attribute on the file
sl@0
   373
TInt CSmlTestUtilsSession::DoChangeFilePermissionL(const RMessage2& aMessage)
sl@0
   374
	{
sl@0
   375
	TInt ret(0);
sl@0
   376
	TRequestStatus status;
sl@0
   377
	TTime time(0); 
sl@0
   378
	CFileMan* fileman = CFileMan::NewL (iFs);
sl@0
   379
	CleanupStack::PushL(fileman);
sl@0
   380
	TBuf<100> path;
sl@0
   381
	aMessage.ReadL(0, path);
sl@0
   382
	ret = fileman->Attribs(path,KEntryAttNormal,KEntryAttReadOnly, time,0,status);
sl@0
   383
	User::WaitForRequest(status);
sl@0
   384
	ret = status.Int(); 
sl@0
   385
	CleanupStack::PopAndDestroy(); 
sl@0
   386
	return ret;	
sl@0
   387
	}