photosgallery/viewframework/commandhandlers/tsrc/ut__commandhandlermarking/src/t_glxcommandhandlermarking.cpp
changeset 0 4e91876724a2
child 13 71da52165949
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:  CommandHandlerMarking unit test cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "t_glxcommandhandlermarking.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <EUnitMacros.h>
       
    26 #include <EUnitDecorators.h>
       
    27 
       
    28 #include <avkon.hrh>
       
    29 
       
    30 #include <mglxmedialist.h>
       
    31 #include <glxattributeretriever.h>
       
    32 #include <glxscreenfurniture.h>
       
    33 
       
    34 //  INTERNAL INCLUDES
       
    35 
       
    36 //
       
    37 CGlxMedia::CGlxMedia(const TGlxMediaId& aId)
       
    38 		: iId(aId)
       
    39     {
       
    40     }
       
    41     
       
    42 CGlxMedia::~CGlxMedia()
       
    43     {
       
    44 	Reset();
       
    45     iValues.Close(); 
       
    46     iAttributes.Close();
       
    47     }    
       
    48        	
       
    49 class _CGlxTestMediaList: public CBase, public MGlxMediaList
       
    50 	{
       
    51 public:
       
    52 	~_CGlxTestMediaList() 
       
    53 	    {
       
    54 	    iItems.Close();
       
    55         iMedia.ResetAndDestroy();
       
    56         iSelectedItems.Close();
       
    57 	    }
       
    58 	    
       
    59 	virtual void Close() 
       
    60 	    {
       
    61 	    };
       
    62 	virtual TGlxMediaListId Id() const 
       
    63 	    {
       
    64 	    return KGlxIdNone;
       
    65 	    }
       
    66 
       
    67 	virtual TInt Count(NGlxListDefs::TCountType /*aType*/) const 
       
    68 	    {
       
    69 	    return iItems.Count();
       
    70 	    }
       
    71 	
       
    72 	virtual TInt FocusIndex() const 
       
    73 	    {
       
    74 	    return iFocusIndex;
       
    75 	    }
       
    76 
       
    77 	virtual void SetFocusL(NGlxListDefs::TFocusSetType /*aType*/, TInt aValue) 
       
    78 	    {
       
    79 	    iFocusIndex = aValue;
       
    80 	    }
       
    81 	
       
    82 	virtual const TGlxMedia& Item(TInt aIndex) const 
       
    83 	    {
       
    84 	    return iItems[aIndex];
       
    85 	    }
       
    86 
       
    87 	virtual TInt Index(const TGlxIdSpaceId& /* aIdSpaceId */, const TGlxMediaId& aId) const 
       
    88 	    {
       
    89 	    TInt count = iItems.Count();
       
    90 	    for (TInt i = 0; i < count; i++)
       
    91 	        {
       
    92 	        if (iItems[i].Id() == aId)
       
    93 	            {
       
    94 	            return i;
       
    95 	            }
       
    96 	        }
       
    97 	    return KErrNotFound;
       
    98 	    }
       
    99 	
       
   100 	virtual void AddMediaListObserverL(MGlxMediaListObserver* /*aObserver*/) 
       
   101 	    {
       
   102 	    }
       
   103 	
       
   104 	virtual void RemoveMediaListObserver(MGlxMediaListObserver* /*aObserver*/) 
       
   105 	    {
       
   106 	    }
       
   107 
       
   108     virtual void AddContextL(const MGlxFetchContext* /*aContext*/, TInt /*aPriority*/) 
       
   109         {
       
   110         }
       
   111 
       
   112 	virtual void RemoveContext(const MGlxFetchContext* /*aContext*/) 
       
   113 	    {
       
   114 	    }
       
   115 	
       
   116 	virtual MMPXCollection& Collection() const 
       
   117 	    {
       
   118 	    // we know that this method is not called in our tests, this is just to make the code compile
       
   119 	    MMPXCollection* empty = NULL;
       
   120 	    return *empty;
       
   121 	    }
       
   122 
       
   123 	virtual TBool IsSelected(TInt aIndex) const 
       
   124 	    {
       
   125 	    TInt idx = iSelectedItems.Find(aIndex);
       
   126 	    return (idx != KErrNotFound);
       
   127 	    }
       
   128 
       
   129 	virtual void SetSelectedL(TInt aIndex, TBool aSelected) 
       
   130 	    {
       
   131 	    if (aSelected)
       
   132 	        {
       
   133             iSelectedItems.InsertInOrder(aIndex);
       
   134 	        }
       
   135 	    else 
       
   136 	        {
       
   137 	        iSelectedItems.Remove(iSelectedItems.Find(aIndex));
       
   138 	        }
       
   139 	    }
       
   140 
       
   141 	virtual const TArray<TInt> Selection() const 
       
   142 	    {
       
   143 	    return iSelectedItems.Array();
       
   144 	    }
       
   145 
       
   146 	virtual void CommandL(CMPXCommand& /*aCommand*/) 
       
   147 	    {
       
   148 	    }
       
   149 
       
   150 	virtual void CancelCommand() 
       
   151 	    {
       
   152 	    }
       
   153 
       
   154 	virtual void SetFilterL(CMPXFilter* /*aFilter*/) 
       
   155 	    {
       
   156 	    }
       
   157 
       
   158 	virtual CMPXFilter* Filter() const 
       
   159 	    {
       
   160 	    return NULL;
       
   161 	    }
       
   162 
       
   163     virtual TGlxIdSpaceId IdSpaceId(TInt /*aIndex*/) const 
       
   164         {
       
   165         return KGlxIdNone;
       
   166         }
       
   167     
       
   168     void AppendL(TInt aId, TBool aCreateMedia) 
       
   169         {
       
   170         if (aCreateMedia) 
       
   171             {
       
   172             CGlxMedia* media = new (ELeave) CGlxMedia(TGlxMediaId(aId));
       
   173             CleanupStack::PushL(media);
       
   174             iMedia.AppendL(media);
       
   175             CleanupStack::Pop(media);
       
   176             iItems.AppendL(TGlxMedia(TGlxMediaId(aId), media));
       
   177             }
       
   178         else 
       
   179             {
       
   180             iItems.AppendL(TGlxMedia(TGlxMediaId(aId)));
       
   181             }
       
   182         }
       
   183         
       
   184     CGlxMedia* MediaObj(TInt aIndex) const 
       
   185         {
       
   186         return const_cast<CGlxMedia*>(static_cast<const CGlxMedia*>(iItems[aIndex].Properties()));
       
   187         }
       
   188         
       
   189     CMPXCollectionPath* PathLC(NGlxListDefs::TPathType /*aType*/) const
       
   190     	{
       
   191     	return NULL;
       
   192     	}
       
   193     
       
   194     TInt SelectionCount() const
       
   195     	{
       
   196     	return iSelectedItems.Count();
       
   197     	}
       
   198     	
       
   199     TInt SelectedItemIndex(TInt /*aSelectionIndex*/) const
       
   200     	{
       
   201     	return 0;
       
   202     	}
       
   203     	
       
   204     TBool IsPopulated() const
       
   205         {
       
   206         return ETrue;
       
   207         }
       
   208     
       
   209     void AddStaticItemL( CGlxMedia* /*aStaticItem*/,
       
   210         NGlxListDefs::TInsertionPosition /*aTargetPosition*/ ) {};
       
   211     
       
   212     void RemoveStaticItem(const TGlxMediaId& /*aItemId*/) {};
       
   213     
       
   214     void SetStaticItemsEnabled( TBool aEnabled ) { iStaticItemsEnabled = aEnabled; };
       
   215     
       
   216     TBool IsStaticItemsEnabled() const { return iStaticItemsEnabled; };
       
   217     
       
   218     void SetFocusInitialPosition(NGlxListDefs::TFocusInitialPosition aFocusInitialPosition){};
       
   219 
       
   220     void ResetFocus(){};        
       
   221  
       
   222     void SetVisibleWindowIndexL( TInt aIndex ){};
       
   223     TInt VisibleWindowIndex() const {};
       
   224     
       
   225     RArray<TGlxMedia> iItems;
       
   226     RPointerArray<CGlxMedia> iMedia;
       
   227     RArray<TInt> iSelectedItems;
       
   228     TInt iFocusIndex;
       
   229     TBool iStaticItemsEnabled;
       
   230 	};
       
   231 	
       
   232 	
       
   233 TInt GlxAttributeRetriever::RetrieveL(const MGlxFetchContext&, MGlxMediaList&, TBool)
       
   234     {
       
   235     return KErrNone;
       
   236     }
       
   237     
       
   238 
       
   239 
       
   240 CGlxMarkingCommandHandlerTester* CGlxMarkingCommandHandlerTester::NewL()
       
   241 	{
       
   242 	CGlxMarkingCommandHandlerTester* me = new(ELeave)CGlxMarkingCommandHandlerTester();
       
   243 	CleanupStack::PushL(me);
       
   244 	me->ConstructL();
       
   245 	CleanupStack::Pop();
       
   246 	return me;
       
   247 	}
       
   248 	
       
   249 CGlxMarkingCommandHandlerTester::~CGlxMarkingCommandHandlerTester()
       
   250 	{
       
   251 	iMarker->Deactivate();
       
   252 	
       
   253 	iCommandHandlerList.ResetAndDestroy();
       
   254 	iCommandHandlerList.Close();
       
   255 	
       
   256 	delete iMediaList;
       
   257 	}
       
   258 
       
   259 
       
   260 CGlxMarkingCommandHandlerTester::CGlxMarkingCommandHandlerTester()
       
   261 	{
       
   262 	
       
   263 	}
       
   264 	
       
   265 void CGlxMarkingCommandHandlerTester::ConstructL()
       
   266 	{
       
   267 	EUNIT_PRINT(_L("CGlxMarkingCommandHandlerTester::ConstructL"));
       
   268 	
       
   269 	iMediaList = new (ELeave) _CGlxTestMediaList;
       
   270 	
       
   271 	EUNIT_PRINT(_L("Construct command handler"));
       
   272 	iMarker = CGlxCommandHandlerMarking::NewL(this,ETrue);
       
   273 	
       
   274 	iCommandHandlerList.AppendL(iMarker);
       
   275 	
       
   276 	iMarker->ActivateL(0);
       
   277 	
       
   278 	EUNIT_PRINT(_L("CGlxMarkingCommandHandlerTester::ConstructL complete"));
       
   279 	}
       
   280 	
       
   281 MGlxMediaList& CGlxMarkingCommandHandlerTester::MediaList()
       
   282 	{
       
   283 	return *iMediaList;
       
   284 	}
       
   285 	
       
   286 TBool CGlxMarkingCommandHandlerTester::ExecuteL(TInt aCommand)
       
   287 	{
       
   288 	return iCommandHandlerList[0]->ExecuteL( aCommand );
       
   289 	}
       
   290 	
       
   291 TBool CGlxMarkingCommandHandlerTester::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   292 	{
       
   293 	TKeyResponse resp = iMarker->OfferKeyEventL(aKeyEvent, aType);
       
   294 	return (resp == EKeyWasConsumed);
       
   295 	}
       
   296 	
       
   297 void CGlxMarkingCommandHandlerTester::HandleFocusChangedL(NGlxListDefs::TFocusChangeType aType, TInt aNewIndex, TInt aOldIndex)
       
   298 	{
       
   299 	iMarker->HandleFocusChangedL(aType, aNewIndex, aOldIndex, iMediaList);
       
   300 	}
       
   301 
       
   302 // CONSTRUCTION
       
   303 ut__commandhandlermarking* ut__commandhandlermarking::NewL()
       
   304     {
       
   305     ut__commandhandlermarking* self = ut__commandhandlermarking::NewLC();
       
   306     CleanupStack::Pop();
       
   307 
       
   308     return self;
       
   309     }
       
   310 
       
   311 ut__commandhandlermarking* ut__commandhandlermarking::NewLC()
       
   312     {
       
   313     ut__commandhandlermarking* self = new( ELeave ) ut__commandhandlermarking();
       
   314     CleanupStack::PushL( self );
       
   315 
       
   316     self->ConstructL();
       
   317 
       
   318     return self;
       
   319     }
       
   320 
       
   321 // Destructor (virtual by CBase)
       
   322 ut__commandhandlermarking::~ut__commandhandlermarking()
       
   323     {
       
   324     }
       
   325 
       
   326 // Default constructor
       
   327 ut__commandhandlermarking::ut__commandhandlermarking()
       
   328     {
       
   329     }
       
   330 
       
   331 // Second phase construct
       
   332 void ut__commandhandlermarking::ConstructL()
       
   333     {
       
   334     CEUnitTestSuiteClass::ConstructL();
       
   335     }
       
   336 
       
   337 //  METHODS
       
   338 
       
   339 
       
   340 void ut__commandhandlermarking::SetupL(  )
       
   341     {
       
   342     EUNIT_PRINT(_L("ut__commandhandlermarking::SetupL"));
       
   343     iTester = CGlxMarkingCommandHandlerTester::NewL();
       
   344     }
       
   345     
       
   346 
       
   347 void ut__commandhandlermarking::Teardown(  )
       
   348     {
       
   349     delete iTester;
       
   350     iTester = NULL;
       
   351     }
       
   352     
       
   353 
       
   354 void ut__commandhandlermarking::T_TestCreateL(  )
       
   355     {
       
   356     }
       
   357     
       
   358 void ut__commandhandlermarking::T_TestExecuteNoItemsL()
       
   359 	{
       
   360 	EUNIT_PRINT(_L("ut__commandhandlermarking::T_TestExecuteNoItemsL"));
       
   361 	TBool exe = iTester->ExecuteL(EAknCmdMark);
       
   362 	EUNIT_ASSERT_DESC( exe == EFalse, "Mark unsupported ");
       
   363 	
       
   364 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   365 	EUNIT_ASSERT_DESC( exe == EFalse, "Unmark unsupported");
       
   366 	
       
   367 	exe = iTester->ExecuteL(EAknMarkAll);
       
   368 	EUNIT_ASSERT_DESC( exe == EFalse, "Mark all unsupported");
       
   369 	
       
   370 	exe = iTester->ExecuteL(EAknUnmarkAll);
       
   371 	EUNIT_ASSERT_DESC( exe == EFalse, "Unmark all unsupported");
       
   372 	
       
   373 	exe = iTester->ExecuteL(-1);
       
   374 	EUNIT_ASSERT_DESC( exe == EFalse, "unknown command -1");
       
   375 	
       
   376 	exe = iTester->ExecuteL(1024);
       
   377 	EUNIT_ASSERT_DESC( exe == EFalse, "unknown command 1024");
       
   378 	}
       
   379 	
       
   380 
       
   381 	
       
   382 void ut__commandhandlermarking::T_TestExecuteItemsL()
       
   383 	{
       
   384 	EUNIT_PRINT(_L("ut__commandhandlermarking::T_TestExecuteItemsL"));
       
   385 	
       
   386 	_CGlxTestMediaList* ml = dynamic_cast<_CGlxTestMediaList*>(&iTester->MediaList());
       
   387 	
       
   388 	ml->AppendL(0, ETrue);
       
   389     ml->AppendL(1, ETrue);
       
   390     ml->AppendL(2, ETrue);
       
   391     ml->AppendL(3, ETrue);
       
   392     ml->AppendL(4, ETrue);
       
   393     ml->iFocusIndex = 0;
       
   394 	
       
   395 	TBool exe = iTester->ExecuteL(EAknCmdMark);
       
   396 	EUNIT_ASSERT_DESC( exe, "Mark supported");
       
   397 	
       
   398 	exe = iTester->ExecuteL(EAknCmdMark);
       
   399 	EUNIT_ASSERT_DESC( exe == EFalse, "Already marked");
       
   400 	
       
   401 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   402 	EUNIT_ASSERT_DESC( exe, "Unmark supported");
       
   403 	
       
   404 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   405 	EUNIT_ASSERT_DESC( exe == EFalse, "Unmark not supported");
       
   406 	
       
   407 	exe = iTester->ExecuteL(EAknMarkAll);
       
   408 	EUNIT_ASSERT_DESC( exe, "Mark all");
       
   409 	
       
   410 	exe = iTester->ExecuteL(EAknCmdMark);
       
   411 	EUNIT_ASSERT_DESC( exe == EFalse, "Cannot mark");
       
   412 	
       
   413 	exe = iTester->ExecuteL(EAknMarkAll);
       
   414 	EUNIT_ASSERT_DESC( exe == EFalse, "Mark all not supported");
       
   415 	
       
   416 	exe = iTester->ExecuteL(EAknUnmarkAll);
       
   417 	EUNIT_ASSERT_DESC( exe, "Unmark all");
       
   418 	
       
   419 	exe = iTester->ExecuteL(EAknUnmarkAll);
       
   420 	EUNIT_ASSERT_DESC( exe==EFalse, "Unmark all not supported");
       
   421 	
       
   422 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   423 	EUNIT_ASSERT_DESC( exe == EFalse, "Unmark not supported");
       
   424 	
       
   425 	exe = iTester->ExecuteL(EAknCmdMark);
       
   426 	EUNIT_ASSERT_DESC( exe, "Mark supported");
       
   427 	
       
   428 	EUNIT_PRINT(_L("ut__commandhandlermarking::T_TestExecuteItemsL change focus pos"));
       
   429 
       
   430 	ml->iFocusIndex = 1;
       
   431 	exe = iTester->ExecuteL(EAknCmdMark);
       
   432 	EUNIT_ASSERT_DESC( exe, "Mark supported");
       
   433 	
       
   434 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   435 	EUNIT_ASSERT_DESC( exe, "Unmark supported");
       
   436 	
       
   437 	ml->iFocusIndex = 0;
       
   438 	
       
   439 	exe = iTester->ExecuteL(EAknCmdMark);
       
   440 	EUNIT_ASSERT_DESC( exe == EFalse, "Already marked");
       
   441 	
       
   442 	ml->iFocusIndex = 1;
       
   443 	exe = iTester->ExecuteL(EAknCmdUnmark);
       
   444 	EUNIT_ASSERT_DESC( exe == EFalse, "not marked");
       
   445 	}
       
   446 
       
   447 void ut__commandhandlermarking::T_TestOfferKeyL()
       
   448 	{
       
   449 	_CGlxTestMediaList* ml = dynamic_cast<_CGlxTestMediaList*>(&iTester->MediaList());
       
   450 	
       
   451 	ml->AppendL(0, ETrue);
       
   452     ml->AppendL(1, ETrue);
       
   453     ml->AppendL(2, ETrue);
       
   454     ml->AppendL(3, ETrue);
       
   455     ml->AppendL(4, ETrue);
       
   456     ml->iFocusIndex = 0;
       
   457 
       
   458   	TKeyEvent kev = { 0 };
       
   459   	kev.iModifiers |= EModifierShift;	  
       
   460   
       
   461   	// shift key pressed
       
   462     iTester->OfferKeyEventL(kev, EEventKeyDown);
       
   463     
       
   464     // change focus
       
   465     iTester->HandleFocusChangedL( NGlxListDefs::EForward, 4,0);
       
   466     
       
   467     // all items should now be marked
       
   468     TBool exe = iTester->ExecuteL(EAknCmdMark);
       
   469 	EUNIT_ASSERT_DESC( exe == EFalse, "Cannot mark");
       
   470 	
       
   471 	exe = iTester->ExecuteL(EAknMarkAll);
       
   472 	EUNIT_ASSERT_DESC( exe == EFalse, "All already marked");
       
   473 	
       
   474 	// shift key disabled
       
   475 	kev.iModifiers = 0;
       
   476 	iTester->OfferKeyEventL(kev, EEventKeyUp);
       
   477 	
       
   478 	iTester->OfferKeyEventL(kev, EEventKeyDown);
       
   479     
       
   480     // changing focus has no effect
       
   481     iTester->HandleFocusChangedL( NGlxListDefs::EBackward, 0,4);
       
   482     
       
   483     exe = iTester->ExecuteL(EAknCmdMark);	
       
   484 	EUNIT_ASSERT_DESC( exe == EFalse, "Cannot mark");
       
   485 	
       
   486 	exe = iTester->ExecuteL(EAknMarkAll);
       
   487 	EUNIT_ASSERT_DESC( exe == EFalse, "All already marked");
       
   488 	
       
   489 	kev.iModifiers |= EModifierShift;	  
       
   490   
       
   491   	// shift key down
       
   492     iTester->OfferKeyEventL(kev, EEventKeyDown);
       
   493     
       
   494     iTester->HandleFocusChangedL( NGlxListDefs::EForward, 4,0);
       
   495     
       
   496     // all items have been unmarked
       
   497     exe = iTester->ExecuteL(EAknUnmarkAll);
       
   498 	EUNIT_ASSERT_DESC( exe == EFalse, "None marked");
       
   499 	
       
   500 	exe = iTester->ExecuteL(EAknCmdMark);
       
   501 	EUNIT_ASSERT_DESC( exe, "Can mark");
       
   502 	
       
   503 	exe = iTester->ExecuteL(EAknCmdMark);
       
   504 	EUNIT_ASSERT_DESC( exe == EFalse, "Already marked");
       
   505 	
       
   506 	// select with shift down
       
   507 	kev.iScanCode=EStdKeyDevice3;
       
   508 	TBool resp = iTester->OfferKeyEventL(kev, EEventKey);
       
   509 	EUNIT_ASSERT_DESC( resp, "Event consumed");
       
   510 	
       
   511 	// item has been unmarked
       
   512 	exe = iTester->ExecuteL(EAknCmdMark);
       
   513 	EUNIT_ASSERT_DESC( exe, "Can mark");
       
   514 	
       
   515 	// shift key up
       
   516 	// select should have no effect on marking
       
   517 	kev.iScanCode=EStdKeyDevice3;
       
   518 	kev.iModifiers = 0;
       
   519 	resp = iTester->OfferKeyEventL(kev, EEventKeyDown);
       
   520 	EUNIT_ASSERT_DESC( resp == EFalse, "Event notconsumed");
       
   521 	
       
   522 	exe = iTester->ExecuteL(EAknCmdMark);
       
   523 	EUNIT_ASSERT_DESC( exe == EFalse, "Already marked");
       
   524 	}
       
   525 
       
   526 //  TEST TABLE
       
   527 EUNIT_BEGIN_TEST_TABLE(
       
   528     ut__commandhandlermarking,
       
   529     "Add test suite description here.",
       
   530     "MODULE" )
       
   531 
       
   532 EUNIT_TEST(
       
   533     "Test0",
       
   534     "Create marking command handler",
       
   535     "Test0",
       
   536     "FUNCTIONALITY",
       
   537     SetupL, T_TestCreateL, Teardown)
       
   538     
       
   539 EUNIT_TEST(
       
   540     "Test1",
       
   541     "Test execute no items",
       
   542     "Test1",
       
   543     "FUNCTIONALITY",
       
   544     SetupL, T_TestExecuteNoItemsL, Teardown)
       
   545     
       
   546 EUNIT_TEST(
       
   547     "Test2",
       
   548     "Test execute items",
       
   549     "Test2",
       
   550     "FUNCTIONALITY",
       
   551     SetupL, T_TestExecuteItemsL, Teardown)
       
   552     
       
   553  EUNIT_TEST(
       
   554     "Test3",
       
   555     "Test offer key events",
       
   556     "Test3",
       
   557     "FUNCTIONALITY",
       
   558     SetupL, T_TestOfferKeyL, Teardown)
       
   559     
       
   560 
       
   561 EUNIT_END_TEST_TABLE
       
   562 
       
   563 //  END OF FILE