os/kernelhwsrv/kerneltest/e32test/misc/t_uid.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/t_uid.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,186 @@
     1.4 +// Copyright (c) 1996-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 the License "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 +// e32test\misc\t_uid.cpp
    1.18 +// Overview:
    1.19 +// Test handling of UIDs (Unique Identifiers). 
    1.20 +// API Information:
    1.21 +// TUid, TUidType, TCheckedUid.
    1.22 +// Details:
    1.23 +// - Assign some globally unique 32-bit numbers with specified values, 
    1.24 +// get standard text form of the UID and check it is as expected.
    1.25 +// - Set the specified Uid type to be packaged and verify
    1.26 +// - validity of UID type. 
    1.27 +// - Uid type contained is as expected.
    1.28 +// - component UIDs are same as specified UID.
    1.29 +// - the most derived UID is as expected.
    1.30 +// - Check the process' Uids are as expected.
    1.31 +// - Load the specified DLL, get Uid of DLL, name of this DLL's file,
    1.32 +// compare the name with a specified text and check it is as expected,
    1.33 +// verify the Uid is as expected.
    1.34 +// Platforms/Drives/Compatibility:
    1.35 +// All 
    1.36 +// Assumptions/Requirement/Pre-requisites:
    1.37 +// Failures and causes:
    1.38 +// Base Port information:
    1.39 +// 
    1.40 +//
    1.41 +
    1.42 +#include <e32test.h>
    1.43 +
    1.44 +LOCAL_D RTest test(_L("T_UID"));
    1.45 +
    1.46 +const TUid g1 = {0x10000001};
    1.47 +const TUid g11 = {0x10000001};
    1.48 +const TUid g2 = {0x10000002};
    1.49 +const TUid g22 = {0x10000002};
    1.50 +const TUid g3 = {0x10000003};
    1.51 +const TUid g33 = {0x10000003};
    1.52 +
    1.53 +LOCAL_C void testUid()
    1.54 +//
    1.55 +// Test UIDs
    1.56 +//
    1.57 +	{
    1.58 +
    1.59 +	test.Start(_L("All functions"));
    1.60 +	test(g1==g11);
    1.61 +	test(g2==g22);
    1.62 +	test(g1!=g2);
    1.63 +	TName a1Name = g1.Name();
    1.64 +	TName a11Name = g11.Name();
    1.65 +	TName a2Name = g2.Name();
    1.66 +	TName a22Name = g22.Name();
    1.67 +	test.Printf(_L("%S %S\n"),&a1Name,&a11Name);
    1.68 +	test.Printf(_L("%S %S\n"),&a2Name,&a22Name);
    1.69 +	test.End();
    1.70 +	}
    1.71 +
    1.72 +LOCAL_C void testCheckedUid()
    1.73 +//
    1.74 +// Test checked UIDs
    1.75 +//
    1.76 +	{
    1.77 +
    1.78 +	test.Start(_L("All functions"));
    1.79 +	TCheckedUid check1;
    1.80 +	check1.Set(TUidType(g1));
    1.81 +	test(check1.UidType().IsValid()==TRUE);
    1.82 +	test(check1.UidType()[0]==g1);
    1.83 +	test(check1.UidType()[1]==KNullUid);
    1.84 +	test(check1.UidType()[2]==KNullUid);
    1.85 +	test(check1.UidType().MostDerived()==g1);
    1.86 +	test(check1.UidType().IsPresent(g1)==TRUE);
    1.87 +	test(check1.UidType().IsPresent(g2)==FALSE);
    1.88 +	test(check1.UidType().IsPresent(g3)==FALSE);
    1.89 +	TCheckedUid check2;
    1.90 +	check2.Set(TUidType(g1,g2));
    1.91 +	test(check2.UidType().IsValid()==TRUE);
    1.92 +	test(check2.UidType()[0]==g1);
    1.93 +	test(check2.UidType()[1]==g2);
    1.94 +	test(check2.UidType()[2]==KNullUid);
    1.95 +	test(check2.UidType().MostDerived()==g2);
    1.96 +	test(check2.UidType().IsPresent(g1)==TRUE);
    1.97 +	test(check2.UidType().IsPresent(g2)==TRUE);
    1.98 +	test(check2.UidType().IsPresent(g3)==FALSE);
    1.99 +	TCheckedUid check3;
   1.100 +	check3.Set(TUidType(g1,g2,g3));
   1.101 +	test(check3.UidType().IsValid()==TRUE);
   1.102 +	test(check3.UidType()[0]==g1);
   1.103 +	test(check3.UidType()[1]==g2);
   1.104 +	test(check3.UidType()[2]==g3);
   1.105 +	test(check3.UidType().MostDerived()==g3);
   1.106 +	test(check3.UidType().IsPresent(g1)==TRUE);
   1.107 +	test(check3.UidType().IsPresent(g2)==TRUE);
   1.108 +	test(check3.UidType().IsPresent(g3)==TRUE);
   1.109 +	HBufC8* pH=check3.Des().Alloc();
   1.110 +    TUidType t1(g3,check3.UidType()[1],check3.UidType()[2]);
   1.111 +    check3=t1;
   1.112 +	test(check3.UidType().IsValid()==TRUE);
   1.113 +    TUidType t2(g3,g1,check3.UidType()[2]);
   1.114 +    check3=t2;
   1.115 +	test(check3.UidType().IsValid()==TRUE);
   1.116 +    TUidType t3(g3,g1,g2);
   1.117 +    check3=t3;
   1.118 +	test(check3.UidType().IsValid()==TRUE);
   1.119 +	test(check3.UidType()[0]==g3);
   1.120 +	test(check3.UidType()[1]==g1);
   1.121 +	test(check3.UidType()[2]==g2);
   1.122 +	test(check3.UidType().IsPresent(g1)==TRUE);
   1.123 +	test(check3.UidType().IsPresent(g2)==TRUE);
   1.124 +	test(check3.UidType().IsPresent(g3)==TRUE);
   1.125 +	check3.Set(*pH);
   1.126 +	test(check3.UidType().IsValid()==TRUE);
   1.127 +	test(check3.UidType()[0]==g1);
   1.128 +	test(check3.UidType()[1]==g2);
   1.129 +	test(check3.UidType()[2]==g3);
   1.130 +	test(check3.UidType().IsPresent(g1)==TRUE);
   1.131 +	test(check3.UidType().IsPresent(g2)==TRUE);
   1.132 +	test(check3.UidType().IsPresent(g3)==TRUE);
   1.133 +	TCheckedUid check4(*pH);
   1.134 +	delete pH;
   1.135 +	test(check4.UidType().IsValid()==TRUE);
   1.136 +	test(check4.UidType()[0]==g1);
   1.137 +	test(check4.UidType()[1]==g2);
   1.138 +	test(check4.UidType()[2]==g3);
   1.139 +//
   1.140 +	test.End();
   1.141 +	}
   1.142 +
   1.143 +GLDEF_C TInt E32Main()
   1.144 +//
   1.145 +// Test Uid handling.
   1.146 +//
   1.147 +    {
   1.148 +
   1.149 +	test.Title();
   1.150 +//
   1.151 +	test.Start(_L("Uid tests"));
   1.152 +	testUid();
   1.153 +//
   1.154 +	test.Next(_L("Checked Uid tests"));
   1.155 +	testCheckedUid();
   1.156 +//
   1.157 +	test.Next(_L("Check this process's Uids"));
   1.158 +	test(RProcess().Type()[1]==TUid::Uid(0x22222222));
   1.159 +	test(RProcess().Type()[2]==TUid::Uid(0x33333333));
   1.160 +
   1.161 +	test.Next(_L("Load Uid DLL"));
   1.162 +	RLibrary lib;
   1.163 +	TInt r=lib.Load(_L("T_DUID.DLL"));
   1.164 +	test(r==KErrNone);
   1.165 +	test.Next(_L("Test FileName"));
   1.166 +	test.Printf(lib.FileName());
   1.167 +	test.Printf(_L("\n"));
   1.168 +
   1.169 +#if defined(__WINS__)
   1.170 +	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   1.171 +		test(lib.FileName().CompareF(_L("Z:\\Sys\\Bin\\T_DUID.DLL"))==0);
   1.172 +	else
   1.173 +		test(lib.FileName().CompareF(_L("Z:\\System\\Bin\\T_DUID.DLL"))==0);
   1.174 +#else
   1.175 +	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   1.176 +		test(lib.FileName().MatchF(_L("?:\\Sys\\Bin\\T_DUID.DLL"))!=KErrNotFound);
   1.177 +	else
   1.178 +		test(lib.FileName().MatchF(_L("?:\\System\\Bin\\T_DUID.DLL"))!=KErrNotFound);
   1.179 +#endif
   1.180 +	test.Next(_L("Check DLL Uid"));
   1.181 +	test(lib.Type()[1]==TUid::Uid(0x12345678));
   1.182 +	test(lib.Type()[2]==TUid::Uid(0x87654321));
   1.183 +	lib.Close();
   1.184 +	test.End();
   1.185 +	return(KErrNone);
   1.186 +	}
   1.187 +
   1.188 +
   1.189 +