os/kernelhwsrv/kerneltest/e32test/dll/t_loadfail.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\dll\t_loadfail.cpp
sl@0
    15
// Overview:
sl@0
    16
// Tests failure codes when loading a RProcess or RLibrary.
sl@0
    17
// Introduced as test for defect DEF092502
sl@0
    18
// API Information:
sl@0
    19
// RProcess, RLibrary
sl@0
    20
// Details:
sl@0
    21
// - Test attempting to open a non-existent DLL fails gracefully
sl@0
    22
// - Test attempting to open a DLL of an invalid name fails gracefully
sl@0
    23
// - Test attempting to open a non-existent EXE fails gracefully
sl@0
    24
// - Test attempting to open an EXE of an invalid name fails gracefully
sl@0
    25
// - Test loading a dll with an incorrect version number as part of it name
sl@0
    26
// will return KErrCorupt
sl@0
    27
// Platforms/Drives/Compatibility:
sl@0
    28
// All
sl@0
    29
// Assumptions/Requirement/Pre-requisites:
sl@0
    30
// Assumes drive 'z' always contains \img\t_ver1{00010001}.dll
sl@0
    31
// Assumes drive 'c' is writeable
sl@0
    32
// Failures and causes:
sl@0
    33
// Base Port information:
sl@0
    34
// Error codes returned on h/w and emulator should be the same
sl@0
    35
// 
sl@0
    36
//
sl@0
    37
sl@0
    38
#include <e32test.h>
sl@0
    39
#include <f32file.h>
sl@0
    40
sl@0
    41
RTest test(_L("T_LOADFAIL"));
sl@0
    42
sl@0
    43
// Test loading dll with incorrect version number in the name returns KErrCorrupt
sl@0
    44
// as the loader will compare the image header version number against that in the
sl@0
    45
// image file's name
sl@0
    46
LOCAL_D TInt TestVersionL()
sl@0
    47
	{
sl@0
    48
// Test only valid on target h/w as emulator uses MS Windows loader which doesn't allow verison 
sl@0
    49
// no. to be in part of the dll name.
sl@0
    50
#ifndef __WINS__
sl@0
    51
	RFs rfs;
sl@0
    52
	rfs.Connect();
sl@0
    53
	CFileMan *fileman = CFileMan::NewL(rfs);
sl@0
    54
	_LIT(KCorrectDll,"z:\\img\\t_ver1{00010001}.dll");
sl@0
    55
	_LIT(KWrongDll,"c:\\sys\\bin\\t_ver1{00010011}.dll");
sl@0
    56
	test(KErrNone == fileman->Copy(KCorrectDll,KWrongDll,CFileMan::ERecurse));
sl@0
    57
	RLibrary lib;
sl@0
    58
	test(KErrCorrupt == lib.Load(KWrongDll));
sl@0
    59
	delete fileman;
sl@0
    60
	rfs.Close();
sl@0
    61
#endif
sl@0
    62
	return KErrNone;
sl@0
    63
	}
sl@0
    64
sl@0
    65
TInt E32Main()
sl@0
    66
	{
sl@0
    67
	test.Title();
sl@0
    68
sl@0
    69
	test.Printf(_L("Test failure modes/codes when loading bad & absent libraries and processes\n"));
sl@0
    70
	
sl@0
    71
	test.Start(_L("Test DLL loading fails gracefully"));
sl@0
    72
	RLibrary library;
sl@0
    73
	
sl@0
    74
	// test non-existent DLL loading
sl@0
    75
	test(library.Load(_L("t_asdasdsadsasd.dll"))==KErrNotFound);
sl@0
    76
sl@0
    77
	// test invalid name loading
sl@0
    78
	test(library.Load(_L("z:\\sys\\bin\\")) == KErrNotFound);
sl@0
    79
	test(library.Load(_L("\\sys\\bin\\")) == KErrNotFound);
sl@0
    80
	test(library.Load(_L("..")) == KErrNotFound);
sl@0
    81
	test(library.Load(_L(".")) == KErrNotFound);
sl@0
    82
	TInt r = library.Load(_L("\\."));
sl@0
    83
	test(r == KErrNotFound || r == KErrAccessDenied);
sl@0
    84
	test(library.Load(_L(".\\")) == KErrNotFound);
sl@0
    85
	test(library.Load(_L("\\")) == KErrNotFound);
sl@0
    86
	test(library.Load(_L("")) == KErrNotFound);
sl@0
    87
sl@0
    88
	// test loading from odd/bad paths
sl@0
    89
	test(library.Load(_L("t_foo.dll"), _L("..")) == KErrNotFound);
sl@0
    90
	test(library.Load(_L("t_foo.dll"), _L(".")) == KErrNotFound);
sl@0
    91
	test(library.Load(_L("t_foo.dll"), _L("\\;")) == KErrNotFound);
sl@0
    92
	test(library.Load(_L("t_foo.dll"), _L(";\\")) == KErrNotFound);
sl@0
    93
	test(library.Load(_L("t_foo.dll"), _L(";")) == KErrNotFound);
sl@0
    94
	test(library.Load(_L("t_foo.dll"), _L("\\")) == KErrNotFound);
sl@0
    95
	test(library.Load(_L("t_foo.dll"), _L("")) == KErrNotFound);
sl@0
    96
sl@0
    97
	// test loading a too long name fails
sl@0
    98
	TBufC16<KMaxFileName+1> buf;
sl@0
    99
	TPtr16 ptr = buf.Des();
sl@0
   100
	ptr.SetLength(KMaxFileName+1);
sl@0
   101
	test(library.Load(ptr) == KErrBadName);
sl@0
   102
	
sl@0
   103
	test.Next(_L("Test EXE loading fails gracefully"));
sl@0
   104
	RProcess process;
sl@0
   105
	
sl@0
   106
	//  test non-existent EXE loading
sl@0
   107
	test(process.Create(_L("t_safcxvxcvsw.exe"), _L("x")) == KErrNotFound);
sl@0
   108
	
sl@0
   109
	
sl@0
   110
	// test invalid name loading
sl@0
   111
	test(process.Create(_L("z:\\sys\\bin\\"),_L("x")) == KErrNotFound);
sl@0
   112
	test(process.Create(_L("\\sys\\bin\\"),_L("x")) == KErrNotFound);
sl@0
   113
	test(process.Create(_L(".."), _L("x")) == KErrNotFound);
sl@0
   114
	test(process.Create(_L("."), _L("x")) == KErrNotFound);
sl@0
   115
	r = process.Create(_L("\\."), _L("x"));
sl@0
   116
	test(r == KErrNotFound || r == KErrAccessDenied);
sl@0
   117
	test(process.Create(_L(".\\"), _L("x")) == KErrNotFound);
sl@0
   118
	test(process.Create(_L("\\"), _L("x")) == KErrNotFound);
sl@0
   119
	test(process.Create(_L(""), _L("x")) == KErrNotFound);
sl@0
   120
	
sl@0
   121
	// test loading a too long name fails
sl@0
   122
	test(process.Create(ptr, _L("x")) == KErrBadName);
sl@0
   123
	
sl@0
   124
	test.Next(_L("Test loading dll with incorrect verison number as part of its name"));
sl@0
   125
	__UHEAP_MARK;
sl@0
   126
	CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0
   127
	TRAPD(ret,TestVersionL());
sl@0
   128
	test(ret==KErrNone);
sl@0
   129
	delete cleanup;
sl@0
   130
	__UHEAP_MARKEND;
sl@0
   131
	test.End();
sl@0
   132
sl@0
   133
	return KErrNone;
sl@0
   134
	}