| 
sl@0
 | 
     1  | 
// Copyright (c) 1997-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 "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  | 
// Started by BLB, May 1996
  | 
| 
sl@0
 | 
    15  | 
// Test comms device
  | 
| 
sl@0
 | 
    16  | 
// 
  | 
| 
sl@0
 | 
    17  | 
//
  | 
| 
sl@0
 | 
    18  | 
  | 
| 
sl@0
 | 
    19  | 
#include <e32test.h>
  | 
| 
sl@0
 | 
    20  | 
#include <f32file.h>
  | 
| 
sl@0
 | 
    21  | 
#include "T_LIBT.H"
  | 
| 
sl@0
 | 
    22  | 
#include <baliba.h>
  | 
| 
sl@0
 | 
    23  | 
  | 
| 
sl@0
 | 
    24  | 
LOCAL_D RTest test(_L("Unloader"));
 | 
| 
sl@0
 | 
    25  | 
LOCAL_D RFs TheFs;
  | 
| 
sl@0
 | 
    26  | 
_LIT(KLibraryName, "libtst.tpr");
  | 
| 
sl@0
 | 
    27  | 
typedef CLibTest* (*NewTestL)();
  | 
| 
sl@0
 | 
    28  | 
typedef TLibAssoc<CLibTest> TTestAssoc;
  | 
| 
sl@0
 | 
    29  | 
  | 
| 
sl@0
 | 
    30  | 
/**
  | 
| 
sl@0
 | 
    31  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0415
  | 
| 
sl@0
 | 
    32  | 
@SYMTestCaseDesc        CLibTest class functionality test
  | 
| 
sl@0
 | 
    33  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
    34  | 
@SYMTestActions         Library tester
  | 
| 
sl@0
 | 
    35  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
    36  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
    37  | 
*/
  | 
| 
sl@0
 | 
    38  | 
void testLibClass(CLibTest* aTester)
  | 
| 
sl@0
 | 
    39  | 
	{
 | 
| 
sl@0
 | 
    40  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0415 "));
 | 
| 
sl@0
 | 
    41  | 
	test(aTester->Test1()==1);
  | 
| 
sl@0
 | 
    42  | 
	test(aTester->Test2()==2);
  | 
| 
sl@0
 | 
    43  | 
	test(aTester->Test3()==3);
  | 
| 
sl@0
 | 
    44  | 
	}
  | 
| 
sl@0
 | 
    45  | 
  | 
| 
sl@0
 | 
    46  | 
/**
  | 
| 
sl@0
 | 
    47  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0416
  | 
| 
sl@0
 | 
    48  | 
@SYMTestCaseDesc        Tests for constant CLibTest class
  | 
| 
sl@0
 | 
    49  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
    50  | 
@SYMTestActions         Library tester
  | 
| 
sl@0
 | 
    51  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
    52  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
    53  | 
*/
  | 
| 
sl@0
 | 
    54  | 
void testLibClassC(const CLibTest* aTester)
  | 
| 
sl@0
 | 
    55  | 
	{
 | 
| 
sl@0
 | 
    56  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0416 "));
 | 
| 
sl@0
 | 
    57  | 
	test(aTester->Test1()==1);
  | 
| 
sl@0
 | 
    58  | 
	test(aTester->Test2()==2);
  | 
| 
sl@0
 | 
    59  | 
	}
  | 
| 
sl@0
 | 
    60  | 
  | 
| 
sl@0
 | 
    61  | 
/**
  | 
| 
sl@0
 | 
    62  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-1283
  | 
| 
sl@0
 | 
    63  | 
@SYMTestCaseDesc        Tests for RLibrary::Load(),RLibrary::Lookup() function
  | 
| 
sl@0
 | 
    64  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
    65  | 
@SYMTestActions         Attempt to load a named DLL.
  | 
| 
sl@0
 | 
    66  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
    67  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
    68  | 
*/
  | 
| 
sl@0
 | 
    69  | 
void LoadCreate(CLibTest*& aTest,RLibrary& aLib)
  | 
| 
sl@0
 | 
    70  | 
	{
 | 
| 
sl@0
 | 
    71  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1283 "));
 | 
| 
sl@0
 | 
    72  | 
	TInt error=aLib.Load(KLibraryName);
  | 
| 
sl@0
 | 
    73  | 
	test(error==KErrNone);
  | 
| 
sl@0
 | 
    74  | 
	NewTestL createClass=(NewTestL)aLib.Lookup(1);
  | 
| 
sl@0
 | 
    75  | 
	aTest=(*createClass)();
  | 
| 
sl@0
 | 
    76  | 
	}
  | 
| 
sl@0
 | 
    77  | 
  | 
| 
sl@0
 | 
    78  | 
/**
  | 
| 
sl@0
 | 
    79  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0417
  | 
| 
sl@0
 | 
    80  | 
@SYMTestCaseDesc        Manual load of library test
  | 
| 
sl@0
 | 
    81  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
    82  | 
@SYMTestActions         Tests for library through manual load.
  | 
| 
sl@0
 | 
    83  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
    84  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
    85  | 
*/
  | 
| 
sl@0
 | 
    86  | 
void testManualLoad()
  | 
| 
sl@0
 | 
    87  | 
	{
 | 
| 
sl@0
 | 
    88  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0417 Manual "));
 | 
| 
sl@0
 | 
    89  | 
	RLibrary library;
  | 
| 
sl@0
 | 
    90  | 
	CLibTest* tester;
  | 
| 
sl@0
 | 
    91  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
    92  | 
	testLibClass(tester);
  | 
| 
sl@0
 | 
    93  | 
	testLibClassC(tester);
  | 
| 
sl@0
 | 
    94  | 
	delete(tester);
  | 
| 
sl@0
 | 
    95  | 
	library.Close();
  | 
| 
sl@0
 | 
    96  | 
	}
  | 
| 
sl@0
 | 
    97  | 
  | 
| 
sl@0
 | 
    98  | 
/**
  | 
| 
sl@0
 | 
    99  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0418
  | 
| 
sl@0
 | 
   100  | 
@SYMTestCaseDesc        Smart load of library test
  | 
| 
sl@0
 | 
   101  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
   102  | 
@SYMTestActions         Tests for library through smart load.
  | 
| 
sl@0
 | 
   103  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
   104  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
   105  | 
*/
  | 
| 
sl@0
 | 
   106  | 
void testSmartLoad()
  | 
| 
sl@0
 | 
   107  | 
	{
 | 
| 
sl@0
 | 
   108  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0418 Smart "));
 | 
| 
sl@0
 | 
   109  | 
	RLibrary library;
  | 
| 
sl@0
 | 
   110  | 
	CLibTest* tester;
  | 
| 
sl@0
 | 
   111  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   112  | 
	testLibClass(tester);
  | 
| 
sl@0
 | 
   113  | 
	testLibClassC(tester);
  | 
| 
sl@0
 | 
   114  | 
	TTestAssoc assoc(library,tester);
  | 
| 
sl@0
 | 
   115  | 
	testLibClass(assoc.Ptr());
  | 
| 
sl@0
 | 
   116  | 
	testLibClassC(assoc.Ptr());
  | 
| 
sl@0
 | 
   117  | 
	assoc.Unload();
  | 
| 
sl@0
 | 
   118  | 
	assoc.Unload();
  | 
| 
sl@0
 | 
   119  | 
	//
  | 
| 
sl@0
 | 
   120  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   121  | 
	TTestAssoc assoc2;
  | 
| 
sl@0
 | 
   122  | 
	assoc2.Set(library,tester);
  | 
| 
sl@0
 | 
   123  | 
	//
  | 
| 
sl@0
 | 
   124  | 
//	Following will panic since not cleared first
  | 
| 
sl@0
 | 
   125  | 
//	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   126  | 
//	assoc2.Set(library,tester);
  | 
| 
sl@0
 | 
   127  | 
	//
  | 
| 
sl@0
 | 
   128  | 
//	Following will not be possible
  | 
| 
sl@0
 | 
   129  | 
//	delete(assoc2);
  | 
| 
sl@0
 | 
   130  | 
	assoc2.Unload();
  | 
| 
sl@0
 | 
   131  | 
	}
  | 
| 
sl@0
 | 
   132  | 
  | 
| 
sl@0
 | 
   133  | 
/**
  | 
| 
sl@0
 | 
   134  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0419
  | 
| 
sl@0
 | 
   135  | 
@SYMTestCaseDesc        Smart load of library test
  | 
| 
sl@0
 | 
   136  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
   137  | 
@SYMTestActions         Tests for Leave,cleanupstack on Leave
  | 
| 
sl@0
 | 
   138  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
   139  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
   140  | 
*/
  | 
| 
sl@0
 | 
   141  | 
void testSmartLeaveL(TTestAssoc& aAssoc,TBool aLeave)
  | 
| 
sl@0
 | 
   142  | 
	{
 | 
| 
sl@0
 | 
   143  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0419 "));
 | 
| 
sl@0
 | 
   144  | 
	CleanupStack::PushL((TCleanupItem)aAssoc);
  | 
| 
sl@0
 | 
   145  | 
	if (aLeave)
  | 
| 
sl@0
 | 
   146  | 
		User::Leave(KErrNone);
  | 
| 
sl@0
 | 
   147  | 
	CleanupStack::PopAndDestroy();
  | 
| 
sl@0
 | 
   148  | 
	}
  | 
| 
sl@0
 | 
   149  | 
  | 
| 
sl@0
 | 
   150  | 
/**
  | 
| 
sl@0
 | 
   151  | 
@SYMTestCaseID          SYSLIB-BAFL-CT-0420
  | 
| 
sl@0
 | 
   152  | 
@SYMTestCaseDesc        Wrapper function calling library tester functions
  | 
| 
sl@0
 | 
   153  | 
@SYMTestPriority        Medium
  | 
| 
sl@0
 | 
   154  | 
@SYMTestActions         Call up library tester functions
  | 
| 
sl@0
 | 
   155  | 
@SYMTestExpectedResults Tests must not fail
  | 
| 
sl@0
 | 
   156  | 
@SYMREQ                 REQ0000
  | 
| 
sl@0
 | 
   157  | 
*/
  | 
| 
sl@0
 | 
   158  | 
void testSmartClass()
  | 
| 
sl@0
 | 
   159  | 
	{
 | 
| 
sl@0
 | 
   160  | 
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0420 Pointer functions "));
 | 
| 
sl@0
 | 
   161  | 
	RLibrary library;
  | 
| 
sl@0
 | 
   162  | 
	CLibTest* tester;
  | 
| 
sl@0
 | 
   163  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   164  | 
	TTestAssoc assoc(library,tester);
  | 
| 
sl@0
 | 
   165  | 
	testLibClass(assoc);
  | 
| 
sl@0
 | 
   166  | 
	testLibClassC(assoc);
  | 
| 
sl@0
 | 
   167  | 
	assoc.Unload();
  | 
| 
sl@0
 | 
   168  | 
	//
  | 
| 
sl@0
 | 
   169  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   170  | 
	assoc.Set(library,tester);
  | 
| 
sl@0
 | 
   171  | 
	TRAPD(error,testSmartLeaveL(assoc,ETrue));
  | 
| 
sl@0
 | 
   172  | 
	test(error==KErrNone);
  | 
| 
sl@0
 | 
   173  | 
	//
  | 
| 
sl@0
 | 
   174  | 
	LoadCreate(tester,library);
  | 
| 
sl@0
 | 
   175  | 
	assoc.Set(library,tester);
  | 
| 
sl@0
 | 
   176  | 
	TRAP(error,testSmartLeaveL(assoc,EFalse));
  | 
| 
sl@0
 | 
   177  | 
	test(error==KErrNone);
  | 
| 
sl@0
 | 
   178  | 
	}
  | 
| 
sl@0
 | 
   179  | 
  | 
| 
sl@0
 | 
   180  | 
GLDEF_C TInt E32Main()
  | 
| 
sl@0
 | 
   181  | 
    {
 | 
| 
sl@0
 | 
   182  | 
	test.Title();
  | 
| 
sl@0
 | 
   183  | 
	test.Start(_L("Unloader "));
 | 
| 
sl@0
 | 
   184  | 
	TInt error=TheFs.Connect();
  | 
| 
sl@0
 | 
   185  | 
	test(error==KErrNone);
  | 
| 
sl@0
 | 
   186  | 
	__UHEAP_MARK;
  | 
| 
sl@0
 | 
   187  | 
	CTrapCleanup *trapCleanup=CTrapCleanup::New();
  | 
| 
sl@0
 | 
   188  | 
	//
  | 
| 
sl@0
 | 
   189  | 
	testManualLoad();
  | 
| 
sl@0
 | 
   190  | 
	testSmartLoad();
  | 
| 
sl@0
 | 
   191  | 
	testSmartClass();
  | 
| 
sl@0
 | 
   192  | 
	//
  | 
| 
sl@0
 | 
   193  | 
	delete(trapCleanup);
  | 
| 
sl@0
 | 
   194  | 
	__UHEAP_MARKEND;
  | 
| 
sl@0
 | 
   195  | 
    test.End();
  | 
| 
sl@0
 | 
   196  | 
	test.Close();
  | 
| 
sl@0
 | 
   197  | 
	return(0);
  | 
| 
sl@0
 | 
   198  | 
    }
  |