|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This file contains the implementation of test classe for TScheduleState2. |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <f32file.h> |
|
20 |
|
21 #include "SCHINFO.H" |
|
22 #include <schinfointernal.h> |
|
23 |
|
24 _LIT(KTestName, "TScheduleState2 Tests"); |
|
25 RTest TheTest(KTestName); |
|
26 |
|
27 // |
|
28 // |
|
29 //Test macroses and functions |
|
30 |
|
31 static void Check(TInt aValue, TInt aLine) |
|
32 { |
|
33 if(!aValue) |
|
34 { |
|
35 TheTest(EFalse, aLine); |
|
36 } |
|
37 } |
|
38 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
39 { |
|
40 if(aValue != aExpected) |
|
41 { |
|
42 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
43 TheTest(EFalse, aLine); |
|
44 } |
|
45 } |
|
46 #define TEST(arg) ::Check((arg), __LINE__) |
|
47 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
48 |
|
49 |
|
50 |
|
51 /** |
|
52 State accessor for the TScheduleState2 object under test. |
|
53 */ |
|
54 class TScheduleState2_StateAccessor |
|
55 { |
|
56 public : |
|
57 void TestDefaultConstructor(); |
|
58 void TestCopyConstructorOverloadedConstructor(); |
|
59 void TestNameSetName(); |
|
60 void TestDueTimeSetDueTime(); |
|
61 void TestPersistsSetPersists(); |
|
62 void TestEnabledSetEnabled(); |
|
63 void TestOperatorEqual(); |
|
64 }; |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 /** |
|
70 @file |
|
71 @SYMTestCaseID SYSLIB-SCHSVR-CT-0224 |
|
72 @SYMTestCaseDesc Check the default constructor works properly |
|
73 @SYMTestPriority low |
|
74 @SYMTestActions Creates an instance of TScheduleState2 and check its data has been |
|
75 set to default values. |
|
76 @SYMTestExpectedResults The test must not fail. |
|
77 @SYMPREQ PREQ234 |
|
78 */ |
|
79 void TScheduleState2_StateAccessor::TestDefaultConstructor() |
|
80 { |
|
81 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0224 ")); |
|
82 TScheduleState2 state; |
|
83 |
|
84 //name should be "" |
|
85 TEST(state.iName == _L("")); |
|
86 |
|
87 //iDueTime UTC, O |
|
88 TEST(state.iDueTime.GetUtcTime() == TTime(0)); |
|
89 |
|
90 //iFlags should be 0 |
|
91 TEST(state.iFlags == 0); |
|
92 |
|
93 //iReserved 0 |
|
94 TEST(state.iReserved == 0); |
|
95 } |
|
96 |
|
97 |
|
98 |
|
99 /** |
|
100 @file |
|
101 @SYMTestCaseID SYSLIB-SCHSVR-CT-0225 |
|
102 @SYMTestCaseDesc Checks the copy constructor and the overloaded constructor |
|
103 @SYMTestPriority low |
|
104 @SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor |
|
105 and another instance of TScheduleState2 using the copy constructor, then compares |
|
106 their data and makes sure they are equal. |
|
107 @SYMTestExpectedResults The test must not fail. |
|
108 @SYMPREQ PREQ234 |
|
109 */ |
|
110 void TScheduleState2_StateAccessor::TestCopyConstructorOverloadedConstructor() |
|
111 { |
|
112 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0225 Test constructors ")); |
|
113 const TName name(_L("test_state")); |
|
114 TDateTime date(2005, EMay, 15, 8, 55, 0, 0); |
|
115 TTime time(date); |
|
116 TTsTime dueTime(time, EFalse); //TTsTime is Home time |
|
117 |
|
118 TScheduleState2 state1(name, dueTime, ETrue, ETrue); |
|
119 TScheduleState2 state2(state1); |
|
120 |
|
121 TEST(state1.iName == state2.iName); |
|
122 TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime()); |
|
123 TEST(state1.iFlags == state2.iFlags); |
|
124 TEST(state1.iReserved == state2.iReserved); |
|
125 |
|
126 } |
|
127 |
|
128 |
|
129 |
|
130 /** |
|
131 @file |
|
132 @SYMTestCaseID SYSLIB-SCHSVR-CT-0226 |
|
133 @SYMTestCaseDesc Checks SetName() and Name() functions of TScheduleState2 |
|
134 @SYMTestPriority low |
|
135 @SYMTestActions Creates an instance of TScheduleState2, calls SetName() and Name() |
|
136 and Name() returns the same value as the one set initially. |
|
137 @SYMTestExpectedResults The test must not fail. |
|
138 @SYMPREQ PREQ234 |
|
139 */ |
|
140 void TScheduleState2_StateAccessor::TestNameSetName() |
|
141 { |
|
142 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0226 ")); |
|
143 TScheduleState2 state; |
|
144 const TName name(_L("name")); |
|
145 state.SetName(name); |
|
146 |
|
147 TEST(state.Name() == name); |
|
148 |
|
149 } |
|
150 |
|
151 /** |
|
152 @file |
|
153 @SYMTestCaseID SYSLIB-SCHSVR-CT-0227 |
|
154 @SYMTestCaseDesc Checks SetDueTime() and DueTime() |
|
155 @SYMTestPriority low |
|
156 @SYMTestActions Creates an instance of TScheduleState2, sets its due time and checks |
|
157 the returned time is equel to one set initially. |
|
158 @SYMTestExpectedResults The test must not fail. |
|
159 @SYMPREQ PREQ234 |
|
160 */ |
|
161 void TScheduleState2_StateAccessor::TestDueTimeSetDueTime() |
|
162 { |
|
163 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0227 Test set and get due time APIs ")); |
|
164 |
|
165 TScheduleState2 state; |
|
166 |
|
167 TDateTime date(2005, EMay, 15, 8, 55, 0, 0); |
|
168 TTime time(date); |
|
169 TTsTime dueTime(time, EFalse); //TTsTime is Home time |
|
170 |
|
171 state.SetDueTime(dueTime); |
|
172 TEST(time == state.DueTime().GetLocalTime()); |
|
173 } |
|
174 |
|
175 |
|
176 |
|
177 /** |
|
178 @file |
|
179 @SYMTestCaseID SYSLIB-SCHSVR-CT-0228 |
|
180 @SYMTestCaseDesc Checks SetPersists() and Persists() functions |
|
181 @SYMTestPriority low |
|
182 @SYMTestActions Creates an instance of TScheduleState2, calls SetPersists then Persists |
|
183 and checks the returned value is equal to the one set initially. |
|
184 @SYMTestExpectedResults The test must not fail. |
|
185 @SYMPREQ PREQ234 |
|
186 */ |
|
187 void TScheduleState2_StateAccessor::TestPersistsSetPersists() |
|
188 { |
|
189 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0228 ")); |
|
190 TScheduleState2 state; |
|
191 |
|
192 //set Persists to Etrue |
|
193 state.SetPersists(ETrue); |
|
194 TEST(state.Persists()); |
|
195 |
|
196 //set Persists to EFalse |
|
197 state.SetPersists(EFalse); |
|
198 TEST(!state.Persists()); |
|
199 } |
|
200 |
|
201 |
|
202 |
|
203 /** |
|
204 @file |
|
205 @SYMTestCaseID SYSLIB-SCHSVR-CT-0229 |
|
206 @SYMTestCaseDesc Checks Enabled() and SetEnabled() functions |
|
207 @SYMTestPriority low |
|
208 @SYMTestActions Creates an instance TScheduleState2, calls SetEnabled() then Enabled() |
|
209 and checks the returned value is equal to the one set initially. |
|
210 @SYMTestExpectedResults The test must not fail. |
|
211 @SYMPREQ PREQ234 |
|
212 */ |
|
213 void TScheduleState2_StateAccessor::TestEnabledSetEnabled() |
|
214 { |
|
215 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0229 ")); |
|
216 TScheduleState2 state; |
|
217 |
|
218 //ETrue |
|
219 state.SetEnabled(ETrue); |
|
220 TEST(state.Enabled()); |
|
221 |
|
222 //EFlase |
|
223 state.SetEnabled(EFalse); |
|
224 TEST(!state.Enabled()); |
|
225 |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 /** |
|
231 @file |
|
232 @SYMTestCaseID SYSLIB-SCHSVR-CT-0230 |
|
233 @SYMTestCaseDesc Check the operator = works properly |
|
234 @SYMTestPriority low |
|
235 @SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor, |
|
236 then creates another instance of TScheduleState2 and assigns it the first instance |
|
237 of TScheduleState2. The tests make sure both instances are equal. |
|
238 @SYMTestExpectedResults The test must not fail. |
|
239 @SYMPREQ PREQ234 |
|
240 */ |
|
241 void TScheduleState2_StateAccessor::TestOperatorEqual() |
|
242 { |
|
243 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0230 Test overloaded equals operator ")); |
|
244 |
|
245 const TName name(_L("name")); |
|
246 //set the current utc time to 8.55am, 15 May 2005 -Daylight savings apply on this date |
|
247 TDateTime date(2005, EMay, 15, 8, 55, 0, 0); |
|
248 TTime time(date); |
|
249 TTsTime dueTime(time, EFalse); //TTsTime is Home time |
|
250 |
|
251 TScheduleState2 state1(name, dueTime, ETrue, ETrue); |
|
252 TScheduleState2 state2 = state1; |
|
253 |
|
254 TEST(state1.iName == state2.iName); |
|
255 TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime() ); |
|
256 TEST(state1.iFlags == state2.iFlags); |
|
257 TEST(state1.iReserved == state2.iReserved); |
|
258 } |
|
259 |
|
260 |
|
261 /** |
|
262 Runs all the tests. |
|
263 */ |
|
264 static void RunTestsL() |
|
265 { |
|
266 TheTest.Start(_L("=== Start TScheduleState2 tests \n")); |
|
267 TScheduleState2_StateAccessor* entry = new (ELeave) TScheduleState2_StateAccessor; |
|
268 CleanupStack::PushL(entry); |
|
269 entry->TestDefaultConstructor(); |
|
270 entry->TestCopyConstructorOverloadedConstructor(); |
|
271 entry->TestNameSetName(); |
|
272 entry->TestDueTimeSetDueTime(); |
|
273 entry->TestPersistsSetPersists(); |
|
274 entry->TestEnabledSetEnabled(); |
|
275 entry->TestOperatorEqual(); |
|
276 CleanupStack::PopAndDestroy(); |
|
277 } |
|
278 |
|
279 |
|
280 |
|
281 //*********************************************************************************** |
|
282 GLDEF_C TInt E32Main() |
|
283 { |
|
284 CTrapCleanup* tc = CTrapCleanup::New(); |
|
285 TEST(tc != NULL); |
|
286 |
|
287 __UHEAP_MARK; |
|
288 |
|
289 TInt err; |
|
290 TheTest.Title(); |
|
291 |
|
292 TRAP(err, ::RunTestsL()) |
|
293 TEST2(err, KErrNone); |
|
294 |
|
295 TheTest.End(); |
|
296 TheTest.Close(); |
|
297 |
|
298 __UHEAP_MARKEND; |
|
299 |
|
300 delete tc; |
|
301 |
|
302 return(KErrNone); |
|
303 |
|
304 } |
|
305 |
|
306 |
|
307 |