os/kernelhwsrv/kerneltest/e32test/dll/t_path.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) 2007-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\dll\t_path.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test imported DLL path search order.
sl@0
    17
// API Information:
sl@0
    18
// None (implicit searching when loading an executable)
sl@0
    19
// Details:
sl@0
    20
// - t_pathdll1 and t_pathdll2 both export the same function which returns 1
sl@0
    21
// 2 respectively.
sl@0
    22
// - Run t_path2 (linked to t_pathdll1) and check return value from DLL - should
sl@0
    23
// be 1.
sl@0
    24
// - Copy t_pathdll2 to C: and rename to t_pathdll1 - it should now be loaded 
sl@0
    25
// instead.
sl@0
    26
// - Run t_path2 again and check return value from DLL - should be 2.
sl@0
    27
// Platforms/Drives/Compatibility:
sl@0
    28
// Not on emulator.
sl@0
    29
// Assumptions/Requirement/Pre-requisites:
sl@0
    30
// Failures and causes:
sl@0
    31
// Base Port information:
sl@0
    32
// 
sl@0
    33
//
sl@0
    34
sl@0
    35
#define __E32TEST_EXTENSION__
sl@0
    36
#include <e32test.h>
sl@0
    37
#include <f32file.h>
sl@0
    38
#include <e32ldr.h>
sl@0
    39
#include <e32ldr_private.h>
sl@0
    40
sl@0
    41
RTest test(_L("T_PATH"));
sl@0
    42
RFs	gFs;
sl@0
    43
CFileMan* gFileMan;
sl@0
    44
sl@0
    45
TInt E32Main()
sl@0
    46
	{
sl@0
    47
	test.Title();
sl@0
    48
	test.Start(_L("Test imported DLL search path order"));
sl@0
    49
sl@0
    50
	if (!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
    51
		{
sl@0
    52
		test.Printf(_L("Skipping test as sysbin enforcement is disabled"));
sl@0
    53
		return KErrNone;
sl@0
    54
		}
sl@0
    55
sl@0
    56
	// Turn off evil lazy dll unloading
sl@0
    57
	RLoader l;
sl@0
    58
	test_KErrNone(l.Connect());
sl@0
    59
	test_KErrNone(l.CancelLazyDllUnload());
sl@0
    60
	l.Close();
sl@0
    61
sl@0
    62
	CTrapCleanup* ct = CTrapCleanup::New();
sl@0
    63
	test_NotNull(ct);
sl@0
    64
	test_KErrNone(gFs.Connect());
sl@0
    65
	TRAPD(r, gFileMan=CFileMan::NewL(gFs));
sl@0
    66
	test_KErrNone(r);
sl@0
    67
sl@0
    68
	test.Next(_L("Run t_path2, expecting DLL 1 to be loaded"));
sl@0
    69
	_LIT(KPath2, "t_path2");
sl@0
    70
	RProcess path2;
sl@0
    71
	test_KErrNone(path2.Create(KPath2, KNullDesC));
sl@0
    72
	TRequestStatus stat;
sl@0
    73
	path2.Logon(stat);
sl@0
    74
	path2.Resume();
sl@0
    75
	User::WaitForRequest(stat);
sl@0
    76
	test_Equal(EExitKill, path2.ExitType());
sl@0
    77
	test_Equal(1, path2.ExitReason());
sl@0
    78
	path2.Close();
sl@0
    79
sl@0
    80
	test.Next(_L("Copy DLL 2 to C drive"));
sl@0
    81
	_LIT(KCopySrc, "Z:\\sys\\bin\\t_pathdll2.dll");
sl@0
    82
	_LIT(KCopyDest, "C:\\sys\\bin\\");
sl@0
    83
	test_KErrNone(gFileMan->Copy(KCopySrc(), KCopyDest(), CFileMan::ERecurse));
sl@0
    84
	_LIT(KRenSrc, "C:\\sys\\bin\\t_pathdll2.dll");
sl@0
    85
	_LIT(KRenDest, "C:\\sys\\bin\\t_pathdll1.dll");
sl@0
    86
	test_KErrNone(gFileMan->Rename(KRenSrc(), KRenDest()));
sl@0
    87
sl@0
    88
	test.Next(_L("Run t_path2, expecting DLL 2 to be loaded"));
sl@0
    89
	test_KErrNone(path2.Create(KPath2, KNullDesC));
sl@0
    90
	path2.Logon(stat);
sl@0
    91
	path2.Resume();
sl@0
    92
	User::WaitForRequest(stat);
sl@0
    93
	test_Equal(EExitKill, path2.ExitType());
sl@0
    94
	test_Equal(2, path2.ExitReason());
sl@0
    95
	path2.Close();
sl@0
    96
sl@0
    97
	// cleanup
sl@0
    98
	gFileMan->Delete(KRenDest);
sl@0
    99
	delete gFileMan;
sl@0
   100
	gFs.Close();
sl@0
   101
	delete ct;
sl@0
   102
	test.End();
sl@0
   103
	return KErrNone;
sl@0
   104
	}
sl@0
   105