ximpfw/tsrc/tsrcutils/testcaseutils/prfwtesteventfactory.cpp
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     1 /*
       
     2 * Copyright (c) 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:  XIMP Framework XIMPTestEventFactory
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "prfwtestcaseutilspanics.h"
       
    20 #include "prfwtesteventfactory.h"
       
    21 
       
    22 #include <eunitmacros.h>
       
    23 #include <ximpcontextstateevent.h>
       
    24 #include <ximprequestcompleteevent.h>
       
    25 #include <ximpstatus.h>
       
    26 #include <presentitypresenceevent.h>
       
    27 #include <presentitygrouplistevent.h>
       
    28 #include <presentitygroupcontentevent.h>
       
    29 #include <presenceinfo.h>
       
    30 
       
    31 #include "ximpidentityimp.h"
       
    32 #include "presencetypehelpers.h"
       
    33 #include "presentitygroupinfoimp.h"
       
    34 #include "presentitygroupmemberinfoimp.h"
       
    35 #include "presentitygroupcontenteventimp.h"
       
    36 #include "presentitygrouplisteventimp.h"
       
    37 
       
    38 
       
    39 
       
    40 using namespace NXIMPTestCaseUtilsPanic;
       
    41 
       
    42 
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // create a group content event with given arrays
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CPresentityGroupContentEventImp*
       
    51 XIMPTestEventFactory::CreateGroupContentEventLCX(
       
    52         const TDesC& aGroupId,
       
    53         const TDesC& aIdentityForDelta,
       
    54         const TDesC& aDispNameForDelta,
       
    55         TTestPGLContentArraySpecifier aArraySpec,
       
    56         const TDesC& aIdentityCurrent,
       
    57         const TDesC& aDispNameCurrent,
       
    58         MXIMPDataSubscriptionState::TSubscriptionState aSubscriptionState,
       
    59         MXIMPDataSubscriptionState::TDataState aDataState
       
    60         )
       
    61     {
       
    62     // id for group
       
    63     CXIMPIdentityImp* idForGroup = CXIMPIdentityImp::NewLC( aGroupId );
       
    64 
       
    65     // create the arrays
       
    66     RPrGrpMemInfoImpArray* addedList = new ( ELeave ) RPrGrpMemInfoImpArray;
       
    67     CleanupDeletePushL( addedList );
       
    68 
       
    69     RPrGrpMemInfoImpArray* updatedList = new ( ELeave ) RPrGrpMemInfoImpArray;
       
    70     CleanupDeletePushL( updatedList );
       
    71 
       
    72     RPrGrpMemInfoImpArray* removedList = new ( ELeave ) RPrGrpMemInfoImpArray;
       
    73     CleanupDeletePushL( removedList );
       
    74 
       
    75     RPrGrpMemInfoImpArray* currentList = new ( ELeave ) RPrGrpMemInfoImpArray;
       
    76     CleanupDeletePushL( currentList );
       
    77 
       
    78     // populate the current list
       
    79     if ( aIdentityCurrent.Length() > 0 )
       
    80         {
       
    81         // but don't put "KNullDesC" there if it's really empty
       
    82         CXIMPIdentityImp* idForCurrent = CXIMPIdentityImp::NewLC( aIdentityCurrent );
       
    83         CPresentityGroupMemberInfoImp* grpInfoForCurrent =
       
    84             CPresentityGroupMemberInfoImp::NewLC( *idForCurrent, aDispNameCurrent );
       
    85         currentList->AppendL( grpInfoForCurrent );
       
    86         CleanupStack::Pop( grpInfoForCurrent );
       
    87         CleanupStack::PopAndDestroy( idForCurrent );
       
    88         }
       
    89 
       
    90     // create the delta list
       
    91     CXIMPIdentityImp* idForEvent = CXIMPIdentityImp::NewLC( aIdentityForDelta );
       
    92     CPresentityGroupMemberInfoImp* grpInfoForEvent =
       
    93         CPresentityGroupMemberInfoImp::NewLC( *idForEvent, aDispNameForDelta );
       
    94 
       
    95     // notice the cleanup stack usage. AppendL takes ownership, but
       
    96     // it might not be done always.
       
    97     TBool didAppend = EFalse;
       
    98 
       
    99     // put the given group info into the specified array.
       
   100     switch ( aArraySpec )
       
   101         {
       
   102         case ETestPGLCntAdded :
       
   103             {
       
   104             if ( aIdentityForDelta.Length() > 0 )
       
   105                 {
       
   106                 addedList->AppendL( grpInfoForEvent );
       
   107                 didAppend = ETrue;
       
   108                 }
       
   109             break;
       
   110             }
       
   111 
       
   112         case ETestPGLCntUpdated :
       
   113             {
       
   114             if ( aIdentityForDelta.Length() > 0 )
       
   115                 {
       
   116                 updatedList->AppendL( grpInfoForEvent );
       
   117                 didAppend = ETrue;
       
   118                 }
       
   119             break;
       
   120             }
       
   121 
       
   122         case ETestPGLCntRemoved :
       
   123             {
       
   124             if ( aIdentityForDelta.Length() > 0 )
       
   125                 {
       
   126                 removedList->AppendL( grpInfoForEvent );
       
   127                 didAppend = ETrue;
       
   128                 }
       
   129             break;
       
   130             }
       
   131 
       
   132         case ETestPGLCntEmpty :
       
   133             {
       
   134             // don't add, thus creating an empty array.
       
   135             break;
       
   136             }
       
   137 
       
   138         default:
       
   139             {
       
   140             User::Leave( KErrArgument );
       
   141             break;
       
   142             }
       
   143         };
       
   144 
       
   145     // remove the event and id from cleanupstack. removal
       
   146     // method depends on whether we did append or not
       
   147     if ( didAppend )
       
   148         {
       
   149         CleanupStack::Pop( grpInfoForEvent );
       
   150         CleanupStack::PopAndDestroy( idForEvent );
       
   151         }
       
   152     else
       
   153         {
       
   154         CleanupStack::PopAndDestroy( 2, idForEvent );
       
   155         }
       
   156 
       
   157     CXIMPDataSubscriptionStateImp* stateImp = CXIMPDataSubscriptionStateImp::NewLC();
       
   158     stateImp->SetSubscriptionStateL( aSubscriptionState );
       
   159     stateImp->SetDataStateL( aDataState );
       
   160         
       
   161     // create the actual event
       
   162     CPresentityGroupContentEventImp* tmp =
       
   163         CPresentityGroupContentEventImp::NewLC(
       
   164                 *idForGroup,
       
   165                 addedList,
       
   166                 updatedList,
       
   167                 removedList,
       
   168                 currentList,
       
   169                 stateImp
       
   170                 );
       
   171     CleanupStack::Pop( 2, stateImp );
       
   172     CleanupStack::PushL( tmp );
       
   173 
       
   174     // test the accessors
       
   175     if ( aIdentityForDelta.Length() > 0 )
       
   176         {
       
   177         switch ( aArraySpec )
       
   178             {
       
   179             case ETestPGLCntAdded :
       
   180                 {
       
   181                 EUNIT_ASSERT_DESC( tmp->NewMembersCount() == 1, "Added group member count mismatch" );
       
   182                 TBool same = 0 == tmp->NewMember( 0 ).GroupMemberId().Identity().Compare( aIdentityForDelta );
       
   183                 EUNIT_ASSERT_DESC( same, "Added group member id mismatch" );
       
   184                 break;
       
   185                 }
       
   186 
       
   187             case ETestPGLCntUpdated :
       
   188                 {
       
   189                 EUNIT_ASSERT_DESC( tmp->UpdatedMembersCount() == 1, "Updated group member count mismatch" );
       
   190                 TBool same = 0 == tmp->UpdatedMember( 0 ).GroupMemberId().Identity().Compare( aIdentityForDelta );
       
   191                 EUNIT_ASSERT_DESC( same, "Updated group member id mismatch" );
       
   192                 break;
       
   193                 }
       
   194 
       
   195             case ETestPGLCntRemoved :
       
   196                 {
       
   197                 EUNIT_ASSERT_DESC( tmp->DisappearedMembersCount() == 1, "Removed group member count mismatch" );
       
   198                 TBool same = 0 == tmp->DisappearedMember( 0 ).GroupMemberId().Identity().Compare( aIdentityForDelta );
       
   199                 EUNIT_ASSERT_DESC( same, "Removed group member id mismatch" );
       
   200                 break;
       
   201                 }
       
   202 
       
   203             case ETestPGLCntEmpty :
       
   204                 {
       
   205                 // don't add, thus creating an empty array.
       
   206                 break;
       
   207                 }
       
   208 
       
   209             default :
       
   210                 {
       
   211                 break;
       
   212                 }
       
   213             }
       
   214         }
       
   215 
       
   216     if ( aIdentityCurrent.Length() > 0 )
       
   217         {
       
   218         EUNIT_ASSERT_DESC( tmp->CurrentMembersCount() == 1, "Current group member count mismatch" );
       
   219         
       
   220         TBool same = 0 == tmp->CurrentMember( 0 ).GroupMemberId().Identity().Compare( aIdentityCurrent );
       
   221         EUNIT_ASSERT_DESC( same, "Current group member id mismatch" );
       
   222         
       
   223         same = 0 == tmp->CurrentMember( 0 ).GroupMemberDisplayName().Compare( aDispNameCurrent );
       
   224         EUNIT_ASSERT_DESC( same, "Current group member display name mismatch" );
       
   225         }
       
   226     else
       
   227         {
       
   228         EUNIT_ASSERT_DESC( tmp->CurrentMembersCount() == 0, "Current group member count mismatch" );
       
   229         }
       
   230 
       
   231     /*
       
   232      * In cleanupstack there are 6 items, FIFO:
       
   233      *   - identity object
       
   234      *   - added list
       
   235      *   - updated list
       
   236      *   - removed list
       
   237      *   - current member list
       
   238      *   - event imp
       
   239      */
       
   240 
       
   241     return tmp;
       
   242     }
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // create a group list event with given arrays
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C CPresentityGroupListEventImp* XIMPTestEventFactory::CreateGroupListEventLCX(
       
   250         const TDesC& aUri,
       
   251         const TDesC& aDispName,
       
   252         TTestPGLArraySpecifier aArraySpec,
       
   253         const TDesC& aUriCurrent,
       
   254         const TDesC& aDispNameCurrent,
       
   255         MXIMPDataSubscriptionState::TSubscriptionState aSubscriptionState,
       
   256         MXIMPDataSubscriptionState::TDataState aDataState
       
   257         )
       
   258     {
       
   259     // create the arrays
       
   260     RPrGrpInfoImpArray* createdList = new ( ELeave ) RPrGrpInfoImpArray;
       
   261     CleanupDeletePushL( createdList );
       
   262 
       
   263     RPrGrpInfoImpArray* updatedList = new ( ELeave ) RPrGrpInfoImpArray;
       
   264     CleanupDeletePushL( updatedList );
       
   265 
       
   266     RPrGrpInfoImpArray* deletedList = new ( ELeave ) RPrGrpInfoImpArray;
       
   267     CleanupDeletePushL( deletedList );
       
   268     
       
   269     RPrGrpInfoImpArray* currentList = new ( ELeave ) RPrGrpInfoImpArray;
       
   270     CleanupDeletePushL( currentList );
       
   271 
       
   272     // create the group info
       
   273     CXIMPIdentityImp* idForEvent = CXIMPIdentityImp::NewLC( aUri );
       
   274     CPresentityGroupInfoImp* grpInfoForEvent =
       
   275         CPresentityGroupInfoImp::NewLC( *idForEvent, aDispName );
       
   276 
       
   277     // populate the current list
       
   278     if ( aUriCurrent.Length() > 0 )
       
   279         {
       
   280         // but don't put "KNullDesC" there if it's really empty
       
   281         CXIMPIdentityImp* idForCurrent = CXIMPIdentityImp::NewLC( aUriCurrent );
       
   282         CPresentityGroupInfoImp* grpInfoForCurrent =
       
   283             CPresentityGroupInfoImp::NewLC( *idForCurrent, aDispNameCurrent );
       
   284         currentList->AppendL( grpInfoForCurrent );
       
   285         CleanupStack::Pop( grpInfoForCurrent );
       
   286         CleanupStack::PopAndDestroy( idForCurrent );
       
   287         }
       
   288     
       
   289     // notice the cleanup stack usage. AppendL takes ownership, but
       
   290     // it might not be done always.
       
   291     TBool didAppend = EFalse;
       
   292 
       
   293     // put the given group info into the specified array
       
   294     switch ( aArraySpec )
       
   295         {
       
   296         case ETestPGLCreated :
       
   297             {
       
   298             if ( aUri.Length() > 0 )
       
   299                 {
       
   300                 createdList->AppendL( grpInfoForEvent );
       
   301                 didAppend = ETrue;
       
   302                 }
       
   303             break;
       
   304             }
       
   305 
       
   306         case ETestPGLUpdated :
       
   307             {
       
   308             if ( aUri.Length() > 0 )
       
   309                 {
       
   310                 updatedList->AppendL( grpInfoForEvent );
       
   311                 didAppend = ETrue;
       
   312                 }
       
   313             break;
       
   314             }
       
   315 
       
   316         case ETestPGLDeleted :
       
   317             {
       
   318             if ( aUri.Length() > 0 )
       
   319                 {
       
   320                 deletedList->AppendL( grpInfoForEvent );
       
   321                 didAppend = ETrue;
       
   322                 }
       
   323             break;
       
   324             }
       
   325 
       
   326         case ETestPGLEmpty :
       
   327             {
       
   328             // don't add, thus creating an empty array
       
   329             break;
       
   330             }
       
   331 
       
   332         default:
       
   333             {
       
   334             User::Leave( KErrArgument );
       
   335             break;
       
   336             }
       
   337         };
       
   338 
       
   339     // remove the event and id from cleanupstack. removal
       
   340     // method depends on whether we did append or not
       
   341     if ( didAppend )
       
   342         {
       
   343         CleanupStack::Pop( grpInfoForEvent );
       
   344         CleanupStack::PopAndDestroy( idForEvent );
       
   345         }
       
   346     else
       
   347         {
       
   348         CleanupStack::PopAndDestroy( 2, idForEvent );
       
   349         }
       
   350 
       
   351     CXIMPDataSubscriptionStateImp* stateImp = CXIMPDataSubscriptionStateImp::NewLC();
       
   352     stateImp->SetSubscriptionStateL( aSubscriptionState );
       
   353     stateImp->SetDataStateL( aDataState );
       
   354         
       
   355     // create the actual event
       
   356     CPresentityGroupListEventImp* tmp =
       
   357         CPresentityGroupListEventImp::NewLC(
       
   358                 createdList,
       
   359                 updatedList,
       
   360                 deletedList,
       
   361                 currentList,
       
   362                 stateImp
       
   363                 );                
       
   364     CleanupStack::Pop( 2, stateImp );
       
   365     CleanupStack::PushL( tmp );
       
   366 
       
   367     // verify that the event contains correct information
       
   368     if ( aUri.Length() > 0 )
       
   369         {
       
   370         switch ( aArraySpec )
       
   371             {
       
   372             case ETestPGLCreated :
       
   373                 {
       
   374                 EUNIT_ASSERT_DESC( tmp->NewGroupsCount() == 1, "Created group count mismatch" );
       
   375                 TBool same = 0 == tmp->NewGroup( 0 ).GroupId().Identity().Compare( aUri );
       
   376                 EUNIT_ASSERT_DESC( same, "Created group id mismatch" );
       
   377                 break;
       
   378                 }
       
   379 
       
   380             case ETestPGLUpdated :
       
   381                 {
       
   382                 EUNIT_ASSERT_DESC( tmp->UpdatedGroupsCount() == 1, "Updated group count mismatch" );
       
   383                 TBool same = 0 == tmp->UpdatedGroup( 0 ).GroupId().Identity().Compare( aUri );
       
   384                 EUNIT_ASSERT_DESC( same, "Updated group id mismatch" );
       
   385                 break;
       
   386                 }
       
   387 
       
   388             case ETestPGLDeleted :
       
   389                 {
       
   390                 EUNIT_ASSERT_DESC( tmp->DisappearedGroupsCount() == 1, "Deleted group count mismatch" );
       
   391                 TBool same = 0 == tmp->DisappearedGroup( 0 ).GroupId().Identity().Compare( aUri );
       
   392                 EUNIT_ASSERT_DESC( same, "Deleted group id mismatch" );
       
   393                 break;
       
   394                 }
       
   395             }
       
   396         }
       
   397     
       
   398     if ( aUriCurrent.Length() > 0 )
       
   399         {
       
   400         EUNIT_ASSERT_DESC( tmp->CurrentGroupsCount() == 1, "Current group count mismatch" );
       
   401    
       
   402         TBool same = 0 == tmp->CurrentGroup( 0 ).GroupId().Identity().Compare( aUriCurrent );
       
   403         EUNIT_ASSERT_DESC( same, "Current group id mismatch" );
       
   404         
       
   405         same = 0 == tmp->CurrentGroup( 0 ).GroupDisplayName().Compare( aDispNameCurrent );
       
   406         EUNIT_ASSERT_DESC( same, "Current group display name mismatch" );
       
   407         }
       
   408     else
       
   409         {
       
   410         EUNIT_ASSERT_DESC( tmp->CurrentGroupsCount() == 0, "Current group count mismatch, expected 0" );
       
   411         }
       
   412 
       
   413     /*
       
   414      * In cleanupstack there are 5 items, FIFO:
       
   415      *   - created list
       
   416      *   - updated list
       
   417      *   - deleted list
       
   418      *   - current list
       
   419      *   - event imp
       
   420      */
       
   421 
       
   422     return tmp;
       
   423     }
       
   424 
       
   425 // end of file
       
   426