textandlocutils/nearestlangutils/tsrc/t_langutilsimp.h
changeset 63 a145c1c7a5f4
equal deleted inserted replaced
57:01e38b33e72a 63:a145c1c7a5f4
       
     1 #ifndef __T_LANGUTILSIMP_H__
       
     2 #define __T_LANGUTILSIMP_H__
       
     3 
       
     4 //#include <w32std.h>
       
     5 #include <test/testexecutestepbase.h>
       
     6 #include <langutil.h>
       
     7 #include "LangUtilImpl.h"
       
     8 #include "T_LangUtilsTestShareFunc.h"
       
     9 
       
    10 struct SDowngradeTest
       
    11     {
       
    12     TLanguage iIn[4];
       
    13     TLanguage iOut[9];
       
    14     };
       
    15 
       
    16 class RTestDirectoryScanner : public RDirectoryScanner
       
    17     {
       
    18 public:
       
    19     RTestDirectoryScanner(CDesCArray*& aMember)
       
    20         : iOpenError(0), iFilesThatExist(aMember)
       
    21         {
       
    22         for (TInt i = 0; i != 26; ++i)
       
    23             iDriveError[i] = 0;
       
    24         }
       
    25     virtual TInt Open(RFs&, const TDesC& aMatchPattern)
       
    26         {
       
    27         iMatch = aMatchPattern;
       
    28         iIndex = 0;
       
    29         return iOpenError;
       
    30         }
       
    31     virtual TInt Next(TEntry& aOut)
       
    32         {
       
    33         if (!iFilesThatExist)
       
    34             return KErrEof;
       
    35         while (iIndex < iFilesThatExist->Count())
       
    36             {
       
    37             TInt i = iIndex++;
       
    38             if (0 <= (*iFilesThatExist)[i].MatchF(iMatch))
       
    39                 {
       
    40                 TPtrC fullName=(*iFilesThatExist)[i];
       
    41                 TParsePtrC name(fullName);
       
    42                 aOut.iName=name.NameAndExt();
       
    43                 if (1 < fullName.Length() && fullName[1] == ':')
       
    44                     {
       
    45                     TInt drive = fullName[0];
       
    46                     if ('a' <= drive && drive <= 'z')
       
    47                         drive -= 'a';
       
    48                     else
       
    49                         {
       
    50                         ASSERT('A' <= drive && drive <= 'Z');
       
    51                         drive -= 'A';
       
    52                         }
       
    53                     return iDriveError[drive];
       
    54                     }
       
    55                 return KErrNone;
       
    56                 }
       
    57             }
       
    58         return KErrEof;
       
    59         }
       
    60     virtual void Close() {}
       
    61     TInt iOpenError;
       
    62     TInt iDriveError[26];
       
    63 private:
       
    64     CDesCArray *&iFilesThatExist;
       
    65     TInt iIndex;
       
    66     TFileName iMatch;
       
    67     };
       
    68 
       
    69 
       
    70 class TTestNearestLanguageFileFinder : public TNearestLanguageFileFinder
       
    71     {
       
    72 public:
       
    73     TTestNearestLanguageFileFinder(const RFs& aFs)
       
    74         : TNearestLanguageFileFinder(aFs), iTestScanner(iFilesThatExist)
       
    75         {
       
    76         iFilesThatExist = 0;
       
    77         iFilesSearchedFor = 0;
       
    78         }
       
    79     ~TTestNearestLanguageFileFinder()
       
    80         {
       
    81         delete iFilesThatExist;
       
    82         delete iFilesSearchedFor;
       
    83         }
       
    84     virtual TInt GetCustomResourceDriveNumber() const { return iCustomRscDrive; }
       
    85     virtual TBool FileExists(const TDesC& aFileName) const
       
    86         {
       
    87         ASSERT(aFileName[1] == ':');
       
    88         ASSERT(0 == aFileName.Left(1).CompareF(iDrivesChecked.Left(1)));
       
    89         iDrivesChecked.Delete(0, 1);
       
    90         ASSERT(0 <= aFileName.MatchF(iFileCheckedFor));
       
    91         if (iFilesSearchedFor)
       
    92             {
       
    93             ASSERT(0 == aFileName.CompareF((*iFilesSearchedFor)[0]));
       
    94             iFilesSearchedFor->Delete(0);
       
    95             }
       
    96         if (!iFilesThatExist)
       
    97             return EFalse;
       
    98         TInt i;
       
    99         iFilesThatExist->Find(aFileName, i);
       
   100         return (0 <= i && i < iFilesThatExist->Count())? ETrue : EFalse;
       
   101         }
       
   102     virtual RDirectoryScanner& DirectoryScanner() { return iTestScanner; }
       
   103 
       
   104     TInt iCustomRscDrive;
       
   105     CDesCArray* iFilesThatExist;
       
   106     // File that is expected to go into FileExists.
       
   107     // Can contain wildcards.
       
   108     TFileName iFileCheckedFor;
       
   109     // Drives expected in calls to FileExists. The first one is checked then
       
   110     // discarded each time FileExists is called.
       
   111     mutable TBuf<26> iDrivesChecked;
       
   112     CDesCArray* iFilesSearchedFor;
       
   113     RTestDirectoryScanner iTestScanner;
       
   114     };
       
   115 
       
   116 
       
   117 class CT_LANGUTILSIMP : public CTestStep
       
   118     {
       
   119 public:
       
   120     CT_LANGUTILSIMP();
       
   121 protected:  
       
   122     TVerdict doTestStepL();
       
   123 private:
       
   124     void TestLANGUTILSIMP();
       
   125     void TestPath(const TLanguagePath& aPath, const TLanguage* aExpected, TInt aExpectedCount);
       
   126     void TestAddLanguage();
       
   127     void TestDowngrade(SDowngradeTest& aTest);
       
   128     void TestMakeLanguageDowngradePath();
       
   129     void SetUpFinderForLanguageAndDriveSearchL(TTestNearestLanguageFileFinder& aFinder);
       
   130     void TestNearestLanguageFinder();
       
   131 
       
   132     };
       
   133 
       
   134 _LIT(KTestStep_T_LANGUTILSIMP, "T_LANGUTILSIMP");
       
   135 
       
   136 #endif