1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dll/t_path.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,105 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\dll\t_path.cpp
1.18 +// Overview:
1.19 +// Test imported DLL path search order.
1.20 +// API Information:
1.21 +// None (implicit searching when loading an executable)
1.22 +// Details:
1.23 +// - t_pathdll1 and t_pathdll2 both export the same function which returns 1
1.24 +// 2 respectively.
1.25 +// - Run t_path2 (linked to t_pathdll1) and check return value from DLL - should
1.26 +// be 1.
1.27 +// - Copy t_pathdll2 to C: and rename to t_pathdll1 - it should now be loaded
1.28 +// instead.
1.29 +// - Run t_path2 again and check return value from DLL - should be 2.
1.30 +// Platforms/Drives/Compatibility:
1.31 +// Not on emulator.
1.32 +// Assumptions/Requirement/Pre-requisites:
1.33 +// Failures and causes:
1.34 +// Base Port information:
1.35 +//
1.36 +//
1.37 +
1.38 +#define __E32TEST_EXTENSION__
1.39 +#include <e32test.h>
1.40 +#include <f32file.h>
1.41 +#include <e32ldr.h>
1.42 +#include <e32ldr_private.h>
1.43 +
1.44 +RTest test(_L("T_PATH"));
1.45 +RFs gFs;
1.46 +CFileMan* gFileMan;
1.47 +
1.48 +TInt E32Main()
1.49 + {
1.50 + test.Title();
1.51 + test.Start(_L("Test imported DLL search path order"));
1.52 +
1.53 + if (!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.54 + {
1.55 + test.Printf(_L("Skipping test as sysbin enforcement is disabled"));
1.56 + return KErrNone;
1.57 + }
1.58 +
1.59 + // Turn off evil lazy dll unloading
1.60 + RLoader l;
1.61 + test_KErrNone(l.Connect());
1.62 + test_KErrNone(l.CancelLazyDllUnload());
1.63 + l.Close();
1.64 +
1.65 + CTrapCleanup* ct = CTrapCleanup::New();
1.66 + test_NotNull(ct);
1.67 + test_KErrNone(gFs.Connect());
1.68 + TRAPD(r, gFileMan=CFileMan::NewL(gFs));
1.69 + test_KErrNone(r);
1.70 +
1.71 + test.Next(_L("Run t_path2, expecting DLL 1 to be loaded"));
1.72 + _LIT(KPath2, "t_path2");
1.73 + RProcess path2;
1.74 + test_KErrNone(path2.Create(KPath2, KNullDesC));
1.75 + TRequestStatus stat;
1.76 + path2.Logon(stat);
1.77 + path2.Resume();
1.78 + User::WaitForRequest(stat);
1.79 + test_Equal(EExitKill, path2.ExitType());
1.80 + test_Equal(1, path2.ExitReason());
1.81 + path2.Close();
1.82 +
1.83 + test.Next(_L("Copy DLL 2 to C drive"));
1.84 + _LIT(KCopySrc, "Z:\\sys\\bin\\t_pathdll2.dll");
1.85 + _LIT(KCopyDest, "C:\\sys\\bin\\");
1.86 + test_KErrNone(gFileMan->Copy(KCopySrc(), KCopyDest(), CFileMan::ERecurse));
1.87 + _LIT(KRenSrc, "C:\\sys\\bin\\t_pathdll2.dll");
1.88 + _LIT(KRenDest, "C:\\sys\\bin\\t_pathdll1.dll");
1.89 + test_KErrNone(gFileMan->Rename(KRenSrc(), KRenDest()));
1.90 +
1.91 + test.Next(_L("Run t_path2, expecting DLL 2 to be loaded"));
1.92 + test_KErrNone(path2.Create(KPath2, KNullDesC));
1.93 + path2.Logon(stat);
1.94 + path2.Resume();
1.95 + User::WaitForRequest(stat);
1.96 + test_Equal(EExitKill, path2.ExitType());
1.97 + test_Equal(2, path2.ExitReason());
1.98 + path2.Close();
1.99 +
1.100 + // cleanup
1.101 + gFileMan->Delete(KRenDest);
1.102 + delete gFileMan;
1.103 + gFs.Close();
1.104 + delete ct;
1.105 + test.End();
1.106 + return KErrNone;
1.107 + }
1.108 +