photosgallery/viewframework/commandhandlers/commoncommandhandlers/tsrc/ut_propertycommandhandlers/src/ut_propertycommandhandlers.cpp
changeset 0 4e91876724a2
child 13 71da52165949
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:  CommandHandlerDetails unit test cases
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "UT_propertycommandhandlers.h"
       
    23 
       
    24 //#include <glxcommandhandlerproperties.h>
       
    25 #include <mglxmedialist.h>
       
    26 #include <mpxcollectionutility.h>
       
    27 #include <mpxcollectionpath.h>
       
    28 
       
    29 #include <glxcommandhandlers.hrh>
       
    30 //  EXTERNAL INCLUDES
       
    31 #include <EUnitMacros.h>
       
    32 
       
    33 //  INTERNAL INCLUDES
       
    34 
       
    35 template<typename T> 
       
    36 inline void CGlxMedia::SetTObjectValueL(const TMPXAttribute& aAttribute, T aValue) 
       
    37 	{
       
    38     TAny* ptr = User::AllocL(sizeof(T));
       
    39     memcpy(ptr, &aValue, sizeof(T));
       
    40 
       
    41     TInt i = Index(aAttribute);
       
    42     if (KErrNotFound != i)
       
    43         {
       
    44         // Replace the existing value
       
    45         TValue& value = iValues[i];
       
    46 		// COMMENTED OUT SINCE NOT EXPORTED 
       
    47 		//Delete(value);
       
    48         
       
    49         value.iValue = ptr; // Takes ownership
       
    50         value.iType = EMPXTypeTObject;
       
    51         }
       
    52     else
       
    53         {
       
    54         TInt err = iValues.Append(TValue(ptr, EMPXTypeTObject));
       
    55         
       
    56         // If appended value ok, try to append the attribute. 
       
    57         if (KErrNone == err) 
       
    58         	{
       
    59 	        err = iAttributes.Append(aAttribute);
       
    60 	        if (err != KErrNone)
       
    61 	        	{
       
    62 	        	// Failed, undo the append
       
    63 	        	iValues.Remove(iValues.Count() - 1);
       
    64 	        	}
       
    65        		}
       
    66        		
       
    67         if (KErrNone != err) 
       
    68         	{
       
    69         	User::Free(ptr);
       
    70         	User::Leave(err);
       
    71         	}
       
    72         }
       
    73    	}
       
    74    	
       
    75 //
       
    76 CGlxMedia::CGlxMedia(const TGlxMediaId& aId)
       
    77 		: iId(aId), iUsedByLists(2) // On average, two list as users assumed
       
    78     {
       
    79     }
       
    80     
       
    81 CGlxMedia::~CGlxMedia()
       
    82     {
       
    83     iUsedByLists.Close();
       
    84 
       
    85 	Reset();
       
    86     iValues.Close(); 
       
    87     iAttributes.Close();
       
    88     }    
       
    89        	
       
    90 
       
    91 
       
    92 struct _CGlxTestMediaList: public CBase, public MGlxMediaList
       
    93 	{
       
    94 	~_CGlxTestMediaList() 
       
    95 	    {
       
    96 	    iItems.Close();
       
    97         iMedia.ResetAndDestroy();
       
    98         iSelectedItems.Close();
       
    99 	    }
       
   100 	    
       
   101 	virtual void Close() 
       
   102 	    {
       
   103 	    };
       
   104 	virtual TGlxMediaListId Id() const 
       
   105 	    {
       
   106 	    return KGlxIdNone;
       
   107 	    }
       
   108 
       
   109     virtual TInt Count(TCountType aType = ECountAll) const
       
   110 	//virtual TInt Count() const 
       
   111 	    {
       
   112 	    return iItems.Count();
       
   113 	    }
       
   114 	
       
   115 	virtual TInt FocusIndex() const 
       
   116 	    {
       
   117 	    return iFocusIndex;
       
   118 	    }
       
   119 
       
   120 	virtual void SetFocusL(NGlxListDefs::TFocusSetType /*aType*/, TInt aValue) 
       
   121 	    {
       
   122 	    iFocusIndex = aValue;
       
   123 	    }
       
   124 	
       
   125 	virtual const TGlxMedia& Item(TInt aIndex) const 
       
   126 	    {
       
   127 	    return iItems[aIndex];
       
   128 	    }
       
   129 
       
   130 	virtual TInt Index(const TGlxMediaId& aId) const 
       
   131 	    {
       
   132 	    TInt count = iItems.Count();
       
   133 	    for (TInt i = 0; i < count; i++)
       
   134 	        {
       
   135 	        if (iItems[i].Id() == aId)
       
   136 	            {
       
   137 	            return i;
       
   138 	            }
       
   139 	        }
       
   140 	    return KErrNotFound;
       
   141 	    }
       
   142 	
       
   143 	virtual void AddMediaListObserverL(MGlxMediaListObserver* /*aObserver*/) 
       
   144 	    {
       
   145 	    }
       
   146 	
       
   147 	virtual void RemoveMediaListObserver(MGlxMediaListObserver* /*aObserver*/) 
       
   148 	    {
       
   149 	    }
       
   150 
       
   151     virtual void AddContextL(const MGlxFetchContext* /*aContext*/, TInt /*aPriority*/) 
       
   152         {
       
   153         }
       
   154 
       
   155 	virtual void RemoveContext(const MGlxFetchContext* /*aContext*/) 
       
   156 	    {
       
   157 	    }
       
   158 	
       
   159 	virtual MMPXCollection& Collection() const 
       
   160 	    {
       
   161 	    return *(MMPXCollection*)NULL;
       
   162 	    }
       
   163 
       
   164 	virtual const TBool IsSelected(TInt aIndex) const 
       
   165 	    {
       
   166 	    TInt idx = iSelectedItems.Find(aIndex);
       
   167 	    return (idx != KErrNotFound);
       
   168 	    }
       
   169 
       
   170 	virtual void SetSelectedL(TInt aIndex, TBool aSelected) 
       
   171 	    {
       
   172 	    if (aSelected)
       
   173 	        {
       
   174             iSelectedItems.InsertInOrder(aIndex);
       
   175 	        }
       
   176 	    else 
       
   177 	        {
       
   178 	        iSelectedItems.Remove(iSelectedItems.Find(aIndex));
       
   179 	        }
       
   180 	    }
       
   181 
       
   182 	virtual const TArray<TInt> Selection() const 
       
   183 	    {
       
   184 	    return iSelectedItems.Array();
       
   185 	    }
       
   186 
       
   187 	virtual void CommandL(CMPXCommand& /*aCommand*/) 
       
   188 	    {
       
   189 	    }
       
   190 
       
   191 	virtual void CancelCommand() 
       
   192 	    {
       
   193 	    }
       
   194 
       
   195 	virtual void SetFilterL(CMPXFilter* /*aFilter*/) 
       
   196 	    {
       
   197 	    }
       
   198 
       
   199 	virtual CMPXFilter* Filter() const 
       
   200 	    {
       
   201 	    return NULL;
       
   202 	    }
       
   203 
       
   204     virtual TGlxIdSpaceId IdSpaceId() const 
       
   205         {
       
   206         return KGlxIdNone;
       
   207         }
       
   208     
       
   209     void AppendL(TInt aId, TBool aCreateMedia) 
       
   210         {
       
   211         if (aCreateMedia) 
       
   212             {
       
   213             CGlxMedia* media = new (ELeave) CGlxMedia(TGlxMediaId(aId));
       
   214             CleanupStack::PushL(media);
       
   215             iMedia.AppendL(media);
       
   216             TMPXAttribute uriAttr(KMPXMediaGeneralUri);
       
   217             media->SetTextValueL (uriAttr,_L("testing"));
       
   218             CleanupStack::Pop(media);
       
   219             iItems.AppendL(TGlxMedia(TGlxMediaId(aId), media));
       
   220             }
       
   221         else 
       
   222             {
       
   223             iItems.AppendL(TGlxMedia(TGlxMediaId(aId)));
       
   224             }
       
   225         }
       
   226         
       
   227     CGlxMedia* MediaObj(TInt aIndex) const 
       
   228         {
       
   229         return const_cast<CGlxMedia*>(static_cast<const CGlxMedia*>(iItems[aIndex].Properties()));
       
   230         }
       
   231         
       
   232     CMPXCollectionPath* PathLC() const
       
   233     	{
       
   234     	return NULL;
       
   235     	}
       
   236     
       
   237     TInt SelectionCount() const
       
   238     	{
       
   239     	return iSelectedItems.Count();
       
   240     	}
       
   241     	
       
   242     TInt SelectedItemIndex(TInt aSelectionIndex) const
       
   243     	{
       
   244     	return 0;
       
   245     	}
       
   246  
       
   247     virtual TBool IsPopulated() const
       
   248         {
       
   249         return ETrue;
       
   250         }
       
   251    
       
   252     RArray<TGlxMedia> iItems;
       
   253     RPointerArray<CGlxMedia> iMedia;
       
   254     RArray<TInt> iSelectedItems;
       
   255     TInt iFocusIndex;
       
   256 	};
       
   257 	
       
   258 // CONSTRUCTION
       
   259 
       
   260 MGlxMediaList& UT_propertycommandhandlers::MediaList() 
       
   261 	{
       
   262 	return *iMediaList;
       
   263 	}
       
   264 
       
   265 UT_propertycommandhandlers* UT_propertycommandhandlers::NewL()
       
   266     {
       
   267     UT_propertycommandhandlers* self = UT_propertycommandhandlers::NewLC();
       
   268     CleanupStack::Pop();
       
   269 
       
   270     return self;
       
   271     }
       
   272 
       
   273 UT_propertycommandhandlers* UT_propertycommandhandlers::NewLC()
       
   274     {
       
   275     UT_propertycommandhandlers* self = new( ELeave ) UT_propertycommandhandlers();
       
   276     CleanupStack::PushL( self );
       
   277 
       
   278     self->ConstructL();
       
   279 
       
   280     return self;
       
   281     }
       
   282   
       
   283     
       
   284 // Destructor (virtual by CBase)
       
   285 UT_propertycommandhandlers::~UT_propertycommandhandlers()
       
   286     {
       
   287     }
       
   288 
       
   289 // Default constructor
       
   290 UT_propertycommandhandlers::UT_propertycommandhandlers()
       
   291     {
       
   292     }
       
   293 
       
   294 // Second phase construct
       
   295 void UT_propertycommandhandlers::ConstructL()
       
   296     {
       
   297     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   298     // It generates the test case table.
       
   299     CEUnitTestSuiteClass::ConstructL();
       
   300     }
       
   301 
       
   302 //  METHODS
       
   303 
       
   304 
       
   305 
       
   306 void UT_propertycommandhandlers::SetupL(  )
       
   307     {
       
   308     //MMPXCollectionUtility* collectionUtility = MMPXCollectionUtility::NewL(NULL, KMcModeDefault);
       
   309     //CMPXCollectionPath* path ;//= collectionUtility->Collection().PathL();
       
   310 		//iML = MGlxMediaList::InstanceL(*path,NULL);
       
   311 	iMediaList = new (ELeave) _CGlxTestMediaList;
       
   312 	iMediaList->AppendL(0, ETrue);
       
   313 	iMediaList->AppendL(1, ETrue);
       
   314 	iMediaList->AppendL(2, ETrue);
       
   315 	iMediaList->AppendL(3, ETrue);
       
   316 	iMediaList->AppendL(4, ETrue);
       
   317 	iMediaList->iFocusIndex = 0;
       
   318 	
       
   319 	iTagManagerCommand = CGlxCommandHandlerProperties::NewTagManagerCommandHandlerL(this);
       
   320 	iMetadataCommand = CGlxCommandHandlerProperties::NewMetadataViewCommandHandlerL(this);
       
   321     }
       
   322 
       
   323 void UT_propertycommandhandlers::Teardown(  )
       
   324     {
       
   325     	
       
   326 	delete iTagManagerCommand;
       
   327 	delete iMetadataCommand;
       
   328 	
       
   329 	delete iMediaList;
       
   330     }
       
   331 
       
   332 void UT_propertycommandhandlers::PropertyCommandHandlerNewL(  )
       
   333     {
       
   334     EUNIT_ASSERT( NULL != iTagManagerCommand );
       
   335     EUNIT_ASSERT( NULL != iMetadataCommand );
       
   336     }
       
   337     
       
   338 void UT_propertycommandhandlers::PropertyCommandHandlerExecuteL(  )
       
   339     {
       
   340     //check that metadata command is consumend
       
   341     EUNIT_ASSERT( iMetadataCommand->ExecuteL(EGlxCmdProperties) );
       
   342     //check that tag manager command is not consumend
       
   343     EUNIT_ASSERT( !iMetadataCommand->ExecuteL(EGlxCmdTagManager) );
       
   344     
       
   345     //check that tag manager command is consumend
       
   346     EUNIT_ASSERT( iTagManagerCommand->ExecuteL(EGlxCmdTagManager) );
       
   347     //check that metadata command is not consumend
       
   348     EUNIT_ASSERT( !iTagManagerCommand->ExecuteL(EGlxCmdProperties) );
       
   349     }
       
   350 
       
   351 //  TEST TABLE
       
   352 
       
   353 EUNIT_BEGIN_TEST_TABLE(
       
   354     UT_propertycommandhandlers,
       
   355     "Property command handler unit testing.",
       
   356     "Property Command handler" )
       
   357 
       
   358 EUNIT_TEST(
       
   359     "NewL ",
       
   360     "CGlxCommandHandlerProperties",
       
   361     "NewL",
       
   362     "FUNCTIONALITY",
       
   363     SetupL, PropertyCommandHandlerNewL, Teardown)
       
   364     
       
   365 EUNIT_TEST(
       
   366     "ExecuteL ",
       
   367     "CGlxCommandHandlerProperties",
       
   368     "ExecuteL",
       
   369     "FUNCTIONALITY",
       
   370     SetupL, PropertyCommandHandlerExecuteL, Teardown)
       
   371 
       
   372 
       
   373 EUNIT_END_TEST_TABLE
       
   374 
       
   375 //  END OF FILE