summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_cviewcontact.cpp
blob: d5a4145496438aaa06a692407c4141346d710c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include <e32test.h>
#include <s32mem.h>
#include <cntdb.h>
#include <cntviewbase.h>
#include "t_utils.h"

_LIT(KTestName,"T_CVIEWCONTACT");

#ifdef SYMIAN_SECURE_DBMS
_LIT(KDatabaseFileName,"C:\\T_CVIEWCONTACT");
#else
_LIT(KDatabaseFileName,"C:\\T_CVIEWCONTACT");
#endif

CCntTest* CntTest=NULL;
LOCAL_D RTest test(KTestName);

const TContactItemId KContactId = 5;
const TContactItemId KModifiedContactId = 6;
_LIT(KContactName,"ContactName");
_LIT(KContactSurname,"ContactSurname");

/** 
 * Test different construction methods.
 */
LOCAL_C void TestConstructionL()
	{
	CViewContact* contact = CViewContact::NewLC(KContactId);

	CViewContact* contact2 = CViewContact::NewL(*contact);
	delete contact2;
	CleanupStack::PopAndDestroy(contact);
	}

/** 
 * Test other CViewContact methods.
 */
LOCAL_C void TestMiscMethodsL()
	{
	CViewContact* contact = CViewContact::NewLC(KContactId);
	test(contact->Id()==KContactId);
	contact->SetId(KModifiedContactId);
	test(contact->Id()==KModifiedContactId);
	contact->SetContactType(CViewContact::EContactItem);
	test(contact->ContactType()==CViewContact::EContactItem);
	contact->SetContactType(CViewContact::EGroup);
	test(contact->ContactType()==CViewContact::EGroup);
	CleanupStack::PopAndDestroy(contact);
	}

/** 
 * Test case 1
 * Add an empty Field when the existing iFieldTextBuf is empty
 * Action : Add an empty Field (i.e. length = 0) when the existing iFieldTextBuf is empty
 * Result : Empty field added
 */
LOCAL_C void AddEmptyFieldL()
	{
	CViewContact* contact = CViewContact::NewLC(KContactId);
	contact->AddFieldL(KNullDesC);
	test(contact->FieldCount()==1);
	test(contact->Field(0)==KNullDesC);
	CleanupStack::PopAndDestroy(contact);
	}

/** 
 * Test case 2
 * Add an empty Field when the existing iFieldTextBuf is not empty 
 * Action : Add an empty Field (i.e. length = 0) when the existing iFieldTextBuf contains some fields already
 * Result : Empty field added
 */
LOCAL_C void AddFieldL()
	{
	CViewContact* contact = CViewContact::NewLC(KContactId);
	contact->AddFieldL(KContactName);
	contact->AddFieldL(KContactSurname);
	contact->AddFieldL(KNullDesC);
	test(contact->FieldCount()==3);
	test(contact->Field(0)==KContactName);
	test(contact->Field(1)==KContactSurname);
	test(contact->Field(2)==KNullDesC);
	CleanupStack::PopAndDestroy(contact);
	}

/** 
 * Test case 3
 * Add an empty Field when OOM 
 * Action : Add an empty Field (i.e. length = 0) when OOM  
 * Result : Empty field added, iFieldTextBuf is unchanged
 */
LOCAL_C void OomAddEmptyFieldL()
	{
	TInt ret=KErrNoMemory;
	TInt failAt=0;	  
	while (ret!=KErrNone)
		{
		failAt++;
		__UHEAP_SETFAIL(RHeap::EDeterministic,failAt);
		__UHEAP_MARK;			
		TRAP(ret, AddEmptyFieldL());
		if (ret!=KErrNone)
			{
			__UHEAP_MARKEND;
			}
		__UHEAP_RESET;
		if (ret!=KErrNoMemory&&ret!=KErrNone)
			{
			test.Printf(_L("Non standard error: %d\n"),ret);
			test.Getch();
			}
		test(ret==KErrNoMemory||ret==KErrNone);
		}
	}

/**

@SYMTestCaseID     PIM-T-CVIEWCONTACT-0001

*/

LOCAL_C void DoTestsL()
    {
	test.Start(_L("@SYMTESTCaseID:PIM-T-CVIEWCONTACT-0001 Tests for CViewContact"));

	TestConstructionL();
	TestMiscMethodsL();
	AddFieldL();
	AddEmptyFieldL();
	OomAddEmptyFieldL();
	}

GLDEF_C TInt E32Main()
	{
    CntTest=new(ELeave) CCntTest;
	CntTest->ConstructL(test,KDatabaseFileName);
    TRAPD(err,DoTestsL());
	CntTest->EndTestLib(err);
	return KErrNone;
    }