|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "t_fat32clusterbound.h" |
|
21 |
|
22 /** |
|
23 Class Constructor |
|
24 */ |
|
25 CBaseTestFat32ClusterBound::CBaseTestFat32ClusterBound() |
|
26 { |
|
27 SetTestStepName(KTestStepClusterBound); |
|
28 } |
|
29 |
|
30 /** |
|
31 Class Destructor |
|
32 */ |
|
33 CBaseTestFat32ClusterBound::~CBaseTestFat32ClusterBound() |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 /** |
|
39 This test should be performed once the disk has been filled to its max capacity. |
|
40 Obtains the cluster bounds action from the configuration file and calls the function |
|
41 that is required to be carried out |
|
42 |
|
43 @return EPass if test passes and EFail if test fails |
|
44 */ |
|
45 TVerdict CBaseTestFat32ClusterBound::doTestStepL() |
|
46 { |
|
47 SetTestStepResult(EFail); |
|
48 TInt r; |
|
49 TBufC<20> clusterAction; |
|
50 TPtrC16 clusteraction = clusterAction; |
|
51 _LIT(KClusterAction,"ClusterAction"); |
|
52 TBool alright = GetStringFromConfig(ConfigSection(), KClusterAction, clusteraction); |
|
53 if (alright) |
|
54 { |
|
55 if (clusteraction == _L("WriteToFile")) |
|
56 { |
|
57 r = TestClusterBoundsWriteFile(); |
|
58 if (r != KErrNone) |
|
59 { |
|
60 INFO_PRINTF1(_L("ClusterAction:WriteToFile failed")); |
|
61 SetTestStepResult(EFail); |
|
62 } |
|
63 else |
|
64 { |
|
65 INFO_PRINTF1(_L("ClusterAction:WriteToFile passed")); |
|
66 SetTestStepResult(EPass); |
|
67 } |
|
68 } |
|
69 if (clusteraction == _L("CreateFiles")) |
|
70 { |
|
71 r = TestClusterBoundsCreateFiles(); |
|
72 if (r != KErrNone) |
|
73 { |
|
74 INFO_PRINTF1(_L("ClusterAction:CreateFiles failed")); |
|
75 SetTestStepResult(EFail); |
|
76 } |
|
77 else |
|
78 { |
|
79 INFO_PRINTF1(_L("ClusterAction:CreateFiles passed")); |
|
80 SetTestStepResult(EPass); |
|
81 } |
|
82 } |
|
83 } |
|
84 else |
|
85 { |
|
86 INFO_PRINTF1(_L("No ClusterAction specified in ini file")); |
|
87 SetTestStepResult(EFail); |
|
88 } |
|
89 return TestStepResult(); |
|
90 } |
|
91 |
|
92 /** |
|
93 Attepts to access out of bounds clusters by creating another file and |
|
94 attempting to write to it. |
|
95 |
|
96 @return KErrNone if successfull, otherwise one of the other system-wide |
|
97 error codes. |
|
98 */ |
|
99 TInt CBaseTestFat32ClusterBound::TestClusterBoundsWriteFile() |
|
100 { |
|
101 TInt r; |
|
102 TVolumeInfo iInfo; |
|
103 |
|
104 TInt freeSpace; |
|
105 RFile rFile; |
|
106 |
|
107 r = iTheFs.Volume(iInfo, CurrentDrive()); |
|
108 if(r != KErrNone) |
|
109 { |
|
110 INFO_PRINTF2(_L("Unable to obtain the volume information, error = %d"), r); |
|
111 return r; |
|
112 } |
|
113 freeSpace = iInfo.iFree; |
|
114 TBuf8<100> buffer3(freeSpace + 1); |
|
115 r = rFile.Replace(iTheFs, _L("TESTClusterBound.txt"), EFileWrite); |
|
116 if(r != KErrNone) |
|
117 { |
|
118 INFO_PRINTF2(_L("Unable to create the file, error = %d"), r); |
|
119 return r; |
|
120 } |
|
121 r = rFile.Write(buffer3,freeSpace + 1); |
|
122 if (r == KErrDiskFull) |
|
123 { |
|
124 INFO_PRINTF1(_L("Disk is Full - Attempting to access out of bounds clusters returns the correct error value")); |
|
125 rFile.Close(); |
|
126 return KErrNone; |
|
127 } |
|
128 else |
|
129 { |
|
130 INFO_PRINTF2(_L("Attempting to access out of bounds clusters returns the incorrect error value %d"), r); |
|
131 rFile.Close(); |
|
132 return r; |
|
133 } |
|
134 |
|
135 } |
|
136 |
|
137 /** |
|
138 Attepts to access out of bounds clusters by creating empty files to fill |
|
139 the root directory and following this, attempting to create another empty file |
|
140 |
|
141 @return KErrNone if successfull, otherwise one of the other system-wide |
|
142 error codes. |
|
143 */ |
|
144 TInt CBaseTestFat32ClusterBound::TestClusterBoundsCreateFiles() |
|
145 { |
|
146 RFile rFile; |
|
147 _LIT(KFileName, "File%d.txt"); |
|
148 |
|
149 TInt sizeOfShortDir = 16 * 4; //Short dir is 64 bytes long |
|
150 TInt bytesPerSector = iBPB_BytsPerSec; |
|
151 TInt sizeOfCluster = iBPB_SecPerClus * bytesPerSector; |
|
152 TInt filesToCreate = sizeOfCluster / sizeOfShortDir; |
|
153 filesToCreate = filesToCreate - 1; |
|
154 |
|
155 TInt r; |
|
156 TInt i; |
|
157 for (i = 0; i < filesToCreate; i++) |
|
158 { |
|
159 TBuf<20> fileName; |
|
160 TInt fileNumber = i + 1; |
|
161 fileName.Format(KFileName, fileNumber); |
|
162 r= rFile.Replace(iTheFs,fileName , EFileWrite); |
|
163 if (r == KErrDiskFull) |
|
164 break; |
|
165 rFile.Close(); |
|
166 } |
|
167 |
|
168 |
|
169 r = rFile.Replace(iTheFs, _L("TFile.txt") , EFileWrite); |
|
170 if (r == KErrDiskFull) |
|
171 { |
|
172 INFO_PRINTF1(_L("Attempting to access out of bounds clusters returns the correct error value")); |
|
173 return KErrNone; |
|
174 } |
|
175 else |
|
176 { |
|
177 INFO_PRINTF2(_L("Attempting to access out of bounds clusters returns the incorrect error value %d"), r); |
|
178 return r; |
|
179 } |
|
180 } |