os/ossrv/genericservices/taskscheduler/Test/TSCheduleEntryInfo2/TU_TSCH_ScheduleEntryInfo2.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 // T_ScheduleEntryInfo2.cpp
15 // This file contains the implementation of test classe for TScheduleEntryInfo2.
22 #include <schinfointernal.h>
27 _LIT(KTestName, "TScheduleEntryInfo2 Tests");
28 RTest TheTest(KTestName);
30 static RFs TheFsSession;
31 _LIT(KFileName,"_:\\tscheduleinfo2.dat");
32 static TBuf<32> fileName;
36 //Test macroses and functions
38 static void Check(TInt aValue, TInt aLine)
42 (void)TheFsSession.Delete(fileName);
43 TheTest(EFalse, aLine);
46 static void Check(TInt aValue, TInt aExpected, TInt aLine)
48 if(aValue != aExpected)
50 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
51 (void)TheFsSession.Delete(fileName);
52 TheTest(EFalse, aLine);
55 #define TEST(arg) ::Check((arg), __LINE__)
56 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
60 State accessor for the TScheduleEntryInfo2 object under test.
62 class TScheduleEntryInfo2_StateAccessor
66 void TestDefaultConstructor();
67 void TestCopyConstructorOverloadedConstructor();
69 //utility Get and Set methods
70 void TestIntervalTypeSetIntervalType();
71 void TestStartTimeSetStartTime();
72 void TestIntervalSetInterval();
73 void TestValidityPeriodSetValidityPeriod();
74 void TestNonExportedConstructor();
75 void TestExternalizeInternalizeL();
82 @SYMTestCaseID SYSLIB-SCHSVR-CT-0231
83 @SYMTestCaseDesc Check the default constructor
85 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor
86 anc checks that the data has been properly initialised
87 @SYMTestExpectedResults The test must not fail.
90 void TScheduleEntryInfo2_StateAccessor::TestDefaultConstructor()
92 //Default constructor called
93 //Sets Start Time to 0 UTC time
94 //the interval type to 0,
96 //the validityPeriod to 0
97 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0231 Test default constructor "));
98 TScheduleEntryInfo2 entry;
100 TEST(entry.iIntervalType==0);
101 TEST(entry.iStartTime.GetUtcTime() == TTime(0));
102 TEST(entry.iInterval == 0);
103 TEST(entry.iValidityPeriod == TTimeIntervalMinutes(0));
109 @SYMTestCaseID SYSLIB-SCHSVR-CT-0232
110 @SYMTestCaseDesc Check the copy constructor and the overloaded constructor
112 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the overloaded
113 constructor and another instance of TScheduleEntryInfo2 using the copy constructor.
114 Then checks that data of both instances are equal.
115 @SYMTestExpectedResults The test must not fail.
118 void TScheduleEntryInfo2_StateAccessor::TestCopyConstructorOverloadedConstructor()
120 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0232 Text contructors "));
122 TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
124 TTsTime startTime(time, EFalse);
125 TIntervalType intervalType(EHourly);
127 TTimeIntervalMinutes validityPeriod(60);
129 TScheduleEntryInfo2 entry1(startTime, intervalType, interval, validityPeriod);
131 TScheduleEntryInfo2 entry2(entry1);
133 //Test entry1 == entry2
134 TEST(entry1.StartTime().GetLocalTime() == entry2.StartTime().GetLocalTime());
135 TEST(entry1.ValidityPeriod() == entry2.ValidityPeriod());
136 TEST(entry1.Interval() == entry2.Interval());
143 @SYMTestCaseID SYSLIB-SCHSVR-CT-0233
144 @SYMTestCaseDesc Check SetIntervalType and IntervalType.
145 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor.
146 Sets its interval type and checks that the returned value of IntervalType()
147 is equal to the one set initially.
148 @SYMTestExpectedResults The test must not fail.
151 void TScheduleEntryInfo2_StateAccessor::TestIntervalTypeSetIntervalType()
153 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0233 Test set and get for Interval Type "));
155 TScheduleEntryInfo2 scheduleEntryInfo;
157 scheduleEntryInfo.SetIntervalType(TIntervalType(EHourly));
158 TIntervalType intervalType = scheduleEntryInfo.IntervalType();
159 TEST(intervalType == EHourly);
165 @SYMTestCaseID SYSLIB-SCHSVR-CT-0234
166 @SYMTestCaseDesc Check SetStartTime() and StartTime()
168 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor
169 Sets its start time using SetStartTime() and compares StartTime() returned value
170 to the one set initially.
171 @SYMTestExpectedResults The test must not fail.
174 void TScheduleEntryInfo2_StateAccessor::TestStartTimeSetStartTime()
176 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0234 Test start time set and get methods "));
178 TScheduleEntryInfo2 scheduleEntryInfo;
180 TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
182 TTsTime startTime(time, EFalse);
184 scheduleEntryInfo.SetStartTime(startTime);
186 TEST(scheduleEntryInfo.StartTime().GetLocalTime() == startTime.GetLocalTime());
192 @SYMTestCaseID SYSLIB-SCHSVR-CT-0235
193 @SYMTestCaseDesc Check SetInterval() and Intervale()
195 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor
196 Sets its Interval using SetInterval() and compares the returned value of
197 Interval() to the one set initially.
198 @SYMTestExpectedResults The test must not fail.
201 void TScheduleEntryInfo2_StateAccessor::TestIntervalSetInterval()
203 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0235 Test set and get for Interval "));
205 TScheduleEntryInfo2 scheduleEntryInfo;
206 scheduleEntryInfo.SetInterval(1);
207 TEST(scheduleEntryInfo.Interval() == TInt(1));
212 @SYMTestCaseID SYSLIB-SCHSVR-CT-0236
213 @SYMTestCaseDesc Check SetValidityPeriod() and ValidityPeriod()
215 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor
216 Sets its validty period using SetValidityPeriod() and checks that ValidityPeriod() returns
217 the same value as the one set initially.
218 @SYMTestExpectedResults The test must not fail.
221 void TScheduleEntryInfo2_StateAccessor::TestValidityPeriodSetValidityPeriod()
223 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0236 Set and get for validity period "));
224 TScheduleEntryInfo2 scheduleEntryInfo;
226 scheduleEntryInfo.SetValidityPeriod(60);
227 TTimeIntervalMinutes retValidityPeriod = scheduleEntryInfo.ValidityPeriod();
229 TEST(retValidityPeriod == TTimeIntervalMinutes(60));
235 @SYMTestCaseID SYSLIB-SCHSVR-CT-0237
236 @SYMTestCaseDesc Check non exported constructor provided for use with the deprecated APIs
238 @SYMTestActions Creates an instance of TScheduleEntryInfo using the default constructor, sets its member data,
239 and creates an instance of TScheduleEntryInfo2 using the provied constructor for use with deprecated APIs.
240 Then checks that TScheduleEntryInfo2 date is equal to TScheduleEntryInfo data.
242 @SYMTestExpectedResults The test must not fail.
245 void TScheduleEntryInfo2_StateAccessor::TestNonExportedConstructor()
247 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0237 Test non exported constructor "));
249 TScheduleEntryInfo entry1;
250 entry1.iIntervalType = EHourly;
251 entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(1);
253 entry1.iInterval = 1;
254 entry1.iValidityPeriod = 20;
256 TScheduleEntryInfo2 entry2(entry1);
258 //test that scheduleEntryInfo2 startTime is local time
259 TEST(!entry2.iStartTime.IsUtc());
262 TEST(entry2.iIntervalType == entry1.iIntervalType);
265 TEST(entry2.iInterval == entry1.iInterval);
267 //test validity period
268 TEST(entry2.iValidityPeriod == entry1.iValidityPeriod);
274 @SYMTestCaseID SYSLIB-SCHSVR-CT-0238
275 @SYMTestCaseDesc Check Exetrnalize and Internalize methods
277 @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the overloaded operator, externalizes it
278 to a file and then internalizes into another instance of TScheduleEntryInfo2.
279 Checks the externalized data is the same as the internalized one.
280 @SYMTestExpectedResults The test must not fail.
283 void TScheduleEntryInfo2_StateAccessor::TestExternalizeInternalizeL()
287 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0238 \n=== Test TScheduleEntryInfo2::ExternalizeL\n"));
291 TFileName testFileName(fileName);
292 TEST2(file.Replace(TheFsSession,testFileName,EFileWrite|EFileRead), KErrNone);
294 CleanupClosePushL(buf);
296 RWriteStream stream(&buf);
298 TTsTime ttime(SchSvrHelpers::TimeBasedOnOffset(1), EFalse);
299 TScheduleEntryInfo2 entry1(ttime, EHourly, 1, 20);
300 stream << entry1; //externalize TScheduleEntryInfo2
302 CleanupStack::PopAndDestroy(&buf);
306 TheTest.Next(_L("\n=== Test TScheduleEntryInfo2::InternalizeL\n"));
307 TScheduleEntryInfo2 entry2;
308 TInt err = file.Open(TheFsSession,testFileName,EFileRead);
309 TEST2(err, KErrNone);
311 CleanupClosePushL(buf2);
313 RReadStream stream2(&buf2);
315 stream2 >> entry2; //internalize TScheduleEntryInfo2
317 //check iIntervalType
318 TEST(entry1.iIntervalType == entry2.iIntervalType);
321 TEST(entry1.iStartTime.GetUtcTime() == entry2.iStartTime.GetUtcTime());
324 TEST(entry1.iInterval == entry2.iInterval);
326 //check iValidityPeriod
327 TEST(entry1.iValidityPeriod == entry2.iValidityPeriod);
329 CleanupStack::PopAndDestroy(&buf2);
334 @SYMTestCaseID SYSLIB-SCHSVR-CT-3368
335 @SYMTestCaseDesc Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup.
336 @SYMTestPriority High
337 @SYMTestActions This test does not have any capability. It tries to create persistent
338 time/ conduction schedule, it fail to create schedule
339 So return code will be KErrPermissionDenied
340 @SYMTestExpectedResults Test must not fail
341 @SYMDEF PDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup.
343 LOCAL_D void CreatePersistentScheduleCapabilityTest()
347 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3368 \nPDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup\n"));
349 RScheduler TheScheduler;
350 TheTest(TheScheduler.Connect() == KErrNone);;
352 //Create persistent time based schedule
353 CArrayFixFlat<TScheduleEntryInfo2>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
354 CleanupStack::PushL(entryList);
355 TSchedulerItemRef ref;
357 TTime ttime(SchSvrHelpers::TimeBasedOnOffset(0));
358 TTsTime startTime1(ttime, EFalse);
360 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
361 entryList->AppendL(entry1);
363 // Create the time base schedule and check capability policing is working .
364 TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrPermissionDenied);
366 CleanupStack::PopAndDestroy(entryList);
368 //Create persistent Condition based schedule
369 CArrayFixFlat<TTaskSchedulerCondition>* conditionList = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);
370 CleanupStack::PushL(conditionList);
371 TSchedulerItemRef ref1;
373 TTaskSchedulerCondition condition1;
374 const TUid KTestUid = TUid::Uid(0x01234566);
375 condition1.iCategory = KTestUid;
376 condition1.iKey = 10;
377 condition1.iState = 10;
378 condition1.iType = TTaskSchedulerCondition::EEquals;
379 conditionList->AppendL(condition1);
381 // Create the condition base schedule and check capability policing is working .
382 TEST2(TheScheduler.CreatePersistentSchedule(ref1, *conditionList,startTime1),KErrPermissionDenied);
384 CleanupStack::PopAndDestroy(conditionList);
385 TheScheduler.Close();
394 static void RunTestsL()
396 TheTest.Start(_L("=== Start TScheduleEntryInfo2 tests \n"));
398 CreatePersistentScheduleCapabilityTest();
400 TScheduleEntryInfo2_StateAccessor* scheduleStateAccessor = new (ELeave) TScheduleEntryInfo2_StateAccessor;
402 CleanupStack::PushL(scheduleStateAccessor);
404 scheduleStateAccessor->TestDefaultConstructor();
405 scheduleStateAccessor->TestCopyConstructorOverloadedConstructor();
407 //utility Get and Set methods
408 scheduleStateAccessor->TestIntervalTypeSetIntervalType();
409 scheduleStateAccessor->TestStartTimeSetStartTime();
410 scheduleStateAccessor->TestIntervalSetInterval();
411 scheduleStateAccessor->TestValidityPeriodSetValidityPeriod();
412 scheduleStateAccessor->TestNonExportedConstructor();
414 //utility externalize internalize
415 scheduleStateAccessor->TestExternalizeInternalizeL();
416 CleanupStack::PopAndDestroy();
421 //***********************************************************************************
422 GLDEF_C TInt E32Main()
424 CTrapCleanup* tc = CTrapCleanup::New();
429 fileName.Copy(KFileName);
430 fileName[0] = RFs::GetSystemDriveChar();
432 TInt err = TheFsSession.Connect();
433 TEST2(err, KErrNone);
437 TRAP(err, ::RunTestsL())
438 TEST2(err, KErrNone);
440 (void)TheFsSession.Delete(fileName);
441 TheFsSession.Close();