os/ossrv/genericservices/taskscheduler/Test/TSCheduleState2/TU_TSCH_ScheduleState2.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file contains the implementation of test classe for TScheduleState2.
22 #include <schinfointernal.h>
24 _LIT(KTestName, "TScheduleState2 Tests");
25 RTest TheTest(KTestName);
29 //Test macroses and functions
31 static void Check(TInt aValue, TInt aLine)
35 TheTest(EFalse, aLine);
38 static void Check(TInt aValue, TInt aExpected, TInt aLine)
40 if(aValue != aExpected)
42 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
43 TheTest(EFalse, aLine);
46 #define TEST(arg) ::Check((arg), __LINE__)
47 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
52 State accessor for the TScheduleState2 object under test.
54 class TScheduleState2_StateAccessor
57 void TestDefaultConstructor();
58 void TestCopyConstructorOverloadedConstructor();
59 void TestNameSetName();
60 void TestDueTimeSetDueTime();
61 void TestPersistsSetPersists();
62 void TestEnabledSetEnabled();
63 void TestOperatorEqual();
71 @SYMTestCaseID SYSLIB-SCHSVR-CT-0224
72 @SYMTestCaseDesc Check the default constructor works properly
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.
79 void TScheduleState2_StateAccessor::TestDefaultConstructor()
81 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0224 "));
82 TScheduleState2 state;
85 TEST(state.iName == _L(""));
88 TEST(state.iDueTime.GetUtcTime() == TTime(0));
91 TEST(state.iFlags == 0);
94 TEST(state.iReserved == 0);
101 @SYMTestCaseID SYSLIB-SCHSVR-CT-0225
102 @SYMTestCaseDesc Checks the copy constructor and the overloaded constructor
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.
110 void TScheduleState2_StateAccessor::TestCopyConstructorOverloadedConstructor()
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);
116 TTsTime dueTime(time, EFalse); //TTsTime is Home time
118 TScheduleState2 state1(name, dueTime, ETrue, ETrue);
119 TScheduleState2 state2(state1);
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);
132 @SYMTestCaseID SYSLIB-SCHSVR-CT-0226
133 @SYMTestCaseDesc Checks SetName() and Name() functions of TScheduleState2
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.
140 void TScheduleState2_StateAccessor::TestNameSetName()
142 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0226 "));
143 TScheduleState2 state;
144 const TName name(_L("name"));
147 TEST(state.Name() == name);
153 @SYMTestCaseID SYSLIB-SCHSVR-CT-0227
154 @SYMTestCaseDesc Checks SetDueTime() and DueTime()
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.
161 void TScheduleState2_StateAccessor::TestDueTimeSetDueTime()
163 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0227 Test set and get due time APIs "));
165 TScheduleState2 state;
167 TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
169 TTsTime dueTime(time, EFalse); //TTsTime is Home time
171 state.SetDueTime(dueTime);
172 TEST(time == state.DueTime().GetLocalTime());
179 @SYMTestCaseID SYSLIB-SCHSVR-CT-0228
180 @SYMTestCaseDesc Checks SetPersists() and Persists() functions
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.
187 void TScheduleState2_StateAccessor::TestPersistsSetPersists()
189 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0228 "));
190 TScheduleState2 state;
192 //set Persists to Etrue
193 state.SetPersists(ETrue);
194 TEST(state.Persists());
196 //set Persists to EFalse
197 state.SetPersists(EFalse);
198 TEST(!state.Persists());
205 @SYMTestCaseID SYSLIB-SCHSVR-CT-0229
206 @SYMTestCaseDesc Checks Enabled() and SetEnabled() functions
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.
213 void TScheduleState2_StateAccessor::TestEnabledSetEnabled()
215 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0229 "));
216 TScheduleState2 state;
219 state.SetEnabled(ETrue);
220 TEST(state.Enabled());
223 state.SetEnabled(EFalse);
224 TEST(!state.Enabled());
232 @SYMTestCaseID SYSLIB-SCHSVR-CT-0230
233 @SYMTestCaseDesc Check the operator = works properly
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.
241 void TScheduleState2_StateAccessor::TestOperatorEqual()
243 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0230 Test overloaded equals operator "));
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);
249 TTsTime dueTime(time, EFalse); //TTsTime is Home time
251 TScheduleState2 state1(name, dueTime, ETrue, ETrue);
252 TScheduleState2 state2 = state1;
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);
264 static void RunTestsL()
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();
281 //***********************************************************************************
282 GLDEF_C TInt E32Main()
284 CTrapCleanup* tc = CTrapCleanup::New();
292 TRAP(err, ::RunTestsL())
293 TEST2(err, KErrNone);