os/ossrv/genericservices/systemagent/test/rtest/t_sysagt2/t_sysagt2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/systemagent/test/rtest/t_sysagt2/t_sysagt2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,242 @@
     1.4 +// Copyright (c) 2004-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 +// The main purpose of this application is to test
    1.18 +// starting of SysAgt2 server and testing RProperty::Get()/Set() methods on
    1.19 +// protected by capability properties.
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#include <e32test.h>
    1.24 +#include <e32debug.h>
    1.25 +#include <e32property.h>
    1.26 +#include <sacls.h>
    1.27 +#include <e32const.h>
    1.28 +#include <saclsdefines.h>
    1.29 +#include "SaPrivate.h"
    1.30 +#include <saclscommon.h>
    1.31 +static RTest TheTest(_L("T_SysAgt2"));
    1.32 +
    1.33 +_LIT(KSysAgent2ServerName, "SysAgt2Svr");
    1.34 +
    1.35 +//
    1.36 +//
    1.37 +//Test macroses and functions
    1.38 +LOCAL_C void Check(TInt aValue, TInt aLine)
    1.39 +	{
    1.40 +	if(!aValue)
    1.41 +		{
    1.42 +		TheTest(EFalse, aLine);
    1.43 +		}
    1.44 +	}
    1.45 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.46 +	{
    1.47 +	if(aValue != aExpected)
    1.48 +		{
    1.49 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.50 +		TheTest(EFalse, aLine);
    1.51 +		}
    1.52 +	}
    1.53 +#define TEST(arg) ::Check((arg), __LINE__)
    1.54 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.55 +//
    1.56 +//
    1.57 +
    1.58 +struct keyAssociation 
    1.59 +{
    1.60 +	TUid iCategory;
    1.61 +	TUint iProperty;
    1.62 +	TBool iIsInt;
    1.63 +};
    1.64 +
    1.65 +/**
    1.66 + * These are keys which are defined by SystemAgent2
    1.67 + * which belong to other subsystems.
    1.68 + */
    1.69 +
    1.70 +keyAssociation KSaExternalKeys[]=
    1.71 +	{
    1.72 +	KUidSystemCategory,KSAUidJavaInstallKeyValue,ETrue, 			// Java Install Key
    1.73 +	KUidSystemCategory,KSAUidSoftwareInstallKeyValue,ETrue,		// Software Install Key
    1.74 +	KUidSystemCategory,KUidSwiLatestInstallation,ETrue,
    1.75 +	KUidSystemCategory,KUidJmiLatestInstallation,ETrue,
    1.76 +	KUidSystemCategory,KUidUnifiedCertstoreFlag,ETrue,
    1.77 +	KUidSystemCategory,KUidBackupRestoreKey,ETrue,
    1.78 +	KSAPosIndicatorCategory,KSAPosIntGpsHwStatus,ETrue,
    1.79 +	KSAPosLastKnownLocationCategory,KSAPosLastKnownLocation,EFalse
    1.80 +	};
    1.81 +
    1.82 +TBool IsProcessRunning(const TDesC& aProcessName)
    1.83 +	{
    1.84 +	TFullName name;
    1.85 +	TBool IsProcessRunning(EFalse);
    1.86 +	TBuf<64> pattern(aProcessName);
    1.87 +	TInt length = pattern.Length();
    1.88 +	pattern += _L("*");
    1.89 +	TFindProcess procFinder(pattern);
    1.90 +
    1.91 +	while(procFinder.Next(name) == KErrNone)
    1.92 +		{
    1.93 +		if(name.Length() > length)
    1.94 +			{//If found name is a string containing aProcessName string.
    1.95 +			TChar c(name[length]);
    1.96 +			if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
    1.97 +				{//If the found name is other valid application name starting with aProcessName string.
    1.98 +				RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
    1.99 +				continue;
   1.100 +				}
   1.101 +			}
   1.102 +		RProcess proc;
   1.103 +		if(proc.Open(name) == KErrNone)
   1.104 +			{
   1.105 +			if (EExitKill == proc.ExitType())
   1.106 +			    {
   1.107 +			    RDebug::Print(_L("\"%S\" process killed.\n"), &name);
   1.108 +			    proc.Close();
   1.109 +			    IsProcessRunning = EFalse;
   1.110 +			    }
   1.111 +			 else
   1.112 +			    {
   1.113 +			    IsProcessRunning = ETrue;
   1.114 +			    RDebug::Print(_L("\"%S\" process is running.\n"), &name);
   1.115 +			    }
   1.116 +
   1.117 +			if(IsProcessRunning)
   1.118 +				{
   1.119 +				RDebug::Print(_L("Waiting additional time...\n"), &name);
   1.120 +
   1.121 +				User::After(1000000);
   1.122 +
   1.123 +				if (EExitKill == proc.ExitType())
   1.124 +					{
   1.125 +					RDebug::Print(_L("\"%S\" process now killed.\n"), &name);
   1.126 +			    	IsProcessRunning = EFalse;
   1.127 +					}
   1.128 +
   1.129 +				proc.Close();
   1.130 +				}
   1.131 +			}
   1.132 +
   1.133 +
   1.134 +		}
   1.135 +	return IsProcessRunning;
   1.136 +	}
   1.137 +
   1.138 +//
   1.139 +//
   1.140 +
   1.141 +/**
   1.142 +@SYMTestCaseID          SYSLIB-SYSAGENT2-CT-1254
   1.143 +@SYMTestCaseDesc	    Tests for SysAgt2 server
   1.144 +@SYMTestPriority 	    High
   1.145 +@SYMTestActions  	    Tests for RProperty::Set() and RProperty::Get() functions
   1.146 +@SYMTestExpectedResults Test must not fail
   1.147 +@SYMREQ                 REQ0000
   1.148 +*/
   1.149 +static void RunTestsL()
   1.150 +	{
   1.151 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SYSAGENT2-CT-1254 StartSysAgt2() test 1 "));
   1.152 +	TInt err = ::StartSysAgt2();
   1.153 +	TEST(err == KErrNone);
   1.154 +
   1.155 +	//proves that server does not run
   1.156 +	err = IsProcessRunning(KSysAgent2ServerName);
   1.157 +    TEST2(err,EFalse);
   1.158 +
   1.159 +	TheTest.Next(_L("Capability test"));
   1.160 +	//The access to KUidPhonePwr, KUidSIMStatus, KUidNetworkStatus, KUidNetworkStrength,
   1.161 +	//KUidChargerStatus, KUidBatteryStrength, KUidCurrentCall capabilities is protected
   1.162 +	//by different capabilities. T_SAgtTest has only ReadDeviceData. Then, all attempts
   1.163 +	//to write/read to/from protected capabilities must fail.
   1.164 +    if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) &&
   1.165 +       PlatSec::IsCapabilityEnforced(ECapabilityWriteDeviceData))
   1.166 +    	{
   1.167 +		err = RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, 1);
   1.168 +		TEST2(err, KErrPermissionDenied);
   1.169 +
   1.170 +		err = RProperty::Set(KUidSystemCategory, KUidSIMStatus.iUid, 1);
   1.171 +		TEST2(err, KErrPermissionDenied);
   1.172 +
   1.173 +		err = RProperty::Set(KUidSystemCategory, KUidNetworkStatus.iUid, 1);
   1.174 +		TEST2(err, KErrPermissionDenied);
   1.175 +
   1.176 +		err = RProperty::Set(KUidSystemCategory, KUidNetworkStrength.iUid, 1);
   1.177 +		TEST2(err, KErrPermissionDenied);
   1.178 +
   1.179 +		err = RProperty::Set(KUidSystemCategory, KUidChargerStatus.iUid, 1);
   1.180 +		TEST2(err, KErrPermissionDenied);
   1.181 +
   1.182 +		err = RProperty::Set(KUidSystemCategory, KUidBatteryStrength.iUid, 1);
   1.183 +		TEST2(err, KErrPermissionDenied);
   1.184 +
   1.185 +		err = RProperty::Set(KUidSystemCategory, KUidCurrentCall.iUid, 1);
   1.186 +		TEST2(err, KErrPermissionDenied);
   1.187 +    	}
   1.188 +
   1.189 +	TheTest.Next(_L("Capability test 2"));
   1.190 +    //If all 48 predefined properties were registered successfully (by SysAgent server),
   1.191 +    //the test must be able to read their values.
   1.192 +    const TInt KPropertyCount = 48;
   1.193 +	TUid saUid = TUid::Uid(KUidPhonePwrValue);
   1.194 +    for(TInt i=0;i<KPropertyCount;++i)
   1.195 +	    {
   1.196 +        TInt val = 0;
   1.197 +	    err = RProperty::Get(KUidSystemCategory, saUid.iUid, val);
   1.198 +        TEST2(err, KErrNone);
   1.199 +	    ++saUid.iUid;
   1.200 +        }
   1.201 +
   1.202 +	TheTest.Next(_L("Other defined Properties test"));
   1.203 +	// This test checks that the other publish and subscribe properties
   1.204 +	// have been defined by SystemAgent2. These are properties which are used
   1.205 +	// in other subsystems, mainly defined by this component due to PlatSec
   1.206 +	// restrictions requiring WriteUserData to define a property.
   1.207 +	for (TInt i=0; i < sizeof(KSaExternalKeys) / sizeof(KSaExternalKeys[0]); ++i)
   1.208 +		{
   1.209 +		if(KSaExternalKeys[i].iIsInt)
   1.210 +			{
   1.211 +			TInt propertyValue=0;
   1.212 +			err = RProperty::Get(KSaExternalKeys[i].iCategory, KSaExternalKeys[i].iProperty, propertyValue);
   1.213 +			}
   1.214 +		else
   1.215 +			{
   1.216 +			TBuf8<512> propertyValue;
   1.217 +			err = RProperty::Get(KSaExternalKeys[i].iCategory, KSaExternalKeys[i].iProperty, propertyValue);
   1.218 +			}
   1.219 +		
   1.220 +
   1.221 +		// We expect the property to be defined, but we cannot make any assumptions
   1.222 +		// about what value it will have since it could have been changed before
   1.223 +		// the test gets here.
   1.224 +		TEST(err==KErrNone);
   1.225 +		}
   1.226 +
   1.227 +	}
   1.228 +
   1.229 +GLDEF_C TInt E32Main()
   1.230 +	{
   1.231 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.232 +	__UHEAP_MARK;
   1.233 +
   1.234 +	TheTest.Title();
   1.235 +	TRAPD(err, ::RunTestsL());
   1.236 +	TheTest(err == KErrNone);
   1.237 +	TheTest.End();
   1.238 +	TheTest.Close();
   1.239 +
   1.240 +	delete tc;
   1.241 +
   1.242 +	__UHEAP_MARKEND;
   1.243 +	User::Heap().Check();
   1.244 +	return KErrNone;
   1.245 +	}