mmshplugins/mmshaoplugin/tsrc/ut_aoplugin/src/ut_musaoplugin.cpp
changeset 0 f0cf47e981f9
child 32 73a1feb507fb
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Main plugin class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ut_musaoplugin.h"   
       
    20 #include "muscallmonitor.h"
       
    21 #include "musaoplugin.h"
       
    22 #include "mustsypropertymonitor.h"
       
    23 #include "musresourceproperties.h"
       
    24 #include "mussesseioninformationapi.h"
       
    25 #include "mussettings.inl"
       
    26 
       
    27 
       
    28 #include <alwaysonlinemanagercommon.h>
       
    29 #include <alwaysonlinemanagerclient.h>
       
    30 #include <digia/eunit/eunitmacros.h>
       
    31 #include "FeatMgr.h"
       
    32 
       
    33 
       
    34 
       
    35 #pragma warn_illtokenpasting off
       
    36 
       
    37 _LIT( KEmptyTelNumber, "");
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // Symbian two-phase constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 // 
       
    44 UT_CMusAoPlugin* UT_CMusAoPlugin::NewLC()
       
    45     {
       
    46     UT_CMusAoPlugin* self = new (ELeave) UT_CMusAoPlugin();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();    
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // C++ destructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 // 
       
    57 UT_CMusAoPlugin::~UT_CMusAoPlugin()
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // C++ constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 // 
       
    66 UT_CMusAoPlugin::UT_CMusAoPlugin()
       
    67     : CEUnitTestSuiteClass()
       
    68     {
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // Symbian second-phase constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 // 
       
    76 void UT_CMusAoPlugin::ConstructL()
       
    77     {
       
    78     CEUnitTestSuiteClass::ConstructL();
       
    79     }
       
    80 
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 // -----------------------------------------------------------------------------
       
    85 // 
       
    86 void UT_CMusAoPlugin::SetupL(  )
       
    87     {
       
    88     TInt keyValue = 0;    
       
    89     MultimediaSharingSettings::SetPropertyValueL(
       
    90                             MusSettingsKeys::KProductModeVariation,keyValue);                               
       
    91     iPlugin = CMusAoPlugin::NewL();   
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 // -----------------------------------------------------------------------------
       
    98 // 
       
    99 void UT_CMusAoPlugin::Teardown(  )
       
   100     {
       
   101     delete iPlugin;
       
   102     iPlugin = NULL ;
       
   103     PropertyHelper::Close();
       
   104     
       
   105     }
       
   106 	
       
   107 	
       
   108 //// -----------------------------------------------------------------------------
       
   109 ////
       
   110 //// -----------------------------------------------------------------------------
       
   111 //// 
       
   112 void UT_CMusAoPlugin::NewLL()
       
   113 	{
       
   114 	
       
   115     TInt res = KErrNone;
       
   116     TInt ret = KErrNone;
       
   117 	FeatureManager::MultimediaSharingNotSupported();
       
   118 	iPlugin->DeleteProperties();
       
   119     delete iPlugin;
       
   120     iPlugin = NULL ;
       
   121 	iPlugin = CMusAoPlugin::NewL(); 
       
   122 	EUNIT_ASSERT( iPlugin );
       
   123     EUNIT_ASSERT( iPlugin->iTsyPropertyMonitor == NULL);
       
   124     EUNIT_ASSERT( iPlugin->iPropertyMonitor == NULL);
       
   125     // camera information property
       
   126     ret = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   127             NMusResourceApi::KCameraInformation,
       
   128                           res );
       
   129     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   130     ret = KErrNone;
       
   131 
       
   132     // call event
       
   133     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   134                           NMusSessionInformationApi::KMusCallEvent,
       
   135                           res );
       
   136     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   137     ret = KErrNone;
       
   138     
       
   139     // phone number
       
   140     TBuf<15> telnumber; // TODO change to des
       
   141     User::LeaveIfError( RProperty::Get(
       
   142                             NMusSessionInformationApi::KCategoryUid,
       
   143                             NMusSessionInformationApi::KMusTelNumber,
       
   144                             telnumber ) );
       
   145     EUNIT_ASSERT_EQUALS( telnumber.Compare( KEmptyTelNumber ), KErrNone )
       
   146     
       
   147     // Mus allowed
       
   148     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   149                           NMusSessionInformationApi::KMUSForbidden,
       
   150                           res );
       
   151     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   152     ret = KErrNone;
       
   153 
       
   154     // Call direction
       
   155     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   156                           NMusSessionInformationApi::KMusCallDirection,
       
   157                           res );
       
   158     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   159     FeatureManager::MultimediaSharingSupported();
       
   160 	}
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 // -----------------------------------------------------------------------------
       
   165 // 
       
   166 void UT_CMusAoPlugin::DefinePropertiesLL()
       
   167     {
       
   168 /* Test 1 */  
       
   169     /* Set Product Mode variation key value to
       
   170        00 - VideoPlayer always available
       
   171        0-Keypad available dynamic
       
   172        00-Keypad Usuable in portrait
       
   173        0-Camera available static
       
   174        00-Usuable Always
       
   175        00000000 = 0 (Int)
       
   176      */
       
   177     TInt keyValue = 0;    
       
   178     MultimediaSharingSettings::SetPropertyValueL(
       
   179     						MusSettingsKeys::KProductModeVariation,keyValue);     						    
       
   180     iPlugin->DefinePropertiesL();
       
   181     // It should not configure any PS keys for camera
       
   182     // Check the stub whether define is called.   
       
   183     TInt err = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   184                     NMusResourceApi::KCameraAvailability,
       
   185                     keyValue );
       
   186     EUNIT_ASSERT(keyValue == KErrNotFound );
       
   187     // Keypad availability is static . 
       
   188     // Check the stub whether define is called. 
       
   189     err = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   190                     NMusResourceApi::KKeypadAvailability,
       
   191                     keyValue );
       
   192                     
       
   193     EUNIT_ASSERT(keyValue == KErrNotFound );  
       
   194     
       
   195     iPlugin->DeleteProperties();
       
   196     
       
   197     
       
   198 /* Test 2 */
       
   199     
       
   200     /* Set Product Mode variation key value to
       
   201        11 - VideoPlayer always available
       
   202        1-Keypad available dynamic
       
   203        11-Keypad Usuable in portrait
       
   204        1-Camera available static
       
   205        11-Usuable Always
       
   206        11111111 = 255 (Int)
       
   207      */
       
   208 	keyValue = 255;
       
   209     MultimediaSharingSettings::SetPropertyValueL(
       
   210     						MusSettingsKeys::KProductModeVariation,keyValue);
       
   211     PropertyHelper::SetErrorCode(KErrNone);    	    
       
   212     iPlugin->DefinePropertiesL();						
       
   213     // It should configure any PS keys for Keypad
       
   214     // Check the stub whether define is called.     
       
   215     err = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   216                     NMusResourceApi::KKeypadAvailability,
       
   217                     keyValue );    
       
   218     EUNIT_ASSERT(keyValue ==NMusResourceApi::ENotAvailable );
       
   219     
       
   220     // camera availability is dynamic . 
       
   221     // so it must define a property
       
   222     // Check the stub whether define is called.     
       
   223     err = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   224                     NMusResourceApi::KCameraAvailability,
       
   225                     keyValue );                    
       
   226     EUNIT_ASSERT(keyValue == NMusResourceApi::ENotAvailable ); 	
       
   227     iPlugin->DeleteProperties();
       
   228     
       
   229  /* Test 3 */
       
   230 
       
   231     iPlugin->DefinePropertiesL();                       
       
   232 
       
   233     // camera information property
       
   234     TInt res = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   235                                         NMusResourceApi::KCameraInformation,
       
   236                                         keyValue );
       
   237     EUNIT_ASSERT_EQUALS( keyValue, NMusResourceApi::EUsePrimaryCamera )    
       
   238     
       
   239     // call event
       
   240     RProperty::Get(NMusSessionInformationApi::KCategoryUid,
       
   241                    NMusSessionInformationApi::KMusCallEvent,
       
   242                                 keyValue );
       
   243     EUNIT_ASSERT_EQUALS( keyValue, NMusSessionInformationApi::ENoCall )    
       
   244     
       
   245     // phone number
       
   246     TBuf<15> telnumber; // TODO change to des
       
   247     User::LeaveIfError( RProperty::Get(
       
   248                             NMusSessionInformationApi::KCategoryUid,
       
   249                             NMusSessionInformationApi::KMusTelNumber,
       
   250                             telnumber ) );
       
   251     EUNIT_ASSERT_EQUALS( telnumber.Compare( KEmptyTelNumber ), KErrNone )
       
   252 
       
   253     // Mus allowed
       
   254     RProperty::Get(NMusSessionInformationApi::KCategoryUid,
       
   255                    NMusSessionInformationApi::KMUSForbidden,
       
   256                    keyValue ) ;
       
   257     EUNIT_ASSERT_EQUALS( keyValue, NMusSessionInformationApi::EMUSAllowed )    
       
   258 
       
   259     // Call direction
       
   260     RProperty::Get(NMusSessionInformationApi::KCategoryUid,
       
   261                    NMusSessionInformationApi::KMusCallDirection,
       
   262                    keyValue ) ;
       
   263     EUNIT_ASSERT_EQUALS( keyValue, NMusSessionInformationApi::ENoDirection )    
       
   264     
       
   265     }
       
   266 
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 // -----------------------------------------------------------------------------
       
   271 // 
       
   272 void UT_CMusAoPlugin::DefinePropertyL_IntPropertyL()
       
   273     {
       
   274     // Normal succcesfull case
       
   275     const TInt KTestAvailability( 0x10282300 ); // Imaginary test value
       
   276     const TInt KTestValue = 50; // Imaginary test value
       
   277     iPlugin->DefinePropertyL( KTestAvailability, RProperty::EInt, KTestValue );
       
   278     
       
   279     TInt keyValueInPS( 0 );
       
   280     User::LeaveIfError( RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   281                                         KTestAvailability,
       
   282                                         keyValueInPS ) );
       
   283     EUNIT_ASSERT_EQUALS( keyValueInPS, KTestValue )    
       
   284     
       
   285     // When trying to define existing property, we are not supposed to 
       
   286     // overwrite already existing value
       
   287     const TInt KTestValue100 = 100; // Imaginary test value
       
   288     PropertyHelper::SetErrorCode( KErrAlreadyExists );
       
   289     iPlugin->DefinePropertyL( KTestAvailability, 
       
   290                               RProperty::EInt, 
       
   291                               KTestValue100 );
       
   292     PropertyHelper::SetErrorCode( KErrNone );
       
   293     
       
   294     User::LeaveIfError( RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   295                     KTestAvailability,
       
   296                     keyValueInPS ) );
       
   297     EUNIT_ASSERT_EQUALS( keyValueInPS, KTestValue ) // Value not changed
       
   298     }
       
   299 
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 // -----------------------------------------------------------------------------
       
   304 // 
       
   305 void UT_CMusAoPlugin::DefinePropertyL_DesCPropertyL()
       
   306     {
       
   307     // Normal succcesfull case
       
   308     const TInt KTestAvailability( 0x10282300 ); // Imaginary test value
       
   309     _LIT( KTestValue, "TestValue" ); // Imaginary test value
       
   310     iPlugin->DefinePropertyL( KTestAvailability, RProperty::EText, KTestValue );
       
   311     
       
   312     TBuf<100> keyValueInPS( KNullDesC );
       
   313     User::LeaveIfError( RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   314                                         KTestAvailability,
       
   315                                         keyValueInPS ) );
       
   316     EUNIT_ASSERT_EQUALS( keyValueInPS, KTestValue )    
       
   317     
       
   318     // When trying to define existing property, we are not supposed to 
       
   319     // overwrite already existing value
       
   320     _LIT( KNewTestValue, "NewTestValue" ); // Imaginary test value
       
   321     PropertyHelper::SetErrorCode( KErrAlreadyExists );
       
   322     iPlugin->DefinePropertyL( KTestAvailability, 
       
   323                               RProperty::EText, 
       
   324                               KNewTestValue );
       
   325     PropertyHelper::SetErrorCode( KErrNone );
       
   326     
       
   327     User::LeaveIfError( RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   328                     KTestAvailability,
       
   329                     keyValueInPS ) );
       
   330     EUNIT_ASSERT_EQUALS( keyValueInPS, KTestValue ) // Value not changed
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 // -----------------------------------------------------------------------------
       
   336 // 
       
   337 void UT_CMusAoPlugin::DeletePropertiesL()
       
   338     {    
       
   339     // Initialize     
       
   340     iPlugin->DefinePropertiesL();
       
   341     // and delete all
       
   342     iPlugin->DeleteProperties();
       
   343     
       
   344     TInt res = KErrNone;
       
   345     TInt ret = KErrNone;
       
   346     // camera availability
       
   347     ret = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   348                           NMusResourceApi::KCameraAvailability,
       
   349                           res );
       
   350     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   351     ret = KErrNone;
       
   352 
       
   353 
       
   354     // keybad availability
       
   355     ret = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   356                           NMusResourceApi::KKeypadAvailability,
       
   357                           res );
       
   358     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   359     ret = KErrNone;
       
   360     
       
   361     // videoplayer availability
       
   362     ret = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   363                           NMusResourceApi::KVideoPlayerAvailability,
       
   364                           res );
       
   365     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   366     ret = KErrNone;
       
   367 
       
   368     // camera information property
       
   369     ret = RProperty::Get( NMusResourceApi::KCategoryUid,
       
   370                           NMusResourceApi::KCameraInformation,
       
   371                           res );
       
   372     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   373     ret = KErrNone;
       
   374     
       
   375     // call event
       
   376     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   377                           NMusSessionInformationApi::KMusCallEvent,
       
   378                           res );
       
   379     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   380     ret = KErrNone;
       
   381     
       
   382     // phone number
       
   383     /* hard to provide stub impl
       
   384     TBuf<15> telnumber; // TODO change to des
       
   385     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   386                           NMusSessionInformationApi::KMusTelNumber,
       
   387                           telnumber );
       
   388     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   389     */
       
   390     
       
   391     ret = KErrNone;
       
   392 
       
   393     // Mus allowed
       
   394     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   395                           NMusSessionInformationApi::KMUSForbidden,
       
   396                           res );
       
   397     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   398     ret = KErrNone;
       
   399 
       
   400     // Call direction
       
   401     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   402                           NMusSessionInformationApi::KMusCallDirection,
       
   403                           res );
       
   404     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   405     
       
   406     // Call privacy
       
   407     ret = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   408                           NMusSessionInformationApi::KMUSPrivacy,
       
   409                           res );
       
   410     EUNIT_ASSERT_EQUALS( ret, KErrNotFound )
       
   411 
       
   412 
       
   413     }
       
   414 
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 // -----------------------------------------------------------------------------
       
   419 // 
       
   420 void UT_CMusAoPlugin::UT_HandleServerCommandLL()
       
   421     {
       
   422     TAny* a = iPlugin->HandleServerCommandL( EAOManagerPluginStart, NULL );
       
   423     EUNIT_ASSERT( a )
       
   424     }
       
   425 
       
   426 
       
   427 //  TEST TABLE
       
   428 
       
   429 EUNIT_BEGIN_TEST_TABLE(
       
   430     UT_CMusAoPlugin,
       
   431     "UT_CMusAoPlugin",
       
   432     "UNIT")
       
   433 
       
   434 EUNIT_TEST(
       
   435     "UT_NewLL",
       
   436     "CMusAoPlugin",
       
   437     "NewL",
       
   438     "FUNCTIONALITY",
       
   439     SetupL, NewLL, Teardown)
       
   440         
       
   441 EUNIT_TEST(
       
   442     "DefinePropertiesLL",
       
   443     "CMusAoPlugin",
       
   444     "DefinePropertiesL",
       
   445     "FUNCTIONALITY",
       
   446     SetupL, DefinePropertiesLL, Teardown)
       
   447 
       
   448 EUNIT_TEST(
       
   449     "DefinePropertyL (int param)",
       
   450     "CMusAoPlugin",
       
   451     "DefinePropertyL",
       
   452     "FUNCTIONALITY",
       
   453     SetupL, DefinePropertyL_IntPropertyL, Teardown)
       
   454     
       
   455 EUNIT_TEST(
       
   456     "DefinePropertyL (desc param)",
       
   457     "CMusAoPlugin",
       
   458     "DefinePropertyL",
       
   459     "FUNCTIONALITY",
       
   460     SetupL, DefinePropertyL_DesCPropertyL, Teardown)
       
   461     
       
   462 EUNIT_TEST(
       
   463     "DeleteProperties",
       
   464     "CMusAoPlugin",
       
   465     "DeleteProperties",
       
   466     "FUNCTIONALITY",
       
   467     SetupL, DeletePropertiesL, Teardown)
       
   468     
       
   469     
       
   470 
       
   471 EUNIT_TEST(
       
   472     "HandleServerCommandL",
       
   473     "CMusAoPlugin",
       
   474     "HandleServerCommandL",
       
   475     "FUNCTIONALITY",
       
   476     SetupL, UT_HandleServerCommandLL, Teardown)
       
   477 
       
   478 
       
   479 EUNIT_END_TEST_TABLE
       
   480 
       
   481 
       
   482 
       
   483 
       
   484 
       
   485 
       
   486