|
1 // Copyright (c) 2009-2010 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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // f32test\filesystem\fat\t_nonrugged.cpp |
|
15 // Functional tests for the non-Rugged file mode (also called the File Sequential mode) |
|
16 // Only perform tests on the Rugged FAT file system |
|
17 // |
|
18 |
|
19 #define __E32TEST_EXTENSION__ |
|
20 |
|
21 #include <f32file.h> |
|
22 #include <e32test.h> |
|
23 |
|
24 #include "t_server.h" |
|
25 #include "fat_utils.h" |
|
26 using namespace Fat_Test_Utils; |
|
27 |
|
28 |
|
29 RTest test(_L("T_NONRUGGED")); |
|
30 |
|
31 TInt gDriveNum; |
|
32 |
|
33 _LIT(KTestPath, ":\\F32-TST\\T_NONRUGGED\\"); // 22 |
|
34 |
|
35 |
|
36 enum TNonRuggedFileMode |
|
37 { |
|
38 ENormalFileMode, // File is in normal (Rugged) mode |
|
39 ENonRuggedFileMode // File is in non-Rugged file mode (EFileSequential) |
|
40 }; |
|
41 |
|
42 enum TNonRuggedControlIO |
|
43 /* |
|
44 * ControlIo enum values |
|
45 */ |
|
46 { |
|
47 EControlIOIsRuggedFSys = 4, // Defined as EIsRuggedFSys in \fileserver\sfat32\common_constants.h |
|
48 EControlIOIsFileSequential = KMaxTInt-23 // Defined as KControlIoIsFileSequential in \fileserver\inc\f32dbg.h |
|
49 }; |
|
50 |
|
51 |
|
52 void CreateFile(RFile& aFile, const TDesC& aPath, TUint aFileMode) |
|
53 /* |
|
54 * Creates/opens a file in Rugged/non-Rugged mode after emptying the trace buffer |
|
55 */ |
|
56 { |
|
57 TInt r = TheFs.MkDirAll(aPath); |
|
58 test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
|
59 r = aFile.Replace(TheFs, aPath, aFileMode); |
|
60 test_KErrNone(r); |
|
61 } |
|
62 |
|
63 |
|
64 void DeleteFileAndDir(const TDesC& aPath) |
|
65 /* |
|
66 * Deletes a single file and the directory containing it |
|
67 */ |
|
68 { |
|
69 TInt r = TheFs.Delete(aPath); |
|
70 test_KErrNone(r); |
|
71 r = TheFs.RmDir(aPath); |
|
72 test_KErrNone(r); |
|
73 } |
|
74 |
|
75 |
|
76 void SingleClientTest() |
|
77 /* |
|
78 * Unit test for Non-Rugged File mode with a single client |
|
79 *********************************************************************************** |
|
80 * 1. Create a file in non-Rugged file mode and then close the file. |
|
81 * 2. Open the file in normal Rugged file mode and then close it. |
|
82 * 3. Open the file in non-Rugged file mode again and then close it. |
|
83 * Expected Results: |
|
84 * 1. File is in non-Rugged file mode. |
|
85 * 2. File is in normal Rugged file mode. |
|
86 * 3. File is in non-Rugged file mode. |
|
87 *********************************************************************************** |
|
88 */ |
|
89 { |
|
90 test.Next(_L("Test single client")); |
|
91 |
|
92 TBuf<34> singleFile; |
|
93 singleFile.Append(gDriveToTest); // 1 |
|
94 singleFile.Append(KTestPath); // 22 |
|
95 singleFile.Append(_L("file.single")); // 11 |
|
96 TInt r = TheFs.Delete(singleFile); |
|
97 test_Value(r, r == KErrNone || r == KErrNotFound || r == KErrPathNotFound); |
|
98 TBuf8<KMaxPath> singleFilePkg; |
|
99 singleFilePkg.Copy(singleFile.Mid(2)); |
|
100 TUint8 fileMode = 0; |
|
101 TPtr8 fileModePkg(&fileMode, 1, 1); |
|
102 |
|
103 test.Printf(_L("Create file in non-Rugged file mode\n")); |
|
104 RFile file; |
|
105 CreateFile(file, singleFile, (EFileWrite | EFileSequential)); |
|
106 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, singleFilePkg, fileModePkg); |
|
107 test_KErrNone(r); |
|
108 test_Equal(ENonRuggedFileMode, fileMode); |
|
109 file.Close(); |
|
110 |
|
111 test.Printf(_L("Open file in normal mode\n")); |
|
112 CreateFile(file, singleFile, EFileWrite); |
|
113 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, singleFilePkg, fileModePkg); |
|
114 test_KErrNone(r); |
|
115 test_Equal(ENormalFileMode, fileMode); |
|
116 file.Close(); |
|
117 |
|
118 test.Printf(_L("Open file in non-Rugged file mode again\n")); |
|
119 CreateFile(file, singleFile, (EFileWrite | EFileSequential)); |
|
120 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, singleFilePkg, fileModePkg); |
|
121 test_KErrNone(r); |
|
122 test_Equal(ENonRuggedFileMode, fileMode); |
|
123 file.Close(); |
|
124 |
|
125 DeleteFileAndDir(singleFile); |
|
126 } |
|
127 |
|
128 |
|
129 void MultipleClientsTest() |
|
130 /* |
|
131 * Unit tests for Non-Rugged File mode with multiple clients accessing the same file |
|
132 */ |
|
133 { |
|
134 /*********************************************************************************** |
|
135 * Use Case 1: |
|
136 * 1. Client1 opens a file in non-Rugged file mode. |
|
137 * 2. Client2 then opens the same file in normal Rugged file mode. |
|
138 * Expected Results: |
|
139 * 1. File is in non-Rugged file mode. |
|
140 * 2. File changed to normal Rugged file mode. |
|
141 *********************************************************************************** |
|
142 */ |
|
143 test.Next(_L("Test multiple clients - Use case 1")); |
|
144 |
|
145 TBuf<33> fileName1; |
|
146 fileName1.Append(gDriveToTest); // 1 |
|
147 fileName1.Append(KTestPath); // 22 |
|
148 fileName1.Append(_L("file1.mult")); // 10 |
|
149 TInt r = TheFs.Delete(fileName1); |
|
150 test_Value(r, r == KErrNone || r == KErrNotFound || r == KErrPathNotFound); |
|
151 TBuf8<31> fileName1Pkg; |
|
152 fileName1Pkg.Copy(fileName1.Mid(2)); |
|
153 TUint8 fileMode = 0; |
|
154 TPtr8 fileModePkg(&fileMode, 1, 1); |
|
155 |
|
156 |
|
157 // Use Case 1.1, Client 1 (Non-Rugged Client) ------------------------------------ |
|
158 test.Printf(_L("Client1 create file in non-Rugged file mode\n")); |
|
159 |
|
160 RFile file1; |
|
161 CreateFile(file1, fileName1, (EFileWrite | EFileSequential | EFileShareAny)); |
|
162 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, fileName1Pkg, fileModePkg); |
|
163 test_KErrNone(r); |
|
164 test_Equal(ENonRuggedFileMode, fileMode); |
|
165 |
|
166 |
|
167 // Use Case 1.2, Client 2 (Rugged Client) ---------------------------------------- |
|
168 test.Printf(_L("Client2 open file in 'normal' Rugged file mode\n")); |
|
169 |
|
170 RFile file2; |
|
171 CreateFile(file2, fileName1, (EFileWrite | EFileShareAny)); |
|
172 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, fileName1Pkg, fileModePkg); |
|
173 test_KErrNone(r); |
|
174 test_Equal(ENormalFileMode, fileMode); |
|
175 |
|
176 |
|
177 file1.Close(); |
|
178 file2.Close(); |
|
179 r = TheFs.Delete(fileName1); |
|
180 test_KErrNone(r); |
|
181 |
|
182 |
|
183 /*********************************************************************************** |
|
184 * Use Case 2: |
|
185 * 1. Client1 opens a file in normal Rugged file mode. |
|
186 * 2. Client2 then opens the same file in non-Rugged file mode. |
|
187 * Expected Results: |
|
188 * 1. File is in normal Rugged file mode. |
|
189 * 2. File does not change to non-Rugged file mode. |
|
190 *********************************************************************************** |
|
191 */ |
|
192 test.Next(_L("Test multiple clients - Use case 2")); |
|
193 |
|
194 TBuf<34> fileName2; |
|
195 fileName2.Append(gDriveToTest); // 1 |
|
196 fileName2.Append(KTestPath); // 22 |
|
197 fileName2.Append(_L("file2.mult")); // 10 |
|
198 r = TheFs.Delete(fileName2); |
|
199 test_Value(r, r == KErrNone || r == KErrNotFound || r == KErrPathNotFound); |
|
200 TBuf8<KMaxPath> fileName2Pkg; |
|
201 fileName2Pkg.Copy(fileName2.Mid(2)); |
|
202 |
|
203 |
|
204 // Use Case 2.1, Client 1 (Rugged Client) ---------------------------------------- |
|
205 test.Printf(_L("Client1 create file in 'normal' Rugged file mode\n")); |
|
206 |
|
207 CreateFile(file1, fileName2, (EFileWrite | EFileShareAny)); |
|
208 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, fileName2Pkg, fileModePkg); |
|
209 test_KErrNone(r); |
|
210 test_Equal(ENormalFileMode, fileMode); |
|
211 |
|
212 |
|
213 // Use Case 2.2, Client 2 (Non-Rugged Client) ------------------------------------ |
|
214 test.Printf(_L("Client2 open file in non-Rugged file mode\n")); |
|
215 |
|
216 CreateFile(file2, fileName2, (EFileWrite | EFileSequential | EFileShareAny)); |
|
217 r = TheFs.ControlIo(gDriveNum, EControlIOIsFileSequential, fileName2Pkg, fileModePkg); |
|
218 test_KErrNone(r); |
|
219 test_Equal(ENormalFileMode, fileMode); |
|
220 |
|
221 |
|
222 file1.Close(); |
|
223 file2.Close(); |
|
224 DeleteFileAndDir(fileName2); |
|
225 } |
|
226 |
|
227 |
|
228 |
|
229 void CallTestsL() |
|
230 /* |
|
231 * Start point of T_NONRUGGED |
|
232 */ |
|
233 { |
|
234 #ifndef _DEBUG |
|
235 test.Printf(_L("T_NONRUGGED skipped. To run only on debug builds.\n")); |
|
236 return; |
|
237 #else |
|
238 |
|
239 TInt r = TheFs.CharToDrive(gDriveToTest, gDriveNum); |
|
240 test_KErrNone(r); |
|
241 |
|
242 // Currently only FAT file system supports Rugged drive |
|
243 if (!Is_Fat(TheFs, gDriveNum)) |
|
244 { |
|
245 test.Printf(_L("T_NONRUGGED skipped. Requires FAT filesystem to run.\n")); |
|
246 return; |
|
247 } |
|
248 |
|
249 // Use this to set filesystem to Rugged if it is not set as such |
|
250 #if(0) |
|
251 { |
|
252 // Ensure that the FAT filesystem is Rugged |
|
253 TUint8 ruggedVal = 0; |
|
254 TPtr8 ruggedPkg(&ruggedVal, 1, 1); |
|
255 r = TheFs.ControlIo(gDriveNum, EControlIOIsRuggedFSys, ruggedPkg); |
|
256 test_KErrNone(r); |
|
257 if (!ruggedVal) |
|
258 { |
|
259 r = TheFs.ControlIo(gDriveNumber, KControlIoRuggedOn); |
|
260 test_KErrNone(r); |
|
261 } |
|
262 } |
|
263 #endif |
|
264 |
|
265 // Test to run only on a rugged FAT drive |
|
266 TUint8 ruggedVal = 0; |
|
267 TPtr8 ruggedPkg(&ruggedVal, 1, 1); |
|
268 r = TheFs.ControlIo(gDriveNum, EControlIOIsRuggedFSys, ruggedPkg); |
|
269 test_KErrNone(r); |
|
270 if (!ruggedVal) |
|
271 { |
|
272 test.Printf(_L("T_NONRUGGED skipped. Requires Rugged FAT to run.\n")); |
|
273 return; |
|
274 } |
|
275 |
|
276 test.Start(_L("T_NONRUGGED Test Start")); |
|
277 |
|
278 // Run tests |
|
279 SingleClientTest(); |
|
280 MultipleClientsTest(); |
|
281 |
|
282 // Use this to unset filesystem to non-Rugged if it has been set above |
|
283 #if(0) |
|
284 // Set filesystem back to non-Rugged |
|
285 if (!ruggedVal) |
|
286 { |
|
287 r = TheFs.ControlIo(gDriveNumber, KControlIoRuggedOff); |
|
288 test_KErrNone(r); |
|
289 } |
|
290 #endif |
|
291 |
|
292 test.End(); |
|
293 test.Close(); |
|
294 #endif |
|
295 } |