photosgallery/viewframework/commandhandlers/commandhandlerupnp/tsrc/t_cglxcommandhandlershowviaupnp/src/t_cglxcommandhandlershowviaupnp.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CommandHandlerShowViaUPnP unit test cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "t_cglxcommandhandlershowviaupnp.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 #include <digia/eunit/eunitdecorators.h>
       
    27 
       
    28 #include <glxcommandhandlers.hrh>
       
    29 #include <mglxmedialist.h>
       
    30 #include <upnpshowcommand.h>
       
    31 
       
    32 //  INTERNAL INCLUDES
       
    33 #include "glxupnprenderer.h" 
       
    34 
       
    35 class _CGlxTestMediaList: public CBase, public MGlxMediaList
       
    36     {
       
    37 public:
       
    38     ~_CGlxTestMediaList() 
       
    39         {
       
    40         iItems.Close();
       
    41         iMedia.ResetAndDestroy();
       
    42         iSelectedItems.Close();
       
    43         }
       
    44         
       
    45     virtual void Close() 
       
    46         {
       
    47         };
       
    48     virtual TGlxMediaListId Id() const 
       
    49         {
       
    50         return KGlxIdNone;
       
    51         }
       
    52 
       
    53     virtual TInt Count(NGlxListDefs::TCountType /*aType*/) const 
       
    54         {
       
    55         return iItems.Count();
       
    56         }
       
    57     
       
    58     virtual TInt FocusIndex() const 
       
    59         {
       
    60         return iFocusIndex;
       
    61         }
       
    62 
       
    63     virtual void SetFocusL(NGlxListDefs::TFocusSetType /*aType*/, TInt aValue) 
       
    64         {
       
    65         iFocusIndex = aValue;
       
    66         }
       
    67     
       
    68     virtual const TGlxMedia& Item(TInt aIndex) const 
       
    69         {
       
    70         return iItems[aIndex];
       
    71         }
       
    72 
       
    73     virtual TInt Index(const TGlxIdSpaceId& /* aIdSpaceId */, const TGlxMediaId& aId) const 
       
    74         {
       
    75         TInt count = iItems.Count();
       
    76         for (TInt i = 0; i < count; i++)
       
    77             {
       
    78             if (iItems[i].Id() == aId)
       
    79                 {
       
    80                 return i;
       
    81                 }
       
    82             }
       
    83         return KErrNotFound;
       
    84         }
       
    85     
       
    86     virtual void AddMediaListObserverL(MGlxMediaListObserver* /*aObserver*/) 
       
    87         {
       
    88         }
       
    89     
       
    90     virtual void RemoveMediaListObserver(MGlxMediaListObserver* /*aObserver*/) 
       
    91         {
       
    92         }
       
    93 
       
    94     virtual void AddContextL(const MGlxFetchContext* /*aContext*/, TInt /*aPriority*/) 
       
    95         {
       
    96         }
       
    97 
       
    98     virtual void RemoveContext(const MGlxFetchContext* /*aContext*/) 
       
    99         {
       
   100         }
       
   101     
       
   102     virtual MMPXCollection& Collection() const 
       
   103         {
       
   104         // we know that this method is not called in our tests, this is just to make the code compile
       
   105         MMPXCollection* empty = NULL;
       
   106         return *empty;
       
   107         }
       
   108 
       
   109     virtual TBool IsSelected(TInt aIndex) const 
       
   110         {
       
   111         TInt idx = iSelectedItems.Find(aIndex);
       
   112         return (idx != KErrNotFound);
       
   113         }
       
   114 
       
   115     virtual void SetSelectedL(TInt aIndex, TBool aSelected) 
       
   116         {
       
   117         if (aSelected)
       
   118             {
       
   119             iSelectedItems.InsertInOrder(aIndex);
       
   120             }
       
   121         else 
       
   122             {
       
   123             iSelectedItems.Remove(iSelectedItems.Find(aIndex));
       
   124             }
       
   125         }
       
   126 
       
   127     virtual const TArray<TInt> Selection() const 
       
   128         {
       
   129         return iSelectedItems.Array();
       
   130         }
       
   131 
       
   132     virtual void CommandL(CMPXCommand& /*aCommand*/) 
       
   133         {
       
   134         }
       
   135 
       
   136     virtual void CancelCommand() 
       
   137         {
       
   138         }
       
   139 
       
   140     virtual void SetFilterL(CMPXFilter* /*aFilter*/) 
       
   141         {
       
   142         }
       
   143 
       
   144     virtual CMPXFilter* Filter() const 
       
   145         {
       
   146         return NULL;
       
   147         }
       
   148 
       
   149     virtual TGlxIdSpaceId IdSpaceId(TInt /*aIndex*/) const 
       
   150         {
       
   151         return KGlxIdNone;
       
   152         }
       
   153     
       
   154     void AppendL(TInt aId, TBool aCreateMedia) 
       
   155         {
       
   156         if (aCreateMedia) 
       
   157             {
       
   158             CGlxMedia* media = new (ELeave) CGlxMedia(TGlxMediaId(aId));
       
   159             CleanupStack::PushL(media);
       
   160             iMedia.AppendL(media);
       
   161             CleanupStack::Pop(media);
       
   162             iItems.AppendL(TGlxMedia(TGlxMediaId(aId), media));
       
   163             }
       
   164         else 
       
   165             {
       
   166             iItems.AppendL(TGlxMedia(TGlxMediaId(aId)));
       
   167             }
       
   168         }
       
   169         
       
   170     CGlxMedia* MediaObj(TInt aIndex) const 
       
   171         {
       
   172         return const_cast<CGlxMedia*>(static_cast<const CGlxMedia*>(iItems[aIndex].Properties()));
       
   173         }
       
   174         
       
   175     CMPXCollectionPath* PathLC(NGlxListDefs::TPathType /*aType*/) const
       
   176         {
       
   177         return NULL;
       
   178         }
       
   179     
       
   180     TInt SelectionCount() const
       
   181         {
       
   182         return iSelectedItems.Count();
       
   183         }
       
   184         
       
   185     TInt SelectedItemIndex(TInt /*aSelectionIndex*/) const
       
   186         {
       
   187         return 0;
       
   188         }
       
   189         
       
   190     TBool IsPopulated() const
       
   191         {
       
   192         return ETrue;
       
   193         }
       
   194     
       
   195     void AddStaticItemL( CGlxMedia* /*aStaticItem*/,
       
   196         NGlxListDefs::TInsertionPosition /*aTargetPosition*/ ) {};
       
   197     
       
   198     void RemoveStaticItem(const TGlxMediaId& /*aItemId*/) {};
       
   199     
       
   200     void SetStaticItemsEnabled( TBool aEnabled ) { iStaticItemsEnabled = aEnabled; };
       
   201     
       
   202     TBool IsStaticItemsEnabled() const { return iStaticItemsEnabled; };
       
   203     
       
   204     void SetFocusInitialPosition(NGlxListDefs::TFocusInitialPosition aFocusInitialPosition){};
       
   205 
       
   206     void ResetFocus(){};        
       
   207  
       
   208     void SetVisibleWindowIndexL( TInt aIndex ){};
       
   209     TInt VisibleWindowIndex() const {};
       
   210     virtual void CancelPreviousRequests() {};
       
   211     RArray<TGlxMedia> iItems;
       
   212     RPointerArray<CGlxMedia> iMedia;
       
   213     RArray<TInt> iSelectedItems;
       
   214     TInt iFocusIndex;
       
   215     TBool iStaticItemsEnabled;
       
   216     };
       
   217 // CONSTRUCTION
       
   218 t_cglxcommandhandlershowviaupnp* t_cglxcommandhandlershowviaupnp::NewL()
       
   219     {
       
   220     t_cglxcommandhandlershowviaupnp* self = t_cglxcommandhandlershowviaupnp::NewLC();
       
   221     CleanupStack::Pop();
       
   222     return self;
       
   223     }
       
   224 
       
   225 t_cglxcommandhandlershowviaupnp* t_cglxcommandhandlershowviaupnp::NewLC()
       
   226     {
       
   227     t_cglxcommandhandlershowviaupnp* self = new( ELeave ) t_cglxcommandhandlershowviaupnp();
       
   228     CleanupStack::PushL( self );
       
   229     self->ConstructL();
       
   230     return self;
       
   231     }
       
   232 
       
   233 
       
   234 // Destructor (virtual by CBase)
       
   235 t_cglxcommandhandlershowviaupnp::~t_cglxcommandhandlershowviaupnp()
       
   236     {
       
   237     }
       
   238 
       
   239 // Default constructor
       
   240 t_cglxcommandhandlershowviaupnp::t_cglxcommandhandlershowviaupnp()
       
   241     {
       
   242     }
       
   243 
       
   244 // Second phase construct
       
   245 void t_cglxcommandhandlershowviaupnp::ConstructL()
       
   246     {
       
   247     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   248     // It generates the test case table.
       
   249     CEUnitTestSuiteClass::ConstructL();
       
   250     }
       
   251 
       
   252 
       
   253 //Create the media List
       
   254 
       
   255 MGlxMediaList& t_cglxcommandhandlershowviaupnp::MediaList()
       
   256     {
       
   257 #if 0
       
   258     EUNIT_PRINT(_L("Entering  MediaList"));
       
   259     CMPXCollectionPath* path = CMPXCollectionPath :: NewL();
       
   260     CleanupStack::PushL(path);      
       
   261     EUNIT_PRINT(_L("MediaList :: MPXCollectionPath created"));
       
   262     iList = MGlxMediaList::InstanceL(*path,TGlxHierarchyId(NULL),NULL);
       
   263     EUNIT_PRINT(_L("Exiting  MediaList"));
       
   264     CleanupStack::PopAndDestroy(path);         
       
   265     return *iList;
       
   266 #endif
       
   267     }
       
   268 
       
   269 
       
   270 
       
   271 //  METHODS
       
   272 //Test the NewL() without medialist
       
   273 void t_cglxcommandhandlershowviaupnp::SetupL(  )
       
   274     {          
       
   275     iCommandShowUpnp = CGlxCommandHandlerShowViaUpnp :: NewL(NULL, EFalse);
       
   276     }
       
   277 
       
   278 //  Medialist created 
       
   279 void t_cglxcommandhandlershowviaupnp::SetupL1(  )
       
   280     { 
       
   281     //create the medialist
       
   282   //  MediaList();  
       
   283     iList = new (ELeave) _CGlxTestMediaList;
       
   284     EUNIT_PRINT(_L("SetupL1 :: created Medialist"));
       
   285     iCommandShowUpnp = CGlxCommandHandlerShowViaUpnp :: NewL(this, EFalse);
       
   286     EUNIT_PRINT(_L("Exiting  SetupL1"));
       
   287     }
       
   288 
       
   289 
       
   290    
       
   291 //Test DoIsDisabled
       
   292 
       
   293 //Command Id ShowViaUpnp
       
   294 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Show()
       
   295     {       
       
   296     TBool result =  ETrue;                                   
       
   297     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(EGlxShowViaUpnp,*iList)));                                        
       
   298     }
       
   299 
       
   300 //Command Id StopShowing
       
   301 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Stop()
       
   302     {
       
   303     TBool result =  ETrue;   
       
   304     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(EGlxStopShowing,*iList)));  
       
   305     }
       
   306 
       
   307 
       
   308 //Command Id Null
       
   309 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_NULL()
       
   310     {
       
   311     TBool result =  ETrue;   
       
   312     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(NULL,*iList)));  
       
   313     }
       
   314 
       
   315 //Command Id Invalid 
       
   316 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Invalid()
       
   317     {
       
   318     TBool result =  ETrue;   
       
   319     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(100,*iList)));  
       
   320     }
       
   321 
       
   322 //Show Command Available
       
   323 
       
   324 //Command Id ShowViaUpnp
       
   325 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Show_Available()
       
   326     { 
       
   327     EUNIT_PRINT(_L("Entering  T_DoIsDisabled_Show_Available"));
       
   328     TBool result =  ETrue;                                   
       
   329     CUpnpShowCommand::SetUpIsAvailable(ETrue);
       
   330     
       
   331     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(EGlxShowViaUpnp,*iList)));                                        
       
   332     }
       
   333 
       
   334 //Command Id StopShowing
       
   335 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Stop_Available()
       
   336     {
       
   337     TBool result =  EFalse;     
       
   338     CUpnpShowCommand::SetUpIsAvailable(ETrue);
       
   339     GlxUpnpRenderer::StartShowingL();
       
   340     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(EGlxStopShowing,*iList)));  
       
   341     GlxUpnpRenderer::StopShowingL();    
       
   342     }
       
   343 
       
   344 
       
   345 //Command Id Null
       
   346 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_NULL_Available()
       
   347     {
       
   348     TBool result =  ETrue; 
       
   349     CUpnpShowCommand::SetUpIsAvailable(ETrue);
       
   350       
       
   351     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(NULL,*iList)));  
       
   352     }
       
   353 
       
   354 //Command Id Invalid 
       
   355 void t_cglxcommandhandlershowviaupnp::T_DoIsDisabled_Invalid_Available()
       
   356     {
       
   357     TBool result =  ETrue;   
       
   358     CUpnpShowCommand::SetUpIsAvailable(ETrue);
       
   359     
       
   360     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoIsDisabled(100,*iList)));  
       
   361     }
       
   362 
       
   363 
       
   364 
       
   365 
       
   366 //Test DoExecuteL
       
   367 
       
   368 //Command Id start
       
   369 void t_cglxcommandhandlershowviaupnp::T_DoExecuteL_Show()
       
   370     {
       
   371     TBool result =  ETrue;    
       
   372     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoExecuteL(EGlxShowViaUpnp,*iList))); 
       
   373     GlxUpnpRenderer::StopShowingL();                             
       
   374     }
       
   375 
       
   376 
       
   377 //Command Id Stop
       
   378 void t_cglxcommandhandlershowviaupnp::T_DoExecuteL_Stop()
       
   379     {
       
   380     GlxUpnpRenderer::StartShowingL();
       
   381     TBool result =  ETrue;  
       
   382     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoExecuteL(EGlxStopShowing,*iList)));            
       
   383     }
       
   384 
       
   385 //Command Id NUll - return EFalse command should not be handled
       
   386 void t_cglxcommandhandlershowviaupnp::T_DoExecuteL_NULL()
       
   387     {
       
   388     TBool result =  EFalse;  
       
   389     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoExecuteL(NULL,*iList)));
       
   390     }
       
   391 
       
   392 //Command Id Invalid -return EFalse command should not be handled
       
   393 void t_cglxcommandhandlershowviaupnp::T_DoExecuteL_Invalid()
       
   394     {
       
   395     TBool result =  EFalse;  
       
   396     EUNIT_ASSERT_EQUALS(result,(iCommandShowUpnp->DoExecuteL(100,*iList)));
       
   397     }
       
   398 
       
   399 
       
   400 //Tear down
       
   401 void t_cglxcommandhandlershowviaupnp::Teardown(  )
       
   402     {
       
   403     EUNIT_PRINT(_L("before teardown"));
       
   404     
       
   405     if(iCommandShowUpnp)
       
   406         {
       
   407         delete iCommandShowUpnp;                  
       
   408         }    
       
   409 
       
   410     if(iList)   
       
   411         {
       
   412         EUNIT_PRINT(_L("before closing list"));
       
   413         delete iList;
       
   414         iList = NULL;
       
   415         }   
       
   416     EUNIT_PRINT(_L("After teardown"));        
       
   417     }
       
   418     
       
   419 
       
   420 //Check the creation
       
   421 void t_cglxcommandhandlershowviaupnp::T_CGlxCommandHandlerShowViaUpnpL(  )
       
   422     {
       
   423     EUNIT_ASSERT_DESC( iCommandShowUpnp, "Creation Failed");
       
   424     }
       
   425     
       
   426     
       
   427 
       
   428 //  TEST TABLE
       
   429 EUNIT_BEGIN_TEST_TABLE(
       
   430     t_cglxcommandhandlershowviaupnp,
       
   431     "Add test suite description here.",
       
   432     "UNIT" )
       
   433 
       
   434 
       
   435 //Set up function without Media List
       
   436 
       
   437 EUNIT_TEST(
       
   438     "Create-nomedialist",
       
   439     "CGlxCommandHandlerShowViaUpnp",
       
   440     "NewL",
       
   441     "UNIT",
       
   442     SetupL, T_CGlxCommandHandlerShowViaUpnpL, Teardown)
       
   443     
       
   444    
       
   445 //Set up function without Media List
       
   446 
       
   447 EUNIT_TEST(
       
   448     "Create-medialist",
       
   449     "CGlxCommandHandlerShowViaUpnp",
       
   450     "NewL-medialist",
       
   451     "UNIT",
       
   452     SetupL1, T_CGlxCommandHandlerShowViaUpnpL, Teardown)
       
   453 
       
   454 
       
   455 //DoIsDisable the command handler with UpnpShowCommand Not available
       
   456 
       
   457 EUNIT_TEST(
       
   458     "Create1",
       
   459     "CGlxCommandHandlerShowViaUpnp",
       
   460     "Disable_show_NotAvailable",
       
   461     "UNIT",
       
   462     SetupL, T_DoIsDisabled_Show, Teardown)
       
   463 
       
   464 EUNIT_TEST(
       
   465     "Create2",
       
   466     "CGlxCommandHandlerShowViaUpnp",
       
   467     "Disable_stop_NotAvailable",
       
   468     "UNIT",
       
   469     SetupL, T_DoIsDisabled_Stop, Teardown)
       
   470 
       
   471 EUNIT_TEST(
       
   472     "Create3",
       
   473     "CGlxCommandHandlerShowViaUpnp",
       
   474     "Disable_Null_NotAvailable",
       
   475     "UNIT",
       
   476     SetupL, T_DoIsDisabled_NULL, Teardown)
       
   477 
       
   478 
       
   479 EUNIT_TEST(
       
   480     "Create4",
       
   481     "CGlxCommandHandlerShowViaUpnp",
       
   482     "Disable_Invalid_NotAvailable",
       
   483     "UNIT",
       
   484     SetupL, T_DoIsDisabled_Invalid, Teardown)
       
   485 
       
   486 //Disabling the command handler with UpnpShowCommand Available
       
   487 
       
   488 /*EUNIT_TEST(
       
   489     "Create5",
       
   490     "CGlxCommandHandlerShowViaUpnp",
       
   491     "Disable_stop_Available",
       
   492     "UNIT",
       
   493     SetupL1, T_DoIsDisabled_Show_Available, Teardown)*/
       
   494 
       
   495 EUNIT_TEST(
       
   496     "Create6",
       
   497     "CGlxCommandHandlerShowViaUpnp",
       
   498     "Disable_Null_Available",
       
   499     "UNIT",
       
   500     SetupL1, T_DoIsDisabled_NULL_Available, Teardown)
       
   501 
       
   502 
       
   503 EUNIT_TEST(
       
   504     "Create7",
       
   505     "CGlxCommandHandlerShowViaUpnp",
       
   506     "Disable_Invalid_Available",
       
   507     "UNIT",
       
   508     SetupL1, T_DoIsDisabled_Invalid_Available, Teardown) 
       
   509   
       
   510   
       
   511 /*EUNIT_TEST(
       
   512     "Create8",
       
   513     "CGlxCommandHandlerShowViaUpnp",
       
   514     "Disable_show_NotAvailable",
       
   515     "UNIT",
       
   516     SetupL1, T_DoIsDisabled_Stop_Available, Teardown)
       
   517     
       
   518 
       
   519 //DoExecuteL with with UpnpShowCommand Not available
       
   520 
       
   521 EUNIT_TEST(
       
   522     "Create9",
       
   523     "CGlxCommandHandlerShowViaUpnp",
       
   524     "Execute_Show",
       
   525     "UNIT",
       
   526     SetupL1, T_DoExecuteL_Show, Teardown)
       
   527     
       
   528 EUNIT_TEST(
       
   529     "Create10",
       
   530     "CGlxCommandHandlerShowViaUpnp",
       
   531     "Execute_stop",
       
   532     "FUNCTIONALITY",
       
   533     SetupL1, T_DoExecuteL_Stop, Teardown) */
       
   534     
       
   535 EUNIT_TEST(
       
   536     "Create11",
       
   537     "CGlxCommandHandlerShowViaUpnp",
       
   538     "Execute_Null",
       
   539     "UNIT",
       
   540     SetupL1, T_DoExecuteL_NULL, Teardown)
       
   541     
       
   542 EUNIT_TEST(
       
   543     "Create12",
       
   544     "CGlxCommandHandlerShowViaUpnp",
       
   545     "Execute_Invalid",
       
   546     "UNIT",
       
   547     SetupL1, T_DoExecuteL_Invalid, Teardown)
       
   548 
       
   549 //DoExecuteL without medialist
       
   550 /*/
       
   551 
       
   552 EUNIT_TEST(
       
   553     "Create",
       
   554     "CGlxCommandHandlerShowViaUpnp",
       
   555     "Execute_stop",
       
   556     "UNIT",
       
   557     SetupL, T_DoExecuteL_Stop, Teardown)
       
   558     
       
   559 EUNIT_TEST(
       
   560     "Create",
       
   561     "CGlxCommandHandlerShowViaUpnp",
       
   562     "Execute_Null",
       
   563     "FUNCTIONALITY",
       
   564     SetupL, T_DoExecuteL_NULL, Teardown)
       
   565     
       
   566 EUNIT_TEST(
       
   567     "Create",
       
   568     "CGlxCommandHandlerShowViaUpnp",
       
   569     "Execute_Invalid",
       
   570     "UNIT",
       
   571     SetupL, T_DoExecuteL_Invalid, Teardown)
       
   572     
       
   573     
       
   574 EUNIT_TEST(
       
   575     "Create",
       
   576     "CGlxCommandHandlerShowViaUpnp",
       
   577     "Execute_Invalid",
       
   578     "UNIT",
       
   579     SetupL, T_DoExecuteL_Show, Teardown)       */ 
       
   580    
       
   581 
       
   582 EUNIT_END_TEST_TABLE
       
   583 
       
   584 //  END OF FILE
       
   585