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