sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\dll\t_loadfail.cpp sl@0: // Overview: sl@0: // Tests failure codes when loading a RProcess or RLibrary. sl@0: // Introduced as test for defect DEF092502 sl@0: // API Information: sl@0: // RProcess, RLibrary sl@0: // Details: sl@0: // - Test attempting to open a non-existent DLL fails gracefully sl@0: // - Test attempting to open a DLL of an invalid name fails gracefully sl@0: // - Test attempting to open a non-existent EXE fails gracefully sl@0: // - Test attempting to open an EXE of an invalid name fails gracefully sl@0: // - Test loading a dll with an incorrect version number as part of it name sl@0: // will return KErrCorupt sl@0: // Platforms/Drives/Compatibility: sl@0: // All sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Assumes drive 'z' always contains \img\t_ver1{00010001}.dll sl@0: // Assumes drive 'c' is writeable sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // Error codes returned on h/w and emulator should be the same sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: RTest test(_L("T_LOADFAIL")); sl@0: sl@0: // Test loading dll with incorrect version number in the name returns KErrCorrupt sl@0: // as the loader will compare the image header version number against that in the sl@0: // image file's name sl@0: LOCAL_D TInt TestVersionL() sl@0: { sl@0: // Test only valid on target h/w as emulator uses MS Windows loader which doesn't allow verison sl@0: // no. to be in part of the dll name. sl@0: #ifndef __WINS__ sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: CFileMan *fileman = CFileMan::NewL(rfs); sl@0: _LIT(KCorrectDll,"z:\\img\\t_ver1{00010001}.dll"); sl@0: _LIT(KWrongDll,"c:\\sys\\bin\\t_ver1{00010011}.dll"); sl@0: test(KErrNone == fileman->Copy(KCorrectDll,KWrongDll,CFileMan::ERecurse)); sl@0: RLibrary lib; sl@0: test(KErrCorrupt == lib.Load(KWrongDll)); sl@0: delete fileman; sl@0: rfs.Close(); sl@0: #endif sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: sl@0: test.Printf(_L("Test failure modes/codes when loading bad & absent libraries and processes\n")); sl@0: sl@0: test.Start(_L("Test DLL loading fails gracefully")); sl@0: RLibrary library; sl@0: sl@0: // test non-existent DLL loading sl@0: test(library.Load(_L("t_asdasdsadsasd.dll"))==KErrNotFound); sl@0: sl@0: // test invalid name loading sl@0: test(library.Load(_L("z:\\sys\\bin\\")) == KErrNotFound); sl@0: test(library.Load(_L("\\sys\\bin\\")) == KErrNotFound); sl@0: test(library.Load(_L("..")) == KErrNotFound); sl@0: test(library.Load(_L(".")) == KErrNotFound); sl@0: TInt r = library.Load(_L("\\.")); sl@0: test(r == KErrNotFound || r == KErrAccessDenied); sl@0: test(library.Load(_L(".\\")) == KErrNotFound); sl@0: test(library.Load(_L("\\")) == KErrNotFound); sl@0: test(library.Load(_L("")) == KErrNotFound); sl@0: sl@0: // test loading from odd/bad paths sl@0: test(library.Load(_L("t_foo.dll"), _L("..")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L(".")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L("\\;")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L(";\\")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L(";")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L("\\")) == KErrNotFound); sl@0: test(library.Load(_L("t_foo.dll"), _L("")) == KErrNotFound); sl@0: sl@0: // test loading a too long name fails sl@0: TBufC16 buf; sl@0: TPtr16 ptr = buf.Des(); sl@0: ptr.SetLength(KMaxFileName+1); sl@0: test(library.Load(ptr) == KErrBadName); sl@0: sl@0: test.Next(_L("Test EXE loading fails gracefully")); sl@0: RProcess process; sl@0: sl@0: // test non-existent EXE loading sl@0: test(process.Create(_L("t_safcxvxcvsw.exe"), _L("x")) == KErrNotFound); sl@0: sl@0: sl@0: // test invalid name loading sl@0: test(process.Create(_L("z:\\sys\\bin\\"),_L("x")) == KErrNotFound); sl@0: test(process.Create(_L("\\sys\\bin\\"),_L("x")) == KErrNotFound); sl@0: test(process.Create(_L(".."), _L("x")) == KErrNotFound); sl@0: test(process.Create(_L("."), _L("x")) == KErrNotFound); sl@0: r = process.Create(_L("\\."), _L("x")); sl@0: test(r == KErrNotFound || r == KErrAccessDenied); sl@0: test(process.Create(_L(".\\"), _L("x")) == KErrNotFound); sl@0: test(process.Create(_L("\\"), _L("x")) == KErrNotFound); sl@0: test(process.Create(_L(""), _L("x")) == KErrNotFound); sl@0: sl@0: // test loading a too long name fails sl@0: test(process.Create(ptr, _L("x")) == KErrBadName); sl@0: sl@0: test.Next(_L("Test loading dll with incorrect verison number as part of its name")); sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: TRAPD(ret,TestVersionL()); sl@0: test(ret==KErrNone); sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: test.End(); sl@0: sl@0: return KErrNone; sl@0: }