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