os/ossrv/genericservices/taskscheduler/Test/TSCheduleEntryInfo2/TU_TSCH_ScheduleEntryInfo2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSCheduleEntryInfo2/TU_TSCH_ScheduleEntryInfo2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,454 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// T_ScheduleEntryInfo2.cpp
    1.18 +// This file contains the implementation of test classe for TScheduleEntryInfo2. 
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32test.h>
    1.23 +#include <f32file.h>
    1.24 +#include <s32file.h>
    1.25 +#include <schinfointernal.h>
    1.26 +#include "Thelpers.h"
    1.27 +
    1.28 +#include "SCHINFO.H"
    1.29 +
    1.30 +_LIT(KTestName,	"TScheduleEntryInfo2 Tests");
    1.31 +RTest	TheTest(KTestName);
    1.32 +
    1.33 +static RFs			TheFsSession;
    1.34 +_LIT(KFileName,"_:\\tscheduleinfo2.dat"); 
    1.35 +static TBuf<32> fileName;
    1.36 + 
    1.37 +//
    1.38 +//
    1.39 +//Test macroses and functions
    1.40 +
    1.41 +static void Check(TInt aValue, TInt aLine)
    1.42 +	{
    1.43 +	if(!aValue)
    1.44 +		{
    1.45 +		(void)TheFsSession.Delete(fileName);
    1.46 +		TheTest(EFalse, aLine);
    1.47 +		}
    1.48 +	}
    1.49 +static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.50 +	{
    1.51 +	if(aValue != aExpected)
    1.52 +		{
    1.53 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.54 +		(void)TheFsSession.Delete(fileName);
    1.55 +		TheTest(EFalse, aLine);
    1.56 +		}
    1.57 +	}
    1.58 +#define TEST(arg) ::Check((arg), __LINE__)
    1.59 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) 
    1.60 +
    1.61 +
    1.62 +/**
    1.63 +State accessor for the TScheduleEntryInfo2 object under test.
    1.64 +*/
    1.65 +class TScheduleEntryInfo2_StateAccessor
    1.66 +	{
    1.67 +
    1.68 +public:
    1.69 +	void TestDefaultConstructor();
    1.70 +	void TestCopyConstructorOverloadedConstructor();	
    1.71 +		
    1.72 +	//utility Get and Set methods
    1.73 +	void TestIntervalTypeSetIntervalType();
    1.74 +	void TestStartTimeSetStartTime();
    1.75 +	void TestIntervalSetInterval();
    1.76 +	void TestValidityPeriodSetValidityPeriod();
    1.77 +	void TestNonExportedConstructor();
    1.78 +	void TestExternalizeInternalizeL();
    1.79 +	};
    1.80 +
    1.81 +
    1.82 +
    1.83 +/**
    1.84 +@file
    1.85 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0231
    1.86 +@SYMTestCaseDesc 			Check the default constructor
    1.87 +@SYMTestPriority 			low
    1.88 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the default constructor
    1.89 +							anc checks that the data has been properly initialised
    1.90 +@SYMTestExpectedResults		The test must not fail.
    1.91 +@SYMPREQ					PREQ234
    1.92 +*/	
    1.93 +void TScheduleEntryInfo2_StateAccessor::TestDefaultConstructor()
    1.94 +	{
    1.95 +	//Default constructor called
    1.96 +	//Sets Start Time to 0 UTC time
    1.97 +	//the interval type to 0,
    1.98 +	//the interval to 0,
    1.99 +	//the validityPeriod to 0
   1.100 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0231 Test default constructor "));
   1.101 +	TScheduleEntryInfo2 entry;
   1.102 +	
   1.103 +	TEST(entry.iIntervalType==0);
   1.104 +	TEST(entry.iStartTime.GetUtcTime() == TTime(0));
   1.105 +	TEST(entry.iInterval == 0);
   1.106 +	TEST(entry.iValidityPeriod == TTimeIntervalMinutes(0));	
   1.107 +	}
   1.108 +
   1.109 +
   1.110 +/**
   1.111 +@file
   1.112 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0232
   1.113 +@SYMTestCaseDesc 			Check the copy constructor and the overloaded constructor
   1.114 +@SYMTestPriority 			low
   1.115 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the overloaded
   1.116 +							constructor and another instance of TScheduleEntryInfo2 using the copy constructor.
   1.117 +							Then checks that data of both instances are equal. 
   1.118 +@SYMTestExpectedResults		The test must not fail.
   1.119 +@SYMPREQ					PREQ234
   1.120 +*/		
   1.121 +void TScheduleEntryInfo2_StateAccessor::TestCopyConstructorOverloadedConstructor()
   1.122 +	{
   1.123 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0232 Text contructors "));	
   1.124 +
   1.125 +	TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
   1.126 +	TTime time(date);
   1.127 +	TTsTime startTime(time, EFalse);
   1.128 +	TIntervalType intervalType(EHourly);
   1.129 +	TInt interval(1);
   1.130 +	TTimeIntervalMinutes validityPeriod(60);
   1.131 +	
   1.132 +	TScheduleEntryInfo2 entry1(startTime, intervalType, interval, validityPeriod);
   1.133 +	
   1.134 +	TScheduleEntryInfo2 entry2(entry1);	
   1.135 +	
   1.136 +	//Test entry1 == entry2
   1.137 +	TEST(entry1.StartTime().GetLocalTime() == entry2.StartTime().GetLocalTime());
   1.138 +	TEST(entry1.ValidityPeriod() == entry2.ValidityPeriod());
   1.139 +	TEST(entry1.Interval() == entry2.Interval());
   1.140 +	
   1.141 +	}
   1.142 +	
   1.143 +	 
   1.144 +/**
   1.145 +@file
   1.146 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0233
   1.147 +@SYMTestCaseDesc 			Check SetIntervalType and IntervalType.
   1.148 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the default constructor.
   1.149 +							Sets its interval type and checks that the returned value of IntervalType() 
   1.150 +							is equal to the one set initially.
   1.151 +@SYMTestExpectedResults		The test must not fail.
   1.152 +@SYMPREQ					PREQ234
   1.153 +*/	
   1.154 +void TScheduleEntryInfo2_StateAccessor::TestIntervalTypeSetIntervalType()
   1.155 +	{
   1.156 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0233 Test set and get for Interval Type "));
   1.157 +
   1.158 +	TScheduleEntryInfo2 scheduleEntryInfo;
   1.159 +	
   1.160 +	scheduleEntryInfo.SetIntervalType(TIntervalType(EHourly));
   1.161 +	TIntervalType intervalType = scheduleEntryInfo.IntervalType();
   1.162 +	TEST(intervalType == EHourly);	
   1.163 +	}
   1.164 +
   1.165 +	
   1.166 +/**
   1.167 +@file
   1.168 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0234
   1.169 +@SYMTestCaseDesc 			Check SetStartTime() and StartTime()
   1.170 +@SYMTestPriority 			low
   1.171 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the default constructor
   1.172 +							Sets its start time using SetStartTime() and compares StartTime() returned value
   1.173 +							to the one set initially.
   1.174 +@SYMTestExpectedResults		The test must not fail.
   1.175 +@SYMPREQ					PREQ234
   1.176 +*/		
   1.177 +void TScheduleEntryInfo2_StateAccessor::TestStartTimeSetStartTime()
   1.178 +	{
   1.179 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0234 Test start time set and get methods "));
   1.180 +	
   1.181 +	TScheduleEntryInfo2 scheduleEntryInfo;
   1.182 +	
   1.183 +	TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
   1.184 +	TTime time(date);
   1.185 +	TTsTime startTime(time, EFalse);
   1.186 +	
   1.187 +	scheduleEntryInfo.SetStartTime(startTime);
   1.188 +	
   1.189 +	TEST(scheduleEntryInfo.StartTime().GetLocalTime() == startTime.GetLocalTime());
   1.190 +	}
   1.191 +
   1.192 +
   1.193 +/**
   1.194 +@file
   1.195 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0235
   1.196 +@SYMTestCaseDesc 			Check SetInterval() and Intervale() 
   1.197 +@SYMTestPriority 			low
   1.198 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the default constructor
   1.199 +							Sets its Interval using SetInterval() and compares the returned value of 
   1.200 +							Interval() to the one set initially.
   1.201 +@SYMTestExpectedResults		The test must not fail.
   1.202 +@SYMPREQ					PREQ234
   1.203 +*/		
   1.204 +void TScheduleEntryInfo2_StateAccessor::TestIntervalSetInterval()
   1.205 +	{
   1.206 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0235 Test set and get for Interval "));
   1.207 +	
   1.208 +	TScheduleEntryInfo2 scheduleEntryInfo;
   1.209 +	scheduleEntryInfo.SetInterval(1);
   1.210 +	TEST(scheduleEntryInfo.Interval() == TInt(1));
   1.211 +	}
   1.212 +	
   1.213 +/**
   1.214 +@file
   1.215 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0236
   1.216 +@SYMTestCaseDesc 			Check SetValidityPeriod() and ValidityPeriod()
   1.217 +@SYMTestPriority 			low
   1.218 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the default constructor
   1.219 +							Sets its validty period using SetValidityPeriod() and checks that ValidityPeriod() returns 
   1.220 +							the same value as the one set initially.
   1.221 +@SYMTestExpectedResults		The test must not fail.
   1.222 +@SYMPREQ					PREQ234
   1.223 +*/	
   1.224 +void TScheduleEntryInfo2_StateAccessor::TestValidityPeriodSetValidityPeriod()
   1.225 +	{
   1.226 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0236 Set and get for validity period  "));
   1.227 +	TScheduleEntryInfo2 scheduleEntryInfo;
   1.228 +	
   1.229 +	scheduleEntryInfo.SetValidityPeriod(60);
   1.230 +	TTimeIntervalMinutes retValidityPeriod = scheduleEntryInfo.ValidityPeriod();
   1.231 +	
   1.232 +	TEST(retValidityPeriod == TTimeIntervalMinutes(60));
   1.233 +	
   1.234 +	}
   1.235 +	
   1.236 +/**
   1.237 +@file
   1.238 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0237
   1.239 +@SYMTestCaseDesc 			Check non exported constructor provided for use with the deprecated APIs
   1.240 +@SYMTestPriority 			low
   1.241 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo using the default constructor, sets its member data, 
   1.242 +							and creates an instance of TScheduleEntryInfo2 using the provied constructor for use with deprecated APIs.
   1.243 +							Then checks that TScheduleEntryInfo2 date is equal to TScheduleEntryInfo data.
   1.244 +
   1.245 +@SYMTestExpectedResults		The test must not fail.
   1.246 +@SYMPREQ					PREQ234
   1.247 +*/	
   1.248 +void TScheduleEntryInfo2_StateAccessor::TestNonExportedConstructor()
   1.249 +	{
   1.250 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0237 Test non exported constructor "));
   1.251 +	
   1.252 +	TScheduleEntryInfo entry1;
   1.253 +	entry1.iIntervalType	= EHourly;
   1.254 +	entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(1); 
   1.255 +	
   1.256 +	entry1.iInterval		= 1;
   1.257 +	entry1.iValidityPeriod	= 20;
   1.258 +	
   1.259 +	TScheduleEntryInfo2 entry2(entry1);
   1.260 +	
   1.261 +	//test that scheduleEntryInfo2 startTime is local time
   1.262 +	TEST(!entry2.iStartTime.IsUtc());
   1.263 +	
   1.264 +	//test intervalType
   1.265 +	TEST(entry2.iIntervalType == entry1.iIntervalType);
   1.266 +		
   1.267 +	//test interval
   1.268 +	TEST(entry2.iInterval == entry1.iInterval);
   1.269 +	
   1.270 +	//test validity period
   1.271 +	TEST(entry2.iValidityPeriod == entry1.iValidityPeriod);	
   1.272 +	}
   1.273 +
   1.274 +
   1.275 +/**
   1.276 +@file
   1.277 +@SYMTestCaseID				SYSLIB-SCHSVR-CT-0238
   1.278 +@SYMTestCaseDesc 			Check Exetrnalize and Internalize methods
   1.279 +@SYMTestPriority 			low
   1.280 +@SYMTestActions  			Creates an instance of 	TScheduleEntryInfo2 using the overloaded operator, externalizes it
   1.281 +							to a file and then internalizes into another instance of TScheduleEntryInfo2.
   1.282 +							Checks the externalized data is the same as the internalized one.
   1.283 +@SYMTestExpectedResults		The test must not fail.
   1.284 +@SYMPREQ					PREQ234
   1.285 +*/	
   1.286 +void TScheduleEntryInfo2_StateAccessor::TestExternalizeInternalizeL()
   1.287 +	{
   1.288 +	
   1.289 +	//	Test externalise 
   1.290 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0238 \n=== Test TScheduleEntryInfo2::ExternalizeL\n"));
   1.291 +	RFile file;
   1.292 +
   1.293 +	
   1.294 +	TFileName testFileName(fileName);
   1.295 +	TEST2(file.Replace(TheFsSession,testFileName,EFileWrite|EFileRead), KErrNone);
   1.296 +	RFileBuf buf;
   1.297 +	CleanupClosePushL(buf);
   1.298 +	buf.Attach(file);
   1.299 +	RWriteStream stream(&buf);
   1.300 +	
   1.301 +	TTsTime ttime(SchSvrHelpers::TimeBasedOnOffset(1), EFalse);
   1.302 +	TScheduleEntryInfo2 entry1(ttime, EHourly, 1, 20);
   1.303 +	stream << entry1; //externalize TScheduleEntryInfo2
   1.304 +	buf.SynchL();
   1.305 +	CleanupStack::PopAndDestroy(&buf);
   1.306 +
   1.307 +	
   1.308 +	//	Test internalise 
   1.309 +	TheTest.Next(_L("\n=== Test TScheduleEntryInfo2::InternalizeL\n"));
   1.310 +	TScheduleEntryInfo2 entry2;
   1.311 +	TInt err = file.Open(TheFsSession,testFileName,EFileRead);
   1.312 +	TEST2(err, KErrNone);
   1.313 +	RFileBuf buf2;
   1.314 +	CleanupClosePushL(buf2);
   1.315 +	buf2.Attach(file);
   1.316 +	RReadStream stream2(&buf2);
   1.317 +	
   1.318 +	stream2 >> entry2; //internalize TScheduleEntryInfo2
   1.319 +	
   1.320 +	//check iIntervalType
   1.321 +	TEST(entry1.iIntervalType == entry2.iIntervalType);
   1.322 +	
   1.323 +	//check iStartTime
   1.324 +	TEST(entry1.iStartTime.GetUtcTime() == entry2.iStartTime.GetUtcTime());
   1.325 +	
   1.326 +	//check iInterval
   1.327 +	TEST(entry1.iInterval == entry2.iInterval);
   1.328 +	
   1.329 +	//check iValidityPeriod
   1.330 +	TEST(entry1.iValidityPeriod == entry2.iValidityPeriod);
   1.331 +	
   1.332 +	CleanupStack::PopAndDestroy(&buf2);	
   1.333 +		
   1.334 +	}
   1.335 +
   1.336 +/**
   1.337 +@SYMTestCaseID          SYSLIB-SCHSVR-CT-3368
   1.338 +@SYMTestCaseDesc	    Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup.
   1.339 +@SYMTestPriority 	    High
   1.340 +@SYMTestActions  	    This test does not have any capability. It tries to create persistent  
   1.341 +						time/ conduction schedule, it fail to create schedule
   1.342 +						So return code will be KErrPermissionDenied
   1.343 +@SYMTestExpectedResults Test must not fail 
   1.344 +@SYMDEF                 PDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup.
   1.345 +*/
   1.346 +LOCAL_D void CreatePersistentScheduleCapabilityTest()
   1.347 +	{
   1.348 +	__UHEAP_MARK;
   1.349 +
   1.350 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3368 \nPDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup\n"));
   1.351 +	
   1.352 +	RScheduler	TheScheduler;
   1.353 +	TheTest(TheScheduler.Connect() == KErrNone);;
   1.354 +	
   1.355 +	//Create persistent  time based schedule 
   1.356 +	CArrayFixFlat<TScheduleEntryInfo2>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
   1.357 +	CleanupStack::PushL(entryList);
   1.358 +	TSchedulerItemRef ref;
   1.359 +	
   1.360 +	TTime ttime(SchSvrHelpers::TimeBasedOnOffset(0));
   1.361 +	TTsTime startTime1(ttime, EFalse); 
   1.362 + 
   1.363 +	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
   1.364 +	entryList->AppendL(entry1);
   1.365 +	
   1.366 +	// Create the time base schedule and check capability policing is working .
   1.367 +	TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrPermissionDenied);	
   1.368 +	
   1.369 +	CleanupStack::PopAndDestroy(entryList);	
   1.370 +	
   1.371 +	//Create persistent  Condition based schedule 
   1.372 +	CArrayFixFlat<TTaskSchedulerCondition>* conditionList = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);
   1.373 +	CleanupStack::PushL(conditionList);
   1.374 +	TSchedulerItemRef ref1;
   1.375 +	
   1.376 +	TTaskSchedulerCondition condition1;
   1.377 +	const TUid KTestUid = TUid::Uid(0x01234566);
   1.378 +	condition1.iCategory = KTestUid;
   1.379 +	condition1.iKey		= 10;
   1.380 +	condition1.iState	= 10;
   1.381 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.382 +	conditionList->AppendL(condition1);
   1.383 +	
   1.384 +	// Create the condition base schedule and check capability policing is working .
   1.385 +	TEST2(TheScheduler.CreatePersistentSchedule(ref1, *conditionList,startTime1),KErrPermissionDenied);	
   1.386 +
   1.387 +	CleanupStack::PopAndDestroy(conditionList);	
   1.388 +	TheScheduler.Close();
   1.389 +	
   1.390 +	__UHEAP_MARKEND;
   1.391 +	}
   1.392 +	
   1.393 +	
   1.394 +/**
   1.395 +Runs all the tests.
   1.396 +*/
   1.397 +static void RunTestsL()
   1.398 +	{
   1.399 +	TheTest.Start(_L("=== Start TScheduleEntryInfo2 tests \n"));
   1.400 +	
   1.401 +	CreatePersistentScheduleCapabilityTest();
   1.402 +	
   1.403 +	TScheduleEntryInfo2_StateAccessor* scheduleStateAccessor = new (ELeave) TScheduleEntryInfo2_StateAccessor;
   1.404 +	
   1.405 +	CleanupStack::PushL(scheduleStateAccessor);
   1.406 +	
   1.407 +	scheduleStateAccessor->TestDefaultConstructor();
   1.408 +	scheduleStateAccessor->TestCopyConstructorOverloadedConstructor();		
   1.409 +	
   1.410 +	//utility Get and Set methods
   1.411 +	scheduleStateAccessor->TestIntervalTypeSetIntervalType();
   1.412 +	scheduleStateAccessor->TestStartTimeSetStartTime();
   1.413 +	scheduleStateAccessor->TestIntervalSetInterval();
   1.414 +	scheduleStateAccessor->TestValidityPeriodSetValidityPeriod();
   1.415 +	scheduleStateAccessor->TestNonExportedConstructor();
   1.416 +	
   1.417 +	//utility externalize internalize
   1.418 +	scheduleStateAccessor->TestExternalizeInternalizeL();	
   1.419 +	CleanupStack::PopAndDestroy();
   1.420 +	}
   1.421 +
   1.422 +
   1.423 +
   1.424 +//***********************************************************************************
   1.425 +GLDEF_C TInt E32Main()
   1.426 + {
   1.427 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.428 +	TEST(tc != NULL);
   1.429 +	
   1.430 +	__UHEAP_MARK;
   1.431 +	
   1.432 +	fileName.Copy(KFileName);
   1.433 +	fileName[0] = RFs::GetSystemDriveChar();
   1.434 +
   1.435 +	TInt err = TheFsSession.Connect();
   1.436 +	TEST2(err, KErrNone);
   1.437 +
   1.438 +	TheTest.Title();
   1.439 +
   1.440 +	TRAP(err, ::RunTestsL())
   1.441 +	TEST2(err, KErrNone);
   1.442 +	
   1.443 +	(void)TheFsSession.Delete(fileName);
   1.444 +	TheFsSession.Close();
   1.445 +	TheTest.End();
   1.446 +	TheTest.Close();
   1.447 +
   1.448 +	__UHEAP_MARKEND;
   1.449 +	
   1.450 +	delete tc;
   1.451 +	
   1.452 +	return(KErrNone);
   1.453 +	
   1.454 +	}
   1.455 +
   1.456 +	
   1.457 +