kerneltest/e32test/dll/t_path.cpp
changeset 0 a41df078684a
child 6 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 
       
    39 RTest test(_L("T_PATH"));
       
    40 RFs	gFs;
       
    41 CFileMan* gFileMan;
       
    42 
       
    43 TInt E32Main()
       
    44 	{
       
    45 	test.Title();
       
    46 	test.Start(_L("Test imported DLL search path order"));
       
    47 
       
    48 	if (!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
       
    49 		{
       
    50 		test.Printf(_L("Skipping test as sysbin enforcement is disabled"));
       
    51 		return KErrNone;
       
    52 		}
       
    53 
       
    54 	// Turn off evil lazy dll unloading
       
    55 	RLoader l;
       
    56 	test_KErrNone(l.Connect());
       
    57 	test_KErrNone(l.CancelLazyDllUnload());
       
    58 	l.Close();
       
    59 
       
    60 	CTrapCleanup* ct = CTrapCleanup::New();
       
    61 	test_NotNull(ct);
       
    62 	test_KErrNone(gFs.Connect());
       
    63 	TRAPD(r, gFileMan=CFileMan::NewL(gFs));
       
    64 	test_KErrNone(r);
       
    65 
       
    66 	test.Next(_L("Run t_path2, expecting DLL 1 to be loaded"));
       
    67 	_LIT(KPath2, "t_path2");
       
    68 	RProcess path2;
       
    69 	test_KErrNone(path2.Create(KPath2, KNullDesC));
       
    70 	TRequestStatus stat;
       
    71 	path2.Logon(stat);
       
    72 	path2.Resume();
       
    73 	User::WaitForRequest(stat);
       
    74 	test_Equal(EExitKill, path2.ExitType());
       
    75 	test_Equal(1, path2.ExitReason());
       
    76 	path2.Close();
       
    77 
       
    78 	test.Next(_L("Copy DLL 2 to C drive"));
       
    79 	_LIT(KCopySrc, "Z:\\sys\\bin\\t_pathdll2.dll");
       
    80 	_LIT(KCopyDest, "C:\\sys\\bin\\");
       
    81 	test_KErrNone(gFileMan->Copy(KCopySrc(), KCopyDest(), CFileMan::ERecurse));
       
    82 	_LIT(KRenSrc, "C:\\sys\\bin\\t_pathdll2.dll");
       
    83 	_LIT(KRenDest, "C:\\sys\\bin\\t_pathdll1.dll");
       
    84 	test_KErrNone(gFileMan->Rename(KRenSrc(), KRenDest()));
       
    85 
       
    86 	test.Next(_L("Run t_path2, expecting DLL 2 to be loaded"));
       
    87 	test_KErrNone(path2.Create(KPath2, KNullDesC));
       
    88 	path2.Logon(stat);
       
    89 	path2.Resume();
       
    90 	User::WaitForRequest(stat);
       
    91 	test_Equal(EExitKill, path2.ExitType());
       
    92 	test_Equal(2, path2.ExitReason());
       
    93 	path2.Close();
       
    94 
       
    95 	// cleanup
       
    96 	gFileMan->Delete(KRenDest);
       
    97 	delete gFileMan;
       
    98 	gFs.Close();
       
    99 	delete ct;
       
   100 	test.End();
       
   101 	return KErrNone;
       
   102 	}
       
   103