1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textandlocutils/nearestlangutils/tsrc/t_langutilsimp.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,136 @@
1.4 +#ifndef __T_LANGUTILSIMP_H__
1.5 +#define __T_LANGUTILSIMP_H__
1.6 +
1.7 +//#include <w32std.h>
1.8 +#include <test/testexecutestepbase.h>
1.9 +#include <langutil.h>
1.10 +#include "LangUtilImpl.h"
1.11 +#include "T_LangUtilsTestShareFunc.h"
1.12 +
1.13 +struct SDowngradeTest
1.14 + {
1.15 + TLanguage iIn[4];
1.16 + TLanguage iOut[9];
1.17 + };
1.18 +
1.19 +class RTestDirectoryScanner : public RDirectoryScanner
1.20 + {
1.21 +public:
1.22 + RTestDirectoryScanner(CDesCArray*& aMember)
1.23 + : iOpenError(0), iFilesThatExist(aMember)
1.24 + {
1.25 + for (TInt i = 0; i != 26; ++i)
1.26 + iDriveError[i] = 0;
1.27 + }
1.28 + virtual TInt Open(RFs&, const TDesC& aMatchPattern)
1.29 + {
1.30 + iMatch = aMatchPattern;
1.31 + iIndex = 0;
1.32 + return iOpenError;
1.33 + }
1.34 + virtual TInt Next(TEntry& aOut)
1.35 + {
1.36 + if (!iFilesThatExist)
1.37 + return KErrEof;
1.38 + while (iIndex < iFilesThatExist->Count())
1.39 + {
1.40 + TInt i = iIndex++;
1.41 + if (0 <= (*iFilesThatExist)[i].MatchF(iMatch))
1.42 + {
1.43 + TPtrC fullName=(*iFilesThatExist)[i];
1.44 + TParsePtrC name(fullName);
1.45 + aOut.iName=name.NameAndExt();
1.46 + if (1 < fullName.Length() && fullName[1] == ':')
1.47 + {
1.48 + TInt drive = fullName[0];
1.49 + if ('a' <= drive && drive <= 'z')
1.50 + drive -= 'a';
1.51 + else
1.52 + {
1.53 + ASSERT('A' <= drive && drive <= 'Z');
1.54 + drive -= 'A';
1.55 + }
1.56 + return iDriveError[drive];
1.57 + }
1.58 + return KErrNone;
1.59 + }
1.60 + }
1.61 + return KErrEof;
1.62 + }
1.63 + virtual void Close() {}
1.64 + TInt iOpenError;
1.65 + TInt iDriveError[26];
1.66 +private:
1.67 + CDesCArray *&iFilesThatExist;
1.68 + TInt iIndex;
1.69 + TFileName iMatch;
1.70 + };
1.71 +
1.72 +
1.73 +class TTestNearestLanguageFileFinder : public TNearestLanguageFileFinder
1.74 + {
1.75 +public:
1.76 + TTestNearestLanguageFileFinder(const RFs& aFs)
1.77 + : TNearestLanguageFileFinder(aFs), iTestScanner(iFilesThatExist)
1.78 + {
1.79 + iFilesThatExist = 0;
1.80 + iFilesSearchedFor = 0;
1.81 + }
1.82 + ~TTestNearestLanguageFileFinder()
1.83 + {
1.84 + delete iFilesThatExist;
1.85 + delete iFilesSearchedFor;
1.86 + }
1.87 + virtual TInt GetCustomResourceDriveNumber() const { return iCustomRscDrive; }
1.88 + virtual TBool FileExists(const TDesC& aFileName) const
1.89 + {
1.90 + ASSERT(aFileName[1] == ':');
1.91 + ASSERT(0 == aFileName.Left(1).CompareF(iDrivesChecked.Left(1)));
1.92 + iDrivesChecked.Delete(0, 1);
1.93 + ASSERT(0 <= aFileName.MatchF(iFileCheckedFor));
1.94 + if (iFilesSearchedFor)
1.95 + {
1.96 + ASSERT(0 == aFileName.CompareF((*iFilesSearchedFor)[0]));
1.97 + iFilesSearchedFor->Delete(0);
1.98 + }
1.99 + if (!iFilesThatExist)
1.100 + return EFalse;
1.101 + TInt i;
1.102 + iFilesThatExist->Find(aFileName, i);
1.103 + return (0 <= i && i < iFilesThatExist->Count())? ETrue : EFalse;
1.104 + }
1.105 + virtual RDirectoryScanner& DirectoryScanner() { return iTestScanner; }
1.106 +
1.107 + TInt iCustomRscDrive;
1.108 + CDesCArray* iFilesThatExist;
1.109 + // File that is expected to go into FileExists.
1.110 + // Can contain wildcards.
1.111 + TFileName iFileCheckedFor;
1.112 + // Drives expected in calls to FileExists. The first one is checked then
1.113 + // discarded each time FileExists is called.
1.114 + mutable TBuf<26> iDrivesChecked;
1.115 + CDesCArray* iFilesSearchedFor;
1.116 + RTestDirectoryScanner iTestScanner;
1.117 + };
1.118 +
1.119 +
1.120 +class CT_LANGUTILSIMP : public CTestStep
1.121 + {
1.122 +public:
1.123 + CT_LANGUTILSIMP();
1.124 +protected:
1.125 + TVerdict doTestStepL();
1.126 +private:
1.127 + void TestLANGUTILSIMP();
1.128 + void TestPath(const TLanguagePath& aPath, const TLanguage* aExpected, TInt aExpectedCount);
1.129 + void TestAddLanguage();
1.130 + void TestDowngrade(SDowngradeTest& aTest);
1.131 + void TestMakeLanguageDowngradePath();
1.132 + void SetUpFinderForLanguageAndDriveSearchL(TTestNearestLanguageFileFinder& aFinder);
1.133 + void TestNearestLanguageFinder();
1.134 +
1.135 + };
1.136 +
1.137 +_LIT(KTestStep_T_LANGUTILSIMP, "T_LANGUTILSIMP");
1.138 +
1.139 +#endif