Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_fnames.cpp
22 GLDEF_D RTest test(_L("T_FNAMES"));
24 LOCAL_C void TestReturnValue(TInt aReturnValue,TInt anExpectedValue)
26 // Test the return value
30 if (aReturnValue==anExpectedValue)
32 test.Printf(_L("ERROR: returnVal=%d, expectedVal=%d\n"),aReturnValue,anExpectedValue);
34 //test.Printf(_L("Press any key to continue\n"));
38 LOCAL_C void DoTestName(const TDesC& aName,TInt anError)
40 // Check errors returned
44 TBuf<32> goodName=_L("\\GOODNAME.TXT");
45 TBuf<32> badName=_L("\\< > : \" / |");
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());
53 TBuf<KMaxFileName> name; // We need an 8-bit name to test RFs::GetLongName() in
54 name.Copy(aName); // both builds
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()
65 TFileName badPath=aName;
66 badPath.Append(_L("\\"));
68 // Test MKDIR with filename containing \000
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);
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);
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);
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);
128 r=TheFs.GetShortName(aName,dummyShortName);
129 TestReturnValue(r,anError);
130 r=TheFs.GetLongName(name,dummy);
131 TestReturnValue(r,anError);
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);
141 r=d.Open(TheFs,aName,KEntryAttNormal);
142 TestReturnValue(r,anError);
143 r=d.Open(TheFs,aName,dumUid);
144 TestReturnValue(r,anError);
148 //-------------------------------------------
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.
155 LOCAL_C void DoTestLongDirName1(void)
160 CleanupClosePushL(rfs);
161 CleanupClosePushL(rDir);
163 test(rfs.Connect() == KErrNone);
165 TPtrC dirName(_L("c:\\mainTestDir\\test000\\1a34567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890123456789012345678901234567890 1234567890\\"));
167 //-- TParse shall work correctly
169 TInt err = parse.Set(dirName,NULL,NULL);
170 test( err == KErrNone );
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);
176 CleanupStack::PopAndDestroy(2); // rfs, rDir
180 Testing the case of passing a directory name longer than KMaxFileName to the file server.
181 KErrBadName shall be the result
183 LOCAL_C void DoTestLongDirName2(void)
186 TBool bDirExisted=EFalse;
188 CleanupClosePushL(rfs);
189 test(rfs.Connect() == KErrNone);
191 //-- create a dir c:\a
192 _LIT(dirName, "C:\\a\\");
193 TInt err = rfs.MkDir(dirName);
194 test(err == KErrNone || err == KErrAlreadyExists);
196 if(err == KErrAlreadyExists)
199 //-- dir name longer than KMaxFileName
200 _LIT(longDirName, "C:\\a\\longnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongname\\");
201 //TInt nLen = dirName().Length();
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);
207 //-- clean up, remove created directory, otherwise some ill-designed tests can fail
211 CleanupStack::PopAndDestroy(1); // rfs
215 //-------------------------------------------
217 GLDEF_C void CallTestsL()
219 // Check illegal chars
223 test.Next(_L("Check bad filenames return KErrBadName"));
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);
234 test.Next(_L("Check bad paths return KErrBadName"));
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);
244 test.Next(_L("Check directory gets checked first"));
247 expectedError=KErrNotReady;
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);
269 test.Next(_L("Check access to the directory with a long name"));
270 DoTestLongDirName1();
272 test.Next(_L("Check creating a directory longer than 256 symbols"));
273 DoTestLongDirName2();