|
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: EUnit test for homescreen settings API, hsps configuration tests |
|
15 * |
|
16 */ |
|
17 |
|
18 // External includes |
|
19 #include <digia/eunit/eunitmacros.h> |
|
20 |
|
21 // Internal includes |
|
22 #include "plugininfo.h" |
|
23 #include "pluginmap.h" |
|
24 #include "itemmap.h" |
|
25 #include "objectmap.h" |
|
26 #include "mt_hspsconfiguration.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 //---------------------------------------------------------------------------- |
|
31 // MT_HspsConfiguration::NewL( ) |
|
32 //---------------------------------------------------------------------------- |
|
33 // |
|
34 MT_HspsConfiguration* MT_HspsConfiguration::NewL() |
|
35 { |
|
36 MT_HspsConfiguration* self = MT_HspsConfiguration::NewLC(); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 //---------------------------------------------------------------------------- |
|
42 // MT_HspsConfiguration::NewLC( ) |
|
43 //---------------------------------------------------------------------------- |
|
44 // |
|
45 MT_HspsConfiguration* MT_HspsConfiguration::NewLC() |
|
46 { |
|
47 MT_HspsConfiguration* self = new( ELeave ) MT_HspsConfiguration(); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 //---------------------------------------------------------------------------- |
|
54 // MT_HspsConfiguration::~MT_HspsConfiguration( ) |
|
55 //---------------------------------------------------------------------------- |
|
56 // |
|
57 MT_HspsConfiguration::~MT_HspsConfiguration() |
|
58 { |
|
59 } |
|
60 |
|
61 //---------------------------------------------------------------------------- |
|
62 // MT_HspsConfiguration::MT_HspsConfiguration( ) |
|
63 //---------------------------------------------------------------------------- |
|
64 // |
|
65 MT_HspsConfiguration::MT_HspsConfiguration() |
|
66 { |
|
67 } |
|
68 |
|
69 //---------------------------------------------------------------------------- |
|
70 // MT_HspsConfiguration::ConstructL( ) |
|
71 //---------------------------------------------------------------------------- |
|
72 // |
|
73 void MT_HspsConfiguration::ConstructL() |
|
74 { |
|
75 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
76 // It generates the test case table. |
|
77 CEUnitTestSuiteClass::ConstructL(); |
|
78 } |
|
79 |
|
80 //---------------------------------------------------------------------------- |
|
81 // MT_HspsConfiguration::SetupL( ) |
|
82 //---------------------------------------------------------------------------- |
|
83 // |
|
84 void MT_HspsConfiguration::SetupL( ) |
|
85 { |
|
86 iConfiguration = HSPluginSettingsIf::CHspsConfiguration::NewL(); |
|
87 } |
|
88 |
|
89 //---------------------------------------------------------------------------- |
|
90 // MT_HspsConfiguration::Teardown( ) |
|
91 //---------------------------------------------------------------------------- |
|
92 // |
|
93 void MT_HspsConfiguration::Teardown( ) |
|
94 { |
|
95 if ( iConfiguration ) |
|
96 { |
|
97 delete iConfiguration; |
|
98 iConfiguration = NULL; |
|
99 } |
|
100 } |
|
101 |
|
102 //---------------------------------------------------------------------------- |
|
103 // MT_HspsConfiguration::ConfigIdTestL( ) |
|
104 //---------------------------------------------------------------------------- |
|
105 // |
|
106 void MT_HspsConfiguration::ConfigIdTestL( ) |
|
107 { |
|
108 // First try to read Id which has not been set yet |
|
109 TBufC8<10> id ( iConfiguration->ConfId() ); |
|
110 EUNIT_ASSERT( id.Compare( KNullDesC8 ) == 0 ); |
|
111 |
|
112 // Set new Id and try to read it |
|
113 _LIT8( KId, "10" ); |
|
114 EUNIT_ASSERT_NO_LEAVE( iConfiguration->SetConfIdL( KId ) ); |
|
115 TBufC8<10> id2 ( iConfiguration->ConfId() ); |
|
116 EUNIT_ASSERT( id2.Compare( KId ) == 0 ); |
|
117 } |
|
118 |
|
119 //---------------------------------------------------------------------------- |
|
120 // MT_HspsConfiguration::PluginInfoTestL( ) |
|
121 //---------------------------------------------------------------------------- |
|
122 // |
|
123 void MT_HspsConfiguration::PluginInfoTestL( ) |
|
124 { |
|
125 // HspsConfiguration creates plugininfo during construction, so |
|
126 // test its existence |
|
127 EUNIT_ASSERT( ( & iConfiguration->PluginInfo() ) != NULL ); |
|
128 HSPluginSettingsIf::CPluginInfo& info = iConfiguration->PluginInfo(); |
|
129 |
|
130 // Fill info with something, in teardown no memory leak should occur |
|
131 _LIT8( KName, "My name is Nobody (Il mio nome e Nessuno)" ); |
|
132 EUNIT_ASSERT_NO_LEAVE( info.SetNameL( KName ) ); |
|
133 } |
|
134 |
|
135 //---------------------------------------------------------------------------- |
|
136 // MT_HspsConfiguration::PluginsTestL( ) |
|
137 //---------------------------------------------------------------------------- |
|
138 // |
|
139 void MT_HspsConfiguration::PluginsTestL( ) |
|
140 { |
|
141 // First try to read map which has not been set yet |
|
142 EUNIT_ASSERT( iConfiguration->PluginMaps().Count() == 0 ); |
|
143 RPointerArray<HSPluginSettingsIf::CPluginMap>& maps = iConfiguration->PluginMaps(); |
|
144 |
|
145 // Fill map with something, in teardown no memory leak should occur |
|
146 TInt itemCount = 10; |
|
147 for ( TInt i = 0; i < itemCount; i++ ) |
|
148 { |
|
149 // Should be deleted automatically in the iConfiguration destructor, |
|
150 // otherwise a memory leak occurs (can be considered as the last test) |
|
151 iConfiguration->AddPluginMapL( HSPluginSettingsIf::CPluginMap::NewL() ); |
|
152 } |
|
153 |
|
154 // Test if the items were added |
|
155 EUNIT_ASSERT( maps.Count() == itemCount ); |
|
156 } |
|
157 |
|
158 //---------------------------------------------------------------------------- |
|
159 // MT_HspsConfiguration::ItemsTestL( ) |
|
160 //---------------------------------------------------------------------------- |
|
161 // |
|
162 void MT_HspsConfiguration::ItemsTestL( ) |
|
163 { |
|
164 // First try to read map which has not been set yet |
|
165 EUNIT_ASSERT( iConfiguration->Settings().Count() == 0 ); |
|
166 RPointerArray<HSPluginSettingsIf::CItemMap>& maps = iConfiguration->Settings(); |
|
167 |
|
168 // Fill map with something, in teardown no memory leak should occur |
|
169 TInt itemCount = 10; |
|
170 for ( TInt i = 0; i < itemCount; i++ ) |
|
171 { |
|
172 // Should be deleted automatically in the iConfiguration destructor, |
|
173 // otherwise a memory leak occurs (can be considered as the last test) |
|
174 iConfiguration->AddItemMapL( HSPluginSettingsIf::CItemMap::NewL() ); |
|
175 } |
|
176 |
|
177 // Test if the items were added |
|
178 EUNIT_ASSERT( maps.Count() == itemCount ); |
|
179 } |
|
180 |
|
181 //---------------------------------------------------------------------------- |
|
182 // MT_HspsConfiguration::ObjectsTestL( ) |
|
183 //---------------------------------------------------------------------------- |
|
184 // |
|
185 void MT_HspsConfiguration::ObjectsTestL( ) |
|
186 { |
|
187 // First try to read map which has not been set yet |
|
188 EUNIT_ASSERT( iConfiguration->Resources().Count() == 0 ); |
|
189 RPointerArray<HSPluginSettingsIf::CObjectMap>& maps = iConfiguration->Resources(); |
|
190 |
|
191 // Fill map with something, in teardown no memory leak should occur |
|
192 TInt itemCount = 10; |
|
193 for ( TInt i = 0; i < itemCount; i++ ) |
|
194 { |
|
195 // Should be deleted automatically in the iConfiguration destructor, |
|
196 // otherwise a memory leak occurs (can be considered as the last test) |
|
197 iConfiguration->AddObjectMapL( HSPluginSettingsIf::CObjectMap::NewL() ); |
|
198 } |
|
199 |
|
200 // Test if the items were added |
|
201 EUNIT_ASSERT( maps.Count() == itemCount ); |
|
202 } |
|
203 |
|
204 // EUnit test table |
|
205 EUNIT_BEGIN_TEST_TABLE( |
|
206 MT_HspsConfiguration, |
|
207 "Test for the CPluginMap basic functionality", |
|
208 "MODULE") |
|
209 |
|
210 |
|
211 EUNIT_TEST( |
|
212 "Test ConfigId Set Get functionality", |
|
213 "CHSPSConfiguration", |
|
214 "SetConfIdL, ConfId", |
|
215 "FUNCTIONALITY", |
|
216 SetupL, ConfigIdTestL, Teardown) |
|
217 |
|
218 EUNIT_TEST( |
|
219 "Test PluginInfo", |
|
220 "CHSPSConfiguration", |
|
221 "PluginInfo", |
|
222 "FUNCTIONALITY", |
|
223 SetupL, PluginInfoTestL, Teardown) |
|
224 |
|
225 EUNIT_TEST( |
|
226 "Test Plugin maps", |
|
227 "CHSPSConfiguration", |
|
228 "PluginMaps, AddPluginMapL", |
|
229 "FUNCTIONALITY", |
|
230 SetupL, PluginsTestL, Teardown) |
|
231 |
|
232 EUNIT_TEST( |
|
233 "Test Item maps", |
|
234 "CHSPSConfiguration", |
|
235 "Settings, AddItemMapL", |
|
236 "FUNCTIONALITY", |
|
237 SetupL, ItemsTestL, Teardown) |
|
238 |
|
239 EUNIT_TEST( |
|
240 "Test Object maps", |
|
241 "CHSPSConfiguration", |
|
242 "Resources, AddObjectMapL", |
|
243 "FUNCTIONALITY", |
|
244 SetupL, ObjectsTestL, Teardown) |
|
245 |
|
246 EUNIT_END_TEST_TABLE |