|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // CLASS UNDER TEST |
|
19 #include <caouserafter.h> |
|
20 #include <aiutility.h> |
|
21 #include <aiplugintool.h> |
|
22 #include <mt_apiaipluginsettings.h> |
|
23 |
|
24 #include <aisystemuids.hrh> |
|
25 #include <aipluginsettings.h> |
|
26 |
|
27 #include <digia/eunit/eunitmacros.h> |
|
28 |
|
29 class TStorer; |
|
30 |
|
31 // CONSTRUCTION |
|
32 MT_ApiAiPluginSettings* MT_ApiAiPluginSettings::NewL() |
|
33 { |
|
34 MT_ApiAiPluginSettings* self = MT_ApiAiPluginSettings::NewLC(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 MT_ApiAiPluginSettings* MT_ApiAiPluginSettings::NewLC() |
|
40 { |
|
41 MT_ApiAiPluginSettings* self = new( ELeave ) MT_ApiAiPluginSettings(); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // Destructor (virtual by CBase) |
|
48 MT_ApiAiPluginSettings::~MT_ApiAiPluginSettings() |
|
49 { |
|
50 #if _BullseyeCoverage |
|
51 cov_write(); |
|
52 #endif |
|
53 } |
|
54 |
|
55 // Default constructor |
|
56 MT_ApiAiPluginSettings::MT_ApiAiPluginSettings() |
|
57 { |
|
58 } |
|
59 |
|
60 // Second phase construct |
|
61 void MT_ApiAiPluginSettings::ConstructL() |
|
62 { |
|
63 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
64 // It generates the test case table. |
|
65 CEUnitTestSuiteClass::ConstructL(); |
|
66 |
|
67 //CAOUserAfter::AfterLD( 2 * 1000000 ); |
|
68 } |
|
69 |
|
70 // METHODS |
|
71 |
|
72 void MT_ApiAiPluginSettings::SetupL( ) |
|
73 { |
|
74 iAiPluginSettings = AiUtility::CreatePluginSettingsL(); |
|
75 } |
|
76 |
|
77 void MT_ApiAiPluginSettings::Teardown( ) |
|
78 { |
|
79 if( iAiPluginSettings ) |
|
80 { |
|
81 delete iAiPluginSettings; |
|
82 iAiPluginSettings = NULL; |
|
83 } |
|
84 |
|
85 } |
|
86 |
|
87 void MT_ApiAiPluginSettings::TestAiPluginSettingsItemL( ) |
|
88 { |
|
89 MAiPluginSettingsItem& item = iAiPluginSettings->AiPluginSettingsItem(); |
|
90 |
|
91 item.SetPublisherId( TUid::Uid( 0x10170FFF ) ); |
|
92 item.SetValueL( _L("DesValue") ); |
|
93 item.SetKey( 1 ); |
|
94 |
|
95 EUNIT_ASSERT( item.PublisherId() == TUid::Uid( 0x10170FFF ) ); |
|
96 EUNIT_ASSERT( item.Value().Compare( _L("DesValue")) == 0 ); |
|
97 EUNIT_ASSERT( item.Key() == 1 ); |
|
98 |
|
99 TInt type = iAiPluginSettings->AiPluginItemType(); |
|
100 |
|
101 } |
|
102 |
|
103 void MT_ApiAiPluginSettings::TestAiPluginContentItemL( ) |
|
104 { |
|
105 MAiPluginContentItem& contentItem = iAiPluginSettings->AiPluginContentItem(); |
|
106 |
|
107 contentItem.SetNameL(_L("ContentItemName")); |
|
108 contentItem.SetTypeL(_L("ContentItemType")); |
|
109 |
|
110 EUNIT_ASSERT( contentItem.Name().Compare( _L("ContentItemName")) == 0 ); |
|
111 EUNIT_ASSERT( contentItem.Type().Compare( _L("ContentItemType")) == 0 ); |
|
112 } |
|
113 |
|
114 void MT_ApiAiPluginSettings::TestAiPluginConfigurationItemL( ) |
|
115 { |
|
116 MAiPluginConfigurationItem& configurationItem = iAiPluginSettings->AiPluginConfigurationItem(); |
|
117 |
|
118 configurationItem.SetOwnerL(_L("ConfigurationItemOwner")); |
|
119 configurationItem.SetNameL( _L("ConfigurationItemName") ); |
|
120 configurationItem.SetValueL( _L("ConfigurationItemValue") ); |
|
121 |
|
122 EUNIT_ASSERT( configurationItem.Owner().Compare( _L("ConfigurationItemOwner")) == 0 ); |
|
123 EUNIT_ASSERT( configurationItem.Name().Compare( _L("ConfigurationItemName")) == 0 ); |
|
124 EUNIT_ASSERT( configurationItem.Value().Compare( _L("ConfigurationItemValue")) == 0 ); |
|
125 } |
|
126 |
|
127 void MT_ApiAiPluginSettings::TestAiPluginSettingsStorerBasicL( ) |
|
128 { |
|
129 //Get settings item |
|
130 MAiPluginSettingsItem& item = iAiPluginSettings->AiPluginSettingsItem(); |
|
131 |
|
132 // test situation the storer is not set, value is not set |
|
133 // should do nothing |
|
134 EUNIT_ASSERT_NO_LEAVE( item.ReadFromStoreL() ); |
|
135 EUNIT_ASSERT_NO_LEAVE( item.SaveToStoreL() ); |
|
136 |
|
137 // test very basic storer functionality when key and value are set |
|
138 // correctly |
|
139 TStorer storer; |
|
140 item.SetStorer( &storer ); |
|
141 TInt32 key = 0x20A; |
|
142 TBuf<20> value( _L("VALUE") ); |
|
143 item.SetKey( key ); |
|
144 item.SetValueL( value ); |
|
145 |
|
146 // Store data to the storer and test storer if the result is stored |
|
147 EUNIT_ASSERT_NO_LEAVE( item.SaveToStoreL() ); |
|
148 TInt32 keyRes; |
|
149 TBuf<20> valueRes; |
|
150 storer.GetKey( keyRes ); |
|
151 storer.GetValue( valueRes ); |
|
152 EUNIT_ASSERT( key == keyRes ); |
|
153 EUNIT_ASSERT( value.Compare( valueRes ) == 0 ); |
|
154 |
|
155 // Read data from the storer and test if the result is read |
|
156 TBuf<20> valueBuf; |
|
157 valueBuf.SetLength(20); |
|
158 // iValue is allocated according to length of input string, erase iValue |
|
159 item.SetValueL( valueBuf ); |
|
160 EUNIT_ASSERT_NO_LEAVE( item.ReadFromStoreL() ); |
|
161 EUNIT_ASSERT( value.Compare( item.Value() )==0 ); |
|
162 } |
|
163 |
|
164 // Storer class implementation |
|
165 TStorer::TStorer( ) |
|
166 { |
|
167 |
|
168 } |
|
169 |
|
170 TStorer::~TStorer( ) |
|
171 { |
|
172 |
|
173 } |
|
174 |
|
175 void TStorer::SaveL( TInt32 aKey, const TDesC& aValue ) |
|
176 { |
|
177 iKey = aKey; |
|
178 if ( aValue.Length()>iValue.MaxLength() ) |
|
179 { |
|
180 User::Leave( KErrArgument ); |
|
181 } |
|
182 iValue.SetLength( 0 ); |
|
183 iValue.Copy( aValue ); |
|
184 } |
|
185 |
|
186 void TStorer::ReadL( TInt32 aKey, TDes& aValue ) |
|
187 { |
|
188 if ( aKey != iKey ) |
|
189 { |
|
190 User::Leave( KErrArgument ); |
|
191 } |
|
192 if ( aValue.MaxLength()<iValue.Length() ) |
|
193 { |
|
194 User::Leave( KErrArgument ); |
|
195 } |
|
196 aValue.SetLength( 0 ); |
|
197 aValue.Copy( iValue ); |
|
198 } |
|
199 |
|
200 void TStorer::SetKey( TInt32 aKey ) |
|
201 { |
|
202 iKey = aKey; |
|
203 } |
|
204 |
|
205 void TStorer::SetValue( const TDesC aValue ) |
|
206 { |
|
207 if ( aValue.Length()<=iValue.MaxLength() ) |
|
208 { |
|
209 iValue.SetLength( 0 ); |
|
210 iValue.Copy( aValue ); |
|
211 } |
|
212 } |
|
213 |
|
214 void TStorer::GetKey( TInt32& aKey ) |
|
215 { |
|
216 aKey = iKey; |
|
217 } |
|
218 |
|
219 void TStorer::GetValue( TDes& aValue ) |
|
220 { |
|
221 if ( aValue.MaxLength()>=iValue.Length() ) |
|
222 { |
|
223 aValue.SetLength( 0 ); |
|
224 aValue.Copy( iValue ); |
|
225 |
|
226 } |
|
227 } |
|
228 |
|
229 // TEST TABLE |
|
230 |
|
231 EUNIT_BEGIN_TEST_TABLE( |
|
232 MT_ApiAiPluginSettings, |
|
233 "Test AiPluginSettingsItem implementation returned from AiUtility::CreatePluginToolL", |
|
234 "MODULE") |
|
235 |
|
236 EUNIT_TEST( |
|
237 "Test AiPluginSettingsItem", |
|
238 "AiPluginSettingsItem", |
|
239 "All", |
|
240 "FUNCTIONALITY", |
|
241 SetupL, TestAiPluginSettingsItemL, Teardown) |
|
242 |
|
243 EUNIT_TEST( |
|
244 "Test AiPluginContentItem", |
|
245 "AiPluginContentItem", |
|
246 "All", |
|
247 "FUNCTIONALITY", |
|
248 SetupL, TestAiPluginContentItemL, Teardown) |
|
249 |
|
250 EUNIT_TEST( |
|
251 "Test AiPluginConfigurationItem", |
|
252 "AiPluginConfigurationItem", |
|
253 "All", |
|
254 "FUNCTIONALITY", |
|
255 SetupL, TestAiPluginConfigurationItemL, Teardown) |
|
256 |
|
257 EUNIT_TEST( |
|
258 "Test TestAiPluginSettingsStorerBasicL", |
|
259 "TestAiPluginSettingsStorerBasicL", |
|
260 "All", |
|
261 "FUNCTIONALITY", |
|
262 SetupL, TestAiPluginSettingsStorerBasicL, Teardown) |
|
263 |
|
264 |
|
265 EUNIT_END_TEST_TABLE |
|
266 |
|
267 // END OF FILE |