60
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: Source code file for device info extension management
|
|
15 |
* interface unit tests.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// CLASS HEADER
|
|
20 |
#include "devinfextmgmtif_test.h"
|
|
21 |
|
|
22 |
// EXTERNAL INCLUDES
|
|
23 |
#include <EUnitMacros.h>
|
|
24 |
#include <EUnitDecorators.h>
|
|
25 |
#include <nsmldevinfextdatacontainerplugin.h>
|
|
26 |
|
|
27 |
// INTERNAL INCLUDES
|
|
28 |
#include "exampledevinfextdatacontainerplugin.h"
|
|
29 |
|
|
30 |
// LOCAL DEFINITIONS
|
|
31 |
namespace
|
|
32 |
{
|
|
33 |
_LIT8( KTestXNam1, "TestExtensionName" );
|
|
34 |
_LIT8( KTestXNam2, "AnotherExtensionName" );
|
|
35 |
_LIT8( KTestXNam3, "ExtensionNameWithNoValues" );
|
|
36 |
|
|
37 |
_LIT8( KTestXVal1, "FirstValue" );
|
|
38 |
_LIT8( KTestXVal2, "SecondValue" );
|
|
39 |
_LIT8( KTestXVal3, "ThirdValue" );
|
|
40 |
_LIT8( KTestXVal4, "FourthValue" );
|
|
41 |
}
|
|
42 |
|
|
43 |
// - Construction -----------------------------------------------------------
|
|
44 |
CDevInfExtMgmtIf_Test* CDevInfExtMgmtIf_Test::NewL()
|
|
45 |
{
|
|
46 |
CDevInfExtMgmtIf_Test* self = CDevInfExtMgmtIf_Test::NewLC();
|
|
47 |
CleanupStack::Pop( self );
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
CDevInfExtMgmtIf_Test* CDevInfExtMgmtIf_Test::NewLC()
|
|
52 |
{
|
|
53 |
CDevInfExtMgmtIf_Test* self = new ( ELeave ) CDevInfExtMgmtIf_Test();
|
|
54 |
CleanupStack::PushL( self );
|
|
55 |
self->ConstructL();
|
|
56 |
return self;
|
|
57 |
}
|
|
58 |
|
|
59 |
CDevInfExtMgmtIf_Test::~CDevInfExtMgmtIf_Test()
|
|
60 |
{
|
|
61 |
if( iEcomPlugin )
|
|
62 |
{
|
|
63 |
delete iEcomPlugin;
|
|
64 |
REComSession::FinalClose();
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
CDevInfExtMgmtIf_Test::CDevInfExtMgmtIf_Test()
|
|
69 |
{
|
|
70 |
}
|
|
71 |
|
|
72 |
void CDevInfExtMgmtIf_Test::ConstructL()
|
|
73 |
{
|
|
74 |
CEUnitTestSuiteClass::ConstructL();
|
|
75 |
}
|
|
76 |
|
|
77 |
// - Setup & Teardown ---------------------------------------------------------
|
|
78 |
|
|
79 |
void CDevInfExtMgmtIf_Test::SetupEmptyL()
|
|
80 |
{
|
|
81 |
// Construct the plugin normally; in its default construction, no
|
|
82 |
// extensions are available.
|
|
83 |
TRAPD( err, iEcomPlugin = CNSmlDevInfExtDataContainerPlugin::NewL() );
|
|
84 |
if( err != KErrNone )
|
|
85 |
{
|
|
86 |
EUNIT_PRINT( _L( "Leave while instantiating plugin: %d" ), err );
|
|
87 |
}
|
|
88 |
EUNIT_ASSERT_DESC( iEcomPlugin, "Plugin instantiation failed." );
|
|
89 |
}
|
|
90 |
|
|
91 |
void CDevInfExtMgmtIf_Test::SetupOneXNamL()
|
|
92 |
{
|
|
93 |
// Default construction
|
|
94 |
SetupEmptyL();
|
|
95 |
|
|
96 |
// Add XNam + XVals
|
|
97 |
CExampleDevInfExtDataContainerPlugin* plugin =
|
|
98 |
reinterpret_cast < CExampleDevInfExtDataContainerPlugin* >( iEcomPlugin );
|
|
99 |
|
|
100 |
plugin->InsertExtension( KTestXNam1, KTestXVal1 );
|
|
101 |
plugin->InsertExtension( KTestXNam1, KTestXVal2 );
|
|
102 |
}
|
|
103 |
|
|
104 |
void CDevInfExtMgmtIf_Test::SetupMultipleXNamL()
|
|
105 |
{
|
|
106 |
// Default construction
|
|
107 |
SetupEmptyL();
|
|
108 |
|
|
109 |
// Add XNam + XVals
|
|
110 |
CExampleDevInfExtDataContainerPlugin* plugin =
|
|
111 |
reinterpret_cast < CExampleDevInfExtDataContainerPlugin* >( iEcomPlugin );
|
|
112 |
|
|
113 |
plugin->InsertExtension( KTestXNam1, KTestXVal1 );
|
|
114 |
plugin->InsertExtension( KTestXNam1, KTestXVal2 );
|
|
115 |
plugin->InsertExtension( KTestXNam2, KTestXVal3 );
|
|
116 |
plugin->InsertExtension( KTestXNam2, KTestXVal4 );
|
|
117 |
plugin->InsertExtension( KTestXNam3, KNullDesC8 );
|
|
118 |
}
|
|
119 |
|
|
120 |
void CDevInfExtMgmtIf_Test::Teardown()
|
|
121 |
{
|
|
122 |
if( iEcomPlugin )
|
|
123 |
{
|
|
124 |
delete iEcomPlugin;
|
|
125 |
}
|
|
126 |
REComSession::FinalClose();
|
|
127 |
}
|
|
128 |
|
|
129 |
// - Actual test methods ------------------------------------------------------
|
|
130 |
void CDevInfExtMgmtIf_Test::NewLL()
|
|
131 |
{
|
|
132 |
// Instantiate the example plugin
|
|
133 |
CNSmlDevInfExtDataContainerPlugin* ecomPlugin = NULL;
|
|
134 |
|
|
135 |
// Instantiate the plugin
|
|
136 |
TRAPD( err, ecomPlugin = CNSmlDevInfExtDataContainerPlugin::NewL() );
|
|
137 |
if( err != KErrNone )
|
|
138 |
{
|
|
139 |
EUNIT_PRINT( _L( "Leave while instantiating plugin: %d" ), err );
|
|
140 |
}
|
|
141 |
|
|
142 |
EUNIT_ASSERT( ecomPlugin );
|
|
143 |
delete ecomPlugin;
|
|
144 |
ecomPlugin = NULL;
|
|
145 |
|
|
146 |
// Tell the framework that plugin is no longer used - resources are released
|
|
147 |
REComSession::FinalClose();
|
|
148 |
}
|
|
149 |
|
|
150 |
// Run tests for the test plugin, when there are no extension configured
|
|
151 |
// in the plugin.
|
|
152 |
void CDevInfExtMgmtIf_Test::TestEmptyPluginL()
|
|
153 |
{
|
|
154 |
// Debug
|
|
155 |
PrintExtensions();
|
|
156 |
|
|
157 |
TInt extCount = 0;
|
|
158 |
TRAPD( err, extCount = iEcomPlugin->GetExtensionCountL() );
|
|
159 |
EUNIT_ASSERT_DESC( err == KErrNone, "GetExtensionCountL() leaves" );
|
|
160 |
EUNIT_ASSERT( extCount == 0 );
|
|
161 |
|
|
162 |
// Ensure that other methods leave, as there are not extensions
|
|
163 |
TRAP( err, iEcomPlugin->GetExtNameL( 0 ) );
|
|
164 |
EUNIT_ASSERT( err == KErrArgument );
|
|
165 |
TRAP( err, iEcomPlugin->GetExtNameL( 1 ) );
|
|
166 |
EUNIT_ASSERT( err == KErrArgument );
|
|
167 |
|
|
168 |
TRAP( err, iEcomPlugin->GetExtValueCountL( 0 ) );
|
|
169 |
EUNIT_ASSERT( err == KErrArgument );
|
|
170 |
TRAP( err, iEcomPlugin->GetExtValueCountL( 1 ) );
|
|
171 |
EUNIT_ASSERT( err == KErrArgument );
|
|
172 |
|
|
173 |
TRAP( err, iEcomPlugin->GetExtValueL( 0, 0 ) );
|
|
174 |
EUNIT_ASSERT( err == KErrArgument );
|
|
175 |
}
|
|
176 |
|
|
177 |
// Run tests for the test plugin, when there is one extension configured
|
|
178 |
// in the plugin.
|
|
179 |
void CDevInfExtMgmtIf_Test::TestOneXNamPluginL()
|
|
180 |
{
|
|
181 |
// Debug
|
|
182 |
PrintExtensions();
|
|
183 |
|
|
184 |
TInt extCount = 0;
|
|
185 |
TRAPD( err, extCount = iEcomPlugin->GetExtensionCountL() );
|
|
186 |
EUNIT_ASSERT_DESC( err == KErrNone, "GetExtensionCountL() leaves" );
|
|
187 |
EUNIT_ASSERT( extCount == 1 );
|
|
188 |
|
|
189 |
// Check legal values
|
|
190 |
TBuf8< 50 > tmpBuf;
|
|
191 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtNameL( 0 ) );
|
|
192 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXNam1 ) == 0 );
|
|
193 |
|
|
194 |
TInt xValCount = 0;
|
|
195 |
EUNIT_ASSERT_NO_LEAVE( xValCount = iEcomPlugin->GetExtValueCountL( 0 ) );
|
|
196 |
EUNIT_ASSERT( xValCount == 2 );
|
|
197 |
|
|
198 |
tmpBuf.Zero();
|
|
199 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 0, 0 ) );
|
|
200 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal1 ) == 0 );
|
|
201 |
tmpBuf.Zero();
|
|
202 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 0, 1 ) );
|
|
203 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal2 ) == 0 );
|
|
204 |
|
|
205 |
// Ensure that methods leave with illegal indices
|
|
206 |
TRAP( err, iEcomPlugin->GetExtNameL( 1 ) );
|
|
207 |
EUNIT_ASSERT( err == KErrArgument );
|
|
208 |
|
|
209 |
TRAP( err, iEcomPlugin->GetExtValueCountL( 1 ) );
|
|
210 |
EUNIT_ASSERT( err == KErrArgument );
|
|
211 |
|
|
212 |
TRAP( err, iEcomPlugin->GetExtValueL( 1, 0 ) );
|
|
213 |
EUNIT_ASSERT( err == KErrArgument );
|
|
214 |
}
|
|
215 |
|
|
216 |
// Run tests for the test plugin, when there are multiple extensions configured
|
|
217 |
// in the plugin.
|
|
218 |
void CDevInfExtMgmtIf_Test::TestMultipleXNamPluginL()
|
|
219 |
{
|
|
220 |
// Debug
|
|
221 |
PrintExtensions();
|
|
222 |
|
|
223 |
TInt extCount = 0;
|
|
224 |
TRAPD( err, extCount = iEcomPlugin->GetExtensionCountL() );
|
|
225 |
EUNIT_ASSERT_DESC( err == KErrNone, "GetExtensionCountL() leaves" );
|
|
226 |
EUNIT_ASSERT( extCount == 3 );
|
|
227 |
|
|
228 |
// Check legal values
|
|
229 |
// 1st extension (index 0)
|
|
230 |
TBuf8< 50 > tmpBuf;
|
|
231 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtNameL( 0 ) );
|
|
232 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXNam1 ) == 0 );
|
|
233 |
|
|
234 |
TInt xValCount = 0;
|
|
235 |
EUNIT_ASSERT_NO_LEAVE( xValCount = iEcomPlugin->GetExtValueCountL( 0 ) );
|
|
236 |
EUNIT_ASSERT( xValCount == 2 );
|
|
237 |
|
|
238 |
tmpBuf.Zero();
|
|
239 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 0, 0 ) );
|
|
240 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal1 ) == 0 );
|
|
241 |
tmpBuf.Zero();
|
|
242 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 0, 1 ) );
|
|
243 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal2 ) == 0 );
|
|
244 |
|
|
245 |
// 2nd extension (index 1)
|
|
246 |
tmpBuf.Zero();
|
|
247 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtNameL( 1 ) );
|
|
248 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXNam2 ) == 0 );
|
|
249 |
|
|
250 |
xValCount = 0;
|
|
251 |
EUNIT_ASSERT_NO_LEAVE( xValCount = iEcomPlugin->GetExtValueCountL( 1 ) );
|
|
252 |
EUNIT_ASSERT( xValCount == 2 );
|
|
253 |
|
|
254 |
tmpBuf.Zero();
|
|
255 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 1, 0 ) );
|
|
256 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal3 ) == 0 );
|
|
257 |
tmpBuf.Zero();
|
|
258 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtValueL( 1, 1 ) );
|
|
259 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXVal4 ) == 0 );
|
|
260 |
|
|
261 |
// 3nd extension (index 2)
|
|
262 |
EUNIT_ASSERT_NO_LEAVE( tmpBuf = iEcomPlugin->GetExtNameL( 2 ) );
|
|
263 |
EUNIT_ASSERT( tmpBuf.Compare( KTestXNam3 ) == 0 );
|
|
264 |
|
|
265 |
xValCount = 0;
|
|
266 |
EUNIT_ASSERT_NO_LEAVE( xValCount = iEcomPlugin->GetExtValueCountL( 2 ) );
|
|
267 |
EUNIT_ASSERT( xValCount == 0 );
|
|
268 |
|
|
269 |
// Ensure that methods leave with illegal indices
|
|
270 |
TRAP( err, iEcomPlugin->GetExtNameL( -1 ) );
|
|
271 |
EUNIT_ASSERT( err == KErrArgument );
|
|
272 |
|
|
273 |
TRAP( err, iEcomPlugin->GetExtValueCountL( 3 ) );
|
|
274 |
EUNIT_ASSERT( err == KErrArgument );
|
|
275 |
|
|
276 |
TRAP( err, iEcomPlugin->GetExtValueL( 5, 2 ) );
|
|
277 |
EUNIT_ASSERT( err == KErrArgument );
|
|
278 |
}
|
|
279 |
|
|
280 |
// - Utilities ----------------------------------------------------------------
|
|
281 |
void CDevInfExtMgmtIf_Test::PrintExtensions()
|
|
282 |
{
|
|
283 |
EUNIT_PRINT( _L( "Extension count %d" ), iEcomPlugin->GetExtensionCountL() );
|
|
284 |
|
|
285 |
for ( TInt i = 0; i < iEcomPlugin->GetExtensionCountL(); i++ )
|
|
286 |
{
|
|
287 |
EUNIT_PRINT( _L("EXTENSION NUMBER %d"), i );
|
|
288 |
|
|
289 |
EUNIT_PRINT( _L( "Name" ) );
|
|
290 |
EUNIT_PRINT( iEcomPlugin->GetExtNameL( i ) );
|
|
291 |
|
|
292 |
EUNIT_PRINT( _L( "Values" ) );
|
|
293 |
for ( TInt j = 0; j < iEcomPlugin->GetExtValueCountL( i ); j++ )
|
|
294 |
{
|
|
295 |
EUNIT_PRINT( iEcomPlugin->GetExtValueL( i, j ) );
|
|
296 |
}
|
|
297 |
|
|
298 |
EUNIT_PRINT( _L("END OF EXTENSION %d"), i );
|
|
299 |
}
|
|
300 |
}
|
|
301 |
|
|
302 |
// - EUnit test table -------------------------------------------------------
|
|
303 |
|
|
304 |
EUNIT_BEGIN_TEST_TABLE(
|
|
305 |
CDevInfExtMgmtIf_Test,
|
|
306 |
"Unit tests for Device info ext management interface.",
|
|
307 |
"UNIT" )
|
|
308 |
|
|
309 |
EUNIT_TEST(
|
|
310 |
"Verify Ecom plugin instantiation",
|
|
311 |
"CNSmlDevInfExtDataContainerPlugin",
|
|
312 |
"NewL",
|
|
313 |
"FUNCTIONALITY",
|
|
314 |
Empty, NewLL, Empty)
|
|
315 |
|
|
316 |
EUNIT_TEST(
|
|
317 |
"Test the behaviour with no extensions",
|
|
318 |
"CNSmlDevInfExtDataContainerPlugin",
|
|
319 |
"NewL",
|
|
320 |
"FUNCTIONALITY",
|
|
321 |
SetupEmptyL, TestEmptyPluginL, Teardown)
|
|
322 |
|
|
323 |
EUNIT_TEST(
|
|
324 |
"Test the behaviour with one extension",
|
|
325 |
"CNSmlDevInfExtDataContainerPlugin",
|
|
326 |
"NewL",
|
|
327 |
"FUNCTIONALITY",
|
|
328 |
SetupOneXNamL, TestOneXNamPluginL, Teardown)
|
|
329 |
|
|
330 |
EUNIT_TEST(
|
|
331 |
"Test the behaviour with multiple extensions",
|
|
332 |
"CNSmlDevInfExtDataContainerPlugin",
|
|
333 |
"NewL",
|
|
334 |
"FUNCTIONALITY",
|
|
335 |
SetupMultipleXNamL, TestMultipleXNamPluginL, Teardown)
|
|
336 |
|
|
337 |
EUNIT_END_TEST_TABLE
|
|
338 |
|
|
339 |
// End of file
|