srsf/speechsynthesis/tsrc/speechsynthesistest/src/speechsynthesistestblocks.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32svr.h>
       
    21 #include <stifparser.h>
       
    22 #include <stiftestinterface.h>
       
    23 #include <StifTestEventInterface.h>
       
    24 
       
    25 #include "speechsynthesistest.h"
       
    26 
       
    27 #include "rubydebug.h"
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSpeechSynthesisTest::Delete
       
    32 // Delete here all resources allocated and opened from test methods. 
       
    33 // Called from destructor. 
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 void CSpeechSynthesisTest::Delete() 
       
    37     {
       
    38     delete iTester;
       
    39     iTester = NULL;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CSpeechSynthesisTest::RunMethodL
       
    44 // Run specified method. Contains also table of test mothods and their names.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 TInt CSpeechSynthesisTest::RunMethodL( CStifItemParser& aItem ) 
       
    48     {
       
    49     TStifFunctionInfo const KFunctions[] =
       
    50         {
       
    51         ENTRY( "Open",                      CSpeechSynthesisTest::OpenL ),
       
    52         ENTRY( "Close",                     CSpeechSynthesisTest::CloseL ),
       
    53         
       
    54         ENTRY( "InitialiseSynthesis",       CSpeechSynthesisTest::SynthesisInitL ),
       
    55         ENTRY( "InitialiseSynthesisFile",   CSpeechSynthesisTest::SynthesisInitFileL ),
       
    56         ENTRY( "Synthesise",                CSpeechSynthesisTest::SynthesiseL ),
       
    57         ENTRY( "Stop",                      CSpeechSynthesisTest::StopL ),
       
    58         ENTRY( "Pause",                     CSpeechSynthesisTest::PauseL ),
       
    59 
       
    60         ENTRY( "GetSupportedLangs",         CSpeechSynthesisTest::GetSupportedLanguagesL ),    
       
    61         
       
    62         ENTRY( "GetSupportedVoices",        CSpeechSynthesisTest::GetSupportedVoicesL ),
       
    63         ENTRY( "Voice",                     CSpeechSynthesisTest::VoiceL ),
       
    64         ENTRY( "SetVoice",                  CSpeechSynthesisTest::SetVoiceL ),
       
    65         
       
    66         ENTRY( "MaxVolume",                 CSpeechSynthesisTest::MaxVolumeL ),
       
    67         ENTRY( "Volume",                    CSpeechSynthesisTest::VolumeL ),
       
    68         ENTRY( "SetVolume",                 CSpeechSynthesisTest::SetVolumeL ),
       
    69         
       
    70         ENTRY( "MaxSpeakingRate",           CSpeechSynthesisTest::MaxSpeakingRateL ),
       
    71         ENTRY( "SpeakingRate",              CSpeechSynthesisTest::SpeakingRateL ),
       
    72         ENTRY( "SetSpeakingRate",           CSpeechSynthesisTest::SetSpeakingRateL ),
       
    73         
       
    74         ENTRY( "SetAudioPriority",          CSpeechSynthesisTest::SetAudioPriorityL ),
       
    75         ENTRY( "CustomCommand",             CSpeechSynthesisTest::CustomCommandL ),
       
    76         };
       
    77 
       
    78     const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo );
       
    79 
       
    80     return RunInternalL( KFunctions, count, aItem );
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CSpeechSynthesisTest::OpenL
       
    85 // 
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 TInt CSpeechSynthesisTest::OpenL( CStifItemParser& aItem )
       
    89     {
       
    90     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
    91     
       
    92     TInt result = iTester->Open();
       
    93     
       
    94     CheckResultL( expectedResult, result );
       
    95     
       
    96     return KErrNone;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CSpeechSynthesisTest::CloseL
       
   101 // 
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CSpeechSynthesisTest::CloseL( CStifItemParser& aItem )
       
   105     {
       
   106     // Expected result not used. 
       
   107     ReadExpectedResultL( aItem ); 
       
   108     
       
   109     iTester->Close();
       
   110     
       
   111     return KErrNone;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSpeechSynthesisTest::SynthesisInitL
       
   116 // 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CSpeechSynthesisTest::SynthesisInitL( CStifItemParser& aItem )
       
   120     {
       
   121     iExpectedResult = ReadExpectedResultL( aItem ); 
       
   122     
       
   123     TPtrC tmp;
       
   124     
       
   125     iText.Delete( 0, iText.MaxLength() );
       
   126     
       
   127     while ( aItem.GetNextString( tmp ) == KErrNone )
       
   128         {
       
   129         iText.Append( tmp );
       
   130         iText.Append( _L(" ") );
       
   131         }
       
   132 
       
   133     iTester->SynthesisInit( iText );
       
   134     
       
   135     return KErrNone;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CSpeechSynthesisTest::SynthesisInitFileL
       
   140 // 
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CSpeechSynthesisTest::SynthesisInitFileL( CStifItemParser& aItem )
       
   144     {
       
   145     iExpectedResult = ReadExpectedResultL( aItem ); 
       
   146     
       
   147     TInt result( KErrArgument );
       
   148     
       
   149     TPtrC tmp;
       
   150     TFileName fileName;
       
   151     
       
   152     iText.Delete( 0, iText.MaxLength() );
       
   153     
       
   154     while ( aItem.GetNextString( tmp ) == KErrNone )
       
   155         {
       
   156         if ( tmp != _L("filename:") )
       
   157             {
       
   158             iText.Append( tmp );
       
   159             iText.Append( _L(" ") );
       
   160             }
       
   161         else
       
   162             {
       
   163             break;
       
   164             }
       
   165         }
       
   166 
       
   167     if ( aItem.GetNextString( tmp ) == KErrNone )
       
   168         {
       
   169         fileName.Append( tmp );
       
   170         
       
   171         iTester->SynthesisInit( iText, fileName );
       
   172         
       
   173         result = KErrNone;
       
   174         }
       
   175     
       
   176     return result;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CSpeechSynthesisTest::SynthesiseL
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 TInt CSpeechSynthesisTest::SynthesiseL( CStifItemParser& aItem )
       
   185     {
       
   186     iExpectedResult = ReadExpectedResultL( aItem ); 
       
   187     
       
   188     iTester->Synthesise();
       
   189 
       
   190     return KErrNone;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CSpeechSynthesisTest::StopL
       
   195 // 
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CSpeechSynthesisTest::StopL( CStifItemParser& aItem )
       
   199     {
       
   200     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   201     
       
   202     TRAPD( result, iTester->StopL() );
       
   203     
       
   204     CheckResultL( expectedResult, result );
       
   205     
       
   206     return KErrNone;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CSpeechSynthesisTest::PauseL
       
   211 // 
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CSpeechSynthesisTest::PauseL( CStifItemParser& aItem )
       
   215     {
       
   216     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   217     
       
   218     TRAPD( result, iTester->PauseL() );
       
   219     
       
   220     CheckResultL( expectedResult, result );
       
   221     
       
   222     return KErrNone;
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CSpeechSynthesisTest::GetSupportedLanguagesL
       
   227 // 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TInt CSpeechSynthesisTest::GetSupportedLanguagesL( CStifItemParser& aItem )
       
   231     {
       
   232     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   233     
       
   234     RArray<TLanguage> languages;
       
   235     CleanupClosePushL( languages );
       
   236     
       
   237     TRAPD( result, iTester->GetSupportedLanguagesL( languages ) );
       
   238     
       
   239     CleanupStack::PopAndDestroy( &languages );
       
   240     
       
   241     CheckResultL( expectedResult, result );
       
   242     
       
   243     return KErrNone;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CSpeechSynthesisTest::GetSupportedVoicesL
       
   248 // 
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 TInt CSpeechSynthesisTest::GetSupportedVoicesL( CStifItemParser& aItem )
       
   252     {
       
   253     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   254     
       
   255     RArray<TVoice> voices;
       
   256     CleanupClosePushL( voices );
       
   257     
       
   258     TInt tmp;
       
   259     User::LeaveIfError( aItem.GetNextInt( tmp ) );
       
   260     TLanguage language( (TLanguage)tmp );
       
   261     
       
   262     TRAPD( result, iTester->GetSupportedVoicesL( voices, language ) ); 
       
   263     
       
   264     CleanupStack::PopAndDestroy( &voices );
       
   265     
       
   266     CheckResultL( expectedResult, result );
       
   267     
       
   268     return KErrNone;
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CSpeechSynthesisTest::VoiceL
       
   273 // 
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TInt CSpeechSynthesisTest::VoiceL( CStifItemParser& aItem )
       
   277     {
       
   278     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   279     
       
   280     TVoice voice;
       
   281     
       
   282     TRAPD( result, voice = iTester->VoiceL() );
       
   283     
       
   284     CheckResultL( expectedResult, result );
       
   285     
       
   286     return KErrNone;
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CSpeechSynthesisTest::SetVoiceL
       
   291 // 
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 TInt CSpeechSynthesisTest::SetVoiceL( CStifItemParser& aItem )
       
   295     {
       
   296     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   297     
       
   298     // @todo Implement this!
       
   299     TInt result = KErrNotSupported;
       
   300     
       
   301     CheckResultL( expectedResult, result );
       
   302     
       
   303     return KErrNone;
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CSpeechSynthesisTest::MaxVolumeL
       
   308 // 
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TInt CSpeechSynthesisTest::MaxVolumeL( CStifItemParser& aItem )
       
   312     {
       
   313     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   314     
       
   315     TInt maxVolume( -1 );
       
   316     
       
   317     TRAPD( result, maxVolume = iTester->MaxVolumeL() );
       
   318     
       
   319     CheckResultL( expectedResult, result );
       
   320     
       
   321     TestModuleIf().Printf( 0, _L("MaxVolume:"), _L("%d"), maxVolume );
       
   322     
       
   323     return KErrNone;
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CSpeechSynthesisTest::VolumeL
       
   328 // 
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 TInt CSpeechSynthesisTest::VolumeL( CStifItemParser& aItem )
       
   332     {
       
   333     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   334     
       
   335     TInt volume( -1 );
       
   336     
       
   337     TRAPD( result, volume = iTester->VolumeL() );
       
   338     
       
   339     CheckResultL( expectedResult, result );
       
   340     
       
   341     TestModuleIf().Printf( 1, _L("Volume:"), _L("%d"), volume );
       
   342     
       
   343     return KErrNone;
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CSpeechSynthesisTest::SetVolumeL
       
   348 // 
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TInt CSpeechSynthesisTest::SetVolumeL( CStifItemParser& aItem )
       
   352     {
       
   353     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   354     
       
   355     TInt newVolume;
       
   356     aItem.GetNextInt( newVolume );
       
   357     
       
   358     TRAPD( result, iTester->SetVolumeL( newVolume * iTester->MaxVolumeL() / 10 ) );
       
   359     
       
   360     CheckResultL( expectedResult, result ); 
       
   361     
       
   362     return KErrNone;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CSpeechSynthesisTest::MaxSpeakingRateL
       
   367 // 
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 TInt CSpeechSynthesisTest::MaxSpeakingRateL( CStifItemParser& aItem )
       
   371     {
       
   372     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   373     
       
   374     TInt maxSpeakingRate( -1 ); 
       
   375     
       
   376     TRAPD( result, maxSpeakingRate = iTester->MaxSpeakingRateL() ); 
       
   377     
       
   378     CheckResultL( expectedResult, result ); 
       
   379     
       
   380     TestModuleIf().Printf( 2, _L("maxSpeakingRate:"), _L("%d"), maxSpeakingRate );
       
   381     
       
   382     return KErrNone;
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CSpeechSynthesisTest::SpeakingRateL
       
   387 // 
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 TInt CSpeechSynthesisTest::SpeakingRateL( CStifItemParser& aItem )
       
   391     {
       
   392     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   393     
       
   394     TInt rate( -1 );
       
   395     
       
   396     TRAPD( result, rate = iTester->SpeakingRateL() );
       
   397     
       
   398     CheckResultL( expectedResult, result ); 
       
   399     
       
   400     TestModuleIf().Printf( 3, _L("SpeakingRate:"), _L("%d"), rate );
       
   401     
       
   402     return KErrNone;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CSpeechSynthesisTest::SetSpeakingRateL
       
   407 // 
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 TInt CSpeechSynthesisTest::SetSpeakingRateL( CStifItemParser& aItem )
       
   411     {
       
   412     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   413     
       
   414     TInt newRate;
       
   415     aItem.GetNextInt( newRate );
       
   416     
       
   417     TRAPD( result, iTester->SetSpeakingRateL( newRate ) );
       
   418     
       
   419     CheckResultL( expectedResult, result ); 
       
   420     
       
   421     return KErrNone;
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CSpeechSynthesisTest::SetAudioPriorityL
       
   426 // 
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 TInt CSpeechSynthesisTest::SetAudioPriorityL( CStifItemParser& aItem )
       
   430     {
       
   431     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   432     
       
   433     TInt priority( -1 );
       
   434     aItem.GetNextInt( priority );
       
   435     
       
   436     TInt preference( -1 );
       
   437     aItem.GetNextInt( preference );
       
   438     
       
   439     TRAPD( result, iTester->SetAudioPriorityL( priority, preference ) );
       
   440     
       
   441     CheckResultL( expectedResult, result ); 
       
   442     
       
   443     return KErrNone;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CSpeechSynthesisTest::CustomCommandL
       
   448 // 
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TInt CSpeechSynthesisTest::CustomCommandL( CStifItemParser& aItem )
       
   452     {
       
   453     TInt expectedResult = ReadExpectedResultL( aItem ); 
       
   454     
       
   455     TRAPD( result, iTester->CustomCommandL( 0, 0 ) );
       
   456     
       
   457     CheckResultL( expectedResult, result );
       
   458         
       
   459     return KErrNone;
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CSpeechSynthesisTest::SynthesisInitComplete
       
   464 // 
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CSpeechSynthesisTest::SynthesisInitComplete( TInt aError )
       
   468     {
       
   469     RUBY_DEBUG0( "SynthesisInitComplete - START" );
       
   470     
       
   471     if ( iExpectedResult != aError )
       
   472         {
       
   473         RUBY_ERROR2( "CSpeechSynthesisTest::SynthesisInitComplete -- %d != %d", 
       
   474                      iExpectedResult, aError );
       
   475         User::Panic( _L("InitComplete"), aError );
       
   476         }
       
   477     
       
   478     TEventIf stifEvent( TEventIf::ESetEvent,  _L( "SynthesisInitComplete" ) );
       
   479     
       
   480     TestModuleIf().Event( stifEvent );
       
   481     
       
   482     RUBY_DEBUG0( "SynthesisInitComplete - EXIT" );
       
   483     }
       
   484     
       
   485 // -----------------------------------------------------------------------------
       
   486 // CSpeechSynthesisTest::SynthesisComplete
       
   487 // 
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 void CSpeechSynthesisTest::SynthesisComplete( TInt aError )
       
   491     {
       
   492     RUBY_DEBUG0( "SynthesisComplete - START" );
       
   493     
       
   494     if ( iExpectedResult != aError )
       
   495         {
       
   496         RUBY_ERROR2( "CSpeechSynthesisTest::SynthesisComplete -- %d != %d", 
       
   497                      iExpectedResult, aError );
       
   498         User::Panic( _L("Complete"), aError );
       
   499         }
       
   500 
       
   501     TEventIf stifEvent( TEventIf::ESetEvent,  _L( "SynthesisComplete" ) );
       
   502     
       
   503     TestModuleIf().Event( stifEvent );
       
   504     
       
   505     RUBY_DEBUG0( "SynthesisComplete - EXIT" );
       
   506     }
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CSpeechSynthesisTest::ReadExpectedResultL
       
   510 // 
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 TInt CSpeechSynthesisTest::ReadExpectedResultL( CStifItemParser& aItem )
       
   514     {
       
   515     TInt expectedResult( -1 );
       
   516     
       
   517     User::LeaveIfError( aItem.GetNextInt( expectedResult ) );
       
   518 
       
   519     return expectedResult;
       
   520     }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CSpeechSynthesisTest::CheckResultL
       
   524 // 
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 void CSpeechSynthesisTest::CheckResultL( TInt aExpectedResult, TInt aResult )
       
   528     {
       
   529     RUBY_DEBUG_BLOCKL( "" );
       
   530     
       
   531     if ( aExpectedResult != aResult )
       
   532         {
       
   533         RUBY_ERROR2( "aExpectedResult = %d - aResult = %d", aExpectedResult, aResult );
       
   534         
       
   535         User::Leave( KErrCompletion );
       
   536         }
       
   537     }
       
   538     
       
   539 //  End of File