mmsharing/mmshmanagersrv/tsrc/ut_managersrv/src/UT_CMusManagerServerSession.cpp
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2004-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 CMusAvailabilityPluginManager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "UT_CMusManagerServerSession.h"
       
    20 #include "musunittesting.h"
       
    21 #include "musmanagerserversession.h"
       
    22 #include "musmanagerserver.h"
       
    23 #include "musmanageripccommon.h"
       
    24 
       
    25 /*
       
    26 #include "musavaavailability.h"
       
    27 #include "musavaavailabilitystub.h"
       
    28 #include "musavainterface.h"
       
    29 #include "cmusavainterfacestub.h"
       
    30 #include "mussessionproperties.h"
       
    31 */
       
    32 
       
    33 #include "mustesthelp.h"
       
    34 #include <e32property.h>
       
    35 #include <apgtask.h>
       
    36 #include <digia/eunit/eunitmacros.h>
       
    37 
       
    38 
       
    39 void CActiveScheduler::Install(CActiveScheduler* /*aScheduler*/)
       
    40     {
       
    41     }
       
    42 
       
    43 void RMessagePtr2::Complete(TInt /*aReason*/) const
       
    44     {
       
    45     }
       
    46 
       
    47 void RMessagePtr2::ReadL(TInt /*aParam*/,TDes8& aDes,TInt /*aOffset*/) const
       
    48     {
       
    49     TUint32 val = 0;
       
    50     TPckgBuf<TUint32> valPckg( val );
       
    51     aDes.Copy( valPckg );
       
    52     }
       
    53 
       
    54 
       
    55 void RMessagePtr2::WriteL(TInt /*aParam*/,const TDesC8& /*aDes*/,TInt /*aOffset*/) const
       
    56     {
       
    57     
       
    58     }
       
    59 
       
    60 TInt RMessagePtr2::GetDesMaxLength(TInt /*aParam*/) const
       
    61     {
       
    62     return 256;
       
    63     }
       
    64 
       
    65 class RMessage2Test : public RMessage2
       
    66     {
       
    67     public:
       
    68     inline RMessage2Test( TInt aFunction );
       
    69     inline void SetHandle( TInt aHandle );
       
    70     };
       
    71 
       
    72 
       
    73 inline RMessage2Test::RMessage2Test( TInt aFunction )
       
    74     : RMessage2()
       
    75     {
       
    76     iFunction = aFunction;
       
    77     }
       
    78 
       
    79 
       
    80 inline void RMessage2Test::SetHandle( TInt aHandle )
       
    81     {
       
    82     iHandle = aHandle;
       
    83     }
       
    84 
       
    85 TInt RMessagePtr2::Client(RThread& /*aClient*/, TOwnerType /*aOwnerType*/) const
       
    86     {
       
    87     return KErrNone;
       
    88     }
       
    89 
       
    90 void RThread::RequestComplete(TRequestStatus*& /*aStatus*/,TInt /*aReason*/) const
       
    91     {
       
    92     }
       
    93 
       
    94 void CServer2::ReStart()
       
    95     {
       
    96     }
       
    97     
       
    98 // ======== MEMBER FUNCTIONS ========
       
    99 
       
   100 
       
   101 UT_CMusManagerServerSession* UT_CMusManagerServerSession::NewL()
       
   102     {
       
   103     UT_CMusManagerServerSession* self = UT_CMusManagerServerSession::NewLC();
       
   104     CleanupStack::Pop();
       
   105     return self;
       
   106     }
       
   107 
       
   108 
       
   109 UT_CMusManagerServerSession* UT_CMusManagerServerSession::NewLC()
       
   110     {
       
   111     UT_CMusManagerServerSession* self = new( ELeave ) UT_CMusManagerServerSession();
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     return self;
       
   115     }
       
   116 
       
   117 
       
   118 UT_CMusManagerServerSession::~UT_CMusManagerServerSession()
       
   119     {
       
   120     }
       
   121 
       
   122 
       
   123 UT_CMusManagerServerSession::UT_CMusManagerServerSession()
       
   124     {
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   130 // It generates the test case table.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void UT_CMusManagerServerSession::ConstructL()
       
   134     {
       
   135     CEUnitTestSuiteClass::ConstructL();
       
   136     }
       
   137 
       
   138 
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // Setups the test by instantiating tested class.
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void UT_CMusManagerServerSession::SetupL()
       
   146     {
       
   147     iServer = CMusManagerServer::NewL();
       
   148     iSession = CMusManagerServerSession::NewL(*iServer, *this );
       
   149     
       
   150     TVersion version;
       
   151     RMessage2 message;    
       
   152     iSession2 = iServer->NewSessionL( version, message );
       
   153     iObserved = (TObserved)0;
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Finalizes test by deleting instance of tested class.
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void UT_CMusManagerServerSession::Teardown()
       
   162     {
       
   163     delete iSession;
       
   164     delete iSession2;
       
   165     iServer->RunError( KErrNone );
       
   166     delete iServer;
       
   167     PropertyHelper::Close(); 
       
   168     
       
   169     }
       
   170 
       
   171 
       
   172 // ======== TEST METHODS ========
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Asserts that instance creation is successful.
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void UT_CMusManagerServerSession::UT_CMusManagerServerSession_NewLL()
       
   180     {
       
   181     EUNIT_ASSERT( iSession );
       
   182     }
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // Asserts that instance creation is successful.
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void UT_CMusManagerServerSession::UT_CMusManagerServerSession_NewLCL()
       
   190     {
       
   191     delete iSession;
       
   192     iSession = NULL;
       
   193     iSession = CMusManagerServerSession::NewLC( *iServer, *this );
       
   194     EUNIT_ASSERT( iSession );
       
   195     CleanupStack::Pop( iSession );
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // 
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void UT_CMusManagerServerSession::
       
   205     UT_CMusManagerServerSession_ServiceLL()
       
   206     {
       
   207     RMessage2Test msg1( EMusManagerIpcAvailabilityQuery );
       
   208     RMessage2Test msg2( EMusManagerIpcInvestigateAvailability );
       
   209     RMessage2Test msg3( EMusManagerIpcInvitationReceived );
       
   210     RMessage2Test msg4( EMusManagerIpcOptionsReceived );
       
   211     RMessage2Test msg5( EMusManagerIpcStartMultimediaSharing );
       
   212     RMessage2Test msg6( EMusManagerIpcStopMultimediaSharing );
       
   213     RMessage2Test msg6_1( EMusManagerIpcStartObservingAvailability );
       
   214     RMessage2Test msg7( EMusManagerIpcMonitorAvailability );
       
   215     RMessage2Test msg8( EMusManagerIpcCancelMonitoring );
       
   216     RMessage2Test msg9( EMusManagerIpcHandleCommand );
       
   217     
       
   218     
       
   219     iSession->ServiceL( msg7 );
       
   220     EUNIT_ASSERT( iObserved == (TObserved)0 );
       
   221     iObserved = (TObserved)0;
       
   222     iSession->ServiceL( msg1 );
       
   223     EUNIT_ASSERT( iObserved == EAvailabilityQueryL );
       
   224     iObserved = (TObserved)0;
       
   225     iSession->ServiceL( msg2 );
       
   226     EUNIT_ASSERT( iObserved == EInvestigateAvailabilityL );
       
   227     iObserved = (TObserved)0;
       
   228     iSession->ServiceL( msg3 );
       
   229     EUNIT_ASSERT( iObserved == EInvitationReceivedL );
       
   230     iObserved = (TObserved)0;
       
   231     iSession->ServiceL( msg4 );
       
   232     EUNIT_ASSERT( iObserved == EOptionsReceivedL );
       
   233     iObserved = (TObserved)0;
       
   234     iSession->ServiceL( msg5 );
       
   235     EUNIT_ASSERT( iObserved == EStartMultimediaSharingL );
       
   236     iObserved = (TObserved)0;
       
   237     iSession->ServiceL( msg6 );
       
   238     EUNIT_ASSERT( iObserved == EStopMultimediaSharingL );
       
   239     iObserved = (TObserved)0;
       
   240     iSession->ServiceL( msg6_1 );
       
   241     EUNIT_ASSERT( iObserved == ERegisterObserverL );
       
   242     iObserved = (TObserved)0;
       
   243     iSession->ServiceL( msg8 );
       
   244     EUNIT_ASSERT( iObserved == ECancelMonitoring );
       
   245     iObserved = (TObserved)0;
       
   246     iSession->ServiceL( msg9 );
       
   247     EUNIT_ASSERT( iObserved == ECommandL );
       
   248     iObserved = (TObserved)0;
       
   249     }
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // 
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 void UT_CMusManagerServerSession::
       
   257     UT_CMusManagerServerSession_AvailabilityChangedLL()
       
   258     {
       
   259     
       
   260     iSession->AvailabilityChangedL(
       
   261         (MultimediaSharing::TMusAvailabilityStatus) KErrNone );
       
   262 
       
   263     RMessage2Test msg7( EMusManagerIpcMonitorAvailability );
       
   264     iSession->ServiceL( msg7 );
       
   265     
       
   266     iSession->AvailabilityChangedL(
       
   267         (MultimediaSharing::TMusAvailabilityStatus) KErrNone );
       
   268     
       
   269     iSession->AvailabilityChangedL(
       
   270         (MultimediaSharing::TMusAvailabilityStatus) KErrNone );
       
   271     
       
   272     msg7.SetHandle( 1 );
       
   273     iSession->ServiceL( msg7 );
       
   274     
       
   275     iSession->AvailabilityChangedL(
       
   276         (MultimediaSharing::TMusAvailabilityStatus) KErrNone );
       
   277 
       
   278     iSession->ServiceL( msg7 );
       
   279 
       
   280     iSession->AvailabilityChangedL(
       
   281         (MultimediaSharing::TMusAvailabilityStatus) KErrNone );
       
   282 
       
   283     }
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 // ======== EUNIT TEST TABLE ========
       
   289 
       
   290 
       
   291 EUNIT_BEGIN_TEST_TABLE(
       
   292     UT_CMusManagerServerSession,
       
   293     "CMusManagerServerSession",
       
   294     "UNIT" )
       
   295 
       
   296 EUNIT_TEST(
       
   297     "NewL - test ",
       
   298     "CMusManagerServerSession",
       
   299     "NewL",
       
   300     "FUNCTIONALITY",
       
   301     SetupL, UT_CMusManagerServerSession_NewLL, Teardown)
       
   302 
       
   303 EUNIT_TEST(
       
   304     "NewLC - test ",
       
   305     "CMusManagerServerSession",
       
   306     "NewLC",
       
   307     "FUNCTIONALITY",
       
   308     SetupL, UT_CMusManagerServerSession_NewLCL, Teardown)
       
   309 
       
   310 EUNIT_TEST(
       
   311     "ServiceL - test ",
       
   312     "CMusManagerServerSession",
       
   313     "ServiceL",
       
   314     "FUNCTIONALITY",
       
   315     SetupL, UT_CMusManagerServerSession_ServiceLL, Teardown)
       
   316 
       
   317 EUNIT_TEST(
       
   318     "AvailabilityChangedL - test ",
       
   319     "CMusManagerServerSession",
       
   320     "AvailabilityChangedL",
       
   321     "FUNCTIONALITY",
       
   322     SetupL, UT_CMusManagerServerSession_AvailabilityChangedLL, Teardown)
       
   323 
       
   324 
       
   325 
       
   326 EUNIT_END_TEST_TABLE