|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <cntdef.h> |
|
18 #include <cntdb.h> |
|
19 #include <cntitem.h> |
|
20 #include <cntfield.h> |
|
21 #include <cntfldst.h> |
|
22 #include <cntviewbase.h> |
|
23 |
|
24 _LIT(KTestName, "CContactRemoteView::ContactAtL Tests"); |
|
25 |
|
26 _LIT(KTestDbName, "c:contactat.cdb"); |
|
27 |
|
28 LOCAL_D RTest test(KTestName); |
|
29 |
|
30 |
|
31 class CTestResources : public CBase , public MContactViewObserver |
|
32 { |
|
33 public: |
|
34 static CTestResources* NewLC(); |
|
35 void ConstructL(); |
|
36 void CreateTestContactsL(); |
|
37 ~CTestResources(); |
|
38 void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent); |
|
39 CContactDatabase* iDb; |
|
40 TContactItemId iAddedContact; |
|
41 RContactViewSortOrder iViewSortOrder; |
|
42 CContactRemoteView* iRemoteView; |
|
43 }; |
|
44 |
|
45 CTestResources* CTestResources::NewLC() |
|
46 { |
|
47 CTestResources* self = new(ELeave) CTestResources; |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 void CTestResources::ConstructL() |
|
54 { |
|
55 iDb = CContactDatabase::ReplaceL(KTestDbName); |
|
56 |
|
57 iViewSortOrder.AppendL(KUidContactFieldFamilyName); |
|
58 iViewSortOrder.AppendL(KUidContactFieldGivenName); |
|
59 iViewSortOrder.AppendL(KUidContactFieldCompanyName); |
|
60 |
|
61 iRemoteView = CContactRemoteView::NewL(*this, *iDb, iViewSortOrder, EContactsOnly); |
|
62 CreateTestContactsL(); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Create a test contact with a Euro character name field. |
|
67 * This bug can be reproduced with most of the cyrillic characters also. |
|
68 */ |
|
69 void CTestResources::CreateTestContactsL() |
|
70 { |
|
71 const TInt KContacts = 1; |
|
72 TInt i; |
|
73 for (i=1; i <= KContacts; ++i) |
|
74 { |
|
75 CContactCard* card = CContactCard::NewLC(); |
|
76 CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); |
|
77 _LIT(KName, "\x20a0"); //Euro character |
|
78 field->TextStorage()->SetTextL(KName); |
|
79 card->AddFieldL(*field); |
|
80 CleanupStack::Pop(field); |
|
81 iAddedContact = iDb->AddNewContactL(*card); |
|
82 CleanupStack::PopAndDestroy(card); |
|
83 } |
|
84 } |
|
85 |
|
86 CTestResources::~CTestResources() |
|
87 { |
|
88 if (iRemoteView) |
|
89 { |
|
90 iRemoteView->Close(*this); |
|
91 } |
|
92 iViewSortOrder.Close(); |
|
93 delete iDb; |
|
94 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KTestDbName)); |
|
95 } |
|
96 |
|
97 void CTestResources::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
98 { |
|
99 if (&aView == iRemoteView && aEvent.iEventType == TContactViewEvent::EItemAdded) |
|
100 { |
|
101 TInt index(0); |
|
102 TRAPD(error, index = iRemoteView->FindL(iAddedContact) ); |
|
103 test(error == KErrNone); |
|
104 TRAP(error, iRemoteView->ContactAtL(index)); |
|
105 test(error == KErrNone); |
|
106 |
|
107 __ASSERT_ALWAYS(error==KErrNone,User::Invariant()); |
|
108 CActiveScheduler::Stop(); |
|
109 } |
|
110 } |
|
111 |
|
112 /** |
|
113 |
|
114 @SYMTestCaseID PIM-T-CONTACTAT-0001 |
|
115 |
|
116 */ |
|
117 |
|
118 void DoTestsL() |
|
119 { |
|
120 test.Start(_L("@SYMTESTCaseID:PIM-T-CONTACTAT-0001 Test CContactRemoteView::ContactAtL")); |
|
121 |
|
122 test.Next(_L("Add a contact with euro sign to db")); |
|
123 |
|
124 CTestResources* res = CTestResources::NewLC(); |
|
125 CActiveScheduler::Start(); |
|
126 CleanupStack::PopAndDestroy(res); |
|
127 test.End(); |
|
128 test.Close(); |
|
129 } |
|
130 |
|
131 GLDEF_C TInt E32Main() |
|
132 { |
|
133 __UHEAP_MARK; |
|
134 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
135 if (!cleanupStack) |
|
136 { |
|
137 return KErrNoMemory; |
|
138 } |
|
139 |
|
140 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
141 if (!activeScheduler) |
|
142 { |
|
143 return KErrNoMemory; |
|
144 } |
|
145 CActiveScheduler::Install(activeScheduler); |
|
146 |
|
147 // Run the tests |
|
148 TRAPD(err, DoTestsL()); |
|
149 |
|
150 // Cleanup |
|
151 delete activeScheduler; |
|
152 delete cleanupStack; |
|
153 __UHEAP_MARKEND; |
|
154 return err; |
|
155 } |
|
156 |