|
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 // ViewObserversBug Test module |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <cntdef.h> |
|
21 #include <cntdb.h> |
|
22 #include <cntitem.h> |
|
23 #include <cntfield.h> |
|
24 #include <cntfldst.h> |
|
25 #include <cntviewbase.h> |
|
26 |
|
27 #include "CContactViewEventQueue.h" |
|
28 |
|
29 _LIT(KTestName, "T_ViewObserversBug"); |
|
30 |
|
31 _LIT(KTestDbName, "c:T_ViewObserversBug.cdb"); |
|
32 |
|
33 LOCAL_D RTest test(KTestName); |
|
34 |
|
35 |
|
36 class CTestResources : public CBase |
|
37 { |
|
38 public: |
|
39 static CTestResources* NewLC(); |
|
40 void ConstructL(); |
|
41 ~CTestResources(); |
|
42 |
|
43 CContactDatabase* iDb; |
|
44 CContactViewEventQueue* iViewEventQueue; |
|
45 RContactViewSortOrder iViewSortOrder; |
|
46 CContactLocalView* iLocalView; |
|
47 }; |
|
48 |
|
49 CTestResources* CTestResources::NewLC() |
|
50 { |
|
51 CTestResources* self = new(ELeave) CTestResources; |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 void CTestResources::ConstructL() |
|
58 { |
|
59 iDb = CContactDatabase::ReplaceL(KTestDbName); |
|
60 |
|
61 iViewEventQueue = CContactViewEventQueue::NewL(); |
|
62 |
|
63 iViewSortOrder.AppendL(KUidContactFieldFamilyName); |
|
64 iViewSortOrder.AppendL(KUidContactFieldGivenName); |
|
65 iViewSortOrder.AppendL(KUidContactFieldCompanyName); |
|
66 |
|
67 const TContactViewPreferences prefs = |
|
68 static_cast<TContactViewPreferences>(EContactsOnly | EUnSortedAtEnd); |
|
69 iLocalView = CContactLocalView::NewL |
|
70 (*iViewEventQueue, *iDb, iViewSortOrder, prefs); |
|
71 |
|
72 // Wait for view to get ready |
|
73 TContactViewEvent event; |
|
74 __ASSERT_ALWAYS(iViewEventQueue->ListenForEvent(10,event),User::Invariant()); |
|
75 __ASSERT_ALWAYS(event.iEventType == TContactViewEvent::EReady,User::Invariant()); |
|
76 } |
|
77 |
|
78 CTestResources::~CTestResources() |
|
79 { |
|
80 if (iLocalView) iLocalView->Close(*iViewEventQueue); |
|
81 iViewSortOrder.Close(); |
|
82 delete iViewEventQueue; |
|
83 delete iDb; |
|
84 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KTestDbName)); |
|
85 } |
|
86 |
|
87 LOCAL_C void TestRegistersObserversL() |
|
88 { |
|
89 // Create test resources |
|
90 CTestResources* res = CTestResources::NewLC(); |
|
91 |
|
92 // Create observer1 |
|
93 CContactViewEventQueue* observer1 = CContactViewEventQueue::NewL(); |
|
94 CleanupStack::PushL(observer1); |
|
95 |
|
96 // Connect observer1 to iLocalView |
|
97 res->iLocalView->OpenL(*observer1); |
|
98 // Wait for EReady event to observer1 |
|
99 TContactViewEvent event; |
|
100 test(observer1->ListenForEvent(10,event)); |
|
101 test(event.iEventType==TContactViewEvent::EReady); |
|
102 |
|
103 // Create observer2 |
|
104 CContactViewEventQueue* observer2 = CContactViewEventQueue::NewL(); |
|
105 CleanupStack::PushL(observer2); |
|
106 |
|
107 // Connect observer2 to iLocalView |
|
108 res->iLocalView->OpenL(*observer2); |
|
109 |
|
110 // Disconnect observer1 from iLocalView |
|
111 res->iLocalView->Close(*observer1); |
|
112 |
|
113 // Wait for EReady event to observer2 |
|
114 test(observer2->ListenForEvent(10,event)); |
|
115 test(event.iEventType==TContactViewEvent::EReady); |
|
116 |
|
117 // Disconnect observer2 from iLocalView |
|
118 res->iLocalView->Close(*observer2); |
|
119 |
|
120 // Cleanup |
|
121 CleanupStack::PopAndDestroy(3); // observer2, observer1, res |
|
122 } |
|
123 |
|
124 /** |
|
125 |
|
126 @SYMTestCaseID PIM-T-VIEWOBSERVERSBUG-0001 |
|
127 |
|
128 */ |
|
129 |
|
130 LOCAL_C void DoTestsL() |
|
131 { |
|
132 test.Start(_L("@SYMTESTCaseID:PIM-T-VIEWOBSERVERSBUG-0001 T_ViewObserversBug")); |
|
133 |
|
134 TestRegistersObserversL(); |
|
135 test.End(); |
|
136 test.Close(); |
|
137 } |
|
138 |
|
139 GLDEF_C TInt E32Main() |
|
140 { |
|
141 // Init |
|
142 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
143 if (!cleanupStack) |
|
144 { |
|
145 return KErrNoMemory; |
|
146 } |
|
147 |
|
148 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
149 if (!activeScheduler) |
|
150 { |
|
151 return KErrNoMemory; |
|
152 } |
|
153 CActiveScheduler::Install(activeScheduler); |
|
154 |
|
155 // Run the tests |
|
156 __UHEAP_MARK; |
|
157 TRAPD(err, DoTestsL()); |
|
158 __UHEAP_MARKEND; |
|
159 |
|
160 // Cleanup |
|
161 delete activeScheduler; |
|
162 delete cleanupStack; |
|
163 |
|
164 return err; |
|
165 } |