photos_plat/controllers_collection_api/tsrc/ut_collectioninfo/src/ut_collectioninfoBlocks.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2009 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: This file contains testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <Stiftestinterface.h>
       
    22 #include <glxcollectionmanager.h>
       
    23 //#include <glxcollectionselectionpopup.h>
       
    24 #include <glxcollectionpluginalbums.hrh>
       
    25 #include <glxcollectioninfo.h>
       
    26 #include "ut_collectioninfo.h"
       
    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 
       
    37 // MACROS
       
    38 //#define ?macro ?macro_def
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 //const ?type ?constant_var = ?constant;
       
    42 //#define ?macro_name ?macro_def
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 //enum ?declaration
       
    46 //typedef ?declaration
       
    47 
       
    48 // LOCAL FUNCTION PROTOTYPES
       
    49 //?type ?function_name( ?arg_type, ?arg_type );
       
    50 
       
    51 // FORWARD DECLARATIONS
       
    52 //class ?FORWARD_CLASSNAME;
       
    53 
       
    54 // ============================= LOCAL FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // ?function_name ?description.
       
    58 // ?description
       
    59 // Returns: ?value_1: ?description
       
    60 //          ?value_n: ?description_line1
       
    61 //                    ?description_line2
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 /*
       
    65 ?type ?function_name(
       
    66     ?arg_type arg,  // ?description
       
    67     ?arg_type arg)  // ?description
       
    68     {
       
    69 
       
    70     ?code  // ?comment
       
    71 
       
    72     // ?comment
       
    73     ?code
       
    74     }
       
    75 */
       
    76 
       
    77 // ============================ MEMBER FUNCTIONS ===============================
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Cut_collectioninfo::Delete
       
    81 // Delete here all resources allocated and opened from test methods. 
       
    82 // Called from destructor. 
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void Cut_collectioninfo::Delete() 
       
    86     {
       
    87 
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // Cut_collectioninfo::RunMethodL
       
    92 // Run specified method. Contains also table of test mothods and their names.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 TInt Cut_collectioninfo::RunMethodL( 
       
    96     CStifItemParser& aItem ) 
       
    97     {
       
    98 
       
    99     static TStifFunctionInfo const KFunctions[] =
       
   100         {  
       
   101         // Copy this line for every implemented function.
       
   102         // First string is the function name used in TestScripter script file.
       
   103         // Second is the actual implementation member function. 
       
   104                 //ADD NEW ENTRY HERE
       
   105         ENTRY( "TestNewL", Cut_collectioninfo::Test_NewL ),
       
   106         ENTRY( "TestExistL", Cut_collectioninfo::Test_ExistsL ),
       
   107         ENTRY( "TestTitleL", Cut_collectioninfo::Test_TitleL ),
       
   108         ENTRY( "TestIdL", Cut_collectioninfo::Test_IdL ),
       
   109         ENTRY( "TestDestructorL", Cut_collectioninfo::Test_DestructorL ),
       
   110         
       
   111         // [test cases entries] - Do not remove
       
   112 
       
   113         };
       
   114 
       
   115     const TInt count = sizeof( KFunctions ) / 
       
   116                         sizeof( TStifFunctionInfo );
       
   117 
       
   118     return RunInternalL( KFunctions, count, aItem );
       
   119 
       
   120     }
       
   121 
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // Cut_collectioninfo::?member_function
       
   126 // ?implementation_description
       
   127 // (other items were commented in a header).
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 /*
       
   131 TInt Cut_collectioninfo::?member_function(
       
   132    CItemParser& aItem )
       
   133    {
       
   134 
       
   135    ?code
       
   136 
       
   137    }
       
   138 */
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // Cut_collectioninfo::Test_NewL
       
   142 // Test for CGlxCollectionInfo::NewL API 
       
   143 // -----------------------------------------------------------------------------
       
   144 
       
   145 TInt Cut_collectioninfo::Test_NewL( CStifItemParser& /*aItem */)
       
   146     {
       
   147     // Print to UI
       
   148     _LIT( KTest_one, "Test_one" );
       
   149     _LIT( KTestText, "In Test_NewL" );
       
   150     TestModuleIf().Printf( 0, KTest_one, KTestText );
       
   151     // Print to log file
       
   152     iLog->Log( KTestText ); 
       
   153 
       
   154    	TRAPD(err,iCollectionInfo = CGlxCollectionInfo::NewL(KGlxCollectionPluginAlbumsImplementationUid));
       
   155     if(iCollectionInfo)
       
   156 		{	
       
   157 		// Test case passed if CGlxCollectionInfo instance is created
       
   158 	    iLog->Log(_L("CGlxCollectionManager::NewL() Passed"));      
       
   159 	    delete iCollectionInfo;
       
   160 	    iCollectionInfo = NULL;
       
   161 	    User::InfoPrint(_L("test CGlxCollectionInfo::NewL passed"));
       
   162 	    return KErrNone;	    	
       
   163 		}
       
   164 	else
       
   165 	   {
       
   166 	   //  Test case Failed if CGlxCollectionManager instance is not created
       
   167 	   iLog->Log(_L("CGlxCollectionManager::NewL() Failed"));      
       
   168 	   User::InfoPrint(_L("test newL failed"));
       
   169 	   return err;
       
   170 	   }   		  
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // Cut_collectioninfo::Test_ExistsL
       
   175 // Test for CGlxCollectionInfo::Exists() API 
       
   176 // Creates the CGlxCollectionInfo instance and calls the Exists() API 
       
   177 // -----------------------------------------------------------------------------
       
   178 
       
   179 TInt Cut_collectioninfo::Test_ExistsL( CStifItemParser& /*aItem */)
       
   180 	{
       
   181 	 // Print to UI
       
   182     _LIT( KTest_two, "Test_two" );
       
   183     _LIT( KTestText, "In Test_ExistsL" );
       
   184     TestModuleIf().Printf( 0, KTest_two, KTestText );
       
   185     // Print to log file
       
   186     iLog->Log( KTestText );
       
   187     
       
   188 	TInt apiErr = KErrNone;
       
   189 	if(!iCollectionInfo)
       
   190 		{
       
   191 		TRAPD(err,iCollectionInfo = CGlxCollectionInfo::NewL(KGlxCollectionPluginAlbumsImplementationUid));
       
   192 		if(iCollectionInfo)
       
   193 			{
       
   194 			apiErr = iCollectionInfo->Exists();
       
   195 			if(!apiErr) //true value // @ToDo: (!apiErr) must chage to (apiErr) and we need to have 2 test cases (1) for case where a collection exists and it is tested for existence. (2) where a collection does not exist and it is tested for non-existence.
       
   196 				{
       
   197 				iLog->Log(_L("CGlxCollectionManager::Exists() Passed"));
       
   198 				User::InfoPrint(_L("Test Exists Passed"));
       
   199 				return KErrNone;
       
   200 				}
       
   201 			else 
       
   202 				{
       
   203 				iLog->Log(_L("CGlxCollectionManager::Exists() Failed"));
       
   204 				User::InfoPrint(_L("Test Exists Failed"));
       
   205 				return KErrNotFound;
       
   206 				}					
       
   207 			}
       
   208 		else
       
   209 			{
       
   210 			return err;
       
   211 			}		
       
   212 		}					
       
   213 	}
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // Cut_collectioninfo::Test_TitleL
       
   217 // Test for CGlxCollectionInfo::Title() API 
       
   218 // 
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TInt Cut_collectioninfo::Test_TitleL( CStifItemParser& /*aItem */)
       
   222 	{
       
   223 	 // Print to UI
       
   224     _LIT( KTest_three, "Test_three" );
       
   225     _LIT( KTestText, "In Test_TitleL" );
       
   226     TestModuleIf().Printf( 0, KTest_three, KTestText );
       
   227     // Print to log file
       
   228     iLog->Log( KTestText );
       
   229     
       
   230 	TRAPD(err,iCollectionInfo = CGlxCollectionInfo::NewL(KGlxCollectionPluginAlbumsImplementationUid));
       
   231 	HBufC* textResource = NULL;
       
   232 	if(iCollectionInfo)
       
   233 		{
       
   234 		textResource = iCollectionInfo->Title().AllocLC();
       
   235 		if(textResource->Length() != 0) //title of collection info is returned
       
   236 			{
       
   237 			//passed
       
   238 			iLog->Log(_L("CGlxCollectionManager::Title()  Passed"));
       
   239 			User::InfoPrint(_L("Test Title Passed"));
       
   240 			CleanupStack::PopAndDestroy( textResource );
       
   241 			return KErrNone;
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			if(textResource->Des() == KNullDesC) //title is returned as KNullDesC
       
   246 				{
       
   247 				//passed since Title() may return a KNullDesC
       
   248 				iLog->Log(_L("CGlxCollectionManager::Title()  Passed"));
       
   249 				User::InfoPrint(_L("Test Title Passed"));
       
   250 				CleanupStack::PopAndDestroy( textResource );
       
   251 				return KErrNone;	
       
   252 				}
       
   253 			else
       
   254 				{
       
   255 				//failed if its a junk value, not sure of how to check for this
       
   256 				//as the API checks and returns null value if the title does
       
   257 				//exist and hence there cannot be a failure scenario
       
   258 				iLog->Log(_L("CGlxCollectionManager::Title() Failed"));
       
   259 				User::InfoPrint(_L("Test Title Failed"));
       
   260 				CleanupStack::PopAndDestroy( textResource );
       
   261 				//Returning KErrNotFound as Title is not available. Still not 100% sure of this.
       
   262 				return KErrNotFound;	
       
   263 				}		
       
   264 			}	
       
   265 		}
       
   266 	else
       
   267 		{
       
   268 		return err;
       
   269 		}	
       
   270 	}
       
   271 // -----------------------------------------------------------------------------
       
   272 // Cut_collectioninfo::Test_IdL
       
   273 // Test for CGlxCollectionInfo::Id() API 
       
   274 // 
       
   275 // -----------------------------------------------------------------------------
       
   276 //	
       
   277 TInt Cut_collectioninfo::Test_IdL( CStifItemParser& /*aItem */)
       
   278 	{
       
   279 	 // Print to UI
       
   280     _LIT( KTest_four, "Test_four" );
       
   281     _LIT( KTestText, "In Test_IdL" );
       
   282     TestModuleIf().Printf( 0, KTest_four, KTestText );
       
   283     // Print to log file
       
   284     iLog->Log( KTestText );
       
   285     TInt err = KErrNone;;
       
   286 	if(!iCollectionInfo)
       
   287 		TRAP(err,iCollectionInfo = CGlxCollectionInfo::NewL(KGlxCollectionPluginAlbumsImplementationUid));
       
   288 	if(iCollectionInfo)
       
   289 		{
       
   290 		TUint32 collectionId = 0;
       
   291 		collectionId = iCollectionInfo->Id();
       
   292 		if(collectionId) //if non zero
       
   293 			{
       
   294 			//passed
       
   295 			iLog->Log(_L("CGlxCollectionManager::Id()  Passed"));			
       
   296 			User::InfoPrint(_L("Test Id Passed"));
       
   297 			return KErrNone;
       
   298 			}
       
   299 		else
       
   300 			{
       
   301 			//failed if zero
       
   302 			iLog->Log(_L("CGlxCollectionManager::Id()  Failed"));
       
   303 			User::InfoPrint(_L("Test Id failed"));
       
   304 			//Returning KErrNotFound as Id() is not available. Still not 100% sure of this.
       
   305 			return KErrNotFound;
       
   306 			}
       
   307 		}
       
   308 	else
       
   309 		{			
       
   310 		return err;	
       
   311 		}	
       
   312 }
       
   313 // -----------------------------------------------------------------------------
       
   314 // Cut_collectioninfo::Test_DestructorL
       
   315 // Test for CGlxCollectionInfo::~CGlxCollectionInfo() API 
       
   316 // Checks if instance is correctly deleted without any memory leaks
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 TInt Cut_collectioninfo::Test_DestructorL( CStifItemParser& /*aItem */)
       
   320 	{
       
   321 	// Print to UI
       
   322     _LIT( KTest_five, "Test_five" );
       
   323     _LIT( KTestText, "In Test_DestructorL" );
       
   324     TestModuleIf().Printf( 0, KTest_five, KTestText );
       
   325     // Print to log file
       
   326     iLog->Log( KTestText );	
       
   327     
       
   328     TInt err = KErrNone;
       
   329 	if(!iCollectionInfo)
       
   330 		TRAPD(err,iCollectionInfo = CGlxCollectionInfo::NewL(KGlxCollectionPluginAlbumsImplementationUid));
       
   331 	if(iCollectionInfo)
       
   332 		{
       
   333 		__UHEAP_MARK;
       
   334 		delete iCollectionInfo;			
       
   335 		iCollectionInfo = NULL;
       
   336 		__UHEAP_MARKEND;
       
   337 		iLog->Log(_L("~CollectionManager() :: Passed"));
       
   338 		User::InfoPrint(_L("Test Destructor Passed"));
       
   339 		return KErrNone;
       
   340 		}
       
   341 	else
       
   342 		{
       
   343 		return err;	
       
   344 		}			
       
   345 	}
       
   346 	
       
   347 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   348 // None
       
   349 
       
   350 //  [End of File] - Do not remove