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