os/ossrv/genericservices/taskscheduler/Test/TSCheduleEntryInfo2/TU_TSCH_ScheduleEntryInfo2.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 // T_ScheduleEntryInfo2.cpp
    15 // This file contains the implementation of test classe for TScheduleEntryInfo2. 
    16 // 
    17 //
    18 
    19 #include <e32test.h>
    20 #include <f32file.h>
    21 #include <s32file.h>
    22 #include <schinfointernal.h>
    23 #include "Thelpers.h"
    24 
    25 #include "SCHINFO.H"
    26 
    27 _LIT(KTestName,	"TScheduleEntryInfo2 Tests");
    28 RTest	TheTest(KTestName);
    29 
    30 static RFs			TheFsSession;
    31 _LIT(KFileName,"_:\\tscheduleinfo2.dat"); 
    32 static TBuf<32> fileName;
    33  
    34 //
    35 //
    36 //Test macroses and functions
    37 
    38 static void Check(TInt aValue, TInt aLine)
    39 	{
    40 	if(!aValue)
    41 		{
    42 		(void)TheFsSession.Delete(fileName);
    43 		TheTest(EFalse, aLine);
    44 		}
    45 	}
    46 static  void Check(TInt aValue, TInt aExpected, TInt aLine)
    47 	{
    48 	if(aValue != aExpected)
    49 		{
    50 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    51 		(void)TheFsSession.Delete(fileName);
    52 		TheTest(EFalse, aLine);
    53 		}
    54 	}
    55 #define TEST(arg) ::Check((arg), __LINE__)
    56 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) 
    57 
    58 
    59 /**
    60 State accessor for the TScheduleEntryInfo2 object under test.
    61 */
    62 class TScheduleEntryInfo2_StateAccessor
    63 	{
    64 
    65 public:
    66 	void TestDefaultConstructor();
    67 	void TestCopyConstructorOverloadedConstructor();	
    68 		
    69 	//utility Get and Set methods
    70 	void TestIntervalTypeSetIntervalType();
    71 	void TestStartTimeSetStartTime();
    72 	void TestIntervalSetInterval();
    73 	void TestValidityPeriodSetValidityPeriod();
    74 	void TestNonExportedConstructor();
    75 	void TestExternalizeInternalizeL();
    76 	};
    77 
    78 
    79 
    80 /**
    81 @file
    82 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0231
    83 @SYMTestCaseDesc 			Check the default constructor
    84 @SYMTestPriority 			low
    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.
    88 @SYMPREQ					PREQ234
    89 */	
    90 void TScheduleEntryInfo2_StateAccessor::TestDefaultConstructor()
    91 	{
    92 	//Default constructor called
    93 	//Sets Start Time to 0 UTC time
    94 	//the interval type to 0,
    95 	//the interval to 0,
    96 	//the validityPeriod to 0
    97 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0231 Test default constructor "));
    98 	TScheduleEntryInfo2 entry;
    99 	
   100 	TEST(entry.iIntervalType==0);
   101 	TEST(entry.iStartTime.GetUtcTime() == TTime(0));
   102 	TEST(entry.iInterval == 0);
   103 	TEST(entry.iValidityPeriod == TTimeIntervalMinutes(0));	
   104 	}
   105 
   106 
   107 /**
   108 @file
   109 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0232
   110 @SYMTestCaseDesc 			Check the copy constructor and the overloaded constructor
   111 @SYMTestPriority 			low
   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.
   116 @SYMPREQ					PREQ234
   117 */		
   118 void TScheduleEntryInfo2_StateAccessor::TestCopyConstructorOverloadedConstructor()
   119 	{
   120 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0232 Text contructors "));	
   121 
   122 	TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
   123 	TTime time(date);
   124 	TTsTime startTime(time, EFalse);
   125 	TIntervalType intervalType(EHourly);
   126 	TInt interval(1);
   127 	TTimeIntervalMinutes validityPeriod(60);
   128 	
   129 	TScheduleEntryInfo2 entry1(startTime, intervalType, interval, validityPeriod);
   130 	
   131 	TScheduleEntryInfo2 entry2(entry1);	
   132 	
   133 	//Test entry1 == entry2
   134 	TEST(entry1.StartTime().GetLocalTime() == entry2.StartTime().GetLocalTime());
   135 	TEST(entry1.ValidityPeriod() == entry2.ValidityPeriod());
   136 	TEST(entry1.Interval() == entry2.Interval());
   137 	
   138 	}
   139 	
   140 	 
   141 /**
   142 @file
   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.
   149 @SYMPREQ					PREQ234
   150 */	
   151 void TScheduleEntryInfo2_StateAccessor::TestIntervalTypeSetIntervalType()
   152 	{
   153 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0233 Test set and get for Interval Type "));
   154 
   155 	TScheduleEntryInfo2 scheduleEntryInfo;
   156 	
   157 	scheduleEntryInfo.SetIntervalType(TIntervalType(EHourly));
   158 	TIntervalType intervalType = scheduleEntryInfo.IntervalType();
   159 	TEST(intervalType == EHourly);	
   160 	}
   161 
   162 	
   163 /**
   164 @file
   165 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0234
   166 @SYMTestCaseDesc 			Check SetStartTime() and StartTime()
   167 @SYMTestPriority 			low
   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.
   172 @SYMPREQ					PREQ234
   173 */		
   174 void TScheduleEntryInfo2_StateAccessor::TestStartTimeSetStartTime()
   175 	{
   176 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0234 Test start time set and get methods "));
   177 	
   178 	TScheduleEntryInfo2 scheduleEntryInfo;
   179 	
   180 	TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
   181 	TTime time(date);
   182 	TTsTime startTime(time, EFalse);
   183 	
   184 	scheduleEntryInfo.SetStartTime(startTime);
   185 	
   186 	TEST(scheduleEntryInfo.StartTime().GetLocalTime() == startTime.GetLocalTime());
   187 	}
   188 
   189 
   190 /**
   191 @file
   192 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0235
   193 @SYMTestCaseDesc 			Check SetInterval() and Intervale() 
   194 @SYMTestPriority 			low
   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.
   199 @SYMPREQ					PREQ234
   200 */		
   201 void TScheduleEntryInfo2_StateAccessor::TestIntervalSetInterval()
   202 	{
   203 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0235 Test set and get for Interval "));
   204 	
   205 	TScheduleEntryInfo2 scheduleEntryInfo;
   206 	scheduleEntryInfo.SetInterval(1);
   207 	TEST(scheduleEntryInfo.Interval() == TInt(1));
   208 	}
   209 	
   210 /**
   211 @file
   212 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0236
   213 @SYMTestCaseDesc 			Check SetValidityPeriod() and ValidityPeriod()
   214 @SYMTestPriority 			low
   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.
   219 @SYMPREQ					PREQ234
   220 */	
   221 void TScheduleEntryInfo2_StateAccessor::TestValidityPeriodSetValidityPeriod()
   222 	{
   223 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0236 Set and get for validity period  "));
   224 	TScheduleEntryInfo2 scheduleEntryInfo;
   225 	
   226 	scheduleEntryInfo.SetValidityPeriod(60);
   227 	TTimeIntervalMinutes retValidityPeriod = scheduleEntryInfo.ValidityPeriod();
   228 	
   229 	TEST(retValidityPeriod == TTimeIntervalMinutes(60));
   230 	
   231 	}
   232 	
   233 /**
   234 @file
   235 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0237
   236 @SYMTestCaseDesc 			Check non exported constructor provided for use with the deprecated APIs
   237 @SYMTestPriority 			low
   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.
   241 
   242 @SYMTestExpectedResults		The test must not fail.
   243 @SYMPREQ					PREQ234
   244 */	
   245 void TScheduleEntryInfo2_StateAccessor::TestNonExportedConstructor()
   246 	{
   247 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0237 Test non exported constructor "));
   248 	
   249 	TScheduleEntryInfo entry1;
   250 	entry1.iIntervalType	= EHourly;
   251 	entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(1); 
   252 	
   253 	entry1.iInterval		= 1;
   254 	entry1.iValidityPeriod	= 20;
   255 	
   256 	TScheduleEntryInfo2 entry2(entry1);
   257 	
   258 	//test that scheduleEntryInfo2 startTime is local time
   259 	TEST(!entry2.iStartTime.IsUtc());
   260 	
   261 	//test intervalType
   262 	TEST(entry2.iIntervalType == entry1.iIntervalType);
   263 		
   264 	//test interval
   265 	TEST(entry2.iInterval == entry1.iInterval);
   266 	
   267 	//test validity period
   268 	TEST(entry2.iValidityPeriod == entry1.iValidityPeriod);	
   269 	}
   270 
   271 
   272 /**
   273 @file
   274 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0238
   275 @SYMTestCaseDesc 			Check Exetrnalize and Internalize methods
   276 @SYMTestPriority 			low
   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.
   281 @SYMPREQ					PREQ234
   282 */	
   283 void TScheduleEntryInfo2_StateAccessor::TestExternalizeInternalizeL()
   284 	{
   285 	
   286 	//	Test externalise 
   287 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0238 \n=== Test TScheduleEntryInfo2::ExternalizeL\n"));
   288 	RFile file;
   289 
   290 	
   291 	TFileName testFileName(fileName);
   292 	TEST2(file.Replace(TheFsSession,testFileName,EFileWrite|EFileRead), KErrNone);
   293 	RFileBuf buf;
   294 	CleanupClosePushL(buf);
   295 	buf.Attach(file);
   296 	RWriteStream stream(&buf);
   297 	
   298 	TTsTime ttime(SchSvrHelpers::TimeBasedOnOffset(1), EFalse);
   299 	TScheduleEntryInfo2 entry1(ttime, EHourly, 1, 20);
   300 	stream << entry1; //externalize TScheduleEntryInfo2
   301 	buf.SynchL();
   302 	CleanupStack::PopAndDestroy(&buf);
   303 
   304 	
   305 	//	Test internalise 
   306 	TheTest.Next(_L("\n=== Test TScheduleEntryInfo2::InternalizeL\n"));
   307 	TScheduleEntryInfo2 entry2;
   308 	TInt err = file.Open(TheFsSession,testFileName,EFileRead);
   309 	TEST2(err, KErrNone);
   310 	RFileBuf buf2;
   311 	CleanupClosePushL(buf2);
   312 	buf2.Attach(file);
   313 	RReadStream stream2(&buf2);
   314 	
   315 	stream2 >> entry2; //internalize TScheduleEntryInfo2
   316 	
   317 	//check iIntervalType
   318 	TEST(entry1.iIntervalType == entry2.iIntervalType);
   319 	
   320 	//check iStartTime
   321 	TEST(entry1.iStartTime.GetUtcTime() == entry2.iStartTime.GetUtcTime());
   322 	
   323 	//check iInterval
   324 	TEST(entry1.iInterval == entry2.iInterval);
   325 	
   326 	//check iValidityPeriod
   327 	TEST(entry1.iValidityPeriod == entry2.iValidityPeriod);
   328 	
   329 	CleanupStack::PopAndDestroy(&buf2);	
   330 		
   331 	}
   332 
   333 /**
   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.
   342 */
   343 LOCAL_D void CreatePersistentScheduleCapabilityTest()
   344 	{
   345 	__UHEAP_MARK;
   346 
   347 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3368 \nPDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup\n"));
   348 	
   349 	RScheduler	TheScheduler;
   350 	TheTest(TheScheduler.Connect() == KErrNone);;
   351 	
   352 	//Create persistent  time based schedule 
   353 	CArrayFixFlat<TScheduleEntryInfo2>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
   354 	CleanupStack::PushL(entryList);
   355 	TSchedulerItemRef ref;
   356 	
   357 	TTime ttime(SchSvrHelpers::TimeBasedOnOffset(0));
   358 	TTsTime startTime1(ttime, EFalse); 
   359  
   360 	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
   361 	entryList->AppendL(entry1);
   362 	
   363 	// Create the time base schedule and check capability policing is working .
   364 	TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrPermissionDenied);	
   365 	
   366 	CleanupStack::PopAndDestroy(entryList);	
   367 	
   368 	//Create persistent  Condition based schedule 
   369 	CArrayFixFlat<TTaskSchedulerCondition>* conditionList = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);
   370 	CleanupStack::PushL(conditionList);
   371 	TSchedulerItemRef ref1;
   372 	
   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);
   380 	
   381 	// Create the condition base schedule and check capability policing is working .
   382 	TEST2(TheScheduler.CreatePersistentSchedule(ref1, *conditionList,startTime1),KErrPermissionDenied);	
   383 
   384 	CleanupStack::PopAndDestroy(conditionList);	
   385 	TheScheduler.Close();
   386 	
   387 	__UHEAP_MARKEND;
   388 	}
   389 	
   390 	
   391 /**
   392 Runs all the tests.
   393 */
   394 static void RunTestsL()
   395 	{
   396 	TheTest.Start(_L("=== Start TScheduleEntryInfo2 tests \n"));
   397 	
   398 	CreatePersistentScheduleCapabilityTest();
   399 	
   400 	TScheduleEntryInfo2_StateAccessor* scheduleStateAccessor = new (ELeave) TScheduleEntryInfo2_StateAccessor;
   401 	
   402 	CleanupStack::PushL(scheduleStateAccessor);
   403 	
   404 	scheduleStateAccessor->TestDefaultConstructor();
   405 	scheduleStateAccessor->TestCopyConstructorOverloadedConstructor();		
   406 	
   407 	//utility Get and Set methods
   408 	scheduleStateAccessor->TestIntervalTypeSetIntervalType();
   409 	scheduleStateAccessor->TestStartTimeSetStartTime();
   410 	scheduleStateAccessor->TestIntervalSetInterval();
   411 	scheduleStateAccessor->TestValidityPeriodSetValidityPeriod();
   412 	scheduleStateAccessor->TestNonExportedConstructor();
   413 	
   414 	//utility externalize internalize
   415 	scheduleStateAccessor->TestExternalizeInternalizeL();	
   416 	CleanupStack::PopAndDestroy();
   417 	}
   418 
   419 
   420 
   421 //***********************************************************************************
   422 GLDEF_C TInt E32Main()
   423  {
   424 	CTrapCleanup* tc = CTrapCleanup::New();
   425 	TEST(tc != NULL);
   426 	
   427 	__UHEAP_MARK;
   428 	
   429 	fileName.Copy(KFileName);
   430 	fileName[0] = RFs::GetSystemDriveChar();
   431 
   432 	TInt err = TheFsSession.Connect();
   433 	TEST2(err, KErrNone);
   434 
   435 	TheTest.Title();
   436 
   437 	TRAP(err, ::RunTestsL())
   438 	TEST2(err, KErrNone);
   439 	
   440 	(void)TheFsSession.Delete(fileName);
   441 	TheFsSession.Close();
   442 	TheTest.End();
   443 	TheTest.Close();
   444 
   445 	__UHEAP_MARKEND;
   446 	
   447 	delete tc;
   448 	
   449 	return(KErrNone);
   450 	
   451 	}
   452 
   453 	
   454