uifw/AvKon/tsrc/bc/S60_SDK3.0/bctestptieng/src/bctestqwertymap.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 #include <BARSREAD.H>
    24 #include <BARSREAD.H>
    24 
    25 
    25 #include "BCTestQwertymap.h"
    26 #include "BCTestQwertymap.h"
    26 #include "BCTestPtiEngcontainer.h"
    27 #include "BCTestPtiEngcontainer.h"
    27 #include "BCTestPtiEng.hrh"
    28 #include "BCTestPtiEng.hrh"
   129 // CBCTestQwertyMap::SetupL()
   130 // CBCTestQwertyMap::SetupL()
   130 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   131 //   
   132 //   
   132 void CBCTestQwertyMap::SetupL()
   133 void CBCTestQwertyMap::SetupL()
   133     {
   134     {
   134     TRAPD(err, iMap = static_cast<CPtiQwertyKeyMappings*>(CreateKeyMapL()));
   135     RArray<TInt> dataImpl;    
   135     if(err == KErrCorrupt)
   136     CPtiKeyMapDataFactory::ListImplementationsL(dataImpl);
   136         {
   137 
   137         AssertTrueL(ETrue, _L("data format err"));
   138     TUid uid = TUid::Uid(dataImpl[0]);
   138         }
   139     CPtiKeyMapDataFactory* keymapDatafactory =
   139     else if ( KErrNotFound == err )
   140     CPtiKeyMapDataFactory::CreateImplementationL(uid);
   140     	{
   141     CleanupStack::PushL(keymapDatafactory);
   141     	iMap = NULL;
   142     dataImpl.Close();
   142     	AssertTrueL(ETrue, _L("data format err KErrNotFound"));
   143 
   143     	}
   144     iKeymapData =static_cast<CPtiKeyMapData*>(
   144     else
   145     keymapDatafactory->KeyMapDataForLanguageL(01));
   145         {
   146     iMap = CPtiQwertyKeyMappings::NewL(iKeymapData);
   146         AssertNotNullL(iMap, _L("created by NewL from descriptor"));
   147 
   147         }
   148     CleanupStack::PopAndDestroy(keymapDatafactory);
       
   149     AssertTrueL(ETrue, _L("CPtiQwertyKeyMappings::NewL"));
   148     }
   150     }
   149 
   151 
   150 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------
   151 // CBCTestQwertyMap::Teardown()
   153 // CBCTestQwertyMap::Teardown()
   152 // ---------------------------------------------------------------------------
   154 // ---------------------------------------------------------------------------
   153 //  
   155 //  
   154 void CBCTestQwertyMap::Teardown()
   156 void CBCTestQwertyMap::Teardown()
   155     {
   157     {
   156     delete iMap;
   158     delete iMap;
   157     iMap = NULL;
   159     iMap = NULL;
       
   160     delete iKeymapData;
       
   161     iKeymapData = NULL;    
   158     }
   162     }
   159 
   163 
   160 
   164 
   161 // ---------------------------------------------------------------------------
   165 // ---------------------------------------------------------------------------
   162 // CBCTestQwertyMap::TestMapping()
   166 // CBCTestQwertyMap::TestMapping()
   173 // CBCTestQwertyMap::TestStartMapping()
   177 // CBCTestQwertyMap::TestStartMapping()
   174 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   175 //  
   179 //  
   176 void CBCTestQwertyMap::TestStartMapping()
   180 void CBCTestQwertyMap::TestStartMapping()
   177     {
   181     {
   178     
   182 
   179     TPtrC keydata(_L('a'));
   183     iMap->StartMapping( EPtiKeyQwerty1, EPtiCaseLower );
   180     TInt size = keydata.Length();
       
   181 
       
   182     iMap->StartMapping( (TPtiKey)keydata[size/2+1], EPtiCaseLower );
       
   183     _LIT( KStartMapping, "StartMapping is invoked" );
   184     _LIT( KStartMapping, "StartMapping is invoked" );
   184     AssertTrueL( ETrue, KStartMapping );
   185     AssertTrueL( ETrue, KStartMapping );
   185         
   186         
   186     iMap->StartMapping( (TPtiKey)keydata[0], EPtiCaseLower );
   187     iMap->StartMapping( EPtiKeyQwerty2, EPtiCaseLower );
   187     _LIT( KStartMapping1, "StartMapping1 is invoked" );
   188     _LIT( KStartMapping1, "StartMapping1 is invoked" );
   188     AssertTrueL( ETrue, KStartMapping1 );
   189     AssertTrueL( ETrue, KStartMapping1 );
   189 
   190 
   190     }
   191     }
   191 
   192 
   194 // CBCTestQwertyMap::TestNextKey()
   195 // CBCTestQwertyMap::TestNextKey()
   195 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   196 //  
   197 //  
   197 void CBCTestQwertyMap::TestNextKey()
   198 void CBCTestQwertyMap::TestNextKey()
   198     {
   199     {
   199     
   200 
   200     TPtrC keydata(_L('a'));
       
   201     TInt size = keydata.Length();
       
   202     
       
   203     TBool isAppend = ETrue;
   201     TBool isAppend = ETrue;
   204     iMap->StartMapping( (TPtiKey)keydata[size/2+1], EPtiCaseLower);
   202     iMap->StartMapping( EPtiKeyQwerty1, EPtiCaseLower);
   205     
   203     
   206     iMap->NextKey( (TPtiKey)keydata[size/2+1], isAppend, EPtiCaseLower );
   204     iMap->NextKey( EPtiKeyQwerty2, isAppend, EPtiCaseLower );
   207     _LIT( KNextKey, "NextKey is invoked" );
   205     _LIT( KNextKey, "NextKey is invoked" );
   208     AssertTrueL( ETrue, KNextKey );     
   206     AssertTrueL( ETrue, KNextKey );     
   209     
   207     
   210     iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseLower );
   208     iMap->NextKey( EPtiKeyQwerty3, isAppend, EPtiCaseLower );
   211     _LIT( KNextKey1, "NextKey1 is invoked" );
   209     _LIT( KNextKey1, "NextKey1 is invoked" );
   212     AssertTrueL( ETrue, KNextKey1 );
   210     AssertTrueL( ETrue, KNextKey1 );
   213 
   211 
   214     }
   212     }
   215 
   213 
   222     {
   220     {
   223     TBool isAppend = ETrue;
   221     TBool isAppend = ETrue;
   224     TBuf<5> lowerMap( KNewMapLower );
   222     TBuf<5> lowerMap( KNewMapLower );
   225     TBuf<5> upperMap( KNewMapUpper );
   223     TBuf<5> upperMap( KNewMapUpper );
   226     
   224     
   227     TPtrC keydata(_L('a'));
   225     iMap->ReplaceKeyMapL( EPtiKeyQwerty1, lowerMap, EPtiCaseLower );
   228     TInt size = keydata.Length();
       
   229 
       
   230     iMap->ReplaceKeyMapL( (TPtiKey)keydata[0], lowerMap, EPtiCaseLower );
       
   231     _LIT( KReplaceKeyMapL, "ReplaceKeyMapL is invoked" );
   226     _LIT( KReplaceKeyMapL, "ReplaceKeyMapL is invoked" );
   232     AssertTrueL( ETrue, KReplaceKeyMapL );    
   227     AssertTrueL( ETrue, KReplaceKeyMapL );    
   233     
   228     
   234     iMap->ReplaceKeyMapL( (TPtiKey)keydata[0], upperMap, EPtiCaseUpper );
   229     iMap->ReplaceKeyMapL( EPtiKeyQwerty2, upperMap, EPtiCaseUpper );
   235      _LIT( KReplaceKeyMapL1, "ReplaceKeyMapL1 is invoked" );
   230      _LIT( KReplaceKeyMapL1, "ReplaceKeyMapL1 is invoked" );
   236     AssertTrueL( ETrue, KReplaceKeyMapL1 ); 
   231     AssertTrueL( ETrue, KReplaceKeyMapL1 ); 
   237     
   232     
   238     iMap->StartMapping( (TPtiKey)keydata[0], EPtiCaseLower );
   233     iMap->StartMapping( EPtiKeyQwerty3, EPtiCaseLower );
   239      _LIT( KStartMapping, "StartMapping is invoked" );
   234      _LIT( KStartMapping, "StartMapping is invoked" );
   240     AssertTrueL( ETrue, KStartMapping ); 
   235     AssertTrueL( ETrue, KStartMapping ); 
   241     
   236     
   242     iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseLower);
   237     iMap->NextKey( EPtiKeyQwerty4, isAppend, EPtiCaseLower);
   243      _LIT( KNextKey, "NextKey is invoked" );
   238      _LIT( KNextKey, "NextKey is invoked" );
   244     AssertTrueL( ETrue, KNextKey ); 
   239     AssertTrueL( ETrue, KNextKey ); 
   245         
   240         
   246     iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseUpper);
   241     iMap->NextKey( EPtiKeyQwerty5, isAppend, EPtiCaseUpper);
   247      _LIT( KNextKey1, "NextKey1 is invoked" );
   242      _LIT( KNextKey1, "NextKey1 is invoked" );
   248     AssertTrueL( ETrue, KNextKey1 ); 
   243     AssertTrueL( ETrue, KNextKey1 ); 
   249 
   244 
   250     }
   245     }
   251 
   246 
   254 // CBCTestQwertyMap::TestReverseMapping()
   249 // CBCTestQwertyMap::TestReverseMapping()
   255 // ---------------------------------------------------------------------------
   250 // ---------------------------------------------------------------------------
   256 //  
   251 //  
   257 void CBCTestQwertyMap::TestReverseMapping()
   252 void CBCTestQwertyMap::TestReverseMapping()
   258     {
   253     {
   259     
   254     TUint16 c = 1;
   260     
   255     iMap->KeyForCharacter( c );
   261     TPtrC keydata(_L('a'));
       
   262     TInt size = keydata.Length();
       
   263     
       
   264     iMap->KeyForCharacter( keydata[1] );
       
   265     _LIT( KKeyForCharacter, "KeyForCharacter is invoked" );
   256     _LIT( KKeyForCharacter, "KeyForCharacter is invoked" );
   266     AssertTrueL( ETrue, KKeyForCharacter );
   257     AssertTrueL( ETrue, KKeyForCharacter );
   267     
   258     
   268     iMap->KeyForCharacter( keydata[2] );
   259     iMap->KeyForCharacter( c );
   269     _LIT( KKeyForCharacter1, "KeyForCharacter1 is invoked" );
   260     _LIT( KKeyForCharacter1, "KeyForCharacter1 is invoked" );
   270     AssertTrueL( ETrue, KKeyForCharacter1 );
   261     AssertTrueL( ETrue, KKeyForCharacter1 );
       
   262     
   271     }
   263     }
   272 
   264 
   273 
   265 
   274 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   275 // CBCTestQwertyMap::TestKeyData()
   267 // CBCTestQwertyMap::TestKeyData()
   276 // ---------------------------------------------------------------------------
   268 // ---------------------------------------------------------------------------
   277 //  
   269 //  
   278 void CBCTestQwertyMap::TestKeyData()
   270 void CBCTestQwertyMap::TestKeyData()
   279     {
   271     {
   280     
   272     
   281     TPtrC keydata(_L('a'));
       
   282     TInt size = keydata.Length();
       
   283     
       
   284     TBuf<8> mapStr;
   273     TBuf<8> mapStr;
   285 
   274 
   286     iMap->GetDataForKey( (TPtiKey)keydata[0], mapStr, EPtiCaseLower );
   275     iMap->GetDataForKey( EPtiKeyQwerty1, mapStr, EPtiCaseLower );
   287     AssertTrueL( ETrue, _L("Lower case data for key 1 is `") );
   276     AssertTrueL( ETrue, _L("Lower case data for key 1 is `") );
   288 
   277 
   289     iMap->GetDataForKey( (TPtiKey)keydata[0], mapStr, EPtiCaseUpper );
   278     iMap->GetDataForKey( EPtiKeyQwerty2, mapStr, EPtiCaseUpper );
   290     AssertTrueL( ETrue, _L("Upper case data for key 1 is ~") );
   279     AssertTrueL( ETrue, _L("Upper case data for key 1 is ~") );
   291     }
   280     }
   292 
   281 
   293 
   282 
   294 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   295 // CBCTestQwertyMap::CreateKeyMapL()
   284 // CBCTestQwertyMap::CreateKeyMapL()
   296 // ---------------------------------------------------------------------------
   285 // ---------------------------------------------------------------------------
   297 //  
   286 //  
   298 MPtiKeyMappings* CBCTestQwertyMap::CreateKeyMapL()
   287 MPtiKeyMappings* CBCTestQwertyMap::CreateKeyMapL()
   299     {
   288     {
   300     
   289     return NULL;
   301     MPtiKeyMappings* keyMappings = NULL;
       
   302     RFs fsSession;
       
   303     User::LeaveIfError( fsSession.Connect() ); // Start session
       
   304     CleanupClosePushL( fsSession ); 
       
   305     
       
   306     fsSession.SetSessionPath( KQwertyDir );                 
       
   307             
       
   308     TResourceReader reader;
       
   309     RResourceFile resFile;
       
   310     
       
   311     TFindFile fileFinder( fsSession );
       
   312     CDir* fileList = NULL;
       
   313     TInt err;   
       
   314     err = fileFinder.FindWildByPath( KMultiTapWildName, &KQwertyDir, fileList );   
       
   315     
       
   316     TInt code = User::Language();
       
   317     TInt lcode;
       
   318     
       
   319     if ( err == KErrNoMemory )
       
   320         {
       
   321         delete fileList;
       
   322     User::Leave( KErrNoMemory );                
       
   323     }
       
   324         
       
   325     else if ( err == KErrNone )
       
   326         {
       
   327         CleanupStack::PushL( fileList );
       
   328         TParse fileName;            
       
   329         HBufC8* rBuffer = NULL; 
       
   330         
       
   331         TInt i;
       
   332         for ( i = 0; i < fileList->Count(); i++ )
       
   333             {
       
   334             fileName.Set( (*fileList)[i].iName, &fileFinder.File(), NULL );
       
   335             resFile.OpenL( fsSession, fileName.FullName() );                
       
   336             CleanupClosePushL( resFile );               
       
   337                 
       
   338             rBuffer = resFile.AllocReadLC( 1 ); 
       
   339             reader.SetBuffer( rBuffer );    
       
   340                 
       
   341             lcode = *( (TInt16*)rBuffer->Ptr() );       
       
   342             if ( lcode == code )
       
   343                 {
       
   344                 break;
       
   345                 }           
       
   346             CleanupStack::PopAndDestroy(2); // rBuffer, resFile                                                             
       
   347             }
       
   348         if ( i >= fileList->Count() )   
       
   349             {
       
   350             User::Leave( KErrNotFound );
       
   351             }
       
   352                 
       
   353         TPtrC mtdata( (TUint16*)( rBuffer->Ptr() + ( 2 * sizeof( TUint16 ) ) ),
       
   354                  ( rBuffer->Length() - (2 * sizeof(TUint16) ) ) / 2 ); 
       
   355         keyMappings = CPtiQwertyKeyMappings::NewL( mtdata );     
       
   356         
       
   357         CleanupStack::PopAndDestroy(3); // fileList, rBuffer, resFile                           
       
   358     }
       
   359         
       
   360     CleanupStack::PopAndDestroy(); // fsSession 
       
   361     
       
   362     return keyMappings;
       
   363     
       
   364     }
   290     }
   365 
   291 
   366 // ---------------------------------------------------------------------------
   292 // ---------------------------------------------------------------------------
   367 // CBCTestQwertyMap::ValidQwertyMode()
   293 // CBCTestQwertyMap::ValidQwertyMode()
   368 // ---------------------------------------------------------------------------
   294 // ---------------------------------------------------------------------------