kerneltest/f32test/server/t_corruptlog.cpp
changeset 109 b3a1d9898418
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    22 //! @SYMTestSuites Base tests
    22 //! @SYMTestSuites Base tests
    23 //! @SYMInitialAuthor Bob Jackman
    23 //! @SYMInitialAuthor Bob Jackman
    24 //! @SYMCreationDate 1/11/04
    24 //! @SYMCreationDate 1/11/04
    25 //! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst
    25 //! @SYMTestCaseDesc Check trap action of CorruptFileNames.lst
    26 
    26 
       
    27 #define __E32TEST_EXTENSION__
    27 #include <e32test.h>
    28 #include <e32test.h>
    28 RTest test(_L("t_corruptlog"));
    29 RTest test(_L("t_corruptlog"));
    29 
    30 
    30 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
    31 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
    31 #include <f32file.h>
    32 #include <f32file.h>
   104 	// fetchs the number of corrupt file trap records that exist
   105 	// fetchs the number of corrupt file trap records that exist
   105 	// there is a separate record for every attempted access to a nominated file
   106 	// there is a separate record for every attempted access to a nominated file
   106 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   107 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   107 	TInt numberOfRecords;
   108 	TInt numberOfRecords;
   108 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords);
   109 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetNumberOfCorruptLogRecords, numberOfRecords);
   109 	test(r==KErrNone);
   110 	test_KErrNone(r);
   110 	return numberOfRecords;
   111 	return numberOfRecords;
   111 	}
   112 	}
   112 
   113 
   113 TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
   114 TInt GetTrapLogRecord(TFsDebugCorruptLogRecordBuf &alogRec, TInt aRecordNumber)
   114 	{
   115 	{
   115 	// fetchs a trap record
   116 	// fetchs a trap record
   116 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   117 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   117 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber);
   118 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptLogRecord, alogRec, aRecordNumber);
   118 	test(r==KErrNone);
   119 	test_KErrNone(r);
   119 	return r;
   120 	return r;
   120 	}
   121 	}
   121 
   122 
   122 TInt GetCorruptFileListFile(TDes& aFileName)
   123 TInt GetCorruptFileListFile(TDes& aFileName)
   123 	{
   124 	{
   124 	// Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate
   125 	// Retrieves the name of the file containing the list of files, nominated as corrupt, used to generate
   125 	// the corrupt files list.
   126 	// the corrupt files list.
   126 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   127 	// Note that C: is used in the IoControl call, which requires a valid drive, but has no other relevance
   127 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName);
   128 	TInt r=controlIo(TheFs, EDriveC, KControlIoGetCorruptListFile, aFileName);
   128 	test(r==KErrNone);
   129 	test_KErrNone(r);
   129 	return r;
   130 	return r;
   130 	}
   131 	}
   131 
   132 
   132 void AccessFiles()
   133 void AccessFiles()
   133 	{
   134 	{
   134 	test.Next(_L("Access corrupt files"));
   135 	test.Next(_L("Access corrupt files"));
   135 	RFile f;
   136 	RFile f;
   136 	const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead;
   137 	const TInt attribs=EFileShareExclusive|EFileStreamText|EFileRead;
   137 	// File1 
   138 	// File1 
   138 	TInt r=f.Open(TheFs,KTestFile1,attribs);
   139 	TInt r=f.Open(TheFs,KTestFile1,attribs);
   139 	test(r==KTestFile1Error1);
   140 	test_Value(r, r == KTestFile1Error1);
   140 	f.Close();
   141 	f.Close();
   141 	numberOfTraps+=(r==KErrNone?0:1);
   142 	numberOfTraps+=(r==KErrNone?0:1);
   142 	// try again
   143 	// try again
   143 	r=f.Open(TheFs,KTestFile1,attribs);
   144 	r=f.Open(TheFs,KTestFile1,attribs);
   144 	test(r==KTestFile1Error2);
   145 	test_Value(r, r == KTestFile1Error2);
   145 	f.Close();
   146 	f.Close();
   146 	numberOfTraps+=(r==KErrNone?0:1);
   147 	numberOfTraps+=(r==KErrNone?0:1);
   147 	// File2 
   148 	// File2 
   148 	r=f.Open(TheFs,KTestFile2,attribs);
   149 	r=f.Open(TheFs,KTestFile2,attribs);
   149 	test(r==KTestFile2Error1);
   150 	test_Value(r, r == KTestFile2Error1);
   150 	f.Close();
   151 	f.Close();
   151 	numberOfTraps+=(r==KErrNone?0:1);
   152 	numberOfTraps+=(r==KErrNone?0:1);
   152 	// try again
   153 	// try again
   153 	r=f.Open(TheFs,KTestFile2,attribs);
   154 	r=f.Open(TheFs,KTestFile2,attribs);
   154 	test(r==KTestFile2Error2);
   155 	test_Value(r, r == KTestFile2Error2);
   155 	f.Close();
   156 	f.Close();
   156 	numberOfTraps+=(r==KErrNone?0:1);
   157 	numberOfTraps+=(r==KErrNone?0:1);
   157 	}
   158 	}
   158 
   159 
   159 void DoTests()
   160 void DoTests()
   160 	{
   161 	{
   161 	TFileName corruptFileNamesList;
   162 	TFileName corruptFileNamesList;
   162     test.Next(_L("Get name of file with list of nominated files"));
   163     test.Next(_L("Get name of file with list of nominated files"));
   163 	TInt r=GetCorruptFileListFile(corruptFileNamesList);
   164 	TInt r=GetCorruptFileListFile(corruptFileNamesList);
   164     test(r==KErrNone);
   165     test_KErrNone(r);
   165  	test.Printf(_L("Using %S\n"),&corruptFileNamesList);
   166  	test.Printf(_L("Using %S\n"),&corruptFileNamesList);
   166 
   167 
   167 	AccessFiles();
   168 	AccessFiles();
   168     test.Next(_L("Get Number of traps"));
   169     test.Next(_L("Get Number of traps"));
   169 	TInt nRecs=GetNumberOfTraps();
   170 	TInt nRecs=GetNumberOfTraps();
   172 
   173 
   173 	TFsDebugCorruptLogRecordBuf logRec;
   174 	TFsDebugCorruptLogRecordBuf logRec;
   174 	for (TInt i=1;i<=nRecs;i++)
   175 	for (TInt i=1;i<=nRecs;i++)
   175 		{ // fetch record #i
   176 		{ // fetch record #i
   176 		TInt r=GetTrapLogRecord(logRec,i);
   177 		TInt r=GetTrapLogRecord(logRec,i);
   177 		test(r==KErrNone);
   178 		test_KErrNone(r);
   178 		r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe"));
   179 		r=logRec().iProcessName.CompareF(_L("t_corruptlog.exe"));
   179 		test(r==KErrNone);
   180 		test_KErrNone(r);
   180 		PrintLogRecord(logRec,i);
   181 		PrintLogRecord(logRec,i);
   181 		}
   182 		}
   182 	}
   183 	}
   183 
   184 
   184 #endif
   185 #endif
   192     
   193     
   193     test.Title();
   194     test.Title();
   194     test.Start(_L("Corrupt File trap log"));
   195     test.Start(_L("Corrupt File trap log"));
   195 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   196 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   196 	TInt r=TheFs.Connect();
   197 	TInt r=TheFs.Connect();
   197     test(r==KErrNone);
   198     test_KErrNone(r);
   198 
   199 
   199     TheFs.ResourceCountMarkStart();
   200     TheFs.ResourceCountMarkStart();
   200     
   201     
   201     DoTests();
   202     DoTests();
   202     
   203