|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Provides testing of CPosLandmarkEncoder class methods |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <EPos_CPosLandmark.h> |
|
22 #include <EPos_CPosLandmarkDatabase.h> |
|
23 #include <EPos_CPosLmCategoryManager.h> |
|
24 #include <EPos_CPosLandmarkCategory.h> |
|
25 #include <EPos_CPosLandmarkEncoder.h> |
|
26 #include <LbsPosition.h> |
|
27 #include "testcposlandmarkencoder.h" |
|
28 #include <StifParser.h> |
|
29 #include <Stiftestinterface.h> |
|
30 |
|
31 // Literals |
|
32 _LIT8( KPosMimeTypeLandmarkCollectionXml, "application/vnd.nokia.landmarkcollection+xml" ); |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CTestPosLandmarkEncoder::CTestPosLandmarkEncoder |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CTestPosLandmarkEncoder::CTestPosLandmarkEncoder( CStifLogger* aLog ) |
|
43 { |
|
44 iLog = aLog; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CTestPosLandmarkEncoder::NewL |
|
49 // |
|
50 // |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CTestPosLandmarkEncoder* CTestPosLandmarkEncoder::NewL(CStifLogger* aLog) |
|
54 { |
|
55 CTestPosLandmarkEncoder* self = new (ELeave) CTestPosLandmarkEncoder( aLog ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CTestPosLandmarkEncoder::ConstructL |
|
64 // |
|
65 // |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CTestPosLandmarkEncoder::ConstructL() |
|
69 { |
|
70 |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CTestPosLandmarkEncoder::ConstructL |
|
75 // |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CTestPosLandmarkEncoder::~CTestPosLandmarkEncoder() |
|
80 { |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CTestPosLandmarkEncoder::CreateEncoder |
|
86 // |
|
87 // |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CTestPosLandmarkEncoder::CreateEncoderL( CStifItemParser& /*aItem*/ ) |
|
91 { |
|
92 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
93 iLog->Log(_L("CreateEncoder successful")); |
|
94 delete encoder; |
|
95 ReleaseLandmarkResources(); |
|
96 return KErrNone; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CTestPosLandmarkEncoder::SetOutputFile |
|
101 // |
|
102 // |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CTestPosLandmarkEncoder::SetOutputFileL( CStifItemParser& aItem ) |
|
106 { |
|
107 TPtrC exportFilePath; |
|
108 TInt err = aItem.GetNextString( exportFilePath ); |
|
109 |
|
110 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
111 CleanupStack::PushL( encoder ); |
|
112 // Delete output file if already exists |
|
113 RFs rfs; |
|
114 rfs.Connect(); |
|
115 rfs.Delete( exportFilePath ); |
|
116 rfs.Close(); |
|
117 // Set output file |
|
118 encoder->SetOutputFileL( exportFilePath ); |
|
119 iLog->Log(_L("SetOutputFile successful")); |
|
120 CleanupStack::PopAndDestroy( encoder ); |
|
121 ReleaseLandmarkResources(); |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CTestPosLandmarkEncoder::SetOutputBuffer |
|
127 // |
|
128 // |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TInt CTestPosLandmarkEncoder::SetOutputBufferL( CStifItemParser& /*aItem*/ ) |
|
132 { |
|
133 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
134 CleanupStack::PushL( encoder ); |
|
135 // Set use output buffer |
|
136 CBufBase* buffer = encoder->SetUseOutputBufferL(); |
|
137 iLog->Log(_L("SetOutputBuffer successful")); |
|
138 delete buffer; |
|
139 CleanupStack::PopAndDestroy( encoder ); |
|
140 ReleaseLandmarkResources(); |
|
141 return KErrNone; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CTestPosLandmarkEncoder::AddCollectionData |
|
146 // |
|
147 // |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CTestPosLandmarkEncoder::AddCollectionDataL( CStifItemParser& aItem ) |
|
151 { |
|
152 TPtrC collNamePtr; |
|
153 TPtrC collDescPtr; |
|
154 TInt err = aItem.GetNextString( collNamePtr ); |
|
155 err = aItem.GetNextString( collDescPtr ); |
|
156 |
|
157 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
158 CleanupStack::PushL( encoder ); |
|
159 // Set use output buffer |
|
160 CBufBase* buffer = encoder->SetUseOutputBufferL(); |
|
161 CleanupStack::PushL( buffer ); |
|
162 // Add Collection Data |
|
163 TPosLmCollectionDataId id = EPosLmCollDataCollectionName; |
|
164 encoder->AddCollectionDataL( id, collNamePtr ); |
|
165 // |
|
166 id = EPosLmCollDataCollectionDescription; |
|
167 encoder->AddCollectionDataL( id, collDescPtr ); |
|
168 // Finalize Encoding |
|
169 //ExecuteAndDeleteLD(encoder->FinalizeEncodingL()); |
|
170 // |
|
171 iLog->Log(_L("AddCollectionData asdf successful")); |
|
172 CleanupStack::PopAndDestroy( 2, encoder ); |
|
173 ReleaseLandmarkResources(); |
|
174 return KErrNone; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CTestPosLandmarkEncoder::AddLandmarkToEncode |
|
179 // |
|
180 // |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 TInt CTestPosLandmarkEncoder::AddLandmarkToEncodeL( CStifItemParser& /*aItem*/ ) |
|
184 { |
|
185 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
186 CleanupStack::PushL( encoder ); |
|
187 // Set use output buffer |
|
188 CBufBase* buffer = encoder->SetUseOutputBufferL(); |
|
189 CleanupStack::PushL( buffer ); |
|
190 // Create a landmark |
|
191 CPosLandmark* landmark = CPosLandmark::NewL(); |
|
192 CleanupStack::PushL( landmark ); |
|
193 // Set name |
|
194 _LIT( KLmkName, "A Test Landmark" ); |
|
195 landmark->SetLandmarkNameL( KLmkName ); |
|
196 // Add Landmark for encoding |
|
197 encoder->AddLandmarkL( *landmark ); |
|
198 // Finalize Encoding |
|
199 ExecuteAndDeleteLD( encoder->FinalizeEncodingL() ); |
|
200 // |
|
201 iLog->Log(_L("AddLandmarkToEncode successful")); |
|
202 CleanupStack::PopAndDestroy( 3, encoder ); |
|
203 ReleaseLandmarkResources(); |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CTestPosLandmarkEncoder::AddCategoryForLatestLandmark |
|
209 // |
|
210 // |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 TInt CTestPosLandmarkEncoder::AddCategoryForLatestLandmarkL( CStifItemParser& /*aItem*/ ) |
|
214 { |
|
215 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
216 CleanupStack::PushL( encoder ); |
|
217 // Set use output buffer |
|
218 CBufBase* buffer = encoder->SetUseOutputBufferL(); |
|
219 CleanupStack::PushL( buffer ); |
|
220 // Create a landmark |
|
221 CPosLandmark* landmark = CPosLandmark::NewL(); |
|
222 CleanupStack::PushL( landmark ); |
|
223 // Set name |
|
224 _LIT( KLmkName, "A Test Landmark" ); |
|
225 landmark->SetLandmarkNameL( KLmkName ); |
|
226 // Add Landmark for encoding |
|
227 encoder->AddLandmarkL( *landmark ); |
|
228 // Create a category |
|
229 CPosLandmarkCategory* category = CPosLandmarkCategory::NewL(); |
|
230 CleanupStack::PushL( category ); |
|
231 // Set name |
|
232 _LIT( KCategoryName, "A Category Name" ); |
|
233 category->SetCategoryNameL( KCategoryName ); |
|
234 // Add category for latest landmark |
|
235 encoder->AddCategoryForLatestLandmarkL( *category ); |
|
236 // Finalize Encoding |
|
237 ExecuteAndDeleteLD( encoder->FinalizeEncodingL() ); |
|
238 // |
|
239 iLog->Log(_L("AddCategoryForLatestLandmark successful")); |
|
240 CleanupStack::PopAndDestroy( 4, encoder ); |
|
241 ReleaseLandmarkResources(); |
|
242 return KErrNone; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CTestPosLandmarkEncoder::FinalizeEncoding |
|
247 // |
|
248 // |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CTestPosLandmarkEncoder::FinalizeEncodingL( CStifItemParser& /*aItem*/ ) |
|
252 { |
|
253 CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL( KPosMimeTypeLandmarkCollectionXml ); |
|
254 CleanupStack::PushL( encoder ); |
|
255 // Set use output buffer |
|
256 CBufBase* buffer = encoder->SetUseOutputBufferL(); |
|
257 CleanupStack::PushL( buffer ); |
|
258 // Create a landmark |
|
259 CPosLandmark* landmark = CPosLandmark::NewL(); |
|
260 CleanupStack::PushL( landmark ); |
|
261 // Set name |
|
262 _LIT( KLmkName, "A Test Landmark" ); |
|
263 landmark->SetLandmarkNameL( KLmkName ); |
|
264 // Add Landmark for encoding |
|
265 encoder->AddLandmarkL( *landmark ); |
|
266 // Finalize Encoding |
|
267 CPosLmOperation* operation = encoder->FinalizeEncodingL(); |
|
268 CleanupStack::PushL( operation ); |
|
269 // Execute operation |
|
270 operation->ExecuteL(); |
|
271 // |
|
272 iLog->Log(_L("FinalizeEncoding successful")); |
|
273 CleanupStack::PopAndDestroy( 4, encoder ); |
|
274 ReleaseLandmarkResources(); |
|
275 return KErrNone; |
|
276 } |