mediator/tsrc/public/basic/src/MediatorTestCases.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32math.h>
       
    22 #include <mediatorpluginbase.h>
       
    23 #include "MediatorTest.h"
       
    24 #include "mediatortestdata.h"
       
    25 
       
    26 using namespace MediatorService;
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 //extern  ?external_data;
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES  
       
    32 //extern ?external_function( ?arg_type,?arg_type );
       
    33 
       
    34 // CONSTANTS
       
    35 //const ?type ?constant_var = ?constant;
       
    36 const TInt KTestUid = 0x101FB3E7;
       
    37 const TInt KTestEventId = 1000;
       
    38 const TInt KNonExistingDomainId = 999;
       
    39 const TInt KReallyNonExistingDomainId = 1234567;
       
    40 const TInt KNonExistingCategoryId = 99;
       
    41 const TInt KNonExistingEventId = 99999;
       
    42 const TInt KExistingEventId = 50;
       
    43 const TInt KOtherUid = 0x00000124;           // static domain defined in StaticEvents.rss
       
    44 const TInt KOtherSIDCategory = 0x00006767;   // static category defined in StaticEvents.rss
       
    45 const TInt KOtherSIDEventId = 12;            // static event defined in StaticEvents.rss
       
    46 const TInt KNonExistingEventCapaId = 5;
       
    47 const TInt KMinListId = 1;
       
    48 const TInt KMaxListId = 99;
       
    49 //const TInt KNonExistingCapsEventId = 889;
       
    50 const TInt KDefaultCommandId = 1000;
       
    51 const TInt KDefaultTimeOut = 3000; // 3 seconds
       
    52 const TInt KInvalidCommandId = 99999;
       
    53 const TInt KDataSize = 2000;
       
    54 const TInt KSecondaryCommandId = 700;
       
    55 const TInt KMinDomainID = 200100;
       
    56 const TInt KMidDomainID = 200150;
       
    57 const TInt KMaxDomainID = 200660;
       
    58 
       
    59 // MACROS
       
    60 //#define ?macro ?macro_def
       
    61 
       
    62 // LOCAL CONSTANTS AND MACROS
       
    63 //const ?type ?constant_var = ?constant;
       
    64 //#define ?macro_name ?macro_def
       
    65 
       
    66 // MODULE DATA STRUCTURES
       
    67 //enum ?declaration
       
    68 //typedef ?declaration
       
    69 
       
    70 // LOCAL FUNCTION PROTOTYPES
       
    71 //?type ?function_name( ?arg_type, ?arg_type );
       
    72 
       
    73 // FORWARD DECLARATIONS
       
    74 //class ?FORWARD_CLASSNAME;
       
    75 
       
    76 // ============================= LOCAL FUNCTIONS ===============================
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // ?function_name ?description.
       
    80 // ?description
       
    81 // Returns: ?value_1: ?description
       
    82 //          ?value_n: ?description_line1
       
    83 //                    ?description_line2
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 /*
       
    87 ?type ?function_name(
       
    88     ?arg_type arg,  // ?description
       
    89     ?arg_type arg)  // ?description
       
    90     {
       
    91 
       
    92     ?code  // ?comment
       
    93 
       
    94     // ?comment
       
    95     ?code
       
    96     }
       
    97 */
       
    98 
       
    99 // ============================ MEMBER FUNCTIONS ===============================
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMediatorTest::Case
       
   103 // Returns a test case by number.
       
   104 //
       
   105 // This function contains an array of all available test cases 
       
   106 // i.e pair of case name and test function. If case specified by parameter
       
   107 // aCaseNumber is found from array, then that item is returned.
       
   108 // 
       
   109 // The reason for this rather complicated function is to specify all the
       
   110 // test cases only in one place. It is not necessary to understand how
       
   111 // function pointers to class member functions works when adding new test
       
   112 // cases. See function body for instructions how to add new test case.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 const TCaseInfo CMediatorTest::Case ( 
       
   116     const TInt aCaseNumber ) const 
       
   117      {
       
   118 
       
   119     /**
       
   120     * To add new test cases, implement new test case function and add new 
       
   121     * line to KCases array specify the name of the case and the function 
       
   122     * doing the test case
       
   123     * In practice, do following
       
   124     * 1) Make copy of existing test case function and change its name
       
   125     *    and functionality. Note that the function must be added to 
       
   126     *    MediatorTest.cpp file and to MediatorTest.h 
       
   127     *    header file.
       
   128     *
       
   129     * 2) Add entry to following KCases array either by using:
       
   130     *
       
   131     * 2.1: FUNCENTRY or ENTRY macro
       
   132     * ENTRY macro takes two parameters: test case name and test case 
       
   133     * function name.
       
   134     *
       
   135     * FUNCENTRY macro takes only test case function name as a parameter and
       
   136     * uses that as a test case name and test case function name.
       
   137     *
       
   138     * Or
       
   139     *
       
   140     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   141     * only with OOM (Out-Of-Memory) testing!
       
   142     *
       
   143     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   144     * function name, TBool which specifies is method supposed to be run using
       
   145     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   146     * TInt value for last heap memory allocation failure.
       
   147     * 
       
   148     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   149     * that as a test case name, TBool which specifies is method supposed to be
       
   150     * run using OOM conditions, TInt value for first heap memory allocation 
       
   151     * failure and TInt value for last heap memory allocation failure. 
       
   152     */ 
       
   153     
       
   154     static TCaseInfoInternal const KCases[] =
       
   155         {
       
   156         // To add new test cases, add new items to this array
       
   157         FUNCENTRY( RegisterOneEvent ),
       
   158         FUNCENTRY( GetListOfDomainsInitL ),        
       
   159         FUNCENTRY( GetListOfDomains1DomainL ),
       
   160         FUNCENTRY( GetListOfEvents1EventInCategoryL ),
       
   161         FUNCENTRY( RegisterMultipleEventsL ),
       
   162         FUNCENTRY( RegisterOver500EventsL ),
       
   163         FUNCENTRY( UnregisterNonExistingEventDom ),
       
   164         FUNCENTRY( GetListOfDomainsMultipleDomainsL ),
       
   165         FUNCENTRY( UnregisterNonExistingEventCat ),
       
   166         FUNCENTRY( UnregisterNonExistingEventEve ),
       
   167         FUNCENTRY( UnregisterExistingEvent ),
       
   168         FUNCENTRY( UnregisterRxistingEventDifferentSID ),
       
   169         FUNCENTRY( UnregisterAListOfEventsL ),
       
   170         FUNCENTRY( UnregisterAListOfEventsNotRegisteredL ),
       
   171         FUNCENTRY( SubscribeToNonExistingEventDom ),
       
   172         FUNCENTRY( SubscribeToNonExistingEventCat ),
       
   173         FUNCENTRY( SubscribeToNonExistingEventEve ),
       
   174         FUNCENTRY( SubscribeToWrongEventVersionMajor ),
       
   175         FUNCENTRY( SubscribeToEventNonExistCapabilities ),
       
   176         FUNCENTRY( SubscribeToEventCorrectParam ),
       
   177         FUNCENTRY( SubscribeToListOfEventsCorrectParamL ),
       
   178         FUNCENTRY( SubscribeToListOfEventsOneInfoIncorrectL ),
       
   179         FUNCENTRY( RaiseNonExistingEventWrongDomainL ),
       
   180         FUNCENTRY( RaiseNonExistingEventWrongCatL ),
       
   181         FUNCENTRY( RaiseNonExistingEventEveL ),
       
   182         FUNCENTRY( RaiseEventWithWrongEventVerMajorL ),
       
   183         FUNCENTRY( RaiseEventRequiresNotExistingCapsInPubL ),
       
   184         FUNCENTRY( RaiseExistingEventL ),
       
   185         FUNCENTRY( SubscribeExistingEventRaiseFromPublisherSideL ),
       
   186         FUNCENTRY( SubscribeExistingEventRaiseFromPublisherSideDataOver1kBL ),
       
   187         FUNCENTRY( SubscribeToEventDeleteConsumerInstanceRaiseEventFromPublisherL ),
       
   188         FUNCENTRY( Add2ndSubscriberToEventRaiseEventFromPublisherL ),
       
   189         FUNCENTRY( UnsubscribeFrom1stSubscriberL ),
       
   190         FUNCENTRY( SubscribeToEventRaise500TimesInLoopL ),
       
   191         FUNCENTRY( RegisterOneCommandToMediator ),
       
   192         FUNCENTRY( RegisterMultipleCommandsToMediatorL ),
       
   193         FUNCENTRY( RegisterOver500CommandsWithinOneCatL ),
       
   194         FUNCENTRY( RegisterCommandWithDomainUID0 ),
       
   195         FUNCENTRY( RegisterCommandWithCategoryUID0 ),
       
   196         FUNCENTRY( RegisterCommandWithCommandID0 ),
       
   197         FUNCENTRY( RegisterCommandWithTimeoutValue0 ),
       
   198         FUNCENTRY( IssueNonExistingCommandWrongDomainL ),
       
   199         FUNCENTRY( IssueNonExistingCommandWrongCatL ),
       
   200         FUNCENTRY( IssueNonExistingCommandIdL ),
       
   201         FUNCENTRY( IssueCommandWrongCommandVerMajorL ),
       
   202         FUNCENTRY( IssueCommandL ),
       
   203         FUNCENTRY( IssueCommand2L ),
       
   204         FUNCENTRY( IssueExistingCommandSameInitiatorWhileProcessingL ),
       
   205         FUNCENTRY( IssueCommandWaitWithoutRespondingToCommandL ),
       
   206         FUNCENTRY( IssueCommandCancelFromInitiatorBeforeTimeoutL ),
       
   207         FUNCENTRY( IssueCommandRespondCorrectlyFromResponderL ),
       
   208         FUNCENTRY( IssueCommandALotOfParameterDataL ),
       
   209         FUNCENTRY( IssueCommandRespondALotOfResponseDataL ),
       
   210         //FUNCENTRY( GetListOfDomainsOver500Domains ),
       
   211         FUNCENTRY( GetListOfCategoriesNoCategoriesL ),
       
   212         FUNCENTRY( GetListOfCategoriesIncorrectDomainUIDL ),
       
   213         FUNCENTRY( GetListOfCategoriesMultipleCategoriesL ),
       
   214         FUNCENTRY( GetListOfCommandsL ),
       
   215         FUNCENTRY( GetListOfCommandsIncorrectDomainUIDL ),
       
   216         FUNCENTRY( GetListOfCommandsIncorrectCategoryUIDL ),
       
   217         FUNCENTRY( GetListOfCommands1CommandL ),
       
   218         FUNCENTRY( GetListOfCommandsMultipleCommandsL ),
       
   219         FUNCENTRY( GetListOfCommandsOver500CommandsL ),
       
   220         FUNCENTRY( GetListOfEventsNoEventsInCategoryL ),
       
   221         FUNCENTRY( GetListOfEventsWithIncorrectDomainUIDL ),
       
   222         FUNCENTRY( GetListOfEventsWithIncorrectCategoryUIDL ),
       
   223         FUNCENTRY( GetListOfEventsMultipleEventsInCategoryL ),
       
   224         FUNCENTRY( GetListOfEventsOver500EventsInCategoryL ),
       
   225         FUNCENTRY( SubscribeNotificationReceiver ),
       
   226         FUNCENTRY( ReSubscribeNotificationReceiver ),
       
   227         FUNCENTRY( ReUnsubscribeNotificationReceiver ),
       
   228         FUNCENTRY( SubscribeNotificationReceiverRegisterCommandsL ),
       
   229         FUNCENTRY( SubscribeNotificationReceiverUnregCommandsSoThatCatIsEmptyL ),
       
   230         FUNCENTRY( SubscribeNotificationReceiverRegisterEventsL ),
       
   231         FUNCENTRY( SubscribeNotificationReceiverUnregisterEventsL ),
       
   232         FUNCENTRY( SubscribeNotificationReceiverUnregisterEventsSoThatCatIsEmptyL ),
       
   233         FUNCENTRY( SubscribeNotificationReceiverRegisterCommandsSoThatErrorInRegistrationL ),
       
   234         FUNCENTRY( SubscribeNotificationReceiverUnegisterCommandsSoThatErrorInRegistrationL ),
       
   235         FUNCENTRY( SubscribeNotificationReceiverRegisterEventsSoThatErrorInRegistration ),
       
   236         FUNCENTRY( SubscribeNotificationReceiverUnregisterEventsSoThatErrorInRegistration ),
       
   237         FUNCENTRY( IssueCommandCancelAndReissueL ),
       
   238         FUNCENTRY( IssueCommandCancelAndIssueNewCommandL ),
       
   239         FUNCENTRY( InstantiateAndDeleteMediatorPluginL ),
       
   240         FUNCENTRY( IssueCommandNoDataL ),
       
   241         FUNCENTRY( RaiseEventNoDataL ),
       
   242         FUNCENTRY( RegisterMultipleEventsWithMultipleUIDsL ),
       
   243         FUNCENTRY( RegisterMultipleCommandsWithMultipleUIDsL ),
       
   244         FUNCENTRY( IssueCommandRespondIncorrectlyFromResponderL ),
       
   245         FUNCENTRY( OOMForEventProviderTestL ),
       
   246         FUNCENTRY( OOMForEventConsumerTestL ),
       
   247         FUNCENTRY( OOMForEventProviderwithListTestL ),
       
   248         FUNCENTRY( OOMForEventConsumerWithEventTestL ),
       
   249         FUNCENTRY( OOMForCommandInitiatorTestL ),
       
   250         FUNCENTRY( OOMForCommandInitiatorCommandListTestL ),
       
   251         FUNCENTRY( OOMForMediatorNotificationsTestL )
       
   252         // Example how to use OOM functionality
       
   253         //OOM_ENTRY( "Loop test with OOM", LoopTest, ETrue, 2, 3 ),
       
   254         //OOM_FUNCENTRY( PrintTest, ETrue, 1, 3 ),
       
   255         };
       
   256 
       
   257     // Verify that case number is valid
       
   258     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   259                                sizeof( TCaseInfoInternal ) )
       
   260         {
       
   261         // Invalid case, construct empty object
       
   262         TCaseInfo null( (const TText*) L"" );
       
   263         null.iMethod = NULL;
       
   264         null.iIsOOMTest = EFalse;
       
   265         null.iFirstMemoryAllocation = 0;
       
   266         null.iLastMemoryAllocation = 0;
       
   267         return null;
       
   268         } 
       
   269 
       
   270     // Construct TCaseInfo object and return it
       
   271     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   272     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   273     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   274     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   275     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   276     return tmp;
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CMediatorTest::PrintTest
       
   281 // Simple printing to UI test.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 TInt CMediatorTest::PrintTest( 
       
   285     TTestResult& aResult )
       
   286     {
       
   287      /* Simple print test */
       
   288     _LIT( KPrintTest, "PrintTest" );
       
   289     _LIT( KEnter, "Enter" );
       
   290     _LIT( KOnGoing, "On-going" );
       
   291     _LIT( KExit, "Exit" );
       
   292 
       
   293     TestModuleIf().Printf( 0, KPrintTest, KEnter );
       
   294            
       
   295     TestModuleIf().Printf( 1, KPrintTest, KOnGoing );
       
   296     
       
   297     TestModuleIf().Printf( 0, KPrintTest, KExit );
       
   298 
       
   299     // Test case passed
       
   300 
       
   301     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   302     _LIT( KDescription, "PrintTest passed" );
       
   303     aResult.SetResult( KErrNone, KDescription );
       
   304 
       
   305     // Case was executed
       
   306     return KErrNone;
       
   307 
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CMediatorTest::LoopTest
       
   312 // Another printing to UI test.
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 TInt CMediatorTest::LoopTest( TTestResult& aResult )
       
   316     {
       
   317 
       
   318     /* Simple print and wait loop */
       
   319     _LIT( KState, "State" );
       
   320     _LIT( KLooping, "Looping" );
       
   321 
       
   322     TestModuleIf().Printf( 0, KState, KLooping );
       
   323 
       
   324     _LIT( KRunning, "Running" );
       
   325     _LIT( KLoop, "%d" );
       
   326     for( TInt i=0; i<10; i++)
       
   327         {
       
   328         TestModuleIf().Printf( 1, KRunning, KLoop, i);
       
   329         User::After( 1000000 );
       
   330         }
       
   331 
       
   332     _LIT( KFinished, "Finished" );
       
   333     TestModuleIf().Printf( 0, KState, KFinished );
       
   334 
       
   335     // Test case passed
       
   336 
       
   337     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   338     _LIT( KDescription, "LoopTest passed" );
       
   339     aResult.SetResult( KErrNone, KDescription );
       
   340 
       
   341     // Case was executed
       
   342     return KErrNone;
       
   343 
       
   344     }
       
   345 
       
   346     
       
   347 ////////////////////////////////////////////////////////////////////////////////
       
   348 //
       
   349 // M E D I A T O R      T E S T S ->
       
   350 //
       
   351 //
       
   352 // -----------------------------------------------------------------------------
       
   353 // -----------------------------------------------------------------------------
       
   354 // CMediatorTest::RegisterOneEvent
       
   355 //
       
   356 // Register one event in Mediator
       
   357 // Expected precondition: No event created previously
       
   358 // Expected behaviour: Registration succeed
       
   359 // Cleaning: Unregister event
       
   360 //
       
   361 // Domain: KTestUid
       
   362 // Category: KTestUid
       
   363 // Event ID: KTestEventId
       
   364 // 
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 
       
   368 TInt CMediatorTest::RegisterOneEvent( TTestResult& aResult )
       
   369     {    
       
   370     TInt status( KErrNone );
       
   371     TUid myUid = TUid::Uid( KTestUid );
       
   372     TCapabilitySet caps;
       
   373     caps.SetEmpty();
       
   374     
       
   375     status = iEventProvider->RegisterEvent( myUid, 
       
   376                                             myUid,
       
   377                                             KTestEventId,
       
   378                                             iDefaultVersion,
       
   379                                             caps ) ;        
       
   380 
       
   381     _LIT( KDescription, "RegisterEvent returns with" );
       
   382     aResult.SetResult( status, KDescription ); // set status as test result
       
   383     
       
   384     if( KErrNone == status  )
       
   385         {
       
   386         /* Registration succeeded -> Clean Event */
       
   387         TInt cleanStatus = CleanRegisterOneEvent( myUid, myUid, KTestEventId ); 
       
   388         if( KErrNone != cleanStatus )
       
   389             {
       
   390             _LIT( KDescription, "Test passed but cleaning failed" );
       
   391             aResult.SetResult( cleanStatus, KDescription );     
       
   392             }
       
   393         }
       
   394     return KErrNone;
       
   395     }
       
   396 
       
   397 
       
   398 TInt CMediatorTest::CleanRegisterOneEvent( TUid aDomain, TUid aCategory, TInt aEventId )
       
   399     {
       
   400     return iEventProvider->UnregisterEvent( aDomain, 
       
   401                                             aCategory,
       
   402                                             aEventId );  
       
   403     }
       
   404 
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CMediatorTest::RegisterMultipleEvents
       
   408 //
       
   409 // Register 50 events in Mediator
       
   410 // Expected precondition: No events created previously
       
   411 // Expected behaviour: Registration succeed
       
   412 // Cleaning: Unregister events
       
   413 //
       
   414 // Domain: KTestUid
       
   415 // Category: KTestUid
       
   416 // Event IDs: 50 - 99
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 TInt CMediatorTest::RegisterMultipleEventsL( TTestResult& aResult )
       
   420     {
       
   421     TInt status( KErrNone );
       
   422     TUid myUid = TUid::Uid( KTestUid );
       
   423     TCapabilitySet caps;
       
   424     caps.SetEmpty();    
       
   425     REventList eventList;
       
   426     CleanupClosePushL( eventList );
       
   427     
       
   428     for( TInt i=50; i<100; i++ ) // i = Event ID
       
   429         {
       
   430         TEvent newEvent;
       
   431         newEvent.iEventId = i;
       
   432         newEvent.iVersion = iDefaultVersion;
       
   433         newEvent.iCaps = caps;  
       
   434         eventList.AppendL( newEvent );
       
   435         }
       
   436     
       
   437     status = iEventProvider->RegisterEvent( myUid, 
       
   438                                             myUid,
       
   439                                             eventList);
       
   440 
       
   441 
       
   442     _LIT( KDescription, "RegisterEvent returns with" );
       
   443     aResult.SetResult( status, KDescription );
       
   444  
       
   445     if( KErrNone == status  )
       
   446         {
       
   447         /* Registration succeeded -> Clean Event */
       
   448         TInt cleanStatus = CleanRegisterMultipleEvents( myUid, myUid, eventList ); 
       
   449         if( KErrNone != cleanStatus )
       
   450             {
       
   451             _LIT( KDescription, "Test passed but cleaning failed" );
       
   452             aResult.SetResult( cleanStatus, KDescription );     
       
   453             }
       
   454         }
       
   455     CleanupStack::PopAndDestroy( &eventList );
       
   456     return KErrNone;
       
   457     }
       
   458 
       
   459 TInt CMediatorTest::CleanRegisterMultipleEvents( TUid aDomain, TUid aCategory, REventList& aEventList )
       
   460     {
       
   461     return iEventProvider->UnregisterEvent( aDomain, 
       
   462                                             aCategory,
       
   463                                             aEventList );
       
   464     }
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // CMediatorTest::RegisterOver500Events
       
   468 //
       
   469 // Register over 500 events
       
   470 // Expected precondition: No events created previously
       
   471 // Expected behaviour: Registration succeed
       
   472 // Cleaning: Unregister events
       
   473 //
       
   474 // Domain: KTestUid
       
   475 // Category: KTestUid
       
   476 // Event IDs: 100 - 699
       
   477 // -----------------------------------------------------------------------------
       
   478 //       
       
   479 TInt CMediatorTest::RegisterOver500EventsL( TTestResult& aResult )
       
   480     {
       
   481     TInt status( KErrNone );
       
   482     TUid myUid = TUid::Uid( KTestUid );
       
   483     TCapabilitySet caps;
       
   484     caps.SetEmpty();
       
   485     REventList eventList;
       
   486     CleanupClosePushL( eventList );
       
   487     
       
   488     for( TInt i=100; i<700; i++ ) // i = event ID
       
   489         {
       
   490         TEvent newEvent;
       
   491         newEvent.iEventId = i;
       
   492         newEvent.iVersion = iDefaultVersion;
       
   493         newEvent.iCaps = caps;    
       
   494         eventList.AppendL( newEvent );
       
   495         }
       
   496     
       
   497     status = iEventProvider->RegisterEvent( myUid, 
       
   498                                             myUid,
       
   499                                             eventList);
       
   500 
       
   501     _LIT( KDescription, "RegisterEvent returns with" );
       
   502     aResult.SetResult( status, KDescription );  // status is returned as test result
       
   503 
       
   504     if( KErrNone == status  )
       
   505         {
       
   506         /* Registration succeeded -> Clean Events */
       
   507         TInt cleanStatus = CleanRegisterOver500Events(myUid, myUid, eventList);  
       
   508         if( KErrNone != cleanStatus)
       
   509             {
       
   510             _LIT( KDescription, "Test passed but cleaning failed" );
       
   511             aResult.SetResult( cleanStatus, KDescription );     
       
   512             }
       
   513         }
       
   514     CleanupStack::PopAndDestroy( &eventList );
       
   515     return KErrNone;
       
   516     }
       
   517 
       
   518 TInt CMediatorTest::CleanRegisterOver500Events( TUid aDomain, TUid aCategory, REventList aEventList )
       
   519     {
       
   520     TInt status = iEventProvider->UnregisterEvent( aDomain, 
       
   521                                                    aCategory,
       
   522                                                    aEventList );    
       
   523     CTestScheduler::StartAndStopL( 1000 ); // wait 1s 
       
   524     
       
   525     return status;
       
   526     }
       
   527 
       
   528  // -----------------------------------------------------------------------------
       
   529 // CMediatorTest::UnregisterNonExistingEventDom
       
   530 //
       
   531 // Expected preconditions: Requested event domain is not existing
       
   532 // Expected behaviour: Unregistration fail (KErrMediatorDomainNotFound)
       
   533 // Cleaning: None
       
   534 //
       
   535 // Try to unregister event from domain that does not exist
       
   536 // Domain: KNonExistingDomainId
       
   537 // Category: KTestUid
       
   538 // Event: KTestEventId
       
   539 // -----------------------------------------------------------------------------
       
   540 //      
       
   541 TInt CMediatorTest::UnregisterNonExistingEventDom( TTestResult& aResult )
       
   542     {   
       
   543     TInt status( KErrNone );
       
   544     TUid myUid = TUid::Uid( KTestUid );
       
   545     TUid invalidUid = TUid::Uid( KNonExistingDomainId );
       
   546     
       
   547     status = iEventProvider->UnregisterEvent( invalidUid, 
       
   548                                               myUid,
       
   549                                               KTestEventId ) ;       
       
   550     //expected status is KErrMediatorDomainNotFound 
       
   551     if( KErrMediatorDomainNotFound == status )
       
   552         {
       
   553         _LIT( KDescription, "UnregisterEvent returned with expected KErrMediatorDomainNotFound" );
       
   554         aResult.SetResult( KErrNone, KDescription );      
       
   555         }
       
   556     else
       
   557         {
       
   558         _LIT( KErrorDescription, "Wrong error status" );
       
   559         aResult.SetResult( KErrGeneral, KErrorDescription );
       
   560         }
       
   561     return KErrNone;
       
   562     }   
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CMediatorTest::UnregisterNonExistingEventCat
       
   566 //
       
   567 // Expected preconditions: Requested event category is not existing
       
   568 // Expected behaviour: Unregistration fail (KErrMediatorCategoryNotFound)
       
   569 // Cleaning: None
       
   570 //
       
   571 // Try to unregister event from category that does not exist 
       
   572 // Domain: KTestUid
       
   573 // Category: KNonExistingCategoryId
       
   574 // Event ID: KTestEventId
       
   575 // -----------------------------------------------------------------------------
       
   576 //      
       
   577 TInt CMediatorTest::UnregisterNonExistingEventCat( TTestResult& aResult )
       
   578     {
       
   579     TInt status( KErrNone );
       
   580     TUid myUid = TUid::Uid( KTestUid );
       
   581     TUid invalidUid = TUid::Uid( KNonExistingCategoryId );
       
   582     status = iEventProvider->UnregisterEvent( myUid, 
       
   583                                               invalidUid,
       
   584                                               KTestEventId) ;
       
   585     //expected status is KErrMediatorCategoryNotFound                                        
       
   586     if( KErrMediatorCategoryNotFound == status )
       
   587         {
       
   588         _LIT( KDescription, "UnregisterEvent returned with expected KErrMediatorCategoryNotFound" );
       
   589         aResult.SetResult( KErrNone, KDescription );        
       
   590         }
       
   591     else
       
   592         {
       
   593         _LIT( KErrorDescription, "Wrong error status" );
       
   594         aResult.SetResult( KErrGeneral, KErrorDescription );
       
   595         }
       
   596        
       
   597     return KErrNone;
       
   598     }
       
   599 
       
   600 
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CMediatorTest::UnregisterNonExistingEventEve
       
   604 //
       
   605 // Expected preconditions: Event is not existing but domain and category is
       
   606 // Expected behaviour: Unregistration fail (KErrMediatorEventNotFound)
       
   607 // Cleaning: Unregister existing events
       
   608 //
       
   609 // Try to unregister nonexisting event from valid Domain and Category
       
   610 // Domain: KTestUid
       
   611 // Category: KTestUid
       
   612 // Event ID: KNonExistingEventId
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 
       
   616 TInt CMediatorTest::UnregisterNonExistingEventEve( TTestResult& aResult )
       
   617     {
       
   618     TInt status( KErrNone );
       
   619     TUid myUid = TUid::Uid( KTestUid );
       
   620     TCapabilitySet caps;
       
   621     caps.SetEmpty();
       
   622     
       
   623     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KExistingEventId, iDefaultVersion, caps );
       
   624     
       
   625     _LIT( KDescription, "PreconditionRegisterOneEvent returns with" );
       
   626     aResult.SetResult( preStatus, KDescription );    
       
   627     
       
   628     if( KErrNone == preStatus )
       
   629         {    
       
   630         //unregister non existing event
       
   631         status = iEventProvider->UnregisterEvent( myUid, 
       
   632                                                   myUid,
       
   633                                                   KNonExistingEventId);          
       
   634         //expected status is KErrMediatorEventNotFound
       
   635         if( KErrMediatorEventNotFound == status )
       
   636             {
       
   637             _LIT( KDescription, "UnregisterEvent returned with expected KErrMediatorEventNotFound" );
       
   638             aResult.SetResult( KErrNone, KDescription );
       
   639             
       
   640             //clean existing event
       
   641             status = CleanRegisterOneEvent( myUid, myUid, KExistingEventId );
       
   642             if( KErrNone != status )
       
   643                 {
       
   644                 _LIT( KErrorDescription, "Test code passed but cleaning event failed" );
       
   645                 aResult.SetResult( status, KErrorDescription );
       
   646                 } 
       
   647             }
       
   648         else
       
   649             {
       
   650             _LIT( KErrorDescription, "Wrong error status" );
       
   651             aResult.SetResult( KErrGeneral, KErrorDescription );
       
   652             }
       
   653         }   
       
   654     return KErrNone;
       
   655     }
       
   656 
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CMediatorTest::UnregisterExistingEvent
       
   660 // 
       
   661 // Expected preconditions: Event is existing
       
   662 // Expected behaviour: Unregistration succeed (KErrNone)
       
   663 // Cleaning: Event is unregistered
       
   664 //
       
   665 // Unregister event
       
   666 // Domain: KTestUid
       
   667 // Category: KTestUid
       
   668 // Event: KExistingEventId
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 
       
   672 TInt CMediatorTest::UnregisterExistingEvent( TTestResult& aResult )
       
   673     {
       
   674     TInt status( KErrNone );
       
   675     TUid myUid = TUid::Uid( KTestUid );
       
   676     TCapabilitySet caps;
       
   677     caps.SetEmpty();
       
   678     
       
   679     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KExistingEventId, iDefaultVersion, caps );
       
   680     
       
   681     _LIT( KDescription, "PreconditionRegisterOneEvent returns with" );
       
   682     aResult.SetResult( preStatus, KDescription );    
       
   683     
       
   684     if( KErrNone == preStatus )
       
   685         {
       
   686         status = iEventProvider->UnregisterEvent( myUid, 
       
   687                                                   myUid,
       
   688                                                   KExistingEventId );
       
   689         _LIT( KDescription, "UnregisterEvent returns with" );
       
   690         aResult.SetResult( status, KDescription );
       
   691         }
       
   692     return KErrNone;
       
   693     }
       
   694 
       
   695 TInt CMediatorTest::PreconditionRegisterOneEvent( TUid aDomain,
       
   696                                                   TUid aCategory, 
       
   697                                                   TInt aEventId, 
       
   698                                                   TVersion aVersion,
       
   699                                                   TCapabilitySet aCaps )
       
   700     {    
       
   701     TInt status( KErrNone );      
       
   702     status = iEventProvider->RegisterEvent( aDomain,
       
   703                                             aCategory, 
       
   704                                             aEventId, 
       
   705                                             aVersion,
       
   706                                             aCaps ) ;
       
   707     CTestScheduler::StartAndStopL(1000); // wait 1s
       
   708     return status;
       
   709     }
       
   710 
       
   711 
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // CMediatorTest::UnregisterRxistingEventDifferentSID
       
   715 //
       
   716 // Expected preconditions: Event is existing
       
   717 // Expected behaviour: Unregistration fail (KErrMediatorSecureIdMismatch)
       
   718 // Cleaning: Not needed
       
   719 //
       
   720 // Try to unregister event that is registered by different SID (static event)
       
   721 // Domain: KOtherUid
       
   722 // Category: KOtherSIDCategory
       
   723 // Event: KOtherSIDEventId
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 
       
   727 TInt CMediatorTest::UnregisterRxistingEventDifferentSID( TTestResult& aResult )
       
   728     {
       
   729     TInt status( KErrNone );
       
   730     TUid myUid = TUid::Uid( KOtherUid );
       
   731     TUid myCat = TUid::Uid( KOtherSIDCategory );
       
   732     
       
   733     // Precondition!!! Event is static, defined in resource file
       
   734         
       
   735     status = iEventProvider->UnregisterEvent( myUid, 
       
   736                                               myCat,
       
   737                                               KOtherSIDEventId) ;       
       
   738     //expected status is KErrMediatorSecureIdMismatch
       
   739     if( KErrMediatorSecureIdMismatch == status ) // Event is registered by different SID
       
   740         {
       
   741         _LIT( KDescription, "UnregisterEvent returned with expected KErrMediatorSecureIdMismatch" );
       
   742         aResult.SetResult( KErrNone, KDescription );
       
   743         }
       
   744     else
       
   745         {
       
   746         _LIT( KErrorDescription, "Wrong error status" );
       
   747         aResult.SetResult( KErrGeneral, KErrorDescription );
       
   748         }
       
   749        
       
   750     return KErrNone;
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CMediatorTest::UnregisterAListOfEvents
       
   755 //
       
   756 // Expected preconditions: Event is existing
       
   757 // Expected behaviour: Unregistration succeed (KErrNone)
       
   758 // Cleaning: Not needed
       
   759 //
       
   760 // Unregister list of events
       
   761 // Domain: KTestUid
       
   762 // Category: KTestUid
       
   763 // Event ID(s): 51 - 75 
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 
       
   767 TInt CMediatorTest::UnregisterAListOfEventsL( TTestResult& aResult )
       
   768     {
       
   769     TInt status( KErrNone );
       
   770     TUid myUid = TUid::Uid( KTestUid );
       
   771     TCapabilitySet caps;
       
   772     caps.SetEmpty();    
       
   773     REventList eventList;
       
   774     CleanupClosePushL( eventList );              
       
   775     for( TInt i=51; i<76; i++ ) // Create list of events (i = event ID)
       
   776         {
       
   777         TEvent newEvent;
       
   778         newEvent.iEventId = i;
       
   779         newEvent.iVersion = iDefaultVersion;
       
   780         newEvent.iCaps = caps;    
       
   781         eventList.AppendL( newEvent );
       
   782         }
       
   783     
       
   784     TInt preStatus = PreconditionRegisterAListOfEvents( myUid, myUid, eventList );
       
   785     _LIT( KDescription, "PreconditionRegisterAListOfEvents returns with" );
       
   786     aResult.SetResult( preStatus, KDescription );
       
   787           
       
   788     if( KErrNone == preStatus )
       
   789         {
       
   790         status = iEventProvider->UnregisterEvent( myUid, 
       
   791                                                   myUid,
       
   792                                                   eventList );
       
   793       
       
   794         _LIT( KDescription, "UnregisterEvent returns with" );
       
   795         aResult.SetResult( status, KDescription );
       
   796         }
       
   797     
       
   798     CleanupStack::PopAndDestroy( &eventList );
       
   799     return KErrNone;
       
   800     }
       
   801 
       
   802 TInt CMediatorTest::PreconditionRegisterAListOfEvents( TUid aDomain,
       
   803                                                        TUid aCategory, 
       
   804                                                        REventList aEventList )
       
   805     {    
       
   806     return iEventProvider->RegisterEvent( aDomain,
       
   807                                             aCategory, 
       
   808                                             aEventList );       
       
   809     }
       
   810 
       
   811 // -----------------------------------------------------------------------------
       
   812 // CMediatorTest::UnregisterAListOfEventsNotRegistered
       
   813 //
       
   814 // Expected preconditions: Event does not exist
       
   815 // Expected behaviour: Unregistration fail (KErrMediatorEventNotFound)
       
   816 // Cleaning: Not needed
       
   817 //
       
   818 // Unregister list of event (some of events are not registered)
       
   819 // Domain: KTestUid
       
   820 // Category: KTestUid
       
   821 // Event ID(s): 73 - 103 
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 
       
   825 TInt CMediatorTest::UnregisterAListOfEventsNotRegisteredL( TTestResult& aResult )
       
   826     {
       
   827     TInt status( KErrNone );
       
   828     TUid myUid = TUid::Uid( KTestUid );
       
   829     TCapabilitySet caps;
       
   830     caps.SetEmpty();
       
   831 
       
   832     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KExistingEventId, iDefaultVersion, caps );
       
   833     
       
   834     _LIT( KDescription, "PreconditionRegisterOneEvent returns with" );
       
   835     aResult.SetResult( preStatus, KDescription );    
       
   836     
       
   837     if( KErrNone == preStatus )
       
   838         {    
       
   839         REventList eventList;
       
   840         CleanupClosePushL( eventList );
       
   841                         
       
   842         for(TInt i=51; i<100; i++) 
       
   843             {
       
   844             TEvent newEvent;
       
   845             newEvent.iEventId = i;
       
   846             newEvent.iVersion = iDefaultVersion;
       
   847             newEvent.iCaps = caps;    
       
   848             eventList.AppendL( newEvent );
       
   849             }
       
   850         
       
   851         //unregister a list of events that is not registered 
       
   852         status = iEventProvider->UnregisterEvent( myUid, 
       
   853                                                 myUid,
       
   854                                                 eventList);
       
   855         //expected status is KErrMediatorEventNotFound
       
   856         if( KErrMediatorEventNotFound == status )
       
   857             {
       
   858             _LIT( KDescription, "UnregisterEvent returned with expected KErrMediatorEventNotFound" );
       
   859             aResult.SetResult( KErrNone, KDescription );
       
   860             //clean the registered event
       
   861             status = CleanRegisterOneEvent( myUid, myUid, KExistingEventId );
       
   862             if( KErrNone != status )
       
   863                 {
       
   864                 _LIT( KErrorDescription, "Test code passed but cleaning event failed" );
       
   865                 aResult.SetResult( status, KErrorDescription );
       
   866                 }
       
   867             }
       
   868         else
       
   869             {
       
   870             _LIT( KErrorDescription, "Wrong error status" );
       
   871             aResult.SetResult( KErrGeneral, KErrorDescription );
       
   872             }
       
   873         CleanupStack::PopAndDestroy( &eventList );
       
   874         } 
       
   875     return KErrNone;
       
   876     }
       
   877 
       
   878 
       
   879 // -----------------------------------------------------------------------------
       
   880 // CMediatorTest::SubscribeToNonExistingEventDom
       
   881 //
       
   882 // Expected preconditions: Event does not exist
       
   883 // Expected behaviour: Subscribe fail (KErrMediatorDomainNotFound)
       
   884 // Cleaning: Not needed
       
   885 //
       
   886 // Try to subscribe to event (domain does not exist)
       
   887 // Domain: KNonExistingDomainId
       
   888 // Category: KTestUid
       
   889 // Event: KTestEventId
       
   890 // -----------------------------------------------------------------------------
       
   891 //
       
   892 
       
   893 TInt CMediatorTest::SubscribeToNonExistingEventDom( TTestResult& aResult )
       
   894     {
       
   895     TInt status( KErrNone );
       
   896     TUid myUid = TUid::Uid( KTestUid );
       
   897     TUid invalidUid = TUid::Uid( KNonExistingDomainId );
       
   898     
       
   899     status = iEventConsumer->SubscribeEvent( invalidUid, 
       
   900                                              myUid,
       
   901                                              KTestEventId,
       
   902                                              iDefaultVersion) ;      
       
   903     //expected status is KErrMediatorDomainNotFound
       
   904     if( KErrMediatorDomainNotFound == status )
       
   905         {
       
   906         _LIT( KDescription, "SubscribeEvent returned with expected KErrMediatorDomainNotFound" );
       
   907         aResult.SetResult( KErrNone, KDescription );        
       
   908         }
       
   909     else
       
   910         {
       
   911         _LIT( KErrorDescription, "Wrong error status" );
       
   912         aResult.SetResult( KErrGeneral, KErrorDescription );
       
   913         }
       
   914     return KErrNone;
       
   915     }
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CMediatorTest::SubscribeToNonExistingEventCat
       
   919 //
       
   920 // Expected preconditions: Event does not exist
       
   921 // Expected behaviour: Subscribe fail (KErrMediatorCategoryNotFound)
       
   922 // Cleaning: Not needed
       
   923 //
       
   924 // Try to subscribe event (category does not exist)
       
   925 // Domain: KTestUid
       
   926 // Category: KNonExistingCategoryId
       
   927 // Event: KTestEventId
       
   928 // -----------------------------------------------------------------------------
       
   929 //
       
   930 
       
   931 TInt CMediatorTest::SubscribeToNonExistingEventCat( TTestResult& aResult )
       
   932     {
       
   933     TInt status( KErrNone );
       
   934     TUid myUid = TUid::Uid( KTestUid );
       
   935     TUid invalidUid = TUid::Uid( KNonExistingCategoryId );
       
   936 
       
   937     status = iEventConsumer->SubscribeEvent( myUid, 
       
   938                                              invalidUid,
       
   939                                              KTestEventId,
       
   940                                              iDefaultVersion ) ;  
       
   941     //expected status is KErrMediatorCategoryNotFound                                        
       
   942     if( KErrMediatorCategoryNotFound == status )
       
   943         {
       
   944         _LIT( KDescription, "SubscribeEvent returned with expected KErrMediatorCategoryNotFound" );
       
   945         aResult.SetResult( KErrNone, KDescription );        
       
   946         }
       
   947     else
       
   948         {
       
   949         _LIT( KErrorDescription, "Wrong error status" );
       
   950         aResult.SetResult( KErrGeneral, KErrorDescription );
       
   951         }
       
   952     return KErrNone;
       
   953     }
       
   954 
       
   955 
       
   956 // -----------------------------------------------------------------------------
       
   957 // CMediatorTest::SubscribeToNonExistingEventEve
       
   958 //
       
   959 // Expected preconditions: Event does not exist
       
   960 // Expected behaviour: Subscribe fail (KErrMediatorEventNotFound)
       
   961 // Cleaning: Not needed
       
   962 //
       
   963 // Try to subscribe event (event does not exist)
       
   964 // Domain: KTestUid
       
   965 // Category: KTestUid
       
   966 // Event: KNonExistingEventId
       
   967 // -----------------------------------------------------------------------------
       
   968 //
       
   969 
       
   970 TInt CMediatorTest::SubscribeToNonExistingEventEve( TTestResult& aResult )
       
   971     {
       
   972     TInt status( KErrNone );
       
   973     TUid myUid = TUid::Uid( KTestUid );
       
   974     TCapabilitySet caps;
       
   975     caps.SetEmpty();
       
   976 
       
   977     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KExistingEventId, iDefaultVersion, caps );
       
   978     
       
   979     _LIT( KDescription, "PreconditionRegisterOneEvent returns with" );
       
   980     aResult.SetResult( preStatus, KDescription );    
       
   981     
       
   982     if( KErrNone == preStatus )
       
   983         {    
       
   984         status = iEventConsumer->SubscribeEvent( myUid, 
       
   985                                                  myUid,
       
   986                                                  KNonExistingEventId,
       
   987                                                  iDefaultVersion );    
       
   988         //expected status is KErrMediatorEventNotFound                                        
       
   989         if( KErrMediatorEventNotFound == status )
       
   990             {
       
   991             _LIT( KDescription, "SubscribeEvent returned with expected KErrMediatorEventNotFound" );
       
   992             aResult.SetResult( KErrNone, KDescription ); 
       
   993             //unregister the registered event
       
   994             status = CleanRegisterOneEvent( myUid, myUid, KExistingEventId );
       
   995             if(KErrNone != status)
       
   996                 {
       
   997                 _LIT( KErrorDescription, "Test code passed but cleaning event failed" );
       
   998                 aResult.SetResult( status, KErrorDescription );
       
   999                 }
       
  1000             }
       
  1001         else
       
  1002             {
       
  1003             _LIT( KErrorDescription, "Wrong error status" );
       
  1004             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1005             }
       
  1006         }   
       
  1007     return KErrNone;
       
  1008     }
       
  1009 
       
  1010 // -----------------------------------------------------------------------------
       
  1011 // CMediatorTest::SubscribeToWrongEventVersionMajor
       
  1012 //
       
  1013 // Expected preconditions: Event does not exist
       
  1014 // Expected behaviour: Subscribe fail (KErrMediatorVersionMismatch)
       
  1015 // Cleaning: Not needed
       
  1016 //
       
  1017 // Try to subscribe event (event exist but version is wrong) 
       
  1018 // Domain: KTestUid
       
  1019 // Category: KTestUid
       
  1020 // Event: KTestEventId
       
  1021 // Version: 6.5.5
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 
       
  1025 TInt CMediatorTest::SubscribeToWrongEventVersionMajor( TTestResult& aResult )
       
  1026     {
       
  1027     TInt status( KErrNone );
       
  1028     TUid myUid = TUid::Uid( KTestUid );
       
  1029     TVersion version( 777, 5, 5 );
       
  1030     TCapabilitySet caps;
       
  1031     caps.SetEmpty();
       
  1032     
       
  1033     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1034     
       
  1035     _LIT( KDescription, "PreconditionRegisterOneEvent returns with" );
       
  1036     aResult.SetResult( preStatus, KDescription );    
       
  1037     
       
  1038     if( KErrNone == preStatus )
       
  1039         {    
       
  1040         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1041                                                  myUid,
       
  1042                                                  KTestEventId,
       
  1043                                                  version );   
       
  1044         //expected status is KErrMediatorVersionMismatch                                      
       
  1045         if( KErrMediatorVersionMismatch == status )
       
  1046             {
       
  1047             _LIT( KDescription, "SubscribeEvent returned with expected KErrMediatorVersionMismatch" );
       
  1048             aResult.SetResult( KErrNone, KDescription );
       
  1049             status = CleanRegisterOneEvent(myUid, myUid, KTestEventId);
       
  1050             if( KErrNone != status )
       
  1051                 {
       
  1052                 _LIT( KErrorDescription, "Test code passed but cleaning event failed" );
       
  1053                 aResult.SetResult( status, KErrorDescription );
       
  1054                 } 
       
  1055             }
       
  1056         else
       
  1057             {
       
  1058             _LIT( KErrorDescription, "Wrong error code" );
       
  1059             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1060             }
       
  1061         }   
       
  1062     return KErrNone;
       
  1063     }
       
  1064 
       
  1065 // -----------------------------------------------------------------------------
       
  1066 // CMediatorTest::SubscribeToEventNonExistCapabilities
       
  1067 //
       
  1068 // Expected preconditions: Event is existing
       
  1069 // Expected behaviour: Subscribe fail (KErrPermissionDenied)
       
  1070 // Cleaning: Not needed
       
  1071 //
       
  1072 // Try to subscribe event that require too much capabilities 
       
  1073 // Domain: KOtherUid
       
  1074 // Category: KOtherSIDCategory
       
  1075 // Event: KNonExistingEventCapaId
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 
       
  1079 TInt CMediatorTest::SubscribeToEventNonExistCapabilities( TTestResult& aResult )
       
  1080     {
       
  1081     TInt status( KErrNone );
       
  1082     TUid myUid = TUid::Uid( KOtherUid );
       
  1083     TUid catUid = TUid::Uid( KOtherSIDCategory );
       
  1084     TVersion version( 1,0,0 );
       
  1085     
       
  1086     status = iEventConsumer->SubscribeEvent( myUid, 
       
  1087                                              catUid,
       
  1088                                              KNonExistingEventCapaId,
       
  1089                                              version);   
       
  1090     //expected status is KErrPermissionDenied                                           
       
  1091     if( KErrPermissionDenied == status )
       
  1092         {
       
  1093         _LIT( KDescription, "SubscribeEvent returned with expected KErrPermissionDenied" );
       
  1094         aResult.SetResult( KErrNone, KDescription );        
       
  1095         }
       
  1096     else
       
  1097         {
       
  1098         _LIT( KErrorDescription, "Wrong error status" );
       
  1099         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1100         }
       
  1101     return KErrNone;
       
  1102     }
       
  1103 
       
  1104 // -----------------------------------------------------------------------------
       
  1105 // CMediatorTest::SubscribeToEventCorrectParam
       
  1106 //
       
  1107 // Expected preconditions: Event is existing
       
  1108 // Expected behaviour: Subscribe succeed (KErrNone)
       
  1109 // Cleaning: Unsubscribe event
       
  1110 //
       
  1111 // Subscribe event
       
  1112 // Domain: KTestUid
       
  1113 // Category: KTestUid
       
  1114 // Event: KTestEventId
       
  1115 // -----------------------------------------------------------------------------
       
  1116 //
       
  1117 
       
  1118 TInt CMediatorTest::SubscribeToEventCorrectParam( TTestResult& aResult )
       
  1119     {
       
  1120     TInt status( KErrNone );
       
  1121     TUid myUid = TUid::Uid( KTestUid );
       
  1122     TCapabilitySet caps;
       
  1123     caps.SetEmpty();
       
  1124     
       
  1125     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1126     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1127     aResult.SetResult( preStatus, KErrorDescription );
       
  1128     
       
  1129     if( KErrNone == preStatus )
       
  1130         {                                 
       
  1131         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1132                                                 myUid,
       
  1133                                                 KTestEventId,
       
  1134                                                 iDefaultVersion );    
       
  1135         
       
  1136         _LIT( KErrorDescription, "SubscribeEvent returns with" );
       
  1137         aResult.SetResult( status, KErrorDescription );
       
  1138         if( KErrNone == status  )
       
  1139             {
       
  1140             status = CleanSubscribeToEvent( myUid, myUid, KTestEventId );
       
  1141             if( KErrNone != status )
       
  1142                 {
       
  1143                 _LIT( KErrorDescription, "Test (SubscribeEvent) passed but unsubscribe failed" );
       
  1144                 aResult.SetResult( status, KErrorDescription );           
       
  1145                 }
       
  1146             }
       
  1147         //unregister the registered event
       
  1148         status = CleanRegisterOneEvent( myUid, myUid, KTestEventId );
       
  1149         if( KErrNone != status )
       
  1150             {
       
  1151             _LIT( KErrorDescription, "Test code passed but cleaning event failed" );
       
  1152             aResult.SetResult( status, KErrorDescription );
       
  1153             }                                         
       
  1154         }
       
  1155     
       
  1156     return KErrNone;
       
  1157     }
       
  1158 
       
  1159 TInt CMediatorTest::CleanSubscribeToEvent( TUid aDomain,
       
  1160                                            TUid aCategory, 
       
  1161                                            TInt aEventId )
       
  1162     {
       
  1163     return iEventConsumer->UnsubscribeEvent( aDomain, 
       
  1164                                              aCategory,
       
  1165                                              aEventId ) ;
       
  1166     }
       
  1167 
       
  1168 // -----------------------------------------------------------------------------
       
  1169 // CMediatorTest::SubscribeToListOfEventsCorrectParam
       
  1170 //
       
  1171 // Expected preconditions: Event is existing
       
  1172 // Expected behaviour: Subscribe succeed (KErrNone)
       
  1173 // Cleaning: Unsubscribe event
       
  1174 //
       
  1175 // Subscribe list of events
       
  1176 // Domain: KTestUid
       
  1177 // Category: KTestUid
       
  1178 // Events: 80 - 90
       
  1179 // -----------------------------------------------------------------------------
       
  1180 //
       
  1181 
       
  1182 TInt CMediatorTest::SubscribeToListOfEventsCorrectParamL( TTestResult& aResult )
       
  1183     {
       
  1184     TInt status( KErrNone );
       
  1185     TUid myUid = TUid::Uid( KTestUid );
       
  1186     TCapabilitySet caps;
       
  1187     caps.SetEmpty();
       
  1188     REventList eventList;
       
  1189     CleanupClosePushL( eventList );                  
       
  1190     for( TInt i=80; i<91; i++ ) // Create list of events (i = event ID)
       
  1191         {
       
  1192         TEvent newEvent;
       
  1193         newEvent.iEventId = i;
       
  1194         newEvent.iVersion = iDefaultVersion;
       
  1195         newEvent.iCaps = caps;    
       
  1196         eventList.AppendL( newEvent );
       
  1197         }
       
  1198     TInt preStatus = PreconditionRegisterEvents( myUid, myUid, eventList );
       
  1199     _LIT( KDescription, "PreconditionRegisterEvents returns with" );
       
  1200     aResult.SetResult( preStatus, KDescription );
       
  1201     
       
  1202     if( KErrNone == preStatus )
       
  1203         {
       
  1204         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1205                                                  myUid,
       
  1206                                                  eventList );
       
  1207         
       
  1208         _LIT( KDescription, "SubscribeEvent returns with" );
       
  1209         aResult.SetResult( status, KDescription );
       
  1210         
       
  1211         if( KErrNone == status  )
       
  1212             {
       
  1213             status = CleanSubscribeToListOfEvents( myUid, myUid, eventList );
       
  1214             if( KErrNone != status )
       
  1215                 {
       
  1216                 _LIT( KDescription, "Test(SubscribeEvent) passed but unsbscribe failed" );
       
  1217                 aResult.SetResult( status, KDescription );
       
  1218                 }
       
  1219             }
       
  1220         //clean registered events
       
  1221         status = CleanRegisterMultipleEvents( myUid, myUid, eventList );
       
  1222         if( KErrNone != status )
       
  1223             {
       
  1224             _LIT( KErrorDescription, "Test passed but cleaning events failed" );
       
  1225             aResult.SetResult( status, KErrorDescription );
       
  1226             }             
       
  1227         }
       
  1228     CleanupStack::PopAndDestroy( &eventList );
       
  1229     return KErrNone;
       
  1230     }
       
  1231 
       
  1232 TInt CMediatorTest::PreconditionRegisterEvents( TUid aDomain, 
       
  1233                                                 TUid aCategory, 
       
  1234                                                 REventList aEvents )
       
  1235     {   
       
  1236     return iEventProvider->RegisterEvent( aDomain, aCategory, aEvents);
       
  1237     }
       
  1238 
       
  1239 TInt CMediatorTest::CleanSubscribeToListOfEvents( TUid aDomain,
       
  1240                                                   TUid aCategory, 
       
  1241                                                   REventList aEvents )
       
  1242     {
       
  1243     return iEventConsumer->UnsubscribeEvent( aDomain, 
       
  1244                                                     aCategory,
       
  1245                                                     aEvents ) ;
       
  1246     }
       
  1247 
       
  1248 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 // CMediatorTest::SubscribeToListOfEventsOneInfoIncorrect
       
  1251 //
       
  1252 // Expected preconditions: Event is existing
       
  1253 // Expected behaviour: Subscribe fail (KErrMediatorVersionMismatch)
       
  1254 // Cleaning: Unsubscribe event
       
  1255 //
       
  1256 // Subscribe to list of events (one item in list not valid)
       
  1257 // Domain: KTestUid
       
  1258 // Category; KTestUid
       
  1259 // Events: 91 - KMaxListId (One event version is incorrect)
       
  1260 // -----------------------------------------------------------------------------
       
  1261 //
       
  1262 
       
  1263 TInt CMediatorTest::SubscribeToListOfEventsOneInfoIncorrectL( TTestResult& aResult )
       
  1264     {
       
  1265     TInt status( KErrNone );
       
  1266     TUid myUid = TUid::Uid( KTestUid );
       
  1267     TCapabilitySet caps;
       
  1268     caps.SetEmpty();
       
  1269     TVersion invalidVersion( 6, 5, 5 );
       
  1270     
       
  1271     REventList eventList;
       
  1272     CleanupClosePushL( eventList );
       
  1273     
       
  1274     for( TInt i=91; i<101; i++ ) // Create list of events (i = event ID)
       
  1275         {
       
  1276         TEvent newEvent;
       
  1277         newEvent.iEventId = i;
       
  1278         newEvent.iVersion = iDefaultVersion;
       
  1279         newEvent.iCaps = caps;    
       
  1280         eventList.AppendL( newEvent );
       
  1281         }
       
  1282       
       
  1283     REventList myList = eventList;
       
  1284             
       
  1285     TInt preStatus = PreconditionRegisterEvents( myUid, myUid, myList );
       
  1286     _LIT( KErrorDescription, "PreconditionRegisterEvents returns with" );
       
  1287     aResult.SetResult( preStatus, KErrorDescription );
       
  1288             
       
  1289     if( KErrNone == preStatus )
       
  1290         {
       
  1291         TEvent newEvent;
       
  1292         newEvent.iEventId = 100;
       
  1293         newEvent.iVersion = invalidVersion;//wrong version 
       
  1294         newEvent.iCaps = caps;    
       
  1295         eventList.AppendL( newEvent );
       
  1296       
       
  1297         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1298                                                  myUid,
       
  1299                                                  eventList );
       
  1300         //expected status is KErrMediatorVersionMismatch  
       
  1301         if( KErrMediatorVersionMismatch == status )
       
  1302             {
       
  1303             _LIT( KDescription, "SubscribeEvent returned with expected KErrMediatorVersionMismatch" );
       
  1304             aResult.SetResult( KErrNone, KDescription );  
       
  1305             //clean the registered events
       
  1306             status = CleanRegisterMultipleEvents( myUid, myUid, myList );
       
  1307             if( KErrNone != status )
       
  1308                 {
       
  1309                 _LIT( KErrorDescription, "Test passed but cleaning failed" );
       
  1310                 aResult.SetResult( status, KErrorDescription );
       
  1311                 }
       
  1312             }
       
  1313         else
       
  1314             {
       
  1315             _LIT( KErrorDescription, "Wrong error status" );
       
  1316             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1317             }
       
  1318         }
       
  1319     CleanupStack::PopAndDestroy( &eventList );
       
  1320     return KErrNone;
       
  1321     }
       
  1322 
       
  1323 // -----------------------------------------------------------------------------
       
  1324 // CMediatorTest::RaiseNonExistingEventWrongDomain
       
  1325 //
       
  1326 // Expected preconditions: There are domains but requested domain does not exist
       
  1327 // Expected behaviour: Raise fail (KErrMediatorDomainNotFound)
       
  1328 // Cleaning: Not needed
       
  1329 //
       
  1330 // Try to raise event (event not registered) 
       
  1331 // Domain: KNonExistingDomainId
       
  1332 // Category: KTestUid   
       
  1333 // Event: KTestEventId
       
  1334 // -----------------------------------------------------------------------------
       
  1335 //
       
  1336 
       
  1337 TInt CMediatorTest::RaiseNonExistingEventWrongDomainL( TTestResult& aResult )
       
  1338     {
       
  1339     TInt status( KErrNone );
       
  1340     TUid invalidUid = TUid::Uid( KNonExistingDomainId );
       
  1341     TUid myUid = TUid::Uid( KTestUid );
       
  1342     TCapabilitySet caps;
       
  1343     caps.SetEmpty();
       
  1344 
       
  1345     _LIT8( KTest, "TestTestTest" );
       
  1346     HBufC8* data = KTest().AllocLC();
       
  1347     status = iEventProvider->RaiseEvent( invalidUid,
       
  1348                                          myUid, 
       
  1349                                          KTestEventId,
       
  1350                                          iDefaultVersion, 
       
  1351                                          *data );
       
  1352     
       
  1353     CleanupStack::PopAndDestroy( data );
       
  1354     //expected status is KErrMediatorDomainNotFound 
       
  1355     if( KErrMediatorDomainNotFound == status )
       
  1356         {
       
  1357         _LIT( KDescription, "RaiseEvent returned with expected KErrMediatorDomainNotFound" );
       
  1358         aResult.SetResult( KErrNone, KDescription );        
       
  1359         }
       
  1360     else
       
  1361         {
       
  1362         _LIT( KErrorDescription, "Wrong error status" );
       
  1363         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1364         }
       
  1365     return KErrNone;
       
  1366     }
       
  1367 
       
  1368 // -----------------------------------------------------------------------------
       
  1369 // CMediatorTest::RaiseNonExistingEventWrongCat
       
  1370 //
       
  1371 // Expected preconditions: There are domains but requested category does not exist
       
  1372 // Expected behaviour: Raise fail (KErrMediatorCategoryNotFound)
       
  1373 // Cleaning: Not needed
       
  1374 //
       
  1375 // Try to raise event (category does not exist)
       
  1376 // Domain: KOtherUid
       
  1377 // Category: KNonExistingCategoryId
       
  1378 // Event: KTestEventId
       
  1379 // -----------------------------------------------------------------------------
       
  1380 //
       
  1381 
       
  1382 TInt CMediatorTest::RaiseNonExistingEventWrongCatL( TTestResult& aResult )
       
  1383     {
       
  1384     TInt status( KErrNone );
       
  1385     TUid invalidUid = TUid::Uid( KNonExistingCategoryId );
       
  1386     TUid myUid = TUid::Uid(KOtherUid);
       
  1387     TCapabilitySet caps;
       
  1388     caps.SetEmpty();
       
  1389 
       
  1390     _LIT8( KTest, "TestTestTest" );
       
  1391     HBufC8* data = KTest().AllocLC();
       
  1392 
       
  1393     status = iEventProvider->RaiseEvent( myUid,
       
  1394                                          invalidUid, 
       
  1395                                          KTestEventId,
       
  1396                                          iDefaultVersion, 
       
  1397                                          *data );
       
  1398     
       
  1399     CleanupStack::PopAndDestroy( data );
       
  1400     //expected status is KErrMediatorCategoryNotFound
       
  1401     if( KErrMediatorCategoryNotFound == status )
       
  1402         {
       
  1403         _LIT( KDescription, "RaiseEvent returned with expected KErrMediatorCategoryNotFound" );
       
  1404         aResult.SetResult( KErrNone, KDescription );        
       
  1405         }
       
  1406     else
       
  1407         {
       
  1408         _LIT( KErrorDescription, "Wrong error status" );
       
  1409         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1410         }
       
  1411     return KErrNone;
       
  1412     }
       
  1413 
       
  1414 // -----------------------------------------------------------------------------
       
  1415 // CMediatorTest::RaiseNonExistingEventEve
       
  1416 //
       
  1417 // Expected preconditions: There is domain and category but requested event does not exist
       
  1418 // Expected behaviour: Raise fail (KErrMediatorEventNotFound)
       
  1419 // Cleaning: Unregister event
       
  1420 //
       
  1421 // Raise event (event does not exist)
       
  1422 // Domain: KTestUid  
       
  1423 // Category: KTestUid
       
  1424 // Event: KNonExistingEventId
       
  1425 // -----------------------------------------------------------------------------
       
  1426 //
       
  1427 
       
  1428 TInt CMediatorTest::RaiseNonExistingEventEveL( TTestResult& aResult )
       
  1429     {
       
  1430     TInt status( KErrNone );
       
  1431     TUid myUid = TUid::Uid( KTestUid );
       
  1432     TCapabilitySet caps;
       
  1433     caps.SetEmpty();
       
  1434 
       
  1435     _LIT8( KTest, "TestTestTest" );
       
  1436     HBufC8* data = KTest().AllocLC();
       
  1437     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1438     if( KErrNone == status  )
       
  1439         {
       
  1440         status = iEventProvider->RaiseEvent( myUid,
       
  1441                                              myUid, 
       
  1442                                              KNonExistingEventId,
       
  1443                                              iDefaultVersion, 
       
  1444                                              *data );
       
  1445         CleanupStack::PopAndDestroy( data );
       
  1446         //expected status is KErrMediatorEventNotFound
       
  1447         if( KErrMediatorEventNotFound == status )
       
  1448             {
       
  1449             _LIT( KDescription, "RaiseEvent returned with expected KErrMediatorEventNotFound" );
       
  1450             aResult.SetResult( KErrNone, KDescription );
       
  1451             status = CleanRegisterOneEvent( myUid, myUid, KTestEventId );
       
  1452             if( KErrNone != status )
       
  1453                     {
       
  1454                     _LIT( KErrorDescription, "Test passed but cleaning failed" );
       
  1455                     aResult.SetResult( status, KErrorDescription );
       
  1456                     }
       
  1457             }
       
  1458         else
       
  1459             {
       
  1460             _LIT( KErrorDescription, "Wrong error status" );
       
  1461             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1462             }
       
  1463         }
       
  1464     return KErrNone;
       
  1465     }
       
  1466 
       
  1467 
       
  1468 // -----------------------------------------------------------------------------
       
  1469 // CMediatorTest::RaiseEventWithWrongEventVerMajor
       
  1470 //
       
  1471 // Expected preconditions: There is domain and category but requested event version does not exist
       
  1472 // Expected behaviour: Raise fail (KErrMediatorVersionMismatch)
       
  1473 // Cleaning: Not needed
       
  1474 //
       
  1475 // Try to raise event (wrong version)
       
  1476 // Domain: KTestUid
       
  1477 // Category: KTestUid
       
  1478 // Event: KTestEventId 
       
  1479 // -----------------------------------------------------------------------------
       
  1480 //
       
  1481 
       
  1482 TInt CMediatorTest::RaiseEventWithWrongEventVerMajorL( TTestResult& aResult )
       
  1483     {
       
  1484     TInt status( KErrNone );
       
  1485     TUid myUid = TUid::Uid( KTestUid );
       
  1486     TCapabilitySet caps;
       
  1487     caps.SetEmpty();
       
  1488     TVersion version( 888, 5, 5 );
       
  1489     
       
  1490     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1491     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1492     aResult.SetResult( preStatus, KErrorDescription );
       
  1493     
       
  1494     if( KErrNone == preStatus )
       
  1495         {
       
  1496         _LIT8( KTest, "TestTestTest" );
       
  1497         HBufC8* data = KTest().AllocLC();
       
  1498         status = iEventProvider->RaiseEvent( myUid,
       
  1499                                              myUid, 
       
  1500                                              KTestEventId,
       
  1501                                              version, 
       
  1502                                              *data );
       
  1503         CleanupStack::PopAndDestroy( data );
       
  1504         //expected status is KErrMediatorVersionMismatch
       
  1505         if( KErrMediatorVersionMismatch == status )
       
  1506             {
       
  1507             _LIT( KDescription, "RaiseEvent returned with expected KErrMediatorVersionMismatch" );
       
  1508             aResult.SetResult( KErrNone, KDescription );
       
  1509             status = CleanRegisterOneEvent( myUid, myUid, KTestEventId );
       
  1510             if( KErrNone != status )
       
  1511                 {
       
  1512                 _LIT( KErrorDescription, "Test passed but cleaning failed" );
       
  1513                 aResult.SetResult( status, KErrorDescription );
       
  1514                 } 
       
  1515             }
       
  1516         else
       
  1517             {
       
  1518             _LIT( KErrorDescription, "Wrong error status" );
       
  1519             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  1520             }
       
  1521         }
       
  1522     return KErrNone;
       
  1523     }
       
  1524 
       
  1525 
       
  1526 // -----------------------------------------------------------------------------
       
  1527 // CMediatorTest::RaiseEventRequiresNotExistingCapsInPub
       
  1528 //
       
  1529 // Expected preconditions: There is domain and category but requested event capabilites does not exist
       
  1530 // Expected behaviour: Raise fail (KErrMediatorDomainNotFound)
       
  1531 // Cleaning: Not needed
       
  1532 //
       
  1533 // Raise event that requires capabilities not existing in publisher
       
  1534 // Domain: KTestUid
       
  1535 // Category: KTestUid
       
  1536 // Event: KNonExistingEventCapaId
       
  1537 // -----------------------------------------------------------------------------
       
  1538 //
       
  1539 
       
  1540 TInt CMediatorTest::RaiseEventRequiresNotExistingCapsInPubL( TTestResult& aResult )
       
  1541     {
       
  1542     TInt status( KErrNone );
       
  1543     TUid myUid = TUid::Uid( KOtherUid );
       
  1544     TUid catUid = TUid::Uid( KOtherSIDCategory );
       
  1545     TVersion version( 1, 0 ,0 );
       
  1546 
       
  1547     _LIT8(KTest, "TestTestTest");
       
  1548     HBufC8* data = KTest().AllocLC();
       
  1549 
       
  1550     status = iEventProvider->RaiseEvent( myUid,
       
  1551                                          catUid, 
       
  1552                                          KNonExistingEventCapaId, // static event
       
  1553                                          version, 
       
  1554                                          *data );
       
  1555     CleanupStack::PopAndDestroy( data );
       
  1556 
       
  1557     _LIT( KErrorDescription, "" );
       
  1558     aResult.SetResult( status, KErrorDescription );
       
  1559 
       
  1560     return KErrNone;
       
  1561 }
       
  1562 
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // CMediatorTest::RaiseExistingEvent
       
  1565 //
       
  1566 // Expected preconditions: Event exist
       
  1567 // Expected behaviour: Raise succeed
       
  1568 // Cleaning: Event unregistered
       
  1569 //
       
  1570 // Raise event
       
  1571 // Domain: KTestUid
       
  1572 // Category: KTestUid
       
  1573 // Event ID: KTestEventId
       
  1574 // -----------------------------------------------------------------------------
       
  1575 //
       
  1576 
       
  1577 TInt CMediatorTest::RaiseExistingEventL( TTestResult& aResult )
       
  1578     {
       
  1579     TInt status( KErrNone );
       
  1580     TUid myUid = TUid::Uid( KTestUid );
       
  1581     TCapabilitySet caps;
       
  1582     caps.SetEmpty();
       
  1583     
       
  1584     iTestHelper->ClearAllNotifyData();
       
  1585     
       
  1586     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1587     _LIT( KErrorDescription, "Preconditions failed" );
       
  1588     aResult.SetResult( preStatus, KErrorDescription );
       
  1589     
       
  1590     if( KErrNone == preStatus )
       
  1591         { 
       
  1592         CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  1593         CleanupStack::PushL( eventProvider );
       
  1594         
       
  1595         _LIT8(KTest, "TestTestTest");
       
  1596         HBufC8* data = KTest().AllocLC();
       
  1597        
       
  1598         status = eventProvider->RaiseEvent( myUid,
       
  1599                                             myUid, 
       
  1600                                             KTestEventId,
       
  1601                                             iDefaultVersion, 
       
  1602                                             *data );        
       
  1603         // wait 3s to make sure that all asyncronous events are completed
       
  1604         CTestScheduler::StartAndStopL( 3000 ); 
       
  1605                                                      
       
  1606         CleanupStack::PopAndDestroy( data );
       
  1607         CleanupStack::PopAndDestroy( eventProvider );
       
  1608         _LIT( KDescription, "RaiseEvent returns with" );
       
  1609         aResult.SetResult( status, KDescription );      
       
  1610         status = CleanRegisterOneEvent(myUid, myUid, KTestEventId);
       
  1611         if( KErrNone != status )
       
  1612             {
       
  1613             _LIT( KErrorDescription, "Test Passed but cleaning event failed" );
       
  1614             aResult.SetResult( status, KErrorDescription );
       
  1615             }      
       
  1616         }
       
  1617     return KErrNone;
       
  1618     }
       
  1619 
       
  1620 // -----------------------------------------------------------------------------
       
  1621 // CMediatorTest::SubscribeExistingEventRaiseFromPublisherSide
       
  1622 //
       
  1623 // Expected preconditions: Event exist
       
  1624 // Expected behaviour: Raise succeed
       
  1625 // Cleaning: Event unregistered
       
  1626 //
       
  1627 // Raise event
       
  1628 // Domain: KTestUid
       
  1629 // Category: KTestUid
       
  1630 // Event ID: KTestEventId
       
  1631 // -----------------------------------------------------------------------------
       
  1632 //
       
  1633 
       
  1634 TInt CMediatorTest::SubscribeExistingEventRaiseFromPublisherSideL( TTestResult& aResult )
       
  1635     {
       
  1636     TInt status( KErrNone );
       
  1637     TUid myUid = TUid::Uid( KTestUid );
       
  1638     TCapabilitySet caps;
       
  1639     caps.SetEmpty();
       
  1640 
       
  1641     CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  1642     CleanupStack::PushL( eventProvider );
       
  1643     _LIT8(KTest, "TestTestTest");
       
  1644     HBufC8* data = KTest().AllocLC();
       
  1645 
       
  1646     // Clear all notify information from helper
       
  1647     iTestHelper->ClearAllNotifyData();
       
  1648 
       
  1649     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1650     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1651     aResult.SetResult( preStatus, KErrorDescription );
       
  1652     
       
  1653     if( KErrNone == preStatus )
       
  1654         {
       
  1655         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1656                                                  myUid,
       
  1657                                                  KTestEventId,
       
  1658                                                  iDefaultVersion) ;  
       
  1659         CTestScheduler::StartAndStopL( 1000 ); // 1s delay 
       
  1660         
       
  1661         if( KErrNone == status  )
       
  1662             {
       
  1663             status = eventProvider->RaiseEvent( myUid,
       
  1664                                                 myUid, 
       
  1665                                                 KTestEventId,
       
  1666                                                 iDefaultVersion, 
       
  1667                                                 *data );
       
  1668             // wait 2s to make sure that all asyncronous events are completed
       
  1669             CTestScheduler::StartAndStopL( 2000 ); 
       
  1670             _LIT( KDescription, "RaiseEvent returns with" );
       
  1671             aResult.SetResult( status, KDescription );
       
  1672             /* Check that notify was received, only when RaiseEvent returns KErrNone*/
       
  1673             if ( ( KErrNone == status  )
       
  1674                 &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  1675                         || ( iTestHelper->iDomain != myUid )
       
  1676                         || ( iTestHelper->iCategory != myUid )
       
  1677                         || ( iTestHelper->iEventId != KTestEventId ) ) )
       
  1678                 {
       
  1679                 status = KErrNotFound; 
       
  1680                 _LIT( KDescription, "iTestHelper checks failed" );
       
  1681                 aResult.SetResult( status, KDescription );  
       
  1682                 }
       
  1683             else if ( KErrNone == status  )
       
  1684                 {
       
  1685                 status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  1686                 if( KErrNone != status )
       
  1687                     {
       
  1688                     _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  1689                     aResult.SetResult( status, KErrorDescription );
       
  1690                     }   
       
  1691                 }
       
  1692             }
       
  1693         }
       
  1694     CleanupStack::PopAndDestroy( data );
       
  1695     CleanupStack::PopAndDestroy( eventProvider );
       
  1696     return KErrNone;
       
  1697     }
       
  1698 
       
  1699 
       
  1700 // -----------------------------------------------------------------------------
       
  1701 // CMediatorTest::SubscribeExistingEventRaiseFromPublisherSideDataOver1kB
       
  1702 //
       
  1703 // Expected preconditions: Event exist
       
  1704 // Expected behaviour: Raise succeed
       
  1705 // Cleaning: Event unregistered
       
  1706 // 
       
  1707 // -----------------------------------------------------------------------------
       
  1708 //
       
  1709 
       
  1710 TInt CMediatorTest::SubscribeExistingEventRaiseFromPublisherSideDataOver1kBL( TTestResult& aResult )
       
  1711     {
       
  1712     TInt status( KErrNone );
       
  1713     TUid myUid = TUid::Uid( KTestUid );
       
  1714     TCapabilitySet caps;
       
  1715     caps.SetEmpty();
       
  1716 
       
  1717     CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  1718     CleanupStack::PushL( eventProvider );
       
  1719 
       
  1720     // Clear all notify information from helper
       
  1721     iTestHelper->ClearAllNotifyData();
       
  1722 
       
  1723     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1724     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1725     aResult.SetResult( preStatus, KErrorDescription );
       
  1726     
       
  1727     if( KErrNone == preStatus )
       
  1728         {
       
  1729         status = iEventConsumer->SubscribeEvent( myUid, 
       
  1730                                                  myUid,
       
  1731                                                  KTestEventId,
       
  1732                                                  iDefaultVersion ) ;
       
  1733                 
       
  1734         HBufC8* data = HBufC8::NewLC( KDataSize );
       
  1735         TPtr8 dataPtr = data->Des();
       
  1736         for( TInt i = 0; i < KDataSize; i++ )
       
  1737             {
       
  1738             TChar tmpChar(64);
       
  1739             dataPtr.Append( tmpChar );
       
  1740             }
       
  1741         _LIT( KDescription, "SubscribeEvent returns with" );
       
  1742         aResult.SetResult( status, KDescription );
       
  1743         if( KErrNone == status  )
       
  1744             {
       
  1745             status = eventProvider->RaiseEvent( myUid,
       
  1746                                                 myUid, 
       
  1747                                                 KTestEventId,
       
  1748                                                 iDefaultVersion, 
       
  1749                                                 *data );
       
  1750             _LIT( KDescription, "RaiseEvent returns with" );
       
  1751             aResult.SetResult( status, KDescription );
       
  1752             
       
  1753             // wait 2s to make sure that all asyncronous events are completed
       
  1754             CTestScheduler::StartAndStopL(2000); 
       
  1755             
       
  1756             /* Check that notify was received, only when RaiseEvent returns KErrNone*/
       
  1757             if( ( KErrNone == status  )
       
  1758                 &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  1759                         || ( iTestHelper->iDomain != myUid )
       
  1760                         || ( iTestHelper->iCategory != myUid )
       
  1761                         || ( iTestHelper->iEventId != KTestEventId ) ) )
       
  1762                 {
       
  1763                 status = KErrNotFound; 
       
  1764                 _LIT( KDescription, "iTestHelper checks failed" );
       
  1765                 aResult.SetResult( status, KDescription );  
       
  1766                 }
       
  1767             else if ( KErrNone == status  )
       
  1768                 {
       
  1769                 status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  1770                 if( KErrNone != status )
       
  1771                     {
       
  1772                     _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  1773                     aResult.SetResult( status, KErrorDescription );
       
  1774                     }   
       
  1775                 }
       
  1776             }
       
  1777         CleanupStack::PopAndDestroy( data );  
       
  1778         CleanupStack::PopAndDestroy( eventProvider );
       
  1779         }
       
  1780     return KErrNone;
       
  1781     }
       
  1782 
       
  1783 // -----------------------------------------------------------------------------
       
  1784 // CMediatorTest::SubscribeToEventDeleteConsumerInstanceRaiseEventFromPublisher
       
  1785 // 
       
  1786 // Expected preconditions: Event exist
       
  1787 // Expected behaviour: Raise succeed
       
  1788 // Cleaning: Event unregistered
       
  1789 // 
       
  1790 // -----------------------------------------------------------------------------
       
  1791 //
       
  1792 
       
  1793 TInt CMediatorTest::SubscribeToEventDeleteConsumerInstanceRaiseEventFromPublisherL( TTestResult& aResult )
       
  1794     {
       
  1795     TInt status( KErrNone );
       
  1796     TUid myUid = TUid::Uid( KTestUid );
       
  1797     TCapabilitySet caps;
       
  1798     caps.SetEmpty();
       
  1799 
       
  1800     // Clear all notify information from helper
       
  1801     iTestHelper->ClearAllNotifyData();
       
  1802     
       
  1803     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps);
       
  1804     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1805     aResult.SetResult( preStatus, KErrorDescription );
       
  1806     
       
  1807     CMediatorEventConsumer* eventConsumer = CMediatorEventConsumer::NewL( iTestHelper );
       
  1808     CleanupStack::PushL( eventConsumer );
       
  1809     if( KErrNone == preStatus )
       
  1810         {
       
  1811         status = eventConsumer->SubscribeEvent( myUid, 
       
  1812                                                 myUid,
       
  1813                                                 KTestEventId,
       
  1814                                                 iDefaultVersion ) ;  
       
  1815         
       
  1816         _LIT8(KTest, "TestTestTest");
       
  1817         HBufC8* data = KTest().AllocLC();
       
  1818         
       
  1819         _LIT( KDescription, "SubscribeEvent returns with" );
       
  1820         aResult.SetResult( status, KDescription );
       
  1821         if( KErrNone == status  )
       
  1822             {
       
  1823             CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  1824             CleanupStack::PushL( eventProvider );
       
  1825             status = eventProvider->RaiseEvent( myUid,
       
  1826                                                 myUid, 
       
  1827                                                 KTestEventId,
       
  1828                                                 iDefaultVersion, 
       
  1829                                                 *data );
       
  1830             
       
  1831             _LIT( KDescription, "RaiseEvent returns with" );
       
  1832             aResult.SetResult( status, KDescription );
       
  1833             // wait 2s to make sure that all asyncronous events are completed
       
  1834             CTestScheduler::StartAndStopL(2000);
       
  1835             /* Check that notify was received, only when RaiseEvent returns KErrNone*/
       
  1836             if( ( KErrNone == status  )
       
  1837                 &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  1838                         || ( iTestHelper->iDomain != myUid )
       
  1839                         || ( iTestHelper->iCategory != myUid )
       
  1840                         || ( iTestHelper->iEventId != KTestEventId ) ) )
       
  1841                 {
       
  1842                 status = KErrNotFound; 
       
  1843                 _LIT( KDescription, "iTestHelper checks failed" );
       
  1844                 aResult.SetResult( status, KDescription );  
       
  1845                 }
       
  1846             //clean the registered event
       
  1847             else if ( KErrNone == status  )
       
  1848                 {
       
  1849                 status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  1850                 if( KErrNone != status )
       
  1851                     {
       
  1852                     _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  1853                     aResult.SetResult( status, KErrorDescription );
       
  1854                     }   
       
  1855                 }
       
  1856             CleanupStack::PopAndDestroy( eventProvider );
       
  1857             }
       
  1858         CleanupStack::PopAndDestroy( data );
       
  1859         }
       
  1860     CleanupStack::PopAndDestroy(eventConsumer);
       
  1861     return KErrNone;
       
  1862     }
       
  1863 
       
  1864 // -----------------------------------------------------------------------------
       
  1865 // CMediatorTest::Add2ndSubscriberToEventRaiseEventFromPublisher
       
  1866 // 
       
  1867 // Expected preconditions: Event exist
       
  1868 // Expected behaviour: Raise succeed
       
  1869 // Cleaning: Event unregistered
       
  1870 // 
       
  1871 // -----------------------------------------------------------------------------
       
  1872 //
       
  1873 
       
  1874 TInt CMediatorTest::Add2ndSubscriberToEventRaiseEventFromPublisherL( TTestResult& aResult )
       
  1875     {
       
  1876     TInt status( KErrNone );
       
  1877     TUid myUid = TUid::Uid( KTestUid );
       
  1878     TCapabilitySet caps;
       
  1879     caps.SetEmpty();
       
  1880 
       
  1881     CMediatorEventConsumer* eventConsumer = CMediatorEventConsumer::NewL( iTestHelper );
       
  1882     CleanupStack::PushL( eventConsumer );
       
  1883     CMediatorEventConsumer* otherEventConsumer = CMediatorEventConsumer::NewL( iAnotherTestHelper );
       
  1884     CleanupStack::PushL( otherEventConsumer );
       
  1885     iTestHelper->ClearAllNotifyData();
       
  1886     iAnotherTestHelper->ClearAllNotifyData();
       
  1887 
       
  1888     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1889     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1890     aResult.SetResult( preStatus, KErrorDescription );
       
  1891 
       
  1892     if( KErrNone == preStatus )
       
  1893         {  
       
  1894         status = eventConsumer->SubscribeEvent( myUid, 
       
  1895                                                 myUid,
       
  1896                                                 KTestEventId,
       
  1897                                                 iDefaultVersion );    
       
  1898         TInt status2( KErrNone );                                        
       
  1899         status2 = otherEventConsumer->SubscribeEvent( myUid, 
       
  1900                                                       myUid,
       
  1901                                                       KTestEventId,
       
  1902                                                       iDefaultVersion);
       
  1903               
       
  1904         _LIT8(KTest, "TestTestTest");
       
  1905         HBufC8* data = KTest().AllocLC();
       
  1906         
       
  1907         _LIT( KDescription, "SubscribeEvent returns with" );
       
  1908         aResult.SetResult( status, KDescription );
       
  1909         
       
  1910         if( ( KErrNone == status2 ) && ( KErrNone ==status ) )
       
  1911             {
       
  1912             CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  1913             CleanupStack::PushL( eventProvider );           
       
  1914             status = eventProvider->RaiseEvent( myUid,
       
  1915                                                 myUid, 
       
  1916                                                 KTestEventId,
       
  1917                                                 iDefaultVersion, 
       
  1918                                                 *data );
       
  1919             _LIT( KDescription, "RaiseEvent returns with" );
       
  1920             aResult.SetResult( status, KDescription );
       
  1921             // wait 2s to make sure that all asyncronous events are completed
       
  1922             CTestScheduler::StartAndStopL(2000);
       
  1923             /* Check that notify was received for both notification, only when RaiseEvent returns KErrNone*/
       
  1924             if( ( KErrNone == status  )
       
  1925                   &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  1926                           || ( iTestHelper->iDomain != myUid )
       
  1927                           || ( iTestHelper->iCategory != myUid )
       
  1928                           || ( iTestHelper->iEventId != KTestEventId ) )
       
  1929                           
       
  1930                   &&( ( iAnotherTestHelper->iNotificationReceived == 0 ) 
       
  1931                           || ( iAnotherTestHelper->iDomain != myUid )
       
  1932                           || ( iAnotherTestHelper->iCategory != myUid )
       
  1933                           || ( iAnotherTestHelper->iEventId != KTestEventId ) ) )
       
  1934                   {
       
  1935                   status = KErrNotFound; 
       
  1936                   _LIT( KDescription, "iTestHelper checks failed" );
       
  1937                   aResult.SetResult( status, KDescription );  
       
  1938                   }
       
  1939             else if ( KErrNone == status  )
       
  1940                 {
       
  1941                 status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  1942                 if( KErrNone != status )
       
  1943                     {
       
  1944                     _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  1945                     aResult.SetResult( status, KErrorDescription );
       
  1946                     }   
       
  1947                 }
       
  1948             CleanupStack::PopAndDestroy( eventProvider );
       
  1949             }
       
  1950         CleanupStack::PopAndDestroy( data );
       
  1951         }
       
  1952     CleanupStack::PopAndDestroy( otherEventConsumer );
       
  1953     CleanupStack::PopAndDestroy( eventConsumer );
       
  1954     return KErrNone;
       
  1955     }
       
  1956 
       
  1957 // -----------------------------------------------------------------------------
       
  1958 // CMediatorTest::UnsubscribeFrom1stSubscriber
       
  1959 // 
       
  1960 // Expected preconditions: Event exist
       
  1961 // Expected behaviour: Raise succeed
       
  1962 // Cleaning: Event unregistered
       
  1963 // 
       
  1964 // -----------------------------------------------------------------------------
       
  1965 //
       
  1966 
       
  1967 TInt CMediatorTest::UnsubscribeFrom1stSubscriberL( TTestResult& aResult )
       
  1968     {
       
  1969     TInt status( KErrNone );
       
  1970     TUid myUid = TUid::Uid( KTestUid );
       
  1971     TCapabilitySet caps;
       
  1972     caps.SetEmpty();
       
  1973 
       
  1974     CMediatorEventConsumer* eventConsumer = CMediatorEventConsumer::NewL( iTestHelper );
       
  1975     CleanupStack::PushL( eventConsumer );
       
  1976     CMediatorEventConsumer* otherEventConsumer = CMediatorEventConsumer::NewL( iAnotherTestHelper );
       
  1977     CleanupStack::PushL( otherEventConsumer );
       
  1978     iTestHelper->ClearAllNotifyData();
       
  1979     iAnotherTestHelper->ClearAllNotifyData();
       
  1980 
       
  1981     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  1982     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  1983     aResult.SetResult( preStatus, KErrorDescription );
       
  1984 
       
  1985     if( KErrNone == preStatus )
       
  1986         {  
       
  1987         status = eventConsumer->SubscribeEvent( myUid, 
       
  1988                                                 myUid,
       
  1989                                                 KTestEventId,
       
  1990                                                 iDefaultVersion );    
       
  1991         TInt status2( KErrNone );                                        
       
  1992         status2 = otherEventConsumer->SubscribeEvent( myUid, 
       
  1993                                                       myUid,
       
  1994                                                       KTestEventId,
       
  1995                                                       iDefaultVersion);
       
  1996               
       
  1997         _LIT8(KTest, "TestTestTest");
       
  1998         HBufC8* data = KTest().AllocLC();
       
  1999         
       
  2000         _LIT( KDescription, "SubscribeEvent returns with" );
       
  2001         aResult.SetResult( status, KDescription );
       
  2002         
       
  2003         if( ( KErrNone == status2 ) && ( KErrNone ==status ) )
       
  2004             {
       
  2005             CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  2006             CleanupStack::PushL( eventProvider ); 
       
  2007             status = otherEventConsumer->UnsubscribeEvent( myUid, 
       
  2008                                                            myUid,
       
  2009                                                            KTestEventId);
       
  2010             _LIT( KDescription, "UnsubscribeEvent returns with" );
       
  2011             aResult.SetResult( status, KDescription );
       
  2012             if( KErrNone == status  )
       
  2013                 {
       
  2014                 status = eventProvider->RaiseEvent( myUid,
       
  2015                                                     myUid, 
       
  2016                                                     KTestEventId,
       
  2017                                                     iDefaultVersion, 
       
  2018                                                     *data );
       
  2019                 
       
  2020                 _LIT( KDescription, "RaiseEvent returns with" );
       
  2021                 aResult.SetResult( status, KDescription );
       
  2022                 
       
  2023                 // wait 2s to make sure that all asyncronous events are completed
       
  2024                 CTestScheduler::StartAndStopL(2000);
       
  2025                 
       
  2026                 /* Check that notify was received for only one notification, only when RaiseEvent returns KErrNone*/
       
  2027                 if( ( KErrNone == status  )
       
  2028                     &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  2029                           || ( iTestHelper->iDomain != myUid )
       
  2030                           || ( iTestHelper->iCategory != myUid )
       
  2031                           || ( iTestHelper->iEventId != KTestEventId ) )
       
  2032                           
       
  2033                     &&( ( iAnotherTestHelper->iNotificationReceived != 0 ) 
       
  2034                           || ( iAnotherTestHelper->iDomain == myUid )
       
  2035                           || ( iAnotherTestHelper->iCategory == myUid )
       
  2036                           || ( iAnotherTestHelper->iEventId == KTestEventId ) ) )
       
  2037                     {
       
  2038                     status = KErrNotFound; 
       
  2039                     _LIT( KDescription, "notifications check failed" );
       
  2040                     aResult.SetResult( status, KDescription );  
       
  2041                     }
       
  2042                 else if ( KErrNone == status  )
       
  2043                     {
       
  2044                     status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  2045                     if( KErrNone != status )
       
  2046                         {
       
  2047                         _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  2048                         aResult.SetResult( status, KErrorDescription );
       
  2049                         }   
       
  2050                     }
       
  2051                 }
       
  2052             CleanupStack::PopAndDestroy( eventProvider );
       
  2053             }
       
  2054         CleanupStack::PopAndDestroy( data );
       
  2055         }
       
  2056     CleanupStack::PopAndDestroy( otherEventConsumer );
       
  2057     CleanupStack::PopAndDestroy( eventConsumer );
       
  2058     return KErrNone;
       
  2059     }
       
  2060   
       
  2061 // -----------------------------------------------------------------------------
       
  2062 // CMediatorTest::SubscribeToEventRaise500TimesInLoop
       
  2063 // 
       
  2064 // Expected preconditions: Event exist
       
  2065 // Expected behaviour: Subscribe and raise succeed
       
  2066 // Cleaning: Event unregistered
       
  2067 //  
       
  2068 // -----------------------------------------------------------------------------
       
  2069 //
       
  2070 
       
  2071 TInt CMediatorTest::SubscribeToEventRaise500TimesInLoopL( TTestResult& aResult )
       
  2072     {
       
  2073     TInt status( KErrNone );
       
  2074     TUid myUid = TUid::Uid( KTestUid );
       
  2075     TCapabilitySet caps;
       
  2076     caps.SetEmpty();
       
  2077 
       
  2078     iTestHelper->ClearAllNotifyData();
       
  2079 
       
  2080     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps );
       
  2081     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  2082     aResult.SetResult( preStatus, KErrorDescription );
       
  2083 
       
  2084     if( KErrNone == preStatus )
       
  2085         {  
       
  2086         status = iEventConsumer->SubscribeEvent( myUid, 
       
  2087                                                  myUid,
       
  2088                                                  KTestEventId,
       
  2089                                                  iDefaultVersion );  
       
  2090         _LIT( KDescription, "SubscribeEvent returns with" );
       
  2091         aResult.SetResult( status, KDescription );
       
  2092         if( KErrNone == status  )
       
  2093             {
       
  2094             CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  2095             CleanupStack::PushL( eventProvider );
       
  2096             _LIT8(KTest, "TestTestTest");
       
  2097             HBufC8* data = KTest().AllocLC();
       
  2098           
       
  2099             for(TInt i=0; i<550; i++)
       
  2100                 {     
       
  2101                 status = eventProvider->RaiseEvent( myUid,
       
  2102                                                     myUid, 
       
  2103                                                     KTestEventId,
       
  2104                                                     iDefaultVersion, 
       
  2105                                                     *data );
       
  2106                 if( KErrNone != status)
       
  2107                     {
       
  2108                     break;
       
  2109                     }
       
  2110                 }
       
  2111             _LIT( KDescription, "RaiseEvent returns with" );
       
  2112             aResult.SetResult( status, KDescription );
       
  2113             // wait 2s to make sure that all asyncronous events are completed
       
  2114             CTestScheduler::StartAndStopL(2000);
       
  2115             
       
  2116             /* Check that notify was received, only when RaiseEvent returns KErrNone*/
       
  2117             if( ( KErrNone == status  )
       
  2118                 &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  2119                         || ( iTestHelper->iDomain != myUid )
       
  2120                         || ( iTestHelper->iCategory != myUid )
       
  2121                         || ( iTestHelper->iEventId != KTestEventId ) ) )
       
  2122                 {
       
  2123                 status = KErrNotFound; 
       
  2124                 _LIT( KDescription, "iTestHelper checks failed" );
       
  2125                 aResult.SetResult( status, KDescription );  
       
  2126                 }
       
  2127             //clean the registered event
       
  2128             else if ( KErrNone == status  )
       
  2129                 {
       
  2130                 status = CleanRegisterOneEvent( myUid, myUid, KTestEventId ) ;
       
  2131                 if( KErrNone != status )
       
  2132                     {
       
  2133                     _LIT( KErrorDescription, "Test passed but cleaning event failed" );
       
  2134                     aResult.SetResult( status, KErrorDescription );
       
  2135                     }   
       
  2136                 }
       
  2137             CleanupStack::PopAndDestroy( data );
       
  2138             CleanupStack::PopAndDestroy( eventProvider );
       
  2139             }
       
  2140         }
       
  2141     return KErrNone;
       
  2142     }
       
  2143 
       
  2144 // -----------------------------------------------------------------------------
       
  2145 // CMediatorTest::RegisterOneCommandToMediator
       
  2146 // 
       
  2147 // Expected preconditions: Command does not exist
       
  2148 // Expected behaviour: Register command succeed
       
  2149 // Cleaning: Command unregistered
       
  2150 //  
       
  2151 // -----------------------------------------------------------------------------
       
  2152 //
       
  2153 
       
  2154 TInt CMediatorTest::RegisterOneCommandToMediator( TTestResult& aResult )
       
  2155     {
       
  2156     TInt status( KErrNone );
       
  2157     TUid myUid = TUid::Uid( KTestUid );
       
  2158     TCapabilitySet caps;
       
  2159     caps.SetEmpty();
       
  2160     
       
  2161     status = iCommandResponder->RegisterCommand( myUid, 
       
  2162                                                  myUid, 
       
  2163                                                  KDefaultCommandId, 
       
  2164                                                  iDefaultVersion,
       
  2165                                                  caps, 
       
  2166                                                  KDefaultTimeOut );
       
  2167     
       
  2168     _LIT( KDescription, "RegisterCommand returns with" );
       
  2169     aResult.SetResult( status, KDescription );
       
  2170        
       
  2171     if( KErrNone == status  )
       
  2172         {
       
  2173         status = CleanRegisterCommand( myUid, 
       
  2174                                        myUid, 
       
  2175                                        KDefaultCommandId );
       
  2176         if( KErrNone != status )
       
  2177             {
       
  2178             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2179             aResult.SetResult( status, KDescription );     
       
  2180             }
       
  2181         }
       
  2182     return KErrNone;    
       
  2183     }
       
  2184 
       
  2185 TInt CMediatorTest::CleanRegisterCommand( TUid aDomain, 
       
  2186                                          TUid aCategory, 
       
  2187                                          TInt aCommandId )
       
  2188     {
       
  2189     TInt status = iCommandResponder->UnregisterCommand( aDomain, 
       
  2190                                                        aCategory, 
       
  2191                                                        aCommandId );  
       
  2192     CTestScheduler::StartAndStopL( 1000 ); // wait 1s
       
  2193     return status;
       
  2194     }
       
  2195                                           
       
  2196 // -----------------------------------------------------------------------------
       
  2197 // CMediatorTest::RegisterMultipleCommandsToMediator
       
  2198 // 
       
  2199 // Expected preconditions: Command does not exist
       
  2200 // Expected behaviour: Register command succeed
       
  2201 // Cleaning: Command unregistered
       
  2202 //  
       
  2203 // Register multiple commands
       
  2204 // Command ID(s): 1 -  KMaxListId
       
  2205 // -----------------------------------------------------------------------------
       
  2206 //
       
  2207 
       
  2208 TInt CMediatorTest::RegisterMultipleCommandsToMediatorL( TTestResult& aResult )
       
  2209     {
       
  2210     TInt status( KErrNone );
       
  2211     TUid myUid = TUid::Uid( KTestUid );
       
  2212     TCapabilitySet caps;
       
  2213     caps.SetEmpty();
       
  2214    
       
  2215     RCommandList  commands;
       
  2216     CleanupClosePushL(commands);
       
  2217     for ( TInt index = KMinListId; index <KMaxListId; index++ )
       
  2218         {
       
  2219          MediatorService::TCommand newCommand;
       
  2220          newCommand.iCommandId = index;
       
  2221          newCommand.iVersion = iDefaultVersion;
       
  2222          newCommand.iCaps = caps;
       
  2223          newCommand.iTimeout = KDefaultTimeOut;
       
  2224          commands.AppendL( newCommand );
       
  2225         }
       
  2226     
       
  2227     status = iCommandResponder->RegisterCommand( myUid,
       
  2228                                                  myUid, 
       
  2229                                                  commands );
       
  2230     
       
  2231     _LIT( KDescription, "RegisterCommand returns with" );
       
  2232     aResult.SetResult( status, KDescription );
       
  2233     
       
  2234     if( KErrNone == status  )
       
  2235         {
       
  2236         status = CleanRegisterCommands( myUid, 
       
  2237                                        myUid, 
       
  2238                                        commands );
       
  2239         if( KErrNone != status )
       
  2240             {
       
  2241             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2242             aResult.SetResult( status, KDescription );     
       
  2243             }
       
  2244         }
       
  2245     CleanupStack::PopAndDestroy( &commands );
       
  2246     return KErrNone;
       
  2247     }
       
  2248 
       
  2249 TInt CMediatorTest::CleanRegisterCommands( TUid aDomain, 
       
  2250                                            TUid aCategory, 
       
  2251                                            RCommandList aCommands )
       
  2252     {
       
  2253    
       
  2254     TInt status = iCommandResponder->UnregisterCommand( aDomain, 
       
  2255                                                         aCategory, 
       
  2256                                                         aCommands );
       
  2257     CTestScheduler::StartAndStopL( 2000 ); // wait 1s                                                   
       
  2258     return status;
       
  2259     }
       
  2260 
       
  2261 // -----------------------------------------------------------------------------
       
  2262 // CMediatorTest::RegisterOver500CommandsWithinOneCat
       
  2263 //
       
  2264 // Expected preconditions: Command does not exist
       
  2265 // Expected behaviour: Register command succeed
       
  2266 // Cleaning: Command unregistered
       
  2267 //
       
  2268 // IDs: KMaxListId - (KMaxListId + 540)
       
  2269 // -----------------------------------------------------------------------------
       
  2270 //
       
  2271 
       
  2272 TInt CMediatorTest::RegisterOver500CommandsWithinOneCatL( TTestResult& aResult )
       
  2273     {
       
  2274     TInt status( KErrNone );
       
  2275     TUid myUid = TUid::Uid( KTestUid );
       
  2276     TCapabilitySet caps;
       
  2277     caps.SetEmpty();
       
  2278 
       
  2279     RCommandList  commands;
       
  2280     CleanupClosePushL(commands);
       
  2281     
       
  2282     for ( TInt index = KMaxListId; index <KMaxListId+540; index++ )
       
  2283         {
       
  2284         MediatorService::TCommand newCommand;
       
  2285         newCommand.iCommandId = index;
       
  2286         newCommand.iVersion = iDefaultVersion;
       
  2287         newCommand.iCaps = caps;
       
  2288         newCommand.iTimeout = KDefaultTimeOut;
       
  2289         User::LeaveIfError( commands.Append( newCommand ) );
       
  2290         }
       
  2291     
       
  2292     status = iCommandResponder->RegisterCommand( myUid,
       
  2293                                                  myUid, 
       
  2294                                                  commands );
       
  2295 
       
  2296     _LIT( KDescription, "RegisterCommand returns with" );
       
  2297     aResult.SetResult( status, KDescription );
       
  2298     
       
  2299     if( KErrNone == status  )
       
  2300        {
       
  2301        status = CleanRegisterCommands( myUid, 
       
  2302                                       myUid, 
       
  2303                                       commands );
       
  2304        if( KErrNone != status )
       
  2305            {
       
  2306            _LIT( KDescription, "Test passed but cleaning failed" );
       
  2307            aResult.SetResult( status, KDescription );     
       
  2308            }
       
  2309        }
       
  2310     CleanupStack::PopAndDestroy( &commands );
       
  2311     return KErrNone;
       
  2312     }
       
  2313 
       
  2314 
       
  2315 // -----------------------------------------------------------------------------
       
  2316 // CMediatorTest::RegisterCommandWithDomainUID0
       
  2317 // 
       
  2318 // Expected preconditions: Command does not exist
       
  2319 // Expected behaviour: Register command succeed
       
  2320 // Cleaning: Command unregistered
       
  2321 //  
       
  2322 // Register command
       
  2323 // Domain: 0 
       
  2324 // -----------------------------------------------------------------------------
       
  2325 //
       
  2326 
       
  2327 TInt CMediatorTest::RegisterCommandWithDomainUID0( TTestResult& aResult )
       
  2328     {
       
  2329     TInt status( KErrNone );
       
  2330     TUid invalidUid = TUid::Uid(0);
       
  2331     TUid myUid = TUid::Uid( KTestUid );
       
  2332     TCapabilitySet caps;
       
  2333     caps.SetEmpty();
       
  2334 
       
  2335     status = iCommandResponder->RegisterCommand( myUid, 
       
  2336                                                  invalidUid, 
       
  2337                                                  KDefaultCommandId, 
       
  2338                                                  iDefaultVersion,
       
  2339                                                  caps, 
       
  2340                                                  KDefaultTimeOut );
       
  2341     
       
  2342     _LIT( KErrorDescription, "RegisterCommand returns with" );
       
  2343     aResult.SetResult( status, KErrorDescription );
       
  2344 
       
  2345     if( KErrNone == status  )
       
  2346         {
       
  2347         status = CleanRegisterCommand( myUid, invalidUid, KDefaultCommandId );
       
  2348         if( KErrNone != status )
       
  2349             {
       
  2350             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2351             aResult.SetResult( status, KDescription );
       
  2352             }
       
  2353         } 
       
  2354     return KErrNone;    
       
  2355     }
       
  2356 
       
  2357 
       
  2358 // -----------------------------------------------------------------------------
       
  2359 // CMediatorTest::RegisterCommandWithCategoryUID0
       
  2360 // 
       
  2361 // Expected preconditions: Command does not exist
       
  2362 // Expected behaviour: Register command fail
       
  2363 // Cleaning: Not needed
       
  2364 //  
       
  2365 // Register command with category 0
       
  2366 // -----------------------------------------------------------------------------
       
  2367 //
       
  2368 
       
  2369 TInt CMediatorTest::RegisterCommandWithCategoryUID0( TTestResult& aResult )
       
  2370     {
       
  2371     TInt status( KErrNone );
       
  2372     TUid myUid = TUid::Uid( KTestUid );
       
  2373     TUid invalidUid = TUid::Uid(0);
       
  2374     TCapabilitySet caps;
       
  2375     caps.SetEmpty();
       
  2376     
       
  2377     status = iCommandResponder->RegisterCommand( myUid, 
       
  2378                                                  invalidUid, 
       
  2379                                                  KDefaultCommandId, 
       
  2380                                                  iDefaultVersion,
       
  2381                                                  caps, 
       
  2382                                                  KDefaultTimeOut );
       
  2383     
       
  2384     _LIT( KErrorDescription, "RegisterCommand returns with" );
       
  2385     aResult.SetResult( status, KErrorDescription );
       
  2386 
       
  2387     if( KErrNone == status  )
       
  2388         {
       
  2389         status = CleanRegisterCommand( myUid, invalidUid, KDefaultCommandId );
       
  2390         if( KErrNone != status )
       
  2391             {
       
  2392             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2393             aResult.SetResult( status, KDescription );
       
  2394             }
       
  2395         }
       
  2396     else
       
  2397         {
       
  2398         _LIT( KErrorDescription, "Wrong error status" );
       
  2399         aResult.SetResult( status, KErrorDescription );
       
  2400         }
       
  2401     return KErrNone;    
       
  2402     }
       
  2403 
       
  2404 
       
  2405 // -----------------------------------------------------------------------------
       
  2406 // CMediatorTest::RegisterCommandWithCommandID0
       
  2407 // 
       
  2408 // Expected preconditions: Command does not exist
       
  2409 // Expected behaviour: Register command succeed
       
  2410 // Cleaning: Unregister command
       
  2411 //  
       
  2412 // REgister command with command ID 0
       
  2413 // -----------------------------------------------------------------------------
       
  2414 //
       
  2415 
       
  2416 TInt CMediatorTest::RegisterCommandWithCommandID0( TTestResult& aResult )
       
  2417     {
       
  2418     TInt status( KErrNone );
       
  2419     TUid myUid = TUid::Uid( KTestUid );
       
  2420     TCapabilitySet caps;
       
  2421     caps.SetEmpty();
       
  2422 
       
  2423     status = iCommandResponder->RegisterCommand( myUid, 
       
  2424                                                  myUid, 
       
  2425                                                  0, 
       
  2426                                                  iDefaultVersion,
       
  2427                                                  caps, 
       
  2428                                                  KDefaultTimeOut );
       
  2429                                                  
       
  2430     _LIT( KErrorDescription, "RegisterCommand returns with" );
       
  2431     aResult.SetResult( status, KErrorDescription );
       
  2432 
       
  2433     if( KErrNone == status  )
       
  2434         {
       
  2435         status = CleanRegisterCommand( myUid, myUid, 0 );
       
  2436         if( KErrNone != status )
       
  2437             {
       
  2438             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2439             aResult.SetResult( status, KDescription );
       
  2440             }
       
  2441         }
       
  2442     return KErrNone;    
       
  2443     }
       
  2444 
       
  2445 
       
  2446 // -----------------------------------------------------------------------------
       
  2447 // CMediatorTest::RegisterCommandWithTimeoutValue
       
  2448 // 
       
  2449 // Expected preconditions: Command does not exist
       
  2450 // Expected behaviour: Register command succeed
       
  2451 // Cleaning: Unregister command
       
  2452 //  
       
  2453 // Register command with time out 0
       
  2454 // -----------------------------------------------------------------------------
       
  2455 //
       
  2456 
       
  2457 TInt CMediatorTest::RegisterCommandWithTimeoutValue0( TTestResult& aResult )
       
  2458     {
       
  2459     TInt status( KErrNone );
       
  2460     TUid myUid = TUid::Uid( KTestUid );
       
  2461     TCapabilitySet caps;
       
  2462     caps.SetEmpty();
       
  2463 
       
  2464     status = iCommandResponder->RegisterCommand( myUid, 
       
  2465                                                  myUid, 
       
  2466                                                  KSecondaryCommandId, 
       
  2467                                                  iDefaultVersion,
       
  2468                                                  caps, 
       
  2469                                                  0 ); // time out
       
  2470     _LIT( KErrorDescription, "RegisterCommand returns with" );
       
  2471     aResult.SetResult( status, KErrorDescription );
       
  2472 
       
  2473     if( KErrNone == status  )
       
  2474         {
       
  2475         status = CleanRegisterCommand( myUid, myUid, KSecondaryCommandId );
       
  2476         if( KErrNone != status )
       
  2477             {
       
  2478             _LIT( KDescription, "Test passed but cleaning failed" );
       
  2479             aResult.SetResult( status, KDescription );
       
  2480             }
       
  2481         }
       
  2482     return KErrNone;    
       
  2483     }
       
  2484 
       
  2485 
       
  2486 // -----------------------------------------------------------------------------
       
  2487 // CMediatorTest::IssueNonExistingCommandWrongDomain
       
  2488 // 
       
  2489 // Expected preconditions: Command domain does not exist
       
  2490 // Expected behaviour: Issue command fail
       
  2491 // Cleaning: Not needed
       
  2492 //  
       
  2493 // Try to issue command
       
  2494 // Domain not valid
       
  2495 // -----------------------------------------------------------------------------
       
  2496 //
       
  2497 
       
  2498 TInt CMediatorTest::IssueNonExistingCommandWrongDomainL( TTestResult& aResult )
       
  2499     {
       
  2500     TInt status( KErrNone );
       
  2501     TUid myUid = TUid::Uid( KTestUid );
       
  2502     TUid invalidUid = TUid::Uid( KNonExistingDomainId );
       
  2503 
       
  2504     _LIT8(KTest, "TestTestTest");
       
  2505     HBufC8* data = KTest().AllocLC();
       
  2506     
       
  2507     status = iCommandInitiator->IssueCommand( invalidUid, 
       
  2508                                               myUid, 
       
  2509                                               KDefaultCommandId,
       
  2510                                               iDefaultVersion, 
       
  2511                                               *data);
       
  2512     CleanupStack::PopAndDestroy( data );
       
  2513     //expected status is KErrMediatorDomainNotFound
       
  2514     if( KErrMediatorDomainNotFound == status )
       
  2515         {
       
  2516           _LIT( KDescription, "IssueCommand returns with expected KErrMediatorDomainNotFound" );
       
  2517           aResult.SetResult( KErrNone, KDescription );        
       
  2518         }
       
  2519     else
       
  2520         {
       
  2521         _LIT( KErrorDescription, "Wrong error status" );
       
  2522         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  2523         }
       
  2524     CTestScheduler::StartAndStopL( 5000 ); // wait 5s                                                                                    
       
  2525     return KErrNone;
       
  2526     }
       
  2527 
       
  2528 
       
  2529 // -----------------------------------------------------------------------------
       
  2530 // CMediatorTest::IssueNonExistingCommandWrongCat
       
  2531 // 
       
  2532 // Expected preconditions: Command category does not exist
       
  2533 // Expected behaviour: Issue command fail
       
  2534 // Cleaning: Not needed
       
  2535 //  
       
  2536 // Try to issue command
       
  2537 // Category not valid
       
  2538 // -----------------------------------------------------------------------------
       
  2539 //
       
  2540 
       
  2541 TInt CMediatorTest::IssueNonExistingCommandWrongCatL( TTestResult& aResult )
       
  2542     {
       
  2543     TInt status( KErrNone );
       
  2544     TUid myUid = TUid::Uid( KTestUid );
       
  2545     TUid invalidUid = TUid::Uid( KNonExistingCategoryId );
       
  2546 
       
  2547     _LIT8(KTest, "TestTestTest");
       
  2548     HBufC8* data = KTest().AllocLC();
       
  2549     
       
  2550     status = iCommandInitiator->IssueCommand( myUid, 
       
  2551                                               invalidUid, 
       
  2552                                               KDefaultCommandId,
       
  2553                                               iDefaultVersion, 
       
  2554                                               *data);
       
  2555     CleanupStack::PopAndDestroy( data );
       
  2556     //expected status is KErrMediatorCategoryNotFound
       
  2557     if( KErrMediatorCategoryNotFound == status )
       
  2558     {
       
  2559       _LIT( KDescription, "IssueCommand returns with expected KErrMediatorCategoryNotFound" );
       
  2560         aResult.SetResult( KErrNone, KDescription );        
       
  2561     }
       
  2562     else
       
  2563     {
       
  2564         _LIT( KErrorDescription, "Wrong error status" );
       
  2565         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  2566     }
       
  2567     CTestScheduler::StartAndStopL( 2000 ); // wait 2s                                                                                    
       
  2568     return KErrNone;
       
  2569     }
       
  2570 
       
  2571 // -----------------------------------------------------------------------------
       
  2572 // CMediatorTest::IssueNonExistingCommandId
       
  2573 // 
       
  2574 // Expected preconditions: Register a command and issue a command with invalid command id
       
  2575 // Expected behaviour: Issue command fail
       
  2576 // Cleaning: Unregister command
       
  2577 //  
       
  2578 // Try to issue command
       
  2579 // Command ID not valid
       
  2580 // -----------------------------------------------------------------------------
       
  2581 //
       
  2582 
       
  2583 TInt CMediatorTest::IssueNonExistingCommandIdL( TTestResult& aResult )
       
  2584     {
       
  2585     TInt status( KErrNone );
       
  2586     TUid myUid = TUid::Uid( KTestUid );
       
  2587     TCapabilitySet caps;
       
  2588     caps.SetEmpty();
       
  2589     
       
  2590     _LIT8(KTest, "TestTestTest");
       
  2591     HBufC8* data = KTest().AllocLC();
       
  2592     
       
  2593     status = PreconditionRegisterCommand( myUid, 
       
  2594                                           myUid, 
       
  2595                                           KDefaultCommandId,
       
  2596                                           iDefaultVersion,
       
  2597                                           caps,
       
  2598                                           KDefaultTimeOut );
       
  2599         
       
  2600     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  2601     aResult.SetResult( status, KErrorDescription );   
       
  2602     if( KErrNone == status  )
       
  2603         {
       
  2604         status = iCommandInitiator->IssueCommand( myUid, 
       
  2605                                                   myUid, 
       
  2606                                                   KInvalidCommandId,//command does not exist
       
  2607                                                   iDefaultVersion, 
       
  2608                                                   *data );
       
  2609         
       
  2610         //expected status is KErrMediatorCommandNotFound                                        
       
  2611         if( KErrMediatorCommandNotFound == status )
       
  2612             {
       
  2613             _LIT( KDescription, "IssueCommand returns with expected KErrMediatorCommandNotFound" );
       
  2614             aResult.SetResult( KErrNone, KDescription );
       
  2615             status = CleanRegisterCommand( myUid, 
       
  2616                                            myUid, 
       
  2617                                            KDefaultCommandId );
       
  2618             if( KErrNone != status )
       
  2619                 {
       
  2620                 _LIT( KDescription, "Test Passed but cleaning failed" );
       
  2621                 aResult.SetResult( status, KDescription );
       
  2622                 }
       
  2623             }
       
  2624         else
       
  2625             {
       
  2626             _LIT( KErrorDescription, "Wrong error status" );
       
  2627             aResult.SetResult( status, KErrorDescription );
       
  2628             }
       
  2629         }
       
  2630     CleanupStack::PopAndDestroy( data );
       
  2631     CTestScheduler::StartAndStopL( 2000 ); // wait 3s 
       
  2632     return KErrNone;
       
  2633     }
       
  2634 
       
  2635 // -----------------------------------------------------------------------------
       
  2636 // CMediatorTest::IssueCommandWrongCommandVerMajor
       
  2637 // 
       
  2638 // Expected preconditions: Command version does not exist
       
  2639 // Expected behaviour: Issue command fail
       
  2640 // Cleaning: Unregister command
       
  2641 //  
       
  2642 // Try to issue command
       
  2643 // Wrong version
       
  2644 // -----------------------------------------------------------------------------
       
  2645 //
       
  2646 
       
  2647 TInt CMediatorTest::IssueCommandWrongCommandVerMajorL( TTestResult& aResult )
       
  2648     {
       
  2649     TInt status( KErrNone );
       
  2650     TUid myUid = TUid::Uid( KTestUid );
       
  2651     TVersion version( 666,5,5);
       
  2652     TCapabilitySet caps;
       
  2653     caps.SetEmpty();
       
  2654         
       
  2655     _LIT8(KTest, "TestTestTest");
       
  2656     HBufC8* data = KTest().AllocLC();
       
  2657     
       
  2658     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  2659                                                   myUid, 
       
  2660                                                   KDefaultCommandId,
       
  2661                                                   iDefaultVersion,
       
  2662                                                   caps,
       
  2663                                                   1000 );
       
  2664     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  2665     aResult.SetResult( preStatus, KErrorDescription );    
       
  2666     if( KErrNone == preStatus )
       
  2667         {
       
  2668         status = iCommandInitiator->IssueCommand( myUid, 
       
  2669                                                   myUid, 
       
  2670                                                   KDefaultCommandId,
       
  2671                                                   version, 
       
  2672                                                   *data );
       
  2673       
       
  2674         CTestScheduler::StartAndStopL(2000); // wait 2s
       
  2675         //expected status is KErrMediatorVersionMismatch
       
  2676         if( KErrMediatorVersionMismatch == status )
       
  2677             {
       
  2678             _LIT( KDescription, "IssueCommand returns with expected KErrMediatorVersionMismatch" );
       
  2679             aResult.SetResult( KErrNone, KDescription );
       
  2680             status = CleanRegisterCommand( myUid, 
       
  2681                                            myUid, 
       
  2682                                            KDefaultCommandId );
       
  2683             if( KErrNone != status )
       
  2684                 {
       
  2685                 _LIT( KDescription, "Test Passed but cleaning failed" );
       
  2686                 aResult.SetResult( status, KDescription );        
       
  2687                 }
       
  2688             }
       
  2689         else
       
  2690             {
       
  2691             _LIT( KErrorDescription, "Wrong error status" );
       
  2692             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  2693             }
       
  2694         }
       
  2695     CleanupStack::PopAndDestroy( data ); 
       
  2696     return KErrNone;
       
  2697     }
       
  2698 
       
  2699 TInt CMediatorTest::PreconditionRegisterCommand( TUid aDomain, 
       
  2700                                                  TUid aCategory, 
       
  2701                                                  TInt aCommandId, 
       
  2702                                                  TVersion aVersion,
       
  2703                                                  TCapabilitySet aCaps, 
       
  2704                                                  TInt aTimeOut )
       
  2705     {
       
  2706     TInt status = iCommandResponder->RegisterCommand( aDomain, 
       
  2707                                                       aCategory, 
       
  2708                                                       aCommandId, 
       
  2709                                                       aVersion,
       
  2710                                                       aCaps, 
       
  2711                                                       aTimeOut );
       
  2712     CTestScheduler::StartAndStopL(1000); // wait 1s  
       
  2713     return status;  
       
  2714     }
       
  2715 
       
  2716 TInt CMediatorTest::PreconditionRegisterCommands( TUid aDomain,
       
  2717                                                   TUid aCategory, 
       
  2718                                                   RCommandList aCommands )
       
  2719     {
       
  2720     TInt status = iCommandResponder->RegisterCommand( aDomain, 
       
  2721                                                       aCategory, 
       
  2722                                                       aCommands );
       
  2723     CTestScheduler::StartAndStopL(1000); // wait 1s
       
  2724     return status;  
       
  2725     }
       
  2726 
       
  2727 
       
  2728 // -----------------------------------------------------------------------------
       
  2729 // CMediatorTest::IssueCommand
       
  2730 //
       
  2731 // Issue command
       
  2732 // -----------------------------------------------------------------------------
       
  2733 //
       
  2734 
       
  2735 TInt CMediatorTest::IssueCommandL( TTestResult& aResult )
       
  2736     {
       
  2737     TInt status( KErrNone );
       
  2738     TUid myUid = TUid::Uid( KTestUid );
       
  2739     TCapabilitySet caps;
       
  2740     caps.SetEmpty();
       
  2741         
       
  2742     _LIT8(KTest, "TestTestTest");
       
  2743     HBufC8* data = KTest().AllocLC();
       
  2744     
       
  2745     iTestHelper->ClearAllNotifyData( );
       
  2746 
       
  2747     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  2748                                                   myUid, 
       
  2749                                                   KDefaultCommandId,
       
  2750                                                   iDefaultVersion,
       
  2751                                                   caps,
       
  2752                                                   KDefaultTimeOut );
       
  2753     
       
  2754     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  2755     aResult.SetResult( preStatus, KErrorDescription );    
       
  2756     
       
  2757     if( KErrNone == preStatus  )
       
  2758         {
       
  2759         status = iCommandInitiator->IssueCommand( myUid, 
       
  2760                                                   myUid, 
       
  2761                                                   KDefaultCommandId,
       
  2762                                                   iDefaultVersion, 
       
  2763                                                   *data );
       
  2764         CTestScheduler::StartAndStopL(2000); // wait 2s
       
  2765          
       
  2766         
       
  2767         _LIT( KDescription, "IssueCommand returns with" );
       
  2768         aResult.SetResult( status, KDescription );    
       
  2769         
       
  2770         if( KErrNone == status  )
       
  2771             {
       
  2772             _LIT8(KTestR, "Command response here");
       
  2773             HBufC8* replyData = KTestR().AllocLC();
       
  2774             status = iCommandResponder->IssueResponse( iTestHelper->iDomain, 
       
  2775                                                        iTestHelper->iCategory, 
       
  2776                                                        iTestHelper->iCommandId, 
       
  2777                                                        KErrNone,
       
  2778                                                        *replyData );                                      
       
  2779             if( KErrNone == status  )
       
  2780                 {
       
  2781                 status = CleanRegisterCommand( myUid, 
       
  2782                                                myUid, 
       
  2783                                                KDefaultCommandId );
       
  2784                 if( KErrNone != status )
       
  2785                     {
       
  2786                     _LIT( KDescription, "Test Passed but cleaning failed" );
       
  2787                     aResult.SetResult( status, KDescription );        
       
  2788                     }
       
  2789                 }
       
  2790             _LIT( KErrorDescription, "IssueResponse returns with" );
       
  2791             aResult.SetResult( status, KErrorDescription );
       
  2792             CleanupStack::PopAndDestroy( replyData );
       
  2793             }
       
  2794         }
       
  2795     CleanupStack::PopAndDestroy( data );
       
  2796     return KErrNone;
       
  2797     }
       
  2798 
       
  2799 // -----------------------------------------------------------------------------
       
  2800 // CMediatorTest::IssueCommand2
       
  2801 //
       
  2802 // Issue command from here. 
       
  2803 // Command receiver implemented in plugin. Reply is expected
       
  2804 // -----------------------------------------------------------------------------
       
  2805 //
       
  2806 TInt CMediatorTest::IssueCommand2L( TTestResult& aResult )
       
  2807     {
       
  2808     TInt status( KErrNone );
       
  2809     TUid myUid = TUid::Uid(0x999101);
       
  2810     TVersion version( 1,0,0);
       
  2811     
       
  2812     _LIT8(KTest, "TestTestTest");
       
  2813     HBufC8* data = KTest().AllocLC();
       
  2814     
       
  2815     CMediatorCommandInitiator *commandInitiator = CMediatorCommandInitiator::NewL( iTestHelper );
       
  2816     CleanupStack::PushL( commandInitiator );
       
  2817     TInt invalidCmd = 1;
       
  2818     commandInitiator->CancelCommand( myUid,
       
  2819                                      myUid, 
       
  2820                                      invalidCmd );
       
  2821     
       
  2822     status = commandInitiator->IssueCommand( myUid, 
       
  2823                                             myUid, 
       
  2824                                             invalidCmd,
       
  2825                                             version, 
       
  2826                                             *data );
       
  2827     
       
  2828     CTestScheduler::StartAndStopL(2000); // wait 2s
       
  2829         
       
  2830     // Check that reply was received
       
  2831     if( ( iTestHelper->iNotificationReceived == ECommandResponse ) && ( KErrNone == status  ) )
       
  2832         {
       
  2833         _LIT( KDescription, "IssueCommand gets notification" );
       
  2834         aResult.SetResult( status, KDescription );      
       
  2835         }
       
  2836     else
       
  2837         {
       
  2838         _LIT( KErrorDescription, "Error" );
       
  2839         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  2840         }
       
  2841     iTestHelper->ClearAllNotifyData( );
       
  2842     commandInitiator->CancelCommand( myUid,
       
  2843                                      myUid, 
       
  2844                                      invalidCmd );
       
  2845     
       
  2846     CleanupStack::PopAndDestroy( commandInitiator );
       
  2847     CleanupStack::PopAndDestroy( data );
       
  2848     return KErrNone;
       
  2849     }
       
  2850 
       
  2851 // -----------------------------------------------------------------------------
       
  2852 // CMediatorTest::IssueExistingCommandSameInitiatorWhileProcessing
       
  2853 // Issue command twice with same command initiator
       
  2854 // Expected preconditions: None
       
  2855 // Expected behaviour: KErrInUse
       
  2856 // Cleaning: Unregister command
       
  2857 // -----------------------------------------------------------------------------
       
  2858 
       
  2859 
       
  2860 TInt CMediatorTest::IssueExistingCommandSameInitiatorWhileProcessingL( TTestResult& aResult )
       
  2861     {
       
  2862     TInt status( KErrNone );
       
  2863     TUid myUid = TUid::Uid( KTestUid );
       
  2864     TCapabilitySet caps;
       
  2865     caps.SetEmpty();
       
  2866         
       
  2867     iTestHelper->ClearAllNotifyData();
       
  2868     
       
  2869     _LIT8(KTest, "TestTestTest");
       
  2870     HBufC8* data = KTest().AllocLC();
       
  2871  
       
  2872     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  2873                                                   myUid, 
       
  2874                                                   KMinListId,
       
  2875                                                   iDefaultVersion,
       
  2876                                                   caps,
       
  2877                                                   5000 );
       
  2878     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  2879     aResult.SetResult( preStatus, KErrorDescription );    
       
  2880     if( KErrNone == preStatus )
       
  2881         {    
       
  2882         status = iCommandInitiator->IssueCommand( myUid, 
       
  2883                                                   myUid, 
       
  2884                                                   KMinListId,
       
  2885                                                   iDefaultVersion, 
       
  2886                                                   *data );
       
  2887         CTestScheduler::StartAndStopL( 2000 ); // wait 2s
       
  2888         if( KErrNone == status  )
       
  2889             {
       
  2890             status = iCommandInitiator->IssueCommand( myUid, 
       
  2891                                                       myUid, 
       
  2892                                                       KMinListId,
       
  2893                                                       iDefaultVersion, 
       
  2894                                                       *data );
       
  2895        
       
  2896             if ( KErrInUse == status )
       
  2897                 {
       
  2898                 _LIT( KErrorDescription, "IssueCommand returns with expected KErrInUse " );
       
  2899                 aResult.SetResult( KErrNone, KErrorDescription );
       
  2900                 status = CleanRegisterCommand( myUid, 
       
  2901                                                myUid, 
       
  2902                                                KMinListId );
       
  2903                 CTestScheduler::StartAndStopL( 2000 );
       
  2904                 if( KErrNone != status )
       
  2905                     {
       
  2906                     _LIT( KDescription, "Test code passed but cleaning failed" );
       
  2907                     aResult.SetResult( status, KDescription );        
       
  2908                     }       
       
  2909                 }   
       
  2910             else
       
  2911                 {
       
  2912                 _LIT( KErrorDescription, "IssueCommand returns with" );
       
  2913                 aResult.SetResult( status, KErrorDescription );
       
  2914                 }
       
  2915             }
       
  2916         }
       
  2917     CleanupStack::PopAndDestroy( data );
       
  2918     return KErrNone;
       
  2919     }
       
  2920 
       
  2921 // -----------------------------------------------------------------------------
       
  2922 // CMediatorTest::IssueCommandWaitWithoutRespondingToCommand
       
  2923 // Issue command and wait for some time and check the notification
       
  2924 // Expected preconditions: None
       
  2925 // Expected behaviour: 
       
  2926 // Cleaning: Unregister command
       
  2927 // -----------------------------------------------------------------------------
       
  2928 //
       
  2929 
       
  2930 TInt CMediatorTest::IssueCommandWaitWithoutRespondingToCommandL( TTestResult& aResult )
       
  2931     {
       
  2932     TInt status( KErrNone );
       
  2933     TUid myUid = TUid::Uid( KTestUid );
       
  2934     
       
  2935     _LIT8(KTest, "TestTestTest");
       
  2936     HBufC8* data = KTest().AllocLC();
       
  2937     TCapabilitySet caps;
       
  2938     caps.SetEmpty();
       
  2939         
       
  2940     iTestHelper->ClearAllNotifyData();
       
  2941     
       
  2942     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  2943                                                   myUid, 
       
  2944                                                   KMinListId+1,
       
  2945                                                   iDefaultVersion,
       
  2946                                                   caps,
       
  2947                                                   5000 );
       
  2948     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  2949     aResult.SetResult( preStatus, KErrorDescription );    
       
  2950     if( KErrNone == preStatus )
       
  2951         {    
       
  2952         status = iCommandInitiator->IssueCommand( myUid, 
       
  2953                                                   myUid, 
       
  2954                                                   KMinListId+1,
       
  2955                                                   iDefaultVersion, 
       
  2956                                                   *data );
       
  2957            
       
  2958         CTestScheduler::StartAndStopL(2000); // wait 2s
       
  2959         _LIT( KErrorDescription, "IssueCommand returns with" );
       
  2960         aResult.SetResult( status, KErrorDescription );
       
  2961         /* Check that notify was received, only when RaiseEvent returns KErrNone*/
       
  2962         if( ( KErrNone == status  )
       
  2963             &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  2964                     || ( iTestHelper->iDomain != myUid )
       
  2965                     || ( iTestHelper->iCategory != myUid )
       
  2966                     || ( iTestHelper->iCommandId != KMinListId+1 ) ) )
       
  2967             {
       
  2968             status = KErrNotFound; 
       
  2969             _LIT( KDescription, "iTestHelper checks failed" );
       
  2970             aResult.SetResult( status, KDescription );  
       
  2971             }
       
  2972         //clean the registered command
       
  2973         else if ( KErrNone == status  )
       
  2974             {
       
  2975             status = CleanRegisterCommand( myUid, 
       
  2976                                            myUid, 
       
  2977                                            KMinListId+1 );
       
  2978             if( KErrNone != status )
       
  2979                 {
       
  2980                 _LIT( KErrorDescription, "Test passed but cleaning command failed" );
       
  2981                 aResult.SetResult( status, KErrorDescription );
       
  2982                 }   
       
  2983             }   
       
  2984         }
       
  2985     CleanupStack::PopAndDestroy( data );
       
  2986     return KErrNone;
       
  2987 }
       
  2988 
       
  2989 
       
  2990 // -----------------------------------------------------------------------------
       
  2991 // CMediatorTest::IssueCommandCancelFromInitiatorBeforeTimeout
       
  2992 // Issue command and cancel it before timeout.
       
  2993 // Expected preconditions: register command with specific time
       
  2994 // Cleaning: Unregister command
       
  2995 // -----------------------------------------------------------------------------
       
  2996 //
       
  2997 
       
  2998 TInt CMediatorTest::IssueCommandCancelFromInitiatorBeforeTimeoutL( TTestResult& aResult )
       
  2999     {
       
  3000     TInt status( KErrNone );
       
  3001     TUid myUid = TUid::Uid( KTestUid );
       
  3002     iTestHelper->ClearAllNotifyData();
       
  3003     _LIT8(KTest, "TestTestTest");
       
  3004     HBufC8* data = KTest().AllocLC();
       
  3005     TCapabilitySet caps;
       
  3006     caps.SetEmpty();
       
  3007     
       
  3008     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  3009                                                   myUid, 
       
  3010                                                   KMinListId+2,
       
  3011                                                   iDefaultVersion,
       
  3012                                                   caps,
       
  3013                                                   5000 );
       
  3014     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  3015     aResult.SetResult( preStatus, KErrorDescription );    
       
  3016     if( KErrNone == preStatus )
       
  3017         {    
       
  3018         status = iCommandInitiator->IssueCommand( myUid, 
       
  3019                                                   myUid, 
       
  3020                                                   KMinListId+2,
       
  3021                                                   iDefaultVersion, 
       
  3022                                                   *data );
       
  3023         _LIT( KErrorDescription, "IssueCommand returns with" );
       
  3024         aResult.SetResult( status, KErrorDescription );
       
  3025         if( KErrNone == status  )
       
  3026             {
       
  3027             iCommandInitiator->CancelCommand( myUid, 
       
  3028                                               myUid, 
       
  3029                                               KMinListId+2 );
       
  3030         
       
  3031             CTestScheduler::StartAndStopL( 2000 ); // wait 2s
       
  3032         
       
  3033             status = CleanRegisterCommand(myUid, 
       
  3034                                     myUid, 
       
  3035                                     KMinListId+2);
       
  3036       
       
  3037             if( KErrNone != status )
       
  3038                 {
       
  3039                 _LIT( KDescription, "Test passed but cleaning failed" );
       
  3040                 aResult.SetResult( status, KDescription );        
       
  3041                 }
       
  3042             }
       
  3043         }
       
  3044     CleanupStack::PopAndDestroy( data );
       
  3045     return KErrNone;
       
  3046     }
       
  3047 
       
  3048 
       
  3049 // -----------------------------------------------------------------------------
       
  3050 // CMediatorTest::IssueCommandRespondCorrectlyFromResponder
       
  3051 // Issue command, get the correct reposonse from command responder
       
  3052 // Cleaning: Unregister command
       
  3053 // -----------------------------------------------------------------------------
       
  3054 //
       
  3055 
       
  3056 TInt CMediatorTest::IssueCommandRespondCorrectlyFromResponderL( TTestResult& aResult )
       
  3057     {
       
  3058     TInt status( KErrNone );
       
  3059     TUid myUid = TUid::Uid( KTestUid );
       
  3060     iTestHelper->ClearAllNotifyData();
       
  3061     _LIT8(KTest, "TestTestTest");
       
  3062     HBufC8* data = KTest().AllocLC();
       
  3063     TCapabilitySet caps;
       
  3064     caps.SetEmpty();
       
  3065     
       
  3066     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  3067                                                   myUid, 
       
  3068                                                   KDefaultCommandId,
       
  3069                                                   iDefaultVersion,
       
  3070                                                   caps,
       
  3071                                                   5000 );
       
  3072                                                   
       
  3073     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  3074     aResult.SetResult( preStatus, KErrorDescription );
       
  3075         
       
  3076     if( KErrNone == preStatus )
       
  3077         {    
       
  3078     
       
  3079         status = iCommandInitiator->IssueCommand( myUid, 
       
  3080                                                   myUid, 
       
  3081                                                   KDefaultCommandId,
       
  3082                                                   iDefaultVersion, 
       
  3083                                                   *data );
       
  3084         
       
  3085         CTestScheduler::StartAndStopL(1000);
       
  3086         _LIT( KDescription, "IssueCommand returns with" );
       
  3087         aResult.SetResult( status, KDescription );
       
  3088         if( KErrNone == status  )
       
  3089             {
       
  3090             _LIT8(KTestR, "Command response here");
       
  3091             HBufC8* replyData = KTestR().AllocLC();
       
  3092             status = iCommandResponder->IssueResponse( iTestHelper->iDomain, 
       
  3093                                                        iTestHelper->iCategory, 
       
  3094                                                        iTestHelper->iCommandId, 
       
  3095                                                        KErrNone,
       
  3096                                                        *replyData );                                      
       
  3097             CleanupStack::PopAndDestroy( replyData );      
       
  3098         
       
  3099             _LIT( KErrorDescription, "IssueResponse returns with" );
       
  3100             aResult.SetResult( status, KErrorDescription );
       
  3101         
       
  3102             status = CleanRegisterCommand( myUid, 
       
  3103                                            myUid, 
       
  3104                                            KDefaultCommandId );
       
  3105             CTestScheduler::StartAndStopL(1000); // wait 1s
       
  3106             if( KErrNone != status )
       
  3107                 {
       
  3108                 _LIT( KDescription, "Test passed but cleaning failed" );
       
  3109                 aResult.SetResult( status, KDescription );        
       
  3110                 }                   
       
  3111             }
       
  3112         }
       
  3113     CleanupStack::PopAndDestroy( data );
       
  3114     return KErrNone;
       
  3115     }
       
  3116 
       
  3117 
       
  3118 // -----------------------------------------------------------------------------
       
  3119 // CMediatorTest::IssueCommandRespondIncorrectlyFromResponderL
       
  3120 // Issue command and get the wrong reposonse from command responder
       
  3121 // Expected preconditions: IssueResponse with wrong category id
       
  3122 // Expected behaviour: KErrMediatorCommandNotFound
       
  3123 // Cleaning: Unregister command
       
  3124 // -----------------------------------------------------------------------------
       
  3125 
       
  3126 
       
  3127 TInt CMediatorTest::IssueCommandRespondIncorrectlyFromResponderL( TTestResult& aResult )
       
  3128     {
       
  3129     TInt status( KErrNone );
       
  3130     TUid myUid = TUid::Uid( KTestUid );
       
  3131     TUid invalidUid = TUid::Uid(KNonExistingCategoryId);
       
  3132 
       
  3133     _LIT8(KTest, "TestTestTest");
       
  3134     HBufC8* data = KTest().AllocLC();
       
  3135     TCapabilitySet caps;
       
  3136     caps.SetEmpty();
       
  3137     
       
  3138     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  3139                                                   myUid, 
       
  3140                                                   KDefaultCommandId,
       
  3141                                                   iDefaultVersion,
       
  3142                                                   caps,
       
  3143                                                   5000 );
       
  3144                                                   
       
  3145     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  3146     aResult.SetResult( preStatus, KErrorDescription );
       
  3147         
       
  3148     if( KErrNone == preStatus )
       
  3149         {    
       
  3150         status = iCommandInitiator->IssueCommand( myUid, 
       
  3151                                                   myUid, 
       
  3152                                                   KDefaultCommandId,
       
  3153                                                   iDefaultVersion, 
       
  3154                                                   *data );
       
  3155                 
       
  3156         CTestScheduler::StartAndStopL(1000); // wait 1s
       
  3157         _LIT( KDescription, "IssueCommand returns with" );
       
  3158         aResult.SetResult( status, KDescription );
       
  3159         if( KErrNone == status  )
       
  3160             {
       
  3161             _LIT8(KTestR, "Command response here");
       
  3162             HBufC8* replyData = KTestR().AllocLC();
       
  3163             status = iCommandResponder->IssueResponse( iTestHelper->iDomain, 
       
  3164                                                        invalidUid,  // This is is incorrect value in reply
       
  3165                                                        iTestHelper->iCommandId, 
       
  3166                                                        KErrNone,
       
  3167                                                        *replyData );                                      
       
  3168             CleanupStack::PopAndDestroy( replyData );      
       
  3169                               
       
  3170             if( KErrMediatorCommandNotFound != status  )
       
  3171                 {
       
  3172                 _LIT( KErrorDescription, "Wrong error code" );
       
  3173                 aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  3174                 }
       
  3175             else
       
  3176                 {
       
  3177                 _LIT( KErrorDescription, "IssueResponse returns with" );
       
  3178                 aResult.SetResult( KErrNone, KDescription );   
       
  3179                 status = CleanRegisterCommand( myUid, 
       
  3180                                                myUid, 
       
  3181                                                KDefaultCommandId );
       
  3182                 CTestScheduler::StartAndStopL(1000); // wait 1s
       
  3183                 if( KErrNone != status )
       
  3184                     {
       
  3185                     _LIT( KDescription, "Test passed but cleaning failed" );
       
  3186                     aResult.SetResult( status, KDescription );        
       
  3187                     }
       
  3188                 }
       
  3189             }
       
  3190         }
       
  3191     CleanupStack::PopAndDestroy( data );
       
  3192     return KErrNone;
       
  3193     }
       
  3194 
       
  3195 // -----------------------------------------------------------------------------
       
  3196 // CMediatorTest::IssueCommandALotOfParameterData
       
  3197 // Issue command with big amount of data
       
  3198 // Expected preconditions: IssueCommand with big data buffer
       
  3199 // Expected behaviour: IssueCommand returns with KErrNone
       
  3200 // Cleaning: Unregister command
       
  3201 // -----------------------------------------------------------------------------
       
  3202 //
       
  3203 
       
  3204 TInt CMediatorTest::IssueCommandALotOfParameterDataL( TTestResult& aResult )
       
  3205     {
       
  3206     TInt status( KErrNone );
       
  3207     TUid myUid = TUid::Uid( KTestUid );
       
  3208     
       
  3209     HBufC8* data = HBufC8::NewLC( KDataSize );
       
  3210     TPtr8 dataPtr = data->Des();
       
  3211     for( TInt i = 0; i < KDataSize; i++ )
       
  3212         {
       
  3213         TChar tmpChar( 64 );
       
  3214         dataPtr.Append( tmpChar );
       
  3215         }
       
  3216 
       
  3217     TCapabilitySet caps;
       
  3218     caps.SetEmpty();
       
  3219     
       
  3220     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  3221                                                   myUid, 
       
  3222                                                   KDefaultCommandId,
       
  3223                                                   iDefaultVersion,
       
  3224                                                   caps,
       
  3225                                                   5000 );
       
  3226                                                   
       
  3227     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  3228     aResult.SetResult( preStatus, KErrorDescription );
       
  3229         
       
  3230     if( KErrNone == preStatus )
       
  3231         {    
       
  3232     
       
  3233         status = iCommandInitiator->IssueCommand( myUid, 
       
  3234                                                   myUid, 
       
  3235                                                   KDefaultCommandId,
       
  3236                                                   iDefaultVersion, 
       
  3237                                                   *data );
       
  3238         
       
  3239         CTestScheduler::StartAndStopL(2000); // wait 2s
       
  3240         _LIT( KErrorDescription, "IssueCommand returns with" );
       
  3241         aResult.SetResult( status, KErrorDescription );
       
  3242         /* Check that notify was received, */
       
  3243         if( ( KErrNone == status  )
       
  3244             &&( ( iTestHelper->iNotificationReceived == 0 ) 
       
  3245                     || ( iTestHelper->iDomain != myUid )
       
  3246                     || ( iTestHelper->iCategory != myUid )
       
  3247                     || ( iTestHelper->iCommandId != KDefaultCommandId ) ) )
       
  3248             {
       
  3249             status = KErrNotFound; 
       
  3250             _LIT( KDescription, "iTestHelper checks failed" );
       
  3251             aResult.SetResult( status, KDescription );  
       
  3252             }
       
  3253         //clean the registered command
       
  3254         else if ( KErrNone == status  )
       
  3255             {
       
  3256             status = CleanRegisterCommand( myUid, 
       
  3257                                            myUid, 
       
  3258                                            KDefaultCommandId );
       
  3259             if( KErrNone != status )
       
  3260                 {
       
  3261                 _LIT( KErrorDescription, "Test passed but cleaning command failed" );
       
  3262                 aResult.SetResult( status, KErrorDescription );
       
  3263                 }   
       
  3264             } 
       
  3265         }
       
  3266     CleanupStack::PopAndDestroy( data  );
       
  3267     return KErrNone;
       
  3268     }
       
  3269 
       
  3270 
       
  3271 // -----------------------------------------------------------------------------
       
  3272 // CMediatorTest::IssueCommandRespondALotOfResponseData
       
  3273 // IssueResponse with big amount of data
       
  3274 // Expected preconditions: IssueResponse with big data buffer
       
  3275 // Expected behaviour: IssueResponse returns with KErrNone
       
  3276 // Cleaning: Unregister command
       
  3277 // -----------------------------------------------------------------------------
       
  3278 //
       
  3279 
       
  3280 TInt CMediatorTest::IssueCommandRespondALotOfResponseDataL( TTestResult& aResult )
       
  3281 {
       
  3282     TInt status( KErrNone );
       
  3283     TUid myUid = TUid::Uid( KTestUid );
       
  3284 
       
  3285     _LIT8(KTest, "Replywithalotofdata");
       
  3286     HBufC8* data = KTest().AllocLC();
       
  3287     TCapabilitySet caps;
       
  3288     caps.SetEmpty();
       
  3289     
       
  3290     iTestHelper->ClearAllNotifyData();
       
  3291     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  3292                                                   myUid, 
       
  3293                                                   KDefaultCommandId,
       
  3294                                                   iDefaultVersion,
       
  3295                                                   caps,
       
  3296                                                   5000 );
       
  3297                                                   
       
  3298     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  3299     aResult.SetResult( preStatus, KErrorDescription );
       
  3300         
       
  3301     if( KErrNone == preStatus )
       
  3302         {        
       
  3303         status = iCommandInitiator->IssueCommand( myUid, 
       
  3304                                                   myUid, 
       
  3305                                                   KDefaultCommandId,
       
  3306                                                   iDefaultVersion, 
       
  3307                                                   *data );
       
  3308         CTestScheduler::StartAndStopL( 2000 );
       
  3309         _LIT( KDescription, "IssueCommand returns with" );
       
  3310         aResult.SetResult( status, KDescription );
       
  3311         HBufC8* rData = HBufC8::NewLC( KDataSize );
       
  3312         TPtr8 dataPtr = rData->Des();
       
  3313         for( TInt i = 0; i < KDataSize; i++ )
       
  3314             {
       
  3315             TChar tmpChar(64);
       
  3316             dataPtr.Append( tmpChar );
       
  3317             }
       
  3318         
       
  3319         status = iCommandResponder->IssueResponse( iTestHelper->iDomain, 
       
  3320                                                    iTestHelper->iCategory, 
       
  3321                                                    iTestHelper->iCommandId, 
       
  3322                                                    KErrNone,
       
  3323                                                    *rData );    
       
  3324         CleanupStack::PopAndDestroy( rData );      
       
  3325                       
       
  3326         if( KErrNone != status )
       
  3327             {
       
  3328             _LIT( KErrorDescription, "Wrong error code" );
       
  3329             aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  3330             }
       
  3331         else
       
  3332             {
       
  3333             _LIT( KErrorDescription, "IssueResponse returns with" );
       
  3334             aResult.SetResult( KErrNone, KDescription );   
       
  3335             status = CleanRegisterCommand( myUid, 
       
  3336                                            myUid, 
       
  3337                                            KDefaultCommandId );
       
  3338             CTestScheduler::StartAndStopL(1000); // wait 1s
       
  3339             if( KErrNone != status )
       
  3340                 {
       
  3341                 _LIT( KDescription, "Test passed but cleaning failed" );
       
  3342                 aResult.SetResult( status, KDescription );        
       
  3343                 }
       
  3344             }
       
  3345         }
       
  3346     CleanupStack::PopAndDestroy( data );
       
  3347     return KErrNone;
       
  3348     }
       
  3349 
       
  3350 // -----------------------------------------------------------------------------
       
  3351 // CMediatorTest::GetListOfDomainsNoDomains
       
  3352 //
       
  3353 // Get list of domains
       
  3354 // Expected: 0 domains
       
  3355 // -----------------------------------------------------------------------------
       
  3356 //
       
  3357 
       
  3358 TInt CMediatorTest::GetListOfDomainsNoDomainsL( TTestResult& aResult )
       
  3359     {
       
  3360     // There shall not be any domains when executing this test
       
  3361     RDomainList domainList;
       
  3362     CleanupClosePushL( domainList );
       
  3363     TInt status = iNotifications->GetDomains( domainList );
       
  3364     
       
  3365     if( KErrNone == status  )
       
  3366         {
       
  3367         if( domainList.Count() == 0 )
       
  3368             {
       
  3369             _LIT( KErrorDescription, "GetDomains returns with" );
       
  3370             aResult.SetResult( status, KErrorDescription );           
       
  3371             }
       
  3372         else
       
  3373             {
       
  3374             _LIT( KErrorDescription, "Registered domains found" );
       
  3375             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3376             }
       
  3377         }
       
  3378     else
       
  3379         {
       
  3380         _LIT( KErrorDescription, "GetDomains returns with" );
       
  3381         aResult.SetResult( status, KErrorDescription );        
       
  3382         }
       
  3383     CleanupStack::PopAndDestroy( &domainList );
       
  3384     return KErrNone;
       
  3385     }
       
  3386 
       
  3387 // -----------------------------------------------------------------------------
       
  3388 // CMediatorTest::GetListOfDomainsInit
       
  3389 //
       
  3390 // Get list of domains
       
  3391 // Expected: Unknown count of domains
       
  3392 // -----------------------------------------------------------------------------
       
  3393 //
       
  3394 
       
  3395 TInt CMediatorTest::GetListOfDomainsInitL( TTestResult& aResult )
       
  3396     {
       
  3397     RDomainList domainList;
       
  3398     CleanupClosePushL( domainList );
       
  3399     TInt status = iNotifications->GetDomains( domainList );
       
  3400     
       
  3401     if( KErrNone == status  )
       
  3402         {
       
  3403         initCountOfDomain = domainList.Count();
       
  3404         _LIT( KErrorDescription, "GetDomains returns with" );
       
  3405         aResult.SetResult( status, KErrorDescription );
       
  3406         }
       
  3407     else
       
  3408         {
       
  3409         _LIT( KErrorDescription, "GetDomains returns with" );
       
  3410         aResult.SetResult( status, KErrorDescription );        
       
  3411         }
       
  3412     CleanupStack::PopAndDestroy( &domainList );
       
  3413     return KErrNone;
       
  3414     }
       
  3415 
       
  3416 // -----------------------------------------------------------------------------
       
  3417 // CMediatorTest::GetListOfDomains1Domain
       
  3418 //
       
  3419 // Get list of domains
       
  3420 // Expected 1 domain (+already existing)
       
  3421 // -----------------------------------------------------------------------------
       
  3422 //
       
  3423 
       
  3424 TInt CMediatorTest::GetListOfDomains1DomainL( TTestResult& aResult )
       
  3425     {
       
  3426     // There shall be one domain when executing this test
       
  3427     RDomainList domainList;
       
  3428     CleanupClosePushL( domainList );
       
  3429     TInt status = iNotifications->GetDomains( domainList );
       
  3430     
       
  3431     if( KErrNone == status  )
       
  3432         {
       
  3433         if( domainList.Count() == initCountOfDomain )
       
  3434             {
       
  3435             _LIT( KErrorDescription, "GetDomains returns with" );
       
  3436             aResult.SetResult( status, KErrorDescription );           
       
  3437             }
       
  3438         else
       
  3439             {
       
  3440             _LIT( KErrorDescription, "Wrong amount of domains found" );
       
  3441             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3442             }
       
  3443         }
       
  3444     else
       
  3445         {
       
  3446         _LIT( KErrorDescription, "GetDomains returns with" );
       
  3447         aResult.SetResult( status, KErrorDescription );        
       
  3448         }
       
  3449     CleanupStack::PopAndDestroy( &domainList );
       
  3450     return KErrNone;
       
  3451     }
       
  3452 
       
  3453 
       
  3454 // -----------------------------------------------------------------------------
       
  3455 // CMediatorTest::GetListOfDomainsMultipleDomains
       
  3456 //
       
  3457 // Get list of domains
       
  3458 // 
       
  3459 // -----------------------------------------------------------------------------
       
  3460 //
       
  3461 
       
  3462 TInt CMediatorTest::GetListOfDomainsMultipleDomainsL( TTestResult& aResult )
       
  3463     {
       
  3464     TInt status( KErrNone );
       
  3465     TUid myUid = TUid::Uid( KTestUid );
       
  3466     TCapabilitySet caps;
       
  3467     caps.SetEmpty();
       
  3468     TUid domain;   
       
  3469     
       
  3470     REventList eventList;
       
  3471     CleanupClosePushL(eventList);
       
  3472     
       
  3473     for(TInt i=50; i<100; i++) // i = Event ID
       
  3474         {
       
  3475         TEvent newEvent;
       
  3476         newEvent.iEventId = i;
       
  3477         newEvent.iVersion = iDefaultVersion;
       
  3478         newEvent.iCaps = caps;  
       
  3479         eventList.AppendL(newEvent);
       
  3480         }
       
  3481     
       
  3482     for( TInt j=KMinDomainID; j<KMidDomainID; j++ ) // j = domain
       
  3483         {
       
  3484         domain = TUid::Uid(j);
       
  3485         status = iEventProvider->RegisterEvent( domain, 
       
  3486                                                 myUid,
       
  3487                                                 eventList );
       
  3488         if( KErrNone != status )
       
  3489             {
       
  3490             _LIT( KErrorDescription, "Register event failure" );
       
  3491             aResult.SetResult( status, KErrorDescription );       
       
  3492             break;
       
  3493             }
       
  3494         }        
       
  3495     // There shall be multiple domain when executing this test
       
  3496     if ( KErrNone == status  )
       
  3497         {
       
  3498         RDomainList domainList;
       
  3499         CleanupClosePushL(domainList);
       
  3500         status = iNotifications->GetDomains( domainList );
       
  3501         
       
  3502         _LIT( KErrorDescription, "GetDomains returns with" );
       
  3503         if( KErrNone == status  )
       
  3504             {
       
  3505             if(domainList.Count() > 1 )
       
  3506                 {
       
  3507                aResult.SetResult( status, KErrorDescription );           
       
  3508                 }
       
  3509             else
       
  3510                 {
       
  3511                 _LIT( KErrorDescription, "Wrong amount of domains found" );
       
  3512                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3513                 }
       
  3514             }
       
  3515         else
       
  3516             {
       
  3517             aResult.SetResult( status, KErrorDescription );        
       
  3518             }
       
  3519         CleanupStack::PopAndDestroy( &domainList );
       
  3520         }
       
  3521     status = CleanRegisterMultipleEvents(domain, myUid, eventList);
       
  3522     if( KErrNone != status )
       
  3523         {
       
  3524         _LIT( KErrorDescription, "Cleaning failed" );
       
  3525         aResult.SetResult( status, KErrorDescription );
       
  3526         }
       
  3527     CleanupStack::PopAndDestroy( &eventList );
       
  3528     return KErrNone;
       
  3529     }
       
  3530 
       
  3531 
       
  3532 // -----------------------------------------------------------------------------
       
  3533 // CMediatorTest::GetListOfDomainsOver500Domains
       
  3534 // 
       
  3535 // Get list of domains
       
  3536 // -----------------------------------------------------------------------------
       
  3537 //
       
  3538 
       
  3539 TInt CMediatorTest::GetListOfDomainsOver500DomainsL( TTestResult& aResult )
       
  3540     {
       
  3541     TInt status( KErrNone );
       
  3542     TUid myUid = TUid::Uid( KTestUid );
       
  3543     TCapabilitySet caps;
       
  3544     caps.SetEmpty();
       
  3545     TUid domain;
       
  3546     REventList eventList;
       
  3547     CleanupClosePushL( eventList );                    
       
  3548     for( TInt i=50; i<100; i++ ) // i = Event ID
       
  3549         {
       
  3550         TEvent newEvent;
       
  3551         newEvent.iEventId = i;
       
  3552         newEvent.iVersion = iDefaultVersion;
       
  3553         newEvent.iCaps = caps;  
       
  3554         eventList.AppendL(newEvent);
       
  3555         }
       
  3556 
       
  3557     for( TInt j=KMidDomainID; j<KMaxDomainID; j++ ) // j = domain
       
  3558         {
       
  3559         domain = TUid::Uid(j);
       
  3560         status = iEventProvider->RegisterEvent( domain, 
       
  3561                                                 myUid,
       
  3562                                                 eventList );
       
  3563         if( KErrNone != status )
       
  3564             {
       
  3565             _LIT( KErrorDescription, "Register event failure" );
       
  3566             aResult.SetResult( status, KErrorDescription );       
       
  3567             break;
       
  3568             }
       
  3569         }         
       
  3570     if( KErrNone == status  )
       
  3571         {
       
  3572  
       
  3573         // There shall be over 500 domain when executing this test
       
  3574         RDomainList domainList;
       
  3575         CleanupClosePushL( domainList );
       
  3576         status = iNotifications->GetDomains( domainList );
       
  3577       
       
  3578         if(KErrNone == status )
       
  3579           {
       
  3580           if(domainList.Count() > 500 )
       
  3581               {
       
  3582               _LIT( KErrorDescription, "GetDomains returns with" );
       
  3583               aResult.SetResult( status, KErrorDescription );           
       
  3584               }
       
  3585           else
       
  3586               {
       
  3587               _LIT( KErrorDescription, "Wrong amount of domains found" );
       
  3588               aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3589               }
       
  3590           }
       
  3591         else
       
  3592           {
       
  3593           _LIT( KErrorDescription, "GetDomains returns with" );
       
  3594           aResult.SetResult( status, KErrorDescription );        
       
  3595           }
       
  3596 
       
  3597         for( TInt j=KMidDomainID; j<KMaxDomainID; j++ ) // j = domain
       
  3598             {      
       
  3599             domain = TUid::Uid(j); 
       
  3600             status = CleanRegisterMultipleEvents(domain, myUid, eventList);
       
  3601             if(KErrNone != status)
       
  3602                 {
       
  3603                 _LIT( KErrorDescription, "Test code passed but cleaning failed" );
       
  3604                 aResult.SetResult( status, KErrorDescription );
       
  3605                 }
       
  3606             }
       
  3607         CleanupStack::PopAndDestroy( &domainList );
       
  3608         }
       
  3609     CleanupStack::PopAndDestroy( &eventList );
       
  3610     return KErrNone;
       
  3611     }
       
  3612 
       
  3613 // -----------------------------------------------------------------------------
       
  3614 // CMediatorTest::GetListOfCategoriesNoCategories
       
  3615 // 
       
  3616 // Get list of categories
       
  3617 // -----------------------------------------------------------------------------
       
  3618 //
       
  3619 TInt CMediatorTest::GetListOfCategoriesNoCategoriesL( TTestResult& aResult )
       
  3620     {
       
  3621     // There shall not be categories in domain
       
  3622     RCategoryList categoryList;
       
  3623     CleanupClosePushL( categoryList );
       
  3624     TUid myUid = TUid::Uid( KTestUid );
       
  3625     iTestHelper->ClearAllNotifyData();
       
  3626     TInt status = iNotifications->GetCategories( myUid, categoryList );
       
  3627     
       
  3628     if( KErrNone == status  )
       
  3629         {
       
  3630         if( categoryList.Count() == 0 )
       
  3631             {
       
  3632             _LIT( KErrorDescription, "GetCategories returns with" );
       
  3633             aResult.SetResult( KErrNone, KErrorDescription );           
       
  3634             }
       
  3635         else
       
  3636             {
       
  3637             _LIT( KErrorDescription, "Wrong number of categories found" );
       
  3638             aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3639             }
       
  3640         }
       
  3641     else
       
  3642         {
       
  3643         _LIT( KErrorDescription, "GetCategories returns with" );
       
  3644         aResult.SetResult( status, KErrorDescription );        
       
  3645         }
       
  3646     CleanupStack::PopAndDestroy( &categoryList );
       
  3647     return KErrNone;
       
  3648     }
       
  3649 
       
  3650 
       
  3651 // -----------------------------------------------------------------------------
       
  3652 // CMediatorTest::GetListOfCategoriesIncorrectDomainUI
       
  3653 // 
       
  3654 // Get list of categories
       
  3655 // Domain ID not valid
       
  3656 // -----------------------------------------------------------------------------
       
  3657 //
       
  3658 
       
  3659 TInt CMediatorTest::GetListOfCategoriesIncorrectDomainUIDL( TTestResult& aResult )
       
  3660     {
       
  3661     // There shall not be categories in domain
       
  3662     RCategoryList categoryList;
       
  3663     CleanupClosePushL( categoryList );
       
  3664     TUid myUid = TUid::Uid(KNonExistingDomainId);
       
  3665     
       
  3666     TInt status = iNotifications->GetCategories( myUid, categoryList );
       
  3667     
       
  3668     if( KErrMediatorDomainNotFound == status )
       
  3669         {
       
  3670        _LIT( KErrorDescription, "GetCategories returns with" );
       
  3671        aResult.SetResult( KErrNone, KErrorDescription );           
       
  3672         }
       
  3673     else
       
  3674         {
       
  3675        _LIT( KErrorDescription, "Wrong error status received" );
       
  3676        aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  3677         }
       
  3678     CleanupStack::PopAndDestroy( &categoryList );
       
  3679     return KErrNone;
       
  3680     }
       
  3681 
       
  3682 // -----------------------------------------------------------------------------
       
  3683 // CMediatorTest::GetListOfCategoriesMultipleCategories
       
  3684 // 
       
  3685 // Get list of categories
       
  3686 // -----------------------------------------------------------------------------
       
  3687 //
       
  3688 
       
  3689 TInt CMediatorTest::GetListOfCategoriesMultipleCategoriesL( TTestResult& aResult )
       
  3690 {
       
  3691     // There shall be more than one category in domain
       
  3692     RCategoryList categoryList;
       
  3693     CleanupClosePushL( categoryList );
       
  3694     TUid myUid = TUid::Uid( KTestUid );
       
  3695     TUid my2ndUid = TUid::Uid(KTestUid+1);
       
  3696     TUid my3rdUid = TUid::Uid(KTestUid+2);
       
  3697     
       
  3698     TCapabilitySet caps;
       
  3699     caps.SetEmpty();
       
  3700         
       
  3701     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps);
       
  3702     preStatus = PreconditionRegisterOneEvent( myUid, my2ndUid, KTestEventId, iDefaultVersion, caps);
       
  3703     preStatus = PreconditionRegisterOneEvent( myUid, my3rdUid, KTestEventId, iDefaultVersion, caps);
       
  3704     
       
  3705     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  3706     aResult.SetResult( preStatus, KErrorDescription );  
       
  3707     
       
  3708     if( KErrNone == preStatus )
       
  3709         {
       
  3710         TInt status = iNotifications->GetCategories( myUid, categoryList );
       
  3711         if( KErrNone == status  )
       
  3712             {
       
  3713             if( categoryList.Count() > 1 )
       
  3714                 {
       
  3715                 _LIT( KErrorDescription, "GetCategories returns with" );
       
  3716                 aResult.SetResult( status, KErrorDescription );           
       
  3717                 }
       
  3718             else
       
  3719                 {
       
  3720                 _LIT( KErrorDescription, "Wrong amount of categories found" );
       
  3721                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3722                 }
       
  3723             }
       
  3724         else
       
  3725             {
       
  3726             _LIT( KErrorDescription, "GetCategories returns with" );
       
  3727             aResult.SetResult( status, KErrorDescription );        
       
  3728             }
       
  3729     
       
  3730         status = CleanRegisterOneEvent( myUid, myUid, KTestEventId);
       
  3731         status = CleanRegisterOneEvent( myUid, my2ndUid, KTestEventId);
       
  3732         status = CleanRegisterOneEvent( myUid, my3rdUid, KTestEventId);
       
  3733         if( KErrNone != status )
       
  3734             {
       
  3735             _LIT( KErrorDescription, "Test code passed but cleaning failed" );
       
  3736             aResult.SetResult( status, KErrorDescription );
       
  3737             }
       
  3738         }
       
  3739     CleanupStack::PopAndDestroy( &categoryList );
       
  3740     return KErrNone;
       
  3741     }
       
  3742 
       
  3743 // -----------------------------------------------------------------------------
       
  3744 // CMediatorTest::GetListOfCommands
       
  3745 // 
       
  3746 // Get list of commands
       
  3747 // -----------------------------------------------------------------------------
       
  3748 //
       
  3749 
       
  3750 TInt CMediatorTest::GetListOfCommandsL( TTestResult& aResult )
       
  3751     {
       
  3752     //There may not be any commands in this category
       
  3753     RCommandList commandList;
       
  3754     CleanupClosePushL( commandList );
       
  3755     TUid myUid = TUid::Uid( KTestUid );
       
  3756     TUid otherUid = TUid::Uid(KOtherUid);
       
  3757     TCapabilitySet caps;
       
  3758     caps.SetEmpty();
       
  3759         
       
  3760     TInt preStatus = PreconditionRegisterOneEvent( myUid, otherUid, KTestEventId, iDefaultVersion, caps);
       
  3761     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  3762     aResult.SetResult( preStatus, KErrorDescription );
       
  3763     
       
  3764     if( KErrNone == preStatus )
       
  3765         {    
       
  3766         TInt status = iNotifications->GetCommands( myUid, otherUid, commandList  );
       
  3767         if( KErrNone == status  )
       
  3768             {
       
  3769             if( commandList.Count() == 0 )
       
  3770                 {
       
  3771                 _LIT( KErrorDescription, "GetCommands returns with" );
       
  3772                 aResult.SetResult( status, KErrorDescription );           
       
  3773                 }
       
  3774             else
       
  3775                 {
       
  3776                 _LIT( KErrorDescription, "Wrong amount of categories found" );
       
  3777                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3778                 }
       
  3779             }
       
  3780         else
       
  3781             {
       
  3782             _LIT( KErrorDescription, "GetCommands returns with" );
       
  3783             aResult.SetResult( status, KErrorDescription );        
       
  3784             }
       
  3785         
       
  3786         status = CleanRegisterOneEvent( myUid, otherUid, KTestEventId );
       
  3787         if(KErrNone != status)
       
  3788             {
       
  3789             _LIT( KErrorDescription, "Cleaning event failed" );
       
  3790             aResult.SetResult( status, KErrorDescription );
       
  3791             }           
       
  3792         }
       
  3793     CleanupStack::PopAndDestroy( &commandList );
       
  3794     return KErrNone;
       
  3795     }
       
  3796 
       
  3797 // -----------------------------------------------------------------------------
       
  3798 // CMediatorTest::GetListOfCommandsIncorrectDomainUID
       
  3799 // 
       
  3800 // Get list of commands
       
  3801 // -----------------------------------------------------------------------------
       
  3802 //
       
  3803 
       
  3804 TInt CMediatorTest::GetListOfCommandsIncorrectDomainUIDL( TTestResult& aResult )
       
  3805     {
       
  3806     //There shall not be this domain   
       
  3807     RCommandList commandList;
       
  3808     CleanupClosePushL( commandList );
       
  3809     TUid myUid = TUid::Uid(KReallyNonExistingDomainId);
       
  3810     
       
  3811     TInt status = iNotifications->GetCommands( myUid, myUid, commandList );
       
  3812     //expected status is KErrMediatorDomainNotFound
       
  3813     if( KErrMediatorDomainNotFound == status )
       
  3814         {
       
  3815         _LIT( KErrorDescription, "GetCommands returns with expected KErrMediatorDomainNotFound" );
       
  3816         aResult.SetResult( KErrNone, KErrorDescription );           
       
  3817         }
       
  3818     else
       
  3819         {
       
  3820         _LIT( KErrorDescription, "Wrong error code" );
       
  3821         aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  3822         }
       
  3823     CleanupStack::PopAndDestroy( &commandList );
       
  3824     return KErrNone;
       
  3825     }
       
  3826 
       
  3827 // -----------------------------------------------------------------------------
       
  3828 // CMediatorTest::GetListOfCommandsIncorrectCategoryUID
       
  3829 // 
       
  3830 // Get list of commands
       
  3831 // -----------------------------------------------------------------------------
       
  3832 //
       
  3833 
       
  3834 TInt CMediatorTest::GetListOfCommandsIncorrectCategoryUIDL( TTestResult& aResult )
       
  3835     {
       
  3836     //There shall not be this category   
       
  3837     RCommandList commandList;
       
  3838     CleanupClosePushL( commandList );
       
  3839     TUid myUid = TUid::Uid( KTestUid );
       
  3840     TUid invalidUid = TUid::Uid(KReallyNonExistingDomainId);
       
  3841     
       
  3842     TInt status = iNotifications->GetCommands( myUid, invalidUid, commandList  );
       
  3843     //expected status is KErrMediatorCategoryNotFound
       
  3844     if( KErrMediatorCategoryNotFound == status )
       
  3845         {
       
  3846         _LIT( KErrorDescription, "GetCommands returns with expected KErrMediatorCategoryNotFound" );
       
  3847         aResult.SetResult( KErrNone, KErrorDescription );           
       
  3848         }
       
  3849     else
       
  3850         {
       
  3851         _LIT( KErrorDescription, "Wrong error code" );
       
  3852         aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  3853         }
       
  3854     CleanupStack::PopAndDestroy( &commandList );
       
  3855     return KErrNone;
       
  3856     }
       
  3857 
       
  3858 // -----------------------------------------------------------------------------
       
  3859 // CMediatorTest::GetListOfCommands1Command
       
  3860 // 
       
  3861 // Get list of commands
       
  3862 // -----------------------------------------------------------------------------
       
  3863 //
       
  3864 
       
  3865 TInt CMediatorTest::GetListOfCommands1CommandL( TTestResult& aResult )
       
  3866     {
       
  3867     RCommandList commandList;
       
  3868     CleanupClosePushL( commandList );
       
  3869     TUid myUid = TUid::Uid(KMinDomainID);
       
  3870     TInt status( KErrNone );
       
  3871     TCapabilitySet caps;
       
  3872     caps.SetEmpty();
       
  3873 
       
  3874     status = iCommandResponder->RegisterCommand( myUid, 
       
  3875                                                  myUid, 
       
  3876                                                  KDefaultCommandId, 
       
  3877                                                  iDefaultVersion,
       
  3878                                                  caps, 
       
  3879                                                  KDefaultTimeOut );
       
  3880     _LIT( KErrorDescription, "RegisterCommand returns with" );
       
  3881     aResult.SetResult( status, KErrorDescription );
       
  3882     if( KErrNone == status  )
       
  3883         {
       
  3884         status = iNotifications->GetCommands( myUid, myUid, commandList  );
       
  3885         if(KErrNone == status )
       
  3886             {
       
  3887             if(commandList.Count() == 1 )
       
  3888                 {
       
  3889                 _LIT( KErrorDescription, "GetCommands returns with" );
       
  3890                 aResult.SetResult( status, KErrorDescription );           
       
  3891                 }
       
  3892             else
       
  3893                 {
       
  3894                 _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  3895                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3896                 }
       
  3897             }
       
  3898         else
       
  3899             {
       
  3900             _LIT( KErrorDescription, "GetCommands returns with" );
       
  3901             aResult.SetResult( status, KErrorDescription );        
       
  3902             }
       
  3903         }
       
  3904     CleanupStack::PopAndDestroy( &commandList );
       
  3905     return KErrNone;
       
  3906     }
       
  3907 
       
  3908 // -----------------------------------------------------------------------------
       
  3909 // CMediatorTest::GetListOfCommandsMultipleCommands
       
  3910 // 
       
  3911 // Get list of commands
       
  3912 // -----------------------------------------------------------------------------
       
  3913 //
       
  3914 
       
  3915 TInt CMediatorTest::GetListOfCommandsMultipleCommandsL( TTestResult& aResult )
       
  3916     {
       
  3917     RCommandList commandList;
       
  3918     CleanupClosePushL(commandList);
       
  3919     TUid myUid = TUid::Uid( KTestUid );
       
  3920 
       
  3921     TCapabilitySet caps;
       
  3922     caps.SetEmpty();
       
  3923    
       
  3924     RCommandList  commands;
       
  3925     CleanupClosePushL(commands);
       
  3926     for ( TInt index = KMinListId; index <KMaxListId; index++ )
       
  3927         {
       
  3928         MediatorService::TCommand newCommand;
       
  3929         newCommand.iCommandId = index;
       
  3930         newCommand.iVersion = iDefaultVersion;
       
  3931         newCommand.iCaps = caps;
       
  3932         newCommand.iTimeout = KDefaultTimeOut;
       
  3933         User::LeaveIfError( commands.Append(newCommand) );
       
  3934         }
       
  3935     
       
  3936     TInt preStatus = PreconditionRegisterCommands( myUid,
       
  3937                                                    myUid, 
       
  3938                                                    commands );
       
  3939     _LIT( KDescription, "PreconditionRegisterCommands returns with" );
       
  3940     aResult.SetResult( preStatus, KDescription );
       
  3941 
       
  3942     if( KErrNone == preStatus )
       
  3943         {
       
  3944         TInt status = iNotifications->GetCommands( myUid, myUid, commandList );
       
  3945         if( KErrNone == status  )
       
  3946             {
       
  3947             if( commandList.Count() > 1 )
       
  3948                 {
       
  3949                 _LIT( KErrorDescription, "GetCommands returns with" );
       
  3950                 aResult.SetResult( status, KErrorDescription );           
       
  3951                 }
       
  3952             else
       
  3953                 {
       
  3954                 _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  3955                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  3956                 }
       
  3957             }
       
  3958       else
       
  3959           {
       
  3960           _LIT( KErrorDescription, "GetCommands returns with" );
       
  3961           aResult.SetResult( status, KErrorDescription );        
       
  3962           }
       
  3963       status = CleanRegisterCommands( myUid, myUid, commands );
       
  3964       if( KErrNone != status )
       
  3965           {
       
  3966           _LIT( KDescription, "Cleaning failed" );
       
  3967           aResult.SetResult( status, KDescription );
       
  3968           }      
       
  3969         }
       
  3970     CleanupStack::PopAndDestroy(&commands);
       
  3971     CleanupStack::PopAndDestroy(&commandList);
       
  3972     return KErrNone;
       
  3973     }
       
  3974 
       
  3975 // -----------------------------------------------------------------------------
       
  3976 // CMediatorTest::GetListOfCommandsOver500Commands
       
  3977 // 
       
  3978 // Get list of commands
       
  3979 // -----------------------------------------------------------------------------
       
  3980 //
       
  3981 
       
  3982 TInt CMediatorTest::GetListOfCommandsOver500CommandsL( TTestResult& aResult )
       
  3983     {
       
  3984     RCommandList commandList;
       
  3985     CleanupClosePushL( commandList );
       
  3986     TUid myUid = TUid::Uid( KTestUid );
       
  3987     TCapabilitySet caps;
       
  3988     caps.SetEmpty();
       
  3989    
       
  3990     RCommandList  commands;
       
  3991     CleanupClosePushL( commands );
       
  3992     for ( TInt index = KMinListId; index <KMinListId+525; index++ )
       
  3993         {
       
  3994         MediatorService::TCommand newCommand;
       
  3995         newCommand.iCommandId = index;
       
  3996         newCommand.iVersion = iDefaultVersion;
       
  3997         newCommand.iCaps = caps;
       
  3998         newCommand.iTimeout = KDefaultTimeOut;
       
  3999         User::LeaveIfError( commandList.Append(newCommand) );
       
  4000         }
       
  4001     
       
  4002     TInt preStatus = PreconditionRegisterCommands( myUid,
       
  4003                                                    myUid, 
       
  4004                                                    commandList );
       
  4005     _LIT( KDescription, "PreconditionRegisterCommands returns with" );
       
  4006     aResult.SetResult( preStatus, KDescription );
       
  4007 
       
  4008     if( KErrNone == preStatus )
       
  4009         {
       
  4010         TInt status = iNotifications->GetCommands( myUid, myUid, commands );
       
  4011         if( KErrNone == status  )
       
  4012             {
       
  4013             if( commands.Count() > 500 )
       
  4014                 {
       
  4015                 _LIT( KErrorDescription, "GetCommands returns with" );
       
  4016                 aResult.SetResult( status, KErrorDescription );           
       
  4017                 }
       
  4018             else
       
  4019                 {
       
  4020                 _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  4021                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4022                 }
       
  4023             }
       
  4024         else
       
  4025             {
       
  4026             _LIT( KErrorDescription, "GetCommands returns with" );
       
  4027             aResult.SetResult( status, KErrorDescription );        
       
  4028             }
       
  4029         status = CleanRegisterCommands( myUid, myUid, commandList );
       
  4030         if( KErrNone != status )
       
  4031             {
       
  4032             _LIT( KDescription, "Cleaning failed" );
       
  4033             aResult.SetResult( status, KDescription );
       
  4034             }
       
  4035         }
       
  4036     CleanupStack::PopAndDestroy( &commands );
       
  4037     CleanupStack::PopAndDestroy( &commandList );
       
  4038     return KErrNone;
       
  4039     }
       
  4040 
       
  4041 // -----------------------------------------------------------------------------
       
  4042 // CMediatorTest::GetListOfEventsNoEventsInCategory
       
  4043 // 
       
  4044 // Get list of events
       
  4045 // -----------------------------------------------------------------------------
       
  4046 //
       
  4047 
       
  4048 TInt CMediatorTest::GetListOfEventsNoEventsInCategoryL( TTestResult& aResult )
       
  4049     {
       
  4050     REventList eventList;
       
  4051     REventList eventListB;
       
  4052     CleanupClosePushL(eventList);
       
  4053     CleanupClosePushL(eventListB);
       
  4054     
       
  4055     TUid myUid = TUid::Uid( KTestUid );
       
  4056 
       
  4057     TCapabilitySet caps;
       
  4058     caps.SetEmpty();
       
  4059    
       
  4060     RCommandList  commands;
       
  4061     CleanupClosePushL(commands);
       
  4062     
       
  4063     TInt status = iNotifications->GetEvents( myUid, myUid, eventListB ); // get events
       
  4064     status = CleanRegisterMultipleEvents(myUid, myUid, eventListB); // clean those events
       
  4065     
       
  4066     for ( TInt index = KMinListId; index <KMinListId+10; index++ )
       
  4067         {
       
  4068         MediatorService::TCommand newCommand;
       
  4069         newCommand.iCommandId = index;
       
  4070         newCommand.iVersion = iDefaultVersion;
       
  4071         newCommand.iCaps = caps;
       
  4072         newCommand.iTimeout = KDefaultTimeOut;
       
  4073         User::LeaveIfError( commands.Append(newCommand) );
       
  4074         }
       
  4075     
       
  4076     TInt preStatus = PreconditionRegisterCommands( myUid,
       
  4077                                                    myUid, 
       
  4078                                                    commands ); // register some commands
       
  4079     _LIT( KDescription, "PreconditionRegisterCommands returns with" );
       
  4080     aResult.SetResult( preStatus, KDescription );
       
  4081 
       
  4082     if( KErrNone == preStatus )
       
  4083         {
       
  4084         TInt status = iNotifications->GetEvents( myUid, myUid, eventList );
       
  4085       
       
  4086         if( KErrNone == status  )
       
  4087             {
       
  4088             if( eventList.Count() == 0 )
       
  4089                 {
       
  4090                 _LIT( KErrorDescription, "GetEvents returns with" );
       
  4091                 aResult.SetResult( status, KErrorDescription );
       
  4092                 status = CleanRegisterCommands( myUid, myUid, commands );
       
  4093                 if(KErrNone != status)
       
  4094                     {
       
  4095                     _LIT( KDescription, "Test code passed but cleaning failed" );
       
  4096                     aResult.SetResult( status, KDescription );
       
  4097                     } 
       
  4098                 }
       
  4099             else
       
  4100                 {
       
  4101                 _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  4102                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4103                 }
       
  4104             }
       
  4105         else
       
  4106             {
       
  4107             _LIT( KErrorDescription, "GetEvents returns with" );
       
  4108             aResult.SetResult( status, KErrorDescription );        
       
  4109             }
       
  4110         status = CleanRegisterMultipleEvents( myUid, myUid, eventListB ); // clean those events
       
  4111         if( KErrNone != status )
       
  4112             {
       
  4113             _LIT( KDescription, "Cleaning failed" );
       
  4114             aResult.SetResult( status, KDescription );
       
  4115             }      
       
  4116         }      
       
  4117     CleanupStack::PopAndDestroy( &commands );
       
  4118     CleanupStack::PopAndDestroy( &eventListB );
       
  4119     CleanupStack::PopAndDestroy( &eventList );
       
  4120     return KErrNone;
       
  4121     }
       
  4122 
       
  4123 // -----------------------------------------------------------------------------
       
  4124 // CMediatorTest::GetListOfEventsWithIncorrectDomainUID
       
  4125 //
       
  4126 // Get list of events
       
  4127 // 
       
  4128 // -----------------------------------------------------------------------------
       
  4129 //
       
  4130 
       
  4131 TInt CMediatorTest::GetListOfEventsWithIncorrectDomainUIDL( TTestResult& aResult )
       
  4132     {
       
  4133     REventList eventList;
       
  4134     CleanupClosePushL( eventList );
       
  4135     TUid invalidUid = TUid::Uid(KNonExistingDomainId);
       
  4136     TUid myUid = TUid::Uid( KTestUid );
       
  4137     
       
  4138     TInt status = iNotifications->GetEvents( invalidUid, myUid, eventList );
       
  4139     //expected status is KErrMediatorDomainNotFound
       
  4140     if( KErrMediatorDomainNotFound == status )
       
  4141         {
       
  4142         _LIT( KErrorDescription, "GetEvents returns with expected KErrMediatorDomainNotFound" );
       
  4143         aResult.SetResult( KErrNone, KErrorDescription );           
       
  4144         }
       
  4145     else
       
  4146         {
       
  4147         _LIT( KErrorDescription, "Wrong error code" );
       
  4148         aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  4149         }    
       
  4150     CleanupStack::PopAndDestroy( &eventList );
       
  4151     return KErrNone;
       
  4152     }
       
  4153 
       
  4154 // -----------------------------------------------------------------------------
       
  4155 // CMediatorTest::GetListOfEventsWithIncorrectCategoryUID
       
  4156 //
       
  4157 // Get list of events
       
  4158 // 
       
  4159 // -----------------------------------------------------------------------------
       
  4160 //
       
  4161 
       
  4162 TInt CMediatorTest::GetListOfEventsWithIncorrectCategoryUIDL( TTestResult& aResult )
       
  4163     {
       
  4164     REventList eventList;
       
  4165     CleanupClosePushL( eventList );
       
  4166     TUid invalidUid = TUid::Uid(KNonExistingDomainId);
       
  4167     TUid myUid = TUid::Uid( KTestUid );
       
  4168     
       
  4169     TInt status = iNotifications->GetEvents( myUid, invalidUid, eventList );
       
  4170     //expected status is KErrMediatorCategoryNotFound
       
  4171     if( KErrMediatorCategoryNotFound == status )
       
  4172         {
       
  4173         _LIT( KErrorDescription, "GetEvents returns with expected KErrMediatorCategoryNotFound" );
       
  4174         aResult.SetResult( KErrNone, KErrorDescription );           
       
  4175         }
       
  4176     else
       
  4177         {
       
  4178         _LIT( KErrorDescription, "Wrong error code" );
       
  4179         aResult.SetResult( KErrGeneral, KErrorDescription );        
       
  4180         }    
       
  4181     CleanupStack::PopAndDestroy( &eventList );
       
  4182     return KErrNone;
       
  4183     }
       
  4184 
       
  4185 // -----------------------------------------------------------------------------
       
  4186 // CMediatorTest::GetListOfEvents1EventInCategory
       
  4187 // 
       
  4188 // Get list of events
       
  4189 // -----------------------------------------------------------------------------
       
  4190 //
       
  4191 
       
  4192 TInt CMediatorTest::GetListOfEvents1EventInCategoryL( TTestResult& aResult )
       
  4193     {
       
  4194     REventList eventList;
       
  4195     CleanupClosePushL( eventList );
       
  4196     TUid myUid = TUid::Uid(KTestUid+6);
       
  4197     TCapabilitySet caps;
       
  4198     caps.SetEmpty();
       
  4199         
       
  4200     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps);
       
  4201     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  4202     aResult.SetResult( preStatus, KErrorDescription );
       
  4203     
       
  4204     if( KErrNone == preStatus )    
       
  4205         {
       
  4206         TInt status = iNotifications->GetEvents( myUid, myUid, eventList );
       
  4207         _LIT( KErrorDescription, "GetEvents returns with" );
       
  4208         if( KErrNone == status  )
       
  4209             {
       
  4210             if( eventList.Count() == 1 )
       
  4211                 {
       
  4212                 aResult.SetResult( status, KErrorDescription );           
       
  4213                 }
       
  4214             else
       
  4215                 {
       
  4216                 _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  4217                 aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4218                 }
       
  4219             }
       
  4220         else
       
  4221             {
       
  4222             aResult.SetResult( status, KErrorDescription );        
       
  4223             }
       
  4224       
       
  4225         TInt cleanStatus = CleanRegisterOneEvent(myUid, myUid, KTestEventId); 
       
  4226         if( KErrNone != cleanStatus)
       
  4227             {
       
  4228             _LIT( KDescription, "Cleaning failed" );
       
  4229             aResult.SetResult( cleanStatus, KDescription );     
       
  4230             }
       
  4231         else
       
  4232             {
       
  4233             aResult.SetResult( cleanStatus, KErrorDescription );
       
  4234             }
       
  4235         }
       
  4236     CleanupStack::PopAndDestroy( &eventList );
       
  4237     return KErrNone;
       
  4238     }
       
  4239 
       
  4240 // -----------------------------------------------------------------------------
       
  4241 // CMediatorTest::GetListOfEventsMultipleEventsInCategory
       
  4242 //
       
  4243 // Get list of events
       
  4244 // 
       
  4245 // -----------------------------------------------------------------------------
       
  4246 //
       
  4247 
       
  4248 TInt CMediatorTest::GetListOfEventsMultipleEventsInCategoryL( TTestResult& aResult )
       
  4249     {
       
  4250     REventList eventList;
       
  4251     CleanupClosePushL(eventList);
       
  4252     TUid myUid = TUid::Uid( KTestUid );
       
  4253 
       
  4254     TCapabilitySet caps;
       
  4255     caps.SetEmpty();
       
  4256     REventList eventList2;
       
  4257     CleanupClosePushL(eventList2);
       
  4258     
       
  4259     for( TInt i=80; i<91; i++ ) // Create list of events (i = event ID)
       
  4260         {
       
  4261         TEvent newEvent;
       
  4262         newEvent.iEventId = i;
       
  4263         newEvent.iVersion = iDefaultVersion;
       
  4264         newEvent.iCaps = caps;    
       
  4265         eventList.AppendL(newEvent);
       
  4266         }
       
  4267     
       
  4268     TInt preStatus = PreconditionRegisterEvents(myUid, myUid, eventList);
       
  4269     _LIT( KDescription, "PreconditionRegisterEvents returns with" );
       
  4270     aResult.SetResult( preStatus, KDescription );
       
  4271     
       
  4272     if( KErrNone == preStatus )
       
  4273         {
       
  4274         TInt status = iNotifications->GetEvents( myUid, myUid, eventList2 );
       
  4275       
       
  4276         if( KErrNone == status )
       
  4277           {
       
  4278           if( eventList2.Count() > 1 )
       
  4279               {
       
  4280               _LIT( KErrorDescription, "GetEvents returns with" );
       
  4281               aResult.SetResult( status, KErrorDescription );           
       
  4282               }
       
  4283           else
       
  4284               {
       
  4285               _LIT( KErrorDescription, "Wrong amount of events found" );
       
  4286               aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4287               }
       
  4288           }
       
  4289         else
       
  4290           {
       
  4291           _LIT( KErrorDescription, "GetEvents returns with" );
       
  4292           aResult.SetResult( status, KErrorDescription );        
       
  4293           }
       
  4294         status = CleanRegisterMultipleEvents(myUid, myUid, eventList); // clean those events
       
  4295         if( KErrNone != status )
       
  4296           {
       
  4297           _LIT( KDescription, "Test passed but cleaning failed" );
       
  4298           aResult.SetResult( status, KDescription );
       
  4299           }
       
  4300         }
       
  4301     CleanupStack::PopAndDestroy(&eventList2);
       
  4302     CleanupStack::PopAndDestroy(&eventList);
       
  4303     return KErrNone;
       
  4304     }
       
  4305 
       
  4306 // -----------------------------------------------------------------------------
       
  4307 // CMediatorTest::GetListOfEventsOver500EventsInCategory
       
  4308 //
       
  4309 // Get list of events
       
  4310 // 
       
  4311 // -----------------------------------------------------------------------------
       
  4312 //
       
  4313 TInt CMediatorTest::GetListOfEventsOver500EventsInCategoryL( TTestResult& aResult )
       
  4314     {
       
  4315     REventList eventList;
       
  4316     CleanupClosePushL( eventList );
       
  4317     TUid myUid = TUid::Uid( KTestUid+5 );
       
  4318     TCapabilitySet caps;
       
  4319     caps.SetEmpty();
       
  4320     REventList eventList2;
       
  4321     CleanupClosePushL( eventList2 );
       
  4322                         
       
  4323     for( TInt i=80; i<600; i++) // Create list of events (i = event ID)
       
  4324         {
       
  4325         TEvent newEvent;
       
  4326         newEvent.iEventId = i;
       
  4327         newEvent.iVersion = iDefaultVersion;
       
  4328         newEvent.iCaps = caps;    
       
  4329         eventList.AppendL( newEvent );
       
  4330         }
       
  4331     
       
  4332     TInt preStatus = PreconditionRegisterEvents(myUid, myUid, eventList);
       
  4333     _LIT( KDescription, "PreconditionRegisterEvents returns with" );
       
  4334     aResult.SetResult( preStatus, KDescription );
       
  4335     
       
  4336     if( KErrNone == preStatus )
       
  4337         {
       
  4338         TInt status = iNotifications->GetEvents( myUid, myUid, eventList2 );      
       
  4339         if( KErrNone == status  )
       
  4340             {
       
  4341             if( eventList2.Count() ==  eventList.Count() )
       
  4342                 {
       
  4343                 _LIT( KErrorDescription, "GetEvents returns with" );
       
  4344                 aResult.SetResult( status, KErrorDescription );
       
  4345                 status = CleanRegisterMultipleEvents( myUid, myUid, eventList);
       
  4346                 if( KErrNone != status )
       
  4347                     {
       
  4348                     _LIT( KDescription, "Cleaning failed" );
       
  4349                     aResult.SetResult( status, KDescription );
       
  4350                     }
       
  4351                 }
       
  4352             else
       
  4353                 {
       
  4354                  _LIT( KErrorDescription, "Wrong amount of commands found" );
       
  4355                  aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4356                 }
       
  4357             }
       
  4358         else
       
  4359             {
       
  4360             _LIT( KErrorDescription, "GetEvents returns with" );
       
  4361             aResult.SetResult( status, KErrorDescription );        
       
  4362             }    
       
  4363         }
       
  4364         CleanupStack::PopAndDestroy( &eventList2 );
       
  4365         CleanupStack::PopAndDestroy( &eventList );
       
  4366         return KErrNone;
       
  4367     }
       
  4368 
       
  4369 // -----------------------------------------------------------------------------
       
  4370 // CMediatorTest::SubscribeNotificationReceiver
       
  4371 //
       
  4372 // Subscribe notification receiver
       
  4373 // KESKEN
       
  4374 // -----------------------------------------------------------------------------
       
  4375 //
       
  4376 
       
  4377 TInt CMediatorTest::SubscribeNotificationReceiver( TTestResult& aResult )
       
  4378     {
       
  4379     TInt status( KErrNone );
       
  4380     iTestHelper->ClearAllNotifyData();
       
  4381     status = iNotifications->RegisterNotificationObserver( iTestHelper );
       
  4382     CTestScheduler::StartAndStopL( 2000 );
       
  4383     _LIT( KErrorDescription, "RegisterNotificationObserver returns with" );
       
  4384     aResult.SetResult( status, KErrorDescription );  
       
  4385     iTestHelper->ClearAllNotifyData();
       
  4386     return KErrNone;
       
  4387     }
       
  4388 
       
  4389 // -----------------------------------------------------------------------------
       
  4390 // CMediatorTest::ReSubscribeNotificationReceiver
       
  4391 // ReSubscribe notification receiver
       
  4392 // KESKEN
       
  4393 // -----------------------------------------------------------------------------
       
  4394 //
       
  4395 
       
  4396 TInt CMediatorTest::ReSubscribeNotificationReceiver( TTestResult& aResult )
       
  4397     {
       
  4398     TInt status( KErrNone );
       
  4399     status = iNotifications->RegisterNotificationObserver( iTestHelper );
       
  4400     
       
  4401     //expected status is KErrAlreadyExists
       
  4402     if( KErrAlreadyExists == status )
       
  4403         {
       
  4404         _LIT( KErrorDescription, "RegisterNotificationObserver returns with expected KErrAlreadyExists" );
       
  4405         aResult.SetResult( KErrNone, KErrorDescription );        
       
  4406         }
       
  4407     else
       
  4408         {
       
  4409         _LIT( KErrorDescription, "Wrong error code" );
       
  4410         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4411         }        
       
  4412     return KErrNone;
       
  4413     }
       
  4414 // -----------------------------------------------------------------------------
       
  4415 // CMediatorTest::UnsubscribeNotificationReceiver
       
  4416 // unsubscribe notification receiver
       
  4417 // KESKEN
       
  4418 // -----------------------------------------------------------------------------
       
  4419 //
       
  4420 
       
  4421 TInt CMediatorTest::UnsubscribeNotificationReceiver( TTestResult& aResult )
       
  4422     {
       
  4423     TInt status( KErrNone );
       
  4424     status = iNotifications->UnregisterNotificationObserver();
       
  4425     _LIT( KErrorDescription, "UnsubscribeNotificationReceiver returns with" );
       
  4426     aResult.SetResult( status, KErrorDescription );        
       
  4427     return KErrNone;
       
  4428     }
       
  4429 // -----------------------------------------------------------------------------
       
  4430 // CMediatorTest::ReUnsubscribeNotificationReceiver
       
  4431 // ReUnsubscribe notification receiver
       
  4432 // KESKEN
       
  4433 // -----------------------------------------------------------------------------
       
  4434 //
       
  4435 TInt CMediatorTest::ReUnsubscribeNotificationReceiver( TTestResult& aResult )
       
  4436     {
       
  4437     TInt status( KErrNone );
       
  4438     status = iNotifications->UnregisterNotificationObserver();
       
  4439     
       
  4440     //expected return is KErrNotFound
       
  4441     if( KErrNotFound == status )
       
  4442         {
       
  4443         status = KErrNone;
       
  4444         }
       
  4445     _LIT( KErrorDescription, "UnregisterNotificationObserver returns with" );
       
  4446     aResult.SetResult( status, KErrorDescription );
       
  4447     CTestScheduler::StartAndStopL( 2000 );
       
  4448     return KErrNone;
       
  4449     }
       
  4450 // -----------------------------------------------------------------------------
       
  4451 // CMediatorTest::SubscribeNotificationReceiverRegisterCommands
       
  4452 // SubscribeNotificationReceiver and Register Commands
       
  4453 // KESKEN
       
  4454 // -----------------------------------------------------------------------------
       
  4455 //
       
  4456 TInt CMediatorTest::SubscribeNotificationReceiverRegisterCommandsL( TTestResult& aResult )
       
  4457     {
       
  4458     TInt status( KErrNone );
       
  4459     TUid myUid = TUid::Uid( KTestUid ); 
       
  4460     TCapabilitySet caps;
       
  4461     caps.SetEmpty();
       
  4462 
       
  4463     iTestHelper->ClearAllNotifyData();
       
  4464     status = iNotifications->RegisterNotificationObserver(iTestHelper);
       
  4465     CTestScheduler::StartAndStopL( 2000 );
       
  4466     _LIT( KDescription, "RegisterNotificationObserver returns with" );
       
  4467     aResult.SetResult( status, KDescription );
       
  4468     if( KErrNone == status  )
       
  4469         {
       
  4470         status = iCommandResponder->RegisterCommand( myUid, 
       
  4471                                                  myUid, 
       
  4472                                                  KMaxListId+1000,
       
  4473                                                  iDefaultVersion,
       
  4474                                                  caps, 
       
  4475                                                  KDefaultTimeOut );
       
  4476     
       
  4477         CTestScheduler::StartAndStopL( 2000 );
       
  4478         _LIT( KDescription, "RegisterCommand returns with" );
       
  4479         aResult.SetResult( status, KDescription );
       
  4480         if ( iTestHelper->iNotificationReceived == EClear )
       
  4481             {
       
  4482             status = KErrNotFound;
       
  4483             _LIT( KDescription, "iTestHelper check failed" );
       
  4484             aResult.SetResult( status, KDescription );
       
  4485             }
       
  4486         }
       
  4487     iNotifications->UnregisterNotificationObserver();
       
  4488     // let request for canceling notications to complete
       
  4489     CTestScheduler::StartAndStopL( 2000 );
       
  4490     return KErrNone;    
       
  4491     }
       
  4492 // -----------------------------------------------------------------------------
       
  4493 // CMediatorTest::SubscribeNotificationReceiverUnregCommands
       
  4494 // SubscribeNotificationReceiver and unegister Commands
       
  4495 // KESKEN
       
  4496 // -----------------------------------------------------------------------------
       
  4497 //
       
  4498 TInt CMediatorTest::SubscribeNotificationReceiverUnregCommandsL( TTestResult& aResult )
       
  4499     {
       
  4500     TInt status( KErrNone );
       
  4501     TUid myUid = TUid::Uid( KTestUid ); 
       
  4502     TCapabilitySet caps;
       
  4503     caps.SetEmpty();
       
  4504 
       
  4505     RCommandList  commands;
       
  4506     CleanupClosePushL(commands);
       
  4507     
       
  4508     for ( TInt index = 1; index <KMaxListId; index++ )
       
  4509         {
       
  4510         MediatorService::TCommand newCommand;
       
  4511         newCommand.iCommandId = index;
       
  4512         newCommand.iVersion = iDefaultVersion;
       
  4513         newCommand.iCaps = caps;
       
  4514         newCommand.iTimeout = KDefaultTimeOut;
       
  4515         User::LeaveIfError( commands.Append(newCommand) );
       
  4516         }
       
  4517 
       
  4518     status = iCommandResponder->UnregisterCommand( myUid, 
       
  4519                                                    myUid,
       
  4520                                                    commands );
       
  4521     
       
  4522      _LIT( KDescription, "UnregisterCommand returns with" );
       
  4523     aResult.SetResult( status, KDescription );
       
  4524     CleanupStack::PopAndDestroy( &commands );
       
  4525     return KErrNone;    
       
  4526     }
       
  4527 // -----------------------------------------------------------------------------
       
  4528 // CMediatorTest::SubscribeNotificationReceiverUnregCommandsSoThatCatIsEmpty
       
  4529 // SubscribeNotificationReceiver and unegister commands 
       
  4530 // KESKEN
       
  4531 // -----------------------------------------------------------------------------
       
  4532 //
       
  4533 TInt CMediatorTest::SubscribeNotificationReceiverUnregCommandsSoThatCatIsEmptyL( TTestResult& aResult )
       
  4534     {
       
  4535     TInt status( KErrNone );
       
  4536     TUid myUid = TUid::Uid( KTestUid ); 
       
  4537     TCapabilitySet caps;
       
  4538     caps.SetEmpty();
       
  4539     RCommandList  commandList;
       
  4540     CleanupClosePushL( commandList );
       
  4541     
       
  4542     // First clean commands if any exist
       
  4543     status = iNotifications->GetCommands( myUid, myUid, commandList );
       
  4544     status = CleanRegisterCommands( myUid, myUid, commandList );
       
  4545     
       
  4546     iTestHelper->ClearAllNotifyData();
       
  4547     status = iNotifications->RegisterNotificationObserver( iTestHelper );
       
  4548     _LIT( KDescription, "RegisterNotificationObserver returns with" );
       
  4549     aResult.SetResult( status, KDescription );
       
  4550     CTestScheduler::StartAndStopL( 2000 );
       
  4551     if( KErrNone == status  )
       
  4552         {
       
  4553         RCommandList  commands;
       
  4554         CleanupClosePushL(commands);
       
  4555         
       
  4556         for ( TInt index = 1; index <KMaxListId; index++ )
       
  4557             {
       
  4558             MediatorService::TCommand newCommand;
       
  4559             newCommand.iCommandId = index;
       
  4560             newCommand.iVersion = iDefaultVersion;
       
  4561             newCommand.iCaps = caps;
       
  4562             newCommand.iTimeout = KDefaultTimeOut;
       
  4563             User::LeaveIfError( commands.Append(newCommand) );
       
  4564             }
       
  4565     
       
  4566         TInt preStatus = PreconditionRegisterCommands( myUid,
       
  4567                                                        myUid, 
       
  4568                                                        commands );
       
  4569         _LIT( KDescription, "PreconditionRegisterCommands register with" );
       
  4570         aResult.SetResult( preStatus, KDescription );
       
  4571     
       
  4572         if( KErrNone == preStatus )
       
  4573             {
       
  4574             status = iCommandResponder->UnregisterCommand( myUid, 
       
  4575                                                            myUid,
       
  4576                                                            commands );
       
  4577             CTestScheduler::StartAndStopL( 2000 );
       
  4578             _LIT( KDescription, "UnregisterCommand returns with" );
       
  4579             aResult.SetResult( status, KDescription );
       
  4580             } 
       
  4581         iNotifications->UnregisterNotificationObserver();
       
  4582         // let request for canceling notications to complete
       
  4583         CTestScheduler::StartAndStopL(2000);
       
  4584         CleanupStack::PopAndDestroy(&commands);    
       
  4585         }
       
  4586     CleanupStack::PopAndDestroy(&commandList);
       
  4587     return KErrNone;    
       
  4588     }
       
  4589 
       
  4590 // -----------------------------------------------------------------------------
       
  4591 // CMediatorTest::SubscribeNotificationReceiverRegisterEvents
       
  4592 // SubscribeNotificationReceiver and Register Events
       
  4593 // KESKEN
       
  4594 // -----------------------------------------------------------------------------
       
  4595 //
       
  4596 TInt CMediatorTest::SubscribeNotificationReceiverRegisterEventsL( TTestResult& aResult )
       
  4597     {
       
  4598     TInt status( KErrNone );
       
  4599     TUid myUid = TUid::Uid( KTestUid );
       
  4600     TCapabilitySet caps;
       
  4601     caps.SetEmpty();
       
  4602 
       
  4603     status = iEventProvider->RegisterEvent( myUid, 
       
  4604                                             myUid,
       
  4605                                             KTestEventId+10002,
       
  4606                                             iDefaultVersion,
       
  4607                                             caps ) ;        
       
  4608     CTestScheduler::StartAndStopL(2000);
       
  4609     _LIT( KDescription, "RegisterEvent returns with" );
       
  4610     aResult.SetResult( status, KDescription ); 
       
  4611     return KErrNone;
       
  4612     }
       
  4613 
       
  4614 // -----------------------------------------------------------------------------
       
  4615 // CMediatorTest::SubscribeNotificationReceiverUnregisterEvents
       
  4616 // SubscribeNotificationReceiver and unegister Events
       
  4617 // KESKEN
       
  4618 // -----------------------------------------------------------------------------
       
  4619 //
       
  4620 TInt CMediatorTest::SubscribeNotificationReceiverUnregisterEventsL( TTestResult& aResult )
       
  4621     {
       
  4622     TInt status( KErrNone );
       
  4623     TUid myUid = TUid::Uid( KTestUid );
       
  4624     TCapabilitySet caps;
       
  4625     caps.SetEmpty();
       
  4626     
       
  4627     iTestHelper->ClearAllNotifyData();
       
  4628     status = iNotifications->RegisterNotificationObserver(iTestHelper);
       
  4629     CTestScheduler::StartAndStopL( 2000 );
       
  4630     _LIT( KDescription, "RegisterNotificationObserver returns with" );
       
  4631     aResult.SetResult( status, KDescription );
       
  4632     if( KErrNone == status  )
       
  4633         {
       
  4634         REventList eventList;
       
  4635         CleanupClosePushL( eventList );
       
  4636         REventList eventList2;
       
  4637         CleanupClosePushL( eventList2 );
       
  4638         //clean the allready registered event
       
  4639         TInt preStatus = iNotifications->GetEvents( myUid, myUid, eventList );  
       
  4640         if( KErrNone == preStatus )
       
  4641             {
       
  4642             preStatus = CleanRegisterMultipleEvents(myUid, myUid, eventList);
       
  4643             }
       
  4644           
       
  4645         for( TInt i=76; i<85; i++ ) // Create list of events (i = event ID)
       
  4646             {
       
  4647             TEvent newEvent;
       
  4648             newEvent.iEventId = i;
       
  4649             newEvent.iVersion = iDefaultVersion;
       
  4650             newEvent.iCaps = caps;    
       
  4651             eventList2.AppendL( newEvent );
       
  4652             }
       
  4653         preStatus = PreconditionRegisterEvents(myUid, myUid, eventList2);
       
  4654         _LIT( KDescription, "PreconditionRegisterEvents returns with" );
       
  4655         aResult.SetResult( preStatus, KDescription );
       
  4656     
       
  4657         if( KErrNone == preStatus )
       
  4658             {
       
  4659             status = iEventProvider->UnregisterEvent( myUid, 
       
  4660                                                       myUid,
       
  4661                                                       eventList2 );
       
  4662             CTestScheduler::StartAndStopL( 3000 );
       
  4663             _LIT( KDescription, "UnregisterEvent returns with" );
       
  4664             aResult.SetResult( status, KDescription );
       
  4665             
       
  4666             if( iTestHelper->iNotificationReceived == 0 )
       
  4667                 {
       
  4668                 status = KErrNotFound;
       
  4669                 _LIT( KDescription, "iTestHelper check failed" );
       
  4670                 aResult.SetResult( status, KDescription );
       
  4671                 }
       
  4672             }
       
  4673         status = iNotifications->UnregisterNotificationObserver();
       
  4674         // let request for canceling notications to complete
       
  4675         CTestScheduler::StartAndStopL( 2000 ); 
       
  4676         CleanupStack::PopAndDestroy( &eventList2 );
       
  4677         CleanupStack::PopAndDestroy( &eventList );
       
  4678         }
       
  4679     return KErrNone;
       
  4680     }
       
  4681 // -----------------------------------------------------------------------------
       
  4682 // CMediatorTest::SubscribeNotificationReceiverUnregisterEventsSoThatCatIsEmpty
       
  4683 // SubscribeNotificationReceiver and unegister Events
       
  4684 // KESKEN
       
  4685 // -----------------------------------------------------------------------------
       
  4686 //
       
  4687 TInt CMediatorTest::SubscribeNotificationReceiverUnregisterEventsSoThatCatIsEmptyL( TTestResult& aResult )
       
  4688     {
       
  4689     TInt status( KErrNone );
       
  4690     TUid myUid = TUid::Uid( KTestUid );
       
  4691     TCapabilitySet caps;
       
  4692     caps.SetEmpty();
       
  4693     
       
  4694     REventList eventList;
       
  4695     CleanupClosePushL( eventList );
       
  4696     REventList eventList2;
       
  4697     CleanupClosePushL( eventList2 );
       
  4698     
       
  4699     // Clean events if any exist
       
  4700     TInt preStatus = iNotifications->GetEvents( myUid, myUid, eventList );
       
  4701     if( KErrNone == preStatus )
       
  4702         {
       
  4703         preStatus = CleanRegisterMultipleEvents(myUid, myUid, eventList);
       
  4704         CTestScheduler::StartAndStopL(2000);
       
  4705         }
       
  4706     
       
  4707     iTestHelper->ClearAllNotifyData();
       
  4708     status = iNotifications->RegisterNotificationObserver(iTestHelper);
       
  4709     CTestScheduler::StartAndStopL( 2000 );
       
  4710     if( KErrNone == status  )
       
  4711         {
       
  4712         for( TInt i=85; i<90; i++ ) // Create list of events (i = event ID)
       
  4713             {
       
  4714             TEvent newEvent;
       
  4715             newEvent.iEventId = i;
       
  4716             newEvent.iVersion = iDefaultVersion;
       
  4717             newEvent.iCaps = caps;    
       
  4718             eventList2.AppendL( newEvent );
       
  4719             }
       
  4720         
       
  4721             preStatus = PreconditionRegisterEvents(myUid, myUid, eventList2);
       
  4722             _LIT( KDescription, "PreconditionRegisterEvents returns with" );
       
  4723             aResult.SetResult( preStatus, KDescription );
       
  4724         
       
  4725             if( KErrNone == preStatus )
       
  4726                 {
       
  4727                 status = iEventProvider->UnregisterEvent( myUid, 
       
  4728                                                           myUid, // this category should be empty when these events are unregistered
       
  4729                                                           eventList2 );
       
  4730     
       
  4731                 CTestScheduler::StartAndStopL(2000);
       
  4732                 _LIT( KDescription, "UnregisterEvent returns with" );
       
  4733                 aResult.SetResult( status, KDescription );
       
  4734                 
       
  4735                 if( iTestHelper->iNotificationReceived == 0 )
       
  4736                     {
       
  4737                     status = KErrNotFound;
       
  4738                     _LIT( KDescription, "iTestHelper check failed" );
       
  4739                     aResult.SetResult( status, KDescription );
       
  4740                     }
       
  4741                 }
       
  4742         status = iNotifications->UnregisterNotificationObserver();
       
  4743         CTestScheduler::StartAndStopL( 2000 );
       
  4744         }
       
  4745     CleanupStack::PopAndDestroy( &eventList2 );
       
  4746     CleanupStack::PopAndDestroy( &eventList );
       
  4747     return KErrNone;
       
  4748     }
       
  4749 // -----------------------------------------------------------------------------
       
  4750 // CMediatorTest::SubscribeNotificationReceiverRegisterCommandsSoThatErrorInRegistration
       
  4751 // SubscribeNotificationReceiver and Register commands
       
  4752 // 
       
  4753 // KESKEN
       
  4754 // -----------------------------------------------------------------------------
       
  4755 //
       
  4756 TInt CMediatorTest::SubscribeNotificationReceiverRegisterCommandsSoThatErrorInRegistrationL( TTestResult& aResult )
       
  4757     {
       
  4758     TInt status( KErrNone );
       
  4759     TUid myUid = TUid::Uid( KTestUid ); 
       
  4760     TCapabilitySet caps;
       
  4761     caps.SetEmpty();
       
  4762     iTestHelper->ClearAllNotifyData();
       
  4763     TInt preStatus = PreconditionRegisterCommand( myUid, 
       
  4764                                                   myUid, 
       
  4765                                                   KDefaultCommandId,
       
  4766                                                   iDefaultVersion,
       
  4767                                                   caps,
       
  4768                                                   KDefaultTimeOut );
       
  4769     
       
  4770     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  4771     aResult.SetResult( preStatus, KErrorDescription );    
       
  4772     if( KErrNone == preStatus )
       
  4773         {
       
  4774         status = iCommandResponder->RegisterCommand( myUid, 
       
  4775                                                      myUid, 
       
  4776                                                      KDefaultCommandId, 
       
  4777                                                      iDefaultVersion,
       
  4778                                                      caps, 
       
  4779                                                      KDefaultTimeOut );
       
  4780         CTestScheduler::StartAndStopL( 2000 );
       
  4781         _LIT( KDescription, "RegisterCommand returns with" );
       
  4782         aResult.SetResult( KErrNone, KDescription );
       
  4783         if( iTestHelper->iNotificationReceived != 0 )
       
  4784             {
       
  4785             status = KErrNotFound;
       
  4786             _LIT( KDescription, "iTestHelper check failed" );
       
  4787             aResult.SetResult( KErrNone, KDescription );
       
  4788             }
       
  4789       
       
  4790          status = CleanRegisterCommand( myUid, 
       
  4791                                         myUid, 
       
  4792                                         KDefaultCommandId );
       
  4793       
       
  4794          if( KErrNone != status )
       
  4795              {
       
  4796              _LIT( KDescription, "Test passed but cleaning failed" );
       
  4797              aResult.SetResult( status, KDescription );        
       
  4798              }     
       
  4799         }
       
  4800     return KErrNone;    
       
  4801     }
       
  4802 
       
  4803 // -----------------------------------------------------------------------------
       
  4804 // CMediatorTest::SubscribeNotificationReceiverUnegisterCommandsSoThatErrorInRegistration
       
  4805 // 
       
  4806 // KESKEN
       
  4807 // -----------------------------------------------------------------------------
       
  4808 //
       
  4809 TInt CMediatorTest::SubscribeNotificationReceiverUnegisterCommandsSoThatErrorInRegistrationL( TTestResult& aResult )
       
  4810     {
       
  4811     TInt status( KErrNone );
       
  4812     TUid myUid = TUid::Uid( KTestUid );
       
  4813     TCapabilitySet caps;
       
  4814     caps.SetEmpty();
       
  4815     TVersion version( 8,5,7 ); // version!
       
  4816     
       
  4817     REventList eventList;
       
  4818     CleanupClosePushL(eventList);
       
  4819                         
       
  4820     for( TInt i=85; i<90; i++ ) // Create list of events (i = event ID)
       
  4821         {
       
  4822         TEvent newEvent;
       
  4823         newEvent.iEventId = i;
       
  4824         newEvent.iVersion = version;
       
  4825         newEvent.iCaps = caps;
       
  4826         eventList.AppendL(newEvent);
       
  4827         }
       
  4828     
       
  4829     // This unregistration should fail!
       
  4830     status = iEventProvider->UnregisterEvent( myUid, 
       
  4831                                               myUid, 
       
  4832                                               eventList );
       
  4833     _LIT( KDescription, "UnregisterEvent returns with" );
       
  4834     if( KErrNone == status  )
       
  4835         {
       
  4836         status = KErrNotFound;
       
  4837         }
       
  4838     else
       
  4839         {
       
  4840         status = KErrNone;
       
  4841         }
       
  4842     CleanupStack::PopAndDestroy(&eventList);
       
  4843     aResult.SetResult( status, KDescription );
       
  4844     return KErrNone;
       
  4845     }
       
  4846 
       
  4847 // -----------------------------------------------------------------------------
       
  4848 // CMediatorTest::SubscribeNotificationReceiverRegisterEventsSoThatErrorInRegistration
       
  4849 // SubscribeNotificationReceiver and Register Events
       
  4850 // KESKEN
       
  4851 // -----------------------------------------------------------------------------
       
  4852 //
       
  4853 TInt CMediatorTest::SubscribeNotificationReceiverRegisterEventsSoThatErrorInRegistration( TTestResult& aResult )
       
  4854     {
       
  4855     TInt status( KErrNone );
       
  4856     TUid myUid = TUid::Uid( KTestUid );
       
  4857     TCapabilitySet caps;
       
  4858     caps.SetEmpty();
       
  4859     TVersion version( -1,5,8 );
       
  4860     
       
  4861     iTestHelper->ClearAllNotifyData();
       
  4862     
       
  4863     TInt preStatus = PreconditionRegisterOneEvent( myUid, myUid, KTestEventId, version, caps );
       
  4864     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  4865     aResult.SetResult( preStatus, KErrorDescription );
       
  4866     
       
  4867     if( KErrNone == preStatus )
       
  4868         {    
       
  4869         iTestHelper->ClearAllNotifyData();
       
  4870         // This registration fail
       
  4871         status = iEventProvider->RegisterEvent( myUid, 
       
  4872                                                 myUid,
       
  4873                                                 KTestEventId,
       
  4874                                                 version,
       
  4875                                                 caps ) ;        
       
  4876         if( KErrNone == status  )
       
  4877             {
       
  4878             status = KErrNotFound;
       
  4879             }
       
  4880         else
       
  4881             {
       
  4882             status = CleanRegisterOneEvent(myUid, myUid, KTestEventId);
       
  4883             if ( KErrNone != status )
       
  4884                 {
       
  4885                 _LIT( KErrorDescription, "Test passed but cleaning failed" );
       
  4886                 aResult.SetResult( status, KErrorDescription );    
       
  4887                 }    
       
  4888             } 
       
  4889         }
       
  4890     _LIT( KDescription, "RegisterEvent test returns with" );
       
  4891     aResult.SetResult( status, KDescription ); // return status as test result
       
  4892     return KErrNone;
       
  4893     }
       
  4894 // -----------------------------------------------------------------------------
       
  4895 // CMediatorTest::SubscribeNotificationReceiverUnregisterEventsSoThatErrorInRegistration
       
  4896 // UnRegister Events with wrong domainId
       
  4897 // Expected Behaviour: KErrMediatorDomainNotFound
       
  4898 // KESKEN
       
  4899 // -----------------------------------------------------------------------------
       
  4900 //
       
  4901 TInt CMediatorTest::SubscribeNotificationReceiverUnregisterEventsSoThatErrorInRegistration( TTestResult& aResult )
       
  4902     {
       
  4903     TInt status( KErrNone );
       
  4904     TUid myUid = TUid::Uid( KTestUid );
       
  4905     TUid invalidUid = TUid::Uid( KNonExistingDomainId );
       
  4906     
       
  4907     status = iEventProvider->UnregisterEvent( invalidUid, 
       
  4908                                               myUid,
       
  4909                                               KTestEventId ) ;       
       
  4910     //expected error is KErrMediatorDomainNotFound
       
  4911     if( KErrMediatorDomainNotFound == status )
       
  4912         {
       
  4913         _LIT( KDescription, "UnregisterEvent returns with expected error KErrMediatorDomainNotFound" );
       
  4914         aResult.SetResult( KErrNone, KDescription );        
       
  4915         }
       
  4916     else
       
  4917         {
       
  4918         _LIT( KErrorDescription, "Wrong error status" );
       
  4919         aResult.SetResult( KErrGeneral, KErrorDescription );
       
  4920         }
       
  4921     return KErrNone;
       
  4922     }
       
  4923        
       
  4924 // -----------------------------------------------------------------------------
       
  4925 // CMediatorTest::IssueCommandCancelAndReissue
       
  4926 //
       
  4927 // Test steps:
       
  4928 // 1) Issues a command
       
  4929 // 2) Cancels the command
       
  4930 // 3) Reissues the command
       
  4931 // -----------------------------------------------------------------------------
       
  4932 //
       
  4933 
       
  4934 TInt CMediatorTest::IssueCommandCancelAndReissueL( TTestResult& aResult )
       
  4935     {
       
  4936     TUid myUid = TUid::Uid( KTestUid );
       
  4937     iTestHelper->ClearAllNotifyData();
       
  4938     TCapabilitySet caps;
       
  4939     caps.SetEmpty();
       
  4940     
       
  4941     TInt status = PreconditionRegisterCommand( myUid, myUid, KMinListId+2, iDefaultVersion, caps, 5000 );
       
  4942     
       
  4943     if( KErrNone == status   )
       
  4944         {    
       
  4945         _LIT8(KTest, "TestTestTest");
       
  4946         HBufC8* data = KTest().AllocLC();
       
  4947         
       
  4948         status = iCommandInitiator->IssueCommand( myUid, myUid, KMinListId+2, iDefaultVersion, *data );
       
  4949         
       
  4950         if ( KErrNone == status  )
       
  4951             {
       
  4952             iCommandInitiator->CancelCommand( myUid, myUid, KMinListId+2 );
       
  4953             status = iCommandInitiator->IssueCommand( myUid, myUid, KMinListId+2, iDefaultVersion, *data );
       
  4954             CTestScheduler::StartAndStopL(4000);
       
  4955             if ( KErrNone != status )
       
  4956                 {
       
  4957                 _LIT( KErrorDescription, "2nd issue command failed" );
       
  4958                 aResult.SetResult( status, KErrorDescription );    
       
  4959                 }
       
  4960             }
       
  4961         else
       
  4962             {
       
  4963             _LIT( KErrorDescription, "1st issue command failed" );
       
  4964             aResult.SetResult( status, KErrorDescription );    
       
  4965             }
       
  4966         CleanupStack::PopAndDestroy( data ); 
       
  4967         status = CleanRegisterCommand( myUid, myUid,  KMinListId+2 );
       
  4968         if ( KErrNone != status )
       
  4969             {
       
  4970             _LIT( KDescription, "Test passed but cleaning failed" );
       
  4971             aResult.SetResult( status, KDescription );      
       
  4972             }
       
  4973         }
       
  4974     else
       
  4975         {
       
  4976         _LIT( KErrorDescription, "Preconditions failed" );
       
  4977         aResult.SetResult( status, KErrorDescription );    
       
  4978         }
       
  4979     return KErrNone;
       
  4980     }
       
  4981 
       
  4982 // -----------------------------------------------------------------------------
       
  4983 // CMediatorTest::IssueCommandCancelAndIssueNewCommand
       
  4984 //
       
  4985 // Test steps:
       
  4986 // 1) Issue a command
       
  4987 // 2) Cancels the command
       
  4988 // 3) Issue a new command
       
  4989 // -----------------------------------------------------------------------------
       
  4990 //
       
  4991 
       
  4992 TInt CMediatorTest::IssueCommandCancelAndIssueNewCommandL( TTestResult& aResult )
       
  4993     {
       
  4994     TUid myUid = TUid::Uid( KTestUid );
       
  4995     iTestHelper->ClearAllNotifyData();
       
  4996     TCapabilitySet caps;
       
  4997     caps.SetEmpty();
       
  4998     const TInt cmdId1 = KMinListId+2;
       
  4999     const TInt cmdId2 = KMinListId+3;
       
  5000     
       
  5001     TInt status = PreconditionRegisterCommand( myUid, myUid, cmdId1, iDefaultVersion, caps, 5000 );
       
  5002     
       
  5003     if ( KErrNone == status  )
       
  5004         {
       
  5005         status = PreconditionRegisterCommand( myUid, myUid, cmdId2, iDefaultVersion, caps, 5000 );
       
  5006         
       
  5007         if( KErrNone == status  )
       
  5008             {    
       
  5009             _LIT8(KTest, "TestTestTest");
       
  5010             HBufC8* data = KTest().AllocLC();
       
  5011             status = iCommandInitiator->IssueCommand( myUid, myUid, cmdId1, iDefaultVersion, *data );
       
  5012             CTestScheduler::StartAndStopL(2000);
       
  5013             if ( KErrNone == status  )
       
  5014                 {
       
  5015                 iCommandInitiator->CancelCommand( myUid, myUid, cmdId1 );
       
  5016                 status = iCommandInitiator->IssueCommand( myUid, myUid, cmdId2, iDefaultVersion, *data );
       
  5017                 CTestScheduler::StartAndStopL(2000);
       
  5018                 if ( KErrNone != status )
       
  5019                     {
       
  5020                     _LIT( KErrorDescription, "2nd issue command failed" );
       
  5021                     aResult.SetResult( status, KErrorDescription );    
       
  5022                     }
       
  5023                 }
       
  5024             else
       
  5025                 {
       
  5026                 _LIT( KErrorDescription, "1st issue command failed" );
       
  5027                 aResult.SetResult( status, KErrorDescription );    
       
  5028                 }
       
  5029             //unregister 2nd command
       
  5030             status = CleanRegisterCommand( myUid, myUid,  cmdId2 );
       
  5031             if ( KErrNone != status )
       
  5032                 {
       
  5033                 _LIT( KDescription, "Cleaning failed: 2nd command" );
       
  5034                 aResult.SetResult( status, KDescription );      
       
  5035                 }
       
  5036             CleanupStack::PopAndDestroy( data );            
       
  5037             }
       
  5038         else
       
  5039             {
       
  5040             _LIT( KErrorDescription, "Preconditions failed: 2nd command register" );
       
  5041             aResult.SetResult( status, KErrorDescription );    
       
  5042             }
       
  5043         //unregister 1st command
       
  5044         status = CleanRegisterCommand( myUid, myUid,  cmdId1 );
       
  5045         if ( KErrNone != status )
       
  5046             {
       
  5047             _LIT( KDescription, "Cleaning failed: 1st command" );
       
  5048             aResult.SetResult( status, KDescription );      
       
  5049             }
       
  5050         CTestScheduler::StartAndStopL(2000); 
       
  5051         }
       
  5052     else
       
  5053         {
       
  5054         _LIT( KErrorDescription, "Preconditions failed: 1st command register" );
       
  5055         aResult.SetResult( status, KErrorDescription );    
       
  5056         }
       
  5057     return KErrNone;
       
  5058     }
       
  5059 
       
  5060 // -----------------------------------------------------------------------------
       
  5061 // CMediatorTest::InstantiateAndDeleteMediatorPlugin
       
  5062 //
       
  5063 // Test steps:
       
  5064 // 1) Instantiates the test plugin
       
  5065 // 2) Destroys the the test plugin
       
  5066 // -----------------------------------------------------------------------------
       
  5067 //
       
  5068 TInt CMediatorTest::InstantiateAndDeleteMediatorPluginL( TTestResult& aResult )
       
  5069     {
       
  5070     CMediatorPluginBase* testPlugin;
       
  5071     TRAPD( status, testPlugin = CMediatorPluginBase::NewL( TUid::Uid(0x87654323 ) ) );
       
  5072     if ( KErrNone != status )
       
  5073         {
       
  5074         _LIT( KDescription, "Failed to create plugin" );
       
  5075         aResult.SetResult( status, KDescription );      
       
  5076         }
       
  5077     else
       
  5078         {
       
  5079         delete testPlugin;
       
  5080         _LIT( KErrorDescription, "InstantiateAndDeleteMediatorPlugin test passed" );
       
  5081         aResult.SetResult( status, KErrorDescription );  
       
  5082         }
       
  5083     REComSession::FinalClose();
       
  5084     return KErrNone;
       
  5085     }
       
  5086 
       
  5087 // -----------------------------------------------------------------------------
       
  5088 // CMediatorTest::IssueCommandNoData
       
  5089 // A command is issued that does not contain parameter data. 
       
  5090 // Test steps:
       
  5091 // 1) Issues a command and check for error
       
  5092 // 2) Issue response and check for error
       
  5093 // 3) Cleanup
       
  5094 // -----------------------------------------------------------------------------
       
  5095 //
       
  5096 TInt CMediatorTest::IssueCommandNoDataL( TTestResult& aResult )
       
  5097     {
       
  5098     TUid myUid = TUid::Uid( KTestUid );
       
  5099     TCapabilitySet caps;
       
  5100     caps.SetEmpty();
       
  5101     iTestHelper->ClearAllNotifyData();
       
  5102 
       
  5103     TInt status = PreconditionRegisterCommand( myUid, 
       
  5104                                                myUid, 
       
  5105                                                KDefaultCommandId,
       
  5106                                                iDefaultVersion,
       
  5107                                                caps,
       
  5108                                                KDefaultTimeOut );
       
  5109     
       
  5110     _LIT( KErrorDescription, "PreconditionRegisterCommand returns with" );
       
  5111     aResult.SetResult( status, KErrorDescription );    
       
  5112     
       
  5113     if( KErrNone == status  )
       
  5114         {
       
  5115         iCommandInitiator->CancelCommand( myUid, myUid, KDefaultCommandId );
       
  5116         status = iCommandInitiator->IssueCommand( myUid, 
       
  5117                                                   myUid, 
       
  5118                                                   KDefaultCommandId,
       
  5119                                                   iDefaultVersion, 
       
  5120                                                   KNullDesC8 );
       
  5121         CTestScheduler::StartAndStopL(2000); // wait 2s
       
  5122         _LIT( KErrorDescription, "IssueCommand returns with");
       
  5123         aResult.SetResult( status, KErrorDescription );
       
  5124         
       
  5125         if ( KErrNone == status  )
       
  5126             {
       
  5127             status = iCommandResponder->IssueResponse( iTestHelper->iDomain, 
       
  5128                                                        iTestHelper->iCategory, 
       
  5129                                                        iTestHelper->iCommandId, 
       
  5130                                                        KErrNone,
       
  5131                                                        KNullDesC8 );                                      
       
  5132             
       
  5133             _LIT( KErrorDescription, "IssueResponse returns with" );
       
  5134             aResult.SetResult( status, KErrorDescription );
       
  5135             
       
  5136             if ( KErrNone == status  ) // execute cleanup as part of the test
       
  5137                 {
       
  5138                 status = CleanRegisterCommand( myUid, myUid, KDefaultCommandId );
       
  5139                 if ( KErrNone != status )
       
  5140                     {
       
  5141                     _LIT( KDescription, "Test passed but cleaning failed" );
       
  5142                     aResult.SetResult( status, KDescription );    
       
  5143                     }
       
  5144                 }
       
  5145             }
       
  5146         else // some step has failed, attempt cleanup but don't care about the result
       
  5147             {
       
  5148             CleanRegisterCommand( myUid, myUid, KDefaultCommandId );
       
  5149             }
       
  5150         CTestScheduler::StartAndStopL(1000);
       
  5151        }
       
  5152     return KErrNone;
       
  5153     }
       
  5154 
       
  5155 // -----------------------------------------------------------------------------
       
  5156 // CMediatorTest::InstantiateAndDeleteMediatorPlugin
       
  5157 // An event is raised that does not contain parameter data. 
       
  5158 // Test steps:
       
  5159 // 1) Raise an event and check return value
       
  5160 // 2) cleanup
       
  5161 // -----------------------------------------------------------------------------
       
  5162 //
       
  5163 TInt CMediatorTest::RaiseEventNoDataL( TTestResult& aResult )
       
  5164     {
       
  5165     TUid myUid = TUid::Uid( KTestUid );
       
  5166     TCapabilitySet caps;
       
  5167     caps.SetEmpty();
       
  5168     TInt status( KErrNone );
       
  5169     iTestHelper->ClearAllNotifyData();
       
  5170     
       
  5171     CMediatorEventProvider* eventProvider = CMediatorEventProvider::NewL();
       
  5172     CleanupStack::PushL( eventProvider );
       
  5173     status = eventProvider->RegisterEvent( myUid, myUid, KTestEventId, iDefaultVersion, caps);
       
  5174     CTestScheduler::StartAndStopL(1000);
       
  5175     
       
  5176     _LIT( KErrorDescription, "PreconditionRegisterOneEvent returns with" );
       
  5177     aResult.SetResult( status, KErrorDescription );
       
  5178       
       
  5179     if( KErrNone == status  )
       
  5180         { 
       
  5181         status = eventProvider->RaiseEvent( myUid,
       
  5182                                             myUid, 
       
  5183                                             KTestEventId,
       
  5184                                             iDefaultVersion, 
       
  5185                                             KNullDesC8 );        
       
  5186         CTestScheduler::StartAndStopL(2000);
       
  5187         _LIT( KDescription, "RaiseEvent returns with" );
       
  5188         aResult.SetResult( status, KDescription );      
       
  5189 
       
  5190         if ( KErrNone == status  ) // execute cleanup as part of the test
       
  5191             {
       
  5192             status = CleanRegisterOneEvent(myUid, myUid, KTestEventId);
       
  5193             
       
  5194             if ( KErrNone != status )
       
  5195                 {
       
  5196                 _LIT( KErrorDescription, "Test passed but cleaning failed" );
       
  5197                 aResult.SetResult( status, KErrorDescription );    
       
  5198                 }                
       
  5199             }
       
  5200         else // some test step has failed, try to cleanup
       
  5201             {
       
  5202             CleanRegisterOneEvent( myUid, myUid, KTestEventId );
       
  5203             }
       
  5204         }
       
  5205     CleanupStack::PopAndDestroy( eventProvider );
       
  5206     return KErrNone;
       
  5207     }
       
  5208 
       
  5209 void ResetTestKeys()
       
  5210     {
       
  5211     RProperty::Set( KMediatorStifTestPsKeys, KCurrentTestListVerificationVerdict, KErrGeneral );
       
  5212     
       
  5213     RProperty::Set( KMediatorStifTestPsKeys, KCurrentTestList, KErrNotSupported ) ;
       
  5214     
       
  5215     TTestItemListSetPckgBuf itemsPckgBuf;
       
  5216     itemsPckgBuf().iCount = 0;
       
  5217     RProperty::Set( KMediatorStifTestPsKeys, KReceivedTestLists, itemsPckgBuf );
       
  5218     }
       
  5219 
       
  5220 TInt VerifyTestItemList()
       
  5221     {
       
  5222     TTestItemListSetPckgBuf itemsPckgBuf;
       
  5223     itemsPckgBuf().iCount = 0;
       
  5224         
       
  5225     TInt err = RProperty::Get( KMediatorStifTestPsKeys, KReceivedTestLists, itemsPckgBuf );
       
  5226     
       
  5227     if ( err != KErrNone ) return err;
       
  5228 
       
  5229     TInt listSize( sizeof(TestItemLists) / sizeof(TTestItemList) );
       
  5230         
       
  5231     if ( listSize !=  itemsPckgBuf().iCount ) return KErrCorrupt;
       
  5232     
       
  5233     TInt verdict( KErrNone );
       
  5234     
       
  5235     for ( TInt i = 0; i < listSize; i++ )
       
  5236         {
       
  5237         const TTestItemList* registeredDataList = &TestItemLists[i];
       
  5238         const TTestItemList* receivedDataList = &( itemsPckgBuf().iTestLists[i]);
       
  5239         
       
  5240         if ( receivedDataList->iDomain != registeredDataList->iDomain ) verdict = KErrCorrupt;
       
  5241         if ( receivedDataList->iCategory != registeredDataList->iCategory ) verdict = KErrCorrupt;
       
  5242         if ( receivedDataList->iFirst !=  registeredDataList->iFirst ) verdict = KErrCorrupt;
       
  5243         if ( receivedDataList->iLast !=  registeredDataList->iLast ) verdict = KErrCorrupt;
       
  5244         }
       
  5245 
       
  5246     return verdict;
       
  5247     }
       
  5248 
       
  5249 // -----------------------------------------------------------------------------
       
  5250 // CMediatorTest::RegisterMultipleEventsWithMultipleUIDs
       
  5251 //
       
  5252 // Register 50 events in Mediator
       
  5253 // Expected precondition: No events created previously
       
  5254 // Expected behaviour: Registration succeed
       
  5255 // Cleaning: Unregister events
       
  5256 //
       
  5257 // Domain: KTestUid
       
  5258 // Category: KTestUid
       
  5259 // Event IDs: 50 - 99
       
  5260 // -----------------------------------------------------------------------------
       
  5261 //
       
  5262 void RegisterTestEventListL( TInt aIndex, CMediatorEventProvider& aEventProvider, MediatorService::REventList& aEventList )
       
  5263     {
       
  5264     if ( aIndex < 0 )User::Leave( KErrCorrupt );
       
  5265     if ( aIndex > (sizeof(TestItemLists) / sizeof(TTestItemList) - 1) ) User::Leave( KErrCorrupt );
       
  5266     
       
  5267     User::LeaveIfError( RProperty::Set( KMediatorStifTestPsKeys, KCurrentTestList, aIndex ) ); 
       
  5268     
       
  5269     TCapabilitySet caps;
       
  5270     caps.SetEmpty();    
       
  5271     aEventList.Reset();
       
  5272     
       
  5273     const TTestItemList* currentList = &TestItemLists[aIndex];
       
  5274     
       
  5275     for( TInt i = currentList->iFirst; i <= currentList->iLast ; i++ )
       
  5276         {
       
  5277         TEvent newEvent;
       
  5278         newEvent.iEventId = i;
       
  5279         newEvent.iVersion = TVersion();
       
  5280         newEvent.iCaps = caps;  
       
  5281         aEventList.AppendL( newEvent );
       
  5282         }
       
  5283     
       
  5284     User::LeaveIfError( aEventProvider.RegisterEvent( currentList->iDomain, 
       
  5285                                                       currentList->iCategory,
       
  5286                                                       aEventList ) );
       
  5287     
       
  5288     }
       
  5289 
       
  5290 void CleanTestEventListL( TInt aIndex, CMediatorEventProvider& aEventProvider, REventList& aEventList )
       
  5291     {
       
  5292     if ( aIndex < 0 )User::Leave( KErrCorrupt );
       
  5293     if ( aIndex > (sizeof(TestItemLists) / sizeof(TTestItemList) - 1) ) User::Leave( KErrCorrupt );
       
  5294     
       
  5295     const TTestItemList* currentList = &TestItemLists[aIndex];
       
  5296     
       
  5297     User::LeaveIfError( aEventProvider.UnregisterEvent( currentList->iDomain, currentList->iCategory, aEventList ) );
       
  5298     
       
  5299     }
       
  5300 
       
  5301 TInt CMediatorTest::RegisterMultipleEventsWithMultipleUIDsL( TTestResult& aResult )
       
  5302     {
       
  5303     TInt KTestRounds( sizeof(TestItemLists) / sizeof(TTestItemList) );
       
  5304     RArray<REventList*> eventLists;
       
  5305     CleanupClosePushL( eventLists );
       
  5306     User::LeaveIfError( eventLists.Reserve(KTestRounds) );
       
  5307     
       
  5308     TInt preStatus( KErrNone );
       
  5309     
       
  5310     // reserve space for events 
       
  5311     for ( TInt i = 0; i < KTestRounds; i++ )
       
  5312         {
       
  5313         REventList* list = new REventList();
       
  5314         if ( list )
       
  5315             {
       
  5316             User::LeaveIfError( preStatus = eventLists.Append(list) );
       
  5317             }
       
  5318         else
       
  5319             {
       
  5320             preStatus = KErrNoMemory;
       
  5321             }
       
  5322         
       
  5323         if ( KErrNone != preStatus )
       
  5324             {
       
  5325             _LIT( KDescription, "Test list initialization failed" );
       
  5326             aResult.SetResult( preStatus, KDescription );
       
  5327             return KErrNone;
       
  5328             }
       
  5329         }
       
  5330     
       
  5331     TInt status( KErrNone );
       
  5332     for ( TInt i = 0; i < KTestRounds; i++ )
       
  5333         {
       
  5334         TRAP( status, RegisterTestEventListL( i, *iEventProvider, *eventLists[i] ) );
       
  5335         if ( KErrNone != status  )
       
  5336             {
       
  5337             _LIT( KDescription, "Registering events failed" );
       
  5338             aResult.SetResult( status, KDescription );
       
  5339             return KErrNone;
       
  5340             }
       
  5341         }
       
  5342     CTestScheduler::StartAndStopL( 2000 ); // wait 2s
       
  5343     // check results
       
  5344     status = VerifyTestItemList();
       
  5345     
       
  5346     if ( KErrNone != status )
       
  5347         {
       
  5348         _LIT( KDescription, "Data registered to client corrupted" );
       
  5349         aResult.SetResult( status, KDescription );
       
  5350         }
       
  5351     
       
  5352     for ( TInt i = 0; i < KTestRounds; i++ )
       
  5353         {
       
  5354         TRAPD( cleanStatus, CleanTestEventListL( i, *iEventProvider, *eventLists[i] ) );
       
  5355         eventLists[i]->Reset();
       
  5356         if ( KErrNone != cleanStatus )
       
  5357              {
       
  5358              _LIT( KDescription, "Cleaning event list failed" );
       
  5359              aResult.SetResult( status, KDescription );
       
  5360              }
       
  5361         }
       
  5362     
       
  5363     for ( TInt i = 0; i < eventLists.Count(); i++ )
       
  5364         {
       
  5365         delete eventLists[i];
       
  5366         }
       
  5367     CleanupStack::PopAndDestroy( &eventLists );
       
  5368     ResetTestKeys();
       
  5369     return KErrNone;
       
  5370     }
       
  5371 
       
  5372 
       
  5373 // -----------------------------------------------------------------------------
       
  5374 // CMediatorTest::RegisterMultipleCommandsWithMultipleUIDs
       
  5375 // 
       
  5376 // Expected preconditions: Command does not exist
       
  5377 // Expected behaviour: Register command succeed
       
  5378 // Cleaning: Command unregistered
       
  5379 //  
       
  5380 // Register multiple commands
       
  5381 // Command ID(s): 1 -  KMaxListId
       
  5382 // -----------------------------------------------------------------------------
       
  5383 //
       
  5384 
       
  5385 void RegisterTestCommandListL( TInt aIndex, CMediatorCommandResponder& aCommandResponder, RCommandList& aCommandList )
       
  5386     {
       
  5387     if ( aIndex < 0 )User::Leave( KErrCorrupt );
       
  5388     if ( aIndex > (sizeof(TestItemLists) / sizeof(TTestItemList) - 1) ) User::Leave( KErrCorrupt );
       
  5389     
       
  5390     User::LeaveIfError( RProperty::Set( KMediatorStifTestPsKeys, KCurrentTestList, aIndex ) ); 
       
  5391     
       
  5392     TCapabilitySet caps;
       
  5393     caps.SetEmpty();    
       
  5394     aCommandList.Reset();
       
  5395     
       
  5396     const TTestItemList* currentList = &TestItemLists[aIndex];
       
  5397     
       
  5398     for( TInt i = currentList->iFirst; i <= currentList->iLast ; i++ )
       
  5399         {
       
  5400         MediatorService::TCommand newCommand;
       
  5401         newCommand.iCommandId = i;
       
  5402         newCommand.iVersion = TVersion();
       
  5403         newCommand.iCaps = caps;
       
  5404         newCommand.iTimeout = KMediatorResponseTimeout;
       
  5405         aCommandList.AppendL( newCommand );
       
  5406         }
       
  5407     
       
  5408     User::LeaveIfError( aCommandResponder.RegisterCommand( currentList->iDomain,
       
  5409                                                            currentList->iCategory, 
       
  5410                                                            aCommandList ) );
       
  5411     }
       
  5412 
       
  5413 void CleanTestCommandListL( TInt aIndex, CMediatorCommandResponder& aCommandResponder, RCommandList& aCommandList  )
       
  5414     {
       
  5415     if ( aIndex < 0 )User::Leave( KErrCorrupt );
       
  5416     if ( aIndex > (sizeof(TestItemLists) / sizeof(TTestItemList) - 1) ) User::Leave( KErrCorrupt );
       
  5417     
       
  5418     const TTestItemList* currentList = &TestItemLists[aIndex];
       
  5419     
       
  5420     User::LeaveIfError( aCommandResponder.UnregisterCommand( currentList->iDomain, currentList->iCategory, aCommandList ) );
       
  5421     
       
  5422     }
       
  5423 
       
  5424 TInt CMediatorTest::RegisterMultipleCommandsWithMultipleUIDsL( TTestResult& aResult )
       
  5425     {
       
  5426     TInt KTestRounds( sizeof(TestItemLists) / sizeof(TTestItemList) );
       
  5427     
       
  5428     RArray<RCommandList*> commandLists;
       
  5429     CleanupClosePushL( commandLists );
       
  5430     User::LeaveIfError( commandLists.Reserve(KTestRounds) );
       
  5431     
       
  5432     TInt preStatus( KErrNone );
       
  5433     // reserve space for events 
       
  5434     for( TInt i = 0; i < KTestRounds; i++ )
       
  5435         {
       
  5436         RCommandList* list = new RCommandList();
       
  5437         if ( list )
       
  5438             {
       
  5439             User::LeaveIfError( preStatus = commandLists.Append(list) );
       
  5440             }
       
  5441         else
       
  5442             {
       
  5443             preStatus = KErrNoMemory;
       
  5444             }
       
  5445         if ( KErrNone != preStatus )
       
  5446             {
       
  5447             _LIT( KDescription, "Test list initialization failed" );
       
  5448             aResult.SetResult( preStatus, KDescription );
       
  5449             return KErrNone;
       
  5450             }
       
  5451         }
       
  5452     TInt status( KErrNone );
       
  5453     for( TInt i = 0; i < KTestRounds; i++ )
       
  5454         {
       
  5455         TRAP( status, RegisterTestCommandListL( i, *iCommandResponder, *commandLists[i] ) );
       
  5456         if ( KErrNone == status  )
       
  5457             {
       
  5458             if ( status != KErrNone )
       
  5459                 {
       
  5460                 _LIT( KDescription, "Receiving end verification failed" );
       
  5461                 aResult.SetResult( status, KDescription );
       
  5462                 return KErrNone;
       
  5463                 }
       
  5464             }
       
  5465         else
       
  5466             {
       
  5467             _LIT( KDescription, "Registering commands failed" );
       
  5468             aResult.SetResult( status, KDescription );
       
  5469             return KErrNone;
       
  5470             }
       
  5471         }
       
  5472     CTestScheduler::StartAndStopL( 2000 ); // wait 2s
       
  5473     // check results
       
  5474     status = VerifyTestItemList();
       
  5475     if( status != KErrNone )
       
  5476         {
       
  5477         _LIT( KDescription, "Data registered to client corrupted" );
       
  5478         aResult.SetResult( status, KDescription );
       
  5479         }
       
  5480     for( TInt i = 0; i < KTestRounds; i++ )
       
  5481         {
       
  5482         TRAPD( cleanStatus, CleanTestCommandListL( i, *iCommandResponder, *commandLists[i] ) );
       
  5483         commandLists[i]->Reset();
       
  5484         if( cleanStatus != KErrNone )
       
  5485             {
       
  5486             _LIT( KDescription, "Cleaning command list failed" );
       
  5487             aResult.SetResult( status, KDescription );
       
  5488             }
       
  5489         }
       
  5490     for( TInt i = 0; i < commandLists.Count(); i++ )
       
  5491         {
       
  5492         delete commandLists[i];
       
  5493         }
       
  5494     CleanupStack::PopAndDestroy( &commandLists );
       
  5495     ResetTestKeys();
       
  5496     return KErrNone;
       
  5497     }
       
  5498 
       
  5499 // -----------------------------------------------------------------------------
       
  5500 //Client side OOM test 
       
  5501 // -----------------------------------------------------------------------------
       
  5502 
       
  5503 // -----------------------------------------------------------------------------
       
  5504 // OOM test for Event Consumer
       
  5505 // -----------------------------------------------------------------------------
       
  5506 
       
  5507 
       
  5508 TInt CMediatorTest::OOMForEventConsumerTestL(TTestResult& aResult)
       
  5509     {
       
  5510     TInt ret = KErrNoMemory;
       
  5511     
       
  5512     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5513         {
       
  5514         __UHEAP_RESET;
       
  5515         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5516         __UHEAP_MARK;
       
  5517         TRAP(ret, EventConsumerTestL());
       
  5518         __UHEAP_MARKEND;
       
  5519         if (ret == KErrNone)
       
  5520             {
       
  5521             break;
       
  5522             }
       
  5523         }
       
  5524     __UHEAP_RESET;
       
  5525     aResult.SetResult(ret, _L("OOMForEventConsumerTestL"));
       
  5526     return KErrNone;
       
  5527     }
       
  5528 
       
  5529 TInt CMediatorTest::EventConsumerTestL()
       
  5530     {
       
  5531     TInt status(KErrNone);
       
  5532     TUid myUid = TUid::Uid(KTestUid);
       
  5533     TCapabilitySet caps;
       
  5534     caps.SetEmpty(); 
       
  5535     CMediatorEventConsumer* eventConsumer;    
       
  5536     eventConsumer = CMediatorEventConsumer::NewL(iTestHelper);
       
  5537     CleanupStack::PushL(eventConsumer);
       
  5538     CMediatorEventProvider* eventProvider;    
       
  5539     eventProvider = CMediatorEventProvider::NewL();
       
  5540     CleanupStack::PushL(eventProvider);
       
  5541      
       
  5542     status = eventProvider->RegisterEvent(myUid, myUid, KTestEventId,iDefaultVersion, caps);
       
  5543        
       
  5544     if( KErrNone == status || KErrMediatorEventAlreadyExists == status )
       
  5545         {
       
  5546         status = eventConsumer->SubscribeEvent(myUid, myUid, KTestEventId, iDefaultVersion);
       
  5547         User::LeaveIfError(status);   
       
  5548         if( KErrNone == status )   
       
  5549             {
       
  5550             status = eventConsumer->UnsubscribeEvent(myUid, myUid, KTestEventId);
       
  5551             User::LeaveIfError(status);
       
  5552             }
       
  5553         status = eventProvider->UnregisterEvent(myUid,myUid,KTestEventId); 
       
  5554         User::LeaveIfError(status);
       
  5555         }
       
  5556     else
       
  5557         {
       
  5558         User::LeaveIfError(status);
       
  5559         }
       
  5560     
       
  5561     CleanupStack::PopAndDestroy(eventProvider);
       
  5562     CleanupStack::PopAndDestroy(eventConsumer);
       
  5563     return status;    
       
  5564     }
       
  5565 
       
  5566 // -----------------------------------------------------------------------------
       
  5567 // OOM test for Event Provider
       
  5568 // -----------------------------------------------------------------------------
       
  5569 
       
  5570 TInt CMediatorTest::OOMForEventProviderTestL(TTestResult& aResult)
       
  5571     {
       
  5572     TInt ret = KErrNoMemory;
       
  5573     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5574         {
       
  5575         __UHEAP_RESET;
       
  5576         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5577         __UHEAP_MARK;
       
  5578         TRAP(ret, EventProviderTestL());
       
  5579         __UHEAP_MARKEND;
       
  5580         if (ret == KErrNone)
       
  5581             {
       
  5582             break;
       
  5583             }
       
  5584         }
       
  5585     __UHEAP_RESET;
       
  5586     aResult.SetResult(ret, _L("OOMForEventProviderTestL"));
       
  5587     return KErrNone;
       
  5588     }
       
  5589 
       
  5590 TInt CMediatorTest::EventProviderTestL()
       
  5591     {
       
  5592     TInt status(KErrNone);
       
  5593     TUid myUid = TUid::Uid(KTestUid);
       
  5594     TCapabilitySet caps;
       
  5595     caps.SetEmpty();
       
  5596     _LIT8(KTest, "TestTestTest");
       
  5597     HBufC8* data = KTest().AllocLC();
       
  5598        
       
  5599     CMediatorEventProvider* eventProvider;    
       
  5600     eventProvider = CMediatorEventProvider::NewL();
       
  5601     CleanupStack::PushL(eventProvider);
       
  5602   
       
  5603     status = eventProvider->RegisterEvent(myUid, myUid, KTestEventId,iDefaultVersion, caps); 
       
  5604     //RaiseEvent and Unregister only if event is registerd.
       
  5605     if( KErrNone == status || KErrMediatorEventAlreadyExists == status )
       
  5606         {
       
  5607         status = eventProvider->RaiseEvent(myUid,myUid,KTestEventId,iDefaultVersion,*data);
       
  5608         User::LeaveIfError(status);   
       
  5609         if( KErrNone == status )   
       
  5610             {
       
  5611             status = eventProvider->UnregisterEvent(myUid,myUid,KTestEventId); 
       
  5612             User::LeaveIfError(status);
       
  5613             }
       
  5614         }
       
  5615     else
       
  5616         {
       
  5617         User::LeaveIfError(status);
       
  5618         }
       
  5619     CleanupStack::PopAndDestroy(eventProvider);
       
  5620     CleanupStack::PopAndDestroy(data);
       
  5621     return status;
       
  5622     }
       
  5623 
       
  5624 // -----------------------------------------------------------------------------
       
  5625 // OOM test for Event provider with list of event
       
  5626 // -----------------------------------------------------------------------------
       
  5627 
       
  5628 TInt CMediatorTest::OOMForEventProviderwithListTestL(TTestResult& aResult)
       
  5629     {
       
  5630     TInt ret = KErrNoMemory;
       
  5631     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5632         {
       
  5633         __UHEAP_RESET;
       
  5634         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5635         __UHEAP_MARK;
       
  5636         TRAP(ret, EventProviderListEventTestL());
       
  5637         __UHEAP_MARKEND;
       
  5638         if (ret == KErrNone)
       
  5639             {
       
  5640             break;
       
  5641             }
       
  5642         }
       
  5643     __UHEAP_RESET;
       
  5644     aResult.SetResult(ret, _L("OOMForEventProviderwithListTestL"));
       
  5645     return KErrNone;
       
  5646     }
       
  5647 
       
  5648 TInt CMediatorTest::EventProviderListEventTestL()
       
  5649     {
       
  5650     TInt status(KErrNone);
       
  5651     TUid myUid = TUid::Uid(KTestUid);
       
  5652     TCapabilitySet caps;
       
  5653     caps.SetEmpty();  
       
  5654     
       
  5655     REventList eventList;
       
  5656     CleanupClosePushL(eventList);
       
  5657     for (TInt i = 1; i < 10; i++) // i = Event ID
       
  5658         {
       
  5659         TEvent newEvent;
       
  5660         newEvent.iEventId = i;
       
  5661         newEvent.iVersion = iDefaultVersion;
       
  5662         newEvent.iCaps = caps;
       
  5663         eventList.AppendL( newEvent );
       
  5664         }
       
  5665     
       
  5666     CMediatorEventProvider* eventProvider;    
       
  5667     eventProvider = CMediatorEventProvider::NewL();
       
  5668     CleanupStack::PushL(eventProvider);
       
  5669   
       
  5670     status = eventProvider->RegisterEvent(myUid, myUid, eventList); 
       
  5671     //Unregister only if event is registerd.
       
  5672     if( KErrNone == status || KErrMediatorEventAlreadyExists == status )
       
  5673         {
       
  5674         status = eventProvider->UnregisterEvent( myUid, myUid, eventList ); 
       
  5675         User::LeaveIfError(status);
       
  5676         }
       
  5677     else
       
  5678         {
       
  5679         User::LeaveIfError(status);
       
  5680         }
       
  5681     CleanupStack::PopAndDestroy(eventProvider);
       
  5682     CleanupStack::PopAndDestroy(&eventList);
       
  5683     
       
  5684     return status;
       
  5685     }
       
  5686 
       
  5687 // -----------------------------------------------------------------------------
       
  5688 // OOM test for Event consumer with list of event
       
  5689 // -----------------------------------------------------------------------------
       
  5690 
       
  5691 TInt CMediatorTest::OOMForEventConsumerWithEventTestL(TTestResult& aResult)
       
  5692     {
       
  5693     TInt ret = KErrNoMemory;
       
  5694     
       
  5695     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5696         {
       
  5697         __UHEAP_RESET;
       
  5698         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5699         __UHEAP_MARK;
       
  5700         TRAP(ret, EventConsumerWithEventTestL());
       
  5701         __UHEAP_MARKEND;
       
  5702         if (ret == KErrNone)
       
  5703             {
       
  5704             break;
       
  5705             }
       
  5706         }
       
  5707     __UHEAP_RESET;
       
  5708     aResult.SetResult(ret, _L("OOMForEventConsumerWithEventTestL"));
       
  5709     return KErrNone;
       
  5710     }
       
  5711 
       
  5712 TInt CMediatorTest::EventConsumerWithEventTestL()
       
  5713     {
       
  5714     TInt status(KErrNone);
       
  5715     TUid myUid = TUid::Uid(KTestUid);
       
  5716     TCapabilitySet caps;
       
  5717     caps.SetEmpty();
       
  5718     REventList eventList;
       
  5719     CleanupClosePushL(eventList);
       
  5720     for (TInt i = 1; i < 10; i++) // i = Event ID
       
  5721         {
       
  5722         TEvent newEvent;
       
  5723         newEvent.iEventId = i;
       
  5724         newEvent.iVersion = iDefaultVersion;
       
  5725         newEvent.iCaps = caps;
       
  5726         eventList.AppendL(newEvent);
       
  5727         }
       
  5728     CMediatorEventConsumer* eventConsumer;    
       
  5729     eventConsumer = CMediatorEventConsumer::NewL(iTestHelper);
       
  5730     CleanupStack::PushL(eventConsumer);
       
  5731     CMediatorEventProvider* eventProvider;    
       
  5732     eventProvider = CMediatorEventProvider::NewL();
       
  5733     CleanupStack::PushL( eventProvider );
       
  5734      
       
  5735     status = eventProvider->RegisterEvent(myUid, myUid, eventList);
       
  5736     if( KErrNone == status || KErrMediatorEventAlreadyExists == status )
       
  5737         {
       
  5738         status = eventConsumer->SubscribeEvent(myUid, myUid, eventList);
       
  5739         User::LeaveIfError( status );   
       
  5740         if( KErrNone == status )   
       
  5741             {
       
  5742             status = eventConsumer->UnsubscribeEvent( myUid, myUid, eventList );
       
  5743             User::LeaveIfError( status );
       
  5744             }
       
  5745         if( KErrNone == status )  
       
  5746             {
       
  5747             status = eventProvider->UnregisterEvent( myUid, myUid, eventList ); 
       
  5748             User::LeaveIfError( status );
       
  5749             }
       
  5750         }
       
  5751     else
       
  5752         {
       
  5753         User::LeaveIfError(status);
       
  5754         }
       
  5755     
       
  5756     CleanupStack::PopAndDestroy(eventProvider);
       
  5757     CleanupStack::PopAndDestroy(eventConsumer);
       
  5758     CleanupStack::PopAndDestroy(&eventList);
       
  5759     return status;    
       
  5760     }
       
  5761 
       
  5762 // -----------------------------------------------------------------------------
       
  5763 // OOM test for CommandInitiator 
       
  5764 // -----------------------------------------------------------------------------
       
  5765 
       
  5766 TInt CMediatorTest::OOMForCommandInitiatorTestL(TTestResult& aResult)
       
  5767     {
       
  5768     TInt ret = KErrNoMemory;
       
  5769     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5770         {
       
  5771         __UHEAP_RESET;
       
  5772         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5773         __UHEAP_MARK;
       
  5774         TRAP(ret, CommandInitiatorTestL());
       
  5775         __UHEAP_MARKEND;
       
  5776         if (ret == KErrNone)
       
  5777             {
       
  5778             break;
       
  5779             }
       
  5780         }
       
  5781     __UHEAP_RESET;
       
  5782     aResult.SetResult(ret, _L("OOMForCommandInitiatorTestL"));
       
  5783     return KErrNone;
       
  5784     }
       
  5785 
       
  5786 TInt CMediatorTest::CommandInitiatorTestL()
       
  5787     {
       
  5788     TInt status(KErrNone);
       
  5789     TUid myUid = TUid::Uid(KTestUid);
       
  5790     TCapabilitySet caps;
       
  5791     caps.SetEmpty();
       
  5792     _LIT8(KTest, "TestTestTest");
       
  5793     HBufC8* data = KTest().AllocLC();
       
  5794     CMediatorCommandResponder* commandResponder;    
       
  5795     commandResponder = CMediatorCommandResponder::NewL( iTestHelper );
       
  5796     CleanupStack::PushL(commandResponder);
       
  5797     
       
  5798     CMediatorCommandInitiator* commandInitiator;
       
  5799     commandInitiator = CMediatorCommandInitiator::NewL(iTestHelper);
       
  5800     CleanupStack::PushL(commandInitiator);
       
  5801     
       
  5802     status = commandResponder->RegisterCommand(myUid, myUid, KDefaultCommandId, iDefaultVersion, caps, KDefaultTimeOut);
       
  5803     if( KErrNone == status || KErrMediatorCommandAlreadyExists == status )
       
  5804         {
       
  5805         status = commandInitiator->IssueCommand(myUid, myUid, KDefaultCommandId, iDefaultVersion, *data);
       
  5806         User::LeaveIfError( status );   
       
  5807         if( KErrNone == status )   
       
  5808             {
       
  5809             _LIT8(KTestResponse, "Command response");
       
  5810             HBufC8* replyData = KTestResponse().AllocLC();
       
  5811             status = commandResponder->IssueResponse( myUid, myUid, KDefaultCommandId,KErrNone,*replyData );
       
  5812             User::LeaveIfError( status );
       
  5813             CleanupStack::PopAndDestroy(replyData);
       
  5814             }
       
  5815         if( KErrNone == status )  
       
  5816             {
       
  5817             status = commandResponder->UnregisterCommand( myUid, myUid, KDefaultCommandId );
       
  5818             User::LeaveIfError( status );
       
  5819             }
       
  5820         }
       
  5821     else
       
  5822         {
       
  5823         User::LeaveIfError(status);
       
  5824         }
       
  5825 
       
  5826     CleanupStack::PopAndDestroy(commandInitiator);
       
  5827     CleanupStack::PopAndDestroy(commandResponder);
       
  5828     CleanupStack::PopAndDestroy(data);
       
  5829     return status;
       
  5830     }
       
  5831 
       
  5832 // -----------------------------------------------------------------------------
       
  5833 // OOM test for CommandInitiator with list of commands
       
  5834 // -----------------------------------------------------------------------------
       
  5835 
       
  5836 TInt CMediatorTest::OOMForCommandInitiatorCommandListTestL(TTestResult& aResult)
       
  5837     {
       
  5838     TInt ret = KErrNoMemory;
       
  5839     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5840         {
       
  5841         __UHEAP_RESET;
       
  5842         __UHEAP_SETFAIL(RHeap::EDeterministic,allocFailRate);
       
  5843         __UHEAP_MARK;
       
  5844         TRAP(ret, CommandInitiatorCommandListTestL());
       
  5845         __UHEAP_MARKEND;
       
  5846         if (ret == KErrNone)
       
  5847             {
       
  5848             break;
       
  5849             }
       
  5850         }
       
  5851     __UHEAP_RESET;
       
  5852     aResult.SetResult(ret, _L("OOMForCommandInitiatorCommandListTestL"));
       
  5853     return KErrNone;
       
  5854     }
       
  5855 
       
  5856 TInt CMediatorTest::CommandInitiatorCommandListTestL()
       
  5857     {
       
  5858     TInt status(KErrNone);
       
  5859     TUid myUid = TUid::Uid(KTestUid);
       
  5860     TCapabilitySet caps;
       
  5861     caps.SetEmpty();
       
  5862     //command list
       
  5863     RCommandList  commandList;
       
  5864     CleanupClosePushL(commandList);    
       
  5865     for ( TInt index = 1; index < 10; index++ )
       
  5866         {
       
  5867          MediatorService::TCommand newCommand;
       
  5868          newCommand.iCommandId = index;
       
  5869          newCommand.iVersion = iDefaultVersion;
       
  5870          newCommand.iCaps = caps;
       
  5871          newCommand.iTimeout = KDefaultTimeOut;
       
  5872          commandList.AppendL( newCommand );
       
  5873         }
       
  5874     CMediatorCommandResponder* commandResponder;    
       
  5875     commandResponder = CMediatorCommandResponder::NewL( iTestHelper );
       
  5876     CleanupStack::PushL(commandResponder);
       
  5877     
       
  5878     status = commandResponder->RegisterCommand(myUid, myUid, commandList);
       
  5879     if( KErrNone == status || KErrMediatorCommandAlreadyExists == status )
       
  5880         {
       
  5881         status = commandResponder->UnregisterCommand( myUid, myUid, commandList );
       
  5882         User::LeaveIfError(status);
       
  5883         }
       
  5884     else
       
  5885         {
       
  5886         User::LeaveIfError( status );
       
  5887         }
       
  5888     
       
  5889     CleanupStack::PopAndDestroy(commandResponder);
       
  5890     CleanupStack::PopAndDestroy(&commandList);
       
  5891    
       
  5892     return status;
       
  5893     }
       
  5894 
       
  5895 // -----------------------------------------------------------------------------
       
  5896 // OOM test for MediatorNotifications
       
  5897 // -----------------------------------------------------------------------------
       
  5898 
       
  5899 TInt CMediatorTest::OOMForMediatorNotificationsTestL( TTestResult& aResult )
       
  5900     {
       
  5901     TInt ret = KErrNoMemory;
       
  5902     for (TInt allocFailRate = 1;; allocFailRate++)
       
  5903         {
       
  5904         __UHEAP_RESET;
       
  5905         __UHEAP_SETFAIL( RHeap::EDeterministic,allocFailRate );
       
  5906         __UHEAP_MARK;
       
  5907         TRAP(ret, CMediatorNotificationsTestL());
       
  5908         __UHEAP_MARKEND;
       
  5909         if ( ret == KErrNone )
       
  5910             {
       
  5911             break;
       
  5912             }
       
  5913         }
       
  5914     __UHEAP_RESET;
       
  5915     aResult.SetResult(ret, _L("OOMForMediatorNotificationsTestL"));
       
  5916     return KErrNone;
       
  5917     }
       
  5918 
       
  5919 TInt CMediatorTest::CMediatorNotificationsTestL()
       
  5920     {
       
  5921     TInt status(KErrNone);
       
  5922     TUid myUid = TUid::Uid(KTestUid);
       
  5923     TCapabilitySet caps;
       
  5924     caps.SetEmpty();
       
  5925     
       
  5926     iTestHelper->ClearAllNotifyData();
       
  5927     CMediatorNotifications* notifyMe = CMediatorNotifications::NewL();
       
  5928     CleanupStack::PushL( notifyMe );
       
  5929     status = notifyMe->RegisterNotificationObserver( iTestHelper );
       
  5930     if( KErrNone == status  )
       
  5931         {
       
  5932         REventList eventList;
       
  5933         CleanupClosePushL( eventList );
       
  5934         
       
  5935         CMediatorEventProvider* eventProvider;    
       
  5936         eventProvider = CMediatorEventProvider::NewL();
       
  5937         CleanupStack::PushL( eventProvider );
       
  5938              
       
  5939         for( TInt i=0; i<5; i++ ) // Create list of events (i = event ID)
       
  5940             {
       
  5941             TEvent newEvent;
       
  5942             newEvent.iEventId = i;
       
  5943             newEvent.iVersion = iDefaultVersion;
       
  5944             newEvent.iCaps = caps;    
       
  5945             eventList.AppendL( newEvent );
       
  5946             }
       
  5947         
       
  5948         status = eventProvider->RegisterEvent( myUid, myUid, eventList );
       
  5949         if( KErrNoMemory == status )
       
  5950              {
       
  5951              User::LeaveIfError( status );
       
  5952              }
       
  5953         CTestScheduler::StartAndStopL( 2000 );
       
  5954         status = eventProvider->UnregisterEvent( myUid, myUid, eventList );
       
  5955         if( KErrNoMemory == status )
       
  5956              {
       
  5957              User::LeaveIfError( status );
       
  5958              }
       
  5959         CleanupStack::PopAndDestroy( eventProvider );
       
  5960         CleanupStack::PopAndDestroy( &eventList );
       
  5961         }
       
  5962     else
       
  5963         {
       
  5964         User::LeaveIfError( status );
       
  5965         }
       
  5966     status = notifyMe->UnregisterNotificationObserver();
       
  5967     if( KErrNoMemory == status )
       
  5968         {
       
  5969         User::LeaveIfError( status );
       
  5970         }
       
  5971     iTestHelper->ClearAllNotifyData();
       
  5972     CleanupStack::PopAndDestroy( notifyMe );
       
  5973     return status;
       
  5974     }
       
  5975 
       
  5976 //  End of File