First public contribution.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\plugins\version_2beta\encrypt\t_plugin_v2beta.cpp
22 #include "f32_test_utils.h"
27 GLREF_C void TestIfEqual( TInt aValue, TInt aExpected, TInt aLine, char aFileName[]);
29 #define TEST_FOR_ERROR( r ) { TInt _r = (r); if (_r < 0) HandleError(_r, __LINE__); }
30 #define TEST_FOR_VALUE( r, expected ) TestIfEqual( r, expected, __LINE__, __FILE__)
32 LOCAL_C TBool gFileSystemExtensionLoaded = EFalse;
34 LOCAL_C void HandleError(TInt aError, TInt aLine)
36 test.Printf(_L("Error %d\n"), aError);
37 test.operator()(EFalse, aLine);
40 _LIT(KLitTestFileName,"encryptedfile.txt");
42 _LIT8( KSampleText, "line 0 abcdefghijklmnopqrstuvwxyz\n"
43 "line 1 abcdefghijklmnopqrstuvwxyz\n"
44 "line 2 abcdefghijklmnopqrstuvwxyz\n"
45 "line 3 abcdefghijklmnopqrstuvwxyz\n"
46 "line 4 abcdefghijklmnopqrstuvwxyz\n"
47 "line 5 abcdefghijklmnopqrstuvwxyz\n"
48 "line 6 abcdefghijklmnopqrstuvwxyz\n"
49 "line 7 abcdefghijklmnopqrstuvwxyz\n"
50 "line 8 abcdefghijklmnopqrstuvwxyz\n"
51 "line 9 abcdefghijklmnopqrstuvwxyz\n");
53 _LIT( KValueTestFailMsg, "ERROR Got %d expected %d" );
54 GLDEF_C void TestIfEqual( TInt aValue, TInt aExpected, TInt aLine, char aFileName[])
56 if( aExpected != aValue )
60 for (; (i < sizeof(filenameU)) && (aFileName[i] != (char)0); i++)
62 filenameU[i]=aFileName[i];
65 test.Printf( KValueTestFailMsg, aValue, aExpected );
66 test.operator()( EFalse, aLine, &filenameU[0]);
70 GLDEF_D RTest test(_L("t_plugin_v2beta"));
73 void TestFileAccessBeforeEncryptionPlugin()
76 //Check that we can read all the files we want before the
77 //encryption plugin is loaded.
78 test.Next(_L("Test opening files before encryption plugin is installed"));
81 TInt r = file.Replace(TheFs, KLitTestFileName, EFileShareAny);
85 binBuffer.Copy(KSampleText);
88 TBuf8<512*2> hexBuffer;
89 Hex(binBuffer, hexBuffer);
91 r = file.Write(hexBuffer);
100 void TestLoadingOfEncryptionPlugin()
102 test.Next(_L("Test the loading of the encryption plugin"));
104 // Try loading the encryption plugin.
105 TInt r = TheFs.AddPlugin(_L("t_enchook"));
108 // Try loading the encryption plugin again.
109 r = TheFs.AddPlugin(_L("t_enchook"));
110 TEST_FOR_VALUE(r, KErrAlreadyExists);
113 // Try mounting the plugin
114 r = TheFs.MountPlugin(_L("EncHook"));
117 //Test the name functions
119 r = TheFs.PluginName(encName,0,1);
120 test.Printf(_L("Encryption plugin name is: %S\n"), &encName);
124 void TestUnloadingOfEncryptionPlugin()
126 test.Next(_L("Test unloading the encryption plugin"));
128 //Unload the encryption plugin
129 //Wait for it to empty it's input queue.
130 User::After(3000000);
132 TInt r = TheFs.DismountPlugin(_L("EncHook"));
135 r = TheFs.DismountPlugin(_L("EncHook"));
136 TEST_FOR_VALUE(r, KErrNotFound);
138 r = TheFs.RemovePlugin(_L("EncHook"));
141 r = TheFs.RemovePlugin(_L("EncHook"));
142 TEST_FOR_VALUE(r, KErrNotFound);
146 void TestFileAccessDuringEncryptionPluginL()
151 TInt len = KSampleText().Length();
152 TPtr8 buffer((TUint8*) buf.Ptr(), len, len);
154 test.Next(_L("Test opening & reading files with the encryption plugin installed"));
156 TInt r = file.Open(TheFs, KLitTestFileName, EFileShareAny);
160 buffer.SetLength(KSampleText().Length());
161 r = file.Read(buffer);
163 TInt driveNum = CurrentDrive();
165 TInt err = TheFs.FileSystemName(name, driveNum);
170 test.Printf(_L("Drive %C: is not ready!"), 'A'+driveNum);
175 if ((gFileSystemExtensionLoaded || name.CompareF(_L("Win32"))==0)&& r == KErrNotSupported)
177 test.Printf(_L("File system extension does not support local buffers\n"));
184 r = buffer.Compare(KSampleText);
185 TEST_FOR_VALUE(r, KErrNone);
188 // read again - this should be read from cache
190 file.Seek(ESeekStart, startPos);
191 r = file.Read(buffer);
193 r = buffer.Compare(KSampleText);
194 TEST_FOR_VALUE(r, KErrNone);
201 void TestFileAccessAfterEncryptionPlugin()
204 test.Next(_L("Test opening files after encryption plugin is uninstalled"));
208 void TestFormatDriveIntercept()
210 test.Next(_L("Test intercepting of formatting of the drive"));
213 TInt tracksRemaining;
214 gSessionPath = _L("?:\\F32-TST\\");
215 gSessionPath[0] = (TText) gDriveToTest;
216 TInt r = format.Open(TheFs, gSessionPath, EQuickFormat, tracksRemaining);
217 TEST_FOR_VALUE(r, KErrNone);
219 // Don't format the whole drive to save time since
220 // it is plugin intercept which is being tested and not
221 // the format operation itself
222 r = format.Next(tracksRemaining);
223 TEST_FOR_VALUE(r, KErrNone);
228 void TestFormatDriveAfterFormatPlugin()
230 test.Next(_L("Test formatting of the drive after plugin unloaded"));
233 TInt tracksRemaining;
234 gSessionPath = _L("?:\\F32-TST\\");
235 gSessionPath[0] = (TText) gDriveToTest;
237 TInt r = format.Open(TheFs, gSessionPath, EQuickFormat, tracksRemaining);
238 TEST_FOR_VALUE(r, KErrNone);
241 while(tracksRemaining)
243 r = format.Next(tracksRemaining);
244 TEST_FOR_VALUE(r, KErrNone);
250 void TestLoadingOfHexPlugin()
252 test.Next(_L("Test the loading of the hex plugin"));
254 // Try loading the hex plugin.
255 TInt r = TheFs.AddPlugin(_L("t_hexhook"));
258 // Try loading the hex plugin again.
259 r = TheFs.AddPlugin(_L("t_hexhook"));
260 TEST_FOR_VALUE(r, KErrAlreadyExists);
263 // Try mounting the plugin
264 r = TheFs.MountPlugin(_L("HexHook"));
267 //Test the name functions
269 r = TheFs.PluginName(hexName,0,2);
270 test.Printf(_L("Hex plugin name is: %S\n"), &hexName);
274 void TestUnloadingOfHexPlugin()
276 test.Next(_L("Test unloading the hex plugin"));
278 //Unload the hex plugin
279 //Wait for it to empty it's input queue.
280 User::After(3000000);
282 TInt r = TheFs.DismountPlugin(_L("HexHook"));
285 r = TheFs.DismountPlugin(_L("HexHook"));
286 TEST_FOR_VALUE(r, KErrNotFound);
288 r = TheFs.RemovePlugin(_L("HexHook"));
291 r = TheFs.RemovePlugin(_L("HexHook"));
292 TEST_FOR_VALUE(r, KErrNotFound);
296 void TestLoadingOfTracePlugin()
298 test.Next(_L("Test the loading of the trace plugin"));
300 // Try loading the trace plugin.
301 TInt r = TheFs.AddPlugin(_L("t_tracehook"));
304 // Try loading the trace plugin again.
305 r = TheFs.AddPlugin(_L("t_tracehook"));
306 TEST_FOR_VALUE(r, KErrAlreadyExists);
309 // Try mounting the plugin
310 r = TheFs.MountPlugin(_L("TraceHook"));
313 //Test the name functions
315 r = TheFs.PluginName(traceName,0,0);
316 test.Printf(_L("Trace plugin name is: %S\n"), &traceName);
320 void TestUnloadingOfTracePlugin()
322 test.Next(_L("Test unloading the trace plugin"));
324 //Unload the trace plugin
325 //Wait for it to empty it's input queue.
326 User::After(3000000);
328 TInt r = TheFs.DismountPlugin(_L("TraceHook"));
331 r = TheFs.DismountPlugin(_L("TraceHook"));
332 TEST_FOR_VALUE(r, KErrNotFound);
334 r = TheFs.RemovePlugin(_L("TraceHook"));
337 r = TheFs.RemovePlugin(_L("TraceHook"));
338 TEST_FOR_VALUE(r, KErrNotFound);
341 void TestLoadingOfFormatPlugin()
343 test.Next(_L("Test the loading of the format plugin"));
345 // Try loading the format plugin.
346 TInt r = TheFs.AddPlugin(_L("t_formathook"));
349 // Try loading the format plugin again.
350 r = TheFs.AddPlugin(_L("t_formathook"));
351 TEST_FOR_VALUE(r, KErrAlreadyExists);
354 // Try mounting the plugin
355 r = TheFs.MountPlugin(_L("FormatHook"));
358 //Test the name functions
359 TFullName formatName;
360 r = TheFs.PluginName(formatName,0,0);
361 test.Printf(_L("Format plugin name is: %S\n"), &formatName);
365 void TestUnloadingOfFormatPlugin()
367 test.Next(_L("Test unloading the format plugin"));
369 //Unload the format plugin
370 //Wait for it to empty it's input queue.
371 User::After(3000000);
373 TInt r = TheFs.DismountPlugin(_L("FormatHook"));
376 r = TheFs.DismountPlugin(_L("FormatHook"));
377 TEST_FOR_VALUE(r, KErrNotFound);
379 r = TheFs.RemovePlugin(_L("FormatHook"));
382 r = TheFs.RemovePlugin(_L("FormatHook"));
383 TEST_FOR_VALUE(r, KErrNotFound);
388 test.Next(_L("Cleanup files"));
390 TInt r = TheFs.Delete(KLitTestFileName);
397 GLDEF_C void CallTestsL()
400 TInt r = TheFs.CharToDrive(gDriveToTest,theDrive);
403 r = TheFs.Volume(volInfo, theDrive);
404 test (r == KErrNone);
405 if (volInfo.iDrive.iType == EMediaRam)
407 #if defined(__WINS__)
408 if(gDriveToTest != 'C')
411 test.Printf(_L("Plugin not supported on RAM drive\n"));
413 #if defined(__WINS__)
420 r = TheFs.ExtensionName(extName,theDrive, 0);
423 test.Printf(_L("File system extension is present (%S)\n"), &extName);
424 gFileSystemExtensionLoaded = ETrue;
428 test.Printf(_L("File system extension not present.\n"));
432 TestFileAccessBeforeEncryptionPlugin();
434 TestLoadingOfTracePlugin();
435 TestLoadingOfEncryptionPlugin();
436 TestLoadingOfHexPlugin();
438 TestFileAccessDuringEncryptionPluginL();
440 TestUnloadingOfHexPlugin();
441 TestUnloadingOfEncryptionPlugin();
442 TestUnloadingOfTracePlugin();
444 TestFileAccessAfterEncryptionPlugin();
449 // run T_FILE with trace plugin installed
451 #if defined(__WINS__) // only in WINS to save time
452 TestLoadingOfTracePlugin();
456 TBuf<4> driveBuf=_L("?");
457 driveBuf[0] = (TText) gDriveToTest;
459 test.Next(_L("Test running T_FILE with plugin installed"));
461 r = p.Create(_L("T_FILE.exe"), driveBuf);
463 TRequestStatus status;
466 User::WaitForRequest(status);
467 TestUnloadingOfTracePlugin();
470 // Cannot format drive C: so skip this test on that drive
471 if (!F32_Test_Utils::Is_Win32(TheFs, EDriveC))
473 TestLoadingOfFormatPlugin();
474 TestFormatDriveIntercept();
475 TestUnloadingOfFormatPlugin();
476 TestFormatDriveAfterFormatPlugin();