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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <schinfointernal.h>
24 #include "platsectaskcommon.h"
28 _LIT(KConsoleName, "PlatSecTaskHandler");
30 static void SignalTestExe()
32 _LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
34 TInt ret = sem.OpenGlobal(KSchSemaphoreName);
42 //***********************************************************************************
43 LOCAL_C TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed)
45 TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow));
48 // Round to 0 decimal places, ie. the nearest whole numer
49 Math::Round(initialRand, initialRand, 0);
50 Math::Int(rand, initialRand);
55 //***********************************************************************************
56 LOCAL_C void DestroyArray(TAny* aArray)
58 static_cast<RArray<TCapability>*>(aArray)->Reset();
61 @SYMTestCaseID SYSLIB-SCHSVR-CT-1345
62 @SYMTestCaseDesc Platform security Task handler test
64 @SYMTestActions Attempt to test the contents of a task file.
65 @SYMTestExpectedResults Test must not fail
68 LOCAL_C void ConstructConsoleL(RFile& aTaskFile, RTest& aTest)
71 CConsoleBase* console=Console::NewL(KConsoleName, TSize(KConsFullScreen, KConsFullScreen));
72 CleanupStack::PushL(console);
73 console->Printf(_L(" contents of task file\n"));
75 RArray<TCapability> enforcedCaps;
76 CleanupStack::PushL(TCleanupItem(&DestroyArray,&enforcedCaps));
78 for (TInt i=0; i<ECapability_Limit; i++)
80 // we're checking here to see which capabilities are enforced, skipping
81 // ECapabilityMultimediaDD and ECapabilityWriteDeviceData as it is
82 // needed to write persistent schedules upon which this test relies.
84 if (i == KPlatSecTestCapability)
86 else if (i == ECapabilityWriteDeviceData)
88 else if (PlatSec::IsCapabilityEnforced((TCapability)i))
89 enforcedCaps.Append((TCapability)i);
92 TBool isTestCapabilityEnforced = PlatSec::IsCapabilityEnforced(KPlatSecTestCapability);
95 store = CDirectFileStore::FromLC(aTaskFile);
97 RStoreReadStream instream;
98 instream.OpenLC(*store,store->Root());
100 TInt count = instream.ReadInt32L();
101 for (TInt i=0;i<count;i++)
103 CScheduledTask* task = CScheduledTask::NewLC(instream);
105 aTest(task->Info().iName.CompareF(KPlatSecTaskName)==0);
106 aTest(task->Data().CompareF(KPlatSecTaskData)==0);
107 aTest(task->SecurityInfo().iSecureId==KPlatSecTestSid); //This is the SID of tschsvrplatsec
109 // check that client has capability it should have
110 if(isTestCapabilityEnforced)
111 aTest(task->SecurityInfo().iCaps.HasCapability(KPlatSecTestCapability));
113 // check that the client has ECapabilityWriteDeviceData
114 aTest(task->SecurityInfo().iCaps.HasCapability(ECapabilityWriteDeviceData));
116 // check that client doesn't have any other capabilities
117 for (TInt j=enforcedCaps.Count()-1; j>=0; --j)
119 aTest(!task->SecurityInfo().iCaps.HasCapability(enforcedCaps[j]));
123 CleanupStack::PopAndDestroy(task);
126 console->Printf(_L("Pausing for a one second..."));
127 User::After(1000000);
129 CleanupStack::PopAndDestroy(4); // instream, store, enforcedCaps, console
133 //***********************************************************************************
134 LOCAL_C TInt Execute()
136 TInt err = KErrNoMemory;
137 CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
140 _LIT(KPlatSecTestName, "PlatSectTaskHandlerTest");
141 RTest theTest(KPlatSecTestName);
142 theTest.Start(KPlatSecTestName);
147 // Adopt the task file from the Task Scheduler
148 err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
149 TScheduledTaskFile::FileHandleIndex());
153 // The aParam is the name of a file where the relevant CTaskExCmdLine is
155 theTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1345 "));
156 TRAPD(err, ConstructConsoleL(file, theTest));
159 // Sometimes we want to return a bogus error value,
160 // sometimes we don't.
163 TInt64 seed = now.Int64();
164 err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned
167 file.Close();// Close the file
179 //***********************************************************************************
180 GLDEF_C TInt E32Main()