First public contribution.
1 // Copyright (c) 2007-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\locl\localeutils\T_SURROGATEPAIR.cpp
18 #define __E32TEST_EXTENSION__
24 #include "..\server\t_server.h"
26 RTest test(_L("T_SURROGATEPAIR"));
29 * Helper function to capture and return any MakeFile error code.
31 TInt SurrogatePair_MakeFile(const TDesC& aFileName)
34 TInt r=file.Replace(TheFs,aFileName,0);
40 * Tests given ShortName against LongName and vice versa for a File Entry.
42 void doFileNameTest(const TDesC& aLongName, const TDesC& aShortName)
44 TFileName lgnFullPath;
45 TFileName shnFullPath;
49 TInt r = TheFs.SessionPath(gSessionPath);
51 lgnFullPath = gSessionPath;
52 lgnFullPath += aLongName;
54 MakeFile(lgnFullPath);
57 r = TheFs.GetShortName(lgnFullPath, shn);
59 r = shn.Compare(aShortName);
63 shnFullPath = gSessionPath;
64 shnFullPath += aShortName;
66 r = TheFs.GetLongName(shnFullPath, lgn);
68 r = lgn.Compare(aLongName);
71 test_KErrNone(TheFs.Delete(lgnFullPath));
75 * Tests given ShortName against LongName and vice versa for a Directory Entry.
77 void doDirNameTest(const TDesC& aLongName, const TDesC& aShortName)
79 TBuf<KMaxFileName> longDirNamePath;
80 TBuf<KMaxFileName> shortDirNamePath;
81 TBuf<KMaxFileName> longName;
82 TBuf<KMaxFileName> shortName;
83 longDirNamePath = gSessionPath;
84 longDirNamePath += aLongName;
85 longDirNamePath.Append('\\');
87 // Create new directory and check creation
88 TInt r = TheFs.MkDir(longDirNamePath);
92 r= TheFs.GetDir(longDirNamePath, dumUint, dumUint, dumDir);
98 r = TheFs.GetShortName(longDirNamePath, shortName);
100 r = shortName.Compare(aShortName);
104 shortDirNamePath = gSessionPath;
105 shortDirNamePath += shortName;
106 shortDirNamePath.Append('\\');
107 r = TheFs.GetLongName(shortDirNamePath, longName);
109 r = longName.Compare(aLongName);
112 r = TheFs.RmDir(longDirNamePath);
117 * Tests File entry and Dir entry.
119 void TestConversion(const TDesC& aLongName, const TDesC& aShortName)
121 doFileNameTest(aLongName, aShortName);
122 doDirNameTest(aLongName, aShortName);
126 * Tests different characters for its validity and conversion in absence of cp dll.
127 * Expects ReplacementForUnconvertibleUnicodeCharacters : "_" : UNDERSCORE for all
130 void TestShortNameCharacter()
132 test.Next(_L("++TestShortNameCharacter"));
136 _LIT16(Uni_1, "\x0019.TXT");
137 _LIT16(Uni_1_ShortName, "_.TXT");
138 TestConversion( Uni_1, Uni_1_ShortName);
140 _LIT16(Uni_2, "\x0020.TXT");
141 _LIT(Uni_2_ShortName, "_.TXT");
142 TestConversion( Uni_2, Uni_2_ShortName);
144 _LIT16(Uni_3, "\x0021.TXT");
145 _LIT16(Uni_3_ShortName, "\x0021.TXT");
146 TestConversion( Uni_3, Uni_3_ShortName);
148 _LIT16(Uni_4, "\x0079"); // y lower case
149 _LIT16(Uni_4_ShortName, "\x0059"); // Y upper case
150 TestConversion( Uni_4, Uni_4_ShortName);
152 _LIT16(Uni_5, "\x0080");
153 _LIT16(Uni_5_ShortName, "_");
154 TestConversion( Uni_5, Uni_5_ShortName);
156 _LIT16(Uni_6, "\x0081");
157 _LIT16(Uni_6_ShortName, "_");
158 TestConversion( Uni_6, Uni_6_ShortName);
160 _LIT16(Uni_7, "\x00fe");
161 _LIT16(Uni_7_ShortName, "_");
162 TestConversion( Uni_7, Uni_7_ShortName);
164 _LIT16(Uni_8, "\x00ff");
165 _LIT16(Uni_8_ShortName, "_");
166 TestConversion( Uni_8, Uni_8_ShortName);
169 _LIT16(Uni_9, "\x0100");
170 _LIT16(Uni_9_ShortName, "_");
171 TestConversion( Uni_9, Uni_9_ShortName);
173 _LIT16(Uni_10, "\x0101");
174 _LIT16(Uni_10_ShortName, "_");
175 TestConversion( Uni_10, Uni_10_ShortName);
177 _LIT16(Uni_11, "\x0ffe");
178 _LIT16(Uni_11_ShortName, "_");
179 TestConversion( Uni_11, Uni_11_ShortName);
181 _LIT16(Uni_12, "\x0fff");
182 _LIT16(Uni_12_ShortName, "_");
183 TestConversion( Uni_12, Uni_12_ShortName);
185 _LIT16(Uni_13, "\x1000");
186 _LIT16(Uni_13_ShortName, "_");
187 TestConversion( Uni_13, Uni_13_ShortName);
189 _LIT16(Uni_14, "\x1001");
190 _LIT16(Uni_14_ShortName, "_");
191 TestConversion( Uni_14, Uni_14_ShortName);
193 _LIT16(Uni_15, "\x2999.TXT");
194 _LIT16(Uni_15_ShortName, "_.TXT");
195 TestConversion( Uni_15, Uni_15_ShortName);
197 _LIT16(Uni_16, "\x4E02.TXT");
198 _LIT16(Uni_16_ShortName, "_.TXT");
199 TestConversion( Uni_16, Uni_16_ShortName);
201 _LIT16(Uni_17, "\x4E02.TXT");
202 _LIT(Uni_17_ShortName, "_.TXT");
203 TestConversion( Uni_17, Uni_17_ShortName);
205 _LIT16(Uni_18, "\xfffe");
206 _LIT16(Uni_18_ShortName, "_");
207 TestConversion( Uni_18, Uni_18_ShortName);
209 _LIT16(Uni_19, "\xffff");
210 _LIT16(Uni_19_ShortName, "_");
211 TestConversion( Uni_19, Uni_19_ShortName);
213 // four-byte surrogate pairs
214 _LIT16(Uni_20, "\xd840\xdc00");
215 _LIT16(Uni_20_ShortName, "_");
216 TestConversion( Uni_20, Uni_20_ShortName);
218 _LIT16(Uni_21, "\xd840\xdc01");
219 _LIT16(Uni_21_ShortName, "_");
220 TestConversion( Uni_21, Uni_21_ShortName);
222 _LIT16(Uni_22, "\xD87F\xdffe");
223 _LIT16(Uni_22_ShortName, "_");
224 TestConversion( Uni_22, Uni_22_ShortName);
226 _LIT16(Uni_23, "\xD87F\xdfff");
227 _LIT16(Uni_23_ShortName, "_");
228 TestConversion( Uni_23, Uni_23_ShortName);
231 _LIT16(Uni_24, "\xd840\xddad");
232 _LIT16(Uni_24_ShortName, "_");
233 TestConversion( Uni_24, Uni_24_ShortName);
235 _LIT16(Uni_25, "\xd801\xdd00");
236 _LIT16(Uni_25_ShortName, "_");
237 TestConversion( Uni_25, Uni_25_ShortName);
239 // corrupt surrogate in file name
240 _LIT16(KTest0xD800, "\xD800.TXT");
241 r = SurrogatePair_MakeFile(KTest0xD800);
242 test(r==KErrBadName);
244 // corrupt surrogate in file ext
245 _LIT16(KTest0xD800XT, "\xD684.\xD800XT");
246 r = SurrogatePair_MakeFile(KTest0xD800XT);
247 test(r==KErrBadName);
249 // corrupt surrogate in file ext
250 _LIT16(KTestTX0xD800, "\xD684.TX\xD800");
251 r = SurrogatePair_MakeFile(KTestTX0xD800);
252 test(r==KErrBadName);
254 // corrupt surrogate in file name
255 _LIT16(KTest0xDFFF, "\xDFFF.TXT");
256 r = SurrogatePair_MakeFile(KTest0xDFFF);
257 test(r==KErrBadName);
259 // corrupt surrogate in file ext
260 _LIT16(KTest0xDFFFXT, "\xD684.\xDFFFXT");
261 r = SurrogatePair_MakeFile(KTest0xDFFFXT);
262 test(r==KErrBadName);
264 // corrupt surrogate in file ext
265 _LIT16(KTestTX0xDFFF, "\xD684.TX\xDFFF");
266 r = SurrogatePair_MakeFile(KTestTX0xDFFF);
267 test(r==KErrBadName);
269 test.Next(_L("--TestShortNameCharacter"));
272 void TestVolumeLabel()
274 test.Next(_L("++TestVolumeLabel"));
275 test.Next(_L("Test unicode volume labels"));
277 TInt r = TheFs.SessionPath(gSessionPath);
280 r = TheFs.CharToDrive(gSessionPath[0], driveNum);
283 // Retrieves the original volume label
285 r = TheFs.Volume(vInfo, driveNum);
286 const TInt KVolumeLabelSize = 11;
287 TBuf<KVolumeLabelSize> originalVolumeLabel(vInfo.iName);
289 // Tests setting volume label with 1 byte characters
290 _LIT(K1ByteVolumeLabel, "\x0079\x0079\x0079");
291 _LIT(K1ByteVolumeLabel_ShortName, "\x0079\x0079\x0079");
293 r = TheFs.SetVolumeLabel(K1ByteVolumeLabel, driveNum);
295 r = TheFs.Volume(vInfo, driveNum);
297 r = vInfo.iName.Compare(K1ByteVolumeLabel_ShortName);
300 // Tests setting volume label with 2 byte characters
301 _LIT(K2ByteVolumeLabel, "\x65B0\x65B0\x65B0");
302 _LIT(K2ByteVolumeLabel_ShortName, "___");
304 r = TheFs.SetVolumeLabel(K2ByteVolumeLabel, driveNum);
306 r = TheFs.Volume(vInfo, driveNum);
308 r = vInfo.iName.Compare(K2ByteVolumeLabel_ShortName);
311 // Tests setting volume label with surrogate pair
312 _LIT(KTestVolumeLabelSurrogatePair1, "\xD846\xDF1D\x0041\x0042");
313 _LIT(KTestVolumeLabelSurrogatePair1_ShortName, "_AB");
315 r = TheFs.SetVolumeLabel(KTestVolumeLabelSurrogatePair1, driveNum);
317 r = TheFs.Volume(vInfo, driveNum);
319 r = vInfo.iName.Compare(KTestVolumeLabelSurrogatePair1_ShortName);
322 _LIT(KTestVolumeLabelSurrogatePair2, "\x0041\x0042\xD846\xDF1D");
323 _LIT(KTestVolumeLabelSurrogatePair2_ShortName, "AB_");
325 r = TheFs.SetVolumeLabel(KTestVolumeLabelSurrogatePair2, driveNum);
327 r = TheFs.Volume(vInfo, driveNum);
329 r = vInfo.iName.Compare(KTestVolumeLabelSurrogatePair2_ShortName);
332 // Sets back the original volume label
333 r = TheFs.SetVolumeLabel(originalVolumeLabel, driveNum);
336 test.Next(_L("--TestVolumeLabel"));
339 void TestConsistentShortNameGeneration()
341 test.Next(_L("++TestConsistentShortNameGeneration"));
342 test.Next(_L("Test consistent short name generation"));
344 //unicode characters.
345 _LIT(KTestFileName1, "a\x65B0(bcd)");
346 _LIT(KTestFileName1_ShortName, "A_(BCD)");
347 _LIT(KTestFileName2, "ab\x65B0(cdef)");
348 _LIT(KTestFileName2_ShortName, "AB_(CD~1");
349 _LIT(KTestFileName3, "abc\x65B0(def)");
350 _LIT(KTestFileName3_ShortName, "ABC_(D~1");
351 _LIT(KTestFileName4, "abcd\x65B0(ef)");
352 _LIT(KTestFileName4_ShortName, "ABCD_(~1");
353 _LIT(KTestFileName5, "abcde\x65B0(f)");
354 _LIT(KTestFileName5_ShortName, "ABCDE_~1");
355 _LIT(KTestFileNameSurrogatePair1, "\x0041\x0308\x006F\xD846\xDF1D\x0042");
356 _LIT(KTestFileNameSurrogatePair1_ShortName, "A_O_B");
357 _LIT(KTestFileNameSurrogatePair2, "\xD846\xDF1D\x0041\x0042");
358 _LIT(KTestFileNameSurrogatePair2_ShortName, "_AB");
359 _LIT(KTestFileNameSurrogatePair3, "\x0041\x0042\xD846\xDF1D");
360 _LIT(KTestFileNameSurrogatePair3_ShortName, "AB_");
362 // Test file creation and long/short name generation
363 TestConversion(KTestFileName1, KTestFileName1_ShortName);
364 TestConversion(KTestFileName2, KTestFileName2_ShortName);
365 TestConversion(KTestFileName3, KTestFileName3_ShortName);
366 TestConversion(KTestFileName4, KTestFileName4_ShortName);
367 TestConversion(KTestFileName5, KTestFileName5_ShortName);
368 TestConversion(KTestFileNameSurrogatePair1, KTestFileNameSurrogatePair1_ShortName);
369 TestConversion(KTestFileNameSurrogatePair2, KTestFileNameSurrogatePair2_ShortName);
370 TestConversion(KTestFileNameSurrogatePair3, KTestFileNameSurrogatePair3_ShortName);
372 test.Next(_L("--TestConsistentShortNameGeneration"));
375 void TestConsistentShortNameExtGeneration()
377 test.Next(_L("++TestConsistentShortNameExtGeneration"));
378 test.Next(_L("Test consistent short name extensions are generated"));
380 // File names will be used for testing boundaries
381 _LIT(KTestFileNameExt1, "abcdefg.\xFFFF");
382 _LIT(KTestFileNameExt1_ShortName, "ABCDEFG._");
383 _LIT(KTestFileNameExt2, "abcdefg.t_");
384 _LIT(KTestFileNameExt2_ShortName, "ABCDEFG.T_");
385 _LIT(KTestFileNameExt3, "abcdefg.\xFFFFt");
386 _LIT(KTestFileNameExt3_ShortName, "ABCDEFG._T");
387 _LIT(KTestFileNameExt4, "abcdefg.\xFFFF\xFFFF");
388 _LIT(KTestFileNameExt4_ShortName, "ABCDEFG.__");
389 _LIT(KTestFileNameExtSurrogatePair1, "ABCDEFG.\xD846\xDF1D\x0041");
390 _LIT(KTestFileNameExtSurrogatePair1_ShortName, "ABCDEFG._A");
391 _LIT(KTestFileNameExtSurrogatePair2, "ABCDEFG.\x0041\xD846\xDF1D");
392 _LIT(KTestFileNameExtSurrogatePair2_ShortName, "ABCDEFG.A_");
394 // Test file creation and long/short name generation
395 TestConversion(KTestFileNameExt1, KTestFileNameExt1_ShortName);
396 TestConversion(KTestFileNameExt2, KTestFileNameExt2_ShortName);
397 TestConversion(KTestFileNameExt3, KTestFileNameExt3_ShortName);
398 TestConversion(KTestFileNameExt4, KTestFileNameExt4_ShortName);
399 TestConversion(KTestFileNameExtSurrogatePair1, KTestFileNameExtSurrogatePair1_ShortName);
400 TestConversion(KTestFileNameExtSurrogatePair2, KTestFileNameExtSurrogatePair2_ShortName);
402 test.Next(_L("--TestConsistentShortNameExtGeneration"));
405 void TestDuplicateLongFileNames()
407 test.Next(_L("++TestDuplicateLongFileNames"));
408 test.Next(_L("Testing tilde and numbers (\"~n\") are applied correctly for multiple long-named files"));
410 // These are to test "~1", "~2" behaviours when the first 8 bytes of new files
411 // are identical with existing files
412 _LIT(KTestFileName1, "ABCD\xFFFE(A).TXT");
413 _LIT(KTestFileName1_ShortName, "ABCD_(A).TXT");
414 _LIT(KTestFileName2, "ABCD\xFFFE(AB).TXT");
415 _LIT(KTestFileName2_ShortName, "ABCD_(~1.TXT");
416 _LIT(KTestFileName3, "ABCD\xFFFE(ABC).TXT");
417 _LIT(KTestFileName3_ShortName, "ABCD_(~2.TXT");
418 _LIT(KTestFileNameSurrogatePair1, "ABCD\xD846\xDF1D(ABC).TXT");
419 _LIT(KTestFileNameSurrogatePair1_ShortName, "ABCD_(~3.TXT");
420 _LIT(KTestFileNameSurrogatePair2, "ABCD\xD846\xDF1D(DEF).TXT");
421 _LIT(KTestFileNameSurrogatePair2_ShortName, "ABCD_(~4.TXT");
424 MakeFile(KTestFileName1);
425 TInt r = TheFs.GetShortName(KTestFileName1, sn);
427 r = sn.Compare(KTestFileName1_ShortName);
430 MakeFile(KTestFileName2);
431 r = TheFs.GetShortName(KTestFileName2, sn);
433 r = sn.Compare(KTestFileName2_ShortName);
436 MakeFile(KTestFileName3);
437 r = TheFs.GetShortName(KTestFileName3, sn);
439 r = sn.Compare(KTestFileName3_ShortName);
442 MakeFile(KTestFileNameSurrogatePair1);
443 r = TheFs.GetShortName(KTestFileNameSurrogatePair1, sn);
445 r = sn.Compare(KTestFileNameSurrogatePair1_ShortName);
448 MakeFile(KTestFileNameSurrogatePair2);
449 r = TheFs.GetShortName(KTestFileNameSurrogatePair2, sn);
451 r = sn.Compare(KTestFileNameSurrogatePair2_ShortName);
454 test_KErrNone(TheFs.Delete(KTestFileName1));
455 test_KErrNone(TheFs.Delete(KTestFileName2));
456 test_KErrNone(TheFs.Delete(KTestFileName3));
457 test_KErrNone(TheFs.Delete(KTestFileNameSurrogatePair1));
458 test_KErrNone(TheFs.Delete(KTestFileNameSurrogatePair2));
460 test.Next(_L("--TestDuplicateLongFileNames"));
463 void TestDuplicateLongDirNames()
465 test.Next(_L("++TestDuplicateLongDirNames"));
466 test.Next(_L("Testing tilde and number appended correctly for duplicate long name dirs"));
468 TheFs.SessionPath(gSessionPath);
470 // These are to test "~1", "~2" behaviours when the first 8 bytes of new directories
471 // are identical with existing directories
472 _LIT(KTestDirName1, "\\F32-TST\\T_SURROGATEPAIR\\ABCD\xFFFE(A)\\");
473 _LIT(KTestDirName1_ShortName, "ABCD_(A)");
474 _LIT(KTestDirName2, "\\F32-TST\\T_SURROGATEPAIR\\ABCD\xFFFE(AB)\\");
475 _LIT(KTestDirName2_ShortName, "ABCD_(~1");
476 _LIT(KTestDirName3, "\\F32-TST\\T_SURROGATEPAIR\\ABCD\xFFFE(ABC)\\");
477 _LIT(KTestDirName3_ShortName, "ABCD_(~2");
478 _LIT(KTestDirNameSurrogatePair1, "\\F32-TST\\T_SURROGATEPAIR\\ABCD\xD846\xDF1D(ABCD)\\");
479 _LIT(KTestDirNameSurrogatePair1_ShortName, "ABCD_(~3");
480 _LIT(KTestDirNameSurrogatePair2, "\\F32-TST\\T_SURROGATEPAIR\\ABCD\xD846\xDF1D(ABCDE)\\");
481 _LIT(KTestDirNameSurrogatePair2_ShortName, "ABCD_(~4");
484 MakeDir(KTestDirName1);
485 TInt r = TheFs.GetShortName(KTestDirName1, sn);
487 r = sn.Compare(KTestDirName1_ShortName);
490 MakeDir(KTestDirName2);
491 r = TheFs.GetShortName(KTestDirName2, sn);
493 r = sn.Compare(KTestDirName2_ShortName);
496 MakeDir(KTestDirName3);
497 r = TheFs.GetShortName(KTestDirName3, sn);
499 r = sn.Compare(KTestDirName3_ShortName);
502 MakeDir(KTestDirNameSurrogatePair1);
503 r = TheFs.GetShortName(KTestDirNameSurrogatePair1, sn);
505 r = sn.Compare(KTestDirNameSurrogatePair1_ShortName);
508 MakeDir(KTestDirNameSurrogatePair2);
509 r = TheFs.GetShortName(KTestDirNameSurrogatePair2, sn);
511 r = sn.Compare(KTestDirNameSurrogatePair2_ShortName);
514 test_KErrNone(TheFs.RmDir(KTestDirName1));
515 test_KErrNone(TheFs.RmDir(KTestDirName2));
516 test_KErrNone(TheFs.RmDir(KTestDirName3));
517 test_KErrNone(TheFs.RmDir(KTestDirNameSurrogatePair1));
518 test_KErrNone(TheFs.RmDir(KTestDirNameSurrogatePair2));
520 test.Next(_L("--TestDuplicateLongDirNames"));
523 void CallTestsL(void)
527 test.Start(_L("Starting T_SURROGATEPAIR tests"));
529 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
531 // Test only runs on Fat file systems
532 TheFs.SessionPath(gSessionPath);
533 TInt driveNum = CurrentDrive();
535 TInt r = TheFs.FileSystemName(name, driveNum);
538 if (name.Compare(_L("Fat")) != 0)
540 test.Printf(_L("Test only runs on 'Fat' drives"));
544 // Check for the default implementation
545 // Disables codepage dll implementation of LocaleUtils functions
546 r = TheFs.ControlIo(driveNum, KControlIoDisableFatUtilityFunctions);
549 CreateTestDirectory(_L("\\F32-TST\\T_SURROGATEPAIR\\"));
552 TestShortNameCharacter();
553 TestConsistentShortNameGeneration();
554 TestConsistentShortNameExtGeneration();
555 TestDuplicateLongFileNames();
556 TestDuplicateLongDirNames();
558 DeleteTestDirectory();
560 // Disables codepage dll implementation of LocaleUtils functions for other base tests
561 r = TheFs.ControlIo(driveNum, KControlIoDisableFatUtilityFunctions);
567 test.Printf(_L("Drive %C: is not ready!"), 'A'+driveNum);
571 test.Printf(_L("Test only runs on DEBUG builds, see test logs of debug builds for details."));
572 #endif // _DEBUG) || _DEBUG_RELEASE