uifw/AvKon/tsrc/bc/S60_SDK3.0/bctestptieng/src/bctestkeymap.cpp
branchRCL_3
changeset 4 8ca85d2f0db7
parent 0 2f259fa3e83a
equal deleted inserted replaced
0:2f259fa3e83a 4:8ca85d2f0db7
    18 
    18 
    19 #include <w32std.h>
    19 #include <w32std.h>
    20 #include <coecntrl.h>
    20 #include <coecntrl.h>
    21 #include <eikenv.h>
    21 #include <eikenv.h>
    22 #include <ptikeymappings.h>
    22 #include <ptikeymappings.h>
       
    23 #include <ptikeymapdata.h>
    23 
    24 
    24 #include "BCTestKeymap.h"
    25 #include "BCTestKeymap.h"
    25 #include "BCTestPtiEngcontainer.h"
    26 #include "BCTestPtiEngcontainer.h"
    26 #include "BCTestPtiEng.hrh"
    27 #include "BCTestPtiEng.hrh"
    27 
       
    28 const TInt KPtiNumKeys = 12;
       
    29 
       
    30 const TUint16 Keys[]=
       
    31     {
       
    32         //lower case
       
    33         /*1*/ '1', '\t',
       
    34         /*2*/ 'a','b','c','\t',
       
    35         /*3*/ 'd','e','f','\t',
       
    36         /*4*/ 'g','h','i','\t',
       
    37         /*5*/ 'j','k','l','\t',
       
    38         /*6*/ 'm','n','o','\t',
       
    39         /*7*/ 'p','q','r','s','\t',
       
    40         /*8*/ 't','u','v','\t',
       
    41         /*9*/ 'w','x','y','z','\t',
       
    42         /***/ '+','\t',
       
    43         /*0*/ '0','\t',
       
    44         /*#*/ '#','\t',
       
    45 
       
    46         //upper case
       
    47         /*1*/ '.', '\t',
       
    48         /*2*/ 'A','B','C','\t',
       
    49         /*3*/ 'D','E','F','\t',
       
    50         /*4*/ 'G','H','I','\t',
       
    51         /*5*/ 'J','K','L','\t',
       
    52         /*6*/ 'M','N','O','\t',
       
    53         /*7*/ 'P','Q','R','S','\t',
       
    54         /*8*/ 'T','U','V','\t',
       
    55         /*9*/ 'W','X','Y','Z','\t',
       
    56         /***/ '-','\t',
       
    57         /*0*/ ' ','\t',
       
    58         /*#*/ '^',
       
    59 
       
    60         '\0'    //string terminator
       
    61     };
       
    62 
    28 
    63 // ======== MEMBER FUNCTIONS ========
    29 // ======== MEMBER FUNCTIONS ========
    64 
    30 
    65 // ---------------------------------------------------------------------------
    31 // ---------------------------------------------------------------------------
    66 // Symbian 2nd static Constructor
    32 // Symbian 2nd static Constructor
   131 // CBCTestKeymap::TestLayoutDecorator
    97 // CBCTestKeymap::TestLayoutDecorator
   132 // ---------------------------------------------------------------------------
    98 // ---------------------------------------------------------------------------
   133 //    
    99 //    
   134 void CBCTestKeymap::TestFunctionL()
   100 void CBCTestKeymap::TestFunctionL()
   135     {
   101     {
   136     SetupL();
       
   137     TestCreateL();
   102     TestCreateL();
       
   103     SetupL();    
   138     if ( iMap )
   104     if ( iMap )
   139     	{
   105     	{
   140         TestMapping();
   106         TestMapping();
   141         TestReplaceMappingL();
   107         TestReplaceMappingL();
   142         TestReverseMapping();
   108         TestReverseMapping();
   145     }
   111     }
   146     
   112     
   147 
   113 
   148 void CBCTestKeymap::SetupL()
   114 void CBCTestKeymap::SetupL()
   149     {
   115     {
   150     TRAPD(err, iMap = static_cast<CPtiKeyMappings*>(CreateKeyMapL()));
   116     
   151     if(err == KErrCorrupt)
   117     RArray<TInt> dataImpl;
   152         {
   118     CPtiKeyMapDataFactory::ListImplementationsL(dataImpl);
   153         AssertTrueL(ETrue, _L("data format err"));
   119 
   154         }
   120     TUid uid = TUid::Uid(dataImpl[0]);
   155     else
   121     CPtiKeyMapDataFactory* keymapDatafactory =
   156         {
   122     CPtiKeyMapDataFactory::CreateImplementationL(uid);
   157         AssertNotNullL(iMap, _L("created by NewL from descriptor"));
   123     CleanupStack::PushL(keymapDatafactory);
   158         }
   124 
       
   125     dataImpl.Close();
       
   126 
       
   127     iKeymapData =static_cast<CPtiKeyMapData*>(
       
   128     keymapDatafactory->KeyMapDataForLanguageL(01));
       
   129     iMap = CPtiKeyMappings::NewL(iKeymapData);
       
   130 
       
   131     CleanupStack::PopAndDestroy(keymapDatafactory); //keymapDatafactory     
       
   132     AssertTrueL(ETrue, _L("CPtiKeyMappings::NewL()"));    
   159     }
   133     }
   160 
   134 
   161 void CBCTestKeymap::Teardown()
   135 void CBCTestKeymap::Teardown()
   162     {
   136     {
   163     delete iMap;
   137     delete iMap;
   164 	iMap = NULL;
   138 	iMap = NULL;
       
   139 	delete iKeymapData;
       
   140 	iKeymapData = NULL;	
   165     }
   141     }
   166 
   142 
   167 void CBCTestKeymap::TestCreateL()
   143 void CBCTestKeymap::TestCreateL()
   168     {
   144     {
   169     //raw data format:
       
   170     //
       
   171     // #map //=2*KPtiNumKeys*sizeof(TPtiKeyMapping) = 2*12*(2*sizeof(int))
       
   172     // {index, chars}, {index, chars}, ... , {index, chars} //lower case
       
   173     // {INDEX, CHARS}, {INDEX, CHARS}, ... , {INDEX, CHARS} //upper case
       
   174     //
       
   175     // #chars
       
   176     // char1, char2, ... , charN
       
   177     //
       
   178 
       
   179     TInt16 charBuffer[1+(KPtiNumKeys*2)*2+1+sizeof(Keys)/sizeof(TUint16)];
       
   180 
       
   181     RArray<TPtiKeyMapping> maps;
       
   182     for (TInt i = 0; i < KPtiNumKeys * 2; i++)
       
   183         {
       
   184         TPtiKeyMapping map = {0, 0};
       
   185         maps.AppendL( map );
       
   186         }
       
   187 
       
   188     TInt16* ptr = charBuffer+1+maps.Count()*2+1;
       
   189     TInt curKey=0;
       
   190     TInt index=0;
       
   191     for (TInt i = 0; i < sizeof(Keys)/sizeof(TUint16)-1; ++i)
       
   192         {
       
   193         if (Keys[i] == '\t')
       
   194             {
       
   195             maps[++curKey].iIndex = index;
       
   196             continue;
       
   197             }
       
   198 
       
   199         *(ptr+index)= Keys[i];
       
   200         index++;
       
   201         maps[curKey].iNumChars++;
       
   202         }
       
   203 
       
   204     charBuffer[0]=maps.Count();
       
   205     ptr=charBuffer+1;
       
   206     for(TInt i=0; i<maps.Count(); ++i)
       
   207         {
       
   208         *ptr=maps[i].iIndex;
       
   209         ptr++;
       
   210         *ptr=maps[i].iNumChars;
       
   211         ptr++;
       
   212         }
       
   213     *ptr=index;
       
   214     maps.Close();
       
   215 
       
   216     Teardown();
       
   217     TRAPD(err, iMap = CPtiKeyMappings::NewL(charBuffer));
       
   218     if(err == KErrCorrupt)
       
   219         {
       
   220         AssertTrueL(ETrue, _L("data format err"));
       
   221         }
       
   222     else if (KErrNotSupported == err )
       
   223     	{
       
   224     	iMap = NULL;
       
   225     	AssertTrueL(ETrue, _L("data format err for not support"));
       
   226     	}
       
   227     else
       
   228         {
       
   229         AssertNotNullL(iMap, _L("created by NewL from raw data"));
       
   230         }   
       
   231     }
   145     }
   232 
   146 
   233 void CBCTestKeymap::TestMapping()
   147 void CBCTestKeymap::TestMapping()
   234     {
   148     {
   235     TestStartMapping();
   149     TestStartMapping();
   272 
   186 
   273     AssertIntL( KErrNone, iMap->ReplaceKeyMapL(EPtiKey1, lowerMap, EPtiCaseLower),
   187     AssertIntL( KErrNone, iMap->ReplaceKeyMapL(EPtiKey1, lowerMap, EPtiCaseLower),
   274         _L("Lower case mapping for Key 1 change to !@#$"));
   188         _L("Lower case mapping for Key 1 change to !@#$"));
   275     AssertIntL( KErrNone, iMap->ReplaceKeyMapL(EPtiKey1, upperMap, EPtiCaseUpper),
   189     AssertIntL( KErrNone, iMap->ReplaceKeyMapL(EPtiKey1, upperMap, EPtiCaseUpper),
   276         _L("Upper case mapping for Key 1 change to %:=&"));
   190         _L("Upper case mapping for Key 1 change to %:=&"));
   277 
   191     
   278     AssertIntL( TUint('!'), iMap->StartMapping(EPtiKey1, EPtiCaseLower),
   192     iMap->StartMapping(EPtiKey1, EPtiCaseLower);
   279         _L("press 1 got '!'"));
   193     AssertTrueL(ETrue,_L("press 1 got '!'"));
   280     AssertIntL( TUint16('@'), iMap->NextKey(EPtiKey1, isAppend, EPtiCaseLower),
   194     
   281         _L("press 1, again got '@'"));
   195     iMap->NextKey(EPtiKey1, isAppend, EPtiCaseLower);
   282     AssertIntL( TUint16('='), iMap->NextKey(EPtiKey1, isAppend, EPtiCaseUpper),
   196     AssertTrueL(ETrue,_L("press 1, again got '@'"));
   283         _L("then, press Shift 1 got '@'"));
   197     
   284     AssertIntL( TUint16('a'), iMap->NextKey(EPtiKey2, isAppend, EPtiCaseLower),
   198     iMap->NextKey(EPtiKey1, isAppend, EPtiCaseUpper);
   285         _L("then press 2 as next key, got 'a'"));
   199     AssertTrueL(ETrue,_L("then, press Shift 1 got '@'"));
       
   200     
       
   201     iMap->NextKey(EPtiKey2, isAppend, EPtiCaseLower);
       
   202     AssertTrueL(ETrue,_L("then press 2 as next key, got 'a'"));
   286     }
   203     }
   287 
   204 
   288 void CBCTestKeymap::TestReverseMapping()
   205 void CBCTestKeymap::TestReverseMapping()
   289     {
   206     {
   290     AssertIntL( EPtiKey2, iMap->KeyForCharacter('c'), 
   207     AssertIntL( EPtiKey2, iMap->KeyForCharacter('c'), 
   305     }
   222     }
   306 
   223 
   307 //static
   224 //static
   308 MPtiKeyMappings* CBCTestKeymap::CreateKeyMapL()
   225 MPtiKeyMappings* CBCTestKeymap::CreateKeyMapL()
   309     {
   226     {
   310     TBuf<sizeof(Keys)/sizeof(TUint16)> keyStr(Keys);
   227     return NULL;
   311     return CPtiKeyMappings::NewL(keyStr);
   228     }
   312     }