os/kernelhwsrv/kerneltest/e32test/misc/t_uid.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1996-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 the License "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 // e32test\misc\t_uid.cpp
    15 // Overview:
    16 // Test handling of UIDs (Unique Identifiers). 
    17 // API Information:
    18 // TUid, TUidType, TCheckedUid.
    19 // Details:
    20 // - Assign some globally unique 32-bit numbers with specified values, 
    21 // get standard text form of the UID and check it is as expected.
    22 // - Set the specified Uid type to be packaged and verify
    23 // - validity of UID type. 
    24 // - Uid type contained is as expected.
    25 // - component UIDs are same as specified UID.
    26 // - the most derived UID is as expected.
    27 // - Check the process' Uids are as expected.
    28 // - Load the specified DLL, get Uid of DLL, name of this DLL's file,
    29 // compare the name with a specified text and check it is as expected,
    30 // verify the Uid is as expected.
    31 // Platforms/Drives/Compatibility:
    32 // All 
    33 // Assumptions/Requirement/Pre-requisites:
    34 // Failures and causes:
    35 // Base Port information:
    36 // 
    37 //
    38 
    39 #include <e32test.h>
    40 
    41 LOCAL_D RTest test(_L("T_UID"));
    42 
    43 const TUid g1 = {0x10000001};
    44 const TUid g11 = {0x10000001};
    45 const TUid g2 = {0x10000002};
    46 const TUid g22 = {0x10000002};
    47 const TUid g3 = {0x10000003};
    48 const TUid g33 = {0x10000003};
    49 
    50 LOCAL_C void testUid()
    51 //
    52 // Test UIDs
    53 //
    54 	{
    55 
    56 	test.Start(_L("All functions"));
    57 	test(g1==g11);
    58 	test(g2==g22);
    59 	test(g1!=g2);
    60 	TName a1Name = g1.Name();
    61 	TName a11Name = g11.Name();
    62 	TName a2Name = g2.Name();
    63 	TName a22Name = g22.Name();
    64 	test.Printf(_L("%S %S\n"),&a1Name,&a11Name);
    65 	test.Printf(_L("%S %S\n"),&a2Name,&a22Name);
    66 	test.End();
    67 	}
    68 
    69 LOCAL_C void testCheckedUid()
    70 //
    71 // Test checked UIDs
    72 //
    73 	{
    74 
    75 	test.Start(_L("All functions"));
    76 	TCheckedUid check1;
    77 	check1.Set(TUidType(g1));
    78 	test(check1.UidType().IsValid()==TRUE);
    79 	test(check1.UidType()[0]==g1);
    80 	test(check1.UidType()[1]==KNullUid);
    81 	test(check1.UidType()[2]==KNullUid);
    82 	test(check1.UidType().MostDerived()==g1);
    83 	test(check1.UidType().IsPresent(g1)==TRUE);
    84 	test(check1.UidType().IsPresent(g2)==FALSE);
    85 	test(check1.UidType().IsPresent(g3)==FALSE);
    86 	TCheckedUid check2;
    87 	check2.Set(TUidType(g1,g2));
    88 	test(check2.UidType().IsValid()==TRUE);
    89 	test(check2.UidType()[0]==g1);
    90 	test(check2.UidType()[1]==g2);
    91 	test(check2.UidType()[2]==KNullUid);
    92 	test(check2.UidType().MostDerived()==g2);
    93 	test(check2.UidType().IsPresent(g1)==TRUE);
    94 	test(check2.UidType().IsPresent(g2)==TRUE);
    95 	test(check2.UidType().IsPresent(g3)==FALSE);
    96 	TCheckedUid check3;
    97 	check3.Set(TUidType(g1,g2,g3));
    98 	test(check3.UidType().IsValid()==TRUE);
    99 	test(check3.UidType()[0]==g1);
   100 	test(check3.UidType()[1]==g2);
   101 	test(check3.UidType()[2]==g3);
   102 	test(check3.UidType().MostDerived()==g3);
   103 	test(check3.UidType().IsPresent(g1)==TRUE);
   104 	test(check3.UidType().IsPresent(g2)==TRUE);
   105 	test(check3.UidType().IsPresent(g3)==TRUE);
   106 	HBufC8* pH=check3.Des().Alloc();
   107     TUidType t1(g3,check3.UidType()[1],check3.UidType()[2]);
   108     check3=t1;
   109 	test(check3.UidType().IsValid()==TRUE);
   110     TUidType t2(g3,g1,check3.UidType()[2]);
   111     check3=t2;
   112 	test(check3.UidType().IsValid()==TRUE);
   113     TUidType t3(g3,g1,g2);
   114     check3=t3;
   115 	test(check3.UidType().IsValid()==TRUE);
   116 	test(check3.UidType()[0]==g3);
   117 	test(check3.UidType()[1]==g1);
   118 	test(check3.UidType()[2]==g2);
   119 	test(check3.UidType().IsPresent(g1)==TRUE);
   120 	test(check3.UidType().IsPresent(g2)==TRUE);
   121 	test(check3.UidType().IsPresent(g3)==TRUE);
   122 	check3.Set(*pH);
   123 	test(check3.UidType().IsValid()==TRUE);
   124 	test(check3.UidType()[0]==g1);
   125 	test(check3.UidType()[1]==g2);
   126 	test(check3.UidType()[2]==g3);
   127 	test(check3.UidType().IsPresent(g1)==TRUE);
   128 	test(check3.UidType().IsPresent(g2)==TRUE);
   129 	test(check3.UidType().IsPresent(g3)==TRUE);
   130 	TCheckedUid check4(*pH);
   131 	delete pH;
   132 	test(check4.UidType().IsValid()==TRUE);
   133 	test(check4.UidType()[0]==g1);
   134 	test(check4.UidType()[1]==g2);
   135 	test(check4.UidType()[2]==g3);
   136 //
   137 	test.End();
   138 	}
   139 
   140 GLDEF_C TInt E32Main()
   141 //
   142 // Test Uid handling.
   143 //
   144     {
   145 
   146 	test.Title();
   147 //
   148 	test.Start(_L("Uid tests"));
   149 	testUid();
   150 //
   151 	test.Next(_L("Checked Uid tests"));
   152 	testCheckedUid();
   153 //
   154 	test.Next(_L("Check this process's Uids"));
   155 	test(RProcess().Type()[1]==TUid::Uid(0x22222222));
   156 	test(RProcess().Type()[2]==TUid::Uid(0x33333333));
   157 
   158 	test.Next(_L("Load Uid DLL"));
   159 	RLibrary lib;
   160 	TInt r=lib.Load(_L("T_DUID.DLL"));
   161 	test(r==KErrNone);
   162 	test.Next(_L("Test FileName"));
   163 	test.Printf(lib.FileName());
   164 	test.Printf(_L("\n"));
   165 
   166 #if defined(__WINS__)
   167 	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   168 		test(lib.FileName().CompareF(_L("Z:\\Sys\\Bin\\T_DUID.DLL"))==0);
   169 	else
   170 		test(lib.FileName().CompareF(_L("Z:\\System\\Bin\\T_DUID.DLL"))==0);
   171 #else
   172 	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   173 		test(lib.FileName().MatchF(_L("?:\\Sys\\Bin\\T_DUID.DLL"))!=KErrNotFound);
   174 	else
   175 		test(lib.FileName().MatchF(_L("?:\\System\\Bin\\T_DUID.DLL"))!=KErrNotFound);
   176 #endif
   177 	test.Next(_L("Check DLL Uid"));
   178 	test(lib.Type()[1]==TUid::Uid(0x12345678));
   179 	test(lib.Type()[2]==TUid::Uid(0x87654321));
   180 	lib.Close();
   181 	test.End();
   182 	return(KErrNone);
   183 	}
   184 
   185 
   186