1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_file.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,3101 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#define __E32TEST_EXTENSION__
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include <e32svr.h>
1.24 +#include "t_server.h"
1.25 +#include "t_chlffs.h"
1.26 +#include "fs_utils.h"
1.27 +
1.28 +#include "f32_test_utils.h"
1.29 +
1.30 +using namespace F32_Test_Utils;
1.31 +
1.32 +RTest test(_L("T_FILE"));
1.33 +
1.34 +TBool gShortFileNamesSupported = EFalse;
1.35 +
1.36 +static TBuf8<1500> gBuf;
1.37 +
1.38 +TInt gDriveNum = -1;
1.39 +
1.40 +static void testShare()
1.41 +//
1.42 +// Test file sharing.
1.43 +//
1.44 + {
1.45 +
1.46 + test.Start(_L("Test exclusive sharing"));
1.47 + MakeFile(_L("TESTER"));
1.48 +
1.49 +/*
1.50 + Extra code to answer a question about a potential WINS bug. WINS Elocal returns
1.51 + KErrAccessDenied to the write operation but EFat returns
1.52 + KErrNone...
1.53 +
1.54 + RFile f1;
1.55 + TInt r=f1.Open(TheFs,_L("TESTER"),EFileRead|EFileShareAny);
1.56 + test(r==KErrNone);
1.57 + RFile f2;
1.58 + r=f2.Open(TheFs,_L("TESTER"),EFileWrite|EFileShareAny);
1.59 + test(r==KErrNone);
1.60 +
1.61 + r=f2.Write(_L("0"));
1.62 + test.Printf(_L("returned %d"),r);
1.63 +
1.64 + f1.Close();
1.65 + f2.Close();
1.66 +
1.67 + r=TheFs.Delete(_L("TESTER"));
1.68 + test(r==KErrNone);
1.69 +*/
1.70 +
1.71 + RFile f1;
1.72 + TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.73 + test(r==KErrNone);
1.74 + RFile f2;
1.75 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.76 + test(r==KErrInUse);
1.77 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.78 + test(r==KErrInUse);
1.79 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.80 + test(r==KErrInUse);
1.81 + f1.Close();
1.82 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive);
1.83 + test(r==KErrNone);
1.84 + f1.Close();
1.85 +
1.86 + test.Next(_L("Test readers only sharing"));
1.87 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly);
1.88 + test(r==KErrArgument);
1.89 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.90 + test(r==KErrNone);
1.91 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.92 + test(r==KErrInUse);
1.93 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.94 + test(r==KErrInUse);
1.95 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly);
1.96 + test(r==KErrArgument);
1.97 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.98 + test(r==KErrNone);
1.99 + f1.Close();
1.100 + f2.Close();
1.101 +
1.102 + test.Next(_L("Test any sharing"));
1.103 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareAny);
1.104 + test(r==KErrNone);
1.105 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.106 + test(r==KErrInUse);
1.107 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.108 + test(r==KErrInUse);
1.109 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.110 + test(r==KErrNone);
1.111 + f1.Close();
1.112 + f2.Close();
1.113 +
1.114 + test.End();
1.115 + }
1.116 +
1.117 +static void testChangeMode()
1.118 +//
1.119 +// Test changing the share mode of a file between EFileShareReadersOnly <-> EFileShareExclusive
1.120 +//
1.121 + {
1.122 +
1.123 + test.Start(_L("Test change mode"));
1.124 + RFile f1;
1.125 + RFile f2;
1.126 + TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.127 + test(r==KErrNone); // Opened exclusive
1.128 + r=f1.ChangeMode(EFileShareReadersOnly);
1.129 + test(r==KErrNone); // Change to readers only
1.130 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.131 + test(r==KErrNone); // Open as reader
1.132 + r=f1.ChangeMode(EFileShareExclusive);
1.133 + test(r==KErrAccessDenied); // Change back to exclusive fails
1.134 + r=f2.ChangeMode(EFileShareExclusive);
1.135 + test(r==KErrAccessDenied); // Change to exclusive fails
1.136 + f1.Close(); // Close other reader
1.137 + r=f2.ChangeMode(EFileShareExclusive);
1.138 + test(r==KErrNone); // Change to exclusive succeeds.
1.139 + f2.Close();
1.140 +
1.141 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.142 + test(r==KErrNone); // Opened readers only
1.143 + r=f1.ChangeMode(EFileShareExclusive);
1.144 + test(r==KErrNone); // Change to exclusive
1.145 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.146 + test(r==KErrInUse); // Open as reader fails
1.147 + r=f1.ChangeMode(EFileShareReadersOnly);
1.148 + test(r==KErrNone); // Change to readers only
1.149 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.150 + test(r==KErrNone); // Open as reader
1.151 + r=f1.ChangeMode(EFileShareExclusive);
1.152 + test(r==KErrAccessDenied); // Change back to exclusive fails
1.153 + r=f2.ChangeMode(EFileShareExclusive);
1.154 + test(r==KErrAccessDenied); // Change to exclusive fails
1.155 + f1.Close(); // Close other reader
1.156 + r=f2.ChangeMode(EFileShareExclusive);
1.157 + test(r==KErrNone); // Change to exclusive succeeds.
1.158 + f2.Close();
1.159 +
1.160 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive);
1.161 + test(r==KErrNone); // Opened exclusive for writing
1.162 + r=f1.ChangeMode(EFileShareReadersOnly);
1.163 + test(r==KErrAccessDenied); // Change to readers fails
1.164 + r=f1.ChangeMode(EFileShareExclusive);
1.165 + test(r==KErrNone); // No change ok
1.166 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.167 + test(r==KErrInUse); // Open as reader fails
1.168 + f1.Close();
1.169 +
1.170 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.171 + test(r==KErrNone); // Opened share any
1.172 + r=f1.ChangeMode(EFileShareExclusive);
1.173 + test(r==KErrAccessDenied); // Change to exclusive fails
1.174 + r=f1.ChangeMode(EFileShareReadersOnly);
1.175 + test(r==KErrAccessDenied); // Change to readers only fails
1.176 + f1.Close();
1.177 +
1.178 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.179 + test(r==KErrNone); // Opened exclusive
1.180 + r=f1.ChangeMode(EFileShareAny);
1.181 + test(r==KErrArgument); // Change to share any fails KErrArgument
1.182 + r=f1.ChangeMode((TFileMode)42);
1.183 + test(r==KErrArgument); // Change to random value fails
1.184 + f1.Close();
1.185 + test.End();
1.186 + }
1.187 +
1.188 +static void testReadFile()
1.189 +//
1.190 +// Test read file handling.
1.191 +//
1.192 + {
1.193 +
1.194 + test.Start(_L("Test read file"));
1.195 + RFile f,ZFile;
1.196 + TInt r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText);
1.197 + test(r==KErrNone);
1.198 + TFileName fn = _L("Z:\\TEST\\T_FILE.CPP");
1.199 + fn[0] = gExeFileName[0];
1.200 + r=ZFile.Open(TheFs,fn,EFileStreamText);
1.201 + test(r==KErrNone);
1.202 +
1.203 + test.Next(_L("Read file"));
1.204 + TBuf8<0x100> a,b;
1.205 + FOREVER
1.206 + {
1.207 + r=f.Read(b);
1.208 + test(r==KErrNone);
1.209 + r=ZFile.Read(a);
1.210 + test(r==KErrNone);
1.211 + test(a==b);
1.212 + if (b.Length()<b.MaxLength())
1.213 + break;
1.214 + }
1.215 + b.SetLength(10);
1.216 + r=f.Read(b);
1.217 + test(r==KErrNone);
1.218 + test(b.Length()==0);
1.219 + f.Close();
1.220 + ZFile.Close();
1.221 +
1.222 + test.Next(_L("Read way beyond the end of the file"));
1.223 + r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText);
1.224 + test(r==KErrNone);
1.225 + r=f.Read(3000000,gBuf);
1.226 + test(r==KErrNone);
1.227 + f.Close();
1.228 +
1.229 + test.Next(_L("Write way beyond the end of the file"));
1.230 + r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite);
1.231 + test(r==KErrNone);
1.232 + gBuf.SetLength(10);
1.233 + r=f.Write(3000000,gBuf);
1.234 + test(r==KErrNone);
1.235 + f.Close();
1.236 + test.End();
1.237 + }
1.238 +
1.239 +static void testMultipleReadFile()
1.240 +//
1.241 +// Test multiple read file handling.
1.242 +//
1.243 + {
1.244 +
1.245 + test.Start(_L("Test multiple read file"));
1.246 + RFile f1;
1.247 + TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.248 + test(r==KErrNone);
1.249 + RFile f2;
1.250 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.251 + test(r==KErrNone);
1.252 +
1.253 + test.Next(_L("Read file"));
1.254 + FOREVER
1.255 + {
1.256 + TBuf8<0x100> b1;
1.257 + r=f1.Read(b1);
1.258 + test(r==KErrNone);
1.259 + TBuf8<0x100> b2;
1.260 + r=f2.Read(b2);
1.261 + test(r==KErrNone);
1.262 + test(b1==b2);
1.263 + if (b1.Length()<b1.MaxLength())
1.264 + break;
1.265 + }
1.266 +
1.267 + test.Next(_L("Close file"));
1.268 + f1.Close();
1.269 + f2.Close();
1.270 +
1.271 + test.End();
1.272 + }
1.273 +
1.274 +static void testWriteFile()
1.275 +//
1.276 +// Test write file handling.
1.277 +//
1.278 + {
1.279 + test.Start(_L("Test write file"));
1.280 + RFile file;
1.281 + TFileName fn = _L("File.File");
1.282 + TBuf8<16> testData=_L8("testData");
1.283 +
1.284 + // write test 1
1.285 + TInt r=file.Replace(TheFs,fn,EFileStreamText);
1.286 + test(r==KErrNone);
1.287 +
1.288 + test.Next(_L("Write file"));
1.289 +
1.290 + r=file.Write(testData);
1.291 + test(r==KErrNone);
1.292 +
1.293 + file.Close();
1.294 +
1.295 + // test write modes
1.296 + // test writing with EFileRead
1.297 + r=file.Open(TheFs,fn,EFileStreamText|EFileRead);
1.298 + test(r==KErrNone);
1.299 +
1.300 + test.Next(_L("Write file"));
1.301 + r=file.Write(testData);
1.302 + test(r==KErrAccessDenied);
1.303 + file.Close();
1.304 +
1.305 + // test writing with EFileWrite
1.306 + r=file.Open(TheFs,fn,EFileStreamText|EFileWrite);
1.307 + test(r==KErrNone);
1.308 +
1.309 + test.Next(_L("Write file"));
1.310 + r=file.Write(testData);
1.311 + test(r==KErrNone);
1.312 + file.Close();
1.313 +
1.314 + // test writing with share mode EFileShareExclusive
1.315 + r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareExclusive);
1.316 + test(r==KErrNone);
1.317 +
1.318 + test.Next(_L("Write file"));
1.319 + r=file.Write(testData);
1.320 + test(r==KErrNone);
1.321 + file.Close();
1.322 +
1.323 + // test writing with share mode EFileShareReadersOnly (fails with KErrArgument)
1.324 + r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOnly);
1.325 + test(r==KErrArgument);
1.326 +
1.327 + // test writing with share mode EFileShareReadersOrWriters
1.328 + r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOrWriters);
1.329 + test(r==KErrNone);
1.330 +
1.331 + test.Next(_L("Write file"));
1.332 + r=file.Write(testData);
1.333 + test(r==KErrNone);
1.334 + file.Close();
1.335 +
1.336 + // test writing with share mode EFileShareAny
1.337 + r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareAny);
1.338 + test(r==KErrNone);
1.339 +
1.340 + test.Next(_L("Write file"));
1.341 + r=file.Write(testData);
1.342 + test(r==KErrNone);
1.343 + file.Close();
1.344 +
1.345 + // tidy up
1.346 + r=TheFs.Delete(fn);
1.347 + test(r==KErrNone);
1.348 +
1.349 + test.End();
1.350 + }
1.351 +
1.352 +static void CopyFileToTestDirectory()
1.353 +//
1.354 +// Make a copy of the file in ram
1.355 +//
1.356 + {
1.357 +
1.358 + TFileName fn = _L("Z:\\TEST\\T_FILE.CPP");
1.359 + fn[0] = gExeFileName[0];
1.360 + TParse f;
1.361 + TInt r;
1.362 + r=TheFs.Parse(fn,f);
1.363 + test(r==KErrNone);
1.364 + TParse fCopy;
1.365 + r=TheFs.Parse(f.NameAndExt(),fCopy);
1.366 + test(r==KErrNone);
1.367 +
1.368 + RFile f1;
1.369 + r=f1.Open(TheFs,f.FullName(),EFileStreamText|EFileShareReadersOnly);
1.370 + test(r==KErrNone);
1.371 + RFile f2;
1.372 + r=f2.Replace(TheFs,fCopy.FullName(),EFileWrite);
1.373 + test(r==KErrNone);
1.374 + TBuf8<512> copyBuf;
1.375 + TInt rem;
1.376 + r=f1.Size(rem);
1.377 + test(r==KErrNone);
1.378 + TInt pos=0;
1.379 + while (rem)
1.380 + {
1.381 + TInt s=Min(rem,copyBuf.MaxSize());
1.382 + r=f1.Read(pos,copyBuf,s);
1.383 + test(r==KErrNone);
1.384 + test(copyBuf.Length()==s);
1.385 + r=f2.Write(pos,copyBuf,s);
1.386 + test(r==KErrNone);
1.387 + pos+=s;
1.388 + rem-=s;
1.389 + }
1.390 + f1.Close();
1.391 + f2.Close();
1.392 + }
1.393 +
1.394 +static void testFileText()
1.395 +//
1.396 +// Test TFileText class methods
1.397 +//
1.398 + {
1.399 +
1.400 + test.Next(_L("Test file text"));
1.401 + TPtrC record[5];
1.402 + record[0].Set(_L("First record"));
1.403 + record[1].Set(_L("Second record"));
1.404 + record[2].Set(_L("Third record"));
1.405 + record[3].Set(_L("Fourth record"));
1.406 + record[4].Set(_L("Fifth record"));
1.407 +
1.408 + RFile f;
1.409 + TInt r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
1.410 + test(r==KErrNone);
1.411 + TFileText textFile;
1.412 + textFile.Set(f);
1.413 + TInt i=0;
1.414 + for (i=0;i<5;i++)
1.415 + {
1.416 + r=textFile.Write(record[i]);
1.417 + test(r==KErrNone);
1.418 + }
1.419 + r=textFile.Seek(ESeekStart);
1.420 + test(r==KErrNone);
1.421 + TBuf<16> recBuf;
1.422 + for(i=0;i<5;i++)
1.423 + {
1.424 + r=textFile.Read(recBuf);
1.425 + test(r==KErrNone);
1.426 + test(recBuf==record[i]);
1.427 + }
1.428 + r=textFile.Read(recBuf);
1.429 + test(r==KErrEof);
1.430 + test(recBuf.Length()==0);
1.431 + f.Close();
1.432 +
1.433 + test.Next(_L("Test dosfile terminator"));
1.434 + TPtrC8 trecord[7];
1.435 + TPtrC tTextrecord[7];
1.436 + tTextrecord[0].Set(_L("First record\r\n"));
1.437 + tTextrecord[1].Set(_L("Second record\r\n"));
1.438 + tTextrecord[2].Set(_L("Third record\r\n"));
1.439 + tTextrecord[3].Set(_L("Fourth record\r\n"));
1.440 + tTextrecord[4].Set(_L("Fifth record\r\n"));
1.441 + tTextrecord[5].Set(_L("Sixth record\n\r"));
1.442 + tTextrecord[6].Set(_L("Seventh record\n"));
1.443 + trecord[0].Set((TUint8*)tTextrecord[0].Ptr(),tTextrecord[0].Length()*sizeof(TText));
1.444 + trecord[1].Set((TUint8*)tTextrecord[1].Ptr(),tTextrecord[1].Length()*sizeof(TText));
1.445 + trecord[2].Set((TUint8*)tTextrecord[2].Ptr(),tTextrecord[2].Length()*sizeof(TText));
1.446 + trecord[3].Set((TUint8*)tTextrecord[3].Ptr(),tTextrecord[3].Length()*sizeof(TText));
1.447 + trecord[4].Set((TUint8*)tTextrecord[4].Ptr(),tTextrecord[4].Length()*sizeof(TText));
1.448 + trecord[5].Set((TUint8*)tTextrecord[5].Ptr(),tTextrecord[5].Length()*sizeof(TText));
1.449 + trecord[6].Set((TUint8*)tTextrecord[6].Ptr(),tTextrecord[6].Length()*sizeof(TText));
1.450 + r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
1.451 + test(r==KErrNone);
1.452 + for(i=0;i<7;i++)
1.453 + {
1.454 + TBuf8<256> buf;
1.455 + buf.Copy(trecord[i]);
1.456 + r=f.Write(buf);
1.457 + test(r==KErrNone);
1.458 + }
1.459 + textFile.Set(f);
1.460 + textFile.Seek(ESeekStart);
1.461 + for(i=0;i<5;i++)
1.462 + {
1.463 + r=textFile.Read(recBuf);
1.464 + test(r==KErrNone);
1.465 + test(recBuf==record[i]);
1.466 + }
1.467 + r=textFile.Read(recBuf);
1.468 + test(r==KErrNone);
1.469 + test(recBuf==_L("Sixth record"));
1.470 + r=textFile.Read(recBuf);
1.471 + test(r==KErrNone);
1.472 + test(recBuf==_L("\rSeventh record"));
1.473 + r=textFile.Read(recBuf);
1.474 + test(r==KErrEof);
1.475 + test(recBuf.Length()==0);
1.476 + f.Close();
1.477 +
1.478 + test.Next(_L("Test read with bufferSize == dataSize"));
1.479 + r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0);
1.480 + test(r==KErrNone);
1.481 + record[0].Set(_L("1234567890123456"));
1.482 +// trecord[0].Set(_L8("1234567890123456\r\n"));
1.483 +// trecord[1].Set(_L8("1234567890123456\n"));
1.484 +
1.485 + TPtrC tmpTextrecord;
1.486 + tmpTextrecord.Set(_L("1234567890123456\r\n"));
1.487 + trecord[0].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText));
1.488 +
1.489 + tmpTextrecord.Set(_L("1234567890123456\n"));
1.490 + trecord[1].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText));
1.491 +
1.492 + for (i=0;i<2;i++)
1.493 + {
1.494 + r=f.Write(trecord[i]);
1.495 + test(r==KErrNone);
1.496 + }
1.497 + textFile.Set(f);
1.498 + textFile.Seek(ESeekStart);
1.499 + for(i=0;i<2;i++)
1.500 + {
1.501 + r=textFile.Read(recBuf);
1.502 + test(r==KErrNone);
1.503 + test(recBuf==record[0]);
1.504 + }
1.505 + r=textFile.Read(recBuf);
1.506 + test(r==KErrEof);
1.507 + test(recBuf.Length()==0);
1.508 + f.Close();
1.509 +
1.510 + test.Next(_L("Read into a buffer < recordSize"));
1.511 + TBuf<8> smallBuf;
1.512 + r=f.Open(TheFs,_L("TEXTFILE.txt"),0);
1.513 + test(r==KErrNone);
1.514 + textFile.Set(f);
1.515 + for(i=0;i<2;i++)
1.516 + {
1.517 + r=textFile.Read(smallBuf);
1.518 + test(r==KErrTooBig);
1.519 + test(smallBuf==_L("12345678"));
1.520 + }
1.521 + f.Close();
1.522 +
1.523 + test.Next(_L("Nasty cases: 1) \\r \\n split over buffer boundary"));
1.524 + r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
1.525 + test(r==KErrNone);
1.526 + HBufC* largeRecord=HBufC::NewL(600);
1.527 + largeRecord->Des().SetLength(250);
1.528 + largeRecord->Des().Fill('A');
1.529 + largeRecord->Des()[249]='\n';
1.530 + TPtrC8 bufPtr;
1.531 + bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); // Size() returns length in bytes
1.532 + r=f.Write(bufPtr);
1.533 + test(r==KErrNone);
1.534 + TBuf<16> boundaryBuf=_L("12345\r\n");
1.535 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.536 + r=f.Write(bufPtr);
1.537 + test(r==KErrNone);
1.538 + r=f.Write(trecord[0]);
1.539 + test(r==KErrNone);
1.540 +
1.541 + textFile.Set(f);
1.542 + textFile.Seek(ESeekStart);
1.543 + r=textFile.Read(recBuf);
1.544 + test(r==KErrTooBig);
1.545 + test(recBuf==_L("AAAAAAAAAAAAAAAA"));
1.546 + r=textFile.Read(recBuf);
1.547 + test(r==KErrNone);
1.548 + test(recBuf==_L("12345"));
1.549 + r=textFile.Read(recBuf);
1.550 + test(r==KErrNone);
1.551 + test(recBuf==record[0]);
1.552 + f.Close();
1.553 +
1.554 + test.Next(_L("Nasty cases: 2) \\r on buffer boundary"));
1.555 + r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
1.556 + test(r==KErrNone);
1.557 + largeRecord->Des().SetLength(250);
1.558 + largeRecord->Des().Fill('A');
1.559 + largeRecord->Des()[249]='\n';
1.560 + bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size());
1.561 + r=f.Write(bufPtr);
1.562 + test(r==KErrNone);
1.563 + boundaryBuf=_L("12345\rxyz\n");
1.564 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.565 + r=f.Write(bufPtr);
1.566 + test(r==KErrNone);
1.567 + r=f.Write(trecord[0]);
1.568 + test(r==KErrNone);
1.569 +
1.570 + textFile.Set(f);
1.571 + textFile.Seek(ESeekStart);
1.572 + r=textFile.Read(recBuf);
1.573 + test(r==KErrTooBig);
1.574 + test(recBuf==_L("AAAAAAAAAAAAAAAA"));
1.575 + r=textFile.Read(recBuf);
1.576 + test(r==KErrNone);
1.577 + test(recBuf==_L("12345\rxyz"));
1.578 + r=textFile.Read(recBuf);
1.579 + test(r==KErrNone);
1.580 + test(recBuf==record[0]);
1.581 + f.Close();
1.582 +
1.583 + test.Next(_L("Nasty cases: 3) record size > buffer size"));
1.584 + r=f.Replace(TheFs,_L("TEXTFILE.txt"),0);
1.585 + test(r==KErrNone);
1.586 + largeRecord->Des().SetLength(600);
1.587 + largeRecord->Des().Fill('Z');
1.588 + largeRecord->Des()[511]='\r';
1.589 + largeRecord->Des()[599]='\n';
1.590 + bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size());
1.591 + r=f.Write(bufPtr);
1.592 + test(r==KErrNone);
1.593 + boundaryBuf=_L("12345\rxyz\n");
1.594 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.595 + r=f.Write(bufPtr);
1.596 + test(r==KErrNone);
1.597 + r=f.Write(trecord[0]);
1.598 + test(r==KErrNone);
1.599 +
1.600 + textFile.Set(f);
1.601 + textFile.Seek(ESeekStart);
1.602 + r=textFile.Read(recBuf);
1.603 + test(r==KErrTooBig);
1.604 + test(recBuf==_L("ZZZZZZZZZZZZZZZZ"));
1.605 + r=textFile.Read(recBuf);
1.606 + test(r==KErrNone);
1.607 + test(recBuf==_L("12345\rxyz"));
1.608 + r=textFile.Read(recBuf);
1.609 + test(r==KErrNone);
1.610 + test(recBuf==record[0]);
1.611 +
1.612 + TBuf<601> bigBuf;
1.613 + TPtrC largePtr((TText*)largeRecord->Ptr(),(largeRecord->Length()-1));
1.614 + textFile.Seek(ESeekStart);
1.615 + r=textFile.Read(bigBuf);
1.616 + test(r==KErrNone);
1.617 + test(bigBuf==largePtr);
1.618 + r=textFile.Read(recBuf);
1.619 + test(r==KErrNone);
1.620 + test(recBuf==_L("12345\rxyz"));
1.621 + r=textFile.Read(recBuf);
1.622 + test(r==KErrNone);
1.623 + test(recBuf==record[0]);
1.624 + f.Close();
1.625 +
1.626 + User::Free(largeRecord);
1.627 + }
1.628 +
1.629 +static void testFileTextEndRecord()
1.630 +//
1.631 +// Test terminating record
1.632 +//
1.633 + {
1.634 +
1.635 + test.Next(_L("Test FileText last record has no terminator"));
1.636 + RFile f;
1.637 + TInt r=f.Replace(TheFs,_L("TextFile"),0);
1.638 + test(r==KErrNone);
1.639 + TPtrC8 bufPtr;
1.640 + TBuf<16>boundaryBuf=_L("Record1\n");
1.641 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.642 + r=f.Write(bufPtr);
1.643 + test(r==KErrNone);
1.644 + boundaryBuf=_L("Record2\n");
1.645 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.646 + r=f.Write(bufPtr);
1.647 + test(r==KErrNone);
1.648 + boundaryBuf=_L("Record3\n");
1.649 + bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size());
1.650 + r=f.Write(bufPtr);
1.651 + test(r==KErrNone);
1.652 +
1.653 + TFileText fText;
1.654 + fText.Set(f);
1.655 + r=fText.Seek(ESeekStart);
1.656 + test(r==KErrNone);
1.657 + TBuf<32> recBuf;
1.658 + r=fText.Read(recBuf);
1.659 + test(r==KErrNone);
1.660 + test(recBuf.MatchF(_L("record1"))!=KErrNotFound);
1.661 + r=fText.Read(recBuf);
1.662 + test(r==KErrNone);
1.663 + test(recBuf.MatchF(_L("record2"))!=KErrNotFound);
1.664 + r=fText.Read(recBuf);
1.665 + test(r==KErrNone);
1.666 + test(recBuf.MatchF(_L("record3"))!=KErrNotFound);
1.667 + r=fText.Read(recBuf);
1.668 + test(r==KErrEof);
1.669 + test(recBuf.Length()==0);
1.670 + f.Close();
1.671 +
1.672 + TBuf<0x100> bigBuf(0x100);
1.673 + bigBuf.Fill('A');
1.674 + r=f.Replace(TheFs,_L("TextFile"),0);
1.675 + test(r==KErrNone);
1.676 +
1.677 + bufPtr.Set((TUint8*)bigBuf.Ptr(),bigBuf.Size());
1.678 + r=f.Write(bufPtr);
1.679 + test(r==KErrNone);
1.680 +
1.681 + fText.Set(f);
1.682 + r=fText.Seek(ESeekStart);
1.683 + test(r==KErrNone);
1.684 + bigBuf.SetLength(0);
1.685 + r=fText.Read(bigBuf);
1.686 + test.Printf(_L("fText.Read returns %d\n"),r);
1.687 + test(r==KErrNone);
1.688 + test.Printf(_L("BigBuf.Length()==%d\n"),bigBuf.Length());
1.689 + test(bigBuf.Length()==0x100);
1.690 + r=fText.Read(bigBuf);
1.691 + test(r==KErrEof);
1.692 + test(bigBuf.Length()==0);
1.693 + f.Close();
1.694 + }
1.695 +
1.696 +static void testFileNames()
1.697 +//
1.698 +// Test file names
1.699 +//
1.700 + {
1.701 +
1.702 + test.Next(_L("Test temp filenames specify drive"));
1.703 + TFileName tempFileName;
1.704 + RFile f;
1.705 + TInt r=f.Temp(TheFs,_L(""),tempFileName,EFileRead);
1.706 + test(r==KErrNone);
1.707 + TParse p;
1.708 + p.Set(tempFileName,NULL,NULL);
1.709 + test(p.DrivePresent());
1.710 + test(p.PathPresent());
1.711 + test(p.NamePresent());
1.712 + test(p.ExtPresent());
1.713 + f.Close();
1.714 +
1.715 + r=f.Replace(TheFs,_L("WELCOMETO"),EFileWrite);
1.716 + test(r==KErrNone);
1.717 + f.Close();
1.718 + r=f.Replace(TheFs,_L("WELCOMETO.WRD"),EFileWrite);
1.719 + test(r==KErrNone);
1.720 + f.Close();
1.721 + }
1.722 +
1.723 +// Nasty hack - mask attributes returned by RFile::Att() with this.
1.724 +// File server used to do this but that stopped the XIP attribute on the ROM file system
1.725 +// from being returned. It should really be up to the file system to return only
1.726 +// the attributes which it supports rather than having the file server unilaterally
1.727 +// mask off any attributes which don't exist on FAT.
1.728 +#define ATT_MASK 0x3f
1.729 +static void testFileAttributes()
1.730 +//
1.731 +// Test the archive attribute gets set
1.732 +//
1.733 + {
1.734 +
1.735 + test.Next(_L("Archive att is set after creation"));
1.736 + RFile f;
1.737 + TInt r=TheFs.Delete(_L("FILEATT.ARC"));
1.738 + test(r==KErrNone || r==KErrNotFound);
1.739 + r=f.Create(TheFs,_L("FILEATT.ARC"),EFileRead);
1.740 + test(r==KErrNone);
1.741 + TUint atts;
1.742 + r=f.Att(atts);
1.743 + test(r==KErrNone);
1.744 + test((atts&ATT_MASK)==KEntryAttArchive);
1.745 + TEntry fileAtt;
1.746 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.747 + test(r==KErrNone);
1.748 + test(fileAtt.iAtt==KEntryAttArchive);
1.749 + f.Close();
1.750 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.751 + test(r==KErrNone);
1.752 + test(fileAtt.iAtt==KEntryAttArchive);
1.753 +
1.754 + test.Next(_L("Archive att is set after a write"));
1.755 + TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
1.756 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.757 + test(r==KErrNone);
1.758 + test(fileAtt.iAtt==0);
1.759 + r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
1.760 + test(r==KErrNone);
1.761 + r=f.Write(_L8("Hello World"));
1.762 + test(r==KErrNone);
1.763 + r=f.Att(atts);
1.764 + test(r==KErrNone);
1.765 + test((atts&ATT_MASK)==KEntryAttArchive);
1.766 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.767 + test(r==KErrNone);
1.768 + test(fileAtt.iAtt==KEntryAttArchive);
1.769 + f.Close();
1.770 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.771 + test(r==KErrNone);
1.772 + test(fileAtt.iAtt==KEntryAttArchive);
1.773 +
1.774 + test.Next(_L("Archive att is set after setsize"));
1.775 + TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
1.776 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.777 + test(r==KErrNone);
1.778 + test(fileAtt.iAtt==0);
1.779 + r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
1.780 + test(r==KErrNone);
1.781 + r=f.SetSize(447);
1.782 + test(r==KErrNone);
1.783 + TInt size;
1.784 + r=f.Size(size);
1.785 + test(r==KErrNone);
1.786 + test(size==447);
1.787 + r=f.Att(atts);
1.788 + test(r==KErrNone);
1.789 + test((atts&ATT_MASK)==KEntryAttArchive);
1.790 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.791 + test(r==KErrNone);
1.792 + test(fileAtt.iAtt==KEntryAttArchive);
1.793 + f.Close();
1.794 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.795 + test(r==KErrNone);
1.796 + test(fileAtt.iAtt==KEntryAttArchive);
1.797 +
1.798 + test.Next(_L("Archive att is not set after open"));
1.799 + r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
1.800 + test(r==KErrNone);
1.801 + r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
1.802 + test(r==KErrNone);
1.803 + r=f.Att(atts);
1.804 + test(r==KErrNone);
1.805 + test((atts&ATT_MASK)==0);
1.806 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.807 + test(r==KErrNone);
1.808 + test(fileAtt.iAtt==0);
1.809 + f.Close();
1.810 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.811 + test(r==KErrNone);
1.812 + test(fileAtt.iAtt==0);
1.813 +
1.814 + test.Next(_L("Archive att is not set after a read"));
1.815 + TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive);
1.816 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.817 + test(r==KErrNone);
1.818 + test(fileAtt.iAtt==0);
1.819 + r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite);
1.820 + test(r==KErrNone);
1.821 + TBuf8<16> readBuf;
1.822 + r=f.Read(readBuf);
1.823 + test(r==KErrNone);
1.824 + r=f.Att(atts);
1.825 + test(r==KErrNone);
1.826 + test((atts&ATT_MASK)==0);
1.827 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.828 + test(r==KErrNone);
1.829 + test(fileAtt.iAtt==0);
1.830 + f.Close();
1.831 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.832 + test(r==KErrNone);
1.833 + test(fileAtt.iAtt==0);
1.834 +
1.835 + test.Next(_L("Archive att is set after replace"));
1.836 + r=f.Replace(TheFs,_L("FILEATT.ARC"),EFileWrite);
1.837 + test(r==KErrNone);
1.838 + r=f.Att(atts);
1.839 + test(r==KErrNone);
1.840 + test((atts&ATT_MASK)==KEntryAttArchive);
1.841 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.842 + test(r==KErrNone);
1.843 + test(fileAtt.iAtt==KEntryAttArchive);
1.844 + f.Close();
1.845 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.846 + test(r==KErrNone);
1.847 + test(fileAtt.iAtt==KEntryAttArchive);
1.848 +
1.849 + test.Next(_L("Read only bit can be unset"));
1.850 + r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0);
1.851 + test(r==KErrNone);
1.852 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.853 + test(r==KErrNone);
1.854 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
1.855 +
1.856 + r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden);
1.857 + test(r==KErrNone);
1.858 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.859 + test(r==KErrNone);
1.860 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive));
1.861 +
1.862 + r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly);
1.863 + test(r==KErrNone);
1.864 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.865 + test(r==KErrNone);
1.866 + test(fileAtt.iAtt==(KEntryAttArchive));
1.867 +
1.868 + r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0);
1.869 + test(r==KErrNone);
1.870 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.871 + test(r==KErrNone);
1.872 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
1.873 +
1.874 + r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly);
1.875 + test(r==KErrNone);
1.876 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.877 + test(r==KErrNone);
1.878 + test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive));
1.879 +
1.880 + r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden);
1.881 + test(r==KErrNone);
1.882 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.883 + test(r==KErrNone);
1.884 + test(fileAtt.iAtt==(KEntryAttArchive));
1.885 +
1.886 + TTime time(0);
1.887 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0);
1.888 + test(r==KErrNone);
1.889 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.890 + test(r==KErrNone);
1.891 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
1.892 +
1.893 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden);
1.894 + test(r==KErrNone);
1.895 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.896 + test(r==KErrNone);
1.897 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive));
1.898 +
1.899 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly);
1.900 + test(r==KErrNone);
1.901 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.902 + test(r==KErrNone);
1.903 + test(fileAtt.iAtt==(KEntryAttArchive));
1.904 +
1.905 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0);
1.906 + test(r==KErrNone);
1.907 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.908 + test(r==KErrNone);
1.909 + test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive));
1.910 +
1.911 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly);
1.912 + test(r==KErrNone);
1.913 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.914 + test(r==KErrNone);
1.915 + test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive));
1.916 +
1.917 + r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden);
1.918 + test(r==KErrNone);
1.919 + r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt);
1.920 + test(r==KErrNone);
1.921 + test(fileAtt.iAtt==(KEntryAttArchive));
1.922 +
1.923 + test.Next(_L("Cashing the 'read-only' attribute"));
1.924 + const TDesC& fname = _L("TEST.RO");
1.925 +
1.926 + // Test RO attribute after creating a file
1.927 + r=f.Create(TheFs,fname,EFileWrite);
1.928 + test(r==KErrNone);
1.929 + r=f.SetAtt(KEntryAttReadOnly,0);
1.930 + test(r==KErrNone);
1.931 + r=f.Write(_L8("Hello World"));
1.932 + test(r==KErrNone); // <-- here!
1.933 + f.Close();
1.934 +
1.935 + // Test we can't open for write or delete a RO file
1.936 + r=f.Open(TheFs,fname,EFileWrite);
1.937 + test(r==KErrAccessDenied);
1.938 + r=TheFs.Delete(fname);
1.939 + test(r==KErrAccessDenied);
1.940 +
1.941 + // Tidy up and re-create test file
1.942 + r=TheFs.SetAtt(fname,0,KEntryAttReadOnly);
1.943 + test(r==KErrNone);
1.944 + r=TheFs.Delete(fname);
1.945 + test(r==KErrNone);
1.946 + r=f.Create(TheFs,fname,EFileWrite);
1.947 + test(r==KErrNone);
1.948 + f.Close();
1.949 +
1.950 + // Test RO attribute after opening a file
1.951 + r=f.Open(TheFs,fname,EFileWrite);
1.952 + test(r==KErrNone);
1.953 + r=f.SetAtt(KEntryAttReadOnly,0);
1.954 + test(r==KErrNone);
1.955 + r=f.Write(_L8("Hello World"));
1.956 + test(r==KErrNone);
1.957 + f.Close();
1.958 +
1.959 + // Tidy up
1.960 + r=TheFs.SetAtt(fname,0,KEntryAttReadOnly);
1.961 + test(r==KErrNone);
1.962 + r=TheFs.Delete(fname);
1.963 + test(r==KErrNone);
1.964 + }
1.965 +
1.966 +static void testShortNameAccessorFunctions()
1.967 +//
1.968 +// Test RFs::GetShortName(...)
1.969 +//
1.970 + {
1.971 + test.Next(_L("Test short name accessor functions"));
1.972 +
1.973 + if(!gShortFileNamesSupported)
1.974 + {
1.975 + test.Printf(_L("Short Names are not supported!. Skipping..."));
1.976 + return;
1.977 + }
1.978 +
1.979 +
1.980 + TBuf<64> sessionPath;
1.981 + TInt r=TheFs.SessionPath(sessionPath);
1.982 + test(r==KErrNone);
1.983 + RFile f;
1.984 + r=TheFs.MkDirAll(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\RANDOM.ENDBIT"));
1.985 + test(r==KErrNone || r==KErrAlreadyExists);
1.986 + r=f.Replace(TheFs,_L("LONGFILENAME.LONGEXT"),EFileWrite);
1.987 + test(r==KErrNone);
1.988 + f.Close();
1.989 + r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),EFileWrite);
1.990 + test(r==KErrNone);
1.991 + f.Close();
1.992 + r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),EFileWrite);
1.993 + test(r==KErrNone);
1.994 + f.Close();
1.995 + r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GoodCHAR.TXT"),EFileWrite);
1.996 + test(r==KErrNone);
1.997 + f.Close();
1.998 + TBuf<12> shortName1;
1.999 + TBuf<12> shortName2;
1.1000 + TBuf<12> shortName3;
1.1001 + TBuf<12> shortName4;
1.1002 + TBuf<12> shortName5;
1.1003 + r=TheFs.GetShortName(_L("LONGFILENAME.LONGEXT"),shortName1);
1.1004 + test(r==KErrNone);
1.1005 + r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),shortName2);
1.1006 + test(r==KErrNone);
1.1007 + r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),shortName3);
1.1008 + test(r==KErrNone);
1.1009 + r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),shortName4);
1.1010 + test(r==KErrNone);
1.1011 + r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY"),shortName5);
1.1012 + test(r==KErrNone);
1.1013 +
1.1014 + if(Is_Win32(TheFs, gDriveNum))
1.1015 + {
1.1016 + test(shortName1==_L("LONGFI~1.LON"));
1.1017 + test(shortName2==_L("LONGFI~1.LON"));
1.1018 + test(shortName3==_L("BADCHA~1"));
1.1019 + test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0);
1.1020 + test(shortName5==_L("MIDDLE~1"));
1.1021 + }
1.1022 + else if(!IsTestingLFFS())
1.1023 + {
1.1024 + // LFFS short names not the same as VFAT ones
1.1025 + test(shortName1==_L("LONGFI~1.LON"));
1.1026 + test(shortName2==_L("LONGFI~1.LON"));
1.1027 + test(shortName3==_L("BAD_CHAR"));
1.1028 + test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0);
1.1029 + test(shortName5==_L("MIDDLE~1"));
1.1030 + }
1.1031 +
1.1032 + TFileName longName1;
1.1033 + TFileName longName2;
1.1034 + TFileName longName3;
1.1035 + TFileName longName4;
1.1036 + TFileName longName5;
1.1037 +
1.1038 + if (Is_Win32(TheFs, gDriveNum))
1.1039 + {
1.1040 + r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1);
1.1041 + test(r==KErrNone);
1.1042 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2);
1.1043 + test(r==KErrNone);
1.1044 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BADCHA~1"),longName3);
1.1045 + test(r==KErrNone);
1.1046 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4);
1.1047 + test(r==KErrNone);
1.1048 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5);
1.1049 + test(r==KErrNone);
1.1050 + }
1.1051 + else if (!IsTestingLFFS())
1.1052 + {
1.1053 + r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1);
1.1054 + test(r==KErrNone);
1.1055 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2);
1.1056 + test(r==KErrNone);
1.1057 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD_CHAR"),longName3);
1.1058 + test(r==KErrNone);
1.1059 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4);
1.1060 + test(r==KErrNone);
1.1061 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5);
1.1062 + test(r==KErrNone);
1.1063 + }
1.1064 + else
1.1065 + {
1.1066 + // LFFS longname tests
1.1067 + r=TheFs.GetLongName(shortName1,longName1);
1.1068 + test(r==KErrNone);
1.1069 + r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\"));
1.1070 + test(r==KErrNone);
1.1071 + r=TheFs.GetLongName(shortName2,longName2);
1.1072 + test(r==KErrNone);
1.1073 + r=TheFs.GetLongName(shortName3,longName3);
1.1074 + test(r==KErrNone);
1.1075 + r=TheFs.GetLongName(shortName4,longName4);
1.1076 + test(r==KErrNone);
1.1077 + r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\"));
1.1078 + test(r==KErrNone);
1.1079 + r=TheFs.GetLongName(shortName5,longName5);
1.1080 + test(r==KErrNone);
1.1081 + r=TheFs.SetSessionPath(sessionPath);
1.1082 + test(r==KErrNone);
1.1083 + }
1.1084 +
1.1085 + test(longName1==_L("LONGFILENAME.LONGEXT"));
1.1086 + test(longName2==_L("LONGFILENAME.LONGEXT"));
1.1087 + test(longName3==_L("BAD CHAR"));
1.1088 + test(longName4.FindF(_L("GOODCHAR.TXT"))>=0);
1.1089 + test(longName5==_L("MIDDLE-DIRECTORY"));
1.1090 +
1.1091 + r=TheFs.GetShortName(_L("XXX.YYY"),shortName1);
1.1092 + test(r==KErrNotFound);
1.1093 + r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),shortName1);
1.1094 + test(r==KErrPathNotFound);
1.1095 + r=TheFs.GetLongName(_L("XXX.YYY"),longName1);
1.1096 + test(r==KErrNotFound);
1.1097 + r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),longName1);
1.1098 + test(r==KErrPathNotFound);
1.1099 +
1.1100 + r=TheFs.Delete(_L("LONGFILENAME.LONGEXT"));
1.1101 + test(r==KErrNone);
1.1102 +
1.1103 + TEntry romEntry;
1.1104 + r=TheFs.Entry(_L("Z:\\System"),romEntry);
1.1105 + if (r==KErrNotReady)
1.1106 + {
1.1107 + test.Printf(_L("ERROR: No rom filesystem present"));
1.1108 + //test.Getch();
1.1109 + //return;
1.1110 + }
1.1111 + test(r==KErrNone);
1.1112 + TBuf<64> romFileName=_L("Z:\\");
1.1113 + romFileName.Append(romEntry.iName);
1.1114 + r=TheFs.GetShortName(romFileName,shortName1);
1.1115 + test(r==KErrNotSupported);
1.1116 + r=TheFs.GetLongName(_L("Z:\\system"),longName1);
1.1117 + test(r==KErrNotSupported);
1.1118 + }
1.1119 +
1.1120 +static void RmDir(const TDesC& aDirName)
1.1121 +//
1.1122 +// Remove a directory
1.1123 +//
1.1124 + {
1.1125 + CFileMan* fMan=CFileMan::NewL(TheFs);
1.1126 + test(fMan!=NULL);
1.1127 + TInt r=TheFs.SessionPath(gSessionPath);
1.1128 + test(r==KErrNone);
1.1129 + r=TheFs.CheckDisk(gSessionPath);
1.1130 + if (r!=KErrNone && r!=KErrNotSupported)
1.1131 + ReportCheckDiskFailure(r);
1.1132 +
1.1133 + TFileName removeDirName = gSessionPath;
1.1134 + removeDirName.Append(aDirName);
1.1135 +
1.1136 + fMan->Attribs(removeDirName, 0, KEntryAttReadOnly, 0, CFileMan::ERecurse);
1.1137 + r=fMan->RmDir(removeDirName);
1.1138 + test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
1.1139 +
1.1140 + delete fMan;
1.1141 + }
1.1142 +//---------------------------------------------
1.1143 +//! @SYMTestCaseID PBASE-T_TFILE-0659
1.1144 +//! @SYMTestType CT
1.1145 +//! @SYMREQ INC112803
1.1146 +//! @SYMTestCaseDesc Tests that RFs::GetShortName() considers the file extension while generating
1.1147 +//! shortname from longname and applies ~num if applicable.
1.1148 +//! @SYMTestActions 1. Generates the shortname for the given filename.
1.1149 +//! 2. Validates the generated shortname against the original filename.
1.1150 +//! @SYMTestExpectedResults The operation completes with no error. Valid shortname is generated.
1.1151 +//! @SYMTestPriority High
1.1152 +//! @SYMTestStatus Implemented
1.1153 +//---------------------------------------------
1.1154 +static void TestINC112803()
1.1155 + {
1.1156 +
1.1157 + if(!gShortFileNamesSupported)
1.1158 + {
1.1159 + test.Printf(_L("TestINC112803 : Short names are not supported!\n"));
1.1160 + return;
1.1161 + }
1.1162 +
1.1163 +
1.1164 + TInt err =0;
1.1165 + _LIT(KOrigFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JARX");
1.1166 + _LIT(KOrigFileShortName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222~1.JAR");
1.1167 + _LIT(KDestinationFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JAR");
1.1168 +
1.1169 + // Make sure the file does not already exist
1.1170 + RmDir(_L("INC112803\\"));
1.1171 +
1.1172 + // Create directories and the file
1.1173 + MakeDir(_L("\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
1.1174 + MakeFile(KOrigFileName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
1.1175 +
1.1176 + // Check the generated shortname of the original file
1.1177 + TBuf<12> shortName;
1.1178 + err = TheFs.GetShortName(KOrigFileName, shortName);
1.1179 + test(err==KErrNone);
1.1180 +
1.1181 + // Validate the generated shorname against the original filename.
1.1182 + if (Is_Win32(TheFs, gDriveNum))
1.1183 + {
1.1184 + test(shortName==_L("2222~1.JAR"));
1.1185 + }
1.1186 + else if(!IsTestingLFFS())
1.1187 + {
1.1188 + // LFFS short names not the same as VFAT ones
1.1189 + test(shortName==_L("2222~1.JAR"));
1.1190 + }
1.1191 +
1.1192 + // Validate that the file "2222~1.JAR" can not be created as this is the shortname for "2222.JARX".
1.1193 + MakeFile(KOrigFileShortName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\"));
1.1194 + CheckFileExists(KOrigFileShortName, KErrNone, EFalse);
1.1195 +
1.1196 + err = TheFs.Rename(KOrigFileName,KDestinationFileName);
1.1197 + test(err==KErrNone);
1.1198 +
1.1199 + // Clean up before leaving
1.1200 + RmDir(_L("INC112803\\"));
1.1201 + }
1.1202 +
1.1203 +static void testIsFileOpen()
1.1204 +//
1.1205 +// Test the IsFileOpen method
1.1206 +//
1.1207 + {
1.1208 +
1.1209 + test.Next(_L("Test IsFileOpen"));
1.1210 + TBool answer;
1.1211 + TInt r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1212 + test(r==KErrNotFound || (r==KErrNone && answer==EFalse));
1.1213 + RFile f;
1.1214 + r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite);
1.1215 + test(r==KErrNone);
1.1216 + r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1217 + test(r==KErrNone);
1.1218 + test(answer!=EFalse);
1.1219 + f.Close();
1.1220 + r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1221 + test(r==KErrNone);
1.1222 + test(answer==EFalse);
1.1223 + r=TheFs.Delete(_L("OPEN.FILE"));
1.1224 + test(r==KErrNone);
1.1225 +
1.1226 + RFile f2;
1.1227 + r=f2.Replace(TheFs,_L("AnotherOpen.File"),EFileWrite);
1.1228 + test(r==KErrNone);
1.1229 + r=TheFs.IsFileOpen(_L("AnotherOpen.File"),answer);
1.1230 + test(r==KErrNone);
1.1231 + test(answer!=EFalse);
1.1232 + r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite);
1.1233 + test(r==KErrNone);
1.1234 + r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1235 + test(r==KErrNone);
1.1236 + test(answer!=EFalse);
1.1237 + f2.Close();
1.1238 + r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1239 + test(r==KErrNone);
1.1240 + test(answer!=EFalse);
1.1241 + f.Close();
1.1242 + r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer);
1.1243 + test(r==KErrNone);
1.1244 + test(answer==EFalse);
1.1245 + r=TheFs.Delete(_L("AnotherOpen.File"));
1.1246 + test(r==KErrNone);
1.1247 + r=TheFs.Delete(_L("OPEN.FILE"));
1.1248 + test(r==KErrNone);
1.1249 + }
1.1250 +
1.1251 +static void testDeleteOpenFiles()
1.1252 +//
1.1253 +// Test opened files cannot be deleted
1.1254 +//
1.1255 + {
1.1256 +
1.1257 + test.Next(_L("Test opened files cannot be deleted"));
1.1258 + RFile f;
1.1259 + f.Close();
1.1260 + TInt r=f.Replace(TheFs,_L("Open.File"),EFileWrite);
1.1261 + test(r==KErrNone);
1.1262 + r=TheFs.Delete(_L("OPEN.FILE"));
1.1263 + test(r==KErrInUse);
1.1264 + f.Close();
1.1265 + f.Close();
1.1266 + f.Close();
1.1267 + r=TheFs.Delete(_L("Open.FILe"));
1.1268 + test(r==KErrNone);
1.1269 +
1.1270 + TFileName fileName;
1.1271 + r=f.Temp(TheFs,_L(""),fileName,EFileWrite);
1.1272 + test(r==KErrNone);
1.1273 + r=TheFs.Delete(fileName);
1.1274 + test(r==KErrInUse);
1.1275 + f.Close();
1.1276 + r=TheFs.Delete(fileName);
1.1277 + test(r==KErrNone);
1.1278 +
1.1279 + MakeFile(_L("\\Documents\\TEstfile.txt"));
1.1280 + r=f.Open(TheFs,_L("\\Documents\\TEstfile.txt"),EFileWrite);
1.1281 + test(r==KErrNone);
1.1282 + r=TheFs.Delete(_L("\\Documents\\TEstfile.txt"));
1.1283 + test(r==KErrInUse);
1.1284 + r=TheFs.Delete(_L("\\documents\\TEstfile.txt"));
1.1285 + test(r==KErrInUse);
1.1286 + r=TheFs.Delete(_L("\\Documents.\\TEstfile.txt"));
1.1287 + test(r==KErrBadName);
1.1288 + r=TheFs.Delete(_L("\\documents.\\TEstfile.txt"));
1.1289 + test(r==KErrBadName);
1.1290 + r=TheFs.Delete(_L("\\Documents\\Testfile.txt"));
1.1291 + test(r==KErrInUse);
1.1292 + r=TheFs.Delete(_L("\\documents\\testfile.txt"));
1.1293 + test(r==KErrInUse);
1.1294 + r=TheFs.Delete(_L("\\Documents.\\TEstfile.TXT"));
1.1295 + test(r==KErrBadName);
1.1296 + r=TheFs.Delete(_L("\\docUMENTS.\\TESTFILE.TXT"));
1.1297 + test(r==KErrBadName);
1.1298 + f.Close();
1.1299 + r=TheFs.Delete(_L("\\Documents\\TEstfile.TXT"));
1.1300 + test(r==KErrNone);
1.1301 +
1.1302 + MakeFile(_L("\\Documents\\Documents\\TEstfile.txt"));
1.1303 + r=f.Open(TheFs,_L("\\Documents\\Documents\\TEstfile.txt"),EFileWrite);
1.1304 + test(r==KErrNone);
1.1305 + r=TheFs.Delete(_L("\\Documents\\documents.\\TEstfile.txt"));
1.1306 + test(r==KErrBadName);
1.1307 + r=TheFs.Delete(_L("\\documents\\Documents.\\TEstfile.txt"));
1.1308 + test(r==KErrBadName);
1.1309 + r=TheFs.Delete(_L("\\Documents.\\documents\\TEstfile.txt"));
1.1310 + test(r==KErrBadName);
1.1311 + r=TheFs.Delete(_L("\\documents.\\Documents\\TEstfile.txt"));
1.1312 + test(r==KErrBadName);
1.1313 + r=TheFs.Delete(_L("\\Documents\\Documents\\Testfile.txt"));
1.1314 + test(r==KErrInUse);
1.1315 + r=TheFs.Delete(_L("\\documents\\documents\\testfile.txt"));
1.1316 + test(r==KErrInUse);
1.1317 + r=TheFs.Delete(_L("\\Documents.\\Documents.\\TEstfile.TXT"));
1.1318 + test(r==KErrBadName);
1.1319 + r=TheFs.Delete(_L("\\docUMENTS.\\docUMENTS.\\TESTFILE.TXT"));
1.1320 + test(r==KErrBadName);
1.1321 +
1.1322 +
1.1323 + r=TheFs.RmDir(_L("\\Documents\\"));
1.1324 + test(r==KErrInUse);
1.1325 + r=TheFs.RmDir(_L("\\documents\\"));
1.1326 + test(r==KErrInUse);
1.1327 + r=TheFs.RmDir(_L("\\Documents.\\"));
1.1328 + test(r==KErrBadName);
1.1329 + r=TheFs.RmDir(_L("\\documents.\\"));
1.1330 + test(r==KErrBadName);
1.1331 + r=TheFs.RmDir(_L("\\Documents\\documents\\"));
1.1332 + test(r==KErrInUse);
1.1333 + r=TheFs.RmDir(_L("\\documents\\documents.\\"));
1.1334 + test(r==KErrBadName);
1.1335 + r=TheFs.RmDir(_L("\\Documents.\\Documents\\"));
1.1336 + test(r==KErrBadName);
1.1337 + r=TheFs.RmDir(_L("\\documents.\\Documents.\\"));
1.1338 + test(r==KErrBadName);
1.1339 + r=TheFs.RmDir(_L("\\Documents\\TestFile.TXT"));
1.1340 + test(r==KErrInUse);
1.1341 + r=TheFs.RmDir(_L("\\documents\\TestFile"));
1.1342 + test(r==KErrInUse);
1.1343 + r=TheFs.RmDir(_L("\\Documents.\\Testfile."));
1.1344 + test(r==KErrBadName);
1.1345 + r=TheFs.RmDir(_L("\\documents.\\t"));
1.1346 + test(r==KErrBadName);
1.1347 + f.Close();
1.1348 + r=TheFs.Delete(_L("\\Documents\\documents\\TEstfile.TXT"));
1.1349 + test(r==KErrNone);
1.1350 + r=TheFs.RmDir(_L("\\Documents\\documents.\\"));
1.1351 + test(r==KErrBadName);
1.1352 + r=TheFs.RmDir(_L("\\Documents.\\"));
1.1353 + test(r==KErrBadName);
1.1354 + }
1.1355 +
1.1356 +static void testFileSeek()
1.1357 +//
1.1358 +// Test seeking
1.1359 +//
1.1360 + {
1.1361 + test.Next(_L("Test file seek"));
1.1362 + RFile f;
1.1363 + TInt r=f.Open(TheFs,_L("T_File.cpp"),EFileWrite);
1.1364 + test(r==KErrNone);
1.1365 +
1.1366 + TBuf8<20> text1;TInt pos1=0;
1.1367 + TBuf8<20> text2;TInt pos2=510;
1.1368 + TBuf8<20> text3;TInt pos3=900;
1.1369 + TBuf8<20> text4;TInt pos4=2010;
1.1370 + TBuf8<20> text5;TInt pos5=4999;
1.1371 +
1.1372 + r=f.Read(pos1,text1);
1.1373 + test(r==KErrNone);
1.1374 + r=f.Read(pos2,text2);
1.1375 + test(r==KErrNone);
1.1376 + r=f.Read(pos3,text3);
1.1377 + test(r==KErrNone);
1.1378 + r=f.Read(pos4,text4);
1.1379 + test(r==KErrNone);
1.1380 + r=f.Read(pos5,text5);
1.1381 + test(r==KErrNone);
1.1382 +
1.1383 + TBuf8<20> testBuf;
1.1384 +
1.1385 + r=f.Read(pos3,testBuf);
1.1386 + test(r==KErrNone);
1.1387 + test(testBuf==text3);
1.1388 +
1.1389 + r=f.Read(pos1,testBuf);
1.1390 + test(r==KErrNone);
1.1391 + test(testBuf==text1);
1.1392 +
1.1393 + r=f.Read(pos4,testBuf);
1.1394 + test(r==KErrNone);
1.1395 + test(testBuf==text4);
1.1396 +
1.1397 + r=f.Read(pos2,testBuf);
1.1398 + test(r==KErrNone);
1.1399 + test(testBuf==text2);
1.1400 +
1.1401 + r=f.Read(pos5,testBuf);
1.1402 + test(r==KErrNone);
1.1403 + test(testBuf==text5);
1.1404 +
1.1405 + r=f.Read(pos2,testBuf);
1.1406 + test(r==KErrNone);
1.1407 + test(testBuf==text2);
1.1408 + r=f.SetSize(1023);
1.1409 + test(r==KErrNone);
1.1410 + r=f.Read(pos2,testBuf);
1.1411 + test(r==KErrNone);
1.1412 + test(testBuf==text2);
1.1413 + r=f.SetSize(1024);
1.1414 + test(r==KErrNone);
1.1415 + r=f.Read(pos1,testBuf);
1.1416 + test(r==KErrNone);
1.1417 + test(testBuf==text1);
1.1418 + r=f.Read(pos2,testBuf);
1.1419 + test(r==KErrNone);
1.1420 + test(testBuf==text2);
1.1421 +
1.1422 + r=f.Read(pos1,testBuf);
1.1423 + test(r==KErrNone);
1.1424 + test(testBuf==text1);
1.1425 + r=f.SetSize(511);
1.1426 + test(r==KErrNone);
1.1427 + r=f.Read(pos1,testBuf);
1.1428 + test(r==KErrNone);
1.1429 + test(testBuf==text1);
1.1430 + r=f.SetSize(512);
1.1431 + test(r==KErrNone);
1.1432 + r=f.Read(pos1,testBuf);
1.1433 + test(r==KErrNone);
1.1434 + test(testBuf==text1);
1.1435 + f.Close();
1.1436 + }
1.1437 +
1.1438 +static void testMoreFileSeek()
1.1439 +//
1.1440 +// Further test of RFile::Seek()
1.1441 +//
1.1442 + {
1.1443 +// Create a zero length file
1.1444 + RFile file;
1.1445 + TInt r=file.Replace(TheFs,_L("\\F32-TST\\TFILE\\seektest"),EFileRead|EFileWrite);
1.1446 + test(r==KErrNone);
1.1447 + r=file.SetSize(20);
1.1448 + test(r==KErrNone);
1.1449 +// Seek beyond the length of the file
1.1450 + TInt seekPos;
1.1451 + seekPos = 80; // Pick a likely offset
1.1452 + TInt err = file.Seek(ESeekEnd, seekPos); // and go there
1.1453 + test(err==KErrNone);
1.1454 + test(seekPos==20); // Somewhat non-intuitive?
1.1455 +
1.1456 + r=file.Write(_L8("A Devil's Haircut"));
1.1457 + test(r==KErrNone);
1.1458 + TInt newFileSize;
1.1459 + r=file.Size(newFileSize);
1.1460 + test(r==KErrNone);
1.1461 +
1.1462 + seekPos = 0;
1.1463 + err = file.Seek(ESeekCurrent, seekPos); // Find out where we ended up?
1.1464 + test(err==KErrNone);
1.1465 + test(seekPos==37);
1.1466 +
1.1467 + file.SetSize(512);
1.1468 + seekPos=513;
1.1469 + err=file.Seek(ESeekStart, seekPos);
1.1470 + test(err==KErrNone);
1.1471 + test(seekPos==513);
1.1472 +
1.1473 + err=file.Seek(ESeekEnd, seekPos);
1.1474 + test(err==KErrNone);
1.1475 + test(seekPos==512);
1.1476 +
1.1477 + seekPos=-530;
1.1478 + err=file.Seek(ESeekEnd, seekPos);
1.1479 + test(err==KErrNone);
1.1480 + test(seekPos==0);
1.1481 +
1.1482 + seekPos=-10;
1.1483 + err=file.Seek(ESeekEnd, seekPos);
1.1484 + test(err==KErrNone);
1.1485 + test(seekPos==502);
1.1486 +
1.1487 + seekPos=-10;
1.1488 + err=file.Seek(ESeekStart,seekPos);
1.1489 + test(err==KErrArgument);
1.1490 + test(seekPos==-10);
1.1491 +
1.1492 + seekPos=0;
1.1493 + err=file.Seek(ESeekEnd,seekPos);
1.1494 + test(err==KErrNone);
1.1495 + test(seekPos==512);
1.1496 +
1.1497 + file.Close();
1.1498 + r=TheFs.Delete(_L("\\F32-TST\\TFILE\\seektest"));
1.1499 + test(r==KErrNone);
1.1500 + }
1.1501 +
1.1502 +static void testSetSize()
1.1503 +//
1.1504 +// Test setsize
1.1505 +//
1.1506 + {
1.1507 +
1.1508 + test.Next(_L("Test SetSize"));
1.1509 + RFile f1;
1.1510 + TInt i=0;
1.1511 + TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
1.1512 + test(r==KErrNone);
1.1513 + gBuf.SetLength(32);
1.1514 + for(i=0;i<32;i++)
1.1515 + gBuf[i]=(TUint8)i;
1.1516 + r=f1.Write(gBuf);
1.1517 + test(r==KErrNone);
1.1518 + gBuf.SetLength(1334);
1.1519 + for(i=64;i<1334+64;i++)
1.1520 + gBuf[i-64]=(TUint8)i;
1.1521 + r=f1.Write(30,gBuf);
1.1522 + r=f1.Read(30,gBuf,1000);
1.1523 + test(r==KErrNone);
1.1524 + test(gBuf[0]==64);
1.1525 + test(gBuf[1]==65);
1.1526 + test(gBuf[2]==66);
1.1527 + f1.Close();
1.1528 +
1.1529 + test.Next(_L("Open a large file"));
1.1530 + r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
1.1531 + test(r==KErrNone);
1.1532 + CheckDisk();
1.1533 + r=f1.SetSize(131072); // 128K
1.1534 + test(r==KErrNone);
1.1535 + TBuf8<16> testData=_L8("testData");
1.1536 + r=f1.Write(131060,testData);
1.1537 + test(r==KErrNone);
1.1538 + f1.Close();
1.1539 + r=f1.Open(TheFs,_L("File.File"),EFileRead);
1.1540 + test(r==KErrNone);
1.1541 + TInt size;
1.1542 + r=f1.Size(size);
1.1543 + test(r==KErrNone);
1.1544 + test(size==131072);
1.1545 + TBuf8<16> testData2;
1.1546 + r=f1.Read(131060,testData2,8);
1.1547 + test(r==KErrNone);
1.1548 + test(testData==testData2);
1.1549 + f1.Close();
1.1550 + TheFs.Delete(_L("File.file"));
1.1551 + CheckDisk();
1.1552 + }
1.1553 +
1.1554 +static void testIsRomAddress()
1.1555 + {
1.1556 + RFile f;
1.1557 + TInt r=f.Open(TheFs, PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\eshell.exe"):_L("Z:\\System\\Bin\\eshell.exe"), EFileRead);
1.1558 + test(r==KErrNone);
1.1559 + TInt anAddress=0;
1.1560 + r=f.Seek(ESeekAddress, anAddress);
1.1561 + test(r==KErrNone);
1.1562 +#if !defined(__WINS__)
1.1563 + test(RFs::IsRomAddress((TAny *)anAddress)); // Always returns EFalse if WINS
1.1564 +#endif
1.1565 + test(RFs::IsRomAddress(NULL)==FALSE);
1.1566 + f.Close();
1.1567 + }
1.1568 +
1.1569 +#include "../../../userlibandfileserver/fileserver/inc/message.h"
1.1570 +#include <f32plugin.h>
1.1571 +
1.1572 +static void testMiscellaneousReportedBugs()
1.1573 +//
1.1574 +// Test bug reports, real or imaginary
1.1575 +//
1.1576 + {
1.1577 +
1.1578 + test.Next(_L("Miscellaneous tests"));
1.1579 + RFile f1;
1.1580 + TInt temp;
1.1581 + TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite);
1.1582 + test(r==KErrNone);
1.1583 + r=f1.Size(temp);
1.1584 + test(r==KErrNone);
1.1585 + test(temp==0);
1.1586 + TUint data=0;
1.1587 + TPtrC8 buf((TText8*)&data,1);
1.1588 + r=f1.Write(buf);
1.1589 +// r=f1.Write(_L("\0"));
1.1590 + test(r==KErrNone);
1.1591 + r=f1.Size(temp);
1.1592 + test(r==KErrNone);
1.1593 + test(temp==1);
1.1594 + temp=0;
1.1595 + r=f1.Seek(ESeekStart,temp);
1.1596 + test(r==KErrNone);
1.1597 + test(temp==0);
1.1598 + TBuf8<32> testBuf;
1.1599 + r=f1.Read(testBuf);
1.1600 + test(r==KErrNone);
1.1601 + test(testBuf==buf);
1.1602 + f1.Close();
1.1603 +
1.1604 + class RHackFile : public RFile
1.1605 + {
1.1606 + public:
1.1607 + inline TInt SendReceive(TInt aFunction, const TIpcArgs& aArgs) const
1.1608 + { return RSubSessionBase::SendReceive(aFunction, aArgs); }
1.1609 + };
1.1610 +
1.1611 + RHackFile f2;
1.1612 + f2.Open(TheFs, _L("File.File"), EFileRead);
1.1613 + test(r == KErrNone);
1.1614 + r = f2.SendReceive(/*47*/ EFsFileChangeMode, TIpcArgs(EFileRead | EFileWrite)); // <- must fail!
1.1615 + test(r == KErrArgument);
1.1616 + r = f2.Write(_L8("Hacked!")); // <- must fail!
1.1617 + test(r == KErrAccessDenied);
1.1618 + f2.Close();
1.1619 +
1.1620 + r=TheFs.Delete(_L("File.FIle"));
1.1621 + test(r==KErrNone);
1.1622 + }
1.1623 +
1.1624 +static void testFileRename()
1.1625 +//
1.1626 +// Test rename
1.1627 +//
1.1628 + {
1.1629 +
1.1630 + test.Next(_L("Test rename"));
1.1631 + TBuf<64> name1=_L("asdfasdfasdfasfd.qwer");
1.1632 + TBuf<64> name2=_L("File.xyz");
1.1633 + TBuf<64> name3=_L("ASdfasdFasdfasfd.qwer");
1.1634 + TBuf8<64> contents;
1.1635 +
1.1636 + TInt r;
1.1637 + RFile f1;
1.1638 +
1.1639 + //-- test renaming a file to a non-existing directory
1.1640 + r = TheFs.MkDir(_L("\\temp\\"));
1.1641 + test(r==KErrNone || r==KErrAlreadyExists);
1.1642 +
1.1643 + r = f1.Replace(TheFs, _L("\\temp\\file1"), 0);
1.1644 + test(r==KErrNone);
1.1645 +
1.1646 + r = f1.Rename(_L("\\temp\\temp\\file1"));
1.1647 + test(r == KErrPathNotFound);
1.1648 +
1.1649 + f1.Close();
1.1650 +
1.1651 +
1.1652 + r=f1.Replace(TheFs,name2,EFileWrite);
1.1653 + test(r==KErrNone);
1.1654 + r=f1.Write(_L8("1234"));
1.1655 + test(r==KErrNone);
1.1656 + TInt len=CheckFileExists(name2,KErrNone);
1.1657 + test(len==4);
1.1658 + r=f1.Rename(name1);
1.1659 + test(r==KErrNone);
1.1660 +
1.1661 + r=f1.Read(0,contents);
1.1662 + test(r==KErrNone);
1.1663 + test(contents==_L8("1234"));
1.1664 + r=f1.Write(4,_L8("5678"));
1.1665 + test(r==KErrNone);
1.1666 +
1.1667 + len=CheckFileExists(name1,KErrNone);
1.1668 + test(len==8);
1.1669 + CheckFileExists(name2,KErrNotFound);
1.1670 + r=f1.Write(8,_L8("90"));
1.1671 + test(r==KErrNone);
1.1672 + f1.Close();
1.1673 + len=CheckFileExists(name1,KErrNone);
1.1674 + test(len==10);
1.1675 +
1.1676 + test.Next(_L("Test can change case using rename"));
1.1677 + r=f1.Open(TheFs,name1,EFileRead|EFileWrite);
1.1678 + test(r==KErrNone);
1.1679 + r=f1.Rename(name3);
1.1680 + test(r==KErrNone);
1.1681 + CheckFileExists(name1,KErrNone,EFalse);
1.1682 + len=CheckFileExists(name3,KErrNone);
1.1683 + test(len==10);
1.1684 + f1.Close();
1.1685 + CheckFileExists(name1,KErrNone,EFalse);
1.1686 + len=CheckFileExists(name3,KErrNone);
1.1687 + test(len==10);
1.1688 +
1.1689 + test.Next(_L("Test can rename to an identical filename"));
1.1690 + r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
1.1691 + test(r==KErrNone);
1.1692 + r=f1.Rename(name3);
1.1693 + test(r==KErrNone);
1.1694 + len=CheckFileExists(name3,KErrNone);
1.1695 + test(len==10);
1.1696 + f1.Close();
1.1697 + len=CheckFileExists(name3,KErrNone);
1.1698 + test(len==10);
1.1699 +
1.1700 + test.Next(_L("Test rename to a name containing a wildcard is rejected"));
1.1701 + r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
1.1702 + test(r==KErrNone);
1.1703 + r=f1.Rename(_L("asdf*ASDF"));
1.1704 + test(r==KErrBadName);
1.1705 + r=f1.Rename(_L("asdf?AF"));
1.1706 + test(r==KErrBadName);
1.1707 + f1.Close();
1.1708 +
1.1709 + r=f1.Open(TheFs,name3,EFileRead);
1.1710 + test(r==KErrNone);
1.1711 + r=f1.Read(contents);
1.1712 + test(r==KErrNone);
1.1713 + test(contents==_L8("1234567890"));
1.1714 + r=f1.Read(contents);
1.1715 + test(r==KErrNone);
1.1716 + test(contents.Length()==0);
1.1717 + f1.Close();
1.1718 +
1.1719 + test.Next(_L("Check file date is retained"));
1.1720 + TDateTime dateTime(1995,(TMonth)10,19,23,0,0,0);
1.1721 + TTime oldTime(dateTime);
1.1722 + r=TheFs.SetEntry(name3,oldTime,0,0);
1.1723 + test(r==KErrNone);
1.1724 + r=f1.Open(TheFs,name3,EFileRead|EFileWrite);
1.1725 + test(r==KErrNone);
1.1726 + TTime check;
1.1727 + r=f1.Modified(check);
1.1728 + test(r==KErrNone);
1.1729 + test(check==oldTime);
1.1730 +
1.1731 + r=f1.Rename(_L("OldFile.Old"));
1.1732 + test(r==KErrNone);
1.1733 +
1.1734 + r=f1.Modified(check);
1.1735 + test(r==KErrNone);
1.1736 + test(check==oldTime);
1.1737 + r=TheFs.Modified(_L("oldfile.old"),check);
1.1738 + test(r==KErrNone);
1.1739 + test(check==oldTime);
1.1740 + f1.Close();
1.1741 + r=TheFs.Modified(_L("oldfile.old"),check);
1.1742 + test(r==KErrNone);
1.1743 + test(check==oldTime);
1.1744 + }
1.1745 +
1.1746 +static void TestFileUids()
1.1747 +//
1.1748 +// Test uids in files
1.1749 +//
1.1750 + {
1.1751 +
1.1752 + test.Next(_L("Uids in files"));
1.1753 + TUidType uidData(TUid::Uid(1),TUid::Uid(1),TUid::Uid(1));
1.1754 + MakeFile(_L("Tmp04005.$$$"),uidData,_L8("Some other data"));
1.1755 + TUidType uidData1(TUid::Uid(2),TUid::Uid(2),TUid::Uid(2));
1.1756 + MakeFile(_L("Sketch(01)"),uidData1,_L8("A different sketch"));
1.1757 +
1.1758 + TEntry e;
1.1759 + TInt r=TheFs.Entry(_L("Tmp04005.$$$"),e);
1.1760 + test(r==KErrNone);
1.1761 + test(uidData==e.iType);
1.1762 + r=TheFs.Entry(_L("Sketch(01)"),e);
1.1763 + test(r==KErrNone);
1.1764 + test(uidData1==e.iType);
1.1765 +
1.1766 + test.Next(_L("Test replace preserves UIDs"));
1.1767 + r=TheFs.Replace(_L("Tmp04005.$$$"),_L("Sketch(01)"));
1.1768 + test(r==KErrNone);
1.1769 +
1.1770 + r=TheFs.Entry(_L("Tmp04005.$$$"),e);
1.1771 + test(r==KErrNotFound);
1.1772 + r=TheFs.Entry(_L("Sketch(01)"),e);
1.1773 + test(r==KErrNone);
1.1774 + test(uidData==e.iType);
1.1775 + }
1.1776 +
1.1777 +
1.1778 +static void TestMaxLengthFilenames()
1.1779 +//
1.1780 +// Test max length filenames can be created/deleted
1.1781 +//
1.1782 + {
1.1783 +
1.1784 +#if defined(__WINS__)
1.1785 + if (gSessionPath[0]=='C')
1.1786 + return;
1.1787 +#endif
1.1788 +
1.1789 + test.Next(_L("Test max length filenames"));
1.1790 + TFileName bigName;
1.1791 + CreateLongName(bigName,gSeed,255);
1.1792 + bigName[0]='\\';
1.1793 + RFile f;
1.1794 + TInt r=f.Create(TheFs,bigName,EFileRead);
1.1795 + test(r==KErrBadName);
1.1796 + bigName.SetLength(254);
1.1797 + r=f.Create(TheFs,bigName,EFileRead);
1.1798 + test(r==KErrNone);
1.1799 + f.Close();
1.1800 +
1.1801 + TInt count;
1.1802 + TFileName countedBigName=bigName;
1.1803 + // This loop may not reach the '\' character, or we will get a bad path.
1.1804 + for (count=0;count<('Z'-'A');count++)
1.1805 + {
1.1806 + countedBigName[2]=(TText)('A'+count);
1.1807 + r=f.Create(TheFs,countedBigName,EFileRead);
1.1808 + if (r==KErrDirFull)
1.1809 + {
1.1810 + r=TheFs.Delete(countedBigName);
1.1811 + test(r==KErrNotFound);
1.1812 + break;
1.1813 + }
1.1814 + if (r!=KErrNone)
1.1815 + test.Printf(_L("File create failed:%d"),r);
1.1816 + test(r==KErrNone);
1.1817 + f.Close();
1.1818 + }
1.1819 + while(count--)
1.1820 + {
1.1821 + countedBigName[2]=(TText)('A'+count);
1.1822 + r=TheFs.Delete(countedBigName);
1.1823 + test(r==KErrNone);
1.1824 + }
1.1825 +
1.1826 + r=TheFs.Delete(bigName);
1.1827 + test(r==KErrNone);
1.1828 +
1.1829 + TFileName subDirFileName=_L("\\F32-TST\\TFILE");
1.1830 + bigName.SetLength(241);
1.1831 + subDirFileName.Append(bigName);
1.1832 + r=f.Create(TheFs,subDirFileName,EFileRead);
1.1833 + test(r==KErrBadName);
1.1834 + subDirFileName.SetLength(254);
1.1835 + r=f.Create(TheFs,subDirFileName,EFileRead);
1.1836 + test(r==KErrNone);
1.1837 + f.Close();
1.1838 + r=TheFs.Delete(subDirFileName);
1.1839 + test(r==KErrNone);
1.1840 + }
1.1841 +
1.1842 +
1.1843 +
1.1844 +
1.1845 +static void testReadersWriters()
1.1846 +//
1.1847 +// Test EFileShareReadersOrWriters file sharing.
1.1848 +//
1.1849 + {
1.1850 +
1.1851 + test.Start(_L("Test EFileShareReadersOrWriters sharing"));
1.1852 + MakeFile(_L("TESTER"));
1.1853 +
1.1854 + // Open a file in EFileShareReadersOnly mode
1.1855 + RFile f1;
1.1856 + TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.1857 + test(r==KErrNone);
1.1858 +
1.1859 + // Opening a share in EFileShareReadersOnly mode should succeed
1.1860 + RFile f2;
1.1861 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.1862 + test(r==KErrNone);
1.1863 + f2.Close();
1.1864 +
1.1865 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
1.1866 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1867 + test(r==KErrNone);
1.1868 + f2.Close();
1.1869 +
1.1870 + // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
1.1871 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.1872 + test(r==KErrInUse);
1.1873 +
1.1874 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
1.1875 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
1.1876 + test(r==KErrInUse);
1.1877 +
1.1878 + // Opening a share in EShareAny mode should fail
1.1879 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.1880 + test(r==KErrInUse);
1.1881 +
1.1882 + f1.Close();
1.1883 +
1.1884 + //////////////////////
1.1885 +
1.1886 + // Open a file in EFileShareReadersOrWriters mode for reading
1.1887 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1888 + test(r==KErrNone);
1.1889 +
1.1890 + // Opening a share in EFileShareExclusive mode should fail
1.1891 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.1892 + test(r==KErrInUse);
1.1893 +
1.1894 + // Opening a share in EFileShareReadersOnly mode should succeed
1.1895 + // (the share doesn't care if the file is opened for reading or writing)
1.1896 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.1897 + test(r==KErrNone);
1.1898 + f2.Close();
1.1899 +
1.1900 + // Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed
1.1901 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1902 + test(r==KErrNone);
1.1903 + f2.Close();
1.1904 +
1.1905 + // Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should succeed
1.1906 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.1907 + test(r==KErrNone);
1.1908 + f2.Close();
1.1909 +
1.1910 + // Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should succeed
1.1911 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
1.1912 + test(r==KErrNone);
1.1913 + f2.Close();
1.1914 +
1.1915 + // Opening a share in EFileShareAny mode should succeed
1.1916 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.1917 + test(r==KErrNone);
1.1918 + f2.Close();
1.1919 +
1.1920 + f1.Close();
1.1921 +
1.1922 + //////////////////////
1.1923 +
1.1924 + // Open a file in EFileShareReadersOrWriters mode for writing
1.1925 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.1926 + test(r==KErrNone);
1.1927 +
1.1928 + // Opening a share in EFileShareExclusive mode should fail
1.1929 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.1930 + test(r==KErrInUse);
1.1931 +
1.1932 + // Opening a share in EFileShareReadersOnly mode should fail
1.1933 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.1934 + test(r==KErrInUse);
1.1935 +
1.1936 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
1.1937 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1938 + test(r==KErrNone);
1.1939 + f2.Close();
1.1940 +
1.1941 + // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
1.1942 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.1943 + test(r==KErrNone);
1.1944 + f2.Close();
1.1945 +
1.1946 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
1.1947 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
1.1948 + test(r==KErrNone);
1.1949 + f2.Close();
1.1950 +
1.1951 + // Opening a share in EFileShareAny mode should succeed
1.1952 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.1953 + test(r==KErrNone);
1.1954 + f2.Close();
1.1955 +
1.1956 + f1.Close();
1.1957 +
1.1958 + //////////////////////////
1.1959 +
1.1960 + // Open a file in EFileShareAny mode
1.1961 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.1962 + test(r==KErrNone);
1.1963 +
1.1964 + // Opening a share in EFileShareExclusive mode should fail
1.1965 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive);
1.1966 + test(r==KErrInUse);
1.1967 +
1.1968 + // Opening a share in EFileShareReadersOnly mode should fail
1.1969 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.1970 + test(r==KErrInUse);
1.1971 +
1.1972 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed
1.1973 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1974 + test(r==KErrNone);
1.1975 + f2.Close();
1.1976 +
1.1977 + // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed
1.1978 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.1979 + test(r==KErrNone);
1.1980 + f2.Close();
1.1981 +
1.1982 + // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed
1.1983 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
1.1984 + test(r==KErrNone);
1.1985 + f2.Close();
1.1986 +
1.1987 + // Opening a share in EFileShareAny mode with should succeed
1.1988 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.1989 + test(r==KErrNone);
1.1990 + f2.Close();
1.1991 +
1.1992 + f1.Close();
1.1993 +
1.1994 + //////////////////////
1.1995 +
1.1996 + // Open a file in EFileShareReadersOrWriters mode for reading
1.1997 + r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.1998 + test(r==KErrNone);
1.1999 +
1.2000 + // Opening a share in EFileShareReadersOnly mode should succeed
1.2001 + // - The share should now be promoted to EFileShareReadersOnly mode
1.2002 + r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly);
1.2003 + test(r==KErrNone);
1.2004 +
1.2005 + TInt pass = 2;
1.2006 + while(pass--)
1.2007 + {
1.2008 + RFile f3;
1.2009 + // Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed
1.2010 + r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead);
1.2011 + test(r==KErrNone);
1.2012 + f3.Close();
1.2013 +
1.2014 + // Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should fail
1.2015 + r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite);
1.2016 + if(pass == 1)
1.2017 + {
1.2018 + // The share is promoted - should obey EFileShareReadersOnly rules
1.2019 + test(r==KErrInUse);
1.2020 + }
1.2021 + else
1.2022 + {
1.2023 + // The share is demoted - should obey EFileShareReadersOrWriters rules
1.2024 + test(r==KErrNone);
1.2025 + f3.Close();
1.2026 + }
1.2027 +
1.2028 + // Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should fail
1.2029 + r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite);
1.2030 + if(pass == 1)
1.2031 + {
1.2032 + // The share is promoted - should obey EFileShareReadersOnly rules
1.2033 + test(r==KErrInUse);
1.2034 + }
1.2035 + else
1.2036 + {
1.2037 + // The share is demoted - should obey EFileShareReadersOrWriters rules
1.2038 + test(r==KErrNone);
1.2039 + f3.Close();
1.2040 + }
1.2041 +
1.2042 + // Opening a share in EFileShareAny mode should fails
1.2043 + r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny);
1.2044 + if(pass == 1)
1.2045 + {
1.2046 + // The share is promoted - should obey EFileShareReadersOnly rules
1.2047 + test(r==KErrInUse);
1.2048 + f2.Close();
1.2049 + }
1.2050 + else
1.2051 + {
1.2052 + // The share is demoted - should obey EFileShareReadersOrWriters rules
1.2053 + test(r==KErrNone);
1.2054 + f3.Close();
1.2055 + }
1.2056 + }
1.2057 +
1.2058 + f1.Close();
1.2059 +
1.2060 + test.End();
1.2061 + }
1.2062 +
1.2063 +
1.2064 +static void testINC070455()
1.2065 +//
1.2066 +// INC070455 - RFile.ChangeMode() panics
1.2067 +//
1.2068 + {
1.2069 + _LIT(KTestName, "Test INC070455 - RFile.ChangeMode() panics");
1.2070 + test.Start(KTestName);
1.2071 +
1.2072 +
1.2073 + // To reproduce this defect, we need a filename of less than 10 characters.
1.2074 + // We cannot use the directories used by the rest of this test harness.
1.2075 + _LIT(KShortName, "C:\\file.txt");
1.2076 +
1.2077 +
1.2078 + test.Next(_L("Create file..."));
1.2079 + RFile TheFile;
1.2080 + TInt r = TheFile.Create(TheFs, KShortName, EFileWrite);
1.2081 + test((KErrNone == r) || (KErrAlreadyExists == r));
1.2082 + TheFile.Close();
1.2083 +
1.2084 +
1.2085 + test.Next(_L("Re-open the file..."));
1.2086 + r = TheFile.Open(TheFs, KShortName, EFileRead | EFileShareExclusive);
1.2087 + test (KErrNone == r);
1.2088 +
1.2089 +
1.2090 + test.Next(_L("Change the file\'s mode..."));
1.2091 + r = TheFile.ChangeMode(EFileShareReadersOnly);
1.2092 + test (KErrNone == r);
1.2093 + TheFile.Close();
1.2094 +
1.2095 +
1.2096 + test.Next(_L("Tidy up"));
1.2097 + r = TheFs.Delete(KShortName);
1.2098 + test (KErrNone == r);
1.2099 +
1.2100 + test.End();
1.2101 + }
1.2102 +
1.2103 +
1.2104 +LOCAL_D TBuf8<0x80000> gLongBuf;
1.2105 +_LIT(KFileName, "\\zerolengthsourcedescriptortest.txt");
1.2106 +
1.2107 +static void zeroSrcDesc()
1.2108 + {
1.2109 + gLongBuf.Zero();
1.2110 + }
1.2111 +
1.2112 +static void setSrcDescLen()
1.2113 + {
1.2114 + gLongBuf.SetLength(0x80000);
1.2115 + }
1.2116 +
1.2117 +static void createTestFile(RFile& aFile)
1.2118 + {
1.2119 + TInt r = aFile.Create(TheFs, KFileName, EFileWrite);
1.2120 + test((KErrNone == r) || (KErrAlreadyExists == r));
1.2121 + }
1.2122 +
1.2123 +static void removeTestFile(RFile& aFile)
1.2124 + {
1.2125 + aFile.Close();
1.2126 + TInt r = TheFs.Delete(KFileName);
1.2127 + test (KErrNone == r);
1.2128 + }
1.2129 +
1.2130 +#ifdef _DEBUG
1.2131 +static TInt testWritePanic(TAny* aPtr)
1.2132 + {
1.2133 + RFile * ptr = (RFile *)aPtr;
1.2134 + TInt r=ptr->Write(gLongBuf,0x80000);
1.2135 + test (KErrNone == r);
1.2136 + return KErrNone;
1.2137 + }
1.2138 +#endif
1.2139 +static void testNegativeLengthToWrite()
1.2140 +//
1.2141 +// DEF091545 - Tests added to check the write function behaviour with Negative length
1.2142 +{
1.2143 +
1.2144 +test.Start(_L("Test RFile::Write variants with Negative Length parameter"));
1.2145 +
1.2146 + LOCAL_D TBuf8<0x100> gBuf;
1.2147 + RFile TheFile;
1.2148 + TInt r;
1.2149 + TRequestStatus status1(KRequestPending);
1.2150 + TRequestStatus status2(KRequestPending);
1.2151 +
1.2152 +// EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength)
1.2153 + createTestFile(TheFile);
1.2154 +
1.2155 + r=TheFile.Write(gBuf, -1);
1.2156 + test(r==KErrArgument);
1.2157 +
1.2158 + removeTestFile(TheFile);
1.2159 +
1.2160 +// EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus)
1.2161 + createTestFile(TheFile);
1.2162 + TheFile.Write(gBuf,-1, status1);
1.2163 + User::WaitForRequest(status1);
1.2164 + test ( status1.Int() == KErrArgument);
1.2165 +
1.2166 + removeTestFile(TheFile);
1.2167 +
1.2168 +
1.2169 +
1.2170 +// EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength)
1.2171 + createTestFile(TheFile);
1.2172 + r = TheFile.Write(0,gBuf,-1);
1.2173 + test(r==KErrArgument);
1.2174 + removeTestFile(TheFile);
1.2175 +
1.2176 +
1.2177 +// EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus)
1.2178 + createTestFile(TheFile);
1.2179 + TheFile.Write(0, gBuf,-1, status2);
1.2180 + User::WaitForRequest(status2);
1.2181 + test ( status2.Int() == KErrArgument);
1.2182 + removeTestFile(TheFile);
1.2183 +
1.2184 + test.End();
1.2185 +
1.2186 +
1.2187 +
1.2188 +}
1.2189 +
1.2190 +static TInt testLockPanic(TAny* aPtr)
1.2191 + {
1.2192 + TInt aPos=128;
1.2193 + TInt aLen=-1;
1.2194 + RFile * ptr = (RFile *)aPtr;
1.2195 + TInt r=ptr->Lock(aPos, aLen);
1.2196 + test (KErrNone == r);
1.2197 + return KErrNone;
1.2198 + }
1.2199 +
1.2200 +static TInt testUnLockPanic(TAny* aPtr)
1.2201 + {
1.2202 + TInt aPos=128;
1.2203 + TInt aLen=-1;
1.2204 + RFile * ptr = (RFile *)aPtr;
1.2205 + TInt r=ptr->UnLock(aPos, aLen);
1.2206 + test (KErrNone == r);
1.2207 + return KErrNone;
1.2208 + }
1.2209 +
1.2210 +static TInt testSetSizePanic(TAny* aPtr)
1.2211 + {
1.2212 + TInt aSize=-1;
1.2213 + RFile * ptr = (RFile *)aPtr;
1.2214 + TInt r=ptr->SetSize(aSize);
1.2215 + test (KErrNone == r);
1.2216 + return KErrNone;
1.2217 + }
1.2218 +
1.2219 +static void testNegativeLength()
1.2220 + {
1.2221 + test.Start(_L("Test RFile::Lock, RFile::Unlock and RFile::SetSize with Negative Length parameter"));
1.2222 +
1.2223 + test(TheFs.ShareProtected() == KErrNone);
1.2224 +
1.2225 + RFile TheFile;
1.2226 + createTestFile(TheFile);
1.2227 + TRequestStatus status = KRequestPending;
1.2228 +
1.2229 + // launch call on separate thread as expected to panic
1.2230 + // Test Lock with a negative length
1.2231 + User::SetJustInTime(EFalse);
1.2232 + RThread t;
1.2233 + test(t.Create(_L("testLockPanic"), testLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
1.2234 + t.Logon(status);
1.2235 + t.Resume();
1.2236 + User::WaitForRequest(status);
1.2237 + User::SetJustInTime(ETrue);
1.2238 + test(t.ExitType() == EExitPanic);
1.2239 + test(t.ExitReason() == 17);
1.2240 + t.Close();
1.2241 +
1.2242 +
1.2243 + // Test Unlock with a negative length
1.2244 + User::SetJustInTime(EFalse);
1.2245 + status = KRequestPending;
1.2246 + test(t.Create(_L("testUnLockPanic"), testUnLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
1.2247 + t.Logon(status);
1.2248 + t.Resume();
1.2249 + User::WaitForRequest(status);
1.2250 + test(t.ExitType() == EExitPanic);
1.2251 + test(t.ExitReason() == 18);
1.2252 + t.Close();
1.2253 + User::SetJustInTime(ETrue);
1.2254 +
1.2255 + // Test SetSize with a negative length
1.2256 + User::SetJustInTime(EFalse);
1.2257 + status = KRequestPending;
1.2258 + test(t.Create(_L("testSetSizePanic"), testSetSizePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
1.2259 + t.Logon(status);
1.2260 + t.Resume();
1.2261 + User::WaitForRequest(status);
1.2262 + test(t.ExitType() == EExitPanic);
1.2263 + test(t.ExitReason() == 20);
1.2264 + t.Close();
1.2265 + User::SetJustInTime(ETrue);
1.2266 +
1.2267 + removeTestFile(TheFile);
1.2268 + test.End();
1.2269 + }
1.2270 +
1.2271 +static void testZeroLengthDescriptors()
1.2272 +//
1.2273 +// INC088416 - NAND thread crash when doing async writes to internal memory
1.2274 +//
1.2275 +// Test each variant of RFile::Write against zero length source descriptor arguements
1.2276 + {
1.2277 + test.Start(_L("Test RFile::Write variants with Zero Length Source Descriptor"));
1.2278 +
1.2279 + RFile TheFile;
1.2280 + TRequestStatus status(KRequestPending);
1.2281 +
1.2282 +
1.2283 +// EXPORT_C TInt RFile::Write(const TDesC8& aDes) PASS ZERO length descriptor
1.2284 +
1.2285 + createTestFile(TheFile);
1.2286 +
1.2287 + zeroSrcDesc();
1.2288 +
1.2289 + test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes) with zero length aDes"));
1.2290 + TInt r=TheFile.Write(gLongBuf);
1.2291 + test(r==KErrNone);
1.2292 +
1.2293 + test.Printf(_L("Test case passed\n"));
1.2294 +
1.2295 + removeTestFile(TheFile);
1.2296 +
1.2297 +
1.2298 + // EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor
1.2299 +
1.2300 + createTestFile(TheFile);
1.2301 +
1.2302 + status = KRequestPending;
1.2303 + zeroSrcDesc();
1.2304 +
1.2305 + test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) with zero length sDes"));
1.2306 + TheFile.Write(gLongBuf,status);
1.2307 + User::WaitForRequest(status);
1.2308 + test(status.Int()==KErrNone);
1.2309 +
1.2310 + test.Printf(_L("Test case passed\n"));
1.2311 +
1.2312 + removeTestFile(TheFile);
1.2313 +
1.2314 +
1.2315 + // EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
1.2316 +
1.2317 + createTestFile(TheFile);
1.2318 +
1.2319 + status = KRequestPending;
1.2320 + setSrcDescLen();
1.2321 +
1.2322 + test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus)"));
1.2323 + TheFile.Write(gLongBuf,status);
1.2324 + test.Printf(_L("Zero source descriptor during async write\n"));
1.2325 + zeroSrcDesc();
1.2326 + User::WaitForRequest(status);
1.2327 + test(status.Int()==KErrNone);
1.2328 +
1.2329 + test.Printf(_L("Test case passed\n"));
1.2330 +
1.2331 + removeTestFile(TheFile);
1.2332 +
1.2333 +
1.2334 + // EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor
1.2335 +
1.2336 + createTestFile(TheFile);
1.2337 +
1.2338 + status = KRequestPending;
1.2339 + zeroSrcDesc();
1.2340 +
1.2341 + test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes,TInt aLength) with zero length aDes"));
1.2342 +#ifdef _DEBUG
1.2343 + // launch call on separate thread as expected to panic
1.2344 + User::SetJustInTime(EFalse);
1.2345 + status = KRequestPending;
1.2346 + RThread t;
1.2347 + test(t.Create(_L("testWritePanic"), testWritePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone);
1.2348 + t.Logon(status);
1.2349 + t.Resume();
1.2350 + User::WaitForRequest(status);
1.2351 + test(t.ExitType() == EExitPanic);
1.2352 + test(t.ExitReason() == 27);
1.2353 + t.Close();
1.2354 + User::SetJustInTime(ETrue);
1.2355 +#else
1.2356 +
1.2357 + r=TheFile.Write(gLongBuf, 0x80000);
1.2358 + test(r==KErrNone);
1.2359 +#endif
1.2360 +
1.2361 + test.Printf(_L("Test case passed\n"));
1.2362 +
1.2363 + removeTestFile(TheFile);
1.2364 +
1.2365 +
1.2366 + // EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor
1.2367 +
1.2368 + createTestFile(TheFile);
1.2369 +
1.2370 + status = KRequestPending;
1.2371 + zeroSrcDesc();
1.2372 +
1.2373 + test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, TInt aLength,TRequestStatus& aStatus) with zero length sDes"));
1.2374 + TheFile.Write(gLongBuf, 0x80000, status); ;
1.2375 + User::WaitForRequest(status);
1.2376 + test(status.Int()==KErrNone);
1.2377 +
1.2378 + test.Printf(_L("Test case passed\n"));
1.2379 +
1.2380 + removeTestFile(TheFile);
1.2381 +
1.2382 +
1.2383 + // EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
1.2384 +
1.2385 + createTestFile(TheFile);
1.2386 +
1.2387 + status = KRequestPending;
1.2388 + setSrcDescLen();
1.2389 +
1.2390 + test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, Int aLength,TRequestStatus& aStatus)"));
1.2391 + TheFile.Write(gLongBuf,0x80000, status);
1.2392 + test.Printf(_L("Zero source descriptor during async write\n"));
1.2393 + zeroSrcDesc();
1.2394 + User::WaitForRequest(status);
1.2395 + test(status.Int()==KErrNone);
1.2396 +
1.2397 + test.Printf(_L("Test case passed\n"));
1.2398 +
1.2399 + removeTestFile(TheFile);
1.2400 +
1.2401 +
1.2402 + // EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes) PASS ZERO length descriptor
1.2403 +
1.2404 + createTestFile(TheFile);
1.2405 +
1.2406 + zeroSrcDesc();
1.2407 +
1.2408 + test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes) with zero length aDes"));
1.2409 + r=TheFile.Write(0, gLongBuf);
1.2410 + test(r==KErrNone);
1.2411 +
1.2412 + test.Printf(_L("Test case passed\n"));
1.2413 +
1.2414 + removeTestFile(TheFile);
1.2415 +
1.2416 +
1.2417 + // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor
1.2418 +
1.2419 + createTestFile(TheFile);
1.2420 +
1.2421 + status = KRequestPending;
1.2422 + zeroSrcDesc();
1.2423 +
1.2424 + test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus) with zero length sDes"));
1.2425 + TheFile.Write(0, gLongBuf, status);
1.2426 + User::WaitForRequest(status);
1.2427 + test(status.Int()==KErrNone);
1.2428 +
1.2429 + test.Printf(_L("Test case passed\n"));
1.2430 +
1.2431 + removeTestFile(TheFile);
1.2432 +
1.2433 +
1.2434 + // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
1.2435 +
1.2436 + createTestFile(TheFile);
1.2437 +
1.2438 + status = KRequestPending;
1.2439 + setSrcDescLen();
1.2440 +
1.2441 + test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus)"));
1.2442 + TheFile.Write(0, gLongBuf, status);
1.2443 + test.Printf(_L("Zero source descriptor during async write\n"));
1.2444 + zeroSrcDesc();
1.2445 + User::WaitForRequest(status);
1.2446 + test(status.Int()==KErrNone);
1.2447 +
1.2448 + test.Printf(_L("Test case passed\n"));
1.2449 +
1.2450 + removeTestFile(TheFile);
1.2451 +
1.2452 +
1.2453 + // EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor
1.2454 +
1.2455 + createTestFile(TheFile);
1.2456 +
1.2457 + zeroSrcDesc();
1.2458 +
1.2459 + test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength) with zero length aDes"));
1.2460 + r=TheFile.Write(0, gLongBuf, 0x80000);
1.2461 + test(r==KErrNone);
1.2462 +
1.2463 + test.Printf(_L("Test case passed\n"));
1.2464 +
1.2465 + removeTestFile(TheFile);
1.2466 +
1.2467 +
1.2468 + // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor
1.2469 +
1.2470 + createTestFile(TheFile);
1.2471 +
1.2472 + status = KRequestPending;
1.2473 + zeroSrcDesc();
1.2474 +
1.2475 + test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) with zero length sDes"));
1.2476 + TheFile.Write(0, gLongBuf, 0x80000, status);
1.2477 + User::WaitForRequest(status);
1.2478 + test(status.Int()==KErrNone);
1.2479 +
1.2480 + test.Printf(_L("Test case passed\n"));
1.2481 +
1.2482 + removeTestFile(TheFile);
1.2483 +
1.2484 +
1.2485 + // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write
1.2486 +
1.2487 + createTestFile(TheFile);
1.2488 +
1.2489 + status = KRequestPending;
1.2490 + setSrcDescLen();
1.2491 +
1.2492 + test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus"));
1.2493 + TheFile.Write(0, gLongBuf, 0x80000, status);
1.2494 + test.Printf(_L("Zero source descriptor during async write\n"));
1.2495 + zeroSrcDesc();
1.2496 + User::WaitForRequest(status);
1.2497 + test(status.Int()==KErrNone);
1.2498 +
1.2499 + test.Printf(_L("Test case passed\n"));
1.2500 +
1.2501 + removeTestFile(TheFile);
1.2502 +
1.2503 +
1.2504 + test.End();
1.2505 + }
1.2506 +
1.2507 +static void testReadBufferOverflow()
1.2508 +//
1.2509 +// Test each variant of RFile::Read when the specified extent to read is
1.2510 +// greater than the available buffer space
1.2511 +//
1.2512 + {
1.2513 + test.Start(_L("Test RFile::Read for oversized requests"));
1.2514 +
1.2515 + RFile file;
1.2516 + TInt r = file.Create(TheFs, KFileName, EFileRead);
1.2517 + test((KErrNone == r) || (KErrAlreadyExists == r));
1.2518 +
1.2519 + TInt err = KErrNone;
1.2520 + TRequestStatus status(KRequestPending);
1.2521 + TBuf8<2> buf8;
1.2522 +
1.2523 +// EXPORT_C TInt RFile::Read(TDes8& aDes,TInt aLength) const
1.2524 + err = file.Read(buf8,5);
1.2525 + test(err==KErrOverflow);
1.2526 + err = KErrNone;
1.2527 +
1.2528 +// EXPORT_C void RFile::Read(TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const
1.2529 + file.Read(buf8,5,status);
1.2530 + test(status.Int()==KErrOverflow);
1.2531 + status = KRequestPending;
1.2532 +
1.2533 +// EXPORT_C TInt RFile::Read(TInt aPos,TDes8& aDes,TInt aLength) const
1.2534 + err = file.Read(0,buf8,5);
1.2535 + test(err==KErrOverflow);
1.2536 +
1.2537 +// EXPORT_C void RFile::Read(TInt aPos,TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const
1.2538 + file.Read(0,buf8,5,status);
1.2539 + test(status.Int()==KErrOverflow);
1.2540 +
1.2541 + removeTestFile(file);
1.2542 + test.End();
1.2543 + }
1.2544 +
1.2545 +RSemaphore gSleepThread;
1.2546 +TFileName gLastTempFileName;
1.2547 +enum TTestDoCMode
1.2548 + {
1.2549 + EDoCPanic=1,
1.2550 + EDoCDeleteOnClose=2
1.2551 + };
1.2552 +
1.2553 +static TInt DeleteOnCloseClientThread(TAny* aMode)
1.2554 + {
1.2555 + TTestDoCMode testMode = *(TTestDoCMode*)&aMode;
1.2556 + TUint fileMode=EFileRead;
1.2557 + RFs fs;
1.2558 + RFile file;
1.2559 +
1.2560 + TInt r=fs.Connect();
1.2561 + test(r==KErrNone);
1.2562 + r=fs.SetSessionPath(gSessionPath);
1.2563 + test(r==KErrNone);
1.2564 + if (testMode & EDoCDeleteOnClose)
1.2565 + fileMode|=EDeleteOnClose;
1.2566 + r=file.Temp(fs,_L(""),gLastTempFileName,fileMode);
1.2567 + test(r==KErrNone);
1.2568 + // Signal controlling thread and pause for panic where requested
1.2569 + // by caller.
1.2570 + if (testMode & EDoCPanic)
1.2571 + {
1.2572 + gSleepThread.Signal();
1.2573 + User::After(10000000);
1.2574 + }
1.2575 + file.Close();
1.2576 + if (!(testMode & EDoCPanic))
1.2577 + gSleepThread.Signal();
1.2578 + fs.Close();
1.2579 + return KErrNone;
1.2580 + }
1.2581 +
1.2582 +static void TestDeleteOnClose()
1.2583 +//
1.2584 +// Test RFile::Temp delete on close behaviour
1.2585 +//
1.2586 + {
1.2587 + test.Start(_L("RFile::Temp default file close behaviour"));
1.2588 +
1.2589 + gSleepThread.CreateLocal(0);
1.2590 + RThread clientThread;
1.2591 + RFile file;
1.2592 + RFile file2;
1.2593 + TFileName filename =_L("DoCFile.tst");
1.2594 + TInt r;
1.2595 +
1.2596 +//
1.2597 +//---------------------------------------------------------------------------------------------------------------------
1.2598 +//! @SYMTestCaseID PBASE-t_file-0804
1.2599 +//! @SYMTestType UT
1.2600 +//! @SYMTestCaseDesc Verifying the original behaviour of RFile::Temp()
1.2601 +//! @SYMPREQ CR1266
1.2602 +//! @SYMTestPriority High
1.2603 +//! @SYMTestActions
1.2604 +//! 1. Test thread creates a file with DeleteOnClose flag unset and
1.2605 +//! exits normally.
1.2606 +//! The main test body attempts to delete the resulting temporary
1.2607 +//! file.
1.2608 +//!
1.2609 +//! @SYMTestExpectedResults
1.2610 +//! 1. The temporary file is successfully created and deleted.
1.2611 +//---------------------------------------------------------------------------------------------------------------------
1.2612 + r=clientThread.Create(_L("DeleteOnCloseClientThread 1"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)0);
1.2613 + test(r==KErrNone);
1.2614 + clientThread.Resume();
1.2615 + gSleepThread.Wait();
1.2616 + r=TheFs.Delete(gLastTempFileName);
1.2617 + test(r==KErrNone);
1.2618 + clientThread.Close();
1.2619 +
1.2620 +//
1.2621 +//---------------------------------------------------------------------------------------------------------------------
1.2622 +//! @SYMTestCaseID PBASE-t_file-0805
1.2623 +//! @SYMTestType UT
1.2624 +//! @SYMTestCaseDesc Verifying the Delete on Close behaviour of RFile::Temp()
1.2625 +//! @SYMPREQ CR1266
1.2626 +//! @SYMTestPriority High
1.2627 +//! @SYMTestActions
1.2628 +//! 1. Test thread creates a file with DeleteOnClose flag set and
1.2629 +//! exits normally.
1.2630 +//! The main test body attempts to delete the resulting temporary
1.2631 +//! file.
1.2632 +//!
1.2633 +//! @SYMTestExpectedResults
1.2634 +//! 1. The temporary file is successfully created and automatically
1.2635 +//! deleted upon close. The subsequent attempted file deletion
1.2636 +//! by the main test body should fail with KErrNotFound.
1.2637 +//---------------------------------------------------------------------------------------------------------------------
1.2638 + test.Next(_L("RFile::Temp EDeleteOnClose behaviour"));
1.2639 + r=clientThread.Create(_L("DeleteOnCloseClientThread 2"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCDeleteOnClose);
1.2640 + test(r==KErrNone);
1.2641 + clientThread.Resume();
1.2642 + gSleepThread.Wait();
1.2643 + r=TheFs.Delete(gLastTempFileName);
1.2644 + test(r==KErrNotFound);
1.2645 + clientThread.Close();
1.2646 +
1.2647 +//
1.2648 +//---------------------------------------------------------------------------------------------------------------------
1.2649 +//! @SYMTestCaseID PBASE-t_file-0806
1.2650 +//! @SYMTestType UT
1.2651 +//! @SYMTestCaseDesc Verifying the original, panic behaviour of RFile::Temp()
1.2652 +//! @SYMPREQ CR1266
1.2653 +//! @SYMTestPriority High
1.2654 +//! @SYMTestActions
1.2655 +//! 1. Test thread creates a file with DeleteOnClose flag unset and
1.2656 +//! is paniced by the main test body.
1.2657 +//! The main test body attempts to delete the resulting temporary
1.2658 +//! file.
1.2659 +//!
1.2660 +//! @SYMTestExpectedResults
1.2661 +//! 1. The temporary file is successfully created and deleted.
1.2662 +//---------------------------------------------------------------------------------------------------------------------
1.2663 + test.Next(_L("RFile::Temp default panic behaviour"));
1.2664 + r=clientThread.Create(_L("DeleteOnCloseClientThread 3"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCPanic);
1.2665 + test(r==KErrNone);
1.2666 + clientThread.Resume();
1.2667 + gSleepThread.Wait();
1.2668 + User::SetJustInTime(EFalse);
1.2669 + clientThread.Panic(_L("Panic temp file thread #3"),KErrGeneral);
1.2670 + User::SetJustInTime(ETrue);
1.2671 + CLOSE_AND_WAIT(clientThread);
1.2672 + FsBarrier();
1.2673 + r=TheFs.Delete(gLastTempFileName);
1.2674 + test(r==KErrNone);
1.2675 +
1.2676 +//
1.2677 +//---------------------------------------------------------------------------------------------------------------------
1.2678 +//! @SYMTestCaseID PBASE-t_file-0807
1.2679 +//! @SYMTestType UT
1.2680 +//! @SYMTestCaseDesc Verifying the Delete on Close, panic behaviour of RFile::Temp()
1.2681 +//! @SYMPREQ CR1266
1.2682 +//! @SYMTestPriority High
1.2683 +//! @SYMTestActions
1.2684 +//! 1. Test thread creates a file with DeleteOnClose flag set and
1.2685 +//! is paniced by the main test body.
1.2686 +//! The main test body attempts to delete the resulting temporary
1.2687 +//! file.
1.2688 +//!
1.2689 +//! @SYMTestExpectedResults
1.2690 +//! 1. The temporary file is successfully created and automatically
1.2691 +//! deleted upon close. The subsequent attempted file deletion
1.2692 +//! by the main test body should fail with KErrNotFound.
1.2693 +//---------------------------------------------------------------------------------------------------------------------
1.2694 + test.Next(_L("RFile::Temp EDeleteOnClose panic behaviour"));
1.2695 + r=clientThread.Create(_L("DeleteOnCloseClientThread 4"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)(EDoCPanic|EDoCDeleteOnClose));
1.2696 + test(r==KErrNone);
1.2697 + clientThread.Resume();
1.2698 + gSleepThread.Wait();
1.2699 + User::SetJustInTime(EFalse);
1.2700 + clientThread.Panic(_L("Panic temp file thread #4"),KErrGeneral);
1.2701 + User::SetJustInTime(ETrue);
1.2702 + CLOSE_AND_WAIT(clientThread);
1.2703 + FsBarrier();
1.2704 + r=TheFs.Delete(gLastTempFileName);
1.2705 + test(r==KErrNotFound);
1.2706 +
1.2707 +//
1.2708 +//---------------------------------------------------------------------------------------------------------------------
1.2709 +//! @SYMTestCaseID PBASE-t_file-0808
1.2710 +//! @SYMTestType UT
1.2711 +//! @SYMTestCaseDesc Verifying RFile::Create() supports Delete On Close.
1.2712 +//! @SYMPREQ CR1266
1.2713 +//! @SYMTestPriority High
1.2714 +//! @SYMTestActions
1.2715 +//! 1. Test creates a file with DeleteOnClose flag set and
1.2716 +//! then closes the file.
1.2717 +//! 2. Test attempts to delete the file.
1.2718 +//!
1.2719 +//! @SYMTestExpectedResults
1.2720 +//! 1. The file creation should succeed.
1.2721 +//! 2. The file deletion should fail with KErrNotFound.
1.2722 +//---------------------------------------------------------------------------------------------------------------------
1.2723 + test.Next(_L("RFile::Create EDeleteOnClose behaviour"));
1.2724 + r=file.Create(TheFs,_L("DoC5"),EFileRead|EFileWrite|EDeleteOnClose);
1.2725 + test(r==KErrNone);
1.2726 + file.Close();
1.2727 + r=TheFs.Delete(filename);
1.2728 + test(r==KErrNotFound);
1.2729 +
1.2730 +//
1.2731 +//---------------------------------------------------------------------------------------------------------------------
1.2732 +//! @SYMTestCaseID PBASE-t_file-0809
1.2733 +//! @SYMTestType UT
1.2734 +//! @SYMTestCaseDesc Verifying Delete On Close with multiple subsessions.
1.2735 +//! @SYMPREQ CR1266
1.2736 +//! @SYMTestPriority High
1.2737 +//! @SYMTestActions
1.2738 +//! 1. Test creates a file with DeleteOnClose and FileShareAny flags
1.2739 +//! set, opens the file a second time with the FileShareAny flag set
1.2740 +//! and then closes the first file handle.
1.2741 +//! 2. Test attempts to delete the file.
1.2742 +//! 3. The second file handle is closed and the test attempts to delete
1.2743 +//! the file.
1.2744 +//!
1.2745 +//! @SYMTestExpectedResults
1.2746 +//! 1. The file create and file open should succeed.
1.2747 +//! 2. The file deletion should fail with KErrInUse.
1.2748 +//! 3. The file deletion should fail with KErrNotFound.
1.2749 +//---------------------------------------------------------------------------------------------------------------------
1.2750 + test.Next(_L("DoC 6 - Multiple subsessions"));
1.2751 + r=file.Create(TheFs,filename,EFileShareAny|EFileRead|EFileWrite|EDeleteOnClose);
1.2752 + test(r==KErrNone);
1.2753 + r=file2.Open(TheFs,filename,EFileShareAny|EFileRead|EFileWrite);
1.2754 + test(r==KErrNone);
1.2755 + file.Close();
1.2756 + test(r==KErrNone);
1.2757 + r=TheFs.Delete(filename);
1.2758 + test(r==KErrInUse);
1.2759 + file2.Close();
1.2760 + r=TheFs.Delete(filename);
1.2761 + test(r==KErrNotFound);
1.2762 +
1.2763 +//
1.2764 +//---------------------------------------------------------------------------------------------------------------------
1.2765 +//! @SYMTestCaseID PBASE-t_file-0810
1.2766 +//! @SYMTestType UT
1.2767 +//! @SYMTestCaseDesc Verifying Delete On Close with preexisting file.
1.2768 +//! @SYMPREQ CR1266
1.2769 +//! @SYMTestPriority High
1.2770 +//! @SYMTestActions
1.2771 +//! 1. Test creates and closes a file, then attempts to create the same
1.2772 +//! file with Delete on Close set.
1.2773 +//!
1.2774 +//! @SYMTestExpectedResults
1.2775 +//! 1. The second create should fail with KErrAlreadyExists.
1.2776 +//---------------------------------------------------------------------------------------------------------------------
1.2777 + test.Next(_L("RFile::Create existing file behaviour"));
1.2778 + r=file.Create(TheFs,filename,EFileRead|EFileWrite);
1.2779 + test(r==KErrNone);
1.2780 + file.Close();
1.2781 + r=file.Create(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose);
1.2782 + test(r==KErrAlreadyExists);
1.2783 +
1.2784 +//
1.2785 +//---------------------------------------------------------------------------------------------------------------------
1.2786 +//! @SYMTestCaseID PBASE-t_file-0811
1.2787 +//! @SYMTestType UT
1.2788 +//! @SYMTestCaseDesc Verifying existing file cannot be opened with delete on close set.
1.2789 +//! @SYMPREQ CR1266
1.2790 +//! @SYMTestPriority High
1.2791 +//! @SYMTestActions
1.2792 +//! 1. Test attempts to open an existing file with delete on close set.
1.2793 +//!
1.2794 +//! @SYMTestExpectedResults
1.2795 +//! 1. The open should fail with KErrArgument.
1.2796 +//---------------------------------------------------------------------------------------------------------------------
1.2797 + test.Next(_L("RFile::Open EDeleteOnClose flag validation"));
1.2798 + r=file.Open(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose);
1.2799 + test(r==KErrArgument);
1.2800 + r=TheFs.Delete(filename);
1.2801 + test(r==KErrNone);
1.2802 +
1.2803 + gSleepThread.Close();
1.2804 + test.End();
1.2805 + }
1.2806 +
1.2807 +//--------------------------------------------------------------
1.2808 +/**
1.2809 + Test that flushing dirty file cache does not affect file attributes and time.
1.2810 + This test shall pass disregarding if there is file cache or not.
1.2811 +
1.2812 +*/
1.2813 +void TestFileAttributesAndCacheFlushing()
1.2814 +{
1.2815 + test.Next(_L("Test that file cache flushing does not affect the file attributes."));
1.2816 + if(Is_Win32(TheFs, gDriveNum))
1.2817 + {
1.2818 + test.Printf(_L("This test doesn't work on Win32 FS, skipping!\n"));
1.2819 + return;
1.2820 + }
1.2821 +
1.2822 + _LIT(KFile, "\\file1");
1.2823 +
1.2824 + TInt nRes;
1.2825 + TEntry entry;
1.2826 + TheFs.Delete(KFile);
1.2827 +
1.2828 + //-- 1. create test file
1.2829 + nRes = CreateEmptyFile(TheFs, KFile, 33);
1.2830 + test(nRes == KErrNone);
1.2831 +
1.2832 + //-- 2. open it for write
1.2833 + RFile file;
1.2834 + nRes = file.Open(TheFs, KFile, EFileWrite);
1.2835 + test(nRes == KErrNone);
1.2836 +
1.2837 + //-- 3. write a couple of bytes there. This must cause 'Archive' attribute set
1.2838 + nRes = file.Write(0, _L8("a"));
1.2839 + test(nRes == KErrNone);
1.2840 + nRes = file.Write(10, _L8("b"));
1.2841 + test(nRes == KErrNone);
1.2842 +
1.2843 + nRes = TheFs.Entry(KFile, entry);
1.2844 + test(nRes == KErrNone);
1.2845 +
1.2846 + test(entry.IsArchive()); //-- 'A' attribute must be set.
1.2847 +
1.2848 + //-- the file cache (if present) is dirty now. Dirty data timer starts to tick.
1.2849 + //-- 4. set new file attributes (w/o 'A') and creation time
1.2850 + const TUint newAtt = KEntryAttSystem ;
1.2851 + nRes = file.SetAtt(newAtt, ~newAtt & KEntryAttMaskSupported);
1.2852 + test(nRes == KErrNone);
1.2853 +
1.2854 + TTime newTime;
1.2855 + nRes = newTime.Set(_L("19970310:101809.000000"));
1.2856 + test(nRes == KErrNone);
1.2857 + nRes = file.SetModified(newTime);
1.2858 + test(nRes == KErrNone);
1.2859 +
1.2860 + //-- 5. wait 5 seconds. file server shall flush dirty data during this period.
1.2861 + User::After(5*K1Sec);
1.2862 +
1.2863 + //-- 6. check that attributes haven't chanded because of flush
1.2864 + nRes = file.Flush(); //-- this will flush attributes to the media
1.2865 + test(nRes == KErrNone);
1.2866 +
1.2867 + nRes = TheFs.Entry(KFile, entry);
1.2868 + test(nRes == KErrNone);
1.2869 +
1.2870 + test(entry.iAtt == newAtt);
1.2871 + test(entry.iModified.DateTime().Year() == 1997);
1.2872 + test(entry.iModified.DateTime().Month() == 3);
1.2873 + test(entry.iModified.DateTime().Day() == 10);
1.2874 +
1.2875 + //-- 7. write some data and ensure that 'A' attribute is set now and 'modified' time updated
1.2876 + nRes = file.Write(12, _L8("c"));
1.2877 + test(nRes == KErrNone);
1.2878 +
1.2879 + file.Close(); //-- this will flush attributes to the media
1.2880 +
1.2881 + nRes = TheFs.Entry(KFile, entry);
1.2882 + test(nRes == KErrNone);
1.2883 + test(entry.iAtt == (newAtt | KEntryAttArchive));
1.2884 + test(entry.iModified.DateTime().Year() != 1997);
1.2885 +
1.2886 +
1.2887 +
1.2888 +}
1.2889 +
1.2890 +/**
1.2891 + Testing access to the very last bytes in the maximal (for FAT32) file size.
1.2892 + This test must pass regardless of write caching configuration.
1.2893 +*/
1.2894 +void TestMaxFileSize()
1.2895 +{
1.2896 + test.Next(_L("test maximal file size on FAT32\n"));
1.2897 +
1.2898 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.2899 +
1.2900 + if(!Is_Fat32(TheFs, gDriveNum))
1.2901 + {
1.2902 + test.Printf(_L("This test requires FAT32! skipping.\n"));
1.2903 + return;
1.2904 + }
1.2905 +
1.2906 + TInt nRes;
1.2907 +
1.2908 + //-- check disk space, it shall be > 4G
1.2909 + TVolumeInfo volInfo;
1.2910 + nRes = TheFs.Volume(volInfo, gDriveNum);
1.2911 + test(nRes == KErrNone);
1.2912 +
1.2913 + const TUint32 KMaxFAT32FileSize = 0xFFFFFFFF; // 4GB-1
1.2914 +
1.2915 + if(volInfo.iFree <= KMaxFAT32FileSize)
1.2916 + {
1.2917 + test.Printf(_L("Not enough space for 4GB file! skipping.\n"));
1.2918 + return;
1.2919 + }
1.2920 +
1.2921 + _LIT(KFileName, "\\huge_file");
1.2922 + TBuf8<10> buf(10);
1.2923 + RFile64 file64;
1.2924 +
1.2925 + //-- 1. create 4GB-1 file
1.2926 + //-- this file has enabled write caching by default
1.2927 + test.Printf(_L("creating maximal length file, size = 0x%x\n"),KMaxFAT32FileSize);
1.2928 + nRes = file64.Replace(TheFs, KFileName, EFileWrite);
1.2929 + test(nRes == KErrNone);
1.2930 +
1.2931 + const TInt64 fileSize = KMaxFAT32FileSize;
1.2932 +
1.2933 + nRes = file64.SetSize(fileSize);
1.2934 + test(nRes == KErrNone);
1.2935 +
1.2936 + test.Printf(_L("seeking to the file end...\n"));
1.2937 + TInt64 filePos = 0;
1.2938 + nRes = file64.Seek(ESeekEnd, filePos);
1.2939 + test(nRes == KErrNone);
1.2940 +
1.2941 +
1.2942 + test.Printf(_L("test writing to the last bytes of the file (rel pos addressing) \n"));
1.2943 +
1.2944 + //-- 1. writing using relative position
1.2945 + filePos = -1;
1.2946 + nRes = file64.Seek(ESeekEnd, filePos);
1.2947 + test(nRes == KErrNone);
1.2948 + test(filePos == fileSize-1);
1.2949 +
1.2950 + nRes = file64.Write(_L8("z")); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
1.2951 + test(nRes == KErrNone);
1.2952 +
1.2953 + nRes = file64.Write(_L8("x")); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
1.2954 + test(nRes == KErrNotSupported);
1.2955 +
1.2956 + nRes = file64.Flush();
1.2957 + test(nRes == KErrNone);
1.2958 +
1.2959 + //-- 1.1 check the result by reading data using rel. pos
1.2960 + filePos = -1;
1.2961 + nRes = file64.Seek(ESeekEnd, filePos);
1.2962 + test(nRes == KErrNone);
1.2963 + test(filePos == fileSize-1);
1.2964 +
1.2965 + test.Printf(_L("reading 1 byte at pos: 0x%x\n"), filePos);
1.2966 + nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
1.2967 + test(nRes == KErrNone);
1.2968 + test(buf.Length() == 1 && buf[0]=='z');
1.2969 +
1.2970 + nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
1.2971 + test(nRes == KErrNone);
1.2972 + test(buf.Length() == 0);
1.2973 +
1.2974 + file64.Close();
1.2975 +
1.2976 + test.Printf(_L("test writing to the last bytes of the file (absolute pos addressing) \n"));
1.2977 + //-- 2. writing using absolute position
1.2978 + nRes = file64.Open(TheFs, KFileName, EFileWrite);
1.2979 + test(nRes == KErrNone);
1.2980 +
1.2981 + filePos = fileSize-1;
1.2982 +
1.2983 + nRes = file64.Write(filePos-2, _L8("0"), 1); //-- write 1 byte a pos 0xFFFFFFFC
1.2984 + test(nRes == KErrNone);
1.2985 +
1.2986 + nRes = file64.Write(filePos, _L8("a"), 1); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
1.2987 + test(nRes == KErrNone);
1.2988 +
1.2989 + nRes = file64.Write(filePos+1, _L8("b"), 1); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail
1.2990 + test(nRes == KErrNotSupported);
1.2991 +
1.2992 + nRes = file64.Flush();
1.2993 + test(nRes == KErrNone);
1.2994 +
1.2995 + //-- 1.1 check the result by reading data absolute rel. position
1.2996 +
1.2997 + nRes = file64.Read(filePos-2, buf, 1); //-- read 1 byte a pos 0xFFFFFFFD
1.2998 + test(nRes == KErrNone);
1.2999 + test(buf.Length() == 1 && buf[0]=='0');
1.3000 +
1.3001 + nRes = file64.Read(filePos, buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file
1.3002 + test(nRes == KErrNone);
1.3003 + test(buf.Length() == 1 && buf[0]=='a');
1.3004 +
1.3005 + nRes = file64.Read(filePos+1, buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size
1.3006 + test(nRes == KErrNone);
1.3007 + test(buf.Length() == 0);
1.3008 +
1.3009 + nRes = file64.Read(filePos+2, buf, 1); //buf.Len must be 0
1.3010 + test(nRes == KErrNone);
1.3011 + test(buf.Length() == 0);
1.3012 +
1.3013 + file64.Close();
1.3014 +
1.3015 + test.Printf(_L("deleting the huge file.\n"));
1.3016 + nRes = TheFs.Delete(KFileName);
1.3017 + test(nRes == KErrNone);
1.3018 +
1.3019 +#else
1.3020 +
1.3021 + test.Printf(_L("RFile64 is not supported! Skipping.\n"));
1.3022 +
1.3023 +#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.3024 +
1.3025 +}
1.3026 +
1.3027 +
1.3028 +//--------------------------------------------------------------
1.3029 +
1.3030 +void CallTestsL()
1.3031 + {
1.3032 +
1.3033 + //-- set up console output
1.3034 + F32_Test_Utils::SetConsole(test.Console());
1.3035 +
1.3036 + TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum);
1.3037 + test(nRes==KErrNone);
1.3038 +
1.3039 + PrintDrvInfo(TheFs, gDriveNum);
1.3040 +
1.3041 + //-- FAT Supports short file names
1.3042 + if(Is_Fat(TheFs, gDriveNum))
1.3043 + gShortFileNamesSupported = ETrue;
1.3044 +
1.3045 + if(Is_Win32(TheFs, gDriveNum))
1.3046 + {//-- find out if this is NTFS and if it supports short names (this feature can be switched OFF)
1.3047 +
1.3048 + _LIT(KLongFN, "\\this is a long file name");
1.3049 + nRes = CreateEmptyFile(TheFs, KLongFN, 10);
1.3050 + test(nRes==KErrNone);
1.3051 +
1.3052 + TBuf<12> shortName;
1.3053 + nRes = TheFs.GetShortName(KLongFN, shortName);
1.3054 + gShortFileNamesSupported = (nRes == KErrNone);
1.3055 +
1.3056 + nRes = TheFs.Delete(KLongFN);
1.3057 + test(nRes==KErrNone);
1.3058 +
1.3059 + DeleteTestDirectory();
1.3060 + }
1.3061 + else
1.3062 + {
1.3063 + nRes = FormatDrive(TheFs, gDriveNum, ETrue);
1.3064 + test(nRes==KErrNone);
1.3065 + }
1.3066 +
1.3067 + CreateTestDirectory(_L("\\F32-TST\\TFILE\\"));
1.3068 +
1.3069 + testFileRename();
1.3070 + testSetSize();
1.3071 + CopyFileToTestDirectory();
1.3072 + testFileSeek();
1.3073 + testMoreFileSeek();
1.3074 + CopyFileToTestDirectory();
1.3075 + testFileText();
1.3076 + testFileTextEndRecord();
1.3077 + testDeleteOpenFiles();
1.3078 + testFileAttributes();
1.3079 + testFileNames();
1.3080 + testShare();
1.3081 + testReadersWriters();
1.3082 + testReadFile();
1.3083 + testMultipleReadFile();
1.3084 + testWriteFile();
1.3085 + testChangeMode();
1.3086 + testShortNameAccessorFunctions();
1.3087 + testIsFileOpen();
1.3088 + testMiscellaneousReportedBugs();
1.3089 + testIsRomAddress();
1.3090 + TestFileUids();
1.3091 + TestMaxLengthFilenames();
1.3092 + testINC070455();
1.3093 + TestINC112803();
1.3094 + testZeroLengthDescriptors();
1.3095 + testNegativeLengthToWrite();
1.3096 + testNegativeLength();
1.3097 + testReadBufferOverflow();
1.3098 + TestDeleteOnClose();
1.3099 + TestFileAttributesAndCacheFlushing();
1.3100 + TestMaxFileSize();
1.3101 +
1.3102 + DeleteTestDirectory();
1.3103 + }
1.3104 +