idlefw/tsrc/framework/ut_aifw/ut_aipluginfactory/src/ut_aipluginfactory.cpp
branchRCL_3
changeset 27 2c7f27287390
equal deleted inserted replaced
25:9e077f9a342c 27:2c7f27287390
       
     1 /*
       
     2 * Copyright (c) 2004 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: EUnit unit test class for CAiPluginFactory
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 #include <e32cmn.h> 
       
    21 #include <bautils.h>
       
    22 #include <digia/eunit/eunitmacros.h>
       
    23 #include <digia/eunit/teunitassertioninfo.h>
       
    24 
       
    25 // User includes
       
    26 #include <hspublisherinfo.h>
       
    27 #include "ut_aipluginfactory.h"
       
    28 #include "aiuicontrollermanager_stub.h"
       
    29 
       
    30 #include "aipluginfactory.h"
       
    31 #include "aifwpublisherinfo.h"
       
    32 #include "aistatemanager.h"
       
    33 
       
    34 // Constants
       
    35 _LIT( KProfile, "Profile" );
       
    36 _LIT( KDevstat, "DeviceStatus");
       
    37 _LIT( KUnknown, "Unknown" );
       
    38 _LIT( KOrganizer, "Organizer" );
       
    39 
       
    40 const TInt KProfileUid( 0x10275101 );
       
    41 const TInt KDevstatUid( 0x102750F8 );
       
    42 const TInt KUnknownUid( 0xBABE2BED );
       
    43 const TInt KOrganizerUid( 0x102750FE );
       
    44 const TInt KDestroyDelay( 600000 );
       
    45 _LIT8( KNs1, "namespace1" );
       
    46 _LIT8( KNs2, "namespace2" );
       
    47 
       
    48 // ======== LOCAL FUNCTIONS ========
       
    49     
       
    50 // ======== MEMBER FUNCTIONS =======
       
    51 // ----------------------------------------------------------------------------
       
    52 // UT_AiPluginFactory::NewL()
       
    53 //
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 UT_AiPluginFactory* UT_AiPluginFactory::NewL()
       
    57     {
       
    58     UT_AiPluginFactory* self = UT_AiPluginFactory::NewLC();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // UT_AiPluginFactory::NewLC()
       
    65 //
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 UT_AiPluginFactory* UT_AiPluginFactory::NewLC()
       
    69     {
       
    70     UT_AiPluginFactory* self = new ( ELeave ) UT_AiPluginFactory();
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // UT_AiPluginFactory::~UT_AiPluginFactory()
       
    78 //
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 UT_AiPluginFactory::~UT_AiPluginFactory()
       
    82     {    
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // UT_AiPluginFactory::UT_AiPluginFactory()
       
    87 //
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 UT_AiPluginFactory::UT_AiPluginFactory()
       
    91     {
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // UT_AiPluginFactory::ConstructL()
       
    96 //
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 void UT_AiPluginFactory::ConstructL()
       
   100     {
       
   101     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   102     // It generates the test case table.
       
   103     CEUnitTestSuiteClass::ConstructL();
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // UT_AiPluginFactory::SetupL()
       
   108 //
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 void UT_AiPluginFactory::SetupL()
       
   112     {
       
   113     iUiMgr = CAiUiControllerManager::NewL();
       
   114     
       
   115     iFactory = CAiPluginFactory::NewL( *iUiMgr );
       
   116     iFactory->ConstructL();
       
   117     
       
   118     iStateManager = CAiStateManager::NewL( *iFactory );
       
   119     
       
   120     iWait = new ( ELeave ) CActiveSchedulerWait;
       
   121     
       
   122     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   123     
       
   124     iResult = KErrNone;
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // UT_AiPluginFactory::Teardown()
       
   129 //
       
   130 // ----------------------------------------------------------------------------
       
   131 //
       
   132 void UT_AiPluginFactory::Teardown()
       
   133     {    
       
   134     delete iFactory;
       
   135     iFactory = NULL;
       
   136 
       
   137     delete iUiMgr;
       
   138     iUiMgr = NULL;
       
   139     
       
   140     delete iStateManager;
       
   141     iStateManager = NULL;
       
   142     
       
   143     if ( iPeriodic->IsActive() )
       
   144         {
       
   145         iPeriodic->Cancel();
       
   146         }
       
   147     delete iPeriodic;
       
   148     iPeriodic = NULL;
       
   149     
       
   150     if ( iWait->IsStarted() )
       
   151         {
       
   152         iWait->AsyncStop();
       
   153         }
       
   154     delete iWait;
       
   155     iWait = NULL;
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // UT_AiPluginFactory::TestCreateDestroyPluginL()
       
   160 //
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 void UT_AiPluginFactory::TestCreateDestroyPluginL()
       
   164     {
       
   165     THsPublisherInfo data( 
       
   166         TUid::Uid( KOrganizerUid ), KOrganizer, KNs1 );
       
   167 
       
   168     THsPublisherInfo profile( 
       
   169         TUid::Uid( KProfileUid ), KProfile, KNs2 );
       
   170 
       
   171     THsPublisherInfo devstat( 
       
   172         TUid::Uid( KDevstatUid ), KDevstat, KNs2 );
       
   173 
       
   174     THsPublisherInfo missing( 
       
   175         TUid::Uid( KProfileUid ), KProfile, KNullDesC8 );
       
   176 
       
   177     THsPublisherInfo unknown( 
       
   178         TUid::Uid( KUnknownUid ), KUnknown, KNs1 );
       
   179 
       
   180     // create 2 same without waiting first to finnish. Second should return
       
   181     // KErrAlreadyExists
       
   182     TAiFwPublisherInfo info( data, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   183     iFactory->LoadPlugin( info );
       
   184     iFactory->LoadPlugin( info );
       
   185     iWait->Start();
       
   186     EUNIT_ASSERT_EQUALS( iResult, KErrAlreadyExists );
       
   187     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) != NULL, ETrue );
       
   188     
       
   189     // wait for destroy to finnish
       
   190     iFactory->DestroyPlugin( info );
       
   191     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   192     iWait->Start();
       
   193     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) == NULL, ETrue );
       
   194     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 0 );
       
   195     
       
   196     // create 2 same and wait first to finnish. Second should return
       
   197     // KErrAlreadyExists
       
   198     iFactory->LoadPlugin( info );
       
   199     iWait->Start();
       
   200     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   201     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) != NULL, ETrue );
       
   202 
       
   203     iFactory->LoadPlugin( info );
       
   204     iWait->Start();
       
   205     EUNIT_ASSERT_EQUALS( iResult, KErrAlreadyExists );
       
   206     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) != NULL, ETrue );
       
   207 
       
   208     // Test missing namespace
       
   209     TAiFwPublisherInfo missingInfo( missing, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   210     iFactory->LoadPlugin( missingInfo );
       
   211     iWait->Start();
       
   212     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported );
       
   213     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( missing ) == NULL, ETrue );
       
   214 
       
   215     // Test unknown
       
   216     TAiFwPublisherInfo unknownInfo( unknown, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   217     iFactory->LoadPlugin( unknownInfo );
       
   218     iWait->Start();
       
   219     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported );
       
   220     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( unknown ) == NULL, ETrue );
       
   221 
       
   222     //profile
       
   223     TAiFwPublisherInfo profileInfo( profile, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   224     iFactory->LoadPlugin( profileInfo );
       
   225     iWait->Start();
       
   226     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   227     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue );
       
   228 
       
   229     // Create devstat
       
   230     TAiFwPublisherInfo devstatInfo( devstat, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   231     iFactory->LoadPlugin( devstatInfo );
       
   232     iWait->Start();
       
   233     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   234     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue );
       
   235 
       
   236     // Test that Devstat is recycled by creating exactly same plugin again
       
   237     iFactory->LoadPlugin( devstatInfo );
       
   238     iWait->Start();
       
   239     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   240     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue );
       
   241 
       
   242     // wait for destroy to finnish
       
   243     iFactory->DestroyPlugin( info );
       
   244     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   245     iWait->Start();
       
   246     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) == NULL, ETrue );
       
   247 
       
   248     // Test profile recycle, it won't be deleted
       
   249     iFactory->DestroyPlugin( profileInfo );
       
   250     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   251     iWait->Start();
       
   252     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile ) != NULL, ETrue );
       
   253 
       
   254     // Test devstat recycle, it won't be deleted
       
   255     iFactory->DestroyPlugin( devstatInfo );
       
   256     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   257     iWait->Start();
       
   258     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( devstat ) != NULL, ETrue );
       
   259 
       
   260     // Try destroying unknown
       
   261     iFactory->DestroyPlugin( unknownInfo );
       
   262     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   263     iWait->Start();
       
   264     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( unknown ) == NULL, ETrue );
       
   265 
       
   266     iFactory->Publishers().ResetAndDestroy();
       
   267     }
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // UT_AiPluginFactory::TestCreateDestroyPluginL()
       
   271 //
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 void UT_AiPluginFactory::TestCreateDestroyAllL()
       
   275     {
       
   276     THsPublisherInfo data( 
       
   277     TUid::Uid( KOrganizerUid ), KOrganizer, KNs1 );
       
   278     
       
   279     TAiFwPublisherInfo info( data, TAiFwCallback( CallBack, this ), EAiFwSystemStartup );
       
   280     iFactory->LoadPlugin( info );
       
   281     iWait->Start();
       
   282     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   283     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) != NULL, ETrue );
       
   284     
       
   285     //destroy using uid
       
   286     iFactory->DestroyPlugin( info.Info().Uid() );
       
   287     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   288     iWait->Start();
       
   289     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) == NULL, ETrue );
       
   290     
       
   291     iFactory->LoadPlugin( info );
       
   292     iWait->Start();
       
   293     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   294     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) != NULL, ETrue );
       
   295     
       
   296     iFactory->DestroyAllPlugins();
       
   297     iPeriodic->Start( KDestroyDelay*2, KDestroyDelay*2, TCallBack( TimerCallBack, this ) );
       
   298     iWait->Start();
       
   299     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( data ) == NULL, ETrue );
       
   300     }
       
   301 // ----------------------------------------------------------------------------
       
   302 // UT_AiPluginFactory::TestPluginByInfoL()
       
   303 //
       
   304 // ----------------------------------------------------------------------------
       
   305 //
       
   306 void UT_AiPluginFactory::TestPluginByInfoL()
       
   307     {
       
   308     THsPublisherInfo profile1( 
       
   309         TUid::Uid( KProfileUid ), KProfile, KNs1 );
       
   310     
       
   311     THsPublisherInfo profile2( 
       
   312         TUid::Uid( KProfileUid ), KProfile, KNs2 );
       
   313 
       
   314     THsPublisherInfo missing( 
       
   315         TUid::Uid( KProfileUid ), KProfile, KNullDesC8 );
       
   316 
       
   317     THsPublisherInfo unknown(
       
   318         TUid::Uid( KUnknownUid ), KUnknown, KNs1 );
       
   319 
       
   320     TAiFwPublisherInfo profile1Info( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   321     iFactory->LoadPlugin( profile1Info );
       
   322     iWait->Start();
       
   323     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   324 
       
   325     TAiFwPublisherInfo profile2Info( profile2, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   326     iFactory->LoadPlugin( profile2Info );
       
   327     iWait->Start();
       
   328     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   329 
       
   330     TAiFwPublisherInfo missingInfo( missing, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   331     iFactory->LoadPlugin( missingInfo );
       
   332     iWait->Start();
       
   333     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported )
       
   334     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( missing ) == NULL, ETrue );
       
   335 
       
   336     TAiFwPublisherInfo unknownInfo( unknown, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   337     iFactory->LoadPlugin( unknownInfo );
       
   338     iWait->Start();
       
   339     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported )
       
   340     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( unknown ) == NULL, ETrue );
       
   341 
       
   342     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile1 ) == NULL, ETrue );
       
   343     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile2 ) != NULL, ETrue );
       
   344 
       
   345     // Because profile2 is recycled, it won't be deleted
       
   346     profile2Info = TAiFwPublisherInfo( profile2, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   347     iFactory->DestroyPlugin( profile2Info );
       
   348     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   349     iWait->Start();
       
   350     EUNIT_ASSERT_EQUALS( iFactory->PluginByInfo( profile2 ) != NULL, ETrue );
       
   351 
       
   352     iFactory->Publishers().ResetAndDestroy();
       
   353     }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 // UT_AiPluginFactory::TestPluginByUidL()
       
   357 //
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void UT_AiPluginFactory::TestPluginByUidL()
       
   361     {
       
   362     THsPublisherInfo profile1( 
       
   363         TUid::Uid( KProfileUid ), KProfile, KNs1 );
       
   364 
       
   365     THsPublisherInfo unknown(
       
   366         TUid::Uid( KUnknownUid ), KUnknown, KNs1 );
       
   367 
       
   368     TAiFwPublisherInfo profile1Info( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   369     iFactory->LoadPlugin( profile1Info );
       
   370     iWait->Start();
       
   371     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   372 
       
   373     TAiFwPublisherInfo unknownInfo( unknown, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   374     iFactory->LoadPlugin( unknownInfo );
       
   375     iWait->Start();
       
   376     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported );
       
   377         
       
   378     EUNIT_ASSERT_EQUALS( iFactory->PluginByUid( unknown.Uid() ) == NULL, ETrue );
       
   379     EUNIT_ASSERT_EQUALS( iFactory->PluginByUid( profile1.Uid() ) != NULL, ETrue );
       
   380 
       
   381     // Because profile1 is recycled, it won't be deleted
       
   382     profile1Info = TAiFwPublisherInfo( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   383     iFactory->DestroyPlugin( profile1Info );
       
   384     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   385     iWait->Start();
       
   386     EUNIT_ASSERT_EQUALS( iFactory->PluginByUid( profile1.Uid() ) != NULL, ETrue );
       
   387 
       
   388     iFactory->Publishers().ResetAndDestroy();
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // UT_AiPluginFactory::TestPluginByNameL()
       
   393 //
       
   394 // ----------------------------------------------------------------------------
       
   395 //
       
   396 void UT_AiPluginFactory::TestPluginByNameL()
       
   397     {
       
   398     THsPublisherInfo profile1( 
       
   399         TUid::Uid( KProfileUid ), KProfile, KNs1 );
       
   400 
       
   401     THsPublisherInfo unknown(
       
   402         TUid::Uid( KUnknownUid ), KUnknown, KNs1 );
       
   403 
       
   404     TAiFwPublisherInfo profile1Info( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   405     iFactory->LoadPlugin( profile1Info );
       
   406     iWait->Start();
       
   407     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   408 
       
   409     TAiFwPublisherInfo unknownInfo( unknown, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   410     iFactory->LoadPlugin( unknownInfo );
       
   411     iWait->Start();
       
   412     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported );
       
   413 
       
   414     EUNIT_ASSERT_EQUALS( iFactory->PluginByName( unknown.Name() ) == NULL, ETrue );
       
   415     EUNIT_ASSERT_EQUALS( iFactory->PluginByName( profile1.Name() ) != NULL, ETrue );
       
   416 
       
   417     // Because profile1 is recycled, it won't be deleted
       
   418     profile1Info = TAiFwPublisherInfo( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   419     iFactory->DestroyPlugin( profile1Info );
       
   420     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   421     iWait->Start();
       
   422     EUNIT_ASSERT_EQUALS( iFactory->PluginByName( profile1.Name() ) != NULL, ETrue );
       
   423 
       
   424     iFactory->Publishers().ResetAndDestroy();
       
   425     }
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // UT_AiPluginFactory::TestGetPublishersL()
       
   429 //
       
   430 // ----------------------------------------------------------------------------
       
   431 //
       
   432 void UT_AiPluginFactory::TestGetPublishersL()
       
   433     {      
       
   434     THsPublisherInfo profile1( 
       
   435         TUid::Uid( KProfileUid ), KProfile, KNs1 );
       
   436     
       
   437     THsPublisherInfo profile2( 
       
   438         TUid::Uid( KProfileUid ), KProfile, KNs2 );
       
   439     
       
   440     THsPublisherInfo unknown(
       
   441         TUid::Uid( KUnknownUid ), KUnknown, KNs1 );
       
   442     
       
   443     THsPublisherInfo data( 
       
   444         TUid::Uid( KOrganizerUid ), KOrganizer, KNs1 );
       
   445 
       
   446     
       
   447     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 0 );
       
   448         
       
   449     TAiFwPublisherInfo profile1Info( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   450     iFactory->LoadPlugin( profile1Info );
       
   451     iWait->Start();
       
   452     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   453     
       
   454     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 1 );
       
   455     
       
   456     TAiFwPublisherInfo dataInfo( data, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   457     iFactory->LoadPlugin( dataInfo );
       
   458     iWait->Start();
       
   459     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   460         
       
   461     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 2 );
       
   462     
       
   463     TAiFwPublisherInfo profile2Info( profile2, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   464     iFactory->LoadPlugin( profile2Info );
       
   465     iWait->Start();
       
   466     EUNIT_ASSERT_EQUALS( iResult, KErrNone );
       
   467            
       
   468     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 2 );
       
   469     
       
   470     TAiFwPublisherInfo unknownInfo( unknown, TAiFwCallback( CallBack, this ), EAiFwPluginStartup );
       
   471     iFactory->LoadPlugin( unknownInfo );
       
   472     iWait->Start();
       
   473     EUNIT_ASSERT_EQUALS( iResult, KErrNotSupported );
       
   474     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 2 );
       
   475     
       
   476     profile1Info = TAiFwPublisherInfo( profile1, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   477     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   478     iWait->Start();
       
   479     iFactory->DestroyPlugin( profile1Info );
       
   480     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 2 );
       
   481     
       
   482     profile2Info = TAiFwPublisherInfo( profile2, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   483     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   484     iWait->Start();
       
   485     iFactory->DestroyPlugin( profile2Info );
       
   486     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 2 );
       
   487     
       
   488     dataInfo = TAiFwPublisherInfo( data, TAiFwCallback( CallBack, this ), EAiFwPluginShutdown );
       
   489     iFactory->DestroyPlugin( dataInfo );
       
   490     iPeriodic->Start( KDestroyDelay, KDestroyDelay, TCallBack( TimerCallBack, this ) );
       
   491     iWait->Start();
       
   492     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 1 );
       
   493         
       
   494     iFactory->Publishers().ResetAndDestroy();
       
   495     EUNIT_ASSERT_EQUALS( iFactory->Publishers().Count(), 0 );
       
   496     }
       
   497 
       
   498 // ----------------------------------------------------------------------------
       
   499 // UT_AiPluginFactory::TestUpgradePublishersL()
       
   500 //
       
   501 // ----------------------------------------------------------------------------
       
   502 //
       
   503 void UT_AiPluginFactory::TestUpgradePublishersL()
       
   504     {
       
   505     RArray< THsPublisherInfo > array;
       
   506     CleanupClosePushL( array );
       
   507 
       
   508     CleanupStack::PopAndDestroy( &array );
       
   509     }
       
   510 
       
   511 // ----------------------------------------------------------------------------
       
   512 // CAiPluginFactory::CallBack()
       
   513 //
       
   514 // ----------------------------------------------------------------------------
       
   515 //
       
   516 void UT_AiPluginFactory::CallBack( TAny* aPtr, TInt aResult )
       
   517     {
       
   518     UT_AiPluginFactory* self = static_cast< UT_AiPluginFactory* >( aPtr );
       
   519     self->iResult = aResult;
       
   520     self->iWait->AsyncStop();
       
   521     }
       
   522 
       
   523 // ----------------------------------------------------------------------------
       
   524 // CAiPluginFactory::TimerCallBack
       
   525 //
       
   526 // ----------------------------------------------------------------------------
       
   527 //
       
   528 TInt UT_AiPluginFactory::TimerCallBack( TAny* aPtr )
       
   529     {
       
   530     UT_AiPluginFactory* self = static_cast< UT_AiPluginFactory* >( aPtr );
       
   531     
       
   532     if ( self->iPeriodic->IsActive() )
       
   533         {
       
   534         self->iPeriodic->Cancel();
       
   535         }
       
   536     
       
   537     self->iWait->AsyncStop();
       
   538     return KErrNone;
       
   539     }
       
   540 
       
   541 
       
   542 //-----------------------------------------------------------------------------
       
   543 // Test case table
       
   544 //
       
   545 //-----------------------------------------------------------------------------
       
   546 //
       
   547 EUNIT_BEGIN_TEST_TABLE(
       
   548     UT_AiPluginFactory,
       
   549     "Unit test suite for CAiPluginFactory",
       
   550     "UNIT" )
       
   551 
       
   552     EUNIT_TEST(
       
   553         "Create/Destroy Plugin",
       
   554         "CAiPluginFactory",
       
   555         "",
       
   556         "FUNCTIONALITY",
       
   557         SetupL, TestCreateDestroyPluginL, Teardown )
       
   558     
       
   559     EUNIT_TEST(
       
   560         "Create/Destroy All",
       
   561         "CAiPluginFactory",
       
   562         "",
       
   563         "FUNCTIONALITY",
       
   564         SetupL, TestCreateDestroyAllL, Teardown )
       
   565     
       
   566     EUNIT_TEST(
       
   567         "PluginByInfo",
       
   568         "CAiPluginFactory",
       
   569         "",
       
   570         "FUNCTIONALITY",
       
   571         SetupL, TestPluginByInfoL, Teardown )
       
   572     
       
   573     EUNIT_TEST(
       
   574         "PluginByUid",
       
   575         "CAiPluginFactory",
       
   576         "",
       
   577         "FUNCTIONALITY",
       
   578         SetupL, TestPluginByUidL, Teardown )
       
   579     
       
   580     EUNIT_TEST(
       
   581         "PluginByName",
       
   582         "CAiPluginFactory",
       
   583         "",
       
   584         "FUNCTIONALITY",
       
   585         SetupL, TestPluginByNameL, Teardown )
       
   586         
       
   587     EUNIT_TEST(
       
   588         "Get Publishers",
       
   589         "CAiPluginFactory",
       
   590         "",
       
   591         "FUNCTIONALITY",
       
   592         SetupL, TestGetPublishersL, Teardown )
       
   593 
       
   594     EUNIT_TEST(
       
   595         "Upgrade Publishers",
       
   596         "CAiPluginFactory",
       
   597         "",
       
   598         "FUNCTIONALITY",
       
   599         SetupL, TestUpgradePublishersL, Teardown )
       
   600         
       
   601 EUNIT_END_TEST_TABLE
       
   602 
       
   603 // End of file