persistentstorage/sql/TEST/t_sqlfilebuf64.cpp
branchRCL_3
changeset 12 6b6fd149daa2
parent 0 08ec8eefde2f
child 15 fcc16690f446
equal deleted inserted replaced
11:211563e4b919 12:6b6fd149daa2
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    28 static RFs   TheFs;
    28 static RFs   TheFs;
    29 
    29 
    30 _LIT(KTestDir, "c:\\test\\");
    30 _LIT(KTestDir, "c:\\test\\");
    31 _LIT(KTestFile, "c:\\test\\t_sqlfilebuf64.bin");
    31 _LIT(KTestFile, "c:\\test\\t_sqlfilebuf64.bin");
    32 _LIT(KTestFile2, "\\test\\t_sqlfilebuf64_2.bin");
    32 _LIT(KTestFile2, "\\test\\t_sqlfilebuf64_2.bin");
       
    33 _LIT(KTestFile3, "c:\\test\\t_sqlfilebuf64_3.bin");
    33 
    34 
    34 static TBuf8<1024> TheBuf;
    35 static TBuf8<1024> TheBuf;
    35 static TFileName TheDbName;
    36 static TFileName TheDbName;
    36 
    37 
    37 static TInt TheProcessHandleCount = 0;
    38 static TInt TheProcessHandleCount = 0;
    55 	{
    56 	{
    56 	if(TheDbName.Length() > 0)
    57 	if(TheDbName.Length() > 0)
    57 		{
    58 		{
    58 		(void)TheFs.Delete(TheDbName);
    59 		(void)TheFs.Delete(TheDbName);
    59 		}
    60 		}
       
    61 	(void)TheFs.Delete(KTestFile3);
    60 	(void)TheFs.Delete(KTestFile);
    62 	(void)TheFs.Delete(KTestFile);
    61 	}
    63 	}
    62 
    64 
    63 void TestEnvDestroy()
    65 void TestEnvDestroy()
    64 	{
    66 	{
   506 void ReadTest1()
   508 void ReadTest1()
   507 	{
   509 	{
   508 	const TInt KBufMaxSize = 20;// This is half the file size
   510 	const TInt KBufMaxSize = 20;// This is half the file size
   509 	RFileBuf64 fbuf(KBufMaxSize);
   511 	RFileBuf64 fbuf(KBufMaxSize);
   510 	TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
   512 	TInt err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead | EFileShareReadersOrWriters);
   511 	TEST2(err, KErrNone); 
   513 	TEST2(err, KErrNone);
   512     fbuf.ProfilerReset();
   514     fbuf.ProfilerReset();
   513     
   515     
   514 	//Zero max length request
   516 	//Zero max length request
   515 	HBufC8* buf1 = HBufC8::New(0);
   517 	HBufC8* buf1 = HBufC8::New(0);
   516 	TEST(buf1 != NULL);
   518 	TEST(buf1 != NULL);
   519 	TEST2(err, KErrNone); 
   521 	TEST2(err, KErrNone); 
   520 	delete buf1;
   522 	delete buf1;
   521 	TEST2(fbuf.iFileReadCount, 0);
   523 	TEST2(fbuf.iFileReadCount, 0);
   522 	TEST2(fbuf.iFileReadAmount, 0);
   524 	TEST2(fbuf.iFileReadAmount, 0);
   523 	TEST2(fbuf.iFileSizeCount, 0);
   525 	TEST2(fbuf.iFileSizeCount, 0);
   524 	
   526 
   525 	//Too big request
   527 	//Too big request
   526 	TBuf8<KBufMaxSize * 2> buf2;
   528 	TBuf8<KBufMaxSize * 2> buf2;
   527 	err = fbuf.Read(0, buf2);
   529 	err = fbuf.Read(0, buf2);
   528 	TEST2(err, KErrNone); 
   530 	TEST2(err, KErrNone); 
   529 	TEST2(fbuf.iFileReadCount, 1);
   531 	TEST2(fbuf.iFileReadCount, 1);
   534 	//Read beyond the end of the file
   536 	//Read beyond the end of the file
   535 	err = fbuf.Read(2000, buf2);
   537 	err = fbuf.Read(2000, buf2);
   536 	TEST2(err, KErrNone); 
   538 	TEST2(err, KErrNone); 
   537 	TEST2(buf2.Length(), 0); 
   539 	TEST2(buf2.Length(), 0); 
   538 
   540 
       
   541 	//Write "5678" in the buffer, pos [4..8)
       
   542 	err = fbuf.Write(4, _L8("5678"));
       
   543 	TEST2(err, KErrNone); 
       
   544 
       
   545 	//Too big request. There are pending data in the buffer.
       
   546 	TBuf8<KBufMaxSize + 2> buf3;
       
   547 	err = fbuf.Read(1, buf3);
       
   548 	TEST2(err, KErrNone); 
       
   549 	VerifyFileContent(buf3, 1);
       
   550 
       
   551 	//Read from a non-zero file position to move the buffer start pos. The cached file pos will be 35 at the end.
       
   552 	TBuf8<5> buf4;
       
   553 	err = fbuf.Read(30, buf4);
       
   554 	TEST2(err, KErrNone); 
       
   555 	VerifyFileContent(buf4, 30);
       
   556 	err = fbuf.Read(35, buf4);
       
   557 	TEST2(err, KErrNone); 
       
   558 	VerifyFileContent(buf4, 35);
       
   559 
       
   560 	//Too big request. No pending data in the buffer. The file read pos is before the position of the cached data in the buffer.  
       
   561 	err = fbuf.Read(10, buf3);
       
   562 	TEST2(err, KErrNone); 
       
   563 	VerifyFileContent(buf3, 10);
       
   564 	
   539 	fbuf.Close();
   565 	fbuf.Close();
   540 	}
   566 	}
   541 
   567 
   542 /**
   568 /**
   543 @SYMTestCaseID			PDS-SQL-UT-4139
   569 @SYMTestCaseID			PDS-SQL-UT-4139
   979 		(void)TheFs.Delete(tmpFileName);
  1005 		(void)TheFs.Delete(tmpFileName);
   980 		}
  1006 		}
   981 	(void)TheFs.Delete(KTestFile);
  1007 	(void)TheFs.Delete(KTestFile);
   982 	}
  1008 	}
   983 
  1009 
       
  1010 /**
       
  1011 @SYMTestCaseID			PDS-SQL-UT-4195
       
  1012 @SYMTestCaseDesc		RFileBuf64::Create() file I/O error simulation test.
       
  1013 						The test calls RFileBuf64:Create() in a file I/O error simulation loop.
       
  1014 @SYMTestActions			RFileBuf64::Create() file I/O error simulation test.
       
  1015 @SYMTestExpectedResults Test must not fail
       
  1016 @SYMTestPriority		High
       
  1017 @SYMDEF					DEF145198
       
  1018 */
       
  1019 void CreateFileIoErrTest()
       
  1020 	{
       
  1021     TInt err = KErrGeneral;
       
  1022     TInt cnt = 0;
       
  1023     for(;err<KErrNone;++cnt)
       
  1024         {
       
  1025         TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
       
  1026         for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
       
  1027             {
       
  1028             TheTest.Printf(_L("%d "), fsError);
       
  1029         	__UHEAP_MARK;
       
  1030             (void)TheFs.SetErrorCondition(fsError, cnt);
       
  1031         	RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
       
  1032         	err = fbuf.Create(TheFs, KTestFile3, EFileRead | EFileWrite);
       
  1033             (void)TheFs.SetErrorCondition(KErrNone);
       
  1034             fbuf.Close();
       
  1035             __UHEAP_MARKEND;
       
  1036 			TInt err2 = TheFs.Delete(KTestFile3);
       
  1037 			TInt expectedErr = err == KErrNone ? KErrNone : KErrNotFound;
       
  1038 			TEST2(err2, expectedErr);
       
  1039             }
       
  1040         TheTest.Printf(_L("\r\n"));
       
  1041         }
       
  1042     TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
       
  1043 	}
       
  1044 
       
  1045 /**
       
  1046 @SYMTestCaseID			PDS-SQL-UT-4196
       
  1047 @SYMTestCaseDesc		RFileBuf64::Open() file I/O error simulation test.
       
  1048 						The test calls RFileBuf64:Open() in a file I/O error simulation loop.
       
  1049 @SYMTestActions			RFileBuf64::Open() file I/O error simulation test.
       
  1050 @SYMTestExpectedResults Test must not fail
       
  1051 @SYMTestPriority		High
       
  1052 @SYMDEF					DEF145198
       
  1053 */
       
  1054 void OpenFileIoErrTest()
       
  1055 	{
       
  1056 	RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
       
  1057 	TInt err = fbuf.Create(TheFs, KTestFile3, EFileRead | EFileWrite);
       
  1058 	fbuf.Close();
       
  1059 	TEST2(err, KErrNone);
       
  1060     err = KErrGeneral;
       
  1061     TInt cnt = 0;
       
  1062     for(;err<KErrNone;++cnt)
       
  1063         {
       
  1064         TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
       
  1065         for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
       
  1066             {
       
  1067             TheTest.Printf(_L("%d "), fsError);
       
  1068         	__UHEAP_MARK;
       
  1069             (void)TheFs.SetErrorCondition(fsError, cnt);
       
  1070         	err = fbuf.Open(TheFs, KTestFile3, EFileRead | EFileWrite);
       
  1071             (void)TheFs.SetErrorCondition(KErrNone);
       
  1072             fbuf.Close();
       
  1073             __UHEAP_MARKEND;
       
  1074             }
       
  1075         TheTest.Printf(_L("\r\n"));
       
  1076         }
       
  1077     TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
       
  1078 	(void)TheFs.Delete(KTestFile3);
       
  1079 	}
       
  1080 
       
  1081 /**
       
  1082 @SYMTestCaseID			PDS-SQL-UT-4197
       
  1083 @SYMTestCaseDesc		RFileBuf64::Temp() file I/O error simulation test.
       
  1084 						The test calls RFileBuf64:Temp() in a file I/O error simulation loop.
       
  1085 @SYMTestActions			RFileBuf64::temp() file I/O error simulation test.
       
  1086 @SYMTestExpectedResults Test must not fail
       
  1087 @SYMTestPriority		High
       
  1088 @SYMDEF					DEF145198
       
  1089 */
       
  1090 void TempFileIoErrTest()
       
  1091 	{
       
  1092     TInt err = KErrGeneral;
       
  1093     TInt cnt = 0;
       
  1094     for(;err<KErrNone;++cnt)
       
  1095         {
       
  1096         TheTest.Printf(_L("===Iteration %d. Simulated error:\r\n"), cnt);       
       
  1097         for (TInt fsError=KErrNotFound;fsError>=KErrBadName;--fsError)
       
  1098             {
       
  1099             TheTest.Printf(_L("%d "), fsError);
       
  1100         	__UHEAP_MARK;
       
  1101             (void)TheFs.SetErrorCondition(fsError, cnt);
       
  1102         	RFileBuf64 fbuf(1024);//buffer capacity = 1024 bytes
       
  1103         	TFileName tmpFileName;
       
  1104 			err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
       
  1105             (void)TheFs.SetErrorCondition(KErrNone);
       
  1106             fbuf.Close();
       
  1107             __UHEAP_MARKEND;
       
  1108 			TInt err2 = TheFs.Delete(tmpFileName);
       
  1109 			TInt expectedErr = err == KErrNone ? KErrNone : KErrNotFound;
       
  1110 			TEST2(err2, expectedErr);
       
  1111             }
       
  1112         TheTest.Printf(_L("\r\n"));
       
  1113         }
       
  1114     TheTest.Printf(_L("\r\n===File I/O error simulation test succeeded on iteration %d===\r\n"), cnt);
       
  1115 	}
       
  1116 
   984 void DoTests()
  1117 void DoTests()
   985 	{
  1118 	{
   986 	TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1"));
  1119 	TheTest.Start(_L(" @SYMTestCaseID:PDS-SQL-UT-4132 RFileBuf64 write test 1"));
   987 	WriteTest1();
  1120 	WriteTest1();
   988 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2"));
  1121 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4133 RFileBuf64 write test 2"));
  1013 	OomTest(EOomCreateTest);
  1146 	OomTest(EOomCreateTest);
  1014 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Open() OOM test"));
  1147 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Open() OOM test"));
  1015 	OomTest(EOomOpenTest);
  1148 	OomTest(EOomOpenTest);
  1016 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Temp() OOM test"));
  1149 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4142 RFileBuf64::Temp() OOM test"));
  1017 	OomTest(EOomTempTest);
  1150 	OomTest(EOomTempTest);
       
  1151 	
       
  1152 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4195 RFileBuf64::Create() file I/O error simulation test"));
       
  1153 	CreateFileIoErrTest();
       
  1154 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4196 RFileBuf64::Open() file I/O error simulation test"));
       
  1155 	OpenFileIoErrTest();
       
  1156 	TheTest.Next( _L(" @SYMTestCaseID:PDS-SQL-UT-4197 RFileBuf64::Temp() file I/O error simulation test"));
       
  1157 	OpenFileIoErrTest();
  1018 	}
  1158 	}
  1019 
  1159 
  1020 TInt E32Main()
  1160 TInt E32Main()
  1021 	{
  1161 	{
  1022 	TheTest.Title();
  1162 	TheTest.Title();