os/kernelhwsrv/kerneltest/f32test/server/t_file.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) 1995-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
//
sl@0
    15
sl@0
    16
#define __E32TEST_EXTENSION__
sl@0
    17
sl@0
    18
#include <f32file.h>
sl@0
    19
#include <e32test.h>
sl@0
    20
#include <e32svr.h>
sl@0
    21
#include "t_server.h"
sl@0
    22
#include "t_chlffs.h"
sl@0
    23
#include "fs_utils.h"
sl@0
    24
sl@0
    25
#include "f32_test_utils.h"
sl@0
    26
sl@0
    27
using namespace F32_Test_Utils;
sl@0
    28
sl@0
    29
RTest test(_L("T_FILE"));
sl@0
    30
sl@0
    31
TBool gShortFileNamesSupported = EFalse;
sl@0
    32
sl@0
    33
static TBuf8<1500> gBuf;
sl@0
    34
sl@0
    35
TInt gDriveNum = -1;
sl@0
    36
sl@0
    37
static void testShare()
sl@0
    38
//
sl@0
    39
// Test file sharing.
sl@0
    40
//
sl@0
    41
	{
sl@0
    42
sl@0
    43
	test.Start(_L("Test exclusive sharing"));
sl@0
    44
	MakeFile(_L("TESTER"));
sl@0
    45
sl@0
    46
/*
sl@0
    47
	Extra code to answer a question about a potential WINS bug.  WINS Elocal returns
sl@0
    48
	KErrAccessDenied to the write operation but EFat returns
sl@0
    49
	KErrNone...
sl@0
    50
sl@0
    51
	RFile f1;
sl@0
    52
	TInt r=f1.Open(TheFs,_L("TESTER"),EFileRead|EFileShareAny);
sl@0
    53
	test(r==KErrNone);
sl@0
    54
	RFile f2;
sl@0
    55
	r=f2.Open(TheFs,_L("TESTER"),EFileWrite|EFileShareAny);
sl@0
    56
	test(r==KErrNone);
sl@0
    57
sl@0
    58
	r=f2.Write(_L("0"));
sl@0
    59
	test.Printf(_L("returned %d"),r);
sl@0
    60
sl@0
    61
	f1.Close();
sl@0
    62
	f2.Close();
sl@0
    63
sl@0
    64
	r=TheFs.Delete(_L("TESTER"));
sl@0
    65
	test(r==KErrNone);
sl@0
    66
*/
sl@0
    67
sl@0
    68
	RFile f1;
sl@0
    69
	TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
    70
	test(r==KErrNone);
sl@0
    71
	RFile f2;
sl@0
    72
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
    73
	test(r==KErrInUse);
sl@0
    74
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
    75
	test(r==KErrInUse);
sl@0
    76
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
    77
	test(r==KErrInUse);
sl@0
    78
	f1.Close();
sl@0
    79
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive);
sl@0
    80
	test(r==KErrNone);
sl@0
    81
	f1.Close();
sl@0
    82
sl@0
    83
	test.Next(_L("Test readers only sharing"));
sl@0
    84
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly);
sl@0
    85
	test(r==KErrArgument);
sl@0
    86
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
    87
	test(r==KErrNone);
sl@0
    88
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
    89
	test(r==KErrInUse);
sl@0
    90
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
    91
	test(r==KErrInUse);
sl@0
    92
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly);
sl@0
    93
	test(r==KErrArgument);
sl@0
    94
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
    95
	test(r==KErrNone);
sl@0
    96
	f1.Close();
sl@0
    97
	f2.Close();
sl@0
    98
sl@0
    99
	test.Next(_L("Test any sharing"));
sl@0
   100
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareAny);
sl@0
   101
	test(r==KErrNone);
sl@0
   102
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
   103
	test(r==KErrInUse);
sl@0
   104
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   105
	test(r==KErrInUse);
sl@0
   106
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
   107
	test(r==KErrNone);
sl@0
   108
	f1.Close();
sl@0
   109
	f2.Close();
sl@0
   110
sl@0
   111
	test.End();
sl@0
   112
	}
sl@0
   113
sl@0
   114
static void testChangeMode()
sl@0
   115
//
sl@0
   116
// Test changing the share mode of a file between EFileShareReadersOnly <-> EFileShareExclusive
sl@0
   117
//
sl@0
   118
	{
sl@0
   119
sl@0
   120
	test.Start(_L("Test change mode"));
sl@0
   121
	RFile f1;
sl@0
   122
	RFile f2;
sl@0
   123
	TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
   124
	test(r==KErrNone); // Opened exclusive
sl@0
   125
	r=f1.ChangeMode(EFileShareReadersOnly);
sl@0
   126
	test(r==KErrNone); // Change to readers only
sl@0
   127
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   128
	test(r==KErrNone); // Open as reader
sl@0
   129
	r=f1.ChangeMode(EFileShareExclusive);
sl@0
   130
	test(r==KErrAccessDenied); // Change back to exclusive fails
sl@0
   131
	r=f2.ChangeMode(EFileShareExclusive);
sl@0
   132
	test(r==KErrAccessDenied); // Change to exclusive fails
sl@0
   133
	f1.Close(); // Close other reader
sl@0
   134
	r=f2.ChangeMode(EFileShareExclusive);
sl@0
   135
	test(r==KErrNone); // Change to exclusive succeeds.
sl@0
   136
	f2.Close();
sl@0
   137
sl@0
   138
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   139
	test(r==KErrNone); // Opened readers only
sl@0
   140
	r=f1.ChangeMode(EFileShareExclusive);
sl@0
   141
	test(r==KErrNone); // Change to exclusive
sl@0
   142
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   143
	test(r==KErrInUse); // Open as reader fails
sl@0
   144
	r=f1.ChangeMode(EFileShareReadersOnly);
sl@0
   145
	test(r==KErrNone); // Change to readers only
sl@0
   146
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   147
	test(r==KErrNone); // Open as reader
sl@0
   148
	r=f1.ChangeMode(EFileShareExclusive);
sl@0
   149
	test(r==KErrAccessDenied); // Change back to exclusive fails
sl@0
   150
	r=f2.ChangeMode(EFileShareExclusive);
sl@0
   151
	test(r==KErrAccessDenied); // Change to exclusive fails
sl@0
   152
	f1.Close(); // Close other reader
sl@0
   153
	r=f2.ChangeMode(EFileShareExclusive);
sl@0
   154
	test(r==KErrNone); // Change to exclusive succeeds.
sl@0
   155
	f2.Close();
sl@0
   156
sl@0
   157
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive);
sl@0
   158
	test(r==KErrNone); // Opened exclusive for writing
sl@0
   159
	r=f1.ChangeMode(EFileShareReadersOnly);
sl@0
   160
	test(r==KErrAccessDenied); // Change to readers fails
sl@0
   161
	r=f1.ChangeMode(EFileShareExclusive);
sl@0
   162
	test(r==KErrNone); // No change ok
sl@0
   163
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   164
	test(r==KErrInUse); // Open as reader fails
sl@0
   165
	f1.Close();
sl@0
   166
sl@0
   167
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
   168
	test(r==KErrNone); // Opened share any
sl@0
   169
	r=f1.ChangeMode(EFileShareExclusive);
sl@0
   170
	test(r==KErrAccessDenied); // Change to exclusive fails
sl@0
   171
	r=f1.ChangeMode(EFileShareReadersOnly);
sl@0
   172
	test(r==KErrAccessDenied); // Change to readers only fails
sl@0
   173
	f1.Close();
sl@0
   174
sl@0
   175
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
   176
	test(r==KErrNone); // Opened exclusive
sl@0
   177
	r=f1.ChangeMode(EFileShareAny);
sl@0
   178
	test(r==KErrArgument); // Change to share any fails KErrArgument
sl@0
   179
	r=f1.ChangeMode((TFileMode)42);
sl@0
   180
	test(r==KErrArgument); // Change to random value fails
sl@0
   181
	f1.Close();
sl@0
   182
	test.End();
sl@0
   183
	}
sl@0
   184
sl@0
   185
static void testReadFile()
sl@0
   186
//
sl@0
   187
// Test read file handling.
sl@0
   188
//
sl@0
   189
	{
sl@0
   190
sl@0
   191
	test.Start(_L("Test read file"));
sl@0
   192
	RFile f,ZFile;
sl@0
   193
	TInt r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText);
sl@0
   194
	test(r==KErrNone);
sl@0
   195
	TFileName fn = _L("Z:\\TEST\\T_FILE.CPP");
sl@0
   196
	fn[0] = gExeFileName[0];
sl@0
   197
	r=ZFile.Open(TheFs,fn,EFileStreamText);
sl@0
   198
	test(r==KErrNone);
sl@0
   199
sl@0
   200
	test.Next(_L("Read file"));
sl@0
   201
	TBuf8<0x100> a,b;
sl@0
   202
	FOREVER
sl@0
   203
		{
sl@0
   204
		r=f.Read(b);
sl@0
   205
		test(r==KErrNone);
sl@0
   206
		r=ZFile.Read(a);
sl@0
   207
		test(r==KErrNone);
sl@0
   208
		test(a==b);
sl@0
   209
		if (b.Length()<b.MaxLength())
sl@0
   210
			break;
sl@0
   211
		}
sl@0
   212
	b.SetLength(10);
sl@0
   213
	r=f.Read(b);
sl@0
   214
	test(r==KErrNone);
sl@0
   215
	test(b.Length()==0);
sl@0
   216
	f.Close();
sl@0
   217
	ZFile.Close();
sl@0
   218
sl@0
   219
	test.Next(_L("Read way beyond the end of the file"));
sl@0
   220
	r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText);
sl@0
   221
	test(r==KErrNone);
sl@0
   222
	r=f.Read(3000000,gBuf);
sl@0
   223
	test(r==KErrNone);
sl@0
   224
	f.Close();
sl@0
   225
sl@0
   226
	test.Next(_L("Write way beyond the end of the file"));
sl@0
   227
	r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite);
sl@0
   228
	test(r==KErrNone);
sl@0
   229
	gBuf.SetLength(10);
sl@0
   230
	r=f.Write(3000000,gBuf);
sl@0
   231
	test(r==KErrNone);
sl@0
   232
	f.Close();
sl@0
   233
	test.End();
sl@0
   234
	}
sl@0
   235
sl@0
   236
static void testMultipleReadFile()
sl@0
   237
//
sl@0
   238
// Test multiple read file handling.
sl@0
   239
//
sl@0
   240
	{
sl@0
   241
sl@0
   242
	test.Start(_L("Test multiple read file"));
sl@0
   243
	RFile f1;
sl@0
   244
	TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   245
	test(r==KErrNone);
sl@0
   246
	RFile f2;
sl@0
   247
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
   248
	test(r==KErrNone);
sl@0
   249
sl@0
   250
	test.Next(_L("Read file"));
sl@0
   251
	FOREVER
sl@0
   252
		{
sl@0
   253
		TBuf8<0x100> b1;
sl@0
   254
		r=f1.Read(b1);
sl@0
   255
		test(r==KErrNone);
sl@0
   256
		TBuf8<0x100> b2;
sl@0
   257
		r=f2.Read(b2);
sl@0
   258
		test(r==KErrNone);
sl@0
   259
		test(b1==b2);
sl@0
   260
		if (b1.Length()<b1.MaxLength())
sl@0
   261
			break;
sl@0
   262
		}
sl@0
   263
sl@0
   264
	test.Next(_L("Close file"));
sl@0
   265
	f1.Close();
sl@0
   266
	f2.Close();
sl@0
   267
sl@0
   268
	test.End();
sl@0
   269
	}
sl@0
   270
sl@0
   271
static void testWriteFile()
sl@0
   272
//
sl@0
   273
// Test write file handling.
sl@0
   274
//
sl@0
   275
	{
sl@0
   276
	test.Start(_L("Test write file"));
sl@0
   277
	RFile file;
sl@0
   278
	TFileName fn = _L("File.File");
sl@0
   279
	TBuf8<16> testData=_L8("testData");
sl@0
   280
sl@0
   281
	// write test 1
sl@0
   282
	TInt r=file.Replace(TheFs,fn,EFileStreamText);
sl@0
   283
	test(r==KErrNone);
sl@0
   284
sl@0
   285
	test.Next(_L("Write file"));
sl@0
   286
sl@0
   287
	r=file.Write(testData);
sl@0
   288
	test(r==KErrNone);
sl@0
   289
sl@0
   290
	file.Close();
sl@0
   291
sl@0
   292
	// test write modes
sl@0
   293
	// test writing with EFileRead
sl@0
   294
	r=file.Open(TheFs,fn,EFileStreamText|EFileRead);
sl@0
   295
	test(r==KErrNone);
sl@0
   296
sl@0
   297
	test.Next(_L("Write file"));
sl@0
   298
	r=file.Write(testData);
sl@0
   299
	test(r==KErrAccessDenied);
sl@0
   300
	file.Close();
sl@0
   301
sl@0
   302
	// test writing with EFileWrite
sl@0
   303
	r=file.Open(TheFs,fn,EFileStreamText|EFileWrite);
sl@0
   304
	test(r==KErrNone);
sl@0
   305
sl@0
   306
	test.Next(_L("Write file"));
sl@0
   307
	r=file.Write(testData);
sl@0
   308
	test(r==KErrNone);
sl@0
   309
	file.Close();
sl@0
   310
sl@0
   311
	// test writing with share mode EFileShareExclusive
sl@0
   312
	r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareExclusive);
sl@0
   313
	test(r==KErrNone);
sl@0
   314
sl@0
   315
	test.Next(_L("Write file"));
sl@0
   316
	r=file.Write(testData);
sl@0
   317
	test(r==KErrNone);
sl@0
   318
	file.Close();
sl@0
   319
sl@0
   320
	// test writing with share mode EFileShareReadersOnly (fails with KErrArgument)
sl@0
   321
	r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOnly);
sl@0
   322
	test(r==KErrArgument);
sl@0
   323
sl@0
   324
	// test writing with share mode EFileShareReadersOrWriters
sl@0
   325
	r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOrWriters);
sl@0
   326
	test(r==KErrNone);
sl@0
   327
sl@0
   328
	test.Next(_L("Write file"));
sl@0
   329
	r=file.Write(testData);
sl@0
   330
	test(r==KErrNone);
sl@0
   331
	file.Close();
sl@0
   332
sl@0
   333
	// test writing with share mode EFileShareAny
sl@0
   334
	r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareAny);
sl@0
   335
	test(r==KErrNone);
sl@0
   336
sl@0
   337
	test.Next(_L("Write file"));
sl@0
   338
	r=file.Write(testData);
sl@0
   339
	test(r==KErrNone);
sl@0
   340
	file.Close();
sl@0
   341
sl@0
   342
	// tidy up
sl@0
   343
	r=TheFs.Delete(fn);
sl@0
   344
	test(r==KErrNone);
sl@0
   345
sl@0
   346
	test.End();
sl@0
   347
	}
sl@0
   348
sl@0
   349
static void CopyFileToTestDirectory()
sl@0
   350
//
sl@0
   351
// Make a copy of the file in ram
sl@0
   352
//
sl@0
   353
	{
sl@0
   354
sl@0
   355
	TFileName fn = _L("Z:\\TEST\\T_FILE.CPP");
sl@0
   356
	fn[0] = gExeFileName[0];
sl@0
   357
	TParse f;
sl@0
   358
	TInt r;
sl@0
   359
	r=TheFs.Parse(fn,f);
sl@0
   360
	test(r==KErrNone);
sl@0
   361
	TParse fCopy;
sl@0
   362
	r=TheFs.Parse(f.NameAndExt(),fCopy);
sl@0
   363
	test(r==KErrNone);
sl@0
   364
sl@0
   365
	RFile f1;
sl@0
   366
	r=f1.Open(TheFs,f.FullName(),EFileStreamText|EFileShareReadersOnly);
sl@0
   367
	test(r==KErrNone);
sl@0
   368
	RFile f2;
sl@0
   369
	r=f2.Replace(TheFs,fCopy.FullName(),EFileWrite);
sl@0
   370
	test(r==KErrNone);
sl@0
   371
	TBuf8<512> copyBuf;
sl@0
   372
	TInt rem;
sl@0
   373
	r=f1.Size(rem);
sl@0
   374
	test(r==KErrNone);
sl@0
   375
	TInt pos=0;
sl@0
   376
	while (rem)
sl@0
   377
		{
sl@0
   378
		TInt s=Min(rem,copyBuf.MaxSize());
sl@0
   379
		r=f1.Read(pos,copyBuf,s);
sl@0
   380
		test(r==KErrNone);
sl@0
   381
		test(copyBuf.Length()==s);
sl@0
   382
		r=f2.Write(pos,copyBuf,s);
sl@0
   383
		test(r==KErrNone);
sl@0
   384
		pos+=s;
sl@0
   385
		rem-=s;
sl@0
   386
		}
sl@0
   387
	f1.Close();
sl@0
   388
	f2.Close();
sl@0
   389
	}
sl@0
   390
sl@0
   391
static void testFileText()
sl@0
   392
//
sl@0
   393
// Test TFileText class methods
sl@0
   394
//
sl@0
   395
	{
sl@0
   396
sl@0
   397
	test.Next(_L("Test file text"));
sl@0
   398
	TPtrC record[5];
sl@0
   399
	record[0].Set(_L("First record"));
sl@0
   400
	record[1].Set(_L("Second record"));
sl@0
   401
	record[2].Set(_L("Third record"));
sl@0
   402
	record[3].Set(_L("Fourth record"));
sl@0
   403
	record[4].Set(_L("Fifth record"));
sl@0
   404
sl@0
   405
	RFile f;
sl@0
   406
	TInt r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
sl@0
   407
	test(r==KErrNone);
sl@0
   408
	TFileText textFile;
sl@0
   409
	textFile.Set(f);
sl@0
   410
	TInt i=0;
sl@0
   411
	for (i=0;i<5;i++)
sl@0
   412
		{
sl@0
   413
		r=textFile.Write(record[i]);
sl@0
   414
		test(r==KErrNone);
sl@0
   415
		}
sl@0
   416
	r=textFile.Seek(ESeekStart);
sl@0
   417
	test(r==KErrNone);
sl@0
   418
	TBuf<16> recBuf;
sl@0
   419
	for(i=0;i<5;i++)
sl@0
   420
		{
sl@0
   421
		r=textFile.Read(recBuf);
sl@0
   422
		test(r==KErrNone);
sl@0
   423
		test(recBuf==record[i]);
sl@0
   424
		}
sl@0
   425
	r=textFile.Read(recBuf);
sl@0
   426
	test(r==KErrEof);
sl@0
   427
	test(recBuf.Length()==0);
sl@0
   428
	f.Close();
sl@0
   429
sl@0
   430
	test.Next(_L("Test dosfile terminator"));
sl@0
   431
	TPtrC8 trecord[7];
sl@0
   432
	TPtrC tTextrecord[7];
sl@0
   433
	tTextrecord[0].Set(_L("First record\r\n"));
sl@0
   434
	tTextrecord[1].Set(_L("Second record\r\n"));
sl@0
   435
	tTextrecord[2].Set(_L("Third record\r\n"));
sl@0
   436
	tTextrecord[3].Set(_L("Fourth record\r\n"));
sl@0
   437
	tTextrecord[4].Set(_L("Fifth record\r\n"));
sl@0
   438
	tTextrecord[5].Set(_L("Sixth record\n\r"));
sl@0
   439
	tTextrecord[6].Set(_L("Seventh record\n"));
sl@0
   440
	trecord[0].Set((TUint8*)tTextrecord[0].Ptr(),tTextrecord[0].Length()*sizeof(TText));
sl@0
   441
	trecord[1].Set((TUint8*)tTextrecord[1].Ptr(),tTextrecord[1].Length()*sizeof(TText));
sl@0
   442
	trecord[2].Set((TUint8*)tTextrecord[2].Ptr(),tTextrecord[2].Length()*sizeof(TText));
sl@0
   443
	trecord[3].Set((TUint8*)tTextrecord[3].Ptr(),tTextrecord[3].Length()*sizeof(TText));
sl@0
   444
	trecord[4].Set((TUint8*)tTextrecord[4].Ptr(),tTextrecord[4].Length()*sizeof(TText));
sl@0
   445
	trecord[5].Set((TUint8*)tTextrecord[5].Ptr(),tTextrecord[5].Length()*sizeof(TText));
sl@0
   446
	trecord[6].Set((TUint8*)tTextrecord[6].Ptr(),tTextrecord[6].Length()*sizeof(TText));
sl@0
   447
	r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
sl@0
   448
	test(r==KErrNone);
sl@0
   449
	for(i=0;i<7;i++)
sl@0
   450
		{
sl@0
   451
		TBuf8<256> buf;
sl@0
   452
		buf.Copy(trecord[i]);
sl@0
   453
		r=f.Write(buf);
sl@0
   454
		test(r==KErrNone);
sl@0
   455
		}
sl@0
   456
	textFile.Set(f);
sl@0
   457
	textFile.Seek(ESeekStart);
sl@0
   458
	for(i=0;i<5;i++)
sl@0
   459
		{
sl@0
   460
		r=textFile.Read(recBuf);
sl@0
   461
		test(r==KErrNone);
sl@0
   462
		test(recBuf==record[i]);
sl@0
   463
		}
sl@0
   464
	r=textFile.Read(recBuf);
sl@0
   465
	test(r==KErrNone);
sl@0
   466
	test(recBuf==_L("Sixth record"));
sl@0
   467
	r=textFile.Read(recBuf);
sl@0
   468
	test(r==KErrNone);
sl@0
   469
	test(recBuf==_L("\rSeventh record"));
sl@0
   470
	r=textFile.Read(recBuf);
sl@0
   471
	test(r==KErrEof);
sl@0
   472
	test(recBuf.Length()==0);
sl@0
   473
	f.Close();
sl@0
   474
sl@0
   475
	test.Next(_L("Test read with bufferSize == dataSize"));
sl@0
   476
	r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
sl@0
   477
	test(r==KErrNone);
sl@0
   478
	record[0].Set(_L("1234567890123456"));
sl@0
   479
//	trecord[0].Set(_L8("1234567890123456\r\n"));
sl@0
   480
//	trecord[1].Set(_L8("1234567890123456\n"));
sl@0
   481
sl@0
   482
	TPtrC tmpTextrecord;
sl@0
   483
	tmpTextrecord.Set(_L("1234567890123456\r\n"));
sl@0
   484
	trecord[0].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText));
sl@0
   485
sl@0
   486
	tmpTextrecord.Set(_L("1234567890123456\n"));
sl@0
   487
	trecord[1].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText));
sl@0
   488
sl@0
   489
	for (i=0;i<2;i++)
sl@0
   490
		{
sl@0
   491
		r=f.Write(trecord[i]);
sl@0
   492
		test(r==KErrNone);
sl@0
   493
		}
sl@0
   494
	textFile.Set(f);
sl@0
   495
	textFile.Seek(ESeekStart);
sl@0
   496
	for(i=0;i<2;i++)
sl@0
   497
		{
sl@0
   498
		r=textFile.Read(recBuf);
sl@0
   499
		test(r==KErrNone);
sl@0
   500
		test(recBuf==record[0]);
sl@0
   501
		}
sl@0
   502
	r=textFile.Read(recBuf);
sl@0
   503
	test(r==KErrEof);
sl@0
   504
	test(recBuf.Length()==0);
sl@0
   505
	f.Close();
sl@0
   506
sl@0
   507
	test.Next(_L("Read into a buffer < recordSize"));
sl@0
   508
	TBuf<8> smallBuf;
sl@0
   509
	r=f.Open(TheFs,_L("TEXTFILE.txt"),0);
sl@0
   510
	test(r==KErrNone);
sl@0
   511
	textFile.Set(f);
sl@0
   512
	for(i=0;i<2;i++)
sl@0
   513
		{
sl@0
   514
		r=textFile.Read(smallBuf);
sl@0
   515
		test(r==KErrTooBig);
sl@0
   516
		test(smallBuf==_L("12345678"));
sl@0
   517
		}
sl@0
   518
	f.Close();
sl@0
   519
sl@0
   520
	test.Next(_L("Nasty cases: 1) \\r \\n split over buffer boundary"));
sl@0
   521
	r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
sl@0
   522
	test(r==KErrNone);
sl@0
   523
	HBufC* largeRecord=HBufC::NewL(600);
sl@0
   524
	largeRecord->Des().SetLength(250);
sl@0
   525
	largeRecord->Des().Fill('A');
sl@0
   526
	largeRecord->Des()[249]='\n';
sl@0
   527
	TPtrC8 bufPtr;
sl@0
   528
	bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); // Size() returns length in bytes
sl@0
   529
	r=f.Write(bufPtr);
sl@0
   530
	test(r==KErrNone);
sl@0
   531
	TBuf<16> boundaryBuf=_L("12345\r\n");
sl@0
   532
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   533
	r=f.Write(bufPtr);
sl@0
   534
	test(r==KErrNone);
sl@0
   535
	r=f.Write(trecord[0]);
sl@0
   536
	test(r==KErrNone);
sl@0
   537
sl@0
   538
	textFile.Set(f);
sl@0
   539
	textFile.Seek(ESeekStart);
sl@0
   540
	r=textFile.Read(recBuf);
sl@0
   541
	test(r==KErrTooBig);
sl@0
   542
	test(recBuf==_L("AAAAAAAAAAAAAAAA"));
sl@0
   543
	r=textFile.Read(recBuf);
sl@0
   544
	test(r==KErrNone);
sl@0
   545
	test(recBuf==_L("12345"));
sl@0
   546
	r=textFile.Read(recBuf);
sl@0
   547
	test(r==KErrNone);
sl@0
   548
	test(recBuf==record[0]);
sl@0
   549
	f.Close();
sl@0
   550
sl@0
   551
	test.Next(_L("Nasty cases: 2) \\r on buffer boundary"));
sl@0
   552
	r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
sl@0
   553
	test(r==KErrNone);
sl@0
   554
	largeRecord->Des().SetLength(250);
sl@0
   555
	largeRecord->Des().Fill('A');
sl@0
   556
	largeRecord->Des()[249]='\n';
sl@0
   557
	bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size());
sl@0
   558
	r=f.Write(bufPtr);
sl@0
   559
	test(r==KErrNone);
sl@0
   560
	boundaryBuf=_L("12345\rxyz\n");
sl@0
   561
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   562
	r=f.Write(bufPtr);
sl@0
   563
	test(r==KErrNone);
sl@0
   564
	r=f.Write(trecord[0]);
sl@0
   565
	test(r==KErrNone);
sl@0
   566
sl@0
   567
	textFile.Set(f);
sl@0
   568
	textFile.Seek(ESeekStart);
sl@0
   569
	r=textFile.Read(recBuf);
sl@0
   570
	test(r==KErrTooBig);
sl@0
   571
	test(recBuf==_L("AAAAAAAAAAAAAAAA"));
sl@0
   572
	r=textFile.Read(recBuf);
sl@0
   573
	test(r==KErrNone);
sl@0
   574
	test(recBuf==_L("12345\rxyz"));
sl@0
   575
	r=textFile.Read(recBuf);
sl@0
   576
	test(r==KErrNone);
sl@0
   577
	test(recBuf==record[0]);
sl@0
   578
	f.Close();
sl@0
   579
sl@0
   580
	test.Next(_L("Nasty cases: 3) record size > buffer size"));
sl@0
   581
	r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
sl@0
   582
	test(r==KErrNone);
sl@0
   583
	largeRecord->Des().SetLength(600);
sl@0
   584
	largeRecord->Des().Fill('Z');
sl@0
   585
	largeRecord->Des()[511]='\r';
sl@0
   586
	largeRecord->Des()[599]='\n';
sl@0
   587
	bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size());
sl@0
   588
	r=f.Write(bufPtr);
sl@0
   589
	test(r==KErrNone);
sl@0
   590
	boundaryBuf=_L("12345\rxyz\n");
sl@0
   591
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   592
	r=f.Write(bufPtr);
sl@0
   593
	test(r==KErrNone);
sl@0
   594
	r=f.Write(trecord[0]);
sl@0
   595
	test(r==KErrNone);
sl@0
   596
sl@0
   597
	textFile.Set(f);
sl@0
   598
	textFile.Seek(ESeekStart);
sl@0
   599
	r=textFile.Read(recBuf);
sl@0
   600
	test(r==KErrTooBig);
sl@0
   601
	test(recBuf==_L("ZZZZZZZZZZZZZZZZ"));
sl@0
   602
	r=textFile.Read(recBuf);
sl@0
   603
	test(r==KErrNone);
sl@0
   604
	test(recBuf==_L("12345\rxyz"));
sl@0
   605
	r=textFile.Read(recBuf);
sl@0
   606
	test(r==KErrNone);
sl@0
   607
	test(recBuf==record[0]);
sl@0
   608
sl@0
   609
	TBuf<601> bigBuf;
sl@0
   610
	TPtrC largePtr((TText*)largeRecord->Ptr(),(largeRecord->Length()-1));
sl@0
   611
	textFile.Seek(ESeekStart);
sl@0
   612
	r=textFile.Read(bigBuf);
sl@0
   613
	test(r==KErrNone);
sl@0
   614
	test(bigBuf==largePtr);
sl@0
   615
	r=textFile.Read(recBuf);
sl@0
   616
	test(r==KErrNone);
sl@0
   617
	test(recBuf==_L("12345\rxyz"));
sl@0
   618
	r=textFile.Read(recBuf);
sl@0
   619
	test(r==KErrNone);
sl@0
   620
	test(recBuf==record[0]);
sl@0
   621
	f.Close();
sl@0
   622
sl@0
   623
	User::Free(largeRecord);
sl@0
   624
	}
sl@0
   625
sl@0
   626
static void testFileTextEndRecord()
sl@0
   627
//
sl@0
   628
// Test terminating record
sl@0
   629
//
sl@0
   630
	{
sl@0
   631
sl@0
   632
	test.Next(_L("Test FileText last record has no terminator"));
sl@0
   633
	RFile f;
sl@0
   634
	TInt r=f.Replace(TheFs,_L("TextFile"),0);
sl@0
   635
	test(r==KErrNone);
sl@0
   636
	TPtrC8 bufPtr;
sl@0
   637
	TBuf<16>boundaryBuf=_L("Record1\n");
sl@0
   638
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   639
	r=f.Write(bufPtr);
sl@0
   640
	test(r==KErrNone);
sl@0
   641
	boundaryBuf=_L("Record2\n");
sl@0
   642
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   643
	r=f.Write(bufPtr);
sl@0
   644
	test(r==KErrNone);
sl@0
   645
	boundaryBuf=_L("Record3\n");
sl@0
   646
	bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
sl@0
   647
	r=f.Write(bufPtr);
sl@0
   648
	test(r==KErrNone);
sl@0
   649
sl@0
   650
	TFileText fText;
sl@0
   651
	fText.Set(f);
sl@0
   652
	r=fText.Seek(ESeekStart);
sl@0
   653
	test(r==KErrNone);
sl@0
   654
	TBuf<32> recBuf;
sl@0
   655
	r=fText.Read(recBuf);
sl@0
   656
	test(r==KErrNone);
sl@0
   657
	test(recBuf.MatchF(_L("record1"))!=KErrNotFound);
sl@0
   658
	r=fText.Read(recBuf);
sl@0
   659
	test(r==KErrNone);
sl@0
   660
	test(recBuf.MatchF(_L("record2"))!=KErrNotFound);
sl@0
   661
	r=fText.Read(recBuf);
sl@0
   662
	test(r==KErrNone);
sl@0
   663
	test(recBuf.MatchF(_L("record3"))!=KErrNotFound);
sl@0
   664
	r=fText.Read(recBuf);
sl@0
   665
	test(r==KErrEof);
sl@0
   666
	test(recBuf.Length()==0);
sl@0
   667
	f.Close();
sl@0
   668
sl@0
   669
	TBuf<0x100> bigBuf(0x100);
sl@0
   670
	bigBuf.Fill('A');
sl@0
   671
	r=f.Replace(TheFs,_L("TextFile"),0);
sl@0
   672
	test(r==KErrNone);
sl@0
   673
sl@0
   674
    bufPtr.Set((TUint8*)bigBuf.Ptr(),bigBuf.Size());
sl@0
   675
	r=f.Write(bufPtr);
sl@0
   676
	test(r==KErrNone);
sl@0
   677
sl@0
   678
	fText.Set(f);
sl@0
   679
	r=fText.Seek(ESeekStart);
sl@0
   680
	test(r==KErrNone);
sl@0
   681
	bigBuf.SetLength(0);
sl@0
   682
	r=fText.Read(bigBuf);
sl@0
   683
	test.Printf(_L("fText.Read returns %d\n"),r);
sl@0
   684
	test(r==KErrNone);
sl@0
   685
	test.Printf(_L("BigBuf.Length()==%d\n"),bigBuf.Length());
sl@0
   686
	test(bigBuf.Length()==0x100);
sl@0
   687
	r=fText.Read(bigBuf);
sl@0
   688
	test(r==KErrEof);
sl@0
   689
	test(bigBuf.Length()==0);
sl@0
   690
	f.Close();
sl@0
   691
	}
sl@0
   692
sl@0
   693
static void testFileNames()
sl@0
   694
//
sl@0
   695
// Test file names
sl@0
   696
//
sl@0
   697
	{
sl@0
   698
sl@0
   699
	test.Next(_L("Test temp filenames specify drive"));
sl@0
   700
	TFileName tempFileName;
sl@0
   701
	RFile f;
sl@0
   702
	TInt r=f.Temp(TheFs,_L(""),tempFileName,EFileRead);
sl@0
   703
	test(r==KErrNone);
sl@0
   704
	TParse p;
sl@0
   705
	p.Set(tempFileName,NULL,NULL);
sl@0
   706
	test(p.DrivePresent());
sl@0
   707
	test(p.PathPresent());
sl@0
   708
	test(p.NamePresent());
sl@0
   709
	test(p.ExtPresent());
sl@0
   710
	f.Close();
sl@0
   711
sl@0
   712
	r=f.Replace(TheFs,_L("WELCOMETO"),EFileWrite);
sl@0
   713
	test(r==KErrNone);
sl@0
   714
	f.Close();
sl@0
   715
	r=f.Replace(TheFs,_L("WELCOMETO.WRD"),EFileWrite);
sl@0
   716
	test(r==KErrNone);
sl@0
   717
	f.Close();
sl@0
   718
	}
sl@0
   719
sl@0
   720
// Nasty hack - mask attributes returned by RFile::Att() with this.
sl@0
   721
// File server used to do this but that stopped the XIP attribute on the ROM file system
sl@0
   722
// from being returned. It should really be up to the file system to return only
sl@0
   723
// the attributes which it supports rather than having the file server unilaterally
sl@0
   724
// mask off any attributes which don't exist on FAT.
sl@0
   725
#define ATT_MASK 0x3f
sl@0
   726
static void testFileAttributes()
sl@0
   727
//
sl@0
   728
// Test the archive attribute gets set
sl@0
   729
//
sl@0
   730
	{
sl@0
   731
sl@0
   732
	test.Next(_L("Archive att is set after creation"));
sl@0
   733
	RFile f;
sl@0
   734
	TInt r=TheFs.Delete(_L("FILEATT.ARC"));
sl@0
   735
	test(r==KErrNone || r==KErrNotFound);
sl@0
   736
	r=f.Create(TheFs,_L("FILEATT.ARC"),EFileRead);
sl@0
   737
	test(r==KErrNone);
sl@0
   738
	TUint atts;
sl@0
   739
	r=f.Att(atts);
sl@0
   740
	test(r==KErrNone);
sl@0
   741
	test((atts&ATT_MASK)==KEntryAttArchive);
sl@0
   742
	TEntry fileAtt;
sl@0
   743
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   744
	test(r==KErrNone);
sl@0
   745
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   746
	f.Close();
sl@0
   747
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   748
	test(r==KErrNone);
sl@0
   749
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   750
sl@0
   751
	test.Next(_L("Archive att is set after a write"));
sl@0
   752
	TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
sl@0
   753
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   754
	test(r==KErrNone);
sl@0
   755
	test(fileAtt.iAtt==0);
sl@0
   756
	r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
sl@0
   757
	test(r==KErrNone);
sl@0
   758
	r=f.Write(_L8("Hello World"));
sl@0
   759
	test(r==KErrNone);
sl@0
   760
	r=f.Att(atts);
sl@0
   761
	test(r==KErrNone);
sl@0
   762
	test((atts&ATT_MASK)==KEntryAttArchive);
sl@0
   763
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   764
	test(r==KErrNone);
sl@0
   765
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   766
	f.Close();
sl@0
   767
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   768
	test(r==KErrNone);
sl@0
   769
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   770
sl@0
   771
	test.Next(_L("Archive att is set after setsize"));
sl@0
   772
	TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
sl@0
   773
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   774
	test(r==KErrNone);
sl@0
   775
	test(fileAtt.iAtt==0);
sl@0
   776
	r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
sl@0
   777
	test(r==KErrNone);
sl@0
   778
	r=f.SetSize(447);
sl@0
   779
	test(r==KErrNone);
sl@0
   780
	TInt size;
sl@0
   781
	r=f.Size(size);
sl@0
   782
	test(r==KErrNone);
sl@0
   783
	test(size==447);
sl@0
   784
	r=f.Att(atts);
sl@0
   785
	test(r==KErrNone);
sl@0
   786
	test((atts&ATT_MASK)==KEntryAttArchive);
sl@0
   787
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   788
	test(r==KErrNone);
sl@0
   789
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   790
	f.Close();
sl@0
   791
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   792
	test(r==KErrNone);
sl@0
   793
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   794
sl@0
   795
	test.Next(_L("Archive att is not set after open"));
sl@0
   796
	r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
sl@0
   797
	test(r==KErrNone);
sl@0
   798
	r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
sl@0
   799
	test(r==KErrNone);
sl@0
   800
	r=f.Att(atts);
sl@0
   801
	test(r==KErrNone);
sl@0
   802
	test((atts&ATT_MASK)==0);
sl@0
   803
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   804
	test(r==KErrNone);
sl@0
   805
	test(fileAtt.iAtt==0);
sl@0
   806
	f.Close();
sl@0
   807
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   808
	test(r==KErrNone);
sl@0
   809
	test(fileAtt.iAtt==0);
sl@0
   810
sl@0
   811
	test.Next(_L("Archive att is not set after a read"));
sl@0
   812
	TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
sl@0
   813
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   814
	test(r==KErrNone);
sl@0
   815
	test(fileAtt.iAtt==0);
sl@0
   816
	r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
sl@0
   817
	test(r==KErrNone);
sl@0
   818
	TBuf8<16> readBuf;
sl@0
   819
	r=f.Read(readBuf);
sl@0
   820
	test(r==KErrNone);
sl@0
   821
	r=f.Att(atts);
sl@0
   822
	test(r==KErrNone);
sl@0
   823
	test((atts&ATT_MASK)==0);
sl@0
   824
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   825
	test(r==KErrNone);
sl@0
   826
	test(fileAtt.iAtt==0);
sl@0
   827
	f.Close();
sl@0
   828
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   829
	test(r==KErrNone);
sl@0
   830
	test(fileAtt.iAtt==0);
sl@0
   831
sl@0
   832
	test.Next(_L("Archive att is set after replace"));
sl@0
   833
	r=f.Replace(TheFs,_L("FILEATT.ARC"),EFileWrite);
sl@0
   834
	test(r==KErrNone);
sl@0
   835
	r=f.Att(atts);
sl@0
   836
	test(r==KErrNone);
sl@0
   837
	test((atts&ATT_MASK)==KEntryAttArchive);
sl@0
   838
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   839
	test(r==KErrNone);
sl@0
   840
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   841
	f.Close();
sl@0
   842
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   843
	test(r==KErrNone);
sl@0
   844
	test(fileAtt.iAtt==KEntryAttArchive);
sl@0
   845
sl@0
   846
	test.Next(_L("Read only bit can be unset"));
sl@0
   847
	r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0);
sl@0
   848
	test(r==KErrNone);
sl@0
   849
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   850
	test(r==KErrNone);
sl@0
   851
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
sl@0
   852
sl@0
   853
	r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden);
sl@0
   854
	test(r==KErrNone);
sl@0
   855
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   856
	test(r==KErrNone);
sl@0
   857
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive));
sl@0
   858
sl@0
   859
	r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly);
sl@0
   860
	test(r==KErrNone);
sl@0
   861
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   862
	test(r==KErrNone);
sl@0
   863
	test(fileAtt.iAtt==(KEntryAttArchive));
sl@0
   864
sl@0
   865
	r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0);
sl@0
   866
	test(r==KErrNone);
sl@0
   867
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   868
	test(r==KErrNone);
sl@0
   869
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
sl@0
   870
sl@0
   871
	r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly);
sl@0
   872
	test(r==KErrNone);
sl@0
   873
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   874
	test(r==KErrNone);
sl@0
   875
	test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive));
sl@0
   876
sl@0
   877
	r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden);
sl@0
   878
	test(r==KErrNone);
sl@0
   879
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   880
	test(r==KErrNone);
sl@0
   881
	test(fileAtt.iAtt==(KEntryAttArchive));
sl@0
   882
sl@0
   883
	TTime time(0);
sl@0
   884
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0);
sl@0
   885
	test(r==KErrNone);
sl@0
   886
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   887
	test(r==KErrNone);
sl@0
   888
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
sl@0
   889
sl@0
   890
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden);
sl@0
   891
	test(r==KErrNone);
sl@0
   892
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   893
	test(r==KErrNone);
sl@0
   894
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive));
sl@0
   895
sl@0
   896
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly);
sl@0
   897
	test(r==KErrNone);
sl@0
   898
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   899
	test(r==KErrNone);
sl@0
   900
	test(fileAtt.iAtt==(KEntryAttArchive));
sl@0
   901
sl@0
   902
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0);
sl@0
   903
	test(r==KErrNone);
sl@0
   904
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   905
	test(r==KErrNone);
sl@0
   906
	test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
sl@0
   907
sl@0
   908
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly);
sl@0
   909
	test(r==KErrNone);
sl@0
   910
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   911
	test(r==KErrNone);
sl@0
   912
	test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive));
sl@0
   913
sl@0
   914
	r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden);
sl@0
   915
	test(r==KErrNone);
sl@0
   916
	r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
sl@0
   917
	test(r==KErrNone);
sl@0
   918
	test(fileAtt.iAtt==(KEntryAttArchive));
sl@0
   919
sl@0
   920
	test.Next(_L("Cashing the 'read-only' attribute"));
sl@0
   921
	const TDesC& fname = _L("TEST.RO");
sl@0
   922
sl@0
   923
	// Test RO attribute after creating a file
sl@0
   924
	r=f.Create(TheFs,fname,EFileWrite);
sl@0
   925
	test(r==KErrNone);
sl@0
   926
	r=f.SetAtt(KEntryAttReadOnly,0);
sl@0
   927
	test(r==KErrNone);
sl@0
   928
	r=f.Write(_L8("Hello World"));
sl@0
   929
	test(r==KErrNone);					// <-- here!
sl@0
   930
	f.Close();
sl@0
   931
sl@0
   932
	// Test we can't open for write or delete a RO file
sl@0
   933
	r=f.Open(TheFs,fname,EFileWrite);
sl@0
   934
	test(r==KErrAccessDenied);
sl@0
   935
	r=TheFs.Delete(fname);
sl@0
   936
	test(r==KErrAccessDenied);
sl@0
   937
sl@0
   938
	// Tidy up and re-create test file
sl@0
   939
	r=TheFs.SetAtt(fname,0,KEntryAttReadOnly);
sl@0
   940
	test(r==KErrNone);
sl@0
   941
	r=TheFs.Delete(fname);
sl@0
   942
	test(r==KErrNone);
sl@0
   943
	r=f.Create(TheFs,fname,EFileWrite);
sl@0
   944
	test(r==KErrNone);
sl@0
   945
	f.Close();
sl@0
   946
sl@0
   947
	// Test RO attribute after opening a file
sl@0
   948
	r=f.Open(TheFs,fname,EFileWrite);
sl@0
   949
	test(r==KErrNone);
sl@0
   950
	r=f.SetAtt(KEntryAttReadOnly,0);
sl@0
   951
	test(r==KErrNone);
sl@0
   952
	r=f.Write(_L8("Hello World"));
sl@0
   953
	test(r==KErrNone);
sl@0
   954
	f.Close();
sl@0
   955
sl@0
   956
	// Tidy up
sl@0
   957
	r=TheFs.SetAtt(fname,0,KEntryAttReadOnly);
sl@0
   958
	test(r==KErrNone);
sl@0
   959
	r=TheFs.Delete(fname);
sl@0
   960
	test(r==KErrNone);
sl@0
   961
	}
sl@0
   962
sl@0
   963
static void testShortNameAccessorFunctions()
sl@0
   964
//
sl@0
   965
// Test RFs::GetShortName(...)
sl@0
   966
//
sl@0
   967
	{
sl@0
   968
	test.Next(_L("Test short name accessor functions"));
sl@0
   969
sl@0
   970
    if(!gShortFileNamesSupported)
sl@0
   971
        {
sl@0
   972
        test.Printf(_L("Short Names are not supported!. Skipping..."));
sl@0
   973
        return;
sl@0
   974
        }
sl@0
   975
sl@0
   976
sl@0
   977
	TBuf<64> sessionPath;
sl@0
   978
	TInt r=TheFs.SessionPath(sessionPath);
sl@0
   979
	test(r==KErrNone);
sl@0
   980
	RFile f;
sl@0
   981
	r=TheFs.MkDirAll(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\RANDOM.ENDBIT"));
sl@0
   982
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   983
	r=f.Replace(TheFs,_L("LONGFILENAME.LONGEXT"),EFileWrite);
sl@0
   984
	test(r==KErrNone);
sl@0
   985
	f.Close();
sl@0
   986
	r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),EFileWrite);
sl@0
   987
	test(r==KErrNone);
sl@0
   988
	f.Close();
sl@0
   989
	r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),EFileWrite);
sl@0
   990
	test(r==KErrNone);
sl@0
   991
	f.Close();
sl@0
   992
	r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GoodCHAR.TXT"),EFileWrite);
sl@0
   993
	test(r==KErrNone);
sl@0
   994
	f.Close();
sl@0
   995
	TBuf<12> shortName1;
sl@0
   996
	TBuf<12> shortName2;
sl@0
   997
	TBuf<12> shortName3;
sl@0
   998
	TBuf<12> shortName4;
sl@0
   999
	TBuf<12> shortName5;
sl@0
  1000
	r=TheFs.GetShortName(_L("LONGFILENAME.LONGEXT"),shortName1);
sl@0
  1001
	test(r==KErrNone);
sl@0
  1002
	r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),shortName2);
sl@0
  1003
	test(r==KErrNone);
sl@0
  1004
	r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),shortName3);
sl@0
  1005
	test(r==KErrNone);
sl@0
  1006
	r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),shortName4);
sl@0
  1007
	test(r==KErrNone);
sl@0
  1008
	r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY"),shortName5);
sl@0
  1009
	test(r==KErrNone);
sl@0
  1010
sl@0
  1011
	if(Is_Win32(TheFs, gDriveNum))
sl@0
  1012
		{
sl@0
  1013
		test(shortName1==_L("LONGFI~1.LON"));
sl@0
  1014
		test(shortName2==_L("LONGFI~1.LON"));
sl@0
  1015
		test(shortName3==_L("BADCHA~1"));
sl@0
  1016
		test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0);
sl@0
  1017
		test(shortName5==_L("MIDDLE~1"));
sl@0
  1018
		}
sl@0
  1019
	else if(!IsTestingLFFS())
sl@0
  1020
		{
sl@0
  1021
		// LFFS short names not the same as VFAT ones
sl@0
  1022
		test(shortName1==_L("LONGFI~1.LON"));
sl@0
  1023
		test(shortName2==_L("LONGFI~1.LON"));
sl@0
  1024
		test(shortName3==_L("BAD_CHAR"));
sl@0
  1025
		test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0);
sl@0
  1026
		test(shortName5==_L("MIDDLE~1"));
sl@0
  1027
		}
sl@0
  1028
sl@0
  1029
	TFileName longName1;
sl@0
  1030
	TFileName longName2;
sl@0
  1031
	TFileName longName3;
sl@0
  1032
	TFileName longName4;
sl@0
  1033
	TFileName longName5;
sl@0
  1034
sl@0
  1035
	if (Is_Win32(TheFs, gDriveNum))
sl@0
  1036
		{
sl@0
  1037
		r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1);
sl@0
  1038
		test(r==KErrNone);
sl@0
  1039
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2);
sl@0
  1040
		test(r==KErrNone);
sl@0
  1041
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BADCHA~1"),longName3);
sl@0
  1042
		test(r==KErrNone);
sl@0
  1043
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4);
sl@0
  1044
		test(r==KErrNone);
sl@0
  1045
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5);
sl@0
  1046
		test(r==KErrNone);
sl@0
  1047
		}
sl@0
  1048
	else if (!IsTestingLFFS())
sl@0
  1049
		{
sl@0
  1050
		r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1);
sl@0
  1051
		test(r==KErrNone);
sl@0
  1052
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2);
sl@0
  1053
		test(r==KErrNone);
sl@0
  1054
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD_CHAR"),longName3);
sl@0
  1055
		test(r==KErrNone);
sl@0
  1056
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4);
sl@0
  1057
		test(r==KErrNone);
sl@0
  1058
		r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5);
sl@0
  1059
		test(r==KErrNone);
sl@0
  1060
		}
sl@0
  1061
    else
sl@0
  1062
    	{
sl@0
  1063
		// LFFS longname tests
sl@0
  1064
        r=TheFs.GetLongName(shortName1,longName1);
sl@0
  1065
        test(r==KErrNone);
sl@0
  1066
        r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\"));
sl@0
  1067
        test(r==KErrNone);
sl@0
  1068
        r=TheFs.GetLongName(shortName2,longName2);
sl@0
  1069
        test(r==KErrNone);
sl@0
  1070
        r=TheFs.GetLongName(shortName3,longName3);
sl@0
  1071
        test(r==KErrNone);
sl@0
  1072
        r=TheFs.GetLongName(shortName4,longName4);
sl@0
  1073
        test(r==KErrNone);
sl@0
  1074
        r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\"));
sl@0
  1075
        test(r==KErrNone);
sl@0
  1076
        r=TheFs.GetLongName(shortName5,longName5);
sl@0
  1077
        test(r==KErrNone);
sl@0
  1078
        r=TheFs.SetSessionPath(sessionPath);
sl@0
  1079
        test(r==KErrNone);
sl@0
  1080
    	}
sl@0
  1081
sl@0
  1082
	test(longName1==_L("LONGFILENAME.LONGEXT"));
sl@0
  1083
	test(longName2==_L("LONGFILENAME.LONGEXT"));
sl@0
  1084
	test(longName3==_L("BAD CHAR"));
sl@0
  1085
	test(longName4.FindF(_L("GOODCHAR.TXT"))>=0);
sl@0
  1086
	test(longName5==_L("MIDDLE-DIRECTORY"));
sl@0
  1087
sl@0
  1088
	r=TheFs.GetShortName(_L("XXX.YYY"),shortName1);
sl@0
  1089
	test(r==KErrNotFound);
sl@0
  1090
	r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),shortName1);
sl@0
  1091
	test(r==KErrPathNotFound);
sl@0
  1092
	r=TheFs.GetLongName(_L("XXX.YYY"),longName1);
sl@0
  1093
	test(r==KErrNotFound);
sl@0
  1094
	r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),longName1);
sl@0
  1095
	test(r==KErrPathNotFound);
sl@0
  1096
sl@0
  1097
	r=TheFs.Delete(_L("LONGFILENAME.LONGEXT"));
sl@0
  1098
	test(r==KErrNone);
sl@0
  1099
sl@0
  1100
	TEntry romEntry;
sl@0
  1101
	r=TheFs.Entry(_L("Z:\\System"),romEntry);
sl@0
  1102
	if (r==KErrNotReady)
sl@0
  1103
		{
sl@0
  1104
		test.Printf(_L("ERROR: No rom filesystem present"));
sl@0
  1105
		//test.Getch();
sl@0
  1106
		//return;
sl@0
  1107
		}
sl@0
  1108
	test(r==KErrNone);
sl@0
  1109
	TBuf<64> romFileName=_L("Z:\\");
sl@0
  1110
	romFileName.Append(romEntry.iName);
sl@0
  1111
	r=TheFs.GetShortName(romFileName,shortName1);
sl@0
  1112
	test(r==KErrNotSupported);
sl@0
  1113
	r=TheFs.GetLongName(_L("Z:\\system"),longName1);
sl@0
  1114
	test(r==KErrNotSupported);
sl@0
  1115
	}
sl@0
  1116
sl@0
  1117
static void RmDir(const TDesC& aDirName)
sl@0
  1118
//
sl@0
  1119
// Remove a directory
sl@0
  1120
//
sl@0
  1121
	{
sl@0
  1122
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
  1123
	test(fMan!=NULL);
sl@0
  1124
	TInt r=TheFs.SessionPath(gSessionPath);
sl@0
  1125
	test(r==KErrNone);
sl@0
  1126
	r=TheFs.CheckDisk(gSessionPath);
sl@0
  1127
	if (r!=KErrNone && r!=KErrNotSupported)
sl@0
  1128
		ReportCheckDiskFailure(r);
sl@0
  1129
sl@0
  1130
	TFileName removeDirName = gSessionPath;
sl@0
  1131
	removeDirName.Append(aDirName);
sl@0
  1132
sl@0
  1133
	fMan->Attribs(removeDirName, 0, KEntryAttReadOnly, 0, CFileMan::ERecurse);
sl@0
  1134
	r=fMan->RmDir(removeDirName);
sl@0
  1135
	test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
sl@0
  1136
sl@0
  1137
	delete fMan;
sl@0
  1138
	}
sl@0
  1139
//---------------------------------------------
sl@0
  1140
//! @SYMTestCaseID			PBASE-T_TFILE-0659
sl@0
  1141
//! @SYMTestType			CT
sl@0
  1142
//! @SYMREQ					INC112803
sl@0
  1143
//! @SYMTestCaseDesc		Tests that RFs::GetShortName() considers the file extension while generating
sl@0
  1144
//!							shortname from longname and applies ~num if applicable.
sl@0
  1145
//! @SYMTestActions			1. Generates the shortname for the given filename.
sl@0
  1146
//! 						2. Validates the generated shortname against the original filename.
sl@0
  1147
//! @SYMTestExpectedResults	The operation completes with no error. Valid shortname is generated.
sl@0
  1148
//! @SYMTestPriority		High
sl@0
  1149
//! @SYMTestStatus			Implemented
sl@0
  1150
//---------------------------------------------
sl@0
  1151
static void TestINC112803()
sl@0
  1152
	{
sl@0
  1153
sl@0
  1154
    if(!gShortFileNamesSupported)
sl@0
  1155
        {
sl@0
  1156
        test.Printf(_L("TestINC112803 : Short names are not supported!\n"));
sl@0
  1157
        return;
sl@0
  1158
        }
sl@0
  1159
sl@0
  1160
sl@0
  1161
	TInt err =0;
sl@0
  1162
	_LIT(KOrigFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JARX");
sl@0
  1163
	_LIT(KOrigFileShortName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222~1.JAR");
sl@0
  1164
	_LIT(KDestinationFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JAR");
sl@0
  1165
sl@0
  1166
	// Make sure the file does not already exist
sl@0
  1167
	RmDir(_L("INC112803\\"));
sl@0
  1168
sl@0
  1169
	// Create directories and the file
sl@0
  1170
	MakeDir(_L("\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
sl@0
  1171
	MakeFile(KOrigFileName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
sl@0
  1172
sl@0
  1173
	// Check the generated shortname of the original file
sl@0
  1174
	TBuf<12> shortName;
sl@0
  1175
	err = TheFs.GetShortName(KOrigFileName, shortName);
sl@0
  1176
	test(err==KErrNone);
sl@0
  1177
sl@0
  1178
	// Validate the generated shorname against the original filename.
sl@0
  1179
	if (Is_Win32(TheFs, gDriveNum))
sl@0
  1180
		{
sl@0
  1181
		test(shortName==_L("2222~1.JAR"));
sl@0
  1182
		}
sl@0
  1183
	else if(!IsTestingLFFS())
sl@0
  1184
		{
sl@0
  1185
		// LFFS short names not the same as VFAT ones
sl@0
  1186
		test(shortName==_L("2222~1.JAR"));
sl@0
  1187
		}
sl@0
  1188
sl@0
  1189
	// Validate that the file "2222~1.JAR" can not be created as this is the shortname for "2222.JARX".
sl@0
  1190
	MakeFile(KOrigFileShortName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
sl@0
  1191
	CheckFileExists(KOrigFileShortName, KErrNone, EFalse);
sl@0
  1192
sl@0
  1193
	err = TheFs.Rename(KOrigFileName,KDestinationFileName);
sl@0
  1194
	test(err==KErrNone);
sl@0
  1195
sl@0
  1196
	// Clean up before leaving
sl@0
  1197
	RmDir(_L("INC112803\\"));
sl@0
  1198
	}
sl@0
  1199
sl@0
  1200
static void testIsFileOpen()
sl@0
  1201
//
sl@0
  1202
// Test the IsFileOpen method
sl@0
  1203
//
sl@0
  1204
	{
sl@0
  1205
sl@0
  1206
	test.Next(_L("Test IsFileOpen"));
sl@0
  1207
	TBool answer;
sl@0
  1208
	TInt r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1209
	test(r==KErrNotFound || (r==KErrNone && answer==EFalse));
sl@0
  1210
	RFile f;
sl@0
  1211
	r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite);
sl@0
  1212
	test(r==KErrNone);
sl@0
  1213
	r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1214
	test(r==KErrNone);
sl@0
  1215
	test(answer!=EFalse);
sl@0
  1216
	f.Close();
sl@0
  1217
	r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1218
	test(r==KErrNone);
sl@0
  1219
	test(answer==EFalse);
sl@0
  1220
	r=TheFs.Delete(_L("OPEN.FILE"));
sl@0
  1221
	test(r==KErrNone);
sl@0
  1222
sl@0
  1223
	RFile f2;
sl@0
  1224
	r=f2.Replace(TheFs,_L("AnotherOpen.File"),EFileWrite);
sl@0
  1225
	test(r==KErrNone);
sl@0
  1226
	r=TheFs.IsFileOpen(_L("AnotherOpen.File"),answer);
sl@0
  1227
	test(r==KErrNone);
sl@0
  1228
	test(answer!=EFalse);
sl@0
  1229
	r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite);
sl@0
  1230
	test(r==KErrNone);
sl@0
  1231
	r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1232
	test(r==KErrNone);
sl@0
  1233
	test(answer!=EFalse);
sl@0
  1234
	f2.Close();
sl@0
  1235
	r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1236
	test(r==KErrNone);
sl@0
  1237
	test(answer!=EFalse);
sl@0
  1238
	f.Close();
sl@0
  1239
	r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
sl@0
  1240
	test(r==KErrNone);
sl@0
  1241
	test(answer==EFalse);
sl@0
  1242
	r=TheFs.Delete(_L("AnotherOpen.File"));
sl@0
  1243
	test(r==KErrNone);
sl@0
  1244
	r=TheFs.Delete(_L("OPEN.FILE"));
sl@0
  1245
	test(r==KErrNone);
sl@0
  1246
	}
sl@0
  1247
sl@0
  1248
static void testDeleteOpenFiles()
sl@0
  1249
//
sl@0
  1250
// Test opened files cannot be deleted
sl@0
  1251
//
sl@0
  1252
	{
sl@0
  1253
sl@0
  1254
	test.Next(_L("Test opened files cannot be deleted"));
sl@0
  1255
	RFile f;
sl@0
  1256
	f.Close();
sl@0
  1257
	TInt r=f.Replace(TheFs,_L("Open.File"),EFileWrite);
sl@0
  1258
	test(r==KErrNone);
sl@0
  1259
	r=TheFs.Delete(_L("OPEN.FILE"));
sl@0
  1260
	test(r==KErrInUse);
sl@0
  1261
	f.Close();
sl@0
  1262
	f.Close();
sl@0
  1263
	f.Close();
sl@0
  1264
	r=TheFs.Delete(_L("Open.FILe"));
sl@0
  1265
	test(r==KErrNone);
sl@0
  1266
sl@0
  1267
	TFileName fileName;
sl@0
  1268
	r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
sl@0
  1269
	test(r==KErrNone);
sl@0
  1270
	r=TheFs.Delete(fileName);
sl@0
  1271
	test(r==KErrInUse);
sl@0
  1272
	f.Close();
sl@0
  1273
	r=TheFs.Delete(fileName);
sl@0
  1274
	test(r==KErrNone);
sl@0
  1275
sl@0
  1276
	MakeFile(_L("\\Documents\\TEstfile.txt"));
sl@0
  1277
	r=f.Open(TheFs,_L("\\Documents\\TEstfile.txt"),EFileWrite);
sl@0
  1278
	test(r==KErrNone);
sl@0
  1279
	r=TheFs.Delete(_L("\\Documents\\TEstfile.txt"));
sl@0
  1280
	test(r==KErrInUse);
sl@0
  1281
	r=TheFs.Delete(_L("\\documents\\TEstfile.txt"));
sl@0
  1282
	test(r==KErrInUse);
sl@0
  1283
	r=TheFs.Delete(_L("\\Documents.\\TEstfile.txt"));
sl@0
  1284
	test(r==KErrBadName);
sl@0
  1285
	r=TheFs.Delete(_L("\\documents.\\TEstfile.txt"));
sl@0
  1286
	test(r==KErrBadName);
sl@0
  1287
	r=TheFs.Delete(_L("\\Documents\\Testfile.txt"));
sl@0
  1288
	test(r==KErrInUse);
sl@0
  1289
	r=TheFs.Delete(_L("\\documents\\testfile.txt"));
sl@0
  1290
	test(r==KErrInUse);
sl@0
  1291
	r=TheFs.Delete(_L("\\Documents.\\TEstfile.TXT"));
sl@0
  1292
	test(r==KErrBadName);
sl@0
  1293
	r=TheFs.Delete(_L("\\docUMENTS.\\TESTFILE.TXT"));
sl@0
  1294
	test(r==KErrBadName);
sl@0
  1295
	f.Close();
sl@0
  1296
	r=TheFs.Delete(_L("\\Documents\\TEstfile.TXT"));
sl@0
  1297
	test(r==KErrNone);
sl@0
  1298
sl@0
  1299
	MakeFile(_L("\\Documents\\Documents\\TEstfile.txt"));
sl@0
  1300
	r=f.Open(TheFs,_L("\\Documents\\Documents\\TEstfile.txt"),EFileWrite);
sl@0
  1301
	test(r==KErrNone);
sl@0
  1302
	r=TheFs.Delete(_L("\\Documents\\documents.\\TEstfile.txt"));
sl@0
  1303
	test(r==KErrBadName);
sl@0
  1304
	r=TheFs.Delete(_L("\\documents\\Documents.\\TEstfile.txt"));
sl@0
  1305
	test(r==KErrBadName);
sl@0
  1306
	r=TheFs.Delete(_L("\\Documents.\\documents\\TEstfile.txt"));
sl@0
  1307
	test(r==KErrBadName);
sl@0
  1308
	r=TheFs.Delete(_L("\\documents.\\Documents\\TEstfile.txt"));
sl@0
  1309
	test(r==KErrBadName);
sl@0
  1310
	r=TheFs.Delete(_L("\\Documents\\Documents\\Testfile.txt"));
sl@0
  1311
	test(r==KErrInUse);
sl@0
  1312
	r=TheFs.Delete(_L("\\documents\\documents\\testfile.txt"));
sl@0
  1313
	test(r==KErrInUse);
sl@0
  1314
	r=TheFs.Delete(_L("\\Documents.\\Documents.\\TEstfile.TXT"));
sl@0
  1315
	test(r==KErrBadName);
sl@0
  1316
	r=TheFs.Delete(_L("\\docUMENTS.\\docUMENTS.\\TESTFILE.TXT"));
sl@0
  1317
	test(r==KErrBadName);
sl@0
  1318
sl@0
  1319
sl@0
  1320
	r=TheFs.RmDir(_L("\\Documents\\"));
sl@0
  1321
	test(r==KErrInUse);
sl@0
  1322
	r=TheFs.RmDir(_L("\\documents\\"));
sl@0
  1323
	test(r==KErrInUse);
sl@0
  1324
	r=TheFs.RmDir(_L("\\Documents.\\"));
sl@0
  1325
	test(r==KErrBadName);
sl@0
  1326
	r=TheFs.RmDir(_L("\\documents.\\"));
sl@0
  1327
	test(r==KErrBadName);
sl@0
  1328
	r=TheFs.RmDir(_L("\\Documents\\documents\\"));
sl@0
  1329
	test(r==KErrInUse);
sl@0
  1330
	r=TheFs.RmDir(_L("\\documents\\documents.\\"));
sl@0
  1331
	test(r==KErrBadName);
sl@0
  1332
	r=TheFs.RmDir(_L("\\Documents.\\Documents\\"));
sl@0
  1333
	test(r==KErrBadName);
sl@0
  1334
	r=TheFs.RmDir(_L("\\documents.\\Documents.\\"));
sl@0
  1335
	test(r==KErrBadName);
sl@0
  1336
	r=TheFs.RmDir(_L("\\Documents\\TestFile.TXT"));
sl@0
  1337
	test(r==KErrInUse);
sl@0
  1338
	r=TheFs.RmDir(_L("\\documents\\TestFile"));
sl@0
  1339
	test(r==KErrInUse);
sl@0
  1340
	r=TheFs.RmDir(_L("\\Documents.\\Testfile."));
sl@0
  1341
	test(r==KErrBadName);
sl@0
  1342
	r=TheFs.RmDir(_L("\\documents.\\t"));
sl@0
  1343
	test(r==KErrBadName);
sl@0
  1344
	f.Close();
sl@0
  1345
	r=TheFs.Delete(_L("\\Documents\\documents\\TEstfile.TXT"));
sl@0
  1346
	test(r==KErrNone);
sl@0
  1347
	r=TheFs.RmDir(_L("\\Documents\\documents.\\"));
sl@0
  1348
	test(r==KErrBadName);
sl@0
  1349
	r=TheFs.RmDir(_L("\\Documents.\\"));
sl@0
  1350
	test(r==KErrBadName);
sl@0
  1351
	}
sl@0
  1352
sl@0
  1353
static void testFileSeek()
sl@0
  1354
//
sl@0
  1355
// Test seeking
sl@0
  1356
//
sl@0
  1357
	{
sl@0
  1358
	test.Next(_L("Test file seek"));
sl@0
  1359
	RFile f;
sl@0
  1360
	TInt r=f.Open(TheFs,_L("T_File.cpp"),EFileWrite);
sl@0
  1361
	test(r==KErrNone);
sl@0
  1362
sl@0
  1363
	TBuf8<20> text1;TInt pos1=0;
sl@0
  1364
	TBuf8<20> text2;TInt pos2=510;
sl@0
  1365
	TBuf8<20> text3;TInt pos3=900;
sl@0
  1366
	TBuf8<20> text4;TInt pos4=2010;
sl@0
  1367
	TBuf8<20> text5;TInt pos5=4999;
sl@0
  1368
sl@0
  1369
	r=f.Read(pos1,text1);
sl@0
  1370
	test(r==KErrNone);
sl@0
  1371
	r=f.Read(pos2,text2);
sl@0
  1372
	test(r==KErrNone);
sl@0
  1373
	r=f.Read(pos3,text3);
sl@0
  1374
	test(r==KErrNone);
sl@0
  1375
	r=f.Read(pos4,text4);
sl@0
  1376
	test(r==KErrNone);
sl@0
  1377
	r=f.Read(pos5,text5);
sl@0
  1378
	test(r==KErrNone);
sl@0
  1379
sl@0
  1380
	TBuf8<20> testBuf;
sl@0
  1381
sl@0
  1382
	r=f.Read(pos3,testBuf);
sl@0
  1383
	test(r==KErrNone);
sl@0
  1384
	test(testBuf==text3);
sl@0
  1385
sl@0
  1386
	r=f.Read(pos1,testBuf);
sl@0
  1387
	test(r==KErrNone);
sl@0
  1388
	test(testBuf==text1);
sl@0
  1389
sl@0
  1390
	r=f.Read(pos4,testBuf);
sl@0
  1391
	test(r==KErrNone);
sl@0
  1392
	test(testBuf==text4);
sl@0
  1393
sl@0
  1394
	r=f.Read(pos2,testBuf);
sl@0
  1395
	test(r==KErrNone);
sl@0
  1396
	test(testBuf==text2);
sl@0
  1397
sl@0
  1398
	r=f.Read(pos5,testBuf);
sl@0
  1399
	test(r==KErrNone);
sl@0
  1400
	test(testBuf==text5);
sl@0
  1401
sl@0
  1402
	r=f.Read(pos2,testBuf);
sl@0
  1403
	test(r==KErrNone);
sl@0
  1404
	test(testBuf==text2);
sl@0
  1405
	r=f.SetSize(1023);
sl@0
  1406
	test(r==KErrNone);
sl@0
  1407
	r=f.Read(pos2,testBuf);
sl@0
  1408
	test(r==KErrNone);
sl@0
  1409
	test(testBuf==text2);
sl@0
  1410
	r=f.SetSize(1024);
sl@0
  1411
	test(r==KErrNone);
sl@0
  1412
	r=f.Read(pos1,testBuf);
sl@0
  1413
	test(r==KErrNone);
sl@0
  1414
	test(testBuf==text1);
sl@0
  1415
	r=f.Read(pos2,testBuf);
sl@0
  1416
	test(r==KErrNone);
sl@0
  1417
	test(testBuf==text2);
sl@0
  1418
sl@0
  1419
	r=f.Read(pos1,testBuf);
sl@0
  1420
	test(r==KErrNone);
sl@0
  1421
	test(testBuf==text1);
sl@0
  1422
	r=f.SetSize(511);
sl@0
  1423
	test(r==KErrNone);
sl@0
  1424
	r=f.Read(pos1,testBuf);
sl@0
  1425
	test(r==KErrNone);
sl@0
  1426
	test(testBuf==text1);
sl@0
  1427
	r=f.SetSize(512);
sl@0
  1428
	test(r==KErrNone);
sl@0
  1429
	r=f.Read(pos1,testBuf);
sl@0
  1430
	test(r==KErrNone);
sl@0
  1431
	test(testBuf==text1);
sl@0
  1432
	f.Close();
sl@0
  1433
	}
sl@0
  1434
sl@0
  1435
static void testMoreFileSeek()
sl@0
  1436
//
sl@0
  1437
//	Further test of RFile::Seek()
sl@0
  1438
//
sl@0
  1439
	{
sl@0
  1440
//	Create a zero length file
sl@0
  1441
	RFile file;
sl@0
  1442
	TInt r=file.Replace(TheFs,_L("\\F32-TST\\TFILE\\seektest"),EFileRead|EFileWrite);
sl@0
  1443
	test(r==KErrNone);
sl@0
  1444
	r=file.SetSize(20);
sl@0
  1445
	test(r==KErrNone);
sl@0
  1446
//	Seek beyond the length of the file
sl@0
  1447
	TInt seekPos;
sl@0
  1448
	seekPos = 80;								//	Pick a likely offset
sl@0
  1449
    TInt err = file.Seek(ESeekEnd, seekPos);	//	and go there
sl@0
  1450
    test(err==KErrNone);
sl@0
  1451
	test(seekPos==20);							//	Somewhat non-intuitive?
sl@0
  1452
sl@0
  1453
	r=file.Write(_L8("A Devil's Haircut"));
sl@0
  1454
	test(r==KErrNone);
sl@0
  1455
	TInt newFileSize;
sl@0
  1456
	r=file.Size(newFileSize);
sl@0
  1457
	test(r==KErrNone);
sl@0
  1458
sl@0
  1459
	seekPos = 0;
sl@0
  1460
    err = file.Seek(ESeekCurrent, seekPos);		//	Find out where we ended up?
sl@0
  1461
	test(err==KErrNone);
sl@0
  1462
	test(seekPos==37);
sl@0
  1463
sl@0
  1464
	file.SetSize(512);
sl@0
  1465
	seekPos=513;
sl@0
  1466
	err=file.Seek(ESeekStart, seekPos);
sl@0
  1467
	test(err==KErrNone);
sl@0
  1468
	test(seekPos==513);
sl@0
  1469
sl@0
  1470
	err=file.Seek(ESeekEnd, seekPos);
sl@0
  1471
	test(err==KErrNone);
sl@0
  1472
	test(seekPos==512);
sl@0
  1473
sl@0
  1474
	seekPos=-530;
sl@0
  1475
	err=file.Seek(ESeekEnd, seekPos);
sl@0
  1476
	test(err==KErrNone);
sl@0
  1477
	test(seekPos==0);
sl@0
  1478
sl@0
  1479
	seekPos=-10;
sl@0
  1480
	err=file.Seek(ESeekEnd, seekPos);
sl@0
  1481
	test(err==KErrNone);
sl@0
  1482
	test(seekPos==502);
sl@0
  1483
sl@0
  1484
	seekPos=-10;
sl@0
  1485
	err=file.Seek(ESeekStart,seekPos);
sl@0
  1486
	test(err==KErrArgument);
sl@0
  1487
	test(seekPos==-10);
sl@0
  1488
sl@0
  1489
	seekPos=0;
sl@0
  1490
	err=file.Seek(ESeekEnd,seekPos);
sl@0
  1491
	test(err==KErrNone);
sl@0
  1492
	test(seekPos==512);
sl@0
  1493
sl@0
  1494
	file.Close();
sl@0
  1495
	r=TheFs.Delete(_L("\\F32-TST\\TFILE\\seektest"));
sl@0
  1496
	test(r==KErrNone);
sl@0
  1497
	}
sl@0
  1498
sl@0
  1499
static void testSetSize()
sl@0
  1500
//
sl@0
  1501
// Test setsize
sl@0
  1502
//
sl@0
  1503
	{
sl@0
  1504
sl@0
  1505
	test.Next(_L("Test SetSize"));
sl@0
  1506
	RFile f1;
sl@0
  1507
	TInt i=0;
sl@0
  1508
	TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
sl@0
  1509
	test(r==KErrNone);
sl@0
  1510
	gBuf.SetLength(32);
sl@0
  1511
	for(i=0;i<32;i++)
sl@0
  1512
		gBuf[i]=(TUint8)i;
sl@0
  1513
	r=f1.Write(gBuf);
sl@0
  1514
	test(r==KErrNone);
sl@0
  1515
	gBuf.SetLength(1334);
sl@0
  1516
	for(i=64;i<1334+64;i++)
sl@0
  1517
		gBuf[i-64]=(TUint8)i;
sl@0
  1518
	r=f1.Write(30,gBuf);
sl@0
  1519
	r=f1.Read(30,gBuf,1000);
sl@0
  1520
	test(r==KErrNone);
sl@0
  1521
	test(gBuf[0]==64);
sl@0
  1522
	test(gBuf[1]==65);
sl@0
  1523
	test(gBuf[2]==66);
sl@0
  1524
	f1.Close();
sl@0
  1525
sl@0
  1526
	test.Next(_L("Open a large file"));
sl@0
  1527
	r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
sl@0
  1528
	test(r==KErrNone);
sl@0
  1529
	CheckDisk();
sl@0
  1530
	r=f1.SetSize(131072); // 128K
sl@0
  1531
	test(r==KErrNone);
sl@0
  1532
	TBuf8<16> testData=_L8("testData");
sl@0
  1533
	r=f1.Write(131060,testData);
sl@0
  1534
	test(r==KErrNone);
sl@0
  1535
	f1.Close();
sl@0
  1536
	r=f1.Open(TheFs,_L("File.File"),EFileRead);
sl@0
  1537
	test(r==KErrNone);
sl@0
  1538
	TInt size;
sl@0
  1539
	r=f1.Size(size);
sl@0
  1540
	test(r==KErrNone);
sl@0
  1541
	test(size==131072);
sl@0
  1542
	TBuf8<16> testData2;
sl@0
  1543
	r=f1.Read(131060,testData2,8);
sl@0
  1544
	test(r==KErrNone);
sl@0
  1545
	test(testData==testData2);
sl@0
  1546
	f1.Close();
sl@0
  1547
	TheFs.Delete(_L("File.file"));
sl@0
  1548
	CheckDisk();
sl@0
  1549
	}
sl@0
  1550
sl@0
  1551
static void testIsRomAddress()
sl@0
  1552
	{
sl@0
  1553
	RFile f;
sl@0
  1554
	TInt r=f.Open(TheFs, PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\eshell.exe"):_L("Z:\\System\\Bin\\eshell.exe"), EFileRead);
sl@0
  1555
	test(r==KErrNone);
sl@0
  1556
	TInt anAddress=0;
sl@0
  1557
	r=f.Seek(ESeekAddress, anAddress);
sl@0
  1558
	test(r==KErrNone);
sl@0
  1559
#if !defined(__WINS__)
sl@0
  1560
	test(RFs::IsRomAddress((TAny *)anAddress)); // Always returns EFalse if WINS
sl@0
  1561
#endif
sl@0
  1562
	test(RFs::IsRomAddress(NULL)==FALSE);
sl@0
  1563
	f.Close();
sl@0
  1564
	}
sl@0
  1565
sl@0
  1566
#include "../../../userlibandfileserver/fileserver/inc/message.h"
sl@0
  1567
#include <f32plugin.h>
sl@0
  1568
sl@0
  1569
static void testMiscellaneousReportedBugs()
sl@0
  1570
//
sl@0
  1571
// Test bug reports, real or imaginary
sl@0
  1572
//
sl@0
  1573
	{
sl@0
  1574
sl@0
  1575
	test.Next(_L("Miscellaneous tests"));
sl@0
  1576
	RFile f1;
sl@0
  1577
	TInt temp;
sl@0
  1578
	TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
sl@0
  1579
	test(r==KErrNone);
sl@0
  1580
	r=f1.Size(temp);
sl@0
  1581
	test(r==KErrNone);
sl@0
  1582
	test(temp==0);
sl@0
  1583
	TUint data=0;
sl@0
  1584
	TPtrC8 buf((TText8*)&data,1);
sl@0
  1585
	r=f1.Write(buf);
sl@0
  1586
//	r=f1.Write(_L("\0"));
sl@0
  1587
	test(r==KErrNone);
sl@0
  1588
	r=f1.Size(temp);
sl@0
  1589
	test(r==KErrNone);
sl@0
  1590
	test(temp==1);
sl@0
  1591
	temp=0;
sl@0
  1592
	r=f1.Seek(ESeekStart,temp);
sl@0
  1593
	test(r==KErrNone);
sl@0
  1594
	test(temp==0);
sl@0
  1595
	TBuf8<32> testBuf;
sl@0
  1596
	r=f1.Read(testBuf);
sl@0
  1597
	test(r==KErrNone);
sl@0
  1598
	test(testBuf==buf);
sl@0
  1599
	f1.Close();
sl@0
  1600
sl@0
  1601
	class RHackFile : public RFile
sl@0
  1602
	{
sl@0
  1603
	public:
sl@0
  1604
		inline TInt SendReceive(TInt aFunction, const TIpcArgs& aArgs) const
sl@0
  1605
			{ return RSubSessionBase::SendReceive(aFunction, aArgs); }
sl@0
  1606
	};
sl@0
  1607
sl@0
  1608
	RHackFile f2;
sl@0
  1609
	f2.Open(TheFs, _L("File.File"), EFileRead);
sl@0
  1610
	test(r == KErrNone);
sl@0
  1611
	r = f2.SendReceive(/*47*/ EFsFileChangeMode, TIpcArgs(EFileRead | EFileWrite));	// <- must fail!
sl@0
  1612
	test(r == KErrArgument);
sl@0
  1613
	r = f2.Write(_L8("Hacked!"));	// <- must fail!
sl@0
  1614
	test(r == KErrAccessDenied);
sl@0
  1615
	f2.Close();
sl@0
  1616
sl@0
  1617
	r=TheFs.Delete(_L("File.FIle"));
sl@0
  1618
	test(r==KErrNone);
sl@0
  1619
	}
sl@0
  1620
sl@0
  1621
static void testFileRename()
sl@0
  1622
//
sl@0
  1623
// Test rename
sl@0
  1624
//
sl@0
  1625
	{
sl@0
  1626
sl@0
  1627
	test.Next(_L("Test rename"));
sl@0
  1628
	TBuf<64> name1=_L("asdfasdfasdfasfd.qwer");
sl@0
  1629
	TBuf<64> name2=_L("File.xyz");
sl@0
  1630
	TBuf<64> name3=_L("ASdfasdFasdfasfd.qwer");
sl@0
  1631
	TBuf8<64> contents;
sl@0
  1632
sl@0
  1633
    TInt r;
sl@0
  1634
    RFile f1;
sl@0
  1635
sl@0
  1636
    //-- test renaming a file to a non-existing directory
sl@0
  1637
    r = TheFs.MkDir(_L("\\temp\\"));
sl@0
  1638
    test(r==KErrNone || r==KErrAlreadyExists);
sl@0
  1639
sl@0
  1640
    r = f1.Replace(TheFs, _L("\\temp\\file1"), 0);
sl@0
  1641
    test(r==KErrNone);
sl@0
  1642
sl@0
  1643
    r = f1.Rename(_L("\\temp\\temp\\file1"));
sl@0
  1644
    test(r == KErrPathNotFound);
sl@0
  1645
sl@0
  1646
    f1.Close();
sl@0
  1647
sl@0
  1648
sl@0
  1649
	r=f1.Replace(TheFs,name2,EFileWrite);
sl@0
  1650
	test(r==KErrNone);
sl@0
  1651
	r=f1.Write(_L8("1234"));
sl@0
  1652
	test(r==KErrNone);
sl@0
  1653
	TInt len=CheckFileExists(name2,KErrNone);
sl@0
  1654
	test(len==4);
sl@0
  1655
	r=f1.Rename(name1);
sl@0
  1656
	test(r==KErrNone);
sl@0
  1657
sl@0
  1658
	r=f1.Read(0,contents);
sl@0
  1659
	test(r==KErrNone);
sl@0
  1660
	test(contents==_L8("1234"));
sl@0
  1661
	r=f1.Write(4,_L8("5678"));
sl@0
  1662
	test(r==KErrNone);
sl@0
  1663
sl@0
  1664
	len=CheckFileExists(name1,KErrNone);
sl@0
  1665
	test(len==8);
sl@0
  1666
	CheckFileExists(name2,KErrNotFound);
sl@0
  1667
	r=f1.Write(8,_L8("90"));
sl@0
  1668
	test(r==KErrNone);
sl@0
  1669
	f1.Close();
sl@0
  1670
	len=CheckFileExists(name1,KErrNone);
sl@0
  1671
	test(len==10);
sl@0
  1672
sl@0
  1673
	test.Next(_L("Test can change case using rename"));
sl@0
  1674
	r=f1.Open(TheFs,name1,EFileRead|EFileWrite);
sl@0
  1675
	test(r==KErrNone);
sl@0
  1676
	r=f1.Rename(name3);
sl@0
  1677
	test(r==KErrNone);
sl@0
  1678
	CheckFileExists(name1,KErrNone,EFalse);
sl@0
  1679
	len=CheckFileExists(name3,KErrNone);
sl@0
  1680
	test(len==10);
sl@0
  1681
	f1.Close();
sl@0
  1682
	CheckFileExists(name1,KErrNone,EFalse);
sl@0
  1683
	len=CheckFileExists(name3,KErrNone);
sl@0
  1684
	test(len==10);
sl@0
  1685
sl@0
  1686
	test.Next(_L("Test can rename to an identical filename"));
sl@0
  1687
	r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
sl@0
  1688
	test(r==KErrNone);
sl@0
  1689
	r=f1.Rename(name3);
sl@0
  1690
	test(r==KErrNone);
sl@0
  1691
	len=CheckFileExists(name3,KErrNone);
sl@0
  1692
	test(len==10);
sl@0
  1693
	f1.Close();
sl@0
  1694
	len=CheckFileExists(name3,KErrNone);
sl@0
  1695
	test(len==10);
sl@0
  1696
sl@0
  1697
	test.Next(_L("Test rename to a name containing a wildcard is rejected"));
sl@0
  1698
	r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
sl@0
  1699
	test(r==KErrNone);
sl@0
  1700
	r=f1.Rename(_L("asdf*ASDF"));
sl@0
  1701
	test(r==KErrBadName);
sl@0
  1702
	r=f1.Rename(_L("asdf?AF"));
sl@0
  1703
	test(r==KErrBadName);
sl@0
  1704
	f1.Close();
sl@0
  1705
sl@0
  1706
	r=f1.Open(TheFs,name3,EFileRead);
sl@0
  1707
	test(r==KErrNone);
sl@0
  1708
	r=f1.Read(contents);
sl@0
  1709
	test(r==KErrNone);
sl@0
  1710
	test(contents==_L8("1234567890"));
sl@0
  1711
	r=f1.Read(contents);
sl@0
  1712
	test(r==KErrNone);
sl@0
  1713
	test(contents.Length()==0);
sl@0
  1714
	f1.Close();
sl@0
  1715
sl@0
  1716
	test.Next(_L("Check file date is retained"));
sl@0
  1717
	TDateTime dateTime(1995,(TMonth)10,19,23,0,0,0);
sl@0
  1718
	TTime oldTime(dateTime);
sl@0
  1719
	r=TheFs.SetEntry(name3,oldTime,0,0);
sl@0
  1720
	test(r==KErrNone);
sl@0
  1721
	r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
sl@0
  1722
	test(r==KErrNone);
sl@0
  1723
	TTime check;
sl@0
  1724
	r=f1.Modified(check);
sl@0
  1725
	test(r==KErrNone);
sl@0
  1726
	test(check==oldTime);
sl@0
  1727
sl@0
  1728
	r=f1.Rename(_L("OldFile.Old"));
sl@0
  1729
	test(r==KErrNone);
sl@0
  1730
sl@0
  1731
	r=f1.Modified(check);
sl@0
  1732
	test(r==KErrNone);
sl@0
  1733
	test(check==oldTime);
sl@0
  1734
	r=TheFs.Modified(_L("oldfile.old"),check);
sl@0
  1735
	test(r==KErrNone);
sl@0
  1736
	test(check==oldTime);
sl@0
  1737
	f1.Close();
sl@0
  1738
	r=TheFs.Modified(_L("oldfile.old"),check);
sl@0
  1739
	test(r==KErrNone);
sl@0
  1740
	test(check==oldTime);
sl@0
  1741
	}
sl@0
  1742
sl@0
  1743
static void TestFileUids()
sl@0
  1744
//
sl@0
  1745
// Test uids in files
sl@0
  1746
//
sl@0
  1747
	{
sl@0
  1748
sl@0
  1749
	test.Next(_L("Uids in files"));
sl@0
  1750
	TUidType uidData(TUid::Uid(1),TUid::Uid(1),TUid::Uid(1));
sl@0
  1751
	MakeFile(_L("Tmp04005.$$$"),uidData,_L8("Some other data"));
sl@0
  1752
	TUidType uidData1(TUid::Uid(2),TUid::Uid(2),TUid::Uid(2));
sl@0
  1753
	MakeFile(_L("Sketch(01)"),uidData1,_L8("A different sketch"));
sl@0
  1754
sl@0
  1755
	TEntry e;
sl@0
  1756
	TInt r=TheFs.Entry(_L("Tmp04005.$$$"),e);
sl@0
  1757
	test(r==KErrNone);
sl@0
  1758
	test(uidData==e.iType);
sl@0
  1759
	r=TheFs.Entry(_L("Sketch(01)"),e);
sl@0
  1760
	test(r==KErrNone);
sl@0
  1761
	test(uidData1==e.iType);
sl@0
  1762
sl@0
  1763
	test.Next(_L("Test replace preserves UIDs"));
sl@0
  1764
	r=TheFs.Replace(_L("Tmp04005.$$$"),_L("Sketch(01)"));
sl@0
  1765
	test(r==KErrNone);
sl@0
  1766
sl@0
  1767
	r=TheFs.Entry(_L("Tmp04005.$$$"),e);
sl@0
  1768
	test(r==KErrNotFound);
sl@0
  1769
	r=TheFs.Entry(_L("Sketch(01)"),e);
sl@0
  1770
	test(r==KErrNone);
sl@0
  1771
	test(uidData==e.iType);
sl@0
  1772
	}
sl@0
  1773
sl@0
  1774
sl@0
  1775
static void TestMaxLengthFilenames()
sl@0
  1776
//
sl@0
  1777
// Test max length filenames can be created/deleted
sl@0
  1778
//
sl@0
  1779
	{
sl@0
  1780
sl@0
  1781
#if defined(__WINS__)
sl@0
  1782
	if (gSessionPath[0]=='C')
sl@0
  1783
		return;
sl@0
  1784
#endif
sl@0
  1785
sl@0
  1786
	test.Next(_L("Test max length filenames"));
sl@0
  1787
	TFileName bigName;
sl@0
  1788
	CreateLongName(bigName,gSeed,255);
sl@0
  1789
	bigName[0]='\\';
sl@0
  1790
	RFile f;
sl@0
  1791
	TInt r=f.Create(TheFs,bigName,EFileRead);
sl@0
  1792
	test(r==KErrBadName);
sl@0
  1793
	bigName.SetLength(254);
sl@0
  1794
	r=f.Create(TheFs,bigName,EFileRead);
sl@0
  1795
	test(r==KErrNone);
sl@0
  1796
	f.Close();
sl@0
  1797
sl@0
  1798
	TInt count;
sl@0
  1799
	TFileName countedBigName=bigName;
sl@0
  1800
    // This loop may not reach the '\' character, or we will get a bad path.
sl@0
  1801
    for (count=0;count<('Z'-'A');count++)
sl@0
  1802
		{
sl@0
  1803
		countedBigName[2]=(TText)('A'+count);
sl@0
  1804
		r=f.Create(TheFs,countedBigName,EFileRead);
sl@0
  1805
		if (r==KErrDirFull)
sl@0
  1806
			{
sl@0
  1807
			r=TheFs.Delete(countedBigName);
sl@0
  1808
			test(r==KErrNotFound);
sl@0
  1809
			break;
sl@0
  1810
			}
sl@0
  1811
		if (r!=KErrNone)
sl@0
  1812
			test.Printf(_L("File create failed:%d"),r);
sl@0
  1813
		test(r==KErrNone);
sl@0
  1814
		f.Close();
sl@0
  1815
		}
sl@0
  1816
	while(count--)
sl@0
  1817
		{
sl@0
  1818
		countedBigName[2]=(TText)('A'+count);
sl@0
  1819
		r=TheFs.Delete(countedBigName);
sl@0
  1820
		test(r==KErrNone);
sl@0
  1821
		}
sl@0
  1822
sl@0
  1823
	r=TheFs.Delete(bigName);
sl@0
  1824
	test(r==KErrNone);
sl@0
  1825
sl@0
  1826
	TFileName subDirFileName=_L("\\F32-TST\\TFILE");
sl@0
  1827
	bigName.SetLength(241);
sl@0
  1828
	subDirFileName.Append(bigName);
sl@0
  1829
	r=f.Create(TheFs,subDirFileName,EFileRead);
sl@0
  1830
	test(r==KErrBadName);
sl@0
  1831
	subDirFileName.SetLength(254);
sl@0
  1832
	r=f.Create(TheFs,subDirFileName,EFileRead);
sl@0
  1833
	test(r==KErrNone);
sl@0
  1834
	f.Close();
sl@0
  1835
	r=TheFs.Delete(subDirFileName);
sl@0
  1836
	test(r==KErrNone);
sl@0
  1837
	}
sl@0
  1838
sl@0
  1839
sl@0
  1840
sl@0
  1841
sl@0
  1842
static void testReadersWriters()
sl@0
  1843
//
sl@0
  1844
// Test EFileShareReadersOrWriters file sharing.
sl@0
  1845
//
sl@0
  1846
	{
sl@0
  1847
sl@0
  1848
	test.Start(_L("Test EFileShareReadersOrWriters sharing"));
sl@0
  1849
	MakeFile(_L("TESTER"));
sl@0
  1850
sl@0
  1851
	// Open a file in EFileShareReadersOnly mode
sl@0
  1852
	RFile f1;
sl@0
  1853
	TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  1854
	test(r==KErrNone);
sl@0
  1855
sl@0
  1856
	// Opening a share in EFileShareReadersOnly mode should succeed
sl@0
  1857
	RFile f2;
sl@0
  1858
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  1859
	test(r==KErrNone);
sl@0
  1860
	f2.Close();
sl@0
  1861
sl@0
  1862
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
sl@0
  1863
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1864
	test(r==KErrNone);
sl@0
  1865
	f2.Close();
sl@0
  1866
sl@0
  1867
	// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
sl@0
  1868
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  1869
	test(r==KErrInUse);
sl@0
  1870
sl@0
  1871
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
sl@0
  1872
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
sl@0
  1873
	test(r==KErrInUse);
sl@0
  1874
sl@0
  1875
	// Opening a share in EShareAny mode should fail
sl@0
  1876
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  1877
	test(r==KErrInUse);
sl@0
  1878
sl@0
  1879
	f1.Close();
sl@0
  1880
sl@0
  1881
	//////////////////////
sl@0
  1882
sl@0
  1883
	// Open a file in EFileShareReadersOrWriters mode for reading
sl@0
  1884
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1885
	test(r==KErrNone);
sl@0
  1886
sl@0
  1887
	// Opening a share in EFileShareExclusive mode should fail
sl@0
  1888
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
  1889
	test(r==KErrInUse);
sl@0
  1890
sl@0
  1891
	// Opening a share in EFileShareReadersOnly mode should succeed
sl@0
  1892
	// (the share doesn't care if the file is opened for reading or writing)
sl@0
  1893
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  1894
	test(r==KErrNone);
sl@0
  1895
	f2.Close();
sl@0
  1896
sl@0
  1897
	// Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed
sl@0
  1898
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1899
	test(r==KErrNone);
sl@0
  1900
	f2.Close();
sl@0
  1901
sl@0
  1902
	// Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should succeed
sl@0
  1903
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  1904
	test(r==KErrNone);
sl@0
  1905
	f2.Close();
sl@0
  1906
sl@0
  1907
	// Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should succeed
sl@0
  1908
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
sl@0
  1909
	test(r==KErrNone);
sl@0
  1910
	f2.Close();
sl@0
  1911
sl@0
  1912
	// Opening a share in EFileShareAny mode should succeed
sl@0
  1913
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  1914
	test(r==KErrNone);
sl@0
  1915
	f2.Close();
sl@0
  1916
sl@0
  1917
	f1.Close();
sl@0
  1918
sl@0
  1919
	//////////////////////
sl@0
  1920
sl@0
  1921
	// Open a file in EFileShareReadersOrWriters mode for writing
sl@0
  1922
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  1923
	test(r==KErrNone);
sl@0
  1924
sl@0
  1925
	// Opening a share in EFileShareExclusive mode should fail
sl@0
  1926
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
  1927
	test(r==KErrInUse);
sl@0
  1928
sl@0
  1929
	// Opening a share in EFileShareReadersOnly mode should fail
sl@0
  1930
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  1931
	test(r==KErrInUse);
sl@0
  1932
sl@0
  1933
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
sl@0
  1934
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1935
	test(r==KErrNone);
sl@0
  1936
	f2.Close();
sl@0
  1937
sl@0
  1938
	// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
sl@0
  1939
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  1940
	test(r==KErrNone);
sl@0
  1941
	f2.Close();
sl@0
  1942
sl@0
  1943
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
sl@0
  1944
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
sl@0
  1945
	test(r==KErrNone);
sl@0
  1946
	f2.Close();
sl@0
  1947
sl@0
  1948
	// Opening a share in EFileShareAny mode should succeed
sl@0
  1949
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  1950
	test(r==KErrNone);
sl@0
  1951
	f2.Close();
sl@0
  1952
sl@0
  1953
	f1.Close();
sl@0
  1954
sl@0
  1955
	//////////////////////////
sl@0
  1956
sl@0
  1957
	// Open a file in EFileShareAny mode
sl@0
  1958
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  1959
	test(r==KErrNone);
sl@0
  1960
sl@0
  1961
	// Opening a share in EFileShareExclusive mode should fail
sl@0
  1962
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
sl@0
  1963
	test(r==KErrInUse);
sl@0
  1964
sl@0
  1965
	// Opening a share in EFileShareReadersOnly mode should fail
sl@0
  1966
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  1967
	test(r==KErrInUse);
sl@0
  1968
sl@0
  1969
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
sl@0
  1970
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1971
	test(r==KErrNone);
sl@0
  1972
	f2.Close();
sl@0
  1973
sl@0
  1974
	// Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
sl@0
  1975
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  1976
	test(r==KErrNone);
sl@0
  1977
	f2.Close();
sl@0
  1978
sl@0
  1979
	// Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
sl@0
  1980
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
sl@0
  1981
	test(r==KErrNone);
sl@0
  1982
	f2.Close();
sl@0
  1983
sl@0
  1984
	// Opening a share in EFileShareAny mode with should succeed
sl@0
  1985
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  1986
	test(r==KErrNone);
sl@0
  1987
	f2.Close();
sl@0
  1988
sl@0
  1989
	f1.Close();
sl@0
  1990
sl@0
  1991
	//////////////////////
sl@0
  1992
sl@0
  1993
	// Open a file in EFileShareReadersOrWriters mode for reading
sl@0
  1994
	r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  1995
	test(r==KErrNone);
sl@0
  1996
sl@0
  1997
	// Opening a share in EFileShareReadersOnly mode should succeed
sl@0
  1998
	//  - The share should now be promoted to EFileShareReadersOnly mode
sl@0
  1999
	r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
sl@0
  2000
	test(r==KErrNone);
sl@0
  2001
sl@0
  2002
	TInt pass = 2;
sl@0
  2003
	while(pass--)
sl@0
  2004
		{
sl@0
  2005
		RFile f3;
sl@0
  2006
		// Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed
sl@0
  2007
		r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
sl@0
  2008
		test(r==KErrNone);
sl@0
  2009
		f3.Close();
sl@0
  2010
sl@0
  2011
		// Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should fail
sl@0
  2012
		r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
sl@0
  2013
		if(pass == 1)
sl@0
  2014
			{
sl@0
  2015
			// The share is promoted - should obey EFileShareReadersOnly rules
sl@0
  2016
			test(r==KErrInUse);
sl@0
  2017
			}
sl@0
  2018
		else
sl@0
  2019
			{
sl@0
  2020
			// The share is demoted - should obey EFileShareReadersOrWriters rules
sl@0
  2021
			test(r==KErrNone);
sl@0
  2022
			f3.Close();
sl@0
  2023
			}
sl@0
  2024
sl@0
  2025
		// Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should fail
sl@0
  2026
		r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
sl@0
  2027
		if(pass == 1)
sl@0
  2028
			{
sl@0
  2029
			// The share is promoted - should obey EFileShareReadersOnly rules
sl@0
  2030
			test(r==KErrInUse);
sl@0
  2031
			}
sl@0
  2032
		else
sl@0
  2033
			{
sl@0
  2034
			// The share is demoted - should obey EFileShareReadersOrWriters rules
sl@0
  2035
			test(r==KErrNone);
sl@0
  2036
			f3.Close();
sl@0
  2037
			}
sl@0
  2038
sl@0
  2039
		// Opening a share in EFileShareAny mode should fails
sl@0
  2040
		r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
sl@0
  2041
		if(pass == 1)
sl@0
  2042
			{
sl@0
  2043
			// The share is promoted - should obey EFileShareReadersOnly rules
sl@0
  2044
			test(r==KErrInUse);
sl@0
  2045
			f2.Close();
sl@0
  2046
			}
sl@0
  2047
		else
sl@0
  2048
			{
sl@0
  2049
			// The share is demoted - should obey EFileShareReadersOrWriters rules
sl@0
  2050
			test(r==KErrNone);
sl@0
  2051
			f3.Close();
sl@0
  2052
			}
sl@0
  2053
		}
sl@0
  2054
sl@0
  2055
	f1.Close();
sl@0
  2056
sl@0
  2057
	test.End();
sl@0
  2058
	}
sl@0
  2059
sl@0
  2060
sl@0
  2061
static void testINC070455()
sl@0
  2062
//
sl@0
  2063
// INC070455 - RFile.ChangeMode() panics
sl@0
  2064
//
sl@0
  2065
	{
sl@0
  2066
	_LIT(KTestName, "Test INC070455 - RFile.ChangeMode() panics");
sl@0
  2067
	test.Start(KTestName);
sl@0
  2068
sl@0
  2069
sl@0
  2070
	// To reproduce this defect, we need a filename of less than 10 characters.
sl@0
  2071
	// We cannot use the directories used by the rest of this test harness.
sl@0
  2072
	_LIT(KShortName, "C:\\file.txt");
sl@0
  2073
sl@0
  2074
sl@0
  2075
	test.Next(_L("Create file..."));
sl@0
  2076
	RFile TheFile;
sl@0
  2077
	TInt r = TheFile.Create(TheFs, KShortName, EFileWrite);
sl@0
  2078
	test((KErrNone == r) || (KErrAlreadyExists == r));
sl@0
  2079
	TheFile.Close();
sl@0
  2080
sl@0
  2081
sl@0
  2082
	test.Next(_L("Re-open the file..."));
sl@0
  2083
	r = TheFile.Open(TheFs, KShortName, EFileRead | EFileShareExclusive);
sl@0
  2084
	test (KErrNone == r);
sl@0
  2085
sl@0
  2086
sl@0
  2087
	test.Next(_L("Change the file\'s mode..."));
sl@0
  2088
	r = TheFile.ChangeMode(EFileShareReadersOnly);
sl@0
  2089
	test (KErrNone == r);
sl@0
  2090
	TheFile.Close();
sl@0
  2091
sl@0
  2092
sl@0
  2093
	test.Next(_L("Tidy up"));
sl@0
  2094
	r = TheFs.Delete(KShortName);
sl@0
  2095
	test (KErrNone == r);
sl@0
  2096
sl@0
  2097
	test.End();
sl@0
  2098
	}
sl@0
  2099
sl@0
  2100
sl@0
  2101
LOCAL_D TBuf8<0x80000> gLongBuf;
sl@0
  2102
_LIT(KFileName, "\\zerolengthsourcedescriptortest.txt");
sl@0
  2103
sl@0
  2104
static void zeroSrcDesc()
sl@0
  2105
	{
sl@0
  2106
	gLongBuf.Zero();
sl@0
  2107
	}
sl@0
  2108
sl@0
  2109
static void setSrcDescLen()
sl@0
  2110
	{
sl@0
  2111
	gLongBuf.SetLength(0x80000);
sl@0
  2112
	}
sl@0
  2113
sl@0
  2114
static void createTestFile(RFile& aFile)
sl@0
  2115
	{
sl@0
  2116
	TInt r = aFile.Create(TheFs, KFileName, EFileWrite);
sl@0
  2117
	test((KErrNone == r) || (KErrAlreadyExists == r));
sl@0
  2118
	}
sl@0
  2119
sl@0
  2120
static void removeTestFile(RFile& aFile)
sl@0
  2121
	{
sl@0
  2122
	aFile.Close();
sl@0
  2123
	TInt r = TheFs.Delete(KFileName);
sl@0
  2124
	test (KErrNone == r);
sl@0
  2125
	}
sl@0
  2126
sl@0
  2127
#ifdef _DEBUG
sl@0
  2128
static TInt testWritePanic(TAny* aPtr)
sl@0
  2129
	{
sl@0
  2130
	RFile * ptr = (RFile *)aPtr;
sl@0
  2131
	TInt r=ptr->Write(gLongBuf,0x80000);
sl@0
  2132
	test (KErrNone == r);
sl@0
  2133
	return KErrNone;
sl@0
  2134
	}
sl@0
  2135
#endif
sl@0
  2136
static void testNegativeLengthToWrite()
sl@0
  2137
//
sl@0
  2138
// DEF091545 - Tests added to check the write function behaviour with Negative length
sl@0
  2139
{
sl@0
  2140
sl@0
  2141
test.Start(_L("Test RFile::Write variants with Negative Length parameter"));
sl@0
  2142
sl@0
  2143
	LOCAL_D TBuf8<0x100> gBuf;
sl@0
  2144
	RFile TheFile;
sl@0
  2145
	TInt r;
sl@0
  2146
	TRequestStatus status1(KRequestPending);
sl@0
  2147
	TRequestStatus status2(KRequestPending);
sl@0
  2148
sl@0
  2149
// EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength)
sl@0
  2150
	createTestFile(TheFile);
sl@0
  2151
sl@0
  2152
	r=TheFile.Write(gBuf, -1);
sl@0
  2153
	test(r==KErrArgument);
sl@0
  2154
sl@0
  2155
	removeTestFile(TheFile);
sl@0
  2156
sl@0
  2157
// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus)
sl@0
  2158
	createTestFile(TheFile);
sl@0
  2159
	TheFile.Write(gBuf,-1, status1);
sl@0
  2160
	User::WaitForRequest(status1);
sl@0
  2161
	test ( status1.Int() == KErrArgument);
sl@0
  2162
sl@0
  2163
	removeTestFile(TheFile);
sl@0
  2164
sl@0
  2165
sl@0
  2166
sl@0
  2167
// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength)
sl@0
  2168
	createTestFile(TheFile);
sl@0
  2169
	r = TheFile.Write(0,gBuf,-1);
sl@0
  2170
	test(r==KErrArgument);
sl@0
  2171
	removeTestFile(TheFile);
sl@0
  2172
sl@0
  2173
sl@0
  2174
// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus)
sl@0
  2175
	createTestFile(TheFile);
sl@0
  2176
	TheFile.Write(0, gBuf,-1, status2);
sl@0
  2177
	User::WaitForRequest(status2);
sl@0
  2178
	test ( status2.Int() == KErrArgument);
sl@0
  2179
	removeTestFile(TheFile);
sl@0
  2180
sl@0
  2181
	test.End();
sl@0
  2182
sl@0
  2183
sl@0
  2184
sl@0
  2185
}
sl@0
  2186
sl@0
  2187
static TInt testLockPanic(TAny* aPtr)
sl@0
  2188
	{
sl@0
  2189
	TInt aPos=128;
sl@0
  2190
	TInt aLen=-1;
sl@0
  2191
	RFile * ptr = (RFile *)aPtr;
sl@0
  2192
	TInt r=ptr->Lock(aPos, aLen);
sl@0
  2193
	test (KErrNone == r);
sl@0
  2194
	return KErrNone;
sl@0
  2195
	}
sl@0
  2196
sl@0
  2197
static TInt testUnLockPanic(TAny* aPtr)
sl@0
  2198
	{
sl@0
  2199
	TInt aPos=128;
sl@0
  2200
	TInt aLen=-1;
sl@0
  2201
	RFile * ptr = (RFile *)aPtr;
sl@0
  2202
	TInt r=ptr->UnLock(aPos, aLen);
sl@0
  2203
	test (KErrNone == r);
sl@0
  2204
	return KErrNone;
sl@0
  2205
	}
sl@0
  2206
sl@0
  2207
static TInt testSetSizePanic(TAny* aPtr)
sl@0
  2208
	{
sl@0
  2209
	TInt aSize=-1;
sl@0
  2210
	RFile * ptr = (RFile *)aPtr;
sl@0
  2211
	TInt r=ptr->SetSize(aSize);
sl@0
  2212
	test (KErrNone == r);
sl@0
  2213
	return KErrNone;
sl@0
  2214
	}
sl@0
  2215
sl@0
  2216
static void testNegativeLength()
sl@0
  2217
	{
sl@0
  2218
	test.Start(_L("Test RFile::Lock, RFile::Unlock and RFile::SetSize with Negative Length parameter"));
sl@0
  2219
sl@0
  2220
	test(TheFs.ShareProtected() == KErrNone);
sl@0
  2221
sl@0
  2222
	RFile TheFile;
sl@0
  2223
	createTestFile(TheFile);
sl@0
  2224
	TRequestStatus status = KRequestPending;
sl@0
  2225
sl@0
  2226
	// launch call on separate thread as expected to panic
sl@0
  2227
	// Test Lock with a negative length
sl@0
  2228
	User::SetJustInTime(EFalse);
sl@0
  2229
	RThread t;
sl@0
  2230
	test(t.Create(_L("testLockPanic"), testLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
sl@0
  2231
	t.Logon(status);
sl@0
  2232
	t.Resume();
sl@0
  2233
	User::WaitForRequest(status);
sl@0
  2234
	User::SetJustInTime(ETrue);
sl@0
  2235
	test(t.ExitType() == EExitPanic);
sl@0
  2236
	test(t.ExitReason() == 17);
sl@0
  2237
	t.Close();
sl@0
  2238
sl@0
  2239
sl@0
  2240
	// Test Unlock with a negative length
sl@0
  2241
	User::SetJustInTime(EFalse);
sl@0
  2242
	status = KRequestPending;
sl@0
  2243
	test(t.Create(_L("testUnLockPanic"), testUnLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
sl@0
  2244
	t.Logon(status);
sl@0
  2245
	t.Resume();
sl@0
  2246
	User::WaitForRequest(status);
sl@0
  2247
	test(t.ExitType() == EExitPanic);
sl@0
  2248
	test(t.ExitReason() == 18);
sl@0
  2249
	t.Close();
sl@0
  2250
	User::SetJustInTime(ETrue);
sl@0
  2251
sl@0
  2252
	// Test SetSize with a negative length
sl@0
  2253
	User::SetJustInTime(EFalse);
sl@0
  2254
	status = KRequestPending;
sl@0
  2255
	test(t.Create(_L("testSetSizePanic"), testSetSizePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
sl@0
  2256
	t.Logon(status);
sl@0
  2257
	t.Resume();
sl@0
  2258
	User::WaitForRequest(status);
sl@0
  2259
	test(t.ExitType() == EExitPanic);
sl@0
  2260
	test(t.ExitReason() == 20);
sl@0
  2261
	t.Close();
sl@0
  2262
	User::SetJustInTime(ETrue);
sl@0
  2263
sl@0
  2264
	removeTestFile(TheFile);
sl@0
  2265
	test.End();
sl@0
  2266
	}
sl@0
  2267
sl@0
  2268
static void testZeroLengthDescriptors()
sl@0
  2269
//
sl@0
  2270
// INC088416 - NAND thread crash when doing async writes to internal memory
sl@0
  2271
//
sl@0
  2272
// Test each variant of RFile::Write against zero length source descriptor arguements
sl@0
  2273
	{
sl@0
  2274
	test.Start(_L("Test RFile::Write variants with Zero Length Source Descriptor"));
sl@0
  2275
sl@0
  2276
	RFile TheFile;
sl@0
  2277
	TRequestStatus status(KRequestPending);
sl@0
  2278
sl@0
  2279
sl@0
  2280
//  EXPORT_C TInt RFile::Write(const TDesC8& aDes) PASS ZERO length descriptor
sl@0
  2281
sl@0
  2282
	createTestFile(TheFile);
sl@0
  2283
sl@0
  2284
	zeroSrcDesc();
sl@0
  2285
sl@0
  2286
	test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes) with zero length aDes"));
sl@0
  2287
	TInt r=TheFile.Write(gLongBuf);
sl@0
  2288
	test(r==KErrNone);
sl@0
  2289
sl@0
  2290
	test.Printf(_L("Test case passed\n"));
sl@0
  2291
sl@0
  2292
	removeTestFile(TheFile);
sl@0
  2293
sl@0
  2294
sl@0
  2295
	// EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor
sl@0
  2296
sl@0
  2297
	createTestFile(TheFile);
sl@0
  2298
sl@0
  2299
	status = KRequestPending;
sl@0
  2300
	zeroSrcDesc();
sl@0
  2301
sl@0
  2302
	test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) with zero length sDes"));
sl@0
  2303
	TheFile.Write(gLongBuf,status);
sl@0
  2304
	User::WaitForRequest(status);
sl@0
  2305
	test(status.Int()==KErrNone);
sl@0
  2306
sl@0
  2307
	test.Printf(_L("Test case passed\n"));
sl@0
  2308
sl@0
  2309
	removeTestFile(TheFile);
sl@0
  2310
sl@0
  2311
sl@0
  2312
	// EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
sl@0
  2313
sl@0
  2314
	createTestFile(TheFile);
sl@0
  2315
sl@0
  2316
	status = KRequestPending;
sl@0
  2317
	setSrcDescLen();
sl@0
  2318
sl@0
  2319
	test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus)"));
sl@0
  2320
	TheFile.Write(gLongBuf,status);
sl@0
  2321
	test.Printf(_L("Zero source descriptor during async write\n"));
sl@0
  2322
	zeroSrcDesc();
sl@0
  2323
	User::WaitForRequest(status);
sl@0
  2324
	test(status.Int()==KErrNone);
sl@0
  2325
sl@0
  2326
	test.Printf(_L("Test case passed\n"));
sl@0
  2327
sl@0
  2328
	removeTestFile(TheFile);
sl@0
  2329
sl@0
  2330
sl@0
  2331
	// EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor
sl@0
  2332
sl@0
  2333
	createTestFile(TheFile);
sl@0
  2334
sl@0
  2335
	status = KRequestPending;
sl@0
  2336
	zeroSrcDesc();
sl@0
  2337
sl@0
  2338
	test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes,TInt aLength) with zero length aDes"));
sl@0
  2339
#ifdef _DEBUG
sl@0
  2340
	// launch call on separate thread as expected to panic
sl@0
  2341
	User::SetJustInTime(EFalse);
sl@0
  2342
	status = KRequestPending;
sl@0
  2343
	RThread t;
sl@0
  2344
	test(t.Create(_L("testWritePanic"), testWritePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
sl@0
  2345
	t.Logon(status);
sl@0
  2346
	t.Resume();
sl@0
  2347
	User::WaitForRequest(status);
sl@0
  2348
	test(t.ExitType() == EExitPanic);
sl@0
  2349
	test(t.ExitReason() == 27);
sl@0
  2350
	t.Close();
sl@0
  2351
	User::SetJustInTime(ETrue);
sl@0
  2352
#else
sl@0
  2353
sl@0
  2354
	r=TheFile.Write(gLongBuf, 0x80000);
sl@0
  2355
	test(r==KErrNone);
sl@0
  2356
#endif
sl@0
  2357
sl@0
  2358
	test.Printf(_L("Test case passed\n"));
sl@0
  2359
sl@0
  2360
	removeTestFile(TheFile);
sl@0
  2361
sl@0
  2362
sl@0
  2363
	// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor
sl@0
  2364
sl@0
  2365
	createTestFile(TheFile);
sl@0
  2366
sl@0
  2367
	status = KRequestPending;
sl@0
  2368
	zeroSrcDesc();
sl@0
  2369
sl@0
  2370
	test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, TInt aLength,TRequestStatus& aStatus) with zero length sDes"));
sl@0
  2371
	TheFile.Write(gLongBuf, 0x80000, status); ;
sl@0
  2372
	User::WaitForRequest(status);
sl@0
  2373
	test(status.Int()==KErrNone);
sl@0
  2374
sl@0
  2375
	test.Printf(_L("Test case passed\n"));
sl@0
  2376
sl@0
  2377
	removeTestFile(TheFile);
sl@0
  2378
sl@0
  2379
sl@0
  2380
	// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
sl@0
  2381
sl@0
  2382
	createTestFile(TheFile);
sl@0
  2383
sl@0
  2384
	status = KRequestPending;
sl@0
  2385
	setSrcDescLen();
sl@0
  2386
sl@0
  2387
	test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, Int aLength,TRequestStatus& aStatus)"));
sl@0
  2388
	TheFile.Write(gLongBuf,0x80000, status);
sl@0
  2389
	test.Printf(_L("Zero source descriptor during async write\n"));
sl@0
  2390
	zeroSrcDesc();
sl@0
  2391
	User::WaitForRequest(status);
sl@0
  2392
	test(status.Int()==KErrNone);
sl@0
  2393
sl@0
  2394
	test.Printf(_L("Test case passed\n"));
sl@0
  2395
sl@0
  2396
	removeTestFile(TheFile);
sl@0
  2397
sl@0
  2398
sl@0
  2399
	// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes) PASS ZERO length descriptor
sl@0
  2400
sl@0
  2401
	createTestFile(TheFile);
sl@0
  2402
sl@0
  2403
	zeroSrcDesc();
sl@0
  2404
sl@0
  2405
	test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes) with zero length aDes"));
sl@0
  2406
	r=TheFile.Write(0, gLongBuf);
sl@0
  2407
	test(r==KErrNone);
sl@0
  2408
sl@0
  2409
	test.Printf(_L("Test case passed\n"));
sl@0
  2410
sl@0
  2411
	removeTestFile(TheFile);
sl@0
  2412
sl@0
  2413
sl@0
  2414
	// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor
sl@0
  2415
sl@0
  2416
	createTestFile(TheFile);
sl@0
  2417
sl@0
  2418
	status = KRequestPending;
sl@0
  2419
	zeroSrcDesc();
sl@0
  2420
sl@0
  2421
	test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus) with zero length sDes"));
sl@0
  2422
	TheFile.Write(0, gLongBuf, status);
sl@0
  2423
	User::WaitForRequest(status);
sl@0
  2424
	test(status.Int()==KErrNone);
sl@0
  2425
sl@0
  2426
	test.Printf(_L("Test case passed\n"));
sl@0
  2427
sl@0
  2428
	removeTestFile(TheFile);
sl@0
  2429
sl@0
  2430
sl@0
  2431
	// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
sl@0
  2432
sl@0
  2433
	createTestFile(TheFile);
sl@0
  2434
sl@0
  2435
	status = KRequestPending;
sl@0
  2436
	setSrcDescLen();
sl@0
  2437
sl@0
  2438
	test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus)"));
sl@0
  2439
	TheFile.Write(0, gLongBuf, status);
sl@0
  2440
	test.Printf(_L("Zero source descriptor during async write\n"));
sl@0
  2441
	zeroSrcDesc();
sl@0
  2442
	User::WaitForRequest(status);
sl@0
  2443
	test(status.Int()==KErrNone);
sl@0
  2444
sl@0
  2445
	test.Printf(_L("Test case passed\n"));
sl@0
  2446
sl@0
  2447
	removeTestFile(TheFile);
sl@0
  2448
sl@0
  2449
sl@0
  2450
	// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor
sl@0
  2451
sl@0
  2452
	createTestFile(TheFile);
sl@0
  2453
sl@0
  2454
	zeroSrcDesc();
sl@0
  2455
sl@0
  2456
	test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength) with zero length aDes"));
sl@0
  2457
	r=TheFile.Write(0, gLongBuf, 0x80000);
sl@0
  2458
	test(r==KErrNone);
sl@0
  2459
sl@0
  2460
	test.Printf(_L("Test case passed\n"));
sl@0
  2461
sl@0
  2462
	removeTestFile(TheFile);
sl@0
  2463
sl@0
  2464
sl@0
  2465
	// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor
sl@0
  2466
sl@0
  2467
	createTestFile(TheFile);
sl@0
  2468
sl@0
  2469
	status = KRequestPending;
sl@0
  2470
	zeroSrcDesc();
sl@0
  2471
sl@0
  2472
	test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) with zero length sDes"));
sl@0
  2473
	TheFile.Write(0, gLongBuf, 0x80000, status);
sl@0
  2474
	User::WaitForRequest(status);
sl@0
  2475
	test(status.Int()==KErrNone);
sl@0
  2476
sl@0
  2477
	test.Printf(_L("Test case passed\n"));
sl@0
  2478
sl@0
  2479
	removeTestFile(TheFile);
sl@0
  2480
sl@0
  2481
sl@0
  2482
	// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
sl@0
  2483
sl@0
  2484
	createTestFile(TheFile);
sl@0
  2485
sl@0
  2486
	status = KRequestPending;
sl@0
  2487
	setSrcDescLen();
sl@0
  2488
sl@0
  2489
	test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus"));
sl@0
  2490
	TheFile.Write(0, gLongBuf, 0x80000, status);
sl@0
  2491
	test.Printf(_L("Zero source descriptor during async write\n"));
sl@0
  2492
	zeroSrcDesc();
sl@0
  2493
	User::WaitForRequest(status);
sl@0
  2494
	test(status.Int()==KErrNone);
sl@0
  2495
sl@0
  2496
	test.Printf(_L("Test case passed\n"));
sl@0
  2497
sl@0
  2498
	removeTestFile(TheFile);
sl@0
  2499
sl@0
  2500
sl@0
  2501
	test.End();
sl@0
  2502
	}
sl@0
  2503
sl@0
  2504
static void testReadBufferOverflow()
sl@0
  2505
//
sl@0
  2506
// Test each variant of RFile::Read when the specified extent to read is
sl@0
  2507
// greater than the available buffer space
sl@0
  2508
//
sl@0
  2509
	{
sl@0
  2510
	test.Start(_L("Test RFile::Read for oversized requests"));
sl@0
  2511
sl@0
  2512
	RFile file;
sl@0
  2513
	TInt r = file.Create(TheFs, KFileName, EFileRead);
sl@0
  2514
	test((KErrNone == r) || (KErrAlreadyExists == r));
sl@0
  2515
sl@0
  2516
	TInt err = KErrNone;
sl@0
  2517
	TRequestStatus status(KRequestPending);
sl@0
  2518
	TBuf8<2> buf8;
sl@0
  2519
sl@0
  2520
// EXPORT_C TInt RFile::Read(TDes8& aDes,TInt aLength) const
sl@0
  2521
	err = file.Read(buf8,5);
sl@0
  2522
	test(err==KErrOverflow);
sl@0
  2523
	err = KErrNone;
sl@0
  2524
sl@0
  2525
// EXPORT_C void RFile::Read(TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const
sl@0
  2526
	file.Read(buf8,5,status);
sl@0
  2527
	test(status.Int()==KErrOverflow);
sl@0
  2528
	status = KRequestPending;
sl@0
  2529
sl@0
  2530
// EXPORT_C TInt RFile::Read(TInt aPos,TDes8& aDes,TInt aLength) const
sl@0
  2531
	err = file.Read(0,buf8,5);
sl@0
  2532
	test(err==KErrOverflow);
sl@0
  2533
sl@0
  2534
// EXPORT_C void RFile::Read(TInt aPos,TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const
sl@0
  2535
	file.Read(0,buf8,5,status);
sl@0
  2536
	test(status.Int()==KErrOverflow);
sl@0
  2537
sl@0
  2538
	removeTestFile(file);
sl@0
  2539
	test.End();
sl@0
  2540
	}
sl@0
  2541
sl@0
  2542
RSemaphore gSleepThread;
sl@0
  2543
TFileName gLastTempFileName;
sl@0
  2544
enum TTestDoCMode
sl@0
  2545
	{
sl@0
  2546
	EDoCPanic=1,
sl@0
  2547
	EDoCDeleteOnClose=2
sl@0
  2548
	};
sl@0
  2549
sl@0
  2550
static TInt DeleteOnCloseClientThread(TAny* aMode)
sl@0
  2551
	{
sl@0
  2552
	TTestDoCMode testMode = *(TTestDoCMode*)&aMode;
sl@0
  2553
	TUint fileMode=EFileRead;
sl@0
  2554
	RFs fs;
sl@0
  2555
	RFile file;
sl@0
  2556
sl@0
  2557
	TInt r=fs.Connect();
sl@0
  2558
	test(r==KErrNone);
sl@0
  2559
	r=fs.SetSessionPath(gSessionPath);
sl@0
  2560
	test(r==KErrNone);
sl@0
  2561
	if (testMode & EDoCDeleteOnClose)
sl@0
  2562
		fileMode|=EDeleteOnClose;
sl@0
  2563
	r=file.Temp(fs,_L(""),gLastTempFileName,fileMode);
sl@0
  2564
	test(r==KErrNone);
sl@0
  2565
	// Signal controlling thread and pause for panic where requested
sl@0
  2566
	// by caller.
sl@0
  2567
	if (testMode & EDoCPanic)
sl@0
  2568
		{
sl@0
  2569
		gSleepThread.Signal();
sl@0
  2570
		User::After(10000000);
sl@0
  2571
		}
sl@0
  2572
	file.Close();
sl@0
  2573
	if (!(testMode & EDoCPanic))
sl@0
  2574
		gSleepThread.Signal();
sl@0
  2575
	fs.Close();
sl@0
  2576
	return KErrNone;
sl@0
  2577
	}
sl@0
  2578
sl@0
  2579
static	void TestDeleteOnClose()
sl@0
  2580
//
sl@0
  2581
// Test RFile::Temp delete on close behaviour
sl@0
  2582
//
sl@0
  2583
	{
sl@0
  2584
	test.Start(_L("RFile::Temp default file close behaviour"));
sl@0
  2585
sl@0
  2586
	gSleepThread.CreateLocal(0);
sl@0
  2587
	RThread clientThread;
sl@0
  2588
	RFile file;
sl@0
  2589
	RFile file2;
sl@0
  2590
	TFileName filename =_L("DoCFile.tst");
sl@0
  2591
	TInt r;
sl@0
  2592
sl@0
  2593
//
sl@0
  2594
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2595
//! @SYMTestCaseID	PBASE-t_file-0804
sl@0
  2596
//! @SYMTestType	UT
sl@0
  2597
//! @SYMTestCaseDesc	Verifying the original behaviour of RFile::Temp()
sl@0
  2598
//! @SYMPREQ		CR1266
sl@0
  2599
//! @SYMTestPriority	High
sl@0
  2600
//! @SYMTestActions
sl@0
  2601
//! 	1.	Test thread creates a file with DeleteOnClose flag unset and
sl@0
  2602
//!		exits normally.
sl@0
  2603
//!		The main test body attempts to delete the resulting temporary
sl@0
  2604
//!		file.
sl@0
  2605
//!
sl@0
  2606
//! @SYMTestExpectedResults
sl@0
  2607
//! 	1.	The temporary file is successfully created and deleted.
sl@0
  2608
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2609
	r=clientThread.Create(_L("DeleteOnCloseClientThread 1"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)0);
sl@0
  2610
	test(r==KErrNone);
sl@0
  2611
	clientThread.Resume();
sl@0
  2612
	gSleepThread.Wait();
sl@0
  2613
	r=TheFs.Delete(gLastTempFileName);
sl@0
  2614
	test(r==KErrNone);
sl@0
  2615
	clientThread.Close();
sl@0
  2616
sl@0
  2617
//
sl@0
  2618
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2619
//! @SYMTestCaseID	PBASE-t_file-0805
sl@0
  2620
//! @SYMTestType	UT
sl@0
  2621
//! @SYMTestCaseDesc	Verifying the Delete on Close behaviour of RFile::Temp()
sl@0
  2622
//! @SYMPREQ		CR1266
sl@0
  2623
//! @SYMTestPriority	High
sl@0
  2624
//! @SYMTestActions
sl@0
  2625
//! 	1.	Test thread creates a file with DeleteOnClose flag set and
sl@0
  2626
//!		exits normally.
sl@0
  2627
//!		The main test body attempts to delete the resulting temporary
sl@0
  2628
//!		file.
sl@0
  2629
//!
sl@0
  2630
//! @SYMTestExpectedResults
sl@0
  2631
//! 	1.	The temporary file is successfully created and automatically
sl@0
  2632
//!		deleted upon close.   The subsequent attempted file deletion
sl@0
  2633
//!		by the main test body should fail with KErrNotFound.
sl@0
  2634
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2635
	test.Next(_L("RFile::Temp EDeleteOnClose behaviour"));
sl@0
  2636
	r=clientThread.Create(_L("DeleteOnCloseClientThread 2"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCDeleteOnClose);
sl@0
  2637
	test(r==KErrNone);
sl@0
  2638
	clientThread.Resume();
sl@0
  2639
	gSleepThread.Wait();
sl@0
  2640
	r=TheFs.Delete(gLastTempFileName);
sl@0
  2641
	test(r==KErrNotFound);
sl@0
  2642
	clientThread.Close();
sl@0
  2643
sl@0
  2644
//
sl@0
  2645
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2646
//! @SYMTestCaseID	PBASE-t_file-0806
sl@0
  2647
//! @SYMTestType	UT
sl@0
  2648
//! @SYMTestCaseDesc	Verifying the original, panic behaviour of RFile::Temp()
sl@0
  2649
//! @SYMPREQ		CR1266
sl@0
  2650
//! @SYMTestPriority	High
sl@0
  2651
//! @SYMTestActions
sl@0
  2652
//! 	1.	Test thread creates a file with DeleteOnClose flag unset and
sl@0
  2653
//!		is paniced by the main test body.
sl@0
  2654
//!		The main test body attempts to delete the resulting temporary
sl@0
  2655
//!		file.
sl@0
  2656
//!
sl@0
  2657
//! @SYMTestExpectedResults
sl@0
  2658
//! 	1.	The temporary file is successfully created and deleted.
sl@0
  2659
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2660
	test.Next(_L("RFile::Temp default panic behaviour"));
sl@0
  2661
	r=clientThread.Create(_L("DeleteOnCloseClientThread 3"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCPanic);
sl@0
  2662
	test(r==KErrNone);
sl@0
  2663
	clientThread.Resume();
sl@0
  2664
	gSleepThread.Wait();
sl@0
  2665
	User::SetJustInTime(EFalse);
sl@0
  2666
	clientThread.Panic(_L("Panic temp file thread #3"),KErrGeneral);
sl@0
  2667
	User::SetJustInTime(ETrue);
sl@0
  2668
	CLOSE_AND_WAIT(clientThread);
sl@0
  2669
	FsBarrier();
sl@0
  2670
	r=TheFs.Delete(gLastTempFileName);
sl@0
  2671
	test(r==KErrNone);
sl@0
  2672
sl@0
  2673
//
sl@0
  2674
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2675
//! @SYMTestCaseID	PBASE-t_file-0807
sl@0
  2676
//! @SYMTestType	UT
sl@0
  2677
//! @SYMTestCaseDesc	Verifying the Delete on Close, panic behaviour of RFile::Temp()
sl@0
  2678
//! @SYMPREQ		CR1266
sl@0
  2679
//! @SYMTestPriority	High
sl@0
  2680
//! @SYMTestActions
sl@0
  2681
//! 	1.	Test thread creates a file with DeleteOnClose flag set and
sl@0
  2682
//!		is paniced by the main test body.
sl@0
  2683
//!		The main test body attempts to delete the resulting temporary
sl@0
  2684
//!		file.
sl@0
  2685
//!
sl@0
  2686
//! @SYMTestExpectedResults
sl@0
  2687
//! 	1.	The temporary file is successfully created and automatically
sl@0
  2688
//!		deleted upon close.   The subsequent attempted file deletion
sl@0
  2689
//!		by the main test body should fail with KErrNotFound.
sl@0
  2690
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2691
	test.Next(_L("RFile::Temp EDeleteOnClose panic behaviour"));
sl@0
  2692
	r=clientThread.Create(_L("DeleteOnCloseClientThread 4"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)(EDoCPanic|EDoCDeleteOnClose));
sl@0
  2693
	test(r==KErrNone);
sl@0
  2694
	clientThread.Resume();
sl@0
  2695
	gSleepThread.Wait();
sl@0
  2696
	User::SetJustInTime(EFalse);
sl@0
  2697
	clientThread.Panic(_L("Panic temp file thread #4"),KErrGeneral);
sl@0
  2698
	User::SetJustInTime(ETrue);
sl@0
  2699
	CLOSE_AND_WAIT(clientThread);
sl@0
  2700
	FsBarrier();
sl@0
  2701
	r=TheFs.Delete(gLastTempFileName);
sl@0
  2702
	test(r==KErrNotFound);
sl@0
  2703
sl@0
  2704
//
sl@0
  2705
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2706
//! @SYMTestCaseID	PBASE-t_file-0808
sl@0
  2707
//! @SYMTestType	UT
sl@0
  2708
//! @SYMTestCaseDesc	Verifying RFile::Create() supports Delete On Close.
sl@0
  2709
//! @SYMPREQ		CR1266
sl@0
  2710
//! @SYMTestPriority	High
sl@0
  2711
//! @SYMTestActions
sl@0
  2712
//! 	1.	Test creates a file with DeleteOnClose flag set and
sl@0
  2713
//!		then closes the file.
sl@0
  2714
//!	2.	Test attempts to delete the file.
sl@0
  2715
//!
sl@0
  2716
//! @SYMTestExpectedResults
sl@0
  2717
//! 	1.	The file creation should succeed.
sl@0
  2718
//!	2.	The file deletion should fail with KErrNotFound.
sl@0
  2719
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2720
	test.Next(_L("RFile::Create EDeleteOnClose behaviour"));
sl@0
  2721
 	r=file.Create(TheFs,_L("DoC5"),EFileRead|EFileWrite|EDeleteOnClose);
sl@0
  2722
	test(r==KErrNone);
sl@0
  2723
	file.Close();
sl@0
  2724
	r=TheFs.Delete(filename);
sl@0
  2725
	test(r==KErrNotFound);
sl@0
  2726
sl@0
  2727
//
sl@0
  2728
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2729
//! @SYMTestCaseID	PBASE-t_file-0809
sl@0
  2730
//! @SYMTestType	UT
sl@0
  2731
//! @SYMTestCaseDesc	Verifying Delete On Close with multiple subsessions.
sl@0
  2732
//! @SYMPREQ		CR1266
sl@0
  2733
//! @SYMTestPriority	High
sl@0
  2734
//! @SYMTestActions
sl@0
  2735
//! 	1.	Test creates a file with DeleteOnClose and FileShareAny flags
sl@0
  2736
//!		set, opens the file a second time with the FileShareAny flag set
sl@0
  2737
//!		and then closes the first file handle.
sl@0
  2738
//!	2.	Test attempts to delete the file.
sl@0
  2739
//!	3.	The second file handle is closed and the test attempts to delete
sl@0
  2740
//!		the file.
sl@0
  2741
//!
sl@0
  2742
//! @SYMTestExpectedResults
sl@0
  2743
//! 	1.	The file create and file open should succeed.
sl@0
  2744
//!	2.	The file deletion should fail with KErrInUse.
sl@0
  2745
//!	3.	The file deletion should fail with KErrNotFound.
sl@0
  2746
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2747
	test.Next(_L("DoC 6 - Multiple subsessions"));
sl@0
  2748
 	r=file.Create(TheFs,filename,EFileShareAny|EFileRead|EFileWrite|EDeleteOnClose);
sl@0
  2749
	test(r==KErrNone);
sl@0
  2750
 	r=file2.Open(TheFs,filename,EFileShareAny|EFileRead|EFileWrite);
sl@0
  2751
	test(r==KErrNone);
sl@0
  2752
	file.Close();
sl@0
  2753
	test(r==KErrNone);
sl@0
  2754
	r=TheFs.Delete(filename);
sl@0
  2755
	test(r==KErrInUse);
sl@0
  2756
	file2.Close();
sl@0
  2757
	r=TheFs.Delete(filename);
sl@0
  2758
	test(r==KErrNotFound);
sl@0
  2759
sl@0
  2760
//
sl@0
  2761
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2762
//! @SYMTestCaseID	PBASE-t_file-0810
sl@0
  2763
//! @SYMTestType	UT
sl@0
  2764
//! @SYMTestCaseDesc	Verifying Delete On Close with preexisting file.
sl@0
  2765
//! @SYMPREQ		CR1266
sl@0
  2766
//! @SYMTestPriority	High
sl@0
  2767
//! @SYMTestActions
sl@0
  2768
//! 	1.	Test creates and closes a file, then attempts to create the same
sl@0
  2769
//!		file with Delete on Close set.
sl@0
  2770
//!
sl@0
  2771
//! @SYMTestExpectedResults
sl@0
  2772
//!	1.	The second create should fail with KErrAlreadyExists.
sl@0
  2773
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2774
	test.Next(_L("RFile::Create existing file behaviour"));
sl@0
  2775
 	r=file.Create(TheFs,filename,EFileRead|EFileWrite);
sl@0
  2776
	test(r==KErrNone);
sl@0
  2777
	file.Close();
sl@0
  2778
 	r=file.Create(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose);
sl@0
  2779
	test(r==KErrAlreadyExists);
sl@0
  2780
sl@0
  2781
//
sl@0
  2782
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2783
//! @SYMTestCaseID	PBASE-t_file-0811
sl@0
  2784
//! @SYMTestType	UT
sl@0
  2785
//! @SYMTestCaseDesc	Verifying existing file cannot be opened with delete on close set.
sl@0
  2786
//! @SYMPREQ		CR1266
sl@0
  2787
//! @SYMTestPriority	High
sl@0
  2788
//! @SYMTestActions
sl@0
  2789
//!	1.	Test attempts to open an existing file with delete on close set.
sl@0
  2790
//!
sl@0
  2791
//! @SYMTestExpectedResults
sl@0
  2792
//!	1.	The open should fail with KErrArgument.
sl@0
  2793
//---------------------------------------------------------------------------------------------------------------------
sl@0
  2794
	test.Next(_L("RFile::Open EDeleteOnClose flag validation"));
sl@0
  2795
	r=file.Open(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose);
sl@0
  2796
	test(r==KErrArgument);
sl@0
  2797
	r=TheFs.Delete(filename);
sl@0
  2798
	test(r==KErrNone);
sl@0
  2799
sl@0
  2800
	gSleepThread.Close();
sl@0
  2801
	test.End();
sl@0
  2802
	}
sl@0
  2803
sl@0
  2804
//--------------------------------------------------------------
sl@0
  2805
/**
sl@0
  2806
    Test that flushing dirty file cache does not affect file attributes and time.
sl@0
  2807
    This test shall pass disregarding if there is file cache or not.
sl@0
  2808
sl@0
  2809
*/
sl@0
  2810
void TestFileAttributesAndCacheFlushing()
sl@0
  2811
{
sl@0
  2812
    test.Next(_L("Test that file cache flushing does not affect the file attributes."));
sl@0
  2813
    if(Is_Win32(TheFs, gDriveNum))
sl@0
  2814
    {
sl@0
  2815
        test.Printf(_L("This test doesn't work on Win32 FS, skipping!\n"));
sl@0
  2816
        return;
sl@0
  2817
    }
sl@0
  2818
sl@0
  2819
    _LIT(KFile, "\\file1");
sl@0
  2820
sl@0
  2821
    TInt    nRes;
sl@0
  2822
    TEntry  entry;
sl@0
  2823
    TheFs.Delete(KFile);
sl@0
  2824
sl@0
  2825
    //-- 1. create test file
sl@0
  2826
    nRes = CreateEmptyFile(TheFs, KFile, 33);
sl@0
  2827
    test(nRes == KErrNone);
sl@0
  2828
sl@0
  2829
    //-- 2. open it for write
sl@0
  2830
    RFile file;
sl@0
  2831
    nRes = file.Open(TheFs, KFile, EFileWrite);
sl@0
  2832
    test(nRes == KErrNone);
sl@0
  2833
sl@0
  2834
    //-- 3. write a couple of bytes there. This must cause 'Archive' attribute set
sl@0
  2835
    nRes = file.Write(0, _L8("a"));
sl@0
  2836
    test(nRes == KErrNone);
sl@0
  2837
    nRes = file.Write(10, _L8("b"));
sl@0
  2838
    test(nRes == KErrNone);
sl@0
  2839
sl@0
  2840
    nRes = TheFs.Entry(KFile, entry);
sl@0
  2841
    test(nRes == KErrNone);
sl@0
  2842
sl@0
  2843
    test(entry.IsArchive());  //-- 'A' attribute must be set.
sl@0
  2844
sl@0
  2845
    //-- the file cache (if present) is dirty now. Dirty data timer starts to tick.
sl@0
  2846
    //-- 4. set new file attributes (w/o 'A') and creation time
sl@0
  2847
    const TUint newAtt = KEntryAttSystem ;
sl@0
  2848
    nRes = file.SetAtt(newAtt, ~newAtt & KEntryAttMaskSupported);
sl@0
  2849
    test(nRes == KErrNone);
sl@0
  2850
sl@0
  2851
    TTime newTime;
sl@0
  2852
    nRes = newTime.Set(_L("19970310:101809.000000"));
sl@0
  2853
    test(nRes == KErrNone);
sl@0
  2854
    nRes = file.SetModified(newTime);
sl@0
  2855
    test(nRes == KErrNone);
sl@0
  2856
sl@0
  2857
    //-- 5. wait 5 seconds. file server shall flush dirty data during this period.
sl@0
  2858
    User::After(5*K1Sec);
sl@0
  2859
sl@0
  2860
    //-- 6. check that attributes haven't chanded because of flush
sl@0
  2861
    nRes = file.Flush(); //-- this will flush attributes to the media
sl@0
  2862
    test(nRes == KErrNone);
sl@0
  2863
sl@0
  2864
    nRes = TheFs.Entry(KFile, entry);
sl@0
  2865
    test(nRes == KErrNone);
sl@0
  2866
sl@0
  2867
    test(entry.iAtt == newAtt);
sl@0
  2868
    test(entry.iModified.DateTime().Year() == 1997);
sl@0
  2869
    test(entry.iModified.DateTime().Month() == 3);
sl@0
  2870
    test(entry.iModified.DateTime().Day() == 10);
sl@0
  2871
sl@0
  2872
    //-- 7. write some data and ensure that 'A' attribute is set now and 'modified' time updated
sl@0
  2873
    nRes = file.Write(12, _L8("c"));
sl@0
  2874
    test(nRes == KErrNone);
sl@0
  2875
sl@0
  2876
    file.Close(); //-- this will flush attributes to the media
sl@0
  2877
sl@0
  2878
    nRes = TheFs.Entry(KFile, entry);
sl@0
  2879
    test(nRes == KErrNone);
sl@0
  2880
    test(entry.iAtt == (newAtt | KEntryAttArchive));
sl@0
  2881
    test(entry.iModified.DateTime().Year() != 1997);
sl@0
  2882
sl@0
  2883
sl@0
  2884
sl@0
  2885
}
sl@0
  2886
sl@0
  2887
/**
sl@0
  2888
    Testing access to the very last bytes in the maximal (for FAT32) file size.
sl@0
  2889
    This test must pass regardless of write caching configuration.
sl@0
  2890
*/
sl@0
  2891
void TestMaxFileSize()
sl@0
  2892
{
sl@0
  2893
    test.Next(_L("test maximal file size on FAT32\n"));
sl@0
  2894
sl@0
  2895
#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
  2896
sl@0
  2897
    if(!Is_Fat32(TheFs, gDriveNum))
sl@0
  2898
    {
sl@0
  2899
        test.Printf(_L("This test requires FAT32! skipping.\n"));
sl@0
  2900
        return;
sl@0
  2901
    }
sl@0
  2902
sl@0
  2903
    TInt nRes;
sl@0
  2904
sl@0
  2905
    //-- check disk space, it shall be > 4G
sl@0
  2906
    TVolumeInfo volInfo;
sl@0
  2907
    nRes = TheFs.Volume(volInfo, gDriveNum);
sl@0
  2908
    test(nRes == KErrNone);
sl@0
  2909
sl@0
  2910
    const TUint32 KMaxFAT32FileSize = 0xFFFFFFFF; // 4GB-1
sl@0
  2911
sl@0
  2912
    if(volInfo.iFree <= KMaxFAT32FileSize)
sl@0
  2913
    {
sl@0
  2914
        test.Printf(_L("Not enough space for 4GB file! skipping.\n"));
sl@0
  2915
        return;
sl@0
  2916
    }
sl@0
  2917
sl@0
  2918
    _LIT(KFileName, "\\huge_file");
sl@0
  2919
    TBuf8<10> buf(10);
sl@0
  2920
    RFile64 file64;
sl@0
  2921
sl@0
  2922
    //-- 1. create 4GB-1 file
sl@0
  2923
    //-- this file has enabled write caching by default
sl@0
  2924
    test.Printf(_L("creating maximal length file, size = 0x%x\n"),KMaxFAT32FileSize);
sl@0
  2925
    nRes = file64.Replace(TheFs, KFileName, EFileWrite);
sl@0
  2926
    test(nRes == KErrNone);
sl@0
  2927
sl@0
  2928
    const TInt64 fileSize = KMaxFAT32FileSize;
sl@0
  2929
sl@0
  2930
    nRes = file64.SetSize(fileSize);
sl@0
  2931
    test(nRes == KErrNone);
sl@0
  2932
sl@0
  2933
    test.Printf(_L("seeking to the file end...\n"));
sl@0
  2934
    TInt64 filePos = 0;
sl@0
  2935
    nRes = file64.Seek(ESeekEnd, filePos);
sl@0
  2936
    test(nRes == KErrNone);
sl@0
  2937
sl@0
  2938
sl@0
  2939
    test.Printf(_L("test writing to the last bytes of the file (rel pos addressing) \n"));
sl@0
  2940
sl@0
  2941
    //-- 1. writing using relative position
sl@0
  2942
    filePos = -1;
sl@0
  2943
    nRes = file64.Seek(ESeekEnd, filePos);
sl@0
  2944
    test(nRes == KErrNone);
sl@0
  2945
    test(filePos == fileSize-1);
sl@0
  2946
sl@0
  2947
    nRes = file64.Write(_L8("z")); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
sl@0
  2948
    test(nRes == KErrNone);
sl@0
  2949
sl@0
  2950
    nRes = file64.Write(_L8("x")); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
sl@0
  2951
    test(nRes == KErrNotSupported);
sl@0
  2952
sl@0
  2953
    nRes = file64.Flush();
sl@0
  2954
    test(nRes == KErrNone);
sl@0
  2955
sl@0
  2956
    //-- 1.1 check the result by reading data using rel. pos
sl@0
  2957
    filePos = -1;
sl@0
  2958
    nRes = file64.Seek(ESeekEnd, filePos);
sl@0
  2959
    test(nRes == KErrNone);
sl@0
  2960
    test(filePos == fileSize-1);
sl@0
  2961
sl@0
  2962
    test.Printf(_L("reading 1 byte at pos: 0x%x\n"), filePos);
sl@0
  2963
    nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
sl@0
  2964
    test(nRes == KErrNone);
sl@0
  2965
    test(buf.Length() == 1 && buf[0]=='z');
sl@0
  2966
sl@0
  2967
    nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
sl@0
  2968
    test(nRes == KErrNone);
sl@0
  2969
    test(buf.Length() == 0);
sl@0
  2970
sl@0
  2971
    file64.Close();
sl@0
  2972
sl@0
  2973
    test.Printf(_L("test writing to the last bytes of the file (absolute pos addressing) \n"));
sl@0
  2974
    //-- 2. writing using absolute position
sl@0
  2975
    nRes = file64.Open(TheFs, KFileName, EFileWrite);
sl@0
  2976
    test(nRes == KErrNone);
sl@0
  2977
sl@0
  2978
    filePos = fileSize-1;
sl@0
  2979
sl@0
  2980
    nRes = file64.Write(filePos-2, _L8("0"), 1); //-- write 1 byte a pos 0xFFFFFFFC
sl@0
  2981
    test(nRes == KErrNone);
sl@0
  2982
sl@0
  2983
    nRes = file64.Write(filePos, _L8("a"), 1);   //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
sl@0
  2984
    test(nRes == KErrNone);
sl@0
  2985
sl@0
  2986
    nRes = file64.Write(filePos+1, _L8("b"), 1); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
sl@0
  2987
    test(nRes == KErrNotSupported);
sl@0
  2988
sl@0
  2989
    nRes = file64.Flush();
sl@0
  2990
    test(nRes == KErrNone);
sl@0
  2991
sl@0
  2992
    //-- 1.1 check the result by reading data absolute rel. position
sl@0
  2993
sl@0
  2994
    nRes = file64.Read(filePos-2, buf, 1); //-- read 1 byte a pos 0xFFFFFFFD
sl@0
  2995
    test(nRes == KErrNone);
sl@0
  2996
    test(buf.Length() == 1 && buf[0]=='0');
sl@0
  2997
sl@0
  2998
    nRes = file64.Read(filePos, buf, 1);   //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
sl@0
  2999
    test(nRes == KErrNone);
sl@0
  3000
    test(buf.Length() == 1 && buf[0]=='a');
sl@0
  3001
sl@0
  3002
    nRes = file64.Read(filePos+1, buf, 1);  //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size
sl@0
  3003
    test(nRes == KErrNone);
sl@0
  3004
    test(buf.Length() == 0);
sl@0
  3005
sl@0
  3006
    nRes = file64.Read(filePos+2, buf, 1); //buf.Len must be 0
sl@0
  3007
    test(nRes == KErrNone);
sl@0
  3008
    test(buf.Length() == 0);
sl@0
  3009
sl@0
  3010
    file64.Close();
sl@0
  3011
sl@0
  3012
    test.Printf(_L("deleting the huge file.\n"));
sl@0
  3013
    nRes = TheFs.Delete(KFileName);
sl@0
  3014
    test(nRes == KErrNone);
sl@0
  3015
sl@0
  3016
#else
sl@0
  3017
sl@0
  3018
    test.Printf(_L("RFile64 is not supported! Skipping.\n"));
sl@0
  3019
sl@0
  3020
#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
sl@0
  3021
sl@0
  3022
}
sl@0
  3023
sl@0
  3024
sl@0
  3025
//--------------------------------------------------------------
sl@0
  3026
sl@0
  3027
void CallTestsL()
sl@0
  3028
	{
sl@0
  3029
sl@0
  3030
    //-- set up console output
sl@0
  3031
    F32_Test_Utils::SetConsole(test.Console());
sl@0
  3032
sl@0
  3033
    TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
sl@0
  3034
    test(nRes==KErrNone);
sl@0
  3035
    
sl@0
  3036
    PrintDrvInfo(TheFs, gDriveNum);
sl@0
  3037
sl@0
  3038
    //-- FAT Supports short file names
sl@0
  3039
    if(Is_Fat(TheFs, gDriveNum))
sl@0
  3040
        gShortFileNamesSupported = ETrue;
sl@0
  3041
    
sl@0
  3042
    if(Is_Win32(TheFs, gDriveNum)) 
sl@0
  3043
    {//-- find out if this is NTFS and if it supports short names (this feature can be switched OFF)
sl@0
  3044
        
sl@0
  3045
        _LIT(KLongFN, "\\this is a long file name");
sl@0
  3046
        nRes = CreateEmptyFile(TheFs, KLongFN, 10);   
sl@0
  3047
        test(nRes==KErrNone);
sl@0
  3048
sl@0
  3049
	    TBuf<12> shortName;
sl@0
  3050
	    nRes = TheFs.GetShortName(KLongFN, shortName);
sl@0
  3051
	    gShortFileNamesSupported = (nRes == KErrNone);
sl@0
  3052
        
sl@0
  3053
        nRes = TheFs.Delete(KLongFN);
sl@0
  3054
        test(nRes==KErrNone);
sl@0
  3055
sl@0
  3056
        DeleteTestDirectory();
sl@0
  3057
    }
sl@0
  3058
    else
sl@0
  3059
    {
sl@0
  3060
        nRes = FormatDrive(TheFs, gDriveNum, ETrue);
sl@0
  3061
        test(nRes==KErrNone);
sl@0
  3062
    }
sl@0
  3063
sl@0
  3064
	CreateTestDirectory(_L("\\F32-TST\\TFILE\\"));
sl@0
  3065
sl@0
  3066
	testFileRename();
sl@0
  3067
	testSetSize();
sl@0
  3068
	CopyFileToTestDirectory();
sl@0
  3069
	testFileSeek();
sl@0
  3070
	testMoreFileSeek();
sl@0
  3071
	CopyFileToTestDirectory();
sl@0
  3072
	testFileText();
sl@0
  3073
	testFileTextEndRecord();
sl@0
  3074
	testDeleteOpenFiles();
sl@0
  3075
	testFileAttributes();
sl@0
  3076
	testFileNames();
sl@0
  3077
	testShare();
sl@0
  3078
	testReadersWriters();
sl@0
  3079
	testReadFile();
sl@0
  3080
	testMultipleReadFile();
sl@0
  3081
	testWriteFile();
sl@0
  3082
	testChangeMode();
sl@0
  3083
	testShortNameAccessorFunctions();
sl@0
  3084
	testIsFileOpen();
sl@0
  3085
	testMiscellaneousReportedBugs();
sl@0
  3086
	testIsRomAddress();
sl@0
  3087
	TestFileUids();
sl@0
  3088
	TestMaxLengthFilenames();
sl@0
  3089
	testINC070455();
sl@0
  3090
	TestINC112803();
sl@0
  3091
	testZeroLengthDescriptors();
sl@0
  3092
	testNegativeLengthToWrite();
sl@0
  3093
	testNegativeLength();
sl@0
  3094
	testReadBufferOverflow();
sl@0
  3095
	TestDeleteOnClose();
sl@0
  3096
    TestFileAttributesAndCacheFlushing();
sl@0
  3097
    TestMaxFileSize();
sl@0
  3098
sl@0
  3099
	DeleteTestDirectory();
sl@0
  3100
	}
sl@0
  3101