os/ossrv/genericservices/taskscheduler/Test/PlatSec/migrationtaskhandler.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-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 //
    15 
    16 #include <e32test.h>
    17 #include <schtask.h>
    18 #include "platsectaskcommon.h"
    19 
    20 LOCAL_C void NotifyTestComplete()
    21 	{
    22 	_LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
    23 	RSemaphore sem;
    24 	TInt ret = sem.OpenGlobal(KSchSemaphoreName);
    25 	if (ret == KErrNone)
    26 		{
    27 		sem.Signal();
    28 		sem.Close();
    29 		}
    30 	}
    31 /**
    32 @SYMTestCaseID          SYSLIB-SCHSVR-CT-1344
    33 @SYMTestCaseDesc	    Migration task handler test
    34 @SYMTestPriority 	    High
    35 @SYMTestActions  	    Attempt to create a representation of a scheduled task from a specified stream.
    36 @SYMTestExpectedResults Test must not fail
    37 @SYMREQ                 REQ0000
    38 */			
    39 LOCAL_C void CheckFileOkL(TFileName& aFileName, RTest& aTest)
    40 	{
    41 	aTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1344 "));
    42 	RFs fs;
    43 	User::LeaveIfError(fs.Connect());
    44 	CleanupClosePushL(fs);
    45 	
    46 	TParse parsedName;
    47 	User::LeaveIfError(fs.Parse(aFileName, parsedName));
    48 	CFileStore* store = CDirectFileStore::OpenLC(fs, parsedName.FullName(), EFileRead);
    49 
    50 	RStoreReadStream instream;
    51 	instream.OpenLC(*store, store->Root());
    52 
    53 	TInt count = instream.ReadInt32L();
    54 	aTest(count==1);
    55 	
    56 	CScheduledTask* task = CScheduledTask::NewLC(instream);
    57 	aTest(task->Info().iName.CompareF(KPlatSecTaskName)==0);
    58 
    59 	CleanupStack::PopAndDestroy(4); // task, fs, instream, store
    60 	}
    61 
    62 LOCAL_C TInt Execute(TFileName& aFilename)
    63 	{
    64 	CTrapCleanup* cleanup = CTrapCleanup::New();
    65 	if(!cleanup)
    66 		return KErrNoMemory;
    67 	
    68 	_LIT(KPlatSecTestName, "MigrationTaskHandlerTest");
    69 	RTest theTest(KPlatSecTestName);
    70 	theTest.Start(KPlatSecTestName);
    71 	theTest.Title();
    72     
    73 	TRAPD(err, CheckFileOkL(aFilename, theTest));
    74 	theTest(err==KErrNone);
    75 
    76 	NotifyTestComplete();
    77 
    78 	theTest.End();
    79 	theTest.Close();
    80 				
    81 	delete cleanup;
    82 
    83 	return err;
    84 	}
    85 
    86 GLDEF_C TInt E32Main()
    87 	{
    88 	TBuf<0x100> cmd;
    89     User::CommandLine(cmd);
    90 	return Execute(cmd);
    91 	}