os/ossrv/lowlevellibsandfws/apputils/tsrc/T_BaflUtilsImp.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-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
// Tests some code internal to BaflUtils
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "BaUtilsImp.h"
sl@0
    19
#include <bautils.h>
sl@0
    20
#include <e32test.h>
sl@0
    21
#include <baflpan.h>
sl@0
    22
sl@0
    23
#define UNUSED_VAR(a) a = a
sl@0
    24
sl@0
    25
const TPtrC KValFolderName=_L("ValidFolderName");
sl@0
    26
const TPtrC KCurrentPath=_L("C:\\System\\Data\\");
sl@0
    27
const TPtrC KNoFolderName = _L("");
sl@0
    28
const TPtrC KInValidFolderName=_L("C:\\System\\Data\\InValid3+FollderName");
sl@0
    29
sl@0
    30
namespace
sl@0
    31
{
sl@0
    32
CTrapCleanup* TrapCleanup;
sl@0
    33
RTest test(_L("T_BaflUtilsImp - Internal Bafl function tests"));
sl@0
    34
}
sl@0
    35
sl@0
    36
class RTestDirectoryScanner : public RDirectoryScanner
sl@0
    37
	{
sl@0
    38
public:
sl@0
    39
	RTestDirectoryScanner(CDesCArray*& aMember)
sl@0
    40
		: iOpenError(0), iFilesThatExist(aMember)
sl@0
    41
		{
sl@0
    42
		for (TInt i = 0; i != 26; ++i)
sl@0
    43
			iDriveError[i] = 0;
sl@0
    44
		}
sl@0
    45
	virtual TInt Open(RFs&, const TDesC& aMatchPattern)
sl@0
    46
		{
sl@0
    47
		iMatch = aMatchPattern;
sl@0
    48
		iIndex = 0;
sl@0
    49
		return iOpenError;
sl@0
    50
		}
sl@0
    51
	virtual TInt Next(TEntry& aOut)
sl@0
    52
		{
sl@0
    53
		if (!iFilesThatExist)
sl@0
    54
			return KErrEof;
sl@0
    55
		while (iIndex < iFilesThatExist->Count())
sl@0
    56
			{
sl@0
    57
			TInt i = iIndex++;
sl@0
    58
			if (0 <= (*iFilesThatExist)[i].MatchF(iMatch))
sl@0
    59
				{
sl@0
    60
				TPtrC fullName=(*iFilesThatExist)[i];
sl@0
    61
				TParsePtrC name(fullName);
sl@0
    62
				aOut.iName=name.NameAndExt();
sl@0
    63
				if (1 < fullName.Length() && fullName[1] == ':')
sl@0
    64
					{
sl@0
    65
					TInt drive = fullName[0];
sl@0
    66
					if ('a' <= drive && drive <= 'z')
sl@0
    67
						drive -= 'a';
sl@0
    68
					else
sl@0
    69
						{
sl@0
    70
						ASSERT('A' <= drive && drive <= 'Z');
sl@0
    71
						drive -= 'A';
sl@0
    72
						}
sl@0
    73
					return iDriveError[drive];
sl@0
    74
					}
sl@0
    75
				return KErrNone;
sl@0
    76
				}
sl@0
    77
			}
sl@0
    78
		return KErrEof;
sl@0
    79
		}
sl@0
    80
	virtual void Close() {}
sl@0
    81
	TInt iOpenError;
sl@0
    82
	TInt iDriveError[26];
sl@0
    83
private:
sl@0
    84
	CDesCArray *&iFilesThatExist;
sl@0
    85
	TInt iIndex;
sl@0
    86
	TFileName iMatch;
sl@0
    87
	};
sl@0
    88
sl@0
    89
class TTestNearestLanguageFileFinder : public TNearestLanguageFileFinder
sl@0
    90
	{
sl@0
    91
public:
sl@0
    92
	TTestNearestLanguageFileFinder(const RFs& aFs)
sl@0
    93
		: TNearestLanguageFileFinder(aFs), iTestScanner(iFilesThatExist)
sl@0
    94
		{
sl@0
    95
		iFilesThatExist = 0;
sl@0
    96
		iFilesSearchedFor = 0;
sl@0
    97
		}
sl@0
    98
	~TTestNearestLanguageFileFinder()
sl@0
    99
		{
sl@0
   100
		delete iFilesThatExist;
sl@0
   101
		delete iFilesSearchedFor;
sl@0
   102
		}
sl@0
   103
	virtual TInt GetCustomResourceDriveNumber() const { return iCustomRscDrive; }
sl@0
   104
	virtual TBool FileExists(const TDesC& aFileName) const
sl@0
   105
		{
sl@0
   106
		test(aFileName[1] == ':');
sl@0
   107
		test(0 == aFileName.Left(1).CompareF(iDrivesChecked.Left(1)));
sl@0
   108
		iDrivesChecked.Delete(0, 1);
sl@0
   109
		test(0 <= aFileName.MatchF(iFileCheckedFor));
sl@0
   110
		if (iFilesSearchedFor)
sl@0
   111
			{
sl@0
   112
			test(0 == aFileName.CompareF((*iFilesSearchedFor)[0]));
sl@0
   113
			iFilesSearchedFor->Delete(0);
sl@0
   114
			}
sl@0
   115
		if (!iFilesThatExist)
sl@0
   116
			return EFalse;
sl@0
   117
		TInt i;
sl@0
   118
		iFilesThatExist->Find(aFileName, i);
sl@0
   119
		return (0 <= i && i < iFilesThatExist->Count())? ETrue : EFalse;
sl@0
   120
		}
sl@0
   121
	virtual RDirectoryScanner& DirectoryScanner() { return iTestScanner; }
sl@0
   122
sl@0
   123
	TInt iCustomRscDrive;
sl@0
   124
	CDesCArray* iFilesThatExist;
sl@0
   125
	// File that is expected to go into FileExists.
sl@0
   126
	// Can contain wildcards.
sl@0
   127
	TFileName iFileCheckedFor;
sl@0
   128
	// Drives expected in calls to FileExists. The first one is checked then
sl@0
   129
	// discarded each time FileExists is called.
sl@0
   130
	mutable TBuf<26> iDrivesChecked;
sl@0
   131
	CDesCArray* iFilesSearchedFor;
sl@0
   132
	RTestDirectoryScanner iTestScanner;
sl@0
   133
	};
sl@0
   134
sl@0
   135
void TestPath(const TLanguagePath& aPath, const TLanguage* aExpected, TInt aExpectedCount)
sl@0
   136
	{
sl@0
   137
	for (int i = 0; i != aExpectedCount; ++i)
sl@0
   138
		test(aPath[i] == *aExpected++);
sl@0
   139
	test(aPath[aExpectedCount] == ELangNone);
sl@0
   140
	}
sl@0
   141
sl@0
   142
const TLanguage ExpectedPath[] = { ELangFrench, ELangJapanese, ELangGerman, ELangGreek,
sl@0
   143
	ELangArabic, ELangEnglish, ELangItalian, ELangHebrew };
sl@0
   144
sl@0
   145
/**
sl@0
   146
@SYMTestCaseID          SYSLIB-BAFL-CT-0443
sl@0
   147
@SYMTestCaseDesc        Tests TLanguagePath class
sl@0
   148
@SYMTestPriority        High
sl@0
   149
@SYMTestActions         Test for adding different language paths
sl@0
   150
@SYMTestExpectedResults Test must not fail
sl@0
   151
@SYMREQ                 REQ0000
sl@0
   152
*/
sl@0
   153
void TestAddLanguage()
sl@0
   154
	{
sl@0
   155
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0443 "));
sl@0
   156
	TLanguagePath path;
sl@0
   157
	path[0] = ELangNone;
sl@0
   158
	AddLanguage(path, ELangNone);
sl@0
   159
	TestPath(path, ExpectedPath, 0);
sl@0
   160
	AddLanguage(path, ELangFrench);
sl@0
   161
	TestPath(path, ExpectedPath, 1);
sl@0
   162
	AddLanguage(path, ELangFrench);
sl@0
   163
	TestPath(path, ExpectedPath, 1);
sl@0
   164
	AddLanguage(path, ELangNone);
sl@0
   165
	TestPath(path, ExpectedPath, 1);
sl@0
   166
	AddLanguage(path, ELangFrench);
sl@0
   167
	TestPath(path, ExpectedPath, 1);
sl@0
   168
	AddLanguage(path, ELangJapanese);
sl@0
   169
	TestPath(path, ExpectedPath, 2);
sl@0
   170
	AddLanguage(path, ELangFrench);
sl@0
   171
	TestPath(path, ExpectedPath, 2);
sl@0
   172
	AddLanguage(path, ELangNone);
sl@0
   173
	TestPath(path, ExpectedPath, 2);
sl@0
   174
	AddLanguage(path, ELangGerman);
sl@0
   175
	TestPath(path, ExpectedPath, 3);
sl@0
   176
	AddLanguage(path, ELangGreek);
sl@0
   177
	TestPath(path, ExpectedPath, 4);
sl@0
   178
	AddLanguage(path, ELangArabic);
sl@0
   179
	TestPath(path, ExpectedPath, 5);
sl@0
   180
	AddLanguage(path, ELangNone);
sl@0
   181
	TestPath(path, ExpectedPath, 5);
sl@0
   182
	AddLanguage(path, ELangEnglish);
sl@0
   183
	TestPath(path, ExpectedPath, 6);
sl@0
   184
	AddLanguage(path, ELangItalian);
sl@0
   185
	TestPath(path, ExpectedPath, 7);
sl@0
   186
	AddLanguage(path, ELangNone);
sl@0
   187
	TestPath(path, ExpectedPath, 7);
sl@0
   188
	AddLanguage(path, ELangHebrew);
sl@0
   189
	TestPath(path, ExpectedPath, 8);
sl@0
   190
	AddLanguage(path, ELangHebrew);
sl@0
   191
	TestPath(path, ExpectedPath, 8);
sl@0
   192
	AddLanguage(path, ELangEnglish);
sl@0
   193
	TestPath(path, ExpectedPath, 8);
sl@0
   194
	AddLanguage(path, ELangItalian);
sl@0
   195
	TestPath(path, ExpectedPath, 8);
sl@0
   196
	AddLanguage(path, ELangNone);
sl@0
   197
	TestPath(path, ExpectedPath, 8);
sl@0
   198
	AddLanguage(path, ELangFrench);
sl@0
   199
	TestPath(path, ExpectedPath, 8);
sl@0
   200
	AddLanguage(path, ELangNone);
sl@0
   201
	TestPath(path, ExpectedPath, 8);
sl@0
   202
	AddLanguage(path, ELangGerman);
sl@0
   203
	TestPath(path, ExpectedPath, 8);
sl@0
   204
	}
sl@0
   205
sl@0
   206
struct SDowngradeTest
sl@0
   207
	{
sl@0
   208
	TLanguage iIn[4];
sl@0
   209
	TLanguage iOut[9];
sl@0
   210
	};
sl@0
   211
sl@0
   212
/**
sl@0
   213
@SYMTestCaseID          SYSLIB-BAFL-CT-0444
sl@0
   214
@SYMTestCaseDesc        Tests for the functionality of TLocale class
sl@0
   215
@SYMTestPriority        High
sl@0
   216
@SYMTestActions         Test for language downgrades
sl@0
   217
@SYMTestExpectedResults Test must not fail
sl@0
   218
@SYMREQ                 REQ0000
sl@0
   219
*/
sl@0
   220
void TestDowngrade(SDowngradeTest& aTest)
sl@0
   221
	{
sl@0
   222
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0444 "));
sl@0
   223
	TLocale loc;
sl@0
   224
	loc.SetLanguageDowngrade(0, aTest.iIn[1]);
sl@0
   225
	loc.SetLanguageDowngrade(1, aTest.iIn[2]);
sl@0
   226
	loc.SetLanguageDowngrade(2, aTest.iIn[3]);
sl@0
   227
	TLanguagePath path;
sl@0
   228
	MakeLanguageDowngradePath(path, aTest.iIn[0], ELangNone, loc);
sl@0
   229
	for (int i = 0; ; ++i)
sl@0
   230
		{
sl@0
   231
		test(i < 9);
sl@0
   232
		test(aTest.iOut[i] == path[i]);
sl@0
   233
		if (path[i] == ELangNone)
sl@0
   234
			return;
sl@0
   235
		}
sl@0
   236
	}
sl@0
   237
sl@0
   238
sl@0
   239
// Test Dialect enumeration.
sl@0
   240
// Each value represents a dialect (variant) of a TLanguage language.
sl@0
   241
// E.g. AmericanSprint is represented by ELangAmerican | EDialectSprint
sl@0
   242
sl@0
   243
// The dialect location -- top six bits
sl@0
   244
const TUint KDialectFactor=0x0400;
sl@0
   245
enum TDialect
sl@0
   246
	{
sl@0
   247
	// The following are example dialects for testing only
sl@0
   248
	EDialectSprint = (1*KDialectFactor),
sl@0
   249
	EDialectOrange = (2*KDialectFactor),
sl@0
   250
	EDialectMaximum = EDialectOrange // This must always be equal to the last TDialect enum.
sl@0
   251
	// Up to 63 dialects.
sl@0
   252
	};
sl@0
   253
sl@0
   254
const TLanguage ELangEnglishOrange = static_cast<TLanguage>(ELangEnglish|EDialectOrange);
sl@0
   255
const TLanguage ELangAmericanSprint = static_cast<TLanguage>(ELangAmerican|EDialectSprint);
sl@0
   256
sl@0
   257
SDowngradeTest DowngradeData[] =
sl@0
   258
	{
sl@0
   259
		// 0 = test language
sl@0
   260
		// 1-3 = language downgrade for locale
sl@0
   261
		// 4- = calculated language downgrade path, terminated with ELangNone.
sl@0
   262
		{{ELangEnglishOrange, ELangNone, ELangNone, ELangNone},
sl@0
   263
			{ELangEnglishOrange, ELangEnglish, ELangNone}},
sl@0
   264
		{{ELangAmericanSprint, ELangNone, ELangNone, ELangNone},
sl@0
   265
			{ELangAmericanSprint, ELangAmerican, ELangEnglish, ELangNone}},
sl@0
   266
		{{ELangFrench, ELangNone, ELangNone, ELangNone},
sl@0
   267
			{ELangFrench, ELangNone}},
sl@0
   268
		{{ELangSwissFrench, ELangNone, ELangNone, ELangNone},
sl@0
   269
			{ELangSwissFrench, ELangFrench, ELangNone}},
sl@0
   270
		{{ELangCanadianEnglish, ELangNone, ELangNone, ELangNone},
sl@0
   271
			{ELangCanadianEnglish, ELangAmerican, ELangEnglish, ELangNone}},
sl@0
   272
		{{ELangSwissFrench, ELangNone, ELangFrench, ELangNone},
sl@0
   273
			{ELangSwissFrench, ELangFrench, ELangNone}},
sl@0
   274
		{{ELangCanadianEnglish, ELangEnglish, ELangNone, ELangAmerican},
sl@0
   275
			{ELangCanadianEnglish, ELangEnglish, ELangAmerican, ELangNone}},
sl@0
   276
		{{ELangCanadianEnglish, ELangNone, ELangNone, ELangSwissFrench},
sl@0
   277
			{ELangCanadianEnglish, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
sl@0
   278
		{{ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench},
sl@0
   279
			{ELangCanadianEnglish, ELangFrench, ELangAmerican, ELangSwissFrench, ELangEnglish, ELangNone}},
sl@0
   280
		{{ELangCanadianEnglish, ELangNone, ELangGerman, ELangSwissFrench},
sl@0
   281
			{ELangCanadianEnglish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
sl@0
   282
		{{ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench},
sl@0
   283
			{ELangCanadianEnglish, ELangFinlandSwedish, ELangGerman, ELangSwissFrench, ELangAmerican, ELangEnglish, ELangNone}},
sl@0
   284
		{{ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish, ELangFinlandSwedish},
sl@0
   285
			{ELangFinlandSwedish, ELangSwedish, ELangNone}},
sl@0
   286
	};
sl@0
   287
sl@0
   288
/**
sl@0
   289
@SYMTestCaseID          SYSLIB-BAFL-CT-0445
sl@0
   290
@SYMTestCaseDesc        Tests for language downgrades
sl@0
   291
@SYMTestPriority        High
sl@0
   292
@SYMTestActions         Call up downgrade path test function
sl@0
   293
@SYMTestExpectedResults Test must not fail
sl@0
   294
@SYMREQ                 REQ0000
sl@0
   295
*/
sl@0
   296
void TestMakeLanguageDowngradePath()
sl@0
   297
	{
sl@0
   298
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0445 "));
sl@0
   299
	for (int i = 0; i != sizeof(DowngradeData)/sizeof(DowngradeData[0]); ++i)
sl@0
   300
		TestDowngrade(DowngradeData[i]);
sl@0
   301
	}
sl@0
   302
sl@0
   303
void SetUpFinderForLanguageAndDriveSearchL(
sl@0
   304
	TTestNearestLanguageFileFinder& aFinder)
sl@0
   305
	{
sl@0
   306
	aFinder.iDrives = _L("ZAG");
sl@0
   307
	aFinder.iFilesSearchedFor = new(ELeave) CDesCArraySeg(10);
sl@0
   308
	aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e02"));
sl@0
   309
	aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e02"));
sl@0
   310
	aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e02"));
sl@0
   311
	aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e15702")); //Extended lang
sl@0
   312
	aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e15702"));
sl@0
   313
	aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e15702"));
sl@0
   314
	aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.e01"));
sl@0
   315
	aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.e01"));
sl@0
   316
	aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.e01"));
sl@0
   317
	aFinder.iFilesSearchedFor->AppendL(_L("z:\\dir\\name.ext"));
sl@0
   318
	aFinder.iFilesSearchedFor->AppendL(_L("a:\\dir\\name.ext"));
sl@0
   319
	aFinder.iFilesSearchedFor->AppendL(_L("g:\\dir\\name.ext"));
sl@0
   320
	aFinder.iDrivesChecked = _L("zagzagzagzagzag");
sl@0
   321
	}
sl@0
   322
sl@0
   323
_LIT(KTestFileName1, "z:\\dir\\name.ext");
sl@0
   324
//_LIT(KTestFileName2, "z:\\dir\\náme.ext");
sl@0
   325
_LIT(KTestFileName2, "z:\\dir\\n\u00c1me.ext");
sl@0
   326
_LIT(KTestFileName3, "a:\\dir\\name.ext");
sl@0
   327
_LIT(KTestFileName4, "c:\\dir\\name.ext");
sl@0
   328
_LIT(KTestFileName5, "d:\\dir\\name.ext");
sl@0
   329
_LIT(KTestFileName6, "y:\\dir\\name.ext");
sl@0
   330
_LIT(KTestFileName7, "A:\\dir\\name.ext");
sl@0
   331
_LIT(KTestFileName8, "C:\\dir\\name.ext");
sl@0
   332
_LIT(KTestFileName9, "Y:\\dir\\name.ext");
sl@0
   333
_LIT(KTestFileName11, "\\abc\\defg.hijkl");
sl@0
   334
_LIT(KTestFileName256Chars, "\
sl@0
   335
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   336
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   337
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   338
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.ext");
sl@0
   339
sl@0
   340
_LIT(KExpectedFileName256Chars, "?:\
sl@0
   341
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   342
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   343
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz01234\
sl@0
   344
\\abcdefghijklmnopqrstuvwxyz01234\\abcdefghijklmnopqrstuvwxyz0.e");
sl@0
   345
_LIT(KExpectedFileName1, "?:\\dir\\name.e");
sl@0
   346
_LIT(KExpectedSuffix1, "xt");
sl@0
   347
_LIT(KExpectedFileName2, "?:\\abc\\defg.hij");
sl@0
   348
_LIT(KExpectedSuffix2, "kl");
sl@0
   349
_LIT(KTestFileName1French, "z:\\dir\\name.e02");
sl@0
   350
_LIT(KTestFileName1Japanese, "z:\\dir\\name.e32");
sl@0
   351
_LIT(KTestFileName1Mongolian, "z:\\dir\\name.e54321");
sl@0
   352
_LIT(KTestFileName1AmericanSprint, "z:\\dir\\name.e1034"); //American=0x0A, Sprint=0x0400. 0x040A=1034.
sl@0
   353
_LIT(KCheckedForFrench, "?:\\dir\\name.e02");
sl@0
   354
sl@0
   355
/**
sl@0
   356
@SYMTestCaseID          SYSLIB-BAFL-CT-0446
sl@0
   357
@SYMTestCaseDesc        Nearest language finder test
sl@0
   358
@SYMTestPriority        High
sl@0
   359
@SYMTestActions         Test drive sequence construction
sl@0
   360
						Test addition of language number
sl@0
   361
						Test searching each drive for the specified file
sl@0
   362
						Test searching language and drive down the language path
sl@0
   363
						Test filename matching
sl@0
   364
						Test searching for any language file within a drive
sl@0
   365
						Test searching all drives for any language
sl@0
   366
@SYMTestExpectedResults Test must not fail
sl@0
   367
@SYMREQ                 REQ0000
sl@0
   368
*/
sl@0
   369
void TestNearestLanguageFinder()
sl@0
   370
	{
sl@0
   371
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0446 "));
sl@0
   372
	RFs dummy;
sl@0
   373
	TTestNearestLanguageFileFinder finder(dummy);
sl@0
   374
sl@0
   375
	// Test file name setting and disecting
sl@0
   376
	// SetFileName
sl@0
   377
	// RepairFileName
sl@0
   378
	TFileName fileName(KTestFileName1);
sl@0
   379
	finder.SetFileName(fileName);
sl@0
   380
	test(0 <= finder.iFileName->MatchF(KExpectedFileName1));
sl@0
   381
	test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
sl@0
   382
	test('z' == finder.iInitialDriveLetter);
sl@0
   383
	finder.RepairFileName();
sl@0
   384
	test(0 == finder.iFileName->Compare(KTestFileName1));
sl@0
   385
	fileName = KTestFileName11;
sl@0
   386
	finder.SetFileName(fileName);
sl@0
   387
	test(0 <= finder.iFileName->MatchF(KExpectedFileName2));
sl@0
   388
	test(0 == finder.iSuffix.Compare(KExpectedSuffix2));
sl@0
   389
	test(-1 == finder.iInitialDriveLetter);
sl@0
   390
	finder.RepairFileName();
sl@0
   391
	test(0 == finder.iFileName->Compare(KTestFileName11));
sl@0
   392
	fileName = KTestFileName256Chars;
sl@0
   393
	finder.SetFileName(fileName);
sl@0
   394
	test(0 <= finder.iFileName->MatchF(KExpectedFileName256Chars));
sl@0
   395
	test(0 == finder.iSuffix.Compare(KExpectedSuffix1));
sl@0
   396
	test(-1 == finder.iInitialDriveLetter);
sl@0
   397
	finder.RepairFileName();
sl@0
   398
	test(0 == finder.iFileName->Compare(KTestFileName256Chars));
sl@0
   399
sl@0
   400
	// Test drive sequence construction
sl@0
   401
	// AddCustomResourceDrive
sl@0
   402
	finder.iCustomRscDrive = static_cast<TInt>(EDriveC);	// drive c:
sl@0
   403
	fileName = KTestFileName1;
sl@0
   404
	finder.SetFileName(fileName);
sl@0
   405
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   406
	test(0 == finder.iDrives.CompareF(_L("CZ")));
sl@0
   407
	fileName = KTestFileName3;
sl@0
   408
	finder.SetFileName(fileName);
sl@0
   409
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   410
	test(0 == finder.iDrives.CompareF(_L("CA")));
sl@0
   411
	fileName = KTestFileName4;
sl@0
   412
	finder.SetFileName(fileName);
sl@0
   413
	test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
sl@0
   414
	test(0 == finder.iDrives.CompareF(_L("C")));
sl@0
   415
	fileName = KTestFileName5;
sl@0
   416
	finder.SetFileName(fileName);
sl@0
   417
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   418
	test(0 == finder.iDrives.CompareF(_L("CD")));
sl@0
   419
	fileName = KTestFileName6;
sl@0
   420
	finder.SetFileName(fileName);
sl@0
   421
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   422
	test(0 == finder.iDrives.CompareF(_L("CY")));
sl@0
   423
	fileName = KTestFileName7;
sl@0
   424
	finder.SetFileName(fileName);
sl@0
   425
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   426
	test(0 == finder.iDrives.CompareF(_L("CA")));
sl@0
   427
	fileName = KTestFileName8;
sl@0
   428
	finder.SetFileName(fileName);
sl@0
   429
	test(finder.AddCustomResourceDrive() == KErrAlreadyExists);
sl@0
   430
	test(0 == finder.iDrives.CompareF(_L("C")));
sl@0
   431
	fileName = KTestFileName9;
sl@0
   432
	finder.SetFileName(fileName);
sl@0
   433
	test(finder.AddCustomResourceDrive() == KErrNone);
sl@0
   434
	test(0 == finder.iDrives.CompareF(_L("CY")));
sl@0
   435
	// AddAllDrives
sl@0
   436
	fileName = KTestFileName1;
sl@0
   437
	finder.SetFileName(fileName);
sl@0
   438
	finder.AddAllDrives();
sl@0
   439
	test(0 == finder.iDrives.CompareF(_L("ZYXWVUTSRQPONMLKJIHGFEDCBA")));
sl@0
   440
	fileName = KTestFileName3;
sl@0
   441
	finder.SetFileName(fileName);
sl@0
   442
	finder.AddAllDrives();
sl@0
   443
	test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
sl@0
   444
	fileName = KTestFileName4;
sl@0
   445
	finder.SetFileName(fileName);
sl@0
   446
	finder.AddAllDrives();
sl@0
   447
	test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
sl@0
   448
	fileName = KTestFileName5;
sl@0
   449
	finder.SetFileName(fileName);
sl@0
   450
	finder.AddAllDrives();
sl@0
   451
	test(0 == finder.iDrives.CompareF(_L("DYXWVUTSRQPONMLKJIHGFECBAZ")));
sl@0
   452
	fileName = KTestFileName6;
sl@0
   453
	finder.SetFileName(fileName);
sl@0
   454
	finder.AddAllDrives();
sl@0
   455
	test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
sl@0
   456
	fileName = KTestFileName7;
sl@0
   457
	finder.SetFileName(fileName);
sl@0
   458
	finder.AddAllDrives();
sl@0
   459
	test(0 == finder.iDrives.CompareF(_L("AYXWVUTSRQPONMLKJIHGFEDCBZ")));
sl@0
   460
	fileName = KTestFileName8;
sl@0
   461
	finder.SetFileName(fileName);
sl@0
   462
	finder.AddAllDrives();
sl@0
   463
	test(0 == finder.iDrives.CompareF(_L("CYXWVUTSRQPONMLKJIHGFEDBAZ")));
sl@0
   464
	fileName = KTestFileName9;
sl@0
   465
	finder.SetFileName(fileName);
sl@0
   466
	finder.AddAllDrives();
sl@0
   467
	test(0 == finder.iDrives.CompareF(_L("YXWVUTSRQPONMLKJIHGFEDCBAZ")));
sl@0
   468
sl@0
   469
	// Test addition of language number
sl@0
   470
	// AppendLanguageCode
sl@0
   471
	fileName = KTestFileName1;
sl@0
   472
	finder.SetFileName(fileName);
sl@0
   473
	finder.AppendLanguageCode(ELangFrench);
sl@0
   474
	test(0 == finder.iFileName->CompareF(KTestFileName1French));
sl@0
   475
	finder.SetFileName(fileName);
sl@0
   476
	finder.AppendLanguageCode(ELangJapanese);
sl@0
   477
	test(0 == finder.iFileName->CompareF(KTestFileName1Japanese));
sl@0
   478
	finder.SetFileName(fileName);
sl@0
   479
	finder.AppendLanguageCode(ELangAmericanSprint);
sl@0
   480
	test(0 == finder.iFileName->CompareF(KTestFileName1AmericanSprint));
sl@0
   481
sl@0
   482
	fileName = KTestFileName1;
sl@0
   483
	finder.SetFileName(fileName);
sl@0
   484
	finder.AppendLanguageCode(static_cast<TLanguage>(54321));
sl@0
   485
	test(0 == finder.iFileName->CompareF(KTestFileName1Mongolian));
sl@0
   486
	fileName = KTestFileName256Chars;
sl@0
   487
	finder.SetFileName(fileName);
sl@0
   488
	test(!finder.AppendLanguageCode(ELangFrench));
sl@0
   489
sl@0
   490
	// Test searching each drive for the specified file
sl@0
   491
	// FindDrive
sl@0
   492
	finder.iFileCheckedFor = KCheckedForFrench;
sl@0
   493
	finder.iDrivesChecked = _L("D");
sl@0
   494
	fileName = KTestFileName5;
sl@0
   495
	finder.SetFileName(fileName);
sl@0
   496
	finder.AppendLanguageCode(ELangFrench);
sl@0
   497
	finder.FindDrive();
sl@0
   498
	test(finder.iDrivesChecked.Length() == 0);
sl@0
   499
	finder.SetFileName(fileName);
sl@0
   500
	finder.AddAllDrives();
sl@0
   501
	finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
sl@0
   502
	finder.AppendLanguageCode(ELangFrench);
sl@0
   503
	finder.FindDrive();
sl@0
   504
	test(finder.iDrivesChecked.Length() == 0);
sl@0
   505
	fileName = KTestFileName5;
sl@0
   506
	finder.SetFileName(fileName);
sl@0
   507
	finder.AddAllDrives();
sl@0
   508
	finder.iDrivesChecked = _L("dyxwvutsrqponmlkjihgfecbaz");
sl@0
   509
	finder.AppendLanguageCode(ELangFrench);
sl@0
   510
	finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
sl@0
   511
	finder.iFilesThatExist->AppendL(_L("o:\\dIR\\NAmE.E02"));
sl@0
   512
	test(finder.FindDrive());
sl@0
   513
	test(0 == finder.iFileName->CompareF(_L("O:\\dir\\name.e02")));
sl@0
   514
	fileName = KTestFileName2;
sl@0
   515
	finder.SetFileName(fileName);
sl@0
   516
	finder.AppendLanguageCode(ELangFrench);
sl@0
   517
	finder.AddAllDrives();
sl@0
   518
	finder.iDrivesChecked = _L("zyxwvutsrqponmlkjihgfedcba");
sl@0
   519
	finder.iFilesThatExist->AppendL(_L("v:\\dIR\\NA\x301mE.E02"));
sl@0
   520
	//finder.iFileCheckedFor = _L("?:\\dir\\nÁme.e02");
sl@0
   521
	finder.iFileCheckedFor = _L("?:\\dir\\n\u00c1me.e02");
sl@0
   522
	test(finder.FindDrive());
sl@0
   523
	//test(0 == finder.iFileName->CompareF(_L("v:\\dir\\nÁme.e02")));
sl@0
   524
	test(0 == finder.iFileName->CompareF(_L("v:\\dir\\n\u00c1me.e02")));
sl@0
   525
	delete finder.iFilesThatExist;
sl@0
   526
	finder.iFilesThatExist = 0;
sl@0
   527
sl@0
   528
	// Test searching language and drive down the language path
sl@0
   529
	// FindLanguageAndDrive
sl@0
   530
	finder.iPath[0] = static_cast<TLanguage>(2);
sl@0
   531
	finder.iPath[1] = static_cast<TLanguage>(15702);
sl@0
   532
	finder.iPath[2] = static_cast<TLanguage>(1);
sl@0
   533
	finder.iPath[3] = ELangNone;
sl@0
   534
	fileName = KTestFileName1;
sl@0
   535
	finder.SetFileName(fileName);
sl@0
   536
	SetUpFinderForLanguageAndDriveSearchL(finder);
sl@0
   537
	finder.iFileCheckedFor = _L("?:\\dir\\name.e*");
sl@0
   538
	test(!finder.FindLanguageAndDrive());
sl@0
   539
	// check that iFileName is undamaged
sl@0
   540
	finder.RepairFileName();
sl@0
   541
	test(0 == finder.iFileName->CompareF(KTestFileName1));
sl@0
   542
	delete finder.iFilesSearchedFor;
sl@0
   543
	finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
sl@0
   544
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15702"));
sl@0
   545
	fileName = KTestFileName1;
sl@0
   546
	finder.SetFileName(fileName);
sl@0
   547
	SetUpFinderForLanguageAndDriveSearchL(finder);
sl@0
   548
	test(finder.FindLanguageAndDrive());
sl@0
   549
	test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e15702")));
sl@0
   550
	delete finder.iFilesSearchedFor;
sl@0
   551
	finder.iFilesSearchedFor = 0;
sl@0
   552
sl@0
   553
	finder.iPath[0] = static_cast<TLanguage>(7);
sl@0
   554
	finder.iPath[1] = ELangNone;
sl@0
   555
	finder.iFilesThatExist->AppendL(_L("g:\\dir\\name.ext"));
sl@0
   556
	fileName = KTestFileName1;
sl@0
   557
	finder.SetFileName(fileName);
sl@0
   558
	finder.iDrives = _L("ZAG");
sl@0
   559
	finder.iDrivesChecked = _L("ZAGZAG");
sl@0
   560
	test(finder.FindLanguageAndDrive());
sl@0
   561
	test(0 == finder.iFileName->CompareF(_L("g:\\dir\\name.ext")));
sl@0
   562
	delete finder.iFilesThatExist;
sl@0
   563
	finder.iFilesThatExist = 0;
sl@0
   564
sl@0
   565
	// Test filename matching
sl@0
   566
	// LanguageNumberFromFile
sl@0
   567
	test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("AVB")));
sl@0
   568
	//test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("ávb04"), _L("A\x301VB")));
sl@0
   569
	//test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("ÁVB")));
sl@0
   570
	test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("\u00e1vb04"), _L("A\x301VB")));
sl@0
   571
	test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("a\x301vb04"), _L("\u00c1VB")));
sl@0
   572
	test(5254 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb5254"), _L("aVb")));
sl@0
   573
	test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("avb04")));
sl@0
   574
	test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("av")));
sl@0
   575
	test(KErrNotFound == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb04"), _L("")));
sl@0
   576
	test(0 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0000000"), _L("AVB00000")));
sl@0
   577
	test(4 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000000004"), _L("AVB0000000")));
sl@0
   578
	test(100004 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb000100004"), _L("AVB000")));
sl@0
   579
	test(111114 == TNearestLanguageFileFinder::LanguageNumberFromFile(_L("avb0111114"), _L("AVB0")));
sl@0
   580
sl@0
   581
	// Test searching for any language file within a drive
sl@0
   582
	// FindFirstLanguageFile
sl@0
   583
	fileName = KTestFileName3;
sl@0
   584
	finder.SetFileName(fileName);
sl@0
   585
	finder.iFilesThatExist = new (ELeave) CDesCArraySeg(10);
sl@0
   586
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e107"));
sl@0
   587
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e07"));
sl@0
   588
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e02"));
sl@0
   589
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.ee01"));
sl@0
   590
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.01"));
sl@0
   591
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01"));
sl@0
   592
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name01.e01"));
sl@0
   593
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e15108"));
sl@0
   594
	finder.iFilesThatExist->AppendL(_L("a:\\dir\\name.e03"));
sl@0
   595
	finder.iTestScanner.iDriveError[0] = KErrNoMemory;
sl@0
   596
	fileName = KTestFileName3;
sl@0
   597
	finder.SetFileName(fileName);
sl@0
   598
	test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
sl@0
   599
	finder.iTestScanner.iDriveError[0] = KErrAbort;
sl@0
   600
	fileName = KTestFileName3;
sl@0
   601
	finder.SetFileName(fileName);
sl@0
   602
	test(KErrNotFound == finder.FindFirstLanguageFile(dummy));
sl@0
   603
	finder.iTestScanner.iDriveError[0] = KErrNone;
sl@0
   604
	fileName = KTestFileName3;
sl@0
   605
	finder.SetFileName(fileName);
sl@0
   606
	test(0 <= finder.FindFirstLanguageFile(dummy));
sl@0
   607
	test(0 == finder.iFileName->CompareF(_L("a:\\dir\\name.e02")));
sl@0
   608
sl@0
   609
	finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.100"));
sl@0
   610
	finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.9539"));
sl@0
   611
	finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.19539"));
sl@0
   612
	finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1000"));
sl@0
   613
	finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.102"));
sl@0
   614
	fileName = _L("a:\\abcdefg.xx");
sl@0
   615
	finder.SetFileName(fileName);
sl@0
   616
	test(0 <= finder.FindFirstLanguageFile(dummy));
sl@0
   617
	test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
sl@0
   618
	finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.aaa100"));
sl@0
   619
	finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.0523"));	// not well-formed. Will not count.
sl@0
   620
	finder.iFilesThatExist->AppendL(_L("a:\\abcdefg.1001"));
sl@0
   621
	fileName = _L("a:\\abcdefg.xx");
sl@0
   622
	finder.SetFileName(fileName);
sl@0
   623
	test(0 <= finder.FindFirstLanguageFile(dummy));
sl@0
   624
	test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
sl@0
   625
	fileName = _L("a:\\abaffafg.xx");
sl@0
   626
	finder.SetFileName(fileName);
sl@0
   627
	test(0 <= finder.FindFirstLanguageFile(dummy));
sl@0
   628
	test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.100")));
sl@0
   629
	finder.iFilesThatExist->AppendL(_L("a:\\abaffafg.09"));
sl@0
   630
	fileName = _L("a:\\abaffafg.xx");
sl@0
   631
	finder.SetFileName(fileName);
sl@0
   632
	test(0 <= finder.FindFirstLanguageFile(dummy));
sl@0
   633
	test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
sl@0
   634
sl@0
   635
	// Test searching all drives for any language
sl@0
   636
	// FindFirstLanguageFileAndDrive
sl@0
   637
	finder.iFilesThatExist->AppendL(_L("z:\\abcdefg.05"));
sl@0
   638
	fileName = _L("c:\\abcdefg.xx");
sl@0
   639
	finder.SetFileName(fileName);
sl@0
   640
	finder.iDrives = _L("az");
sl@0
   641
	test(0 <= finder.FindFirstLanguageFileAndDrive());
sl@0
   642
	test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
sl@0
   643
	fileName = _L("c:\\abaffafg.xx");
sl@0
   644
	finder.SetFileName(fileName);
sl@0
   645
	finder.iDrives = _L("az");
sl@0
   646
	test(0 <= finder.FindFirstLanguageFileAndDrive());
sl@0
   647
	test(0 == finder.iFileName->CompareF(_L("a:\\abaffafg.09")));
sl@0
   648
	fileName = _L("c:\\abcdefg.xx");
sl@0
   649
	finder.SetFileName(fileName);
sl@0
   650
	finder.iDrives = _L("za");
sl@0
   651
	test(0 <= finder.FindFirstLanguageFileAndDrive());
sl@0
   652
	test(0 == finder.iFileName->CompareF(_L("z:\\abcdefg.05")));
sl@0
   653
	fileName = _L("c:\\xxx.xx");
sl@0
   654
	finder.SetFileName(fileName);
sl@0
   655
	finder.iDrives = _L("za");
sl@0
   656
	test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
sl@0
   657
	finder.iTestScanner.iDriveError[25] = KErrAbort;
sl@0
   658
	fileName = _L("c:\\abcdefg.xx");
sl@0
   659
	finder.SetFileName(fileName);
sl@0
   660
	finder.iDrives = _L("za");
sl@0
   661
	test(0 <= finder.FindFirstLanguageFileAndDrive());
sl@0
   662
	test(0 == finder.iFileName->CompareF(_L("a:\\abcdefg.1000")));
sl@0
   663
	fileName = _L("c:\\abcdefg.xx");
sl@0
   664
	finder.SetFileName(fileName);
sl@0
   665
	finder.iDrives = _L("za");
sl@0
   666
	finder.iTestScanner.iDriveError[0] = KErrNoMemory;
sl@0
   667
	test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
sl@0
   668
	fileName = _L("c:\\abcdefg.xx");
sl@0
   669
	finder.SetFileName(fileName);
sl@0
   670
	finder.iDrives = _L("za");
sl@0
   671
	finder.iTestScanner.iDriveError[0] = KErrAbort;
sl@0
   672
	test(KErrNotFound == finder.FindFirstLanguageFileAndDrive());
sl@0
   673
sl@0
   674
	}
sl@0
   675
sl@0
   676
/**
sl@0
   677
@SYMTestCaseID          SYSLIB-BAFL-CT-0447
sl@0
   678
@SYMTestCaseDesc        Tests for defect number DEF039977
sl@0
   679
@SYMTestPriority        High
sl@0
   680
@SYMTestActions         Test for Panic in BaflUtils::DiskIsReadOnly()
sl@0
   681
						when unexpected parameter supplied
sl@0
   682
@SYMTestExpectedResults Test must not fail
sl@0
   683
@SYMREQ                 REQ0000
sl@0
   684
*/
sl@0
   685
void TestforDEF039977()
sl@0
   686
	{
sl@0
   687
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0447 "));
sl@0
   688
	TFileName filename;
sl@0
   689
	TBool readOnly;
sl@0
   690
	TInt theRes;
sl@0
   691
	RFs fileserver;
sl@0
   692
	TInt err=fileserver.Connect();
sl@0
   693
	test(err==KErrNone);
sl@0
   694
sl@0
   695
	filename=_L("c");
sl@0
   696
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   697
	test(theRes==KErrBadName);
sl@0
   698
sl@0
   699
	filename=_L(" z:");
sl@0
   700
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   701
	test(theRes==KErrBadName);
sl@0
   702
sl@0
   703
	filename=_L("z\\");
sl@0
   704
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   705
	test(theRes==KErrBadName);
sl@0
   706
sl@0
   707
	filename=_L("b:");
sl@0
   708
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   709
	test(theRes==KErrNotReady);
sl@0
   710
sl@0
   711
	filename=_L("c:");
sl@0
   712
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   713
	test(theRes==KErrNone);
sl@0
   714
	test(!readOnly);
sl@0
   715
sl@0
   716
	filename=_L("z:");
sl@0
   717
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   718
	test(theRes==KErrNone);
sl@0
   719
	test(readOnly);
sl@0
   720
sl@0
   721
	filename=_L("z:\\");
sl@0
   722
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   723
	test(theRes==KErrNone);
sl@0
   724
sl@0
   725
	filename=_L("z:\\system\\data\\");
sl@0
   726
	theRes=BaflUtils::DiskIsReadOnly(fileserver,filename,readOnly);
sl@0
   727
	test(theRes==KErrNone);
sl@0
   728
sl@0
   729
	fileserver.Close();
sl@0
   730
	}
sl@0
   731
sl@0
   732
/*
sl@0
   733
@SYMTestCaseID          SYSLIB-BAFL-CT-1284
sl@0
   734
@SYMTestCaseDesc        Tests for invalid character
sl@0
   735
@SYMTestPriority        High
sl@0
   736
@SYMTestActions         Test for panic when an invalid character when
sl@0
   737
                        supplied to BaflUtils::RootFolderPath's parameter as drive letter
sl@0
   738
@SYMTestExpectedResults Test must not fail
sl@0
   739
@SYMREQ                 REQ0000
sl@0
   740
*/
sl@0
   741
TInt TestforInvalidCharacter(TAny* /*aData*/)
sl@0
   742
/**
sl@0
   743
 This is a root thread function which runs as part of the TestforDEF040198().
sl@0
   744
 It tests a panic is produced when an invalid non alphabet character is supplied
sl@0
   745
 in the aDriveLetter argument in BaflUtils::RootFolderPath(const TBuf<1> aDriveLetter)
sl@0
   746
*/
sl@0
   747
	{
sl@0
   748
	TBuf<1> buf1=_L("?");
sl@0
   749
	TFileName retValue;
sl@0
   750
	retValue=BaflUtils::RootFolderPath(buf1);
sl@0
   751
sl@0
   752
	// Line above panics if working OK, so should never get here.
sl@0
   753
	test(0);
sl@0
   754
	return 0;
sl@0
   755
	}
sl@0
   756
sl@0
   757
/**
sl@0
   758
This method is a test case to demonstrate the fix for DEF040198 by supplying an invalid
sl@0
   759
input aDriveLetter argument (e.g "?") to BaflUtils::RootFolderPath(aDriveLetter).
sl@0
   760
sl@0
   761
@SYMTestCaseID          SYSLIB-BAFL-CT-0448
sl@0
   762
@SYMTestCaseDesc        Tests for defect number DEF040198
sl@0
   763
@SYMTestPriority        High
sl@0
   764
@SYMTestActions         Check by giving an invalid aDriveLetter argument
sl@0
   765
@SYMTestExpectedResults Test must not fail
sl@0
   766
@SYMREQ                 REQ0000
sl@0
   767
*/
sl@0
   768
void TestforDEF040198()
sl@0
   769
	{
sl@0
   770
        test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0448 "));
sl@0
   771
//Check invalid aDriveLetter argument panics with panic code EBaflPanicBadOpenArg
sl@0
   772
#if defined(_DEBUG)
sl@0
   773
		TRequestStatus threadStatus;
sl@0
   774
		RThread thread;
sl@0
   775
		_LIT(KThreadName,"ThreadTest");
sl@0
   776
		TInt rc;
sl@0
   777
		TBool jit;
sl@0
   778
		jit=User::JustInTime();
sl@0
   779
		User::SetJustInTime(EFalse);
sl@0
   780
sl@0
   781
		test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1284 "));
sl@0
   782
		rc=thread.Create(KThreadName,TestforInvalidCharacter,KDefaultStackSize,KMinHeapSize,KMinHeapSize*4,NULL);
sl@0
   783
		test(rc==KErrNone);
sl@0
   784
		thread.Logon(threadStatus);
sl@0
   785
		thread.Resume();
sl@0
   786
		User::WaitForRequest(threadStatus);
sl@0
   787
		test (thread.ExitType()==EExitPanic);
sl@0
   788
		test (thread.ExitReason()==EBafPanicBadOpenArg);
sl@0
   789
		thread.Close();
sl@0
   790
		User::SetJustInTime(jit);
sl@0
   791
#endif
sl@0
   792
	}
sl@0
   793
sl@0
   794
/*
sl@0
   795
@SYMTestCaseID          SYSLIB-BAFL-CT-1285
sl@0
   796
@SYMTestCaseDesc        Tests for invalid path name
sl@0
   797
@SYMTestPriority        High
sl@0
   798
@SYMTestActions         Test for panic when an invalid character supplied to BaflUtils::RootFolderPath's parameter as drive letter
sl@0
   799
@SYMTestExpectedResults Test must not fail
sl@0
   800
@SYMREQ                 REQ0000
sl@0
   801
*/
sl@0
   802
TInt TestforInvalidPathName(TAny* /*aData*/)
sl@0
   803
/**
sl@0
   804
 This is a root thread function which runs as part of the TestforDEF040299().
sl@0
   805
 It tests a panic is produced when an invalid name is supplied
sl@0
   806
 in the aFullName argument in BaflUtils::FolderNameFromFullName(const TDesC& aFullName)
sl@0
   807
*/
sl@0
   808
	{	
sl@0
   809
	TBuf<1> buf1=_L("?");
sl@0
   810
	TFileName retValue;
sl@0
   811
	retValue=BaflUtils::FolderNameFromFullName(buf1);
sl@0
   812
sl@0
   813
	// Line above panics if working OK, so should never get here.
sl@0
   814
	test(0);
sl@0
   815
	return 0;
sl@0
   816
	}
sl@0
   817
sl@0
   818
/**
sl@0
   819
@SYMTestCaseID          SYSLIB-BAFL-CT-0449
sl@0
   820
@SYMTestCaseDesc        Tests for defect number DEF047305
sl@0
   821
@SYMTestPriority        High
sl@0
   822
@SYMTestActions         Test for correct syntax
sl@0
   823
@SYMTestExpectedResults Test must not fail
sl@0
   824
@SYMREQ                 REQ0000
sl@0
   825
*/
sl@0
   826
void TestForDEF047305()
sl@0
   827
	{
sl@0
   828
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0449 "));
sl@0
   829
	RFs aFs;
sl@0
   830
	CleanupClosePushL(aFs);
sl@0
   831
	User::LeaveIfError(aFs.Connect());
sl@0
   832
sl@0
   833
	TFileName newFolderFullName = KCurrentPath;
sl@0
   834
sl@0
   835
	test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KValFolderName, KCurrentPath, newFolderFullName)==KErrNone));
sl@0
   836
 	test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KNoFolderName, KCurrentPath, newFolderFullName)==KErrArgument));
sl@0
   837
 	test(User::LeaveIfError(BaflUtils::ValidateFolderNameTypedByUserL(aFs, KInValidFolderName, KCurrentPath, newFolderFullName)==KErrBadName));
sl@0
   838
sl@0
   839
	CleanupStack::PopAndDestroy(&aFs);
sl@0
   840
	}
sl@0
   841
sl@0
   842
/**
sl@0
   843
@SYMTestCaseID          SYSLIB-BAFL-CT-0450
sl@0
   844
@SYMTestCaseDesc        Tests for defect number DEF040299
sl@0
   845
@SYMTestPriority        High
sl@0
   846
@SYMTestActions         Test by supplying an invalid input aFullName argument to BaflUtils::FolderNameFromFullName(aFullName)
sl@0
   847
@SYMTestExpectedResults Test must not fail
sl@0
   848
@SYMREQ                 REQ0000
sl@0
   849
*/
sl@0
   850
void TestforDEF040299()
sl@0
   851
	{
sl@0
   852
    test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0450 "));
sl@0
   853
	TBuf<30> buf;
sl@0
   854
	TFileName fileName;
sl@0
   855
sl@0
   856
	//Path name="c:"
sl@0
   857
	buf=_L("c:");
sl@0
   858
	fileName=BaflUtils::FolderNameFromFullName(buf);
sl@0
   859
	test(buf==fileName);
sl@0
   860
sl@0
   861
	//Path name="c:\\"
sl@0
   862
	buf=_L("c:\\");
sl@0
   863
	fileName=BaflUtils::FolderNameFromFullName(buf);
sl@0
   864
	test(fileName==buf);
sl@0
   865
sl@0
   866
	//Path name="c:\\file.txt"
sl@0
   867
	buf=_L("c:\\file.txt");
sl@0
   868
	fileName=BaflUtils::FolderNameFromFullName(buf);
sl@0
   869
	test(fileName==_L("c:\\"));
sl@0
   870
sl@0
   871
	//Path name="c:\\system\\file.txt"
sl@0
   872
	buf=_L("c:\\system\\file.txt");
sl@0
   873
	fileName=BaflUtils::FolderNameFromFullName(buf);
sl@0
   874
	test(fileName==_L("system"));
sl@0
   875
sl@0
   876
	/**
sl@0
   877
	This method is a test case to demonstrate the fix for DEF040299 by supplying an invalid
sl@0
   878
	input aFullName argument (e.g "?") to BaflUtils::FolderNameFromFullName(aFullName).
sl@0
   879
	*/
sl@0
   880
	//Check invalid aFullName argument panics with panic code EBaflPanicBadOpenArg
sl@0
   881
#if defined(_DEBUG)
sl@0
   882
		TRequestStatus threadStatus;
sl@0
   883
		RThread thread;
sl@0
   884
		//Tread name is changed due to test failing on slow machine
sl@0
   885
		//Using "TreadTest" here are causing KErrAlreadyExist at tread creating stage.
sl@0
   886
		//This is because the previous tread maybe still being closed when this thread is created.
sl@0
   887
		_LIT(KThreadName,"ThreadTest1");
sl@0
   888
		TInt rc;
sl@0
   889
		TBool jit;
sl@0
   890
		jit=User::JustInTime();
sl@0
   891
		User::SetJustInTime(EFalse);
sl@0
   892
		test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1285 "));
sl@0
   893
rc=thread.Create(KThreadName,TestforInvalidPathName,KDefaultStackSize,KMinHeapSize,KMinHeapSize*4,NULL);
sl@0
   894
		test(rc==KErrNone);
sl@0
   895
		thread.Logon(threadStatus);
sl@0
   896
		thread.Resume();
sl@0
   897
		User::WaitForRequest(threadStatus);
sl@0
   898
		test (thread.ExitType()==EExitPanic);
sl@0
   899
		test (thread.ExitReason()==EBafPanicBadOpenArg);
sl@0
   900
		thread.Close();
sl@0
   901
		User::SetJustInTime(jit);
sl@0
   902
#endif
sl@0
   903
sl@0
   904
	}
sl@0
   905
sl@0
   906
/**
sl@0
   907
@SYMTestCaseID          SYSLIB-BAFL-CT-3416
sl@0
   908
@SYMTestCaseDesc        Tests for defect number DEF101927
sl@0
   909
@SYMTestPriority        High
sl@0
   910
@SYMTestActions         Test the simulated Tls functionalities Dll::Tls, Dll::SetTls and Dll::FreeTls
sl@0
   911
						which is needed for BAUtils.cpp to be complied as part of an .exe.
sl@0
   912
						Dll::Tls - Recalls the value currently referred to by the Tls pointer
sl@0
   913
						Dll::SetTls - Sets the the values referred to by the Tls pointer
sl@0
   914
						Dll::FreeTls - Sets the Tls pointer to NULL
sl@0
   915
@SYMTestExpectedResults Pass if the TLanguage values is returned as expected after calls to IdealLanguage,
sl@0
   916
						SetIdealLanguage and ReleaseIdealLanguage.
sl@0
   917
@SYMDEF                 DEF101927
sl@0
   918
*/
sl@0
   919
void TestForDEF101927()
sl@0
   920
	{
sl@0
   921
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3416 "));
sl@0
   922
	TLanguage test_language(ELangAmerican);
sl@0
   923
sl@0
   924
	test(BaflUtils::IdealLanguage()==ELangNone);
sl@0
   925
sl@0
   926
	BaflUtils::SetIdealLanguage(ELangAmerican);
sl@0
   927
	test(test_language == ELangAmerican);
sl@0
   928
sl@0
   929
	test_language = ELangNone;
sl@0
   930
	test_language = BaflUtils::IdealLanguage();
sl@0
   931
	test(test_language == ELangAmerican);
sl@0
   932
sl@0
   933
	BaflUtils::ReleaseIdealLanguage();
sl@0
   934
	test_language = BaflUtils::IdealLanguage();
sl@0
   935
	test(test_language == ELangNone);
sl@0
   936
	}
sl@0
   937
sl@0
   938
/**
sl@0
   939
@SYMTestCaseID			SYSLIB-BAFL-UT-3667
sl@0
   940
@SYMTestCaseDesc		Tests for defect number DEF109928
sl@0
   941
@SYMTestPriority		Normal
sl@0
   942
@SYMTestActions         Test for the extended NextLanguage(). Check if the MakeLanguageDowngradePath()
sl@0
   943
						can now return the correct default fallback for the languages which are newly
sl@0
   944
						added into the NextLanguage().
sl@0
   945
@SYMTestExpectedResults Test must not fail
sl@0
   946
@SYMDEF					DEF109928
sl@0
   947
*/
sl@0
   948
void TestForDEF109928()
sl@0
   949
	{
sl@0
   950
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-UT-3667 "));
sl@0
   951
	TLanguage testDeviceLangs[8] = {ELangEnglish_Japan, ELangSwissFrench, ELangSwissGerman,
sl@0
   952
									ELangLatinAmericanSpanish, ELangSwissItalian, ELangFinlandSwedish,
sl@0
   953
									ELangMalay_Apac, ELangBrazilianPortuguese};
sl@0
   954
	TLanguagePath testOutputPath[8] = {{ELangEnglish_Japan, ELangEnglish}, {ELangSwissFrench, ELangFrench},
sl@0
   955
				{ELangSwissGerman, ELangGerman}, {ELangLatinAmericanSpanish, ELangSpanish},
sl@0
   956
				{ELangSwissItalian, ELangItalian}, {ELangFinlandSwedish, ELangSwedish},
sl@0
   957
				{ELangMalay_Apac, ELangMalay}, {ELangBrazilianPortuguese, ELangPortuguese}};
sl@0
   958
	TLocale loc;
sl@0
   959
	loc.SetLanguageDowngrade(0, ELangNone);
sl@0
   960
	loc.SetLanguageDowngrade(1, ELangNone);
sl@0
   961
	loc.SetLanguageDowngrade(2, ELangNone);
sl@0
   962
	TLanguagePath path;
sl@0
   963
	TLanguage testlang;
sl@0
   964
sl@0
   965
	for(TInt i = 0; i < 8 ; i++)
sl@0
   966
		{
sl@0
   967
		testlang = testDeviceLangs[i];
sl@0
   968
		MakeLanguageDowngradePath(path, testlang, ELangNone, loc);
sl@0
   969
		test(path[0] == testOutputPath[i][0]);
sl@0
   970
		test(path[1] == testOutputPath[i][1]);
sl@0
   971
		test(path[2] == ELangNone);
sl@0
   972
		}
sl@0
   973
	}
sl@0
   974
sl@0
   975
/* The following 3 function is defined so that the functions IdealLanguage,
sl@0
   976
SetIdealLanguage, ReleaseIdealLanguage will compile as part as an .exe
sl@0
   977
These functions use a global TAny* to store the data that would have been
sl@0
   978
stored in the TLS under normal compilation (ie If the BaUtils was compilled
sl@0
   979
as part of a DLL).
sl@0
   980
*/
sl@0
   981
sl@0
   982
TAny* ptr(NULL);
sl@0
   983
sl@0
   984
TAny* Dll::Tls()
sl@0
   985
	{
sl@0
   986
	return ptr;
sl@0
   987
	}
sl@0
   988
sl@0
   989
TInt Dll::SetTls(TAny* aPtr)
sl@0
   990
	{
sl@0
   991
	ptr = aPtr;
sl@0
   992
	return KErrNone;
sl@0
   993
	}
sl@0
   994
sl@0
   995
void Dll::FreeTls()
sl@0
   996
	{
sl@0
   997
	ptr = NULL;
sl@0
   998
	}
sl@0
   999
sl@0
  1000
void RunTestsL()
sl@0
  1001
	{
sl@0
  1002
	__UHEAP_MARK;
sl@0
  1003
sl@0
  1004
	test.Title();
sl@0
  1005
	test.Start(_L("BaflUtils Internal Tests: "));
sl@0
  1006
sl@0
  1007
	TestAddLanguage();
sl@0
  1008
	TestMakeLanguageDowngradePath();
sl@0
  1009
	TestNearestLanguageFinder();
sl@0
  1010
	TestforDEF039977();
sl@0
  1011
	TestforDEF040198();
sl@0
  1012
	TestforDEF040299();
sl@0
  1013
	TestForDEF047305();
sl@0
  1014
	TestForDEF101927();
sl@0
  1015
	TestForDEF109928();
sl@0
  1016
	test.End();
sl@0
  1017
	test.Close();
sl@0
  1018
sl@0
  1019
	__UHEAP_MARKENDC(0);
sl@0
  1020
	}
sl@0
  1021
sl@0
  1022
TInt E32Main()
sl@0
  1023
	{
sl@0
  1024
	TrapCleanup = CTrapCleanup::New();
sl@0
  1025
	TRAPD(err, RunTestsL());
sl@0
  1026
    test(err == KErrNone);
sl@0
  1027
	delete TrapCleanup;
sl@0
  1028
	return 0;
sl@0
  1029
	}