phonebookengines_old/contactsmodel/tsrc/T_VExportBirthday.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This harness Creates a Contact Item and adds a single field to it (a birthday)
       
    15 // This is then exported to a vcard and the date from this export is checked.
       
    16 // This is to prove that INC038574 that time is not exported with the birthday and therefore
       
    17 // time differences from UTC do not affect the birthday date.
       
    18 // 
       
    19 //
       
    20 
       
    21 #include <vutil.h>
       
    22 #include <e32test.h>
       
    23 #include <cntdb.h>
       
    24 #include <cntvcard.h>
       
    25 #include <cntitem.h>
       
    26 #include <cntfield.h>
       
    27 #include <cntfldst.h>
       
    28 #include "T_UTILS.H"
       
    29 
       
    30 LOCAL_D CCntTest* CntTest=NULL;
       
    31 LOCAL_D const TPtrC KDatabaseFileName=_L("C:VBirthdayDb.cdb");
       
    32 
       
    33 LOCAL_D RTest test(_L("T_VExportBirthday"));
       
    34 
       
    35 LOCAL_C void MainTestsL()
       
    36 /**
       
    37  *Testing the vcard export of a birthday field from the contact model.
       
    38  *
       
    39  */
       
    40 	{
       
    41 	CContactDatabase *db=CntTest->CreateDatabaseL();
       
    42 	
       
    43 	// Versit treats months and days as being numbers from 0, therefore EAugust is 7, and the 
       
    44 	// day here (0) represents the first day.  Some seconds are added to this date,
       
    45 	// but the birthday should only be exported as a date without time.
       
    46 	TDateTime date(1976,EAugust,0,22,0,0,0);
       
    47 	_LIT8(KExpectedExportDateStr,"19760801");
       
    48 		
       
    49 	//Create a contact with just a birthday date
       
    50 	const TContactItemId templateId = db->TemplateId();
       
    51 	CContactItem* templateCard = db->ReadContactLC(templateId);
       
    52 	CContactCard* card = CContactCard::NewL(templateCard); 
       
    53 	CleanupStack::PushL(card);
       
    54 	//
       
    55 	CContactItemFieldSet& cardFields=card->CardFields();
       
    56 	// Set the birthday
       
    57 	TInt pos=cardFields.Find(KUidContactFieldBirthday);
       
    58 	if (pos!=KErrNotFound)
       
    59 		{
       
    60 		cardFields[pos].SetMapping(KUidContactFieldVCardMapBDAY);
       
    61 		cardFields[pos].DateTimeStorage()->SetTime(date);
       
    62 		}
       
    63 	
       
    64 	//Create contact now
       
    65 	const TContactItemId id = db->AddNewContactL(*card);
       
    66 	CleanupStack::PopAndDestroy(2, templateCard); 
       
    67 	CContactIdArray* idArray = CContactIdArray::NewLC();
       
    68 	idArray->AddL(id);
       
    69 	
       
    70 	//export contact to buf
       
    71 	TBuf8<256> buf;
       
    72 	RDesWriteStream vCardWriteStream(buf);
       
    73 	vCardWriteStream.PushL();
       
    74 	db->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl),*idArray,vCardWriteStream,CContactVCardConverter::EDefault);
       
    75 	vCardWriteStream.CommitL();
       
    76 	CleanupStack::PopAndDestroy(&vCardWriteStream);
       
    77 	CleanupStack::PopAndDestroy(idArray); 
       
    78 	
       
    79 	//check there is no date in export
       
    80 	pos=buf.Find(KVersitTokenBDAY);
       
    81 	test(pos>0);
       
    82 	pos+=5;
       
    83 	_LIT8(KEndOfLine,"\r\n");
       
    84 	TInt datePos = buf.Mid(pos).Find(KEndOfLine);
       
    85 	TPtrC8 extractedDate = buf.Mid(pos,datePos);
       
    86 	test(TPtrC8(KExpectedExportDateStr)==extractedDate);
       
    87 	
       
    88 	CntTest->CloseDatabase();
       
    89 	}
       
    90 
       
    91 /**
       
    92 
       
    93 @SYMTestCaseID     PIM-T-VEXPORTBIRTHDAY-0001
       
    94 
       
    95 */
       
    96 
       
    97 void DoTestsL()
       
    98     {
       
    99 	test.Start(_L("@SYMTESTCaseID:PIM-T-VEXPORTBIRTHDAY-0001 Test Versit Export of a Birthday Date"));
       
   100 
       
   101 	TRAPD(ret,MainTestsL());
       
   102 	test(ret==KErrNone);
       
   103 
       
   104 	test.Next(_L("Delete database"));
       
   105 
       
   106 	TRAPD(ret2,CntTest->DeleteDatabaseL());
       
   107 	test(ret2==KErrNone);
       
   108     }
       
   109 
       
   110 GLDEF_C TInt E32Main()
       
   111 	{
       
   112 	__UHEAP_MARK;
       
   113     CntTest=new(ELeave) CCntTest;
       
   114 	CntTest->ConstructL(test,KDatabaseFileName);
       
   115     TRAPD(err,DoTestsL());
       
   116 	CntTest->EndTestLib(err);
       
   117 	__UHEAP_MARKEND;
       
   118 	return KErrNone;
       
   119     }
       
   120 
       
   121