|
1 /* |
|
2 * Copyright (c) 2004 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: SAP settings observer test cases |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 #include "WVSAPSettingsObserverTestCases.h" |
|
21 #include "CIMPSSAPSettingsStore.h" |
|
22 #include "CIMPSSAPSettings.h" |
|
23 #include "CIMPSSAPSettingsList.h" |
|
24 #include "IMPSSAPSettingsStoreTestUtils.h" |
|
25 #include "CObserverWait.h" |
|
26 |
|
27 #include <e32err.h> |
|
28 |
|
29 enum TThreadOps |
|
30 { |
|
31 EThreadOp_AccessStore, |
|
32 EThreadOp_QueryDefault, |
|
33 EThreadOp_AddSAP, |
|
34 EThreadOp_SeveralTransactions, |
|
35 EThreadOp_ComplexTransactionsEncapsulated, |
|
36 EThreadOp_ComplexTransactionsEncapsulatedRollBack |
|
37 }; |
|
38 |
|
39 |
|
40 // CONSTRUCTION |
|
41 // Static constructor |
|
42 WVSAPSettingsObserverTestCases* WVSAPSettingsObserverTestCases::NewLC() |
|
43 { |
|
44 WVSAPSettingsObserverTestCases* self = new( ELeave ) WVSAPSettingsObserverTestCases; |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 WVSAPSettingsObserverTestCases* WVSAPSettingsObserverTestCases::NewL() |
|
51 { |
|
52 WVSAPSettingsObserverTestCases* self = WVSAPSettingsObserverTestCases::NewLC(); |
|
53 CleanupStack::Pop(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // Destructor (virtual by CBase) |
|
58 WVSAPSettingsObserverTestCases::~WVSAPSettingsObserverTestCases() |
|
59 { |
|
60 delete iStore; |
|
61 |
|
62 delete iSettingsEmpty; |
|
63 delete iSettingsFilled; |
|
64 delete iDefaultSAP; |
|
65 delete iLoggedInSAP; |
|
66 |
|
67 |
|
68 delete iObsWait; |
|
69 } |
|
70 |
|
71 // Second phase construct |
|
72 void WVSAPSettingsObserverTestCases::ConstructL() |
|
73 { |
|
74 iSettingsEmpty = CIMPSSAPSettings::NewL(); |
|
75 |
|
76 iSettingsFilled = CIMPSSAPSettings::NewL(); |
|
77 IMPSSAPSettingsStoreTestUtils::FillContainerL( *iSettingsFilled, _L( "SettingsFilled" ) ); |
|
78 |
|
79 iDefaultSAP = CIMPSSAPSettings::NewL(); |
|
80 IMPSSAPSettingsStoreTestUtils::FillContainerL( *iDefaultSAP, _L( "DefaultSAP" ) ); |
|
81 |
|
82 iLoggedInSAP = CIMPSSAPSettings::NewL(); |
|
83 IMPSSAPSettingsStoreTestUtils::FillContainerL( *iLoggedInSAP, _L( "LoggedInSAP" ) ); |
|
84 |
|
85 iObsWait = CObserverWait<TBool, TInt>::NewL(); |
|
86 |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 WVSAPSettingsObserverTestCases::WVSAPSettingsObserverTestCases() |
|
92 { |
|
93 iSAPNameIndex = 0; |
|
94 } |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 //--------------------------------------------------------------- |
|
100 //----------------- TEST CASE METHODS --------------------------- |
|
101 //--------------------------------------------------------------- |
|
102 //Observer Test cases to add SAP and Remove SAP. |
|
103 |
|
104 TInt WVSAPSettingsObserverTestCases::TestNotify_AddSapL() |
|
105 { |
|
106 ResetTheObsState(); |
|
107 |
|
108 /* IMPSSAPSettingsStoreTestUtils::UnigueSAPNameL( iSAPNameIndex, |
|
109 *iSettingsFilled ); */ |
|
110 |
|
111 //Create the Store |
|
112 iStore = CIMPSSAPSettingsStore::NewL(); |
|
113 |
|
114 IMPSSAPSettingsStoreTestUtils::DeleteAllSAPSettingsL( *iStore ); |
|
115 |
|
116 //Add the observer |
|
117 iStore->AddObserverL( this, EIMPSPECAccessGroup ); |
|
118 |
|
119 IMPSSAPSettingsStoreTestUtils::UnigueSAPNameL( iSAPNameIndex, |
|
120 *iSettingsFilled ); |
|
121 |
|
122 //Do the operation for store |
|
123 iStore->StoreNewSAPL( iSettingsFilled, EIMPSPECAccessGroup ); |
|
124 |
|
125 //Start the timer, expect HandleSAPEvent to be called. |
|
126 iObsWait->Wait( 100000 ); //wait or timeout |
|
127 |
|
128 RDebug::Print( _L( "First event: %d" ), iObsWait->Value2() ); |
|
129 |
|
130 iObsWait->Value1(); |
|
131 if ( iObsWait->Value2() != ESAPSettingChanged ) |
|
132 { |
|
133 //There was an error, just return from the function. |
|
134 return KErrArgument; |
|
135 } |
|
136 |
|
137 WaitQuedEvents( 1 ); |
|
138 |
|
139 //Get the SAP count after deletion of SAPs |
|
140 TInt count = iStore->SAPCountL( EIMPSPECAccessGroup ); |
|
141 |
|
142 //Delete the observer |
|
143 iStore->RemoveObserver( this ); |
|
144 |
|
145 //Check the count of SAPs added : |
|
146 if ( count == 1 ) |
|
147 { |
|
148 //StoreNewSAPL operation was successfull |
|
149 return KErrNone; |
|
150 } |
|
151 else |
|
152 { |
|
153 return KErrGeneral; |
|
154 } |
|
155 |
|
156 } |
|
157 |
|
158 |
|
159 TInt WVSAPSettingsObserverTestCases::TestNotify_RemoveSapL() |
|
160 { |
|
161 ResetTheObsState(); |
|
162 |
|
163 //Create the Store |
|
164 iStore = CIMPSSAPSettingsStore::NewL(); |
|
165 |
|
166 // Add the observer |
|
167 iStore->AddObserverL( this, EIMPSPECAccessGroup ); |
|
168 |
|
169 //Delete the previuosly existing SAP settings |
|
170 IMPSSAPSettingsStoreTestUtils::DeleteAllSAPSettingsL( *iStore ); |
|
171 |
|
172 //Add the SAP |
|
173 IMPSSAPSettingsStoreTestUtils::AddSAPSettingsL( *iStore, |
|
174 2, |
|
175 iExistingUid1, |
|
176 iExistingUid2, |
|
177 EIMPSPECAccessGroup ); |
|
178 //Delete the SAPs added |
|
179 iStore->DeleteSAPL( iExistingUid1 ); |
|
180 iObsWait->Wait( 100000 ); //wait or timeout |
|
181 |
|
182 RDebug::Print( _L( "First event: %d" ), iObsWait->Value2() ); |
|
183 |
|
184 iObsWait->Value1(); |
|
185 if ( iObsWait->Value2() != ESAPSettingChanged ) |
|
186 { |
|
187 //There was an error, return from the function. |
|
188 return KErrArgument; |
|
189 } |
|
190 |
|
191 WaitQuedEvents( 1 ); |
|
192 |
|
193 //Get the SAP count after deletion of SAPs |
|
194 TInt count = iStore->SAPCountL( EIMPSPECAccessGroup ); |
|
195 |
|
196 //Delete the observer |
|
197 iStore->RemoveObserver( this ); |
|
198 |
|
199 if ( count != 1 ) //deletion did not happen. |
|
200 //we created 2 SAPs and deleted one SAP, the count of number of SAPs on the store must be 1. |
|
201 { |
|
202 return KErrGeneral ; |
|
203 } |
|
204 else |
|
205 { |
|
206 return KErrNone; |
|
207 } |
|
208 } |
|
209 |
|
210 //Implementation of the HandleSAPEvent function, the observer interface |
|
211 |
|
212 void WVSAPSettingsObserverTestCases::HandleSAPEvent( TSAPEvent aEvent ) |
|
213 { |
|
214 iObsWait->SetValue1( ETrue ); //Event is really called |
|
215 iObsWait->SetValue2( aEvent ); |
|
216 iObsWait->Completed();//now the wait will return |
|
217 RDebug::Print( _L( "SAP Event occurred!" ) ); |
|
218 } |
|
219 |
|
220 //Implementation of the private helper functions |
|
221 void WVSAPSettingsObserverTestCases::ResetTheObsState() |
|
222 { |
|
223 iObsWait->SetValue1( EFalse ); |
|
224 iObsWait->SetValue2( KErrNotFound ); |
|
225 } |
|
226 |
|
227 |
|
228 void WVSAPSettingsObserverTestCases::WaitQuedEvents( TInt aEventCountStart ) |
|
229 { |
|
230 FOREVER |
|
231 { |
|
232 ResetTheObsState(); |
|
233 if ( iObsWait->Wait( 5000000 ) ) |
|
234 { |
|
235 RDebug::Print( _L( "Queued event[%d]: %d" ), aEventCountStart, |
|
236 iObsWait->Value2() ); |
|
237 aEventCountStart++; |
|
238 } |
|
239 else |
|
240 { |
|
241 return; |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 TInt WVSAPSettingsObserverTestCases::CountQueuedEvents( TInt aEventCountStart ) |
|
247 { |
|
248 FOREVER |
|
249 { |
|
250 ResetTheObsState(); |
|
251 if ( iObsWait->Wait( 1000000 ) ) |
|
252 { |
|
253 RDebug::Print( _L( "Queued event[%d]: %d" ), aEventCountStart, |
|
254 iObsWait->Value2() ); |
|
255 aEventCountStart++; |
|
256 } |
|
257 else |
|
258 { |
|
259 return aEventCountStart; |
|
260 } |
|
261 } |
|
262 } |
|
263 |
|
264 // End of File |
|
265 |