os/ossrv/lowlevellibsandfws/apputils/tsrc/t_fileutils.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/tsrc/t_fileutils.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,149 @@
     1.4 +// Copyright (c) 2004-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 "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 +// Tests EikFileUtils::SortByTable() function.
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +#include <f32file.h>
    1.23 +#include <bautils.h>
    1.24 +
    1.25 +LOCAL_D RTest test(_L("t_fileutils.exe"));
    1.26 +
    1.27 +const TInt KSortTableUid1=0x3f631;
    1.28 +const TInt KSortTableUid2=0x276a9;
    1.29 +
    1.30 +/**
    1.31 +@SYMTestCaseID          SYSLIB-BAFL-CT-0486
    1.32 +@SYMTestCaseDesc        Tests for the sorting of files containing an array of UIDs.
    1.33 +@SYMTestPriority        High
    1.34 +@SYMTestActions         Tests BaflUtils::SortByTable() function.
    1.35 +@SYMTestExpectedResults Tests must not fail
    1.36 +@SYMREQ                 REQ0000
    1.37 +*/
    1.38 +void TestSortByTableL()
    1.39 +	{
    1.40 +	CDir* theFileList;
    1.41 +	TInt theAttribs=KEntryAttMatchMask|KEntryAttAllowUid;
    1.42 +	TFileName theCurrentPath = _L("Z:\\system\\documents\\baflsortbytabletest\\");
    1.43 +
    1.44 +    RFs fileSession;
    1.45 +    User::LeaveIfError(fileSession.Connect());
    1.46 +	CleanupClosePushL(fileSession);
    1.47 +
    1.48 +	TInt ret=fileSession.GetDir(theCurrentPath,theAttribs,ESortByName,theFileList);
    1.49 +	test(ret==KErrNone);
    1.50 +	CleanupStack::PushL(theFileList);
    1.51 +
    1.52 +	CBaflFileSortTable*theTable = new (ELeave) CBaflFileSortTable();
    1.53 +	CleanupStack::PushL(theTable);
    1.54 +
    1.55 +	TInt insertErr;
    1.56 +
    1.57 +	TRAP(insertErr,theTable->InsertL(0,TUid::Uid(KSortTableUid1)));
    1.58 +	test(insertErr==KErrNone);
    1.59 +
    1.60 +	TRAP(insertErr,theTable->InsertL(1,TUid::Uid(KSortTableUid2)));
    1.61 +	test(insertErr==KErrNone);
    1.62 +
    1.63 +	test.Printf(_L("\nGet the names of the files sorted by alphabetical order\n"));
    1.64 +	for(TInt theIndex1 = 0; theIndex1 < theFileList->Count(); theIndex1++)
    1.65 +		{
    1.66 +		TEntry	theEntry = (*theFileList)[theIndex1];
    1.67 +		TUid	theUid1		= theEntry[2];
    1.68 +		test.Printf(_L("The %d file in list %S, Uid = 0x%x\n"), theIndex1 + 1, &theEntry.iName, theUid1.iUid);
    1.69 +		switch(theIndex1)
    1.70 +			{
    1.71 +		case 0:
    1.72 +			test(theEntry.iName == _L("addcert.rsc"));
    1.73 +			break;
    1.74 +		case 1:
    1.75 +			test(theEntry.iName == _L("help.rsc"));
    1.76 +			break;
    1.77 +		case 2:
    1.78 +			test(theEntry.iName == _L("msgeditor.rsc"));
    1.79 +			break;
    1.80 +		case 3:
    1.81 +			test(theEntry.iName == _L("smlprogress.rsc"));
    1.82 +			break;
    1.83 +		default:
    1.84 +			break;
    1.85 +			}
    1.86 +		}
    1.87 +
    1.88 +	TInt sortErr = BaflUtils::SortByTable(*theFileList, theTable);
    1.89 +	test(sortErr==KErrNone);
    1.90 +
    1.91 +	test.Printf(_L("\nGet the names of the files sorted by the Uid's table\n"));
    1.92 +	for(TInt theIndex = 0; theIndex < theFileList->Count(); theIndex++)
    1.93 +		{
    1.94 +		TEntry	theEntry = (*theFileList)[theIndex];
    1.95 +		TUid	theUid1		= theEntry[2];
    1.96 +
    1.97 +		test.Printf(_L("The %d file in list %S, Uid = 0x%x\n"), theIndex + 1, &theEntry.iName, theUid1.iUid);
    1.98 +		switch(theIndex)
    1.99 +			{
   1.100 +		case 0:
   1.101 +			test(theEntry.iName == _L("msgeditor.rsc"));
   1.102 +			break;
   1.103 +		case 1:
   1.104 +			test(theEntry.iName == _L("help.rsc"));
   1.105 +			break;
   1.106 +		case 2:
   1.107 +			test(theEntry.iName == _L("addcert.rsc"));
   1.108 +			break;
   1.109 +		case 3:
   1.110 +			test(theEntry.iName == _L("smlprogress.rsc"));
   1.111 +			break;
   1.112 +		default:
   1.113 +			break;
   1.114 +			}
   1.115 +		}
   1.116 +	CleanupStack::PopAndDestroy(3, &fileSession);
   1.117 +	}
   1.118 +
   1.119 +
   1.120 +void DoTestsL()
   1.121 +	{
   1.122 +	__UHEAP_MARK;
   1.123 +
   1.124 +	TRAPD(testsortErr,TestSortByTableL());
   1.125 +	test(testsortErr==KErrNone);
   1.126 +
   1.127 +	__UHEAP_MARKEND;
   1.128 +	}
   1.129 +
   1.130 +
   1.131 +GLDEF_C TInt E32Main()
   1.132 +	{
   1.133 +	__UHEAP_MARK;
   1.134 +
   1.135 +	test.Title();
   1.136 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0486 SORT BY TABLE TEST "));
   1.137 +
   1.138 +	// get clean-up stack
   1.139 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.140 +
   1.141 +	test (cleanup!=0);
   1.142 +
   1.143 +	TRAPD(err,DoTestsL());
   1.144 +	test(err==KErrNone);
   1.145 +
   1.146 +	delete cleanup;
   1.147 +	test.End();
   1.148 +	test.Close();
   1.149 +
   1.150 +	__UHEAP_MARKEND;
   1.151 +	return(KErrNone);
   1.152 +	}