TInt CFloggerTest028_Sync_Static_Multiple2::DoTestCheckWriteL() { RFile logFile; HBufC8* hBuffer; TInt listfilesize,returnCode; RFs fileSystem; //For file operation create a file system TInt numSuccessful = 0; User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(logFile); User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); //To access the buffer // Read from position 0: start of file User::LeaveIfError(returnCode = logFile.Read(ptrString)); // the test case writes 5 elements 100 times, but we only check these things: // 1. that the long test message with one parameter is written 100 times // 2. that the test message with one param is written 100 times // 3. that the end of test message has been written TPtrC8 ptrStringOffsetForSearching; returnCode = ptrString.Find(KTestMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } TInt newLength; // allow length to be watched during debugging TInt loop; ptrStringOffsetForSearching.Set(ptrString.Right((ptrString.Length()-returnCode)-KTestMessageOneParamExpected().Length())); for (loop=0; loop < KMultipleWriteStressTimes; loop++) { returnCode = ptrStringOffsetForSearching.Find(KTestMessageOneParamExpected); //find the next occurance if (returnCode > 0) { numSuccessful++; } newLength = ptrStringOffsetForSearching.Length() - returnCode - KTestMessageOneParamExpected().Length(); if (newLength < 0) { User::Leave(KErrUnknown); } ptrStringOffsetForSearching.Set(ptrStringOffsetForSearching.Right(newLength)); } returnCode = ptrString.Find(KTestTooLongMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } newLength = ptrString.Length()-returnCode-KTestTooLongMessageOneParamExpected().Length(); ptrStringOffsetForSearching.Set(ptrString.Right(newLength)); for (loop=0; loop < KMultipleWriteStressTimes; loop++) { returnCode = ptrStringOffsetForSearching.Find(KTestTooLongMessageOneParamExpected); //find the next occurance if (returnCode > 0) { numSuccessful++; } if (loop < (KMultipleWriteStressTimes - 1)) { newLength = ptrStringOffsetForSearching.Length() - returnCode - KTestTooLongMessageOneParamExpected().Length(); if (newLength < 0) { User::Leave(KErrUnknown); } ptrStringOffsetForSearching.Set(ptrStringOffsetForSearching.Right(newLength)); } } returnCode = ptrString.Find(KTestEndMessage8); if (returnCode > 0) { numSuccessful++; } CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); //logFile if ( numSuccessful == 201 ) return KErrNone; else return KErrUnknown; }
TInt CFloggerTest028_Sync_ConMultiple2::DoTestCheckWriteL() { RFile logFile; HBufC8* hBuffer; TInt listfilesize,returnCode; RFs fileSystem; //For file operation create a file system TInt numSuccessful = 0; TInt loop = 0; User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(logFile); User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer. This is about 176K in size CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); //To access the buffer // Read from position 0: start of file User::LeaveIfError(returnCode = logFile.Read(ptrString)); // the test case writes 6 elements 100 times, but we only check these things: // 1. that the test message with one parameter is written 100 times // 2. that the long message is written 100 times // 3. that the end of test message has been written // 4. that the file is suitably big enough to be expected to contain the // 1K data segment 100 times in it. TPtrC8 ptrStringOffsetForSearching; returnCode = ptrString.Find(KTestMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } TInt newLength; ptrStringOffsetForSearching.Set(ptrString.Right((ptrString.Length()-returnCode)-KTestMessageOneParamExpected().Length())); for (loop=0; loop < KMultipleWriteStressTimes; loop++) { returnCode = ptrStringOffsetForSearching.Find(KTestMessageOneParamExpected); //find the next occurance if (returnCode > 0) { numSuccessful++; } newLength = ptrStringOffsetForSearching.Length() - returnCode - KTestMessageOneParamExpected().Length(); if (newLength < 0) { User::Leave(KErrUnknown); } ptrStringOffsetForSearching.Set(ptrStringOffsetForSearching.Right(newLength)); } returnCode = ptrString.Find(KTestTooLongExpectedMessage); if (returnCode > 0) { numSuccessful++; } ptrStringOffsetForSearching.Set(ptrString.Right((ptrString.Length()-returnCode)-KTestTooLongExpectedMessage().Length())); for (loop=0; loop < KMultipleWriteStressTimes; loop++) { returnCode = ptrStringOffsetForSearching.Find(KTestTooLongExpectedMessage); //find the next occurance if (returnCode > 0) { numSuccessful++; } newLength = ptrStringOffsetForSearching.Length() - returnCode - KTestTooLongExpectedMessage().Length(); if (newLength <0) { User::Leave(KErrUnknown); } ptrStringOffsetForSearching.Set(ptrStringOffsetForSearching.Right(newLength)); } returnCode = ptrString.Find(KTestEndMessage8); if (returnCode > 0) { numSuccessful++; } // we don't check that all the binary data is there - just that the file is nice and long if ( listfilesize > (K1KilobyteOfDataSize * KMultipleWriteStressTimes)) { numSuccessful++; } CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); //logFile if ( numSuccessful == 202 ) return KErrNone; else return KErrUnknown; }
TInt CFloggerTest028_Sync_ConMultiple::DoTestCheckWriteL() { RFile logFile; HBufC8* hBuffer; TInt listfilesize,returnCode; RFs fileSystem; //For file operation create a file system TInt numSuccessful = 0; User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(logFile); User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); //To access the buffer // Read from position 0: start of file User::LeaveIfError(returnCode = logFile.Read(ptrString)); returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read //from the file if (returnCode > 0) { numSuccessful++; } returnCode = ptrString.Find(KTestMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } TPtrC8 ptrStringOffsetForSearching = ptrString.Right((ptrString.Length()-returnCode)-KTestMessageOneParamExpected().Length()); returnCode = ptrStringOffsetForSearching.Find(KTestMessageOneParamExpected); //find the next occurance if (returnCode > 0) { numSuccessful++; } returnCode = ptrString.Find(KTestTooLongExpectedMessage); if (returnCode > 0) { numSuccessful++; } returnCode = ptrString.Find(KTestTooLongMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } // we don't check that all the binary data is there - just that the file is nice and long if ( listfilesize > K1KilobyteOfDataSize) { numSuccessful++; } CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); //logFile if ( numSuccessful == 6 ) return KErrNone; else return KErrUnknown; }
TInt CFloggerTest028_Sync_Static_Multiple::DoTestCheckWriteL() { RFile logFile; HBufC8* hBuffer; TInt listfilesize,returnCode; RFs fileSystem; //For file operation create a file system TInt numSuccessful = 0; User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(logFile); User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); //To access the buffer // Read from position 0: start of file User::LeaveIfError(returnCode = logFile.Read(ptrString)); returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read //from the file if (returnCode > 0) { numSuccessful++; } returnCode = ptrString.Find(KTestTooLongMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } // search for the occurance that the VA_LIST put in // when testing serial, the length will be negative, so skip TInt len; len = (ptrString.Length()-returnCode)-KTestTooLongMessageOneParamExpected().Length(); if (len > 0) { TPtrC8 ptrStringOffsetForSearching = ptrString.Right(len); returnCode = ptrStringOffsetForSearching.Find(KTestTooLongMessageOneParamExpected); //find the next occurance if (returnCode > 0) { numSuccessful++; } } returnCode = ptrString.Find(KTestMessageOneParamExpected); if (returnCode > 0) { numSuccessful++; } returnCode = ptrString.Find(KTestMessageAsHex8); if (returnCode > 0) { numSuccessful++; } CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); //logFile if ( numSuccessful == 5 ) return KErrNone; else return KErrUnknown; }
LOCAL_C void TestUnicode() // // Test RFs::ReadFileSection() // { test.Next(_L("Use RFs::ReadFileSection() to read from a file")); // First, test for non-existant file TBuf8<256> testDes; TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\NonExistantFile.txt"),0,testDes,52); test_Value(r, r == KErrNotFound); test(testDes.Length()==0); // Test with file closed r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,52); test_KErrNone(r); test(testDes.Length()==52); test(testDes==alphaPtr); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),52,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),72,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); // Test for Null File length TBuf8<256> testDesN; test.Next(_L("Check for null file name")); r=TheFs.ReadFileSection(_L(""),0,testDesN,26); test_Value(r, r == KErrBadName); // Check the lentgh of descriptor. TInt x = testDesN.Length(); test ( x == 0); test.Next(_L("Check for non existing file")); r=TheFs.ReadFileSection(_L("sdfsd.dfg"),0,testDesN,26); test.Printf(_L("Return %d"),r); test_Value(r, (r == KErrNotFound) || (r == KErrPathNotFound)); // Check the lentgh of descriptor. x = testDesN.Length(); test ( x == 0); // Test for Empty directory r=TheFs.ReadFileSection(_L("\\F32-tst\\"),0,testDesN,52); test_Value(r, r == KErrBadName); test(testDesN.Length()==0); // Test for File with wildcard name r=TheFs.ReadFileSection(_L("\\F32-tst\\*.txt"),0,testDesN,52); test_Value(r, r == KErrBadName); test(testDesN.Length()==0); // Test for Folder with wildcard name r=TheFs.ReadFileSection(_L("\\F32-tst*\\ReadFileSection1.txt"),0,testDesN,52); test_Value(r, r == KErrBadName); test(testDesN.Length()==0); // Test for Root directory r=TheFs.ReadFileSection(_L("\\"),0,testDesN,52); test_Value(r, r == KErrBadName); test(testDesN.Length()==0); // Test for no file being specified. r=TheFs.ReadFileSection(_L(""),0,testDesN,26); test_Value(r, r == KErrBadName); test(testDesN.Length()==0); // Test with file open EFileShareAny|EFileRead RFile file; r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileRead); test_KErrNone(r); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),100,testDes,52); test_KErrNone(r); test(testDes==alphaPtr); test(testDes.Length()==52); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),152,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),172,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); file.Close(); // Test with file open EFileShareExclusive|EFileRead r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileRead); test_KErrNone(r); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),200,testDes,52); test_KErrNone(r); test(testDes==alphaPtr); test(testDes.Length()==52); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),252,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),272,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); file.Close(); // Test with file open EFileShareExclusive|EFileWrite r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileWrite); test_KErrNone(r); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),300,testDes,52); test_KErrNone(r); test(testDes==alphaPtr); test(testDes.Length()==52); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),352,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),372,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); file.Close(); // Test with file open EFileShareReadersOnly|EFileRead r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareReadersOnly|EFileRead); test_KErrNone(r); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),400,testDes,52); test_KErrNone(r); test(testDes==alphaPtr); test(testDes.Length()==52); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),452,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),472,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); file.Close(); // Test with several accesses to a file EFileShareAny|EFileWrite r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite); test_KErrNone(r); RFile secondFile; r=secondFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite); test_KErrNone(r); RFile thirdFile; r=thirdFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite); test_KErrNone(r); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),500,testDes,52); test_KErrNone(r); #if defined(__WINS__) #if defined(_DEBUG) test(testDes==alphaPtr); test(testDes.Length()==52); #endif #else test(testDes==alphaPtr); test(testDes.Length()==52); #endif r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),552,testDes,20); test_KErrNone(r); test(testDes==numberPtr); test(testDes.Length()==20); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),572,testDes,28); test_KErrNone(r); test(testDes==humptyPtr); test(testDes.Length()==28); // Test across potential cluster boundaries r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200); test_KErrNone(r); test(testDes.Length()==200); TBuf8<200> amalgam; TInt i=0; for (; i<2; i++) { amalgam.Append(alphaPtr); amalgam.Append(numberPtr); amalgam.Append(humptyPtr); } r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200); test_KErrNone(r); test(testDes.Length()==200); test(testDes==amalgam); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),3000,testDes,200); test_KErrNone(r); test(testDes.Length()==200); test(testDes==amalgam); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,testDes,200); test_KErrNone(r); test(testDes.Length()==200); test(testDes==amalgam); file.Close(); secondFile.Close(); thirdFile.Close(); // Test errors and boundary conditions test.Next(_L("Test Error handling")); // Test that specifying a zero length section returns a zero length descriptor TBuf8<30> testDes2; r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),50,testDes2,0); test_KErrNone(r); test(testDes2.Length()==0); // Test that specifying a negative starting position causes a panic // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),-1,testDes2,10); // This will panic: See RFs::ReadFileSection() code - relevant lines are // __ASSERT_ALWAYS(aPos>=0,Panic(EPosNegative)); // Test that specifying a section of greater length than the descriptor to // hold the data will cause a panic // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes2,45); // This will panic: See RFs::ReadFileSection() code - relevant lines are // __ASSERT_ALWAYS(aDes.MaxLength()>=aLength,Panic(EBadLength)); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes2,-20); test_Value(r, r == KErrArgument); // Test that specifying a position and length which extends beyond the end of // the file returns a zero length descriptor and KErrNone r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9993,testDes2,30); test_KErrNone(r); test(testDes2.Length()==7); test(testDes2==humptyPtr.Right(7)); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9999,testDes2,1); test_KErrNone(r); test(testDes2.Length()==1); test(testDes2==humptyPtr.Right(1)); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,testDes2,1); test_KErrNone(r); test(testDes2.Length()==0); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10550,testDes2,20); test_KErrNone(r); test(testDes2.Length()==0); // Test reading the whole file HBufC8* hDes=HBufC8::New(10002); if (!hDes) User::Leave(KErrNoMemory); TPtr8 pDes=hDes->Des(); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000); test_KErrNone(r); test(pDes.Length()==10000); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000); test_KErrNone(r); test(pDes.Length()==10000); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10002); test_KErrNone(r); test(pDes.Length()==10000); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,6000); test_KErrNone(r); test(pDes.Length()==6000); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,8002); test_KErrNone(r); test(pDes.Length()==6000); r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,pDes,10002); test_KErrNone(r); test(pDes.Length()==0); delete hDes; }