author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32test\server\t_fnames.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include "t_server.h" |
|
22 |
||
23 |
GLDEF_D RTest test(_L("T_FNAMES")); |
|
24 |
||
25 |
LOCAL_C void TestReturnValue(TInt aReturnValue,TInt anExpectedValue) |
|
26 |
// |
|
27 |
// Test the return value |
|
28 |
// |
|
29 |
{ |
|
30 |
||
31 |
if (aReturnValue==anExpectedValue) |
|
32 |
return; |
|
33 |
test.Printf(_L("ERROR: returnVal=%d, expectedVal=%d\n"),aReturnValue,anExpectedValue); |
|
34 |
test(0); |
|
35 |
//test.Printf(_L("Press any key to continue\n")); |
|
36 |
//test.Getch(); |
|
37 |
} |
|
38 |
||
39 |
LOCAL_C void DoTestName(const TDesC& aName,TInt anError) |
|
40 |
// |
|
41 |
// Check errors returned |
|
42 |
// |
|
43 |
{ |
|
44 |
||
45 |
TBuf<32> goodName=_L("\\GOODNAME.TXT"); |
|
46 |
TBuf<32> badName=_L("\\< > : \" / |"); |
|
47 |
TParse parser; |
|
48 |
TInt r=parser.Set(aName,NULL,NULL); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
test_Value(r, r == KErrNone || r==anError); |
0 | 50 |
goodName.Insert(0,parser.Drive()); |
51 |
badName.Insert(0,parser.Drive()); |
|
52 |
||
53 |
||
54 |
TBuf<KMaxFileName> name; // We need an 8-bit name to test RFs::GetLongName() in |
|
55 |
name.Copy(aName); // both builds |
|
56 |
||
57 |
TFileName dummy; // To use as an argument to RFs::GetLongName() will store the |
|
58 |
TBuf<12> dummyShortName; // To use as an argument to RFs::GetShortName() |
|
59 |
TUint dumVal; |
|
60 |
TTime dumTime; |
|
61 |
TBool dumAnswer; |
|
62 |
TEntry dumEntry; |
|
63 |
CDir* dumDir; |
|
64 |
TUidType dumUid; |
|
65 |
TInt dumInt=0; |
|
66 |
TFileName badPath=aName; |
|
67 |
badPath.Append(_L("\\")); |
|
68 |
||
69 |
// Test MKDIR with filename containing \000 |
|
70 |
TBuf<32> emptyName; |
|
71 |
emptyName.Format(_L("\\%c\\"),0); |
|
72 |
emptyName.Insert(0,parser.Drive()); |
|
73 |
r=TheFs.MkDir(emptyName); |
|
74 |
TestReturnValue(r, anError); |
|
75 |
emptyName.Format(_L("\\Big%cGreen\\"),0); |
|
76 |
emptyName.Insert(0,parser.Drive()); |
|
77 |
r=TheFs.MkDir(emptyName); |
|
78 |
TestReturnValue(r, anError); |
|
79 |
r=TheFs.SetSessionPath(badPath); |
|
80 |
TestReturnValue(r,KErrBadName); // Do not check drives |
|
81 |
r=TheFs.MkDir(badPath); |
|
82 |
TestReturnValue(r,anError); |
|
83 |
r=TheFs.MkDirAll(badPath); |
|
84 |
TestReturnValue(r,anError); |
|
85 |
r=TheFs.RmDir(badPath); |
|
86 |
TestReturnValue(r,anError); |
|
87 |
r=TheFs.GetDir(aName,dumInt,dumInt,dumDir); |
|
88 |
TestReturnValue(r,anError); |
|
89 |
r=TheFs.GetDir(aName,dumInt,dumInt,dumDir,dumDir); |
|
90 |
TestReturnValue(r,anError); |
|
91 |
r=TheFs.GetDir(aName,dumUid,dumInt,dumDir); |
|
92 |
TestReturnValue(r,anError); |
|
93 |
r=TheFs.Delete(aName); |
|
94 |
TestReturnValue(r,anError); |
|
95 |
||
96 |
r=TheFs.Rename(aName,goodName); |
|
97 |
TestReturnValue(r,anError); |
|
98 |
r=TheFs.Rename(aName,badName); |
|
99 |
TestReturnValue(r,anError); |
|
100 |
r=TheFs.Rename(goodName,aName); |
|
101 |
TestReturnValue(r,anError); |
|
102 |
r=TheFs.Rename(badName,aName); |
|
103 |
TestReturnValue(r,anError); |
|
104 |
||
105 |
r=TheFs.Replace(aName,goodName); |
|
106 |
TestReturnValue(r,anError); |
|
107 |
r=TheFs.Replace(aName,badName); |
|
108 |
TestReturnValue(r,anError); |
|
109 |
r=TheFs.Replace(goodName,aName); |
|
110 |
TestReturnValue(r,anError); |
|
111 |
r=TheFs.Replace(badName,aName); |
|
112 |
TestReturnValue(r,anError); |
|
113 |
||
114 |
r=TheFs.Att(aName,dumVal); |
|
115 |
TestReturnValue(r,anError); |
|
116 |
r=TheFs.SetAtt(aName,dumInt,dumInt); |
|
117 |
TestReturnValue(r,anError); |
|
118 |
r=TheFs.Modified(aName,dumTime); |
|
119 |
TestReturnValue(r,anError); |
|
120 |
r=TheFs.SetModified(aName,dumTime); |
|
121 |
TestReturnValue(r,anError); |
|
122 |
r=TheFs.Entry(aName,dumEntry); |
|
123 |
TestReturnValue(r,anError); |
|
124 |
r=TheFs.SetEntry(aName,dumTime,dumInt,dumInt); |
|
125 |
TestReturnValue(r,anError); |
|
126 |
r=TheFs.IsFileOpen(aName,dumAnswer); |
|
127 |
TestReturnValue(r,anError); |
|
128 |
||
129 |
r=TheFs.GetShortName(aName,dummyShortName); |
|
130 |
TestReturnValue(r,anError); |
|
131 |
r=TheFs.GetLongName(name,dummy); |
|
132 |
TestReturnValue(r,anError); |
|
133 |
||
134 |
RFile f; |
|
135 |
r=f.Open(TheFs,aName,EFileWrite); |
|
136 |
TestReturnValue(r,anError); |
|
137 |
r=f.Create(TheFs,aName,EFileWrite); |
|
138 |
TestReturnValue(r,anError); |
|
139 |
r=f.Replace(TheFs,aName,EFileWrite); |
|
140 |
TestReturnValue(r,anError); |
|
141 |
RDir d; |
|
142 |
r=d.Open(TheFs,aName,KEntryAttNormal); |
|
143 |
TestReturnValue(r,anError); |
|
144 |
r=d.Open(TheFs,aName,dumUid); |
|
145 |
TestReturnValue(r,anError); |
|
146 |
} |
|
147 |
||
148 |
||
149 |
//------------------------------------------- |
|
150 |
||
151 |
/** |
|
152 |
Testing the case when the full length of the directory name is shorter than KMaxFileName but |
|
153 |
on the emulator because of the conversion epoc "c:\something" to e.g. "d:\epoc32\release\winscw\c\something" |
|
154 |
it gets exactly KMaxFileName lengths, which causes +-1 syndrom problems. |
|
155 |
*/ |
|
156 |
LOCAL_C void DoTestLongDirName1(void) |
|
157 |
{ |
|
158 |
RFs rfs; |
|
159 |
RDir rDir; |
|
160 |
||
161 |
CleanupClosePushL(rfs); |
|
162 |
CleanupClosePushL(rDir); |
|
163 |
||
164 |
test(rfs.Connect() == KErrNone); |
|
165 |
||
166 |
TPtrC dirName(_L("c:\\mainTestDir\\test000\\1a34567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890\\")); |
|
167 |
||
168 |
//-- TParse shall work correctly |
|
169 |
TParse parse; |
|
170 |
TInt err = parse.Set(dirName,NULL,NULL); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
test_KErrNone(err); |
0 | 172 |
|
173 |
//-- try to access a directory with a long name. This just shall not panic. |
|
174 |
//-- The return code can be any, on the emulator it's very likely to be KErrBadname |
|
175 |
err = rDir.Open(rfs,dirName,EFileStream|EFileWrite|EFileShareExclusive); |
|
176 |
||
177 |
CleanupStack::PopAndDestroy(2); // rfs, rDir |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
Testing the case of passing a directory name longer than KMaxFileName to the file server. |
|
182 |
KErrBadName shall be the result |
|
183 |
*/ |
|
184 |
LOCAL_C void DoTestLongDirName2(void) |
|
185 |
{ |
|
186 |
RFs rfs; |
|
187 |
TBool bDirExisted=EFalse; |
|
188 |
||
189 |
CleanupClosePushL(rfs); |
|
190 |
test(rfs.Connect() == KErrNone); |
|
191 |
||
192 |
//-- create a dir c:\a |
|
193 |
_LIT(dirName, "C:\\a\\"); |
|
194 |
TInt err = rfs.MkDir(dirName); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
test_Value(err, err == KErrNone || err == KErrAlreadyExists); |
0 | 196 |
|
197 |
if(err == KErrAlreadyExists) |
|
198 |
bDirExisted = ETrue; |
|
199 |
||
200 |
//-- dir name longer than KMaxFileName |
|
201 |
_LIT(longDirName, "C:\\a\\longnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongname\\"); |
|
202 |
//TInt nLen = dirName().Length(); |
|
203 |
||
204 |
//-- try to create a directory with a very long name, checking that it doesn't get truncated to the "c:\a" |
|
205 |
err = rfs.MkDir(longDirName); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
test_Value(err, err == KErrBadName); |
0 | 207 |
|
208 |
//-- clean up, remove created directory, otherwise some ill-designed tests can fail |
|
209 |
if(!bDirExisted) |
|
210 |
rfs.RmDir(dirName); |
|
211 |
||
212 |
CleanupStack::PopAndDestroy(1); // rfs |
|
213 |
} |
|
214 |
||
215 |
||
216 |
//------------------------------------------- |
|
217 |
||
218 |
GLDEF_C void CallTestsL() |
|
219 |
// |
|
220 |
// Check illegal chars |
|
221 |
// |
|
222 |
{ |
|
223 |
||
224 |
test.Next(_L("Check bad filenames return KErrBadName")); |
|
225 |
||
226 |
DoTestName(_L("\\Name(1/12/97)"),KErrBadName); |
|
227 |
DoTestName(_L("\\Na>me"),KErrBadName); |
|
228 |
DoTestName(_L("\\<Name(1/12/97)"),KErrBadName); |
|
229 |
DoTestName(_L("\\Name:"),KErrBadName); |
|
230 |
DoTestName(_L("\\Na\"me"),KErrBadName); |
|
231 |
DoTestName(_L("\\|"),KErrBadName); |
|
232 |
DoTestName(_L("\\ \\ "),KErrBadName); |
|
233 |
DoTestName(_L("\\:C:"),KErrBadName); |
|
234 |
||
235 |
test.Next(_L("Check bad paths return KErrBadName")); |
|
236 |
||
237 |
DoTestName(_L("\\asdf\\Name(1/12/97)\\asdf.txt"),KErrBadName); |
|
238 |
DoTestName(_L("\\asdf\\Na>me\\asdf.txt"),KErrBadName); |
|
239 |
DoTestName(_L("\\asdf\\<Name(1/12/97)\\asdf.txt"),KErrBadName); |
|
240 |
DoTestName(_L("\\asdf\\Name:\\asdf.txt"),KErrBadName); |
|
241 |
DoTestName(_L("\\asdf\\Na\"me\\asdf.txt"),KErrBadName); |
|
242 |
DoTestName(_L("\\asdf\\|\\asdf.txt"),KErrBadName); |
|
243 |
DoTestName(_L("\\asdf\\ \\asdf.txt"),KErrBadName); |
|
244 |
||
245 |
test.Next(_L("Check directory gets checked first")); |
|
246 |
||
247 |
TInt expectedError; |
|
248 |
expectedError=KErrNotReady; |
|
249 |
||
250 |
//The intention here is that even though these are bad file names, the |
|
251 |
//drive it's referencing is not being used. Hence the first error caught |
|
252 |
//will be KErrNotReady, not KErrBadName. If S becomes a valid drive letter |
|
253 |
//and you run this test on that drive, it'll fail with KErrBadName. So |
|
254 |
//you'll need to move the drive letter to an unused one. |
|
255 |
DoTestName(_L("S:\\Name(1/12/97)"),expectedError); |
|
256 |
DoTestName(_L("S:\\Na>me"),expectedError); |
|
257 |
DoTestName(_L("S:\\<Name(1/12/97)"),expectedError); |
|
258 |
DoTestName(_L("S:\\Name:"),expectedError); |
|
259 |
DoTestName(_L("S:\\Na\"me"),expectedError); |
|
260 |
DoTestName(_L("S:\\|"),expectedError); |
|
261 |
DoTestName(_L("S:\\ \\>"),expectedError); |
|
262 |
DoTestName(_L("S:\\asdf\\Name(1/12/97)\\asdf.txt"),expectedError); |
|
263 |
DoTestName(_L("S:\\asdf\\Na>me\\asdf.txt"),expectedError); |
|
264 |
DoTestName(_L("S:\\asdf\\<Name(1/12/97)\\asdf.txt"),expectedError); |
|
265 |
DoTestName(_L("S:\\asdf\\Name:\\asdf.txt"),expectedError); |
|
266 |
DoTestName(_L("S:\\asdf\\Na\"me\\asdf.txt"),expectedError); |
|
267 |
DoTestName(_L("S:\\asdf\\|\\asdf.txt"),expectedError); |
|
268 |
DoTestName(_L("S:\\asdf\\ \\asdf.txt"),expectedError); |
|
269 |
||
270 |
test.Next(_L("Check access to the directory with a long name")); |
|
271 |
DoTestLongDirName1(); |
|
272 |
||
273 |
test.Next(_L("Check creating a directory longer than 256 symbols")); |
|
274 |
DoTestLongDirName2(); |
|
275 |
||
276 |
||
277 |
} |