contacts_pub/phonebook_vcard_importexport_api/tsrc/bc/src/BCTestPbkVcardImportExportBlocks.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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:        ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // [INCLUDE FILES] - do not remove
       
    27 #include <e32svr.h>
       
    28 #include <StifParser.h>
       
    29 #include <Stiftestinterface.h>
       
    30 #include "BCTestPbkVcardImportExport.h"
       
    31 
       
    32 #include <BCardEng.h>
       
    33 #include <CPbkContactItem.h>
       
    34 #include "PbkFields.hrh"
       
    35 
       
    36 
       
    37 // EXTERNAL DATA STRUCTURES
       
    38 //extern  ?external_data;
       
    39 
       
    40 // EXTERNAL FUNCTION PROTOTYPES  
       
    41 //extern ?external_function( ?arg_type,?arg_type );
       
    42 
       
    43 // CONSTANTS
       
    44 //const ?type ?constant_var = ?constant;
       
    45 
       
    46 // MACROS
       
    47 //#define ?macro ?macro_def
       
    48 
       
    49 // LOCAL CONSTANTS AND MACROS
       
    50 //const ?type ?constant_var = ?constant;
       
    51 //#define ?macro_name ?macro_def
       
    52 
       
    53 // MODULE DATA STRUCTURES
       
    54 //enum ?declaration
       
    55 //typedef ?declaration
       
    56 
       
    57 // LOCAL FUNCTION PROTOTYPES
       
    58 //?type ?function_name( ?arg_type, ?arg_type );
       
    59 
       
    60 // FORWARD DECLARATIONS
       
    61 //class ?FORWARD_CLASSNAME;
       
    62 
       
    63 // ============================= LOCAL FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // ?function_name ?description.
       
    67 // ?description
       
    68 // Returns: ?value_1: ?description
       
    69 //          ?value_n: ?description_line1
       
    70 //                    ?description_line2
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 /*
       
    74 ?type ?function_name(
       
    75     ?arg_type arg,  // ?description
       
    76     ?arg_type arg)  // ?description
       
    77     {
       
    78 
       
    79     ?code  // ?comment
       
    80 
       
    81     // ?comment
       
    82     ?code
       
    83     }
       
    84 */
       
    85 
       
    86 // ============================ MEMBER FUNCTIONS ===============================
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CBCTestPbkVcardImportExport::Delete
       
    90 // Delete here all resources allocated and opened from test methods. 
       
    91 // Called from destructor. 
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CBCTestPbkVcardImportExport::Delete() 
       
    95     {
       
    96 
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CBCTestPbkVcardImportExport::RunMethodL
       
   101 // Run specified method. Contains also table of test mothods and their names.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CBCTestPbkVcardImportExport::RunMethodL( 
       
   105     CStifItemParser& aItem ) 
       
   106     {
       
   107 
       
   108     static TStifFunctionInfo const KFunctions[] =
       
   109         {  
       
   110         // Copy this line for every implemented function.
       
   111         // First string is the function name used in TestScripter script file.
       
   112         // Second is the actual implementation member function. 
       
   113         ENTRY( "Example", CBCTestPbkVcardImportExport::ExampleL ),
       
   114         ENTRY( "TestNewL", CBCTestPbkVcardImportExport::TestNewL ),
       
   115         ENTRY( "TestImportVCardWithMemoryL", CBCTestPbkVcardImportExport::TestImportVCardWithMemoryL ),
       
   116         ENTRY( "TestEmptyStreamL", CBCTestPbkVcardImportExport::TestEmptyStreamL ),
       
   117         ENTRY( "TestImportPicVCardL", CBCTestPbkVcardImportExport::TestImportPicVCardL ),
       
   118         ENTRY( "TestImportCCardWithMemoryL", CBCTestPbkVcardImportExport::TestImportCCardWithMemoryL ),
       
   119         ENTRY( "TestImportCCardPhoneNbrsL", CBCTestPbkVcardImportExport::TestImportCCardPhoneNbrsL ),
       
   120         ENTRY( "TestMaxSizeCompactCardL", CBCTestPbkVcardImportExport::TestMaxSizeCompactCardL ),
       
   121         ENTRY( "TestNoBusinessCompactCardL", CBCTestPbkVcardImportExport::TestNoBusinessCompactCardL ),
       
   122         ENTRY( "TestSupportsFieldTypeL", CBCTestPbkVcardImportExport::TestSupportsFieldTypeL ),
       
   123         ENTRY( "TestExportCardL", CBCTestPbkVcardImportExport::TestExportCardL ),
       
   124         ENTRY( "TestExportCard2L", CBCTestPbkVcardImportExport::TestExportCard2L ),
       
   125         //ADD NEW ENTRY HERE
       
   126         // [test cases entries] - Do not remove
       
   127 
       
   128         };
       
   129 
       
   130     const TInt count = sizeof( KFunctions ) / 
       
   131                         sizeof( TStifFunctionInfo );
       
   132 
       
   133     return RunInternalL( KFunctions, count, aItem );
       
   134 
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CBCTestPbkVcardImportExport::ExampleL
       
   139 // Example test method function.
       
   140 // (other items were commented in a header).
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CBCTestPbkVcardImportExport::ExampleL( CStifItemParser& aItem )
       
   144     {
       
   145 
       
   146     // Print to UI
       
   147     _LIT( KBCTestPbkVcardImportExport, "BCTestPbkVcardImportExport" );
       
   148     _LIT( KExample, "In Example" );
       
   149     TestModuleIf().Printf( 0, KBCTestPbkVcardImportExport, KExample );
       
   150     // Print to log file
       
   151     iLog->Log( KExample );
       
   152 
       
   153     TInt i = 0;
       
   154     TPtrC string;
       
   155     _LIT( KParam, "Param[%i]: %S" );
       
   156     while ( aItem.GetNextString ( string ) == KErrNone )
       
   157         {
       
   158         TestModuleIf().Printf( i, KBCTestPbkVcardImportExport, 
       
   159                                 KParam, i, &string );
       
   160         i++;
       
   161         }
       
   162 
       
   163     return KErrNone;
       
   164 
       
   165     }
       
   166 
       
   167 TInt CBCTestPbkVcardImportExport::TestNewL( CStifItemParser& /*aItem*/ )
       
   168     {
       
   169 
       
   170      CBCardEngine*	testBCEngine;
       
   171      testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   172 
       
   173 		if(testBCEngine)
       
   174 			{ 
       
   175 					delete testBCEngine;
       
   176 					testBCEngine = NULL;
       
   177 			}
       
   178 			
       
   179     return KErrNone;
       
   180 
       
   181     }
       
   182     
       
   183   TInt CBCTestPbkVcardImportExport::TestImportVCardWithMemoryL( CStifItemParser& /*aItem*/ )
       
   184   {
       
   185 
       
   186    CBCardEngine*	testBCEngine;
       
   187    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   188    RFs	iFs;
       
   189    
       
   190    
       
   191    	User::LeaveIfError(iFs.Connect());
       
   192     User::LeaveIfError(iReadStream.Open(iFs,KCardBasic03, EFileRead));
       
   193     
       
   194     iContactItem = iContactEngine->CreateEmptyContactL();
       
   195     
       
   196     TRAPD(err, testBCEngine->ImportBusinessCardL(*iContactItem, iReadStream));
       
   197     
       
   198     if(testBCEngine)
       
   199 				{ 
       
   200 					delete testBCEngine;
       
   201 					testBCEngine = NULL;
       
   202 				}	
       
   203 		
       
   204 		iFs.Close();
       
   205 			
       
   206     return err;
       
   207 		 	
       
   208   }
       
   209   
       
   210   TInt CBCTestPbkVcardImportExport::TestEmptyStreamL( CStifItemParser& /*aItem*/ )
       
   211   {
       
   212 
       
   213    CBCardEngine*	testBCEngine;
       
   214    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   215    RFs	iFs;
       
   216    
       
   217    
       
   218    	User::LeaveIfError(iFs.Connect());
       
   219     User::LeaveIfError(iReadStream.Open(iFs,KCardDummy, EFileRead));
       
   220     
       
   221     iContactItem = iContactEngine->CreateEmptyContactL();
       
   222     
       
   223     TRAPD(err, testBCEngine->ImportBusinessCardL(*iContactItem, iReadStream));
       
   224     
       
   225     if(testBCEngine)
       
   226 				{ 
       
   227 					delete testBCEngine;
       
   228 					testBCEngine = NULL;
       
   229 				}	
       
   230 		iFs.Close();
       
   231 				
       
   232     return err;
       
   233 
       
   234   }
       
   235   
       
   236  
       
   237  TInt CBCTestPbkVcardImportExport::TestImportPicVCardL( CStifItemParser& /*aItem*/ )
       
   238   {
       
   239 
       
   240    CBCardEngine*	testBCEngine;
       
   241    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   242    RFs	iFs;
       
   243    
       
   244    
       
   245    	User::LeaveIfError(iFs.Connect());
       
   246     User::LeaveIfError(iReadStream.Open(iFs,KCardPicture2, EFileRead));
       
   247     
       
   248     iContactItem = iContactEngine->CreateEmptyContactL();
       
   249     
       
   250     TRAPD(err, testBCEngine->ImportBusinessCardL(*iContactItem, iReadStream));
       
   251     
       
   252    	if(testBCEngine)
       
   253 				{ 
       
   254 					delete testBCEngine;
       
   255 					testBCEngine = NULL;
       
   256 				}	
       
   257 		iFs.Close();
       
   258 				
       
   259     return err;
       
   260 
       
   261   }
       
   262   
       
   263   TInt CBCTestPbkVcardImportExport::TestImportCCardWithMemoryL( CStifItemParser& /*aItem*/ )
       
   264   {
       
   265 
       
   266    CBCardEngine*	testBCEngine;
       
   267    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   268    RFs	iFs;
       
   269    
       
   270    
       
   271    	User::LeaveIfError(iFs.Connect());
       
   272     User::LeaveIfError(iReadStream.Open(iFs,KCardBasicCC01, EFileRead));
       
   273     
       
   274     iContactItem = iContactEngine->CreateEmptyContactL();
       
   275     
       
   276     TRAPD(err, testBCEngine->ImportCompactBusinessCardL(*iContactItem, iReadStream));
       
   277     
       
   278     if(testBCEngine)
       
   279 				{ 
       
   280 					delete testBCEngine;
       
   281 					testBCEngine = NULL;
       
   282 				}	
       
   283 		
       
   284 		iFs.Close();
       
   285 				
       
   286     return err;
       
   287 	
       
   288   }
       
   289   
       
   290   TInt CBCTestPbkVcardImportExport::TestImportCCardPhoneNbrsL( CStifItemParser& /*aItem*/ )
       
   291   {
       
   292 
       
   293    CBCardEngine*	testBCEngine;
       
   294    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   295    RFs	iFs;
       
   296    
       
   297    
       
   298    	User::LeaveIfError(iFs.Connect());
       
   299     User::LeaveIfError(iReadStream.Open(iFs,KCardBasicCC02, EFileRead));
       
   300     
       
   301     iContactItem = iContactEngine->CreateEmptyContactL();
       
   302     
       
   303     TRAPD(err, testBCEngine->ImportCompactBusinessCardL(*iContactItem, iReadStream));
       
   304     
       
   305     if(testBCEngine)
       
   306 				{ 
       
   307 					delete testBCEngine;
       
   308 					testBCEngine = NULL;
       
   309 				}	
       
   310 		iFs.Close();
       
   311 				
       
   312     return err;
       
   313 	
       
   314   }
       
   315   
       
   316   TInt CBCTestPbkVcardImportExport::TestMaxSizeCompactCardL( CStifItemParser& /*aItem*/ )
       
   317   {
       
   318 
       
   319    CBCardEngine*	testBCEngine;
       
   320    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   321    RFs	iFs;
       
   322    
       
   323    
       
   324    	User::LeaveIfError(iFs.Connect());
       
   325     User::LeaveIfError(iReadStream.Open(iFs,KCardBasicMaxSize, EFileRead));
       
   326     
       
   327     iContactItem = iContactEngine->CreateEmptyContactL();
       
   328     
       
   329     TRAPD(err, testBCEngine->ImportCompactBusinessCardL(*iContactItem, iReadStream));
       
   330     
       
   331     if(testBCEngine)
       
   332 				{ 
       
   333 					delete testBCEngine;
       
   334 					testBCEngine = NULL;
       
   335 				}	
       
   336 		iFs.Close();
       
   337 				
       
   338     return err;
       
   339 	
       
   340   }
       
   341   
       
   342   TInt CBCTestPbkVcardImportExport::TestNoBusinessCompactCardL( CStifItemParser& /*aItem*/ )
       
   343   {
       
   344 
       
   345    CBCardEngine*	testBCEngine;
       
   346    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   347    RFs	iFs;
       
   348    
       
   349    
       
   350    	User::LeaveIfError(iFs.Connect());
       
   351     User::LeaveIfError(iReadStream.Open(iFs,KCardBasicNoBusiness, EFileRead));
       
   352     
       
   353     iContactItem = iContactEngine->CreateEmptyContactL();
       
   354     
       
   355     TRAPD(err, testBCEngine->ImportCompactBusinessCardL(*iContactItem, iReadStream));
       
   356     
       
   357     if(testBCEngine)
       
   358 				{ 
       
   359 					delete testBCEngine;
       
   360 					testBCEngine = NULL;
       
   361 				}	
       
   362 		iFs.Close();
       
   363 				
       
   364     return err;
       
   365   }
       
   366   
       
   367   TInt CBCTestPbkVcardImportExport::TestSupportsFieldTypeL( CStifItemParser& /*aItem*/ )
       
   368   {
       
   369 
       
   370    CBCardEngine*	testBCEngine;
       
   371    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   372    
       
   373    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdLastName));
       
   374    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdFirstName));
       
   375    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberGeneral));
       
   376    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberStandard));
       
   377    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberHome));
       
   378    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberWork));
       
   379    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberMobile));
       
   380    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdFaxNumber));
       
   381    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPagerNumber));
       
   382    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdEmailAddress));
       
   383    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPostalAddress));
       
   384    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdURL));
       
   385    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdJobTitle));
       
   386    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdCompanyName));
       
   387    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdCompanyAddress));
       
   388    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdDate));
       
   389    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdNote));
       
   390    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdThumbnailImage));
       
   391    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPOBox));
       
   392    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdExtendedAddress));
       
   393    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdStreetAddress));
       
   394    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPostalCode));
       
   395    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdCity));
       
   396    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdState));
       
   397    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdCountry));
       
   398    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdSecondName));
       
   399    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPhoneNumberVideo));
       
   400    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdVOIP));
       
   401    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPushToTalk));
       
   402    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdShareView));
       
   403    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdSIPID));
       
   404    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdPrefix));
       
   405    ASSERT(testBCEngine->SupportsFieldType(EPbkFieldIdSuffix));
       
   406    
       
   407    if(testBCEngine)
       
   408 				{ 
       
   409 					delete testBCEngine;
       
   410 					testBCEngine = NULL;
       
   411 				}	
       
   412 				
       
   413     
       
   414 	 return KErrNone;
       
   415   }
       
   416   
       
   417 TInt CBCTestPbkVcardImportExport::TestExportCardL( CStifItemParser& /*aItem*/ )
       
   418   {
       
   419 
       
   420    CBCardEngine*	testBCEngine;
       
   421    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   422    RFs	iFs;
       
   423    
       
   424    
       
   425    	User::LeaveIfError(iFs.Connect());
       
   426     User::LeaveIfError(iWriteStream.Replace(iFs,KCardOut01, EFileRead));
       
   427     
       
   428     iContactItem = iContactEngine->CreateEmptyContactL();
       
   429     
       
   430     // actually export the data:    
       
   431     TRAPD(err,testBCEngine->ExportBusinessCardL(iWriteStream, *iContactItem));
       
   432     
       
   433     if(testBCEngine)
       
   434 				{ 
       
   435 					delete testBCEngine;
       
   436 					testBCEngine = NULL;
       
   437 				}	
       
   438 		iFs.Close();
       
   439 				
       
   440     return err;
       
   441   }
       
   442   
       
   443   TInt CBCTestPbkVcardImportExport::TestExportCard2L( CStifItemParser& /*aItem*/ )
       
   444   {
       
   445 
       
   446    CBCardEngine*	testBCEngine;
       
   447    testBCEngine = CBCardEngine::NewL(iContactEngine);
       
   448    RFs	iFs;
       
   449    
       
   450    
       
   451    	User::LeaveIfError(iFs.Connect());
       
   452     User::LeaveIfError(iWriteStream.Replace(iFs,KCardOut02, EFileRead));
       
   453     
       
   454     iContactItem = iContactEngine->CreateEmptyContactL();
       
   455     
       
   456     // actually export the data:    
       
   457     TRAPD(err,testBCEngine->ExportBusinessCardL(iWriteStream, *iContactItem));
       
   458     
       
   459     if(testBCEngine)
       
   460 				{ 
       
   461 					delete testBCEngine;
       
   462 					testBCEngine = NULL;
       
   463 				}	
       
   464 		iFs.Close();
       
   465 				
       
   466     return err;
       
   467   }
       
   468 // -----------------------------------------------------------------------------
       
   469 // CBCTestPbkVcardImportExport::?member_function
       
   470 // ?implementation_description
       
   471 // (other items were commented in a header).
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 /*
       
   475 TInt CBCTestPbkVcardImportExport::?member_function(
       
   476    CItemParser& aItem )
       
   477    {
       
   478 
       
   479    ?code
       
   480 
       
   481    }
       
   482 */
       
   483 
       
   484 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   485 // None
       
   486 
       
   487 //  [End of File] - Do not remove