os/kernelhwsrv/kerneltest/e32test/dll/t_loadfail.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dll/t_loadfail.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,134 @@
     1.4 +// Copyright (c) 2006-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_loadfail.cpp
    1.18 +// Overview:
    1.19 +// Tests failure codes when loading a RProcess or RLibrary.
    1.20 +// Introduced as test for defect DEF092502
    1.21 +// API Information:
    1.22 +// RProcess, RLibrary
    1.23 +// Details:
    1.24 +// - Test attempting to open a non-existent DLL fails gracefully
    1.25 +// - Test attempting to open a DLL of an invalid name fails gracefully
    1.26 +// - Test attempting to open a non-existent EXE fails gracefully
    1.27 +// - Test attempting to open an EXE of an invalid name fails gracefully
    1.28 +// - Test loading a dll with an incorrect version number as part of it name
    1.29 +// will return KErrCorupt
    1.30 +// Platforms/Drives/Compatibility:
    1.31 +// All
    1.32 +// Assumptions/Requirement/Pre-requisites:
    1.33 +// Assumes drive 'z' always contains \img\t_ver1{00010001}.dll
    1.34 +// Assumes drive 'c' is writeable
    1.35 +// Failures and causes:
    1.36 +// Base Port information:
    1.37 +// Error codes returned on h/w and emulator should be the same
    1.38 +// 
    1.39 +//
    1.40 +
    1.41 +#include <e32test.h>
    1.42 +#include <f32file.h>
    1.43 +
    1.44 +RTest test(_L("T_LOADFAIL"));
    1.45 +
    1.46 +// Test loading dll with incorrect version number in the name returns KErrCorrupt
    1.47 +// as the loader will compare the image header version number against that in the
    1.48 +// image file's name
    1.49 +LOCAL_D TInt TestVersionL()
    1.50 +	{
    1.51 +// Test only valid on target h/w as emulator uses MS Windows loader which doesn't allow verison 
    1.52 +// no. to be in part of the dll name.
    1.53 +#ifndef __WINS__
    1.54 +	RFs rfs;
    1.55 +	rfs.Connect();
    1.56 +	CFileMan *fileman = CFileMan::NewL(rfs);
    1.57 +	_LIT(KCorrectDll,"z:\\img\\t_ver1{00010001}.dll");
    1.58 +	_LIT(KWrongDll,"c:\\sys\\bin\\t_ver1{00010011}.dll");
    1.59 +	test(KErrNone == fileman->Copy(KCorrectDll,KWrongDll,CFileMan::ERecurse));
    1.60 +	RLibrary lib;
    1.61 +	test(KErrCorrupt == lib.Load(KWrongDll));
    1.62 +	delete fileman;
    1.63 +	rfs.Close();
    1.64 +#endif
    1.65 +	return KErrNone;
    1.66 +	}
    1.67 +
    1.68 +TInt E32Main()
    1.69 +	{
    1.70 +	test.Title();
    1.71 +
    1.72 +	test.Printf(_L("Test failure modes/codes when loading bad & absent libraries and processes\n"));
    1.73 +	
    1.74 +	test.Start(_L("Test DLL loading fails gracefully"));
    1.75 +	RLibrary library;
    1.76 +	
    1.77 +	// test non-existent DLL loading
    1.78 +	test(library.Load(_L("t_asdasdsadsasd.dll"))==KErrNotFound);
    1.79 +
    1.80 +	// test invalid name loading
    1.81 +	test(library.Load(_L("z:\\sys\\bin\\")) == KErrNotFound);
    1.82 +	test(library.Load(_L("\\sys\\bin\\")) == KErrNotFound);
    1.83 +	test(library.Load(_L("..")) == KErrNotFound);
    1.84 +	test(library.Load(_L(".")) == KErrNotFound);
    1.85 +	TInt r = library.Load(_L("\\."));
    1.86 +	test(r == KErrNotFound || r == KErrAccessDenied);
    1.87 +	test(library.Load(_L(".\\")) == KErrNotFound);
    1.88 +	test(library.Load(_L("\\")) == KErrNotFound);
    1.89 +	test(library.Load(_L("")) == KErrNotFound);
    1.90 +
    1.91 +	// test loading from odd/bad paths
    1.92 +	test(library.Load(_L("t_foo.dll"), _L("..")) == KErrNotFound);
    1.93 +	test(library.Load(_L("t_foo.dll"), _L(".")) == KErrNotFound);
    1.94 +	test(library.Load(_L("t_foo.dll"), _L("\\;")) == KErrNotFound);
    1.95 +	test(library.Load(_L("t_foo.dll"), _L(";\\")) == KErrNotFound);
    1.96 +	test(library.Load(_L("t_foo.dll"), _L(";")) == KErrNotFound);
    1.97 +	test(library.Load(_L("t_foo.dll"), _L("\\")) == KErrNotFound);
    1.98 +	test(library.Load(_L("t_foo.dll"), _L("")) == KErrNotFound);
    1.99 +
   1.100 +	// test loading a too long name fails
   1.101 +	TBufC16<KMaxFileName+1> buf;
   1.102 +	TPtr16 ptr = buf.Des();
   1.103 +	ptr.SetLength(KMaxFileName+1);
   1.104 +	test(library.Load(ptr) == KErrBadName);
   1.105 +	
   1.106 +	test.Next(_L("Test EXE loading fails gracefully"));
   1.107 +	RProcess process;
   1.108 +	
   1.109 +	//  test non-existent EXE loading
   1.110 +	test(process.Create(_L("t_safcxvxcvsw.exe"), _L("x")) == KErrNotFound);
   1.111 +	
   1.112 +	
   1.113 +	// test invalid name loading
   1.114 +	test(process.Create(_L("z:\\sys\\bin\\"),_L("x")) == KErrNotFound);
   1.115 +	test(process.Create(_L("\\sys\\bin\\"),_L("x")) == KErrNotFound);
   1.116 +	test(process.Create(_L(".."), _L("x")) == KErrNotFound);
   1.117 +	test(process.Create(_L("."), _L("x")) == KErrNotFound);
   1.118 +	r = process.Create(_L("\\."), _L("x"));
   1.119 +	test(r == KErrNotFound || r == KErrAccessDenied);
   1.120 +	test(process.Create(_L(".\\"), _L("x")) == KErrNotFound);
   1.121 +	test(process.Create(_L("\\"), _L("x")) == KErrNotFound);
   1.122 +	test(process.Create(_L(""), _L("x")) == KErrNotFound);
   1.123 +	
   1.124 +	// test loading a too long name fails
   1.125 +	test(process.Create(ptr, _L("x")) == KErrBadName);
   1.126 +	
   1.127 +	test.Next(_L("Test loading dll with incorrect verison number as part of its name"));
   1.128 +	__UHEAP_MARK;
   1.129 +	CTrapCleanup* cleanup=CTrapCleanup::New();
   1.130 +	TRAPD(ret,TestVersionL());
   1.131 +	test(ret==KErrNone);
   1.132 +	delete cleanup;
   1.133 +	__UHEAP_MARKEND;
   1.134 +	test.End();
   1.135 +
   1.136 +	return KErrNone;
   1.137 +	}