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