mmshplugins/mmshsipcrplugin/tsrc/ut_sipcrplugin/src/mussipcrplugintest.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     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 "musunittesting.h"
       
    20 #include "musmanagerstub.h"
       
    21 #include "mussipcrplugin.h"
       
    22 #include "mussipcrplugintest.h"
       
    23 #include "muslogger.h" 
       
    24 #include "musmanager.h"
       
    25 #include "mussettings.h"
       
    26 
       
    27 #include <alwaysonlinemanagercommon.h>
       
    28 #include <alwaysonlinemanagerclient.h>
       
    29 #include <digia/eunit/eunitmacros.h>
       
    30 #include <SipResolvedClient.h>    
       
    31 #include <sipstrings.h>
       
    32 #include <sipstrconsts.h>
       
    33 #include <SdpCodecStringPool.h>
       
    34 #include <sdpdocument.h>
       
    35 
       
    36 // Next row is to disable warning emerging from EUnit code.
       
    37 #pragma warn_illtokenpasting off
       
    38 
       
    39 _LIT8( KSdpSendOnly, "v=0\r\n\
       
    40 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    41 s=-\r\n\
       
    42 c=IN IP4 10.0.0.6\r\n\
       
    43 t=0 0\r\n\
       
    44 m=video 49152 RTP/AVP 98\r\n\
       
    45 a=sendonly\r\n\
       
    46 a=rtpmap:98 H264/90000\r\n" );
       
    47 
       
    48 _LIT8( KSdpSendRecv, "v=0\r\n\
       
    49 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    50 s=-\r\n\
       
    51 c=IN IP4 10.0.0.6\r\n\
       
    52 t=0 0\r\n\
       
    53 m=video 49152 RTP/AVP 98\r\n\
       
    54 a=sendrecv\r\n\
       
    55 a=rtpmap:98 H264/90000\r\n" );
       
    56 
       
    57 _LIT8( KSdpNoMedia, "v=0\r\n\
       
    58 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    59 s=-\r\n\
       
    60 c=IN IP4 10.0.0.6\r\n\
       
    61 t=0 0\r\n" );
       
    62 
       
    63 _LIT8( KSdpNoVideo, "v=0\r\n\
       
    64 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    65 s=-\r\n\
       
    66 c=IN IP4 10.0.0.6\r\n\
       
    67 t=0 0\r\n\
       
    68 m=audio 5000 RTP/AVP 106 8 0\r\n\
       
    69 a=sendrecv\r\n\
       
    70 a=rtpmap:106 AMR/8000\r\n" );
       
    71 
       
    72 _LIT8( KSdpVideoNoAttributes, "v=0\r\n\
       
    73 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    74 s=-\r\n\
       
    75 c=IN IP4 10.0.0.6\r\n\
       
    76 t=0 0\r\n\
       
    77 m=video 49152 RTP/AVP 98\r\n" );
       
    78 
       
    79 _LIT8( KSdpRecvOnly, "v=0\r\n\
       
    80 o=Inviter2008 63241204263093750 132223800 IN IP4 10.0.0.6\r\n\
       
    81 s=-\r\n\
       
    82 c=IN IP4 10.0.0.6\r\n\
       
    83 t=0 0\r\n\
       
    84 m=video 49152 RTP/AVP 98\r\n\
       
    85 a=recvonly\r\n\
       
    86 a=rtpmap:98 H264/90000\r\n" );
       
    87 
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // C++ constructor.
       
    91 // --------------------------------------------------------------------------
       
    92 // 
       
    93 CMusSipCrPluginTest::CMusSipCrPluginTest()
       
    94     : CEUnitTestSuiteClass()
       
    95     {
       
    96     }
       
    97 
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // Symbian two-phase constructor.
       
   101 // --------------------------------------------------------------------------
       
   102 // 
       
   103 CMusSipCrPluginTest* CMusSipCrPluginTest::NewL()
       
   104     {
       
   105     CMusSipCrPluginTest* self = new (ELeave) CMusSipCrPluginTest();
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     CleanupStack::Pop( self );
       
   109     return self;
       
   110     }
       
   111 
       
   112 
       
   113 // --------------------------------------------------------------------------
       
   114 // Symbian second-phase constructor.
       
   115 // --------------------------------------------------------------------------
       
   116 // 
       
   117 void CMusSipCrPluginTest::ConstructL()
       
   118     {
       
   119     CEUnitTestSuiteClass::ConstructL();
       
   120     }
       
   121 
       
   122 
       
   123 // --------------------------------------------------------------------------
       
   124 // C++ destructor.
       
   125 // --------------------------------------------------------------------------
       
   126 // 
       
   127 CMusSipCrPluginTest::~CMusSipCrPluginTest()
       
   128     {
       
   129     }
       
   130 
       
   131 
       
   132 
       
   133 // ------------------------ Test case setup begin ---------------------------
       
   134 
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // 
       
   138 // --------------------------------------------------------------------------
       
   139 //     
       
   140 void CMusSipCrPluginTest::SetupL(  )
       
   141     {
       
   142     iPlugin = CMusSipCrPlugin::NewL();
       
   143     SIPStrings::OpenL();
       
   144     }
       
   145 
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // 
       
   149 // --------------------------------------------------------------------------
       
   150 // 
       
   151 void CMusSipCrPluginTest::Teardown(  )
       
   152     {
       
   153     SIPStrings::Close();
       
   154     delete iPlugin;
       
   155     }
       
   156 
       
   157 
       
   158 
       
   159 // ------------------------- Test functions begin ---------------------------
       
   160 
       
   161 // --------------------------------------------------------------------------
       
   162 // 
       
   163 // --------------------------------------------------------------------------
       
   164 // 
       
   165 void CMusSipCrPluginTest::UT_ConstructL()
       
   166     {
       
   167     // 1. String pool was opend by us
       
   168     EUNIT_ASSERT( iPlugin->iCloseStringPool );
       
   169         
       
   170     // 2. String pool was already opened by someone else, KErrAlreadyExists
       
   171     delete iPlugin;
       
   172     iPlugin = NULL;
       
   173     SdpCodecStringPool::OpenL();
       
   174     TRAPD( err, iPlugin = CMusSipCrPlugin::NewL() );
       
   175     if ( err != KErrNone )
       
   176         {
       
   177         SdpCodecStringPool::Close();
       
   178         User::Leave(err);
       
   179         }
       
   180     EUNIT_ASSERT( !iPlugin->iCloseStringPool );
       
   181     SdpCodecStringPool::Close();    
       
   182     }
       
   183 
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // 
       
   187 // --------------------------------------------------------------------------
       
   188 // 
       
   189 void CMusSipCrPluginTest::UT_ChannelL()
       
   190     {
       
   191     RPointerArray<CSIPHeaderBase> array;
       
   192     
       
   193     TUid response;
       
   194     
       
   195     // Options
       
   196     response = iPlugin->ChannelL( 
       
   197                        SIPStrings::StringF( SipStrConsts::EOptions ),
       
   198                        KNullDesC8(),
       
   199                        array,
       
   200                        KNullDesC8(),
       
   201                        NULL );
       
   202 
       
   203     EUNIT_ASSERT( response.iUid == CMusManager::ESipOptions )
       
   204 
       
   205     // Everything is OK, 2-way video not supported
       
   206     CMusManager::SetAvailability( 
       
   207                  ( MultimediaSharing::TMusAvailabilityStatus ) KErrNone );
       
   208     
       
   209     response = iPlugin->ChannelL( SIPStrings::StringF( SipStrConsts::EMessage ),
       
   210                        KNullDesC8(),
       
   211                        array,
       
   212                        KNullDesC8(),
       
   213                        NULL );
       
   214     
       
   215     EUNIT_ASSERT( response.iUid == CMusManager::ESipInviteDesired )
       
   216     
       
   217     // Server is shut down                     
       
   218     CMusManager::SetAvailability( MultimediaSharing::EErrServerShutDown );
       
   219     
       
   220     response = iPlugin->ChannelL( SIPStrings::StringF( SipStrConsts::EMessage ),
       
   221                        KNullDesC8(),
       
   222                        array,
       
   223                        KNullDesC8(),
       
   224                        NULL );
       
   225 
       
   226     EUNIT_ASSERT( response.iUid == CMusManager::ESipInviteNotDesired )
       
   227 
       
   228     // Mus is not supported
       
   229     CMusManager::SetAvailability(
       
   230             ( MultimediaSharing::TMusAvailabilityStatus ) KErrNotSupported );
       
   231     
       
   232     response = iPlugin->ChannelL( SIPStrings::StringF( SipStrConsts::EMessage ),
       
   233                        KNullDesC8(),
       
   234                        array,
       
   235                        KNullDesC8(),
       
   236                        NULL );
       
   237     
       
   238     EUNIT_ASSERT( response.iUid == CMusManager::ESipInviteNotDesired )
       
   239        
       
   240     // 2-way video is supported and sendrecv not present in SDP    
       
   241     MultimediaSharingSettings::iVideoDirection = MusSettingsKeys::ETwoWayVideo;    
       
   242     CMusManager::SetAvailability( 
       
   243                  ( MultimediaSharing::TMusAvailabilityStatus ) KErrNone );
       
   244 
       
   245     response = iPlugin->ChannelL( SIPStrings::StringF( SipStrConsts::EMessage ),
       
   246                        KNullDesC8(),
       
   247                        array,
       
   248                        KSdpSendOnly(),
       
   249                        NULL );
       
   250 
       
   251     EUNIT_ASSERT( response.iUid == CMusManager::ESipInviteDesired )
       
   252     
       
   253     // 2-way video is supported and sendrecv is present in SDP    
       
   254     response = iPlugin->ChannelL( SIPStrings::StringF( SipStrConsts::EMessage ),
       
   255                        KNullDesC8(),
       
   256                        array,
       
   257                        KSdpSendRecv(),
       
   258                        NULL );
       
   259         
       
   260     EUNIT_ASSERT( response.iUid == CMusManager::ESipInviteDesired2WayVideo )
       
   261     }
       
   262 
       
   263 
       
   264 // --------------------------------------------------------------------------
       
   265 // 
       
   266 // --------------------------------------------------------------------------
       
   267 // 
       
   268 void CMusSipCrPluginTest::UT_ConnectL()
       
   269     {
       
   270     // Options
       
   271     TUid uid;
       
   272     uid.iUid = CMusManager::ESipOptions;
       
   273     iPlugin->ConnectL( uid );
       
   274     EUNIT_ASSERT_EQUALS( iPlugin->iManager->iHandleSipRequestLCalledWithParam,
       
   275                          CMusManager::ESipOptions )
       
   276     
       
   277     // Desired invite
       
   278     uid.iUid = CMusManager::ESipInviteDesired;
       
   279     iPlugin->ConnectL( uid );
       
   280     EUNIT_ASSERT_EQUALS( iPlugin->iManager->iHandleSipRequestLCalledWithParam,
       
   281                          CMusManager::ESipInviteDesired )
       
   282     
       
   283     // Not desired invite
       
   284     uid.iUid = CMusManager::ESipInviteNotDesired;
       
   285     iPlugin->ConnectL( uid );
       
   286     EUNIT_ASSERT_EQUALS( iPlugin->iManager->iHandleSipRequestLCalledWithParam,
       
   287                          CMusManager::ESipInviteNotDesired )
       
   288       
       
   289     // Unknown case, manager is not called and value does not change    
       
   290     uid.iUid = KErrNone;
       
   291     EUNIT_ASSERT_SPECIFIC_LEAVE( iPlugin->ConnectL( uid ), KErrNotSupported )
       
   292     EUNIT_ASSERT_EQUALS( iPlugin->iManager->iHandleSipRequestLCalledWithParam,
       
   293                          CMusManager::ESipInviteNotDesired )
       
   294     }
       
   295 
       
   296 
       
   297 // --------------------------------------------------------------------------
       
   298 // 
       
   299 // --------------------------------------------------------------------------
       
   300 // 
       
   301 void CMusSipCrPluginTest::UT_Capabilities()
       
   302     {
       
   303     // Dummy test is enough
       
   304     iPlugin->Capabilities();
       
   305     }
       
   306 
       
   307 
       
   308 // --------------------------------------------------------------------------
       
   309 // 
       
   310 // --------------------------------------------------------------------------
       
   311 // 
       
   312 void CMusSipCrPluginTest::UT_ImplementationGroupProxy()
       
   313     {
       
   314     // Dummy test
       
   315     TInt tableCount;
       
   316     
       
   317     ImplementationGroupProxy( tableCount );
       
   318     }
       
   319 
       
   320 
       
   321 // --------------------------------------------------------------------------
       
   322 // 
       
   323 // --------------------------------------------------------------------------
       
   324 // 
       
   325 void CMusSipCrPluginTest::UT_CheckForSendRecvAttributeL()
       
   326     {
       
   327     CSdpDocument* sdpDocument;
       
   328     TBool sendRecv;
       
   329     
       
   330     // 1. SDP doesn't have a single media field
       
   331     sdpDocument = CSdpDocument::DecodeLC( KSdpNoMedia() );
       
   332     sendRecv = iPlugin->CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
       
   333     CleanupStack::PopAndDestroy( sdpDocument );
       
   334     EUNIT_ASSERT( !sendRecv );
       
   335     
       
   336     // 2. SDP has audio field, but no video
       
   337     sdpDocument = CSdpDocument::DecodeLC( KSdpNoVideo() );
       
   338     sendRecv = iPlugin->CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
       
   339     CleanupStack::PopAndDestroy( sdpDocument );
       
   340     EUNIT_ASSERT( !sendRecv );
       
   341     
       
   342     // 3. SDP has video field without any attributes
       
   343     sdpDocument = CSdpDocument::DecodeLC( KSdpVideoNoAttributes() );
       
   344     sendRecv = iPlugin->CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
       
   345     CleanupStack::PopAndDestroy( sdpDocument );
       
   346     EUNIT_ASSERT( sendRecv );
       
   347         
       
   348     // 4. SDP has video with "sendrecv" attribute
       
   349     sdpDocument = CSdpDocument::DecodeLC( KSdpSendRecv() );
       
   350     sendRecv = iPlugin->CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
       
   351     CleanupStack::PopAndDestroy( sdpDocument );
       
   352     EUNIT_ASSERT( sendRecv );    
       
   353     
       
   354     // 5. SDP has video with "recvonly" attribute
       
   355     sdpDocument = CSdpDocument::DecodeLC( KSdpRecvOnly() );
       
   356     sendRecv = iPlugin->CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
       
   357     CleanupStack::PopAndDestroy( sdpDocument );
       
   358     EUNIT_ASSERT( !sendRecv );
       
   359     }
       
   360 
       
   361 
       
   362 //  TEST TABLE
       
   363 
       
   364 EUNIT_BEGIN_TEST_TABLE(
       
   365     CMusSipCrPluginTest,
       
   366     "CMusSipCrPluginTest",
       
   367     "CMusSipCrPluginTest" )
       
   368    
       
   369 EUNIT_TEST(
       
   370     "ConstructL - test",
       
   371     "CMusSipCrPluginTest",
       
   372     "UT_ConstructL",
       
   373     "FUNCTIONALITY",
       
   374     SetupL, UT_ConstructL, Teardown)
       
   375 
       
   376 EUNIT_TEST(
       
   377     "CMusSipCrPluginTest",
       
   378     "CMusSipCrPluginTest",
       
   379     "ConnectL",
       
   380     "FUNCTIONALITY",
       
   381     SetupL, UT_ConnectL, Teardown)
       
   382 
       
   383 EUNIT_TEST(
       
   384     "CMusSipCrPluginTest",
       
   385     "CMusSipCrPluginTest",
       
   386     "ChannelL",
       
   387     "FUNCTIONALITY",
       
   388     SetupL, UT_ChannelL, Teardown)
       
   389 
       
   390 EUNIT_TEST(
       
   391     "CMusSipCrPluginTest",
       
   392     "CMusSipCrPluginTest",
       
   393     "Capabilities",
       
   394     "FUNCTIONALITY",
       
   395     SetupL, UT_Capabilities, Teardown)
       
   396 
       
   397 EUNIT_TEST(
       
   398     "CMusSipCrPluginTest",
       
   399     "CMusSipCrPluginTest",
       
   400     "ImplementationGroupProxyTest",
       
   401     "FUNCTIONALITY",
       
   402     SetupL, UT_ImplementationGroupProxy, Teardown)
       
   403     
       
   404 EUNIT_TEST(
       
   405     "CheckForSendRecvAttribute - stest",
       
   406     "CMusSipCrPluginTest",
       
   407     "UT_CheckForSendRecvAttribute",
       
   408     "FUNCTIONALITY",
       
   409     SetupL, UT_CheckForSendRecvAttributeL, Teardown)
       
   410     
       
   411 EUNIT_END_TEST_TABLE
       
   412