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