uifw/AvKon/tsrc/bc/S60_SDK3.0/bctestptieng/src/bctestptiengine.cpp
changeset 0 2f259fa3e83a
child 3 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  test case
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <w32std.h>
       
    20 #include <coecntrl.h>
       
    21 #include <eikenv.h>
       
    22 #include <ptiengine.h>
       
    23 #include <ptiuids.hrh>
       
    24 #include <ptidefs.h>
       
    25 #include <badesca.h>
       
    26 #include <ptiuserdicentry.h>
       
    27 
       
    28 #include "BCTestPtiEngine.h"
       
    29 #include "BCTestPtiEngcontainer.h"
       
    30 #include "BCTestPtiEng.hrh"
       
    31 #include "streamlogger.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Symbian 2nd static Constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CBCTestPtiEngine* CBCTestPtiEngine::NewL()
       
    40     {
       
    41     CBCTestPtiEngine* self = new( ELeave ) CBCTestPtiEngine();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // C++ default constructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CBCTestPtiEngine::CBCTestPtiEngine():iEngine(NULL)
       
    53     {
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Destructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CBCTestPtiEngine::~CBCTestPtiEngine()
       
    61     {
       
    62     Teardown();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Symbian 2nd Constructor
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CBCTestPtiEngine::ConstructL()
       
    70     {
       
    71     BuildScriptL();
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CBCTestPtiEngine::BuildScriptL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CBCTestPtiEngine::BuildScriptL()
       
    79     {
       
    80     // Add script as your need.
       
    81     AddTestL( LeftCBA,
       
    82         REP(Down, 5),
       
    83         KeyOK, TEND );
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CBCTestPtiEngine::RunL
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CBCTestPtiEngine::RunL( TInt aCmd )
       
    91     {
       
    92     if ( aCmd != EBCTestCmdPtiEng)
       
    93         {
       
    94         return;
       
    95         }
       
    96 
       
    97     TestFunctionL();
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CBCTestPtiEngine::TestLayoutDecorator
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CBCTestPtiEngine::TestFunctionL()
       
   105     {
       
   106     SetupL();
       
   107     TestLanguageL();
       
   108     TestInfoL();
       
   109     TestInputL();
       
   110     TestJapaneseInputL();
       
   111     TestChineseInputL();
       
   112     //TestDictL();
       
   113     TestOtherL();
       
   114     }
       
   115 
       
   116 
       
   117 void CBCTestPtiEngine::SetupL()
       
   118     {
       
   119     iEngine = CPtiEngine::NewL();
       
   120     AssertNotNullL(iEngine, _L("pti engine created"));
       
   121     }
       
   122 
       
   123 void CBCTestPtiEngine::Teardown()
       
   124     {
       
   125     if(iEngine)
       
   126         iEngine->CloseCurrentLanguageL();
       
   127     delete iEngine;
       
   128     iEngine=NULL;
       
   129     }
       
   130 
       
   131 void CBCTestPtiEngine::TestLanguageL()
       
   132     {
       
   133     CArrayFixFlat<TInt>* langs = new (ELeave) CArrayFixFlat<TInt>(100);
       
   134     CleanupStack::PushL(langs);
       
   135     iEngine->GetAvailableLanguagesL(langs);
       
   136 
       
   137     AssertTrueL(langs->Count()>0, _L("available languages got"));
       
   138     CleanupStack::PopAndDestroy( 1 ); // cores, langs
       
   139 
       
   140     RArray<TInt> langRefs;
       
   141     iEngine->GetAvailableLanguagesL(langRefs);
       
   142     AssertTrueL(langRefs.Count()>0, _L("available languages got into RArray"));
       
   143 
       
   144     //
       
   145     //activate
       
   146     //
       
   147     if(langRefs.Count())
       
   148         {
       
   149         MPtiLanguage *lan = iEngine->GetLanguage(langRefs[0]);
       
   150         if (lan->HasInputMode(EPtiEngineMultitapping))
       
   151             {
       
   152             iEngine->ActivateLanguageL(lan->LanguageCode(), EPtiEngineMultitapping);
       
   153             AssertTrueL( ETrue, _L("activate multitapping"));
       
   154             }
       
   155         else
       
   156             {
       
   157             iEngine->ActivateLanguageL(lan->LanguageCode(), EPtiEnginePredictive);
       
   158             AssertTrueL( ETrue, _L("activate predictive"));
       
   159             }
       
   160         }
       
   161 
       
   162     langRefs.Close();
       
   163     }
       
   164 
       
   165 
       
   166 void CBCTestPtiEngine::TestInfoL()
       
   167     {
       
   168     TBuf<16> msg;
       
   169     msg.Format(_L("num of lan: %d"), iEngine->NumberOfLanguages());
       
   170     msg.ZeroTerminate();
       
   171     AssertTrueL(iEngine->NumberOfLanguages()>0, msg);
       
   172 
       
   173     if (iEngine->InputMode() == EPtiEngineMultitapping)
       
   174         {
       
   175         AssertTrueL(ETrue, _L("input mode is Multitapping"));
       
   176         }
       
   177     else
       
   178         {
       
   179         AssertTrueL(ETrue, _L("input mode is Predictive"));
       
   180         }
       
   181 
       
   182     // localized language name
       
   183     TFileName localName;
       
   184     iEngine->GetLocalizedLanguageName(31, localName); //31 is chinese?
       
   185     localName.ZeroTerminate();
       
   186     AssertTrueL(ETrue, localName);
       
   187 
       
   188     //observer
       
   189     MPtiObserver* obs = iEngine->Observer();
       
   190     AssertTrueL(ETrue, _L("observer got"));
       
   191     iEngine->SetObserver(obs);
       
   192     AssertTrueL(ETrue, _L("observer set"));
       
   193     }
       
   194 
       
   195 void CBCTestPtiEngine::TestInputL()
       
   196     {
       
   197     TestInputModeL();
       
   198     TestMultitappingL();
       
   199     TestPredictL();
       
   200     TestLastKeyL();
       
   201     TestNavigationL();
       
   202     TestReorderingL();
       
   203     }
       
   204 
       
   205 void CBCTestPtiEngine::TestMultitappingL()
       
   206     {
       
   207     //multitapping
       
   208     iEngine->ActivateLanguageL(ELangEnglish, EPtiEngineMultitapping);
       
   209     iEngine->AppendKeyPress(EPtiKey3);
       
   210     iEngine->AppendKeyPress(EPtiKey6);
       
   211     iEngine->AppendKeyPress(EPtiKey6);
       
   212     iEngine->AppendKeyPress(EPtiKey6);
       
   213     iEngine->AppendKeyPress(EPtiKey4);
       
   214     _LIT(KDog, "dog");
       
   215     AssertTrueL( iEngine->CurrentWord()==KDog, _L("multityping input verified"));
       
   216 
       
   217     // commit
       
   218     AssertIntL(KErrNone, iEngine->CommitCurrentWord(),
       
   219         _L("Tell engine that current word was accepted"));
       
   220 
       
   221     // set external key map
       
   222     TInt ret(0);
       
   223     TBuf<5> testLit;
       
   224     testLit.Copy(_L("abcd"));
       
   225     TRAPD(err, ret = iEngine->SetExternalKeyMapL(EPtiEngineMultitapping, EPtiKey5,
       
   226                                                 testLit, EPtiCaseUpper));
       
   227     if ((ret == KErrNone) || (err != KErrNone))
       
   228         {
       
   229         AssertTrueL(ETrue, _L("set external key map failure"));
       
   230         }
       
   231     AssertTrueL(ETrue, _L("external key map set"));
       
   232     }
       
   233 
       
   234 static void SimuInput(CPtiEngine* aEngine, const TDesC& aKeys)
       
   235     {
       
   236     for(int i=0; i<aKeys.Length(); ++i)
       
   237         {
       
   238         if (aKeys[i] == ' ')
       
   239             {
       
   240             continue;
       
   241             }
       
   242         else if (aKeys[i] == 'p')
       
   243             {
       
   244             continue;
       
   245             }
       
   246         else if (aKeys[i] == 'd')
       
   247             {
       
   248             aEngine->DeleteKeyPress();
       
   249             }
       
   250         else
       
   251             {
       
   252             aEngine->AppendKeyPress(aEngine->CharacterToKey(aKeys[i]));
       
   253             }
       
   254         }
       
   255     }
       
   256 
       
   257 void CBCTestPtiEngine::TestPredictL()
       
   258     {
       
   259     //predictive
       
   260     iEngine->ActivateLanguageL(ELangEnglish, EPtiEnginePredictive);
       
   261     SimuInput(iEngine, _L("this"));
       
   262 
       
   263     TBuf<256> msg=_L("current word is: ");
       
   264     msg.Append(iEngine->CurrentWord());  //may be "this"
       
   265     msg.ZeroTerminate();
       
   266     AssertTrueL( ETrue, msg);
       
   267 
       
   268     // next
       
   269     msg=_L("next word is: ");
       
   270     msg.Append(iEngine->NextCandidate()); // Move on to next candidate.
       
   271     msg.ZeroTerminate();
       
   272     AssertTrueL( ETrue, msg);
       
   273     iEngine->CommitCurrentWord();
       
   274 
       
   275     // delete
       
   276     SimuInput(iEngine, _L("8447"));
       
   277     msg = _L("current word after del is: ");
       
   278     msg.Append(iEngine->DeleteKeyPress());
       
   279     msg.ZeroTerminate();
       
   280     AssertTrueL(ETrue, msg);
       
   281 
       
   282     // reject
       
   283     iEngine->ClearCurrentWord();
       
   284     AssertTrueL(ETrue, _L("reject current word"));
       
   285 
       
   286     // char2key
       
   287     AssertIntL(EPtiKey7, iEngine->CharacterToKey('s'), _L("char 's' map to key 7"));
       
   288 
       
   289     // candidate list
       
   290     iEngine->ClearCurrentWord();
       
   291     CDesCArray* cands = new (ELeave) CDesCArrayFlat(16);
       
   292     CleanupStack::PushL(cands);
       
   293 
       
   294     SimuInput(iEngine, _L("8447"));
       
   295     iEngine->GetCandidateListL(*cands);
       
   296     msg=_L("candidates: ");
       
   297     for (int i = 0; i < cands->Count(); ++i)
       
   298         {
       
   299         msg.Append(cands->MdcaPoint(i));
       
   300         msg.Append(_L(", "));
       
   301         }
       
   302     msg.ZeroTerminate();
       
   303     AssertIntL(cands->Count(), iEngine->NumberOfCandidates(), msg);
       
   304     CleanupStack::PopAndDestroy();  // cands
       
   305 
       
   306     // set current word
       
   307     iEngine->SetCurrentWord(_L("dog"));
       
   308     SimuInput(iEngine, _L("t"));
       
   309     msg=_L("dog+t change to: ");
       
   310     msg.Append(iEngine->CurrentWord());
       
   311     msg.ZeroTerminate();
       
   312     AssertTrueL(ETrue, msg);
       
   313     }
       
   314 
       
   315 void CBCTestPtiEngine::TestInputModeL()
       
   316     {
       
   317     AssertIntL(iEngine->SetInputMode(EPtiEngineMultitapping), KErrNone,
       
   318         _L("set input mode to multitapping"));
       
   319     AssertIntL(iEngine->SetInputMode(EPtiEnginePredictive), KErrNone,
       
   320         _L("set input mode to predictive"));
       
   321     AssertIntL(iEngine->SetInputMode(EPtiEngineNumeric), KErrNone,
       
   322         _L("set input mode to numeric"));
       
   323 
       
   324     // set case
       
   325     iEngine->SetCase(EPtiCaseUpper);
       
   326     AssertIntL(EPtiCaseUpper, iEngine->Case(), _L("upper case set"));
       
   327 
       
   328     iEngine->SetCase(EPtiCaseLower);
       
   329     AssertIntL(EPtiCaseLower, iEngine->Case(), _L("lower case set"));
       
   330     }
       
   331 
       
   332 void CBCTestPtiEngine::TestDictL()
       
   333     {
       
   334     CDesCArrayFlat* words = new (ELeave) CDesCArrayFlat(5);
       
   335     CleanupStack::PushL( words );
       
   336     words->AppendL(_L("lorem"));
       
   337     words->AppendL(_L("ipsum"));
       
   338     words->AppendL(_L("dolor"));
       
   339     words->AppendL(_L("sit"));
       
   340     words->AppendL(_L("amet"));
       
   341 
       
   342     TBuf<50> filename(_L("C:\\BCTestLog\\TestUserDict.txt"));
       
   343     AssertIntL(KErrNotSupported,
       
   344         iEngine->CreateUserDictionaryL(filename, words, EPtiEngineWordCompletion),
       
   345         _L("user dict created isn't supported"));
       
   346 
       
   347     CleanupStack::PopAndDestroy();  //words
       
   348 
       
   349 
       
   350 	TInt err;
       
   351     //attach
       
   352     MPtiUserDictionary* dict = iEngine->AttachUserDictionaryL(filename);
       
   353     if(dict)
       
   354         {
       
   355         AssertTrueL(ETrue, _L("user dict attached"));
       
   356         }
       
   357     else
       
   358         {
       
   359         AssertTrueL(ETrue, _L("user dict attached failure"));
       
   360         }
       
   361 
       
   362     //detach
       
   363     if(iEngine->DetachUserDictionary(filename) == KErrNone)
       
   364         {
       
   365         AssertTrueL(ETrue, _L("user dict detach"));
       
   366         }
       
   367     else
       
   368         {
       
   369         AssertTrueL(ETrue, _L("User dict detach failure"));
       
   370         }
       
   371 
       
   372     if(iEngine->DetachUserDictionary(0) == KErrNone)
       
   373         {
       
   374         AssertTrueL(ETrue, _L("user dict detach by ID"));
       
   375         }
       
   376     else
       
   377         {
       
   378         AssertTrueL(ETrue, _L("User dict detach by ID failure"));
       
   379         }
       
   380 
       
   381     //entry
       
   382     TFileName msg;
       
   383     TPtiUserDictionaryEntry entry(_L("foobar"));
       
   384 
       
   385     TInt number = iEngine->NumberOfEntriesInUserDictionary();
       
   386     if(number == KErrNotSupported)
       
   387         {
       
   388         AssertTrueL(ETrue, _L("user dict doesn't support entry"));
       
   389         }
       
   390     else
       
   391         {
       
   392         msg.Format(_L("total %d entries"), number);
       
   393         AssertTrueL(ETrue, msg);
       
   394         }
       
   395 
       
   396     err=iEngine->AddUserDictionaryEntry(entry);
       
   397     msg.Format(_L("add entry returns: %d"), err);
       
   398     msg.ZeroTerminate();
       
   399     AssertTrueL(ETrue, msg);
       
   400 
       
   401     err=iEngine->AddUserDictionaryEntry(entry, 0);
       
   402     msg.Format(_L("add entry with ID 0 returns: %d"), err);
       
   403     msg.ZeroTerminate();
       
   404     AssertTrueL(ETrue, msg);
       
   405 
       
   406     err=iEngine->RemoveEntryFromUserDictionary(entry);
       
   407     msg.Format(_L("remove entry returns: %d"), err);
       
   408     msg.ZeroTerminate();
       
   409     AssertTrueL(ETrue, msg);
       
   410 
       
   411     err=iEngine->RemoveEntryFromUserDictionary(entry, 0);
       
   412     msg.Format(_L("remove entry with ID 0 returns: %d"), err);
       
   413     msg.ZeroTerminate();
       
   414     AssertTrueL(ETrue, msg);
       
   415 
       
   416     err = iEngine->GetUserDictionaryEntry(0, entry);
       
   417     msg.Format(_L("get first entry returns: %d"), err);
       
   418     msg.ZeroTerminate();
       
   419     AssertTrueL(ETrue, msg);
       
   420 
       
   421     dict = iEngine->DefaultUserDictionary(EPtiEnginePinyin);
       
   422     if(dict)
       
   423         {
       
   424         AssertNotNullL(dict, _L("dict for Pinyin found"));
       
   425         }
       
   426     else
       
   427         {
       
   428         AssertTrueL(ETrue, _L("dict for Pinyin not found"));
       
   429         }
       
   430     }
       
   431 
       
   432 void CBCTestPtiEngine::TestLastKeyL()
       
   433     {
       
   434     iEngine->ClearCurrentWord();
       
   435     AssertIntL(EPtiKeyNone, iEngine->LastEnteredKey(), _L("none last entered key"));
       
   436 
       
   437     SimuInput(iEngine, _L("dog"));
       
   438     AssertIntL(EPtiKeyGHI, iEngine->LastEnteredKey(), _L("last key for 'dog' is GHI"));
       
   439     }
       
   440 
       
   441 void CBCTestPtiEngine::TestNavigationL()
       
   442     {
       
   443     iEngine->ClearCurrentWord();
       
   444     SimuInput(iEngine, _L("46873"));
       
   445 
       
   446     CDesCArray* cands = new (ELeave) CDesCArrayFlat(16);
       
   447     CleanupStack::PushL(cands);
       
   448 
       
   449     iEngine->GetCandidateListL(*cands);
       
   450 
       
   451     if (cands->Count() == 0)
       
   452     	{
       
   453     	CleanupStack::PopAndDestroy(); // cands
       
   454     	AssertTrueL(ETrue, _L("cands->Count() =0 return"));
       
   455     	return;
       
   456     	}
       
   457 
       
   458     AssertIntL(0, iEngine->FirstCandidate().Compare(cands->MdcaPoint(0)),
       
   459         _L("First candidate verified"));
       
   460 
       
   461     for (int i = 1; i < cands->Count(); ++i)
       
   462         {
       
   463         AssertIntL(0, iEngine->NextCandidate().Compare(cands->MdcaPoint(i)),
       
   464             _L("next candidate verified"));
       
   465         }
       
   466 
       
   467     for (int i = cands->Count() - 2; i >= 0; --i)
       
   468         {
       
   469         AssertIntL(0, iEngine->PreviousCandidate().Compare(cands->MdcaPoint(i)),
       
   470             _L("Previous candidate verified"));
       
   471         }
       
   472 
       
   473     CleanupStack::PopAndDestroy(); // cands
       
   474     }
       
   475 
       
   476 void CBCTestPtiEngine::TestReorderingL()
       
   477     {
       
   478     TInt err=iEngine->SetReordering(ETrue);
       
   479     if(err == KErrNone)
       
   480         {
       
   481         AssertIntL(KErrNone, err, _L("set reordering"));
       
   482         iEngine->ClearCurrentWord();
       
   483         SimuInput(iEngine, _L("364"));
       
   484 
       
   485         // get the third candidate
       
   486         TBuf<64> word;
       
   487         iEngine->NextCandidate();
       
   488         iEngine->NextCandidate();
       
   489         word.Copy(iEngine->NextCandidate());
       
   490 
       
   491         // comit it 4 times
       
   492         for(int i=0; i<4; ++i)
       
   493             {
       
   494             iEngine->SetCurrentWord(word);
       
   495             iEngine->CommitCurrentWord();
       
   496             }
       
   497         SimuInput(iEngine, _L("364"));
       
   498         AssertIntL(0, iEngine->CurrentWord().Compare(word),
       
   499             _L("reordered candidate verified"));
       
   500         iEngine->SetReordering(EFalse);
       
   501         }
       
   502     else
       
   503         {
       
   504         AssertIntL(KErrNotSupported, err,
       
   505             _L("set reordering isn't supported"));
       
   506         }
       
   507     }
       
   508 
       
   509 CPtiEngine* CreateEngineL(TInt aLanguage, TPtiEngineInputMode aMode)
       
   510     {
       
   511     CPtiEngine* engine = CPtiEngine::NewL();
       
   512     MPtiLanguage* lang = engine->GetLanguage(aLanguage);
       
   513 
       
   514     TBuf<100> numStr;
       
   515 
       
   516     if (!lang)
       
   517         {
       
   518         goto fail;
       
   519         }
       
   520 
       
   521     if (!lang->HasInputMode(aMode))
       
   522         {
       
   523         goto fail;
       
   524         }
       
   525 
       
   526     TInt err = engine->ActivateLanguageL(aLanguage, aMode);
       
   527     if (err != KErrNone)
       
   528         {
       
   529         goto fail;
       
   530         }
       
   531 
       
   532     return engine;
       
   533 
       
   534 fail:
       
   535     delete engine;
       
   536     return NULL;
       
   537     }
       
   538 
       
   539 void CBCTestPtiEngine::TestChineseInputL()
       
   540     {
       
   541     Teardown();
       
   542 
       
   543     if((iEngine = CreateEngineL(ELangPrcChinese, EPtiEngineStroke))!=NULL)
       
   544         {
       
   545         AssertNotNullL(iEngine, _L("Chinese Pinyin activated"));
       
   546         SimuInput(iEngine, _L("wei"));
       
   547 
       
   548         int page=0;
       
   549         iEngine->SetCandidatePageLength(20);
       
   550         AssertTrueL(ETrue, _L("page length set to 20"));
       
   551         for(TPtrC str=iEngine->CandidatePage();
       
   552                 iEngine->MoreCandidatePages();
       
   553                 iEngine->NextCandidatePage())
       
   554             {
       
   555             TFileName res;
       
   556             res.Format(_L("page[%d]: "), page++);
       
   557             for(int j=0; j<str.Length(); ++j)
       
   558                 {
       
   559                 res.Append(_L("<"));
       
   560                 res.AppendNumUC(str[j], EHex);
       
   561                 res.Append(_L(">"));
       
   562                 }
       
   563             res.ZeroTerminate();
       
   564             AssertTrueL(ETrue, res);
       
   565 
       
   566             if(page>10)
       
   567                 {
       
   568                 break;
       
   569                 }
       
   570             }//end of for
       
   571 
       
   572         //predict
       
   573         iEngine->PreviousCandidatePage();
       
   574         TPtrC aChar=iEngine->CandidatePage();
       
   575         iEngine->SetPredictiveChineseChar(aChar);
       
   576         AssertTrueL(ETrue, _L("next chinese char predicted"));
       
   577 
       
   578         //test next candidate list
       
   579         iEngine->CommitCurrentWord();
       
   580         CDesCArray* cands = new (ELeave) CDesCArrayFlat(16);
       
   581         CleanupStack::PushL(cands);
       
   582 
       
   583         TRAPD(err, iEngine->GetNextWordCandidateListL(*cands));
       
   584         if(err == KErrNotSupported)
       
   585             {
       
   586             AssertTrueL(ETrue, _L("predict next candidate not supported"));
       
   587             }
       
   588         else{
       
   589             TFileName msg=_L("candidates: ");
       
   590             for (int i = 0; i < cands->Count(); ++i)
       
   591             {
       
   592                 msg.Append(cands->MdcaPoint(i));
       
   593                 msg.Append(_L(", "));
       
   594             }
       
   595             msg.ZeroTerminate();
       
   596             AssertTrueL(ETrue, msg);
       
   597             }
       
   598         CleanupStack::PopAndDestroy();  // cands
       
   599 
       
   600         //test conversion
       
   601         TInt convCap=iEngine->AvailableCharConversions();
       
   602         if((convCap & EPtiSimplifiedToComplex)!=0)
       
   603             {
       
   604             AssertTrueL(ETrue, _L("can convert from simplified chinese to traditional"));
       
   605             }
       
   606         else
       
   607             {
       
   608             AssertIntL(0, convCap, _L("conv capability:"));
       
   609             }
       
   610         char inbuf[]={0x76, 0x84};
       
   611         char outbuf[]={0,0};
       
   612         iEngine->CharConversion(EPtiSimplifiedToComplex, inbuf, 2, outbuf);
       
   613         AssertTrueL(ETrue, _L("tried char conversion"));
       
   614 
       
   615         //Chinese Varient
       
   616         RArray<TInt> modes;
       
   617         iEngine->GetModeNameIndexL(EPtiChineseVariantPrc, modes);
       
   618         AssertTrueL(ETrue, _L("Chinese varient index table got"));
       
   619         modes.Close();
       
   620 
       
   621         //phrase list
       
   622         iEngine->ClearCurrentWord();
       
   623         SimuInput(iEngine, _L("wei"));
       
   624         cands = new (ELeave) CDesCArrayFlat(16);
       
   625         CleanupStack::PushL(cands);
       
   626         iEngine->GetChinesePhraseCandidatesL(*cands);
       
   627         AssertTrueL(ETrue, _L("Chinese phrase candidate list got"));
       
   628         CleanupStack::PopAndDestroy();  //cands
       
   629 
       
   630         TestSpellL();
       
   631         TestDictL();// test Pinyin dict.
       
   632         }
       
   633     else
       
   634         {
       
   635         AssertTrueL(ETrue, _L("unable to activate Chinese Pinyin"));
       
   636         if ( iEngine == NULL )
       
   637             {
       
   638             SetupL();
       
   639             } 
       
   640         iEngine->ActivateLanguageL(ELangEnglish, EPtiEnginePredictive);
       
   641         }
       
   642     }
       
   643 
       
   644 void CBCTestPtiEngine::TestSpellL()
       
   645     {
       
   646     TBuf<8> spell;
       
   647     TInt err=iEngine->GetSpelling(0x7684, spell, EPtiPinyin);
       
   648     if(err==KErrNotSupported)
       
   649         {
       
   650         AssertTrueL(ETrue, _L("get spelling not support"));
       
   651         }
       
   652     else if(err==KErrNone)
       
   653         {
       
   654         spell.ZeroTerminate();
       
   655         AssertTrueL(ETrue, spell);
       
   656         }
       
   657     else
       
   658         {
       
   659         AssertTrueL(ETrue, _L("get spelling failuer"));
       
   660         }
       
   661 
       
   662     //phonetic
       
   663     iEngine->ClearCurrentWord();
       
   664     SimuInput(iEngine, _L("wei"));
       
   665     TInt number = iEngine->PhoneticSpellingCount();
       
   666     TFileName msg;
       
   667     msg.Format(_L("phonetic spelling count: %d"), number);
       
   668     msg.ZeroTerminate();
       
   669     AssertTrueL(ETrue, msg);
       
   670 
       
   671     spell=iEngine->GetPhoneticSpelling(0);
       
   672     AssertTrueL(ETrue, _L("get phonetic spelling for 0"));
       
   673 
       
   674     TBool result = iEngine->SelectPhoneticSpelling(0);
       
   675     AssertTrueL(ETrue, _L("select phonetic spelling for 0"));
       
   676 
       
   677     number = iEngine->SelectedPhoneticSpelling();
       
   678     msg.Format(_L("selected phonetic spelling: %d"), number);
       
   679     msg.ZeroTerminate();
       
   680     AssertTrueL(ETrue, msg);
       
   681 
       
   682     CDesCArray* array = new (ELeave) CDesCArrayFlat(16);
       
   683     CleanupStack::PushL(array);
       
   684     iEngine->GetPhoneticSpellingsL(*array);
       
   685     AssertTrueL(ETrue, _L("phonetic spellings got"));
       
   686     CleanupStack::PopAndDestroy();  //array
       
   687     }
       
   688 
       
   689 void CBCTestPtiEngine::TestOtherL()
       
   690     {
       
   691     iEngine->HandleCommandL(EPtiCommandNone);
       
   692     AssertTrueL(ETrue, _L("handle command"));
       
   693 
       
   694     iEngine->EnableToneMarks(ETrue);
       
   695     iEngine->EnableToneMarks(EFalse);
       
   696     iEngine->ResetToneMark();
       
   697     AssertTrueL(ETrue, _L("tone mark set and reset"));
       
   698 
       
   699     TText result;
       
   700     iEngine->ToneMark(result);
       
   701     AssertTrueL(ETrue, _L("tone mark got"));
       
   702 
       
   703     if(iEngine->IsToneMarkValidForSpelling())
       
   704         AssertTrueL(ETrue, _L("tone mark is valid for spelling"));
       
   705     else
       
   706         AssertTrueL(ETrue, _L("tone mark is invalid for spelling"));
       
   707 
       
   708     if(iEngine->IncrementToneMark(ETrue))
       
   709         AssertTrueL(ETrue, _L("new tone mark was found and set"));
       
   710     else
       
   711         AssertTrueL(ETrue, _L("didn't found new tone mark"));
       
   712 
       
   713     if(iEngine->SetToneMark(0))
       
   714         AssertTrueL(ETrue, _L("tone mark was legal"));
       
   715     else
       
   716         AssertTrueL(ETrue, _L("illegal tone mark"));
       
   717 
       
   718     //key mapping
       
   719     TBuf<8> mapRes;
       
   720     iEngine->MappingDataForKey(EPtiKey2, mapRes, EPtiCaseLower);
       
   721     AssertTrueL(ETrue, _L("mapping data for key"));
       
   722 
       
   723     RArray<TPtiNumericKeyBinding> qwertyMapRes;
       
   724     iEngine->GetNumericModeKeysForQwertyL(ELangEnglish, qwertyMapRes);
       
   725     AssertTrueL(ETrue, _L("get numeric mode keys for qwerty keys"));
       
   726     qwertyMapRes.Close();
       
   727     }
       
   728 
       
   729 void CBCTestPtiEngine::TestJapaneseInputL()
       
   730     {
       
   731     Teardown();
       
   732 
       
   733     if((iEngine = CreateEngineL(ELangJapanese, /*EPtiEngineHiraganaKanji*/EPtiEnginePredictive))!=NULL)
       
   734         {
       
   735         AssertTrueL(ETrue, _L("Japanese Hirakana Kanji activated"));
       
   736         }
       
   737     else
       
   738         {
       
   739         AssertTrueL(ETrue, _L("can not activate Japanese input"));
       
   740         if ( iEngine == NULL )
       
   741             {
       
   742             SetupL();
       
   743             }        
       
   744         iEngine->ActivateLanguageL(ELangEnglish, EPtiEnginePredictive);
       
   745         }
       
   746 
       
   747     MPtiEngineCompositionDataInterface* data=iEngine->CompositionData();
       
   748     AssertTrueL(ETrue, _L("Japanese composition data IF got"));
       
   749 
       
   750     SimuInput(iEngine, _L("nihon"));
       
   751     TPtrC str=iEngine->ReadingTextL();
       
   752     AssertTrueL(ETrue, _L("reading text for japanese input"));
       
   753     iEngine->ClearCurrentWord();
       
   754     }