summaryrefslogtreecommitdiff
path: root/indra/llfilesystem/tests/lldir_test.cpp
blob: 6e191ad096da92d5151a0fcc3bb817be21752356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/**
 * @file lldir_test.cpp
 * @date 2008-05
 * @brief LLDir test cases.
 *
 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "llstring.h"
#include "tests/StringVec.h"
#include "../lldir.h"
#include "../lldiriterator.h"

#include "../test/lltut.h"
#include "stringize.h"
#include <boost/assign/list_of.hpp>

using boost::assign::list_of;

// We use ensure_equals(..., vec(list_of(...))) not because it's functionally
// required, but because ensure_equals() knows how to format a StringVec.
// Turns out that when ensure_equals() displays a test failure with just
// list_of("string")("another"), you see 'stringanother' vs. '("string",
// "another")'.
StringVec vec(const StringVec& v)
{
    return v;
}

// For some tests, use a dummy LLDir that uses memory data instead of touching
// the filesystem
struct LLDir_Dummy: public LLDir
{
    /*----------------------------- LLDir API ------------------------------*/
    LLDir_Dummy()
    {
        // Initialize important LLDir data members based on the filesystem
        // data below.
        mDirDelimiter = "/";
        mExecutableDir = "install";
        mExecutableFilename = "test";
        mExecutablePathAndName = add(mExecutableDir, mExecutableFilename);
        mWorkingDir = mExecutableDir;
        mAppRODataDir = "install";
        mSkinBaseDir = add(mAppRODataDir, "skins");
        mOSUserDir = "user";
        mOSUserAppDir = mOSUserDir;
        mLindenUserDir = "";

        // Make the dummy filesystem look more or less like what we expect in
        // the real one.
        static const char* preload[] =
        {
            // We group these fixture-data pathnames by basename, rather than
            // sorting by full path as you might expect, because the outcome
            // of each test strongly depends on which skins/languages provide
            // a given basename.
            "install/skins/default/colors.xml",
            "install/skins/steam/colors.xml",
            "user/skins/default/colors.xml",
            "user/skins/steam/colors.xml",

            "install/skins/default/xui/en/strings.xml",
            "install/skins/default/xui/fr/strings.xml",
            "install/skins/steam/xui/en/strings.xml",
            "install/skins/steam/xui/fr/strings.xml",
            "user/skins/default/xui/en/strings.xml",
            "user/skins/default/xui/fr/strings.xml",
            "user/skins/steam/xui/en/strings.xml",
            "user/skins/steam/xui/fr/strings.xml",

            "install/skins/default/xui/en/floater.xml",
            "install/skins/default/xui/fr/floater.xml",
            "user/skins/default/xui/fr/floater.xml",

            "install/skins/default/xui/en/newfile.xml",
            "install/skins/default/xui/fr/newfile.xml",
            "user/skins/default/xui/en/newfile.xml",

            "install/skins/default/html/en-us/welcome.html",
            "install/skins/default/html/fr/welcome.html",

            "install/skins/default/textures/only_default.jpeg",
            "install/skins/steam/textures/only_steam.jpeg",
            "user/skins/default/textures/only_user_default.jpeg",
            "user/skins/steam/textures/only_user_steam.jpeg",

            "install/skins/default/future/somefile.txt"
        };
        for (const char* path : preload)
        {
            buildFilesystem(path);
        }
    }

    virtual ~LLDir_Dummy() {}

    virtual void initAppDirs(const std::string& app_name, const std::string& app_read_only_data_dir)
    {
        // Implement this when we write a test that needs it
    }

    virtual std::string getCurPath()
    {
        // Implement this when we write a test that needs it
        return "";
    }

    virtual U32 countFilesInDir(const std::string& dirname, const std::string& mask)
    {
        // Implement this when we write a test that needs it
        return 0;
    }

    virtual bool fileExists(const std::string& pathname) const
    {
        // Record fileExists() calls so we can check whether caching is
        // working right. Certain LLDir calls should be able to make decisions
        // without calling fileExists() again, having already checked existence.
        mChecked.insert(pathname);
        // For our simple flat set of strings, see whether the identical
        // pathname exists in our set.
        return (mFilesystem.find(pathname) != mFilesystem.end());
    }

    virtual std::string getLLPluginLauncher()
    {
        // Implement this when we write a test that needs it
        return "";
    }

    virtual std::string getLLPluginFilename(std::string base_name)
    {
        // Implement this when we write a test that needs it
        return "";
    }

    /*----------------------------- Dummy data -----------------------------*/
    void clearFilesystem() { mFilesystem.clear(); }
    void buildFilesystem(const std::string& path)
    {
        // Split the pathname on slashes, ignoring leading, trailing, doubles
        StringVec components;
        LLStringUtil::getTokens(path, components, "/");
        // Ensure we have an entry representing every level of this path
        std::string partial;
        for (std::string component : components)
        {
            append(partial, component);
            mFilesystem.insert(partial);
        }
    }

    void clear_checked() { mChecked.clear(); }
    void ensure_checked(const std::string& pathname) const
    {
        tut::ensure(STRINGIZE(pathname << " was not checked but should have been"),
                    mChecked.find(pathname) != mChecked.end());
    }
    void ensure_not_checked(const std::string& pathname) const
    {
        tut::ensure(STRINGIZE(pathname << " was checked but should not have been"),
                    mChecked.find(pathname) == mChecked.end());
    }

    std::set<std::string> mFilesystem;
    mutable std::set<std::string> mChecked;
};

namespace tut
{
    struct LLDirTest
        {
        };
        typedef test_group<LLDirTest> LLDirTest_t;
        typedef LLDirTest_t::object LLDirTest_object_t;
        tut::LLDirTest_t tut_LLDirTest("LLDir");

    template<> template<>
    void LLDirTest_object_t::test<1>()
        // getDirDelimiter
    {
        ensure("getDirDelimiter", !gDirUtilp->getDirDelimiter().empty());
    }

    template<> template<>
    void LLDirTest_object_t::test<2>()
        // getBaseFileName
    {
        std::string delim = gDirUtilp->getDirDelimiter();
        std::string rawFile = "foo";
        std::string rawFileExt = "foo.bAr";
        std::string rawFileNullExt = "foo.";
        std::string rawExt = ".bAr";
        std::string rawDot = ".";
        std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
        std::string pathExt = pathNoExt + ".eXt";
        std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
        std::string dottedPathExt = dottedPathNoExt + ".eXt";

        // foo[.bAr]

        ensure_equals("getBaseFileName/r-no-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(rawFile, false),
                  "foo");

        ensure_equals("getBaseFileName/r-no-ext/strip-exten",
                  gDirUtilp->getBaseFileName(rawFile, true),
                  "foo");

        ensure_equals("getBaseFileName/r-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(rawFileExt, false),
                  "foo.bAr");

        ensure_equals("getBaseFileName/r-ext/strip-exten",
                  gDirUtilp->getBaseFileName(rawFileExt, true),
                  "foo");

        // foo.

        ensure_equals("getBaseFileName/rn-no-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(rawFileNullExt, false),
                  "foo.");

        ensure_equals("getBaseFileName/rn-no-ext/strip-exten",
                  gDirUtilp->getBaseFileName(rawFileNullExt, true),
                  "foo");

        // .bAr
        // interesting case - with no basename, this IS the basename, not the extension.

        ensure_equals("getBaseFileName/e-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(rawExt, false),
                  ".bAr");

        ensure_equals("getBaseFileName/e-ext/strip-exten",
                  gDirUtilp->getBaseFileName(rawExt, true),
                  ".bAr");

        // .

        ensure_equals("getBaseFileName/d/no-strip-exten",
                  gDirUtilp->getBaseFileName(rawDot, false),
                  ".");

        ensure_equals("getBaseFileName/d/strip-exten",
                  gDirUtilp->getBaseFileName(rawDot, true),
                  ".");

        // aa/bb/cc/dd/ee[.eXt]

        ensure_equals("getBaseFileName/no-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(pathNoExt, false),
                  "ee");

        ensure_equals("getBaseFileName/no-ext/strip-exten",
                  gDirUtilp->getBaseFileName(pathNoExt, true),
                  "ee");

        ensure_equals("getBaseFileName/ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(pathExt, false),
                  "ee.eXt");

        ensure_equals("getBaseFileName/ext/strip-exten",
                  gDirUtilp->getBaseFileName(pathExt, true),
                  "ee");

        // aa/bb/cc.dd/ee[.eXt]

        ensure_equals("getBaseFileName/d-no-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(dottedPathNoExt, false),
                  "ee");

        ensure_equals("getBaseFileName/d-no-ext/strip-exten",
                  gDirUtilp->getBaseFileName(dottedPathNoExt, true),
                  "ee");

        ensure_equals("getBaseFileName/d-ext/no-strip-exten",
                  gDirUtilp->getBaseFileName(dottedPathExt, false),
                  "ee.eXt");

        ensure_equals("getBaseFileName/d-ext/strip-exten",
                  gDirUtilp->getBaseFileName(dottedPathExt, true),
                  "ee");
    }

    template<> template<>
    void LLDirTest_object_t::test<3>()
        // getDirName
    {
        std::string delim = gDirUtilp->getDirDelimiter();
        std::string rawFile = "foo";
        std::string rawFileExt = "foo.bAr";
        std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
        std::string pathExt = pathNoExt + ".eXt";
        std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
        std::string dottedPathExt = dottedPathNoExt + ".eXt";

        // foo[.bAr]

        ensure_equals("getDirName/r-no-ext",
                  gDirUtilp->getDirName(rawFile),
                  "");

        ensure_equals("getDirName/r-ext",
                  gDirUtilp->getDirName(rawFileExt),
                  "");

        // aa/bb/cc/dd/ee[.eXt]

        ensure_equals("getDirName/no-ext",
                  gDirUtilp->getDirName(pathNoExt),
                  "aa" + delim + "bb" + delim + "cc" + delim + "dd");

        ensure_equals("getDirName/ext",
                  gDirUtilp->getDirName(pathExt),
                  "aa" + delim + "bb" + delim + "cc" + delim + "dd");

        // aa/bb/cc.dd/ee[.eXt]

        ensure_equals("getDirName/d-no-ext",
                  gDirUtilp->getDirName(dottedPathNoExt),
                  "aa" + delim + "bb" + delim + "cc.dd");

        ensure_equals("getDirName/d-ext",
                  gDirUtilp->getDirName(dottedPathExt),
                  "aa" + delim + "bb" + delim + "cc.dd");
    }

    template<> template<>
    void LLDirTest_object_t::test<4>()
        // getExtension
    {
        std::string delim = gDirUtilp->getDirDelimiter();
        std::string rawFile = "foo";
        std::string rawFileExt = "foo.bAr";
        std::string rawFileNullExt = "foo.";
        std::string rawExt = ".bAr";
        std::string rawDot = ".";
        std::string pathNoExt = "aa" + delim + "bb" + delim + "cc" + delim + "dd" + delim + "ee";
        std::string pathExt = pathNoExt + ".eXt";
        std::string dottedPathNoExt = "aa" + delim + "bb" + delim + "cc.dd" + delim + "ee";
        std::string dottedPathExt = dottedPathNoExt + ".eXt";

        // foo[.bAr]

        ensure_equals("getExtension/r-no-ext",
                  gDirUtilp->getExtension(rawFile),
                  "");

        ensure_equals("getExtension/r-ext",
                  gDirUtilp->getExtension(rawFileExt),
                  "bar");

        // foo.

        ensure_equals("getExtension/rn-no-ext",
                  gDirUtilp->getExtension(rawFileNullExt),
                  "");

        // .bAr
        // interesting case - with no basename, this IS the basename, not the extension.

        ensure_equals("getExtension/e-ext",
                  gDirUtilp->getExtension(rawExt),
                  "");

        // .

        ensure_equals("getExtension/d",
                  gDirUtilp->getExtension(rawDot),
                  "");

        // aa/bb/cc/dd/ee[.eXt]

        ensure_equals("getExtension/no-ext",
                  gDirUtilp->getExtension(pathNoExt),
                  "");

        ensure_equals("getExtension/ext",
                  gDirUtilp->getExtension(pathExt),
                  "ext");

        // aa/bb/cc.dd/ee[.eXt]

        ensure_equals("getExtension/d-no-ext",
                  gDirUtilp->getExtension(dottedPathNoExt),
                  "");

        ensure_equals("getExtension/d-ext",
                  gDirUtilp->getExtension(dottedPathExt),
                  "ext");
    }

   std::string makeTestFile( const std::string& dir, const std::string& file )
   {
      std::string path = dir + file;
      LLFILE* handle = LLFile::fopen( path, "w" );
      ensure("failed to open test file '"+path+"'", handle != NULL );
      // Harbison & Steele, 4th ed., p. 366: "If an error occurs, fputs
      // returns EOF; otherwise, it returns some other, nonnegative value."
      ensure("failed to write to test file '"+path+"'", EOF != fputs("test file", handle) );
      fclose(handle);
      return path;
   }

   std::string makeTestDir( const std::string& dirbase )
   {
      int counter;
      std::string uniqueDir;
      bool foundUnused;
      std::string delim = gDirUtilp->getDirDelimiter();

      for (counter=0, foundUnused=false; !foundUnused; counter++ )
      {
         char counterStr[3];
         sprintf(counterStr, "%02d", counter);
         uniqueDir = dirbase + counterStr;
         foundUnused = ! ( LLFile::isdir(uniqueDir) || LLFile::isfile(uniqueDir) );
      }
      ensure("test directory '" + uniqueDir + "' creation failed", !LLFile::mkdir(uniqueDir));

      return uniqueDir + delim; // HACK - apparently, the trailing delimiter is needed...
   }

   static const char* DirScanFilename[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" };

   void scanTest(const std::string& directory, const std::string& pattern, bool correctResult[5])
   {

      // Scan directory and see if any file1.* files are found
      std::string scanResult;
      int   found = 0;
      bool  filesFound[5] = { false, false, false, false, false };
      //std::cerr << "searching '"+directory+"' for '"+pattern+"'\n";

      LLDirIterator iter(directory, pattern);
      while ( found <= 5 && iter.next(scanResult) )
      {
         found++;
         //std::cerr << "  found '"+scanResult+"'\n";
         int check;
         for (check=0; check < 5 && ! ( scanResult == DirScanFilename[check] ); check++)
         {
         }
         // check is now either 5 (not found) or the index of the matching name
         if (check < 5)
         {
            ensure( "found file '"+(std::string)DirScanFilename[check]+"' twice", ! filesFound[check] );
            filesFound[check] = true;
         }
         else // check is 5 - should not happen
         {
            fail( "found unknown file '"+scanResult+"'");
         }
      }
      for (int i=0; i<5; i++)
      {
         if (correctResult[i])
         {
            ensure("scan of '"+directory+"' using '"+pattern+"' did not return '"+DirScanFilename[i]+"'", filesFound[i]);
         }
         else
         {
            ensure("scan of '"+directory+"' using '"+pattern+"' incorrectly returned '"+DirScanFilename[i]+"'", !filesFound[i]);
         }
      }
   }

   template<> template<>
   void LLDirTest_object_t::test<5>()
      // LLDirIterator::next
   {
      std::string delim = gDirUtilp->getDirDelimiter();
      std::string dirTemp = LLFile::tmpdir();

      // Create the same 5 file names of the two directories

      std::string dir1 = makeTestDir(dirTemp + "LLDirIterator");
      std::string dir2 = makeTestDir(dirTemp + "LLDirIterator");
      std::string dir1files[5];
      std::string dir2files[5];
      for (int i=0; i<5; i++)
      {
         dir1files[i] = makeTestFile(dir1, DirScanFilename[i]);
         dir2files[i] = makeTestFile(dir2, DirScanFilename[i]);
      }

      // Scan dir1 and see if each of the 5 files is found exactly once
      bool expected1[5] = { true, true, true, true, true };
      scanTest(dir1, "*", expected1);

      // Scan dir2 and see if only the 2 *.xyz files are found
      bool  expected2[5] = { false, false, true, true, false };
      scanTest(dir1, "*.xyz", expected2);

      // Scan dir2 and see if only the 1 *.mno file is found
      bool  expected3[5] = { false, false, false, false, true };
      scanTest(dir2, "*.mno", expected3);

      // Scan dir1 and see if any *.foo files are found
      bool  expected4[5] = { false, false, false, false, false };
      scanTest(dir1, "*.foo", expected4);

      // Scan dir1 and see if any file1.* files are found
      bool  expected5[5] = { true, false, true, false, true };
      scanTest(dir1, "file1.*", expected5);

      // Scan dir1 and see if any file1.* files are found
      bool  expected6[5] = { true, true, false, false, false };
      scanTest(dir1, "file?.abc", expected6);

      // Scan dir2 and see if any file?.x?z files are found
      bool  expected7[5] = { false, false, true, true, false };
      scanTest(dir2, "file?.x?z", expected7);

      // Scan dir2 and see if any file?.??c files are found
      bool  expected8[5] = { true, true, false, false, false };
      scanTest(dir2, "file?.??c", expected8);
      scanTest(dir2, "*.??c", expected8);

      // Scan dir1 and see if any *.?n? files are found
      bool  expected9[5] = { false, false, false, false, true };
      scanTest(dir1, "*.?n?", expected9);

      // Scan dir1 and see if any *.???? files are found
      bool  expected10[5] = { false, false, false, false, false };
      scanTest(dir1, "*.????", expected10);

      // Scan dir1 and see if any ?????.* files are found
      bool  expected11[5] = { true, true, true, true, true };
      scanTest(dir1, "?????.*", expected11);

      // Scan dir1 and see if any ??l??.xyz files are found
      bool  expected12[5] = { false, false, true, true, false };
      scanTest(dir1, "??l??.xyz", expected12);

      bool expected13[5] = { true, false, true, false, false };
      scanTest(dir1, "file1.{abc,xyz}", expected13);

      bool expected14[5] = { true, true, false, false, false };
      scanTest(dir1, "file[0-9].abc", expected14);

      bool expected15[5] = { true, true, false, false, false };
      scanTest(dir1, "file[!a-z].abc", expected15);

      // clean up all test files and directories
      for (int i=0; i<5; i++)
      {
         LLFile::remove(dir1files[i]);
         LLFile::remove(dir2files[i]);
      }
      LLFile::rmdir(dir1);
      LLFile::rmdir(dir2);
   }

    template<> template<>
    void LLDirTest_object_t::test<6>()
    {
        set_test_name("findSkinnedFilenames()");
        LLDir_Dummy lldir;
        /*------------------------ "default", "en" -------------------------*/
        // Setting "default" means we shouldn't consider any "*/skins/steam"
        // directories; setting "en" means we shouldn't consider any "xui/fr"
        // directories.
        lldir.setSkinFolder("default", "en");
        ensure_equals(lldir.getSkinFolder(), "default");
        ensure_equals(lldir.getLanguage(), "en");

        // top-level directory of a skin isn't localized
        ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS),
                      vec(list_of("install/skins/default/colors.xml")
                                 ("user/skins/default/colors.xml")));
        // We should not have needed to check for skins/default/en. We should
        // just "know" that SKINBASE is not localized.
        lldir.ensure_not_checked("install/skins/default/en");

        ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_default.jpeg"),
                      vec(list_of("install/skins/default/textures/only_default.jpeg")));
        // Nor should we have needed to check skins/default/textures/en
        // because textures is known not to be localized.
        lldir.ensure_not_checked("install/skins/default/textures/en");

        StringVec expected(vec(list_of("install/skins/default/xui/en/strings.xml")
                               ("user/skins/default/xui/en/strings.xml")));
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS),
                      expected);
        // The first time, we had to probe to find out whether xui was localized.
        lldir.ensure_checked("install/skins/default/xui/en");
        lldir.clear_checked();
        // Now make the same call again -- should return same result --
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS),
                      expected);
        // but this time it should remember that xui is localized.
        lldir.ensure_not_checked("install/skins/default/xui/en");

        // localized subdir with "en-us" instead of "en"
        ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"),
                      vec(list_of("install/skins/default/html/en-us/welcome.html")));
        lldir.ensure_checked("install/skins/default/html/en");
        lldir.ensure_checked("install/skins/default/html/en-us");
        lldir.clear_checked();
        ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"),
                      vec(list_of("install/skins/default/html/en-us/welcome.html")));
        lldir.ensure_not_checked("install/skins/default/html/en");
        lldir.ensure_not_checked("install/skins/default/html/en-us");

        ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"),
                      vec(list_of("install/skins/default/future/somefile.txt")));
        // Test probing for an unrecognized unlocalized future subdir.
        lldir.ensure_checked("install/skins/default/future/en");
        lldir.clear_checked();
        ensure_equals(lldir.findSkinnedFilenames("future", "somefile.txt"),
                      vec(list_of("install/skins/default/future/somefile.txt")));
        // Second time it should remember that future is unlocalized.
        lldir.ensure_not_checked("install/skins/default/future/en");

        // When language is set to "en", requesting an html file pulls up the
        // "en-us" version -- not because it magically matches those strings,
        // but because there's no "en" localization and it falls back on the
        // default "en-us"! Note that it would probably still be better to
        // make the default localization be "en" and allow "en-gb" (or
        // whatever) localizations, which would work much more the way you'd
        // expect.
        ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"),
                      vec(list_of("install/skins/default/html/en-us/welcome.html")));

        /*------------------------ "default", "fr" -------------------------*/
        // We start being able to distinguish localized subdirs from
        // unlocalized when we ask for a non-English language.
        lldir.setSkinFolder("default", "fr");
        ensure_equals(lldir.getLanguage(), "fr");

        // pass merge=true to request this filename in all relevant skins
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS),
                      vec(list_of
                          ("install/skins/default/xui/en/strings.xml")
                          ("install/skins/default/xui/fr/strings.xml")
                          ("user/skins/default/xui/en/strings.xml")
                          ("user/skins/default/xui/fr/strings.xml")));

        // pass (or default) merge=false to request only most specific skin
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"),
                      vec(list_of
                          ("user/skins/default/xui/en/strings.xml")
                          ("user/skins/default/xui/fr/strings.xml")));

        // Our dummy floater.xml has a user localization (for "fr") but no
        // English override. This is a case in which CURRENT_SKIN nonetheless
        // returns paths from two different skins.
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "floater.xml"),
                      vec(list_of
                          ("install/skins/default/xui/en/floater.xml")
                          ("user/skins/default/xui/fr/floater.xml")));

        // Our dummy newfile.xml has an English override but no user
        // localization. This is another case in which CURRENT_SKIN
        // nonetheless returns paths from two different skins.
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "newfile.xml"),
                      vec(list_of
                          ("user/skins/default/xui/en/newfile.xml")
                          ("install/skins/default/xui/fr/newfile.xml")));

        ensure_equals(lldir.findSkinnedFilenames("html", "welcome.html"),
                      vec(list_of
                          ("install/skins/default/html/en-us/welcome.html")
                          ("install/skins/default/html/fr/welcome.html")));

        /*------------------------ "default", "zh" -------------------------*/
        lldir.setSkinFolder("default", "zh");
        // Because strings.xml has only a "fr" override but no "zh" override
        // in any skin, the most localized version we can find is "en".
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"),
                      vec(list_of("user/skins/default/xui/en/strings.xml")));

        /*------------------------- "steam", "en" --------------------------*/
        lldir.setSkinFolder("steam", "en");

        ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS),
                      vec(list_of
                          ("install/skins/default/colors.xml")
                          ("install/skins/steam/colors.xml")
                          ("user/skins/default/colors.xml")
                          ("user/skins/steam/colors.xml")));

        ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_default.jpeg"),
                      vec(list_of("install/skins/default/textures/only_default.jpeg")));

        ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_steam.jpeg"),
                      vec(list_of("install/skins/steam/textures/only_steam.jpeg")));

        ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_user_default.jpeg"),
                      vec(list_of("user/skins/default/textures/only_user_default.jpeg")));

        ensure_equals(lldir.findSkinnedFilenames(LLDir::TEXTURES, "only_user_steam.jpeg"),
                      vec(list_of("user/skins/steam/textures/only_user_steam.jpeg")));

        // CURRENT_SKIN
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"),
                      vec(list_of("user/skins/steam/xui/en/strings.xml")));

        // pass constraint=ALL_SKINS to request this filename in all relevant skins
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS),
                      vec(list_of
                          ("install/skins/default/xui/en/strings.xml")
                          ("install/skins/steam/xui/en/strings.xml")
                          ("user/skins/default/xui/en/strings.xml")
                          ("user/skins/steam/xui/en/strings.xml")));

        /*------------------------- "steam", "fr" --------------------------*/
        lldir.setSkinFolder("steam", "fr");

        // pass CURRENT_SKIN to request only the most specialized files
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml"),
                      vec(list_of
                          ("user/skins/steam/xui/en/strings.xml")
                          ("user/skins/steam/xui/fr/strings.xml")));

        // pass ALL_SKINS to request this filename in all relevant skins
        ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS),
                      vec(list_of
                          ("install/skins/default/xui/en/strings.xml")
                          ("install/skins/default/xui/fr/strings.xml")
                          ("install/skins/steam/xui/en/strings.xml")
                          ("install/skins/steam/xui/fr/strings.xml")
                          ("user/skins/default/xui/en/strings.xml")
                          ("user/skins/default/xui/fr/strings.xml")
                          ("user/skins/steam/xui/en/strings.xml")
                          ("user/skins/steam/xui/fr/strings.xml")));
    }

    template<> template<>
    void LLDirTest_object_t::test<7>()
    {
        set_test_name("add()");
        LLDir_Dummy lldir;
        ensure_equals("both empty", lldir.add("", ""), "");
        ensure_equals("path empty", lldir.add("", "b"), "b");
        ensure_equals("name empty", lldir.add("a", ""), "a");
        ensure_equals("both simple", lldir.add("a", "b"), "a/b");
        ensure_equals("name leading slash", lldir.add("a", "/b"), "a/b");
        ensure_equals("path trailing slash", lldir.add("a/", "b"), "a/b");
        ensure_equals("both bring slashes", lldir.add("a/", "/b"), "a/b");
    }
}