|
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 // Test Context module |
|
15 // |
|
16 // |
|
17 |
|
18 #pragma message(__FILE__ "(1) : NOTE: Requires TContext.dat in the help directory") |
|
19 |
|
20 // System includes |
|
21 #include <e32test.h> |
|
22 #include <f32file.h> |
|
23 #include <coehelp.h> |
|
24 |
|
25 // User includes |
|
26 #include "hlpmodel.h" |
|
27 |
|
28 // Globals |
|
29 static RFs TheFs; |
|
30 static RTest TheTest(_L("TCONTEXT - Test context sensitive searching in help model")); |
|
31 static CTrapCleanup* TheTrapCleanup; |
|
32 static CActiveScheduler* TheScheduler; |
|
33 |
|
34 // Constants |
|
35 const TInt KTestCleanupStack=0x20; |
|
36 |
|
37 |
|
38 class CHelpTester : public CBase, public MHlpModelObserver |
|
39 { |
|
40 public: |
|
41 CHelpTester(); |
|
42 ~CHelpTester(); |
|
43 void ConstructL(); |
|
44 |
|
45 public: |
|
46 void Test1L(); |
|
47 |
|
48 public: // from MHlpModelObserver |
|
49 void HandleModelEventL(TInt aEvent); |
|
50 |
|
51 private: |
|
52 TInt iLastResponse; |
|
53 CHlpModel* iModel; |
|
54 }; |
|
55 |
|
56 |
|
57 CHelpTester::CHelpTester() |
|
58 { |
|
59 } |
|
60 |
|
61 CHelpTester::~CHelpTester() |
|
62 { |
|
63 delete iModel; |
|
64 } |
|
65 |
|
66 void CHelpTester::ConstructL() |
|
67 { |
|
68 iModel = CHlpModel::NewL(TheFs, this); |
|
69 } |
|
70 |
|
71 /** |
|
72 @SYMTestCaseID PIM-TCONTEXT-0001 |
|
73 */ |
|
74 void CHelpTester::Test1L() |
|
75 { |
|
76 TheTest.Next(_L("@SYMTestCaseID PIM-TCONTEXT-0001 Test 1: Test category searching")); |
|
77 |
|
78 iModel->OpenL(); |
|
79 |
|
80 // Create a context that we know exists |
|
81 TCoeContextName contextName(_L("A_Remove_dialog")); |
|
82 TUid contextUid = {268450396}; |
|
83 TCoeHelpContext context(contextUid, contextName); |
|
84 |
|
85 // Request a search on the context |
|
86 iModel->ContextSearchL(context); |
|
87 |
|
88 // Check that the response is "Found" |
|
89 TheTest(iLastResponse == ETopicAvailable); |
|
90 |
|
91 // Now get the topic text |
|
92 CHlpTopic* topic = CHlpTopic::NewLC(); |
|
93 TRAPD(error, iModel->LoadTopicL(topic)); |
|
94 TheTest(error == KErrNone); |
|
95 CleanupStack::PopAndDestroy(); // topic |
|
96 |
|
97 // Create a context that we know doesn't exists |
|
98 contextName = _L("SomeSymbianTopic"); |
|
99 contextUid.iUid = 123456789; |
|
100 TCoeHelpContext missingContext(contextUid, contextName); |
|
101 |
|
102 // Request a search on the context |
|
103 iModel->ContextSearchL(missingContext); |
|
104 |
|
105 // Check that the response is "Found" |
|
106 TheTest(iLastResponse == ETopicNotFound); |
|
107 |
|
108 iModel->CloseL(); |
|
109 } |
|
110 |
|
111 void CHelpTester::HandleModelEventL(TInt aEvent) |
|
112 { |
|
113 // Just store the last event reported by the model so that we |
|
114 // can test against it in the actual test. |
|
115 iLastResponse = aEvent; |
|
116 } |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 static void DoTestL() |
|
124 { |
|
125 CHelpTester* tester = new(ELeave) CHelpTester(); |
|
126 CleanupStack::PushL(tester); |
|
127 tester->ConstructL(); |
|
128 tester->Test1L(); |
|
129 CleanupStack::PopAndDestroy(); |
|
130 } |
|
131 |
|
132 static void setupFileServerAndSchedulerL() |
|
133 // |
|
134 // Initialise the cleanup stack. |
|
135 // |
|
136 { |
|
137 TheTest(TheFs.Connect() == KErrNone); |
|
138 TheScheduler = new (ELeave) CActiveScheduler; |
|
139 CActiveScheduler::Install(TheScheduler); |
|
140 } |
|
141 |
|
142 |
|
143 static void setupCleanup() |
|
144 // |
|
145 // Initialise the cleanup stack. |
|
146 // |
|
147 { |
|
148 TheTrapCleanup = CTrapCleanup::New(); |
|
149 TheTest(TheTrapCleanup!=NULL); |
|
150 TRAPD(r,\ |
|
151 {\ |
|
152 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
153 CleanupStack::PushL((TAny*)0);\ |
|
154 CleanupStack::Pop(KTestCleanupStack);\ |
|
155 }); |
|
156 TheTest(r==KErrNone); |
|
157 } |
|
158 |
|
159 GLDEF_C TInt E32Main() |
|
160 // |
|
161 // Test Help Model API |
|
162 // |
|
163 { |
|
164 __UHEAP_MARK; |
|
165 |
|
166 TheTest.Title(); |
|
167 setupCleanup(); |
|
168 |
|
169 TRAPD(r, |
|
170 setupFileServerAndSchedulerL(); |
|
171 DoTestL(); |
|
172 ); |
|
173 TheTest(r==KErrNone); |
|
174 |
|
175 delete TheScheduler; |
|
176 delete TheTrapCleanup; |
|
177 TheFs.Close(); |
|
178 TheTest.Close(); |
|
179 |
|
180 __UHEAP_MARKEND; |
|
181 return KErrNone; |
|
182 } |