inputmethods/src/InputMethodSmokeTestModuleBlocks.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 /*
       
     2 * Copyright (c) 2009 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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: This file contains testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <Stiftestinterface.h>
       
    22 #include <ocrsrv.h>
       
    23 #include <ptiengine.h>
       
    24 #include <ptiuserdictionary.h>
       
    25 #include <Ecom/Ecom.h>
       
    26 #include "InputMethodSmokeTestModule.h"
       
    27 #include "TestOcrObserver.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 //extern  ?external_data;
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 //extern ?external_function( ?arg_type,?arg_type );
       
    34 
       
    35 // CONSTANTS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 const TInt KMaxSize = 32;
       
    38 
       
    39 // MACROS
       
    40 //#define ?macro ?macro_def
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 //const ?type ?constant_var = ?constant;
       
    44 //#define ?macro_name ?macro_def
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 //enum ?declaration
       
    48 //typedef ?declaration
       
    49 
       
    50 // LOCAL FUNCTION PROTOTYPES
       
    51 //?type ?function_name( ?arg_type, ?arg_type );
       
    52 
       
    53 // FORWARD DECLARATIONS
       
    54 //class ?FORWARD_CLASSNAME;
       
    55 
       
    56 // ============================= LOCAL FUNCTIONS ===============================
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // ?function_name ?description.
       
    60 // ?description
       
    61 // Returns: ?value_1: ?description
       
    62 //          ?value_n: ?description_line1
       
    63 //                    ?description_line2
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 /*
       
    67 ?type ?function_name(
       
    68     ?arg_type arg,  // ?description
       
    69     ?arg_type arg)  // ?description
       
    70     {
       
    71 
       
    72     ?code  // ?comment
       
    73 
       
    74     // ?comment
       
    75     ?code
       
    76     }
       
    77 */
       
    78 
       
    79 // ============================ MEMBER FUNCTIONS ===============================
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CInputMethodSmokeTestModule::Delete
       
    83 // Delete here all resources allocated and opened from test methods. 
       
    84 // Called from destructor. 
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CInputMethodSmokeTestModule::Delete() 
       
    88     {
       
    89 
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CInputMethodSmokeTestModule::RunMethodL
       
    94 // Run specified method. Contains also table of test mothods and their names.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 TInt CInputMethodSmokeTestModule::RunMethodL( 
       
    98     CStifItemParser& aItem ) 
       
    99     {
       
   100     static TStifFunctionInfo const KFunctions[] =
       
   101         {  
       
   102         // Copy this line for every implemented function.
       
   103         // First string is the function name used in TestScripter script file.
       
   104         // Second is the actual implementation member function. 
       
   105         ENTRY( "CreateOcrEngine", CInputMethodSmokeTestModule::CreateOcrEngineL ),
       
   106         ENTRY( "CreatePtiEngine", CInputMethodSmokeTestModule::CreatePtiEngineL ),
       
   107         ENTRY( "CreatePtiDictionary", CInputMethodSmokeTestModule::CreatePtiDictionaryL ),
       
   108         ENTRY( "MultitapWord", CInputMethodSmokeTestModule::MultitapWordL ),
       
   109         //ADD NEW ENTRY HERE
       
   110         // [test cases entries] - Do not remove
       
   111 
       
   112         };
       
   113 
       
   114     const TInt count = sizeof( KFunctions ) / 
       
   115                         sizeof( TStifFunctionInfo );
       
   116 
       
   117     return RunInternalL( KFunctions, count, aItem );
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CInputMethodSmokeTestModule::ExampleL
       
   122 // Example test method function.
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CInputMethodSmokeTestModule::CreateOcrEngineL( CStifItemParser& /*aItem*/ )
       
   127     {
       
   128     // Print to UI
       
   129     _LIT( KInputMethodSmokeTestModule, "InputMethodSmokeTestModule" );
       
   130     _LIT( KCreateOcrEngine, "In Create OCR Engine" );
       
   131     
       
   132     iLog->Log( KCreateOcrEngine );
       
   133     
       
   134     TOcrEngineEnv engineEnv;
       
   135     engineEnv.iPriority = EPriorityNormal;
       
   136     engineEnv.iMaxHeapSize = 1200+KMinHeapGrowBy+1;
       
   137     
       
   138     TTestOcrObserver observer;
       
   139     
       
   140     MOCREngineInterface* ocrEngine = NULL;
       
   141     ocrEngine = OCREngineFactory::CreateOCREngineL(observer, engineEnv, OCREngineFactory::EEngineLayoutRecognize);
       
   142     
       
   143     return KErrNone;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CInputMethodSmokeTestModule::ExampleL
       
   148 // Example test method function.
       
   149 // (other items were commented in a header).
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TInt CInputMethodSmokeTestModule::CreatePtiEngineL( CStifItemParser& /*aItem*/ )
       
   153     {
       
   154     // Print to UI
       
   155     _LIT( KInputMethodSmokeTestModule, "InputMethodSmokeTestModule" );
       
   156     _LIT( KCreatePtiEngine, "In Create PTI Engine" );
       
   157     
       
   158     iLog->Log( KCreatePtiEngine );
       
   159     
       
   160     CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
   161     CleanupStack::PushL(ptiEngine);
       
   162     
       
   163     ptiEngine->ActivateLanguageL(ELangEnglish, EPtiEngineMultitapping);
       
   164     
       
   165     CleanupStack::PopAndDestroy(ptiEngine);
       
   166     REComSession::FinalClose();
       
   167     
       
   168     return KErrNone;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CInputMethodSmokeTestModule::ExampleL
       
   173 // Example test method function.
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TInt CInputMethodSmokeTestModule::CreatePtiDictionaryL( CStifItemParser& /*aItem*/ )
       
   178     {
       
   179     // Print to UI
       
   180     _LIT( KInputMethodSmokeTestModule, "InputMethodSmokeTestModule" );
       
   181     _LIT( KCreatePtiDictionary, "In Create PTI Dictionary" );
       
   182     
       
   183     iLog->Log( KCreatePtiDictionary );
       
   184     
       
   185     CPtiUserDictionary* ptiDictionary = CPtiUserDictionary::NewL(KMaxSize);
       
   186 
       
   187     delete ptiDictionary;
       
   188     ptiDictionary = NULL;
       
   189     
       
   190     REComSession::FinalClose();
       
   191     
       
   192     return KErrNone;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CInputMethodSmokeTestModule::ExampleL
       
   197 // Example test method function.
       
   198 // (other items were commented in a header).
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TInt CInputMethodSmokeTestModule::MultitapWordL(CStifItemParser& aItem)
       
   202 	{
       
   203     // Print to UI
       
   204     _LIT( KInputMethodSmokeTestModule, "InputMethodSmokeTestModule" );
       
   205     _LIT( KMultitapWord, "In Multitap Word" );
       
   206     
       
   207     iLog->Log( KMultitapWord );
       
   208 	
       
   209 	TPtrC inputSequence;
       
   210 	if ( aItem.GetNextString(inputSequence) == KErrNone )
       
   211 		{
       
   212 		CPtiEngine *ptiEngine = CPtiEngine::NewL();
       
   213 		CleanupStack::PushL(ptiEngine);
       
   214 
       
   215 		// setup multitap
       
   216 		ptiEngine->ActivateLanguageL(ELangEnglish, EPtiEngineMultitapping);
       
   217 		PtiEngSimulateInput(ptiEngine, inputSequence);
       
   218 		
       
   219 		TPtrC expectedWord;
       
   220 		if ( aItem.GetNextString(expectedWord) == KErrNone )
       
   221 			{
       
   222 			if ( ptiEngine->CurrentWord() == expectedWord )
       
   223 				{
       
   224 				iLog->Log(_L("Words matched"));
       
   225 				}
       
   226 			else
       
   227 				{
       
   228 				User::Leave(KErrArgument);
       
   229 				}
       
   230 			}
       
   231 
       
   232 		ptiEngine->CommitCurrentWord();
       
   233 
       
   234 		ptiEngine->CloseCurrentLanguageL();
       
   235 		CleanupStack::PopAndDestroy(ptiEngine);
       
   236 		REComSession::FinalClose();
       
   237 		}
       
   238 
       
   239 	return KErrNone;
       
   240 	}
       
   241 
       
   242 void CInputMethodSmokeTestModule::PtiEngSimulateInput(CPtiEngine* aEngine, const TDesC& aKeys)
       
   243     {
       
   244     for(int i=0; i<aKeys.Length(); ++i)
       
   245         {
       
   246         if (aKeys[i] == ' ')
       
   247             {
       
   248             continue;
       
   249             }
       
   250         else if (aKeys[i] == 'p')
       
   251             {
       
   252             continue;
       
   253             }
       
   254         else if (aKeys[i] == 'd')
       
   255             {
       
   256             aEngine->DeleteKeyPress();
       
   257             }
       
   258         else
       
   259             {
       
   260             aEngine->AppendKeyPress(aEngine->CharacterToKey(aKeys[i]));
       
   261             }
       
   262         }
       
   263     }
       
   264 
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CInputMethodSmokeTestModule::?member_function
       
   268 // ?implementation_description
       
   269 // (other items were commented in a header).
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 /*
       
   273 TInt CInputMethodSmokeTestModule::?member_function(
       
   274    CItemParser& aItem )
       
   275    {
       
   276 
       
   277    ?code
       
   278 
       
   279    }
       
   280 */
       
   281 
       
   282 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   283 // None
       
   284 
       
   285 //  [End of File] - Do not remove