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