mmsharing/mmshindicator/tsrc/ut_indicator/src/ut_cmussoundplayer.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 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:  Unit tests for CMusSoundPlayer class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "ut_cmussoundplayer.h"
       
    21 #include <audiopreference.h>
       
    22 #include <digia/eunit/eunitmacros.h>
       
    23 
       
    24 
       
    25 // Next row is to disable warning emerging from EUnit code.
       
    26 #pragma warn_illtokenpasting off
       
    27 
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 
       
    32 UT_CMusSoundPlayer* UT_CMusSoundPlayer::NewL()
       
    33     {
       
    34     UT_CMusSoundPlayer* self = UT_CMusSoundPlayer::NewLC();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 UT_CMusSoundPlayer* UT_CMusSoundPlayer::NewLC()
       
    41     {
       
    42     UT_CMusSoundPlayer* self = new( ELeave ) UT_CMusSoundPlayer();
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 UT_CMusSoundPlayer::~UT_CMusSoundPlayer()
       
    50     {
       
    51     delete iSoundPlayer;
       
    52     iSoundPlayer = NULL;
       
    53     }
       
    54 
       
    55 
       
    56 UT_CMusSoundPlayer::UT_CMusSoundPlayer()
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    63 // It generates the test case table.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void UT_CMusSoundPlayer::ConstructL()
       
    67     {
       
    68     CEUnitTestSuiteClass::ConstructL();
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // From MMusSoundPlayerObserver.
       
    74 // Notifies of sound playing complete.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void UT_CMusSoundPlayer::PlaySoundComplete( TInt /*aError*/ )
       
    78     {
       
    79     }
       
    80 
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Prepares a test for execution.
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 void UT_CMusSoundPlayer::SetupL()
       
    87     {
       
    88     iSoundPlayer = CMusSoundPlayer::NewL( *this );
       
    89     }
       
    90 
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // Finalizes a test by releasing used resources.
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 void UT_CMusSoundPlayer::Teardown()
       
    97     {
       
    98     delete iSoundPlayer;
       
    99     }
       
   100 
       
   101 
       
   102 // ======== UNIT TEST METHODS ========
       
   103 
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // Asserts that instantiation is successful.
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_NewLL()
       
   110     {
       
   111     EUNIT_ASSERT( iSoundPlayer );
       
   112     }
       
   113 
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // Asserts that instantiation is successful.
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_NewLCL()
       
   120     {
       
   121     delete iSoundPlayer;
       
   122     iSoundPlayer = NULL;
       
   123     iSoundPlayer = CMusSoundPlayer::NewLC( *this );
       
   124     CleanupStack::Pop( iSoundPlayer );
       
   125     EUNIT_ASSERT( iSoundPlayer );
       
   126     }
       
   127 
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // Dummy test.
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_PlayLL()
       
   134     {
       
   135     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
       
   136     EUNIT_ASSERT( iSoundPlayer->iMdaPlayer )
       
   137     EUNIT_ASSERT_EQUALS( iSoundPlayer->iState,
       
   138                          CMusSoundPlayer::ESoundPlayerPlaying )
       
   139     
       
   140     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   141                     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound ),
       
   142                     KErrNotReady )
       
   143     }
       
   144 
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // Asserts that stopping works.
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_StopL()
       
   151     {
       
   152     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
       
   153     iSoundPlayer->Stop();
       
   154     EUNIT_ASSERT( CMusSoundPlayer::ESoundPlayerReady == iSoundPlayer->iState );
       
   155     
       
   156     // No harm done if called second time
       
   157     iSoundPlayer->Stop();
       
   158     }
       
   159 
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // Asserts that failure in init deletes MDA sound player instance.
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_MapcInitCompleteL()
       
   166     {
       
   167     iSoundPlayer->iMdaPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(
       
   168         _L( "C:\\wav.wav" ),
       
   169         *iSoundPlayer,
       
   170         EMdaPriorityMax,
       
   171         (TMdaPriorityPreference) KAudioPrefVoiceAid );
       
   172     iSoundPlayer->MapcInitComplete( KErrGeneral, 1000 );
       
   173     EUNIT_ASSERT( !iSoundPlayer->iMdaPlayer );
       
   174     }
       
   175 
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // Asserts that completion of playback deletes MDA sound player instance.
       
   179 // ----------------------------------------------------------------------------
       
   180 //
       
   181 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_MapcPlayCompleteL()
       
   182     {
       
   183     iSoundPlayer->iMdaPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(
       
   184         _L( "C:\\wav.wav" ),
       
   185         *iSoundPlayer,
       
   186         EMdaPriorityMax,
       
   187         (TMdaPriorityPreference) KAudioPrefVoiceAid );
       
   188     iSoundPlayer->MapcPlayComplete( KErrNone );
       
   189     EUNIT_ASSERT( !iSoundPlayer->iMdaPlayer );
       
   190     }
       
   191 
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // Asserts that sound filename is generated.
       
   195 // ----------------------------------------------------------------------------
       
   196 //
       
   197 void UT_CMusSoundPlayer::UT_CMusSoundPlayer_SoundFileNameLCL()
       
   198     {
       
   199     HBufC* filename = iSoundPlayer->SoundFileNameLC(
       
   200         CMusSoundPlayer::EVsAvailableSound );
       
   201     EUNIT_ASSERT( filename );
       
   202     EUNIT_ASSERT( filename->Length() );
       
   203     CleanupStack::PopAndDestroy( filename );
       
   204     }
       
   205 
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 // 
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void UT_CMusSoundPlayer::IT_CMusSoundPlayer_DeletePlayerWhenPlaying()
       
   212     {
       
   213     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
       
   214     EUNIT_ASSERT( iSoundPlayer->iMdaPlayer )
       
   215     EUNIT_ASSERT_EQUALS( iSoundPlayer->iState,
       
   216                          CMusSoundPlayer::ESoundPlayerPlaying )
       
   217 
       
   218     delete iSoundPlayer;
       
   219     iSoundPlayer = NULL;
       
   220     }
       
   221  
       
   222 
       
   223 // ======== EUNIT TEST TABLE ========
       
   224 
       
   225 
       
   226 EUNIT_BEGIN_TEST_TABLE(
       
   227     UT_CMusSoundPlayer,
       
   228     "UT_CMusSoundPlayer",
       
   229     "UNIT" )
       
   230 
       
   231 EUNIT_TEST(
       
   232     "NewL - test",
       
   233     "CMusSoundPlayer",
       
   234     "NewL",
       
   235     "FUNCTIONALITY",
       
   236     SetupL, UT_CMusSoundPlayer_NewLL, Teardown )
       
   237 
       
   238 EUNIT_TEST(
       
   239     "NewLC - test ",
       
   240     "CMusSoundPlayer",
       
   241     "NewLC",
       
   242     "FUNCTIONALITY",
       
   243     SetupL, UT_CMusSoundPlayer_NewLCL, Teardown )
       
   244 
       
   245 EUNIT_TEST(
       
   246     "PlayL - test ",
       
   247     "CMusSoundPlayer",
       
   248     "PlayL",
       
   249     "FUNCTIONALITY",
       
   250     SetupL, UT_CMusSoundPlayer_PlayLL, Teardown )
       
   251 
       
   252 EUNIT_TEST(
       
   253     "Stop - test ",
       
   254     "CMusSoundPlayer",
       
   255     "Stop",
       
   256     "FUNCTIONALITY",
       
   257     SetupL, UT_CMusSoundPlayer_StopL, Teardown )
       
   258 
       
   259 EUNIT_TEST(
       
   260     "MapcInitComplete - test ",
       
   261     "CMusSoundPlayer",
       
   262     "MapcInitComplete",
       
   263     "FUNCTIONALITY",
       
   264     SetupL, UT_CMusSoundPlayer_MapcInitCompleteL, Teardown )
       
   265 
       
   266 EUNIT_TEST(
       
   267     "MapcPlayComplete - test ",
       
   268     "CMusSoundPlayer",
       
   269     "MapcPlayComplete",
       
   270     "FUNCTIONALITY",
       
   271     SetupL, UT_CMusSoundPlayer_MapcPlayCompleteL, Teardown )
       
   272 
       
   273 EUNIT_TEST(
       
   274     "SoundFileNameLC - test ",
       
   275     "CMusSoundPlayer",
       
   276     "SoundFileNameLC",
       
   277     "FUNCTIONALITY",
       
   278     SetupL, UT_CMusSoundPlayer_SoundFileNameLCL, Teardown )
       
   279 
       
   280 EUNIT_TEST(
       
   281     "Test deleting player when playing",
       
   282     "CMusSoundPlayer",
       
   283     "Destructor",
       
   284     "FUNCTIONALITY",
       
   285     SetupL, IT_CMusSoundPlayer_DeletePlayerWhenPlaying, Teardown )
       
   286 
       
   287 
       
   288 EUNIT_END_TEST_TABLE