os/graphics/graphicstest/graphicstestharness/src/GraphicsTestUtilsServer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/graphicstestharness/src/GraphicsTestUtilsServer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,387 @@
     1.4 +// Copyright (c) 2005-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 +// GraphicsTestUtilsServer implementation
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code 
    1.25 +*/
    1.26 +
    1.27 +#include <e32std.h>
    1.28 +
    1.29 +#include "GraphicsTestUtilsServer.h"
    1.30 +#include "GraphicsTestUtils.h"
    1.31 +
    1.32 +typedef TUint8 TWipeItems;
    1.33 +
    1.34 +inline CShutdown::CShutdown()
    1.35 +	:CTimer(-1)
    1.36 +	{CActiveScheduler::Add(this);}
    1.37 +inline void CShutdown::ConstructL()
    1.38 +	{CTimer::ConstructL();}
    1.39 +inline void CShutdown::Start()
    1.40 +	{After(KMyShutdownDelay);}
    1.41 +
    1.42 +inline CSmlTestUtilsServer::CSmlTestUtilsServer()
    1.43 +	:CServer2(0,ESharableSessions)
    1.44 +	{}
    1.45 +
    1.46 +inline CSmlTestUtilsSession::CSmlTestUtilsSession()
    1.47 +	{}
    1.48 +inline CSmlTestUtilsServer& CSmlTestUtilsSession::Server()
    1.49 +	{return *static_cast<CSmlTestUtilsServer*>(const_cast<CServer2*>(CSession2::Server()));}
    1.50 +
    1.51 +
    1.52 +void PanicClient(const RMessage2& aMessage,TTestPanic aPanic)
    1.53 +//
    1.54 +// RMessage::Panic() also completes the message. This is:
    1.55 +// (a) important for efficient cleanup within the kernel
    1.56 +// (b) a problem if the message is completed a second time
    1.57 +//
    1.58 +	{
    1.59 +	_LIT(KPanic,"TestServer");
    1.60 + 	aMessage.Panic(KPanic,aPanic);
    1.61 +	}
    1.62 +
    1.63 +void CSmlTestUtilsSession::CreateL()
    1.64 +//
    1.65 +// 2nd phase construct for sessions - called by the CServer framework
    1.66 +//
    1.67 +	{
    1.68 +	Server().AddSession();
    1.69 +	User::LeaveIfError(iFs.Connect());
    1.70 +	iFileMan = CFileMan::NewL(iFs);
    1.71 +	}
    1.72 +
    1.73 +CSmlTestUtilsSession::~CSmlTestUtilsSession()
    1.74 +	{
    1.75 +	Server().DropSession();
    1.76 +	iFs.Close();
    1.77 +	delete iFileMan;
    1.78 +	}
    1.79 +
    1.80 +
    1.81 +void CSmlTestUtilsSession::ServiceL(const RMessage2& aMessage)
    1.82 +//
    1.83 +// Entry point for when a new message is received
    1.84 +//
    1.85 +	{
    1.86 +	TInt result = KErrNone;
    1.87 +
    1.88 +	switch (aMessage.Function())
    1.89 +		{
    1.90 +	case ECreateDir:
    1.91 +		result = DoCreateDirectoryL(aMessage);
    1.92 +		break;
    1.93 +	case ERenameDir:
    1.94 +		result = DoRenameDirectoryL(aMessage);
    1.95 +		break;
    1.96 +	case EDeleteDir:
    1.97 +		result = DoDeleteDirectoryL(aMessage);
    1.98 +		break;
    1.99 +	case ECreateFile:
   1.100 +		result = DoCreateFileL(aMessage);
   1.101 +		break;
   1.102 +	case EDeleteFile:
   1.103 +		result = DoDeleteFileL(aMessage);
   1.104 +		break;
   1.105 +	case EDeleteFileUsingWildcard:
   1.106 +		result = DoDeleteFileUsingWildcardL(aMessage);
   1.107 +		break;
   1.108 +	case ECopyFile:
   1.109 +		result = DoCopyFileL(aMessage);
   1.110 +		break;
   1.111 +	case EReplaceFile:
   1.112 +		result = DoReplaceFileL(aMessage);
   1.113 +		break;
   1.114 +	case EIsFilePresent:
   1.115 +		result = DoIsFilePresentL(aMessage);
   1.116 +		break;
   1.117 +	case ESetReadOnly:
   1.118 +		result = DoSetReadOnlyL(aMessage);
   1.119 +		break;
   1.120 +	case EGetAttributes:
   1.121 +		result = DoGetAttL( aMessage );
   1.122 +		break;
   1.123 +	case ESetAttributes:
   1.124 +		result = DoSetAttL( aMessage );
   1.125 +		break;		
   1.126 +	case ECopyDirectory:
   1.127 +		result = DoCopyDirectoryL(aMessage);
   1.128 +		break;
   1.129 +	case EChangeFilePermission:
   1.130 +		result = DoChangeFilePermissionL(aMessage);
   1.131 +		break;	
   1.132 +	default:
   1.133 +		PanicClient(aMessage,ETestPanicIllegalFunction);
   1.134 +		break;
   1.135 +		}
   1.136 +	aMessage.Complete(result);
   1.137 +	}
   1.138 +
   1.139 +TInt CSmlTestUtilsSession::DoCreateDirectoryL(const RMessage2& aMessage)
   1.140 +	{
   1.141 +	TBuf<255> path;
   1.142 +	aMessage.ReadL(0, path);
   1.143 +	TInt ret = iFs.MkDirAll(path);
   1.144 +	return ret;
   1.145 +	}
   1.146 +	
   1.147 +TInt CSmlTestUtilsSession::DoRenameDirectoryL(const RMessage2& aMessage)
   1.148 +	{
   1.149 +	TBuf<100> srcpath;
   1.150 +	aMessage.ReadL(0, srcpath);
   1.151 +	TBuf<100> destpath;
   1.152 +	aMessage.ReadL(1, destpath);
   1.153 +	TInt ret = iFs.Rename(srcpath, destpath);
   1.154 +	
   1.155 +	return ret;	
   1.156 +	}
   1.157 +	
   1.158 +TInt CSmlTestUtilsSession::DoDeleteDirectoryL(const RMessage2& aMessage)
   1.159 +	{
   1.160 +	TBuf<255> path;
   1.161 +	aMessage.ReadL(0, path);
   1.162 +	TInt ret = iFs.RmDir(path);
   1.163 +	return ret;
   1.164 +	}
   1.165 +	
   1.166 +TInt CSmlTestUtilsSession::DoCreateFileL(const RMessage2& aMessage)
   1.167 +	{
   1.168 +	TBuf<100> path;
   1.169 +	aMessage.ReadL(0, path);
   1.170 +	RFile file;
   1.171 +	CleanupClosePushL(file);
   1.172 +	TInt ret = file.Create(iFs, path, EFileRead);
   1.173 +	CleanupStack::PopAndDestroy(&file);
   1.174 +	return ret;
   1.175 +	}
   1.176 +	
   1.177 +	
   1.178 +TInt CSmlTestUtilsSession::DoDeleteFileL(const RMessage2& aMessage)
   1.179 +	{
   1.180 +	TBuf<100> path;
   1.181 +	aMessage.ReadL(0, path);
   1.182 +	TInt ret = iFs.Delete(path);
   1.183 +	return ret;	
   1.184 +	}
   1.185 +
   1.186 +TInt CSmlTestUtilsSession::DoDeleteFileUsingWildcardL(const RMessage2& aMessage)
   1.187 +	{
   1.188 +	TBuf<100> path;
   1.189 +	aMessage.ReadL(0, path);
   1.190 +	TInt ret = iFileMan->Delete(path);
   1.191 +	return ret;	
   1.192 +	}
   1.193 +
   1.194 +TInt CSmlTestUtilsSession::DoCopyFileL(const RMessage2& aMessage)
   1.195 +	{
   1.196 +	TBuf<100> srcpath;
   1.197 +	aMessage.ReadL(0, srcpath);
   1.198 +	
   1.199 +	TBuf<100> destpath;
   1.200 +	aMessage.ReadL(1, destpath);
   1.201 +	
   1.202 +	TInt ret = iFileMan->Copy(srcpath,destpath);
   1.203 +	return ret;	
   1.204 +	}
   1.205 +
   1.206 +TInt CSmlTestUtilsSession::DoReplaceFileL(const RMessage2& aMessage)
   1.207 +	{
   1.208 +	TBuf<100> srcpath;
   1.209 +	aMessage.ReadL(0, srcpath);
   1.210 +	TUint lFileMode;
   1.211 +	TPckgBuf<TUint> temp;
   1.212 +	aMessage.ReadL(1, temp);
   1.213 +	
   1.214 +	lFileMode=temp();
   1.215 +	RFile file;
   1.216 +	
   1.217 +	TInt ret = file.Replace(iFs,srcpath,lFileMode);
   1.218 +	return ret;	
   1.219 +	}
   1.220 +
   1.221 +TInt CSmlTestUtilsSession::DoIsFilePresentL(const RMessage2& aMessage)
   1.222 +	{
   1.223 +	TFileName srcpath;
   1.224 +	aMessage.ReadL(0, srcpath);
   1.225 +
   1.226 +	TEntry entry;
   1.227 +	TInt err = iFs.Entry(srcpath, entry);
   1.228 +	if (err == KErrNotFound)
   1.229 +		{
   1.230 +		aMessage.WriteL(1,TPckgBuf<TBool>(EFalse));
   1.231 +		}
   1.232 +	else
   1.233 +		{
   1.234 +		aMessage.WriteL(1,TPckgBuf<TBool>(ETrue));
   1.235 +		}
   1.236 +
   1.237 +	return KErrNone;
   1.238 +	}
   1.239 +
   1.240 +TInt CSmlTestUtilsSession::DoSetReadOnlyL(const RMessage2& aMessage)
   1.241 +	{
   1.242 +	TBuf<100> srcpath;
   1.243 +	aMessage.ReadL(0, srcpath);
   1.244 +	TUint attMask;
   1.245 +	TPckgBuf<TUint> temp;
   1.246 +	aMessage.ReadL(1, temp);
   1.247 +	
   1.248 +	attMask=temp();
   1.249 +	TInt ret = iFs.SetAtt(srcpath,attMask,KEntryAttReadOnly);
   1.250 +	return ret;	
   1.251 +	}
   1.252 +	
   1.253 +TInt CSmlTestUtilsSession::DoGetAttL( const RMessage2& aMessage )
   1.254 +	{
   1.255 +	
   1.256 +	TFileName nameBuf;
   1.257 +	TUint attributes = 0;
   1.258 +	
   1.259 +	aMessage.ReadL( 0, nameBuf );
   1.260 +	
   1.261 +	TInt err = iFs.Att( nameBuf, attributes );	
   1.262 +	
   1.263 +	if ( KErrNone == err )
   1.264 +		{
   1.265 +		aMessage.WriteL( 1, TPckgBuf<TInt>(attributes) );
   1.266 +		}
   1.267 +	
   1.268 +	
   1.269 +	return err;
   1.270 +	}
   1.271 +
   1.272 +
   1.273 +TInt CSmlTestUtilsSession::DoSetAttL( const RMessage2& aMessage )
   1.274 +	{
   1.275 +	
   1.276 +	TFileName nameBuf;
   1.277 +	aMessage.ReadL( 0, nameBuf );
   1.278 +	
   1.279 +	TUint setAttMask = *(TUint*)aMessage.Ptr1();
   1.280 +	TUint clearAttMask = *(TUint*)aMessage.Ptr2();
   1.281 +	
   1.282 +	TInt err = iFs.SetAtt( nameBuf, setAttMask, clearAttMask );
   1.283 +	
   1.284 +	
   1.285 +	return err;
   1.286 +	}
   1.287 +	
   1.288 +void CSmlTestUtilsSession::ServiceError(const RMessage2& aMessage,TInt aError)
   1.289 +//
   1.290 +// Handle an error from CMySession::ServiceL()
   1.291 +// A bad descriptor error implies a badly programmed client, so panic it;
   1.292 +// otherwise use the default handling (report the error to the client)
   1.293 +//
   1.294 +	{
   1.295 +	if (aError==KErrBadDescriptor)
   1.296 +		PanicClient(aMessage,ETestPanicBadDescriptor);
   1.297 +	CSession2::ServiceError(aMessage,aError);
   1.298 +	}
   1.299 +
   1.300 +
   1.301 +TInt CSmlTestUtilsSession::DoCopyDirectoryL(const RMessage2& aMessage)
   1.302 +	{
   1.303 +	TBuf<100> source;
   1.304 +	aMessage.ReadL(0, source);
   1.305 +	
   1.306 +	TBuf<100> target;
   1.307 +	aMessage.ReadL(1, target);
   1.308 +	
   1.309 +	TInt ret = iFileMan->Copy(source,target, CFileMan::ERecurse);
   1.310 +	return ret;		
   1.311 +	}
   1.312 +
   1.313 +
   1.314 +void CShutdown::RunL()
   1.315 +//
   1.316 +// Initiate server exit when the timer expires
   1.317 +//
   1.318 +	{
   1.319 +	CActiveScheduler::Stop();
   1.320 +	}
   1.321 +
   1.322 +CServer2* CSmlTestUtilsServer::NewLC()
   1.323 +	{
   1.324 +	CSmlTestUtilsServer* self=new(ELeave) CSmlTestUtilsServer;
   1.325 +	CleanupStack::PushL(self);
   1.326 +	self->ConstructL();
   1.327 +	return self;
   1.328 +	}
   1.329 +
   1.330 +void CSmlTestUtilsServer::ConstructL()
   1.331 +//
   1.332 +// 2nd phase construction - ensure the timer and server objects are running
   1.333 +//
   1.334 +	{
   1.335 +	StartL(KTestServerName);
   1.336 +	iShutdown.ConstructL();
   1.337 +	// ensure that the server still exits even if the 1st client fails to connect
   1.338 +	iShutdown.Start();
   1.339 +	}
   1.340 +
   1.341 +
   1.342 +CSession2* CSmlTestUtilsServer::NewSessionL(const TVersion&,const RMessage2&) const
   1.343 +//
   1.344 +// Cretae a new client session. This should really check the version number.
   1.345 +//
   1.346 +	{
   1.347 +	return new(ELeave) CSmlTestUtilsSession();
   1.348 +	}
   1.349 +
   1.350 +void CSmlTestUtilsServer::AddSession()
   1.351 +//
   1.352 +// A new session is being created
   1.353 +// Cancel the shutdown timer if it was running
   1.354 +//
   1.355 +	{
   1.356 +	++iSessionCount;
   1.357 +	iShutdown.Cancel();
   1.358 +	}
   1.359 +
   1.360 +void CSmlTestUtilsServer::DropSession()
   1.361 +//
   1.362 +// A session is being destroyed
   1.363 +// Start the shutdown timer if it is the last session.
   1.364 +//
   1.365 +	{
   1.366 +	if (--iSessionCount==0)
   1.367 +		iShutdown.Start();
   1.368 +	}
   1.369 +	
   1.370 +
   1.371 +
   1.372 +
   1.373 +
   1.374 +
   1.375 +//Given the name of a read-only file, this functions clears the read-only attribute on the file
   1.376 +TInt CSmlTestUtilsSession::DoChangeFilePermissionL(const RMessage2& aMessage)
   1.377 +	{
   1.378 +	TInt ret(0);
   1.379 +	TRequestStatus status;
   1.380 +	TTime time(0); 
   1.381 +	CFileMan* fileman = CFileMan::NewL (iFs);
   1.382 +	CleanupStack::PushL(fileman);
   1.383 +	TBuf<100> path;
   1.384 +	aMessage.ReadL(0, path);
   1.385 +	ret = fileman->Attribs(path,KEntryAttNormal,KEntryAttReadOnly, time,0,status);
   1.386 +	User::WaitForRequest(status);
   1.387 +	ret = status.Int(); 
   1.388 +	CleanupStack::PopAndDestroy(); 
   1.389 +	return ret;	
   1.390 +	}