os/ossrv/genericservices/taskscheduler/Test/TSCheduleState2/TU_TSCH_ScheduleState2.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSCheduleState2/TU_TSCH_ScheduleState2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,307 @@
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 +// This file contains the implementation of test classe for TScheduleState2.
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <f32file.h>
1.23 +
1.24 +#include "SCHINFO.H"
1.25 +#include <schinfointernal.h>
1.26 +
1.27 +_LIT(KTestName, "TScheduleState2 Tests");
1.28 +RTest TheTest(KTestName);
1.29 +
1.30 +//
1.31 +//
1.32 +//Test macroses and functions
1.33 +
1.34 +static void Check(TInt aValue, TInt aLine)
1.35 + {
1.36 + if(!aValue)
1.37 + {
1.38 + TheTest(EFalse, aLine);
1.39 + }
1.40 + }
1.41 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
1.42 + {
1.43 + if(aValue != aExpected)
1.44 + {
1.45 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.46 + TheTest(EFalse, aLine);
1.47 + }
1.48 + }
1.49 +#define TEST(arg) ::Check((arg), __LINE__)
1.50 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.51 +
1.52 +
1.53 +
1.54 +/**
1.55 +State accessor for the TScheduleState2 object under test.
1.56 +*/
1.57 +class TScheduleState2_StateAccessor
1.58 + {
1.59 +public :
1.60 + void TestDefaultConstructor();
1.61 + void TestCopyConstructorOverloadedConstructor();
1.62 + void TestNameSetName();
1.63 + void TestDueTimeSetDueTime();
1.64 + void TestPersistsSetPersists();
1.65 + void TestEnabledSetEnabled();
1.66 + void TestOperatorEqual();
1.67 + };
1.68 +
1.69 +
1.70 +
1.71 +
1.72 +/**
1.73 +@file
1.74 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0224
1.75 +@SYMTestCaseDesc Check the default constructor works properly
1.76 +@SYMTestPriority low
1.77 +@SYMTestActions Creates an instance of TScheduleState2 and check its data has been
1.78 + set to default values.
1.79 +@SYMTestExpectedResults The test must not fail.
1.80 +@SYMPREQ PREQ234
1.81 +*/
1.82 +void TScheduleState2_StateAccessor::TestDefaultConstructor()
1.83 + {
1.84 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0224 "));
1.85 + TScheduleState2 state;
1.86 +
1.87 + //name should be ""
1.88 + TEST(state.iName == _L(""));
1.89 +
1.90 + //iDueTime UTC, O
1.91 + TEST(state.iDueTime.GetUtcTime() == TTime(0));
1.92 +
1.93 + //iFlags should be 0
1.94 + TEST(state.iFlags == 0);
1.95 +
1.96 + //iReserved 0
1.97 + TEST(state.iReserved == 0);
1.98 + }
1.99 +
1.100 +
1.101 +
1.102 +/**
1.103 +@file
1.104 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0225
1.105 +@SYMTestCaseDesc Checks the copy constructor and the overloaded constructor
1.106 +@SYMTestPriority low
1.107 +@SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor
1.108 + and another instance of TScheduleState2 using the copy constructor, then compares
1.109 + their data and makes sure they are equal.
1.110 +@SYMTestExpectedResults The test must not fail.
1.111 +@SYMPREQ PREQ234
1.112 +*/
1.113 +void TScheduleState2_StateAccessor::TestCopyConstructorOverloadedConstructor()
1.114 + {
1.115 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0225 Test constructors "));
1.116 + const TName name(_L("test_state"));
1.117 + TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
1.118 + TTime time(date);
1.119 + TTsTime dueTime(time, EFalse); //TTsTime is Home time
1.120 +
1.121 + TScheduleState2 state1(name, dueTime, ETrue, ETrue);
1.122 + TScheduleState2 state2(state1);
1.123 +
1.124 + TEST(state1.iName == state2.iName);
1.125 + TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime());
1.126 + TEST(state1.iFlags == state2.iFlags);
1.127 + TEST(state1.iReserved == state2.iReserved);
1.128 +
1.129 + }
1.130 +
1.131 +
1.132 +
1.133 +/**
1.134 +@file
1.135 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0226
1.136 +@SYMTestCaseDesc Checks SetName() and Name() functions of TScheduleState2
1.137 +@SYMTestPriority low
1.138 +@SYMTestActions Creates an instance of TScheduleState2, calls SetName() and Name()
1.139 + and Name() returns the same value as the one set initially.
1.140 +@SYMTestExpectedResults The test must not fail.
1.141 +@SYMPREQ PREQ234
1.142 +*/
1.143 +void TScheduleState2_StateAccessor::TestNameSetName()
1.144 + {
1.145 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0226 "));
1.146 + TScheduleState2 state;
1.147 + const TName name(_L("name"));
1.148 + state.SetName(name);
1.149 +
1.150 + TEST(state.Name() == name);
1.151 +
1.152 + }
1.153 +
1.154 +/**
1.155 +@file
1.156 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0227
1.157 +@SYMTestCaseDesc Checks SetDueTime() and DueTime()
1.158 +@SYMTestPriority low
1.159 +@SYMTestActions Creates an instance of TScheduleState2, sets its due time and checks
1.160 + the returned time is equel to one set initially.
1.161 +@SYMTestExpectedResults The test must not fail.
1.162 +@SYMPREQ PREQ234
1.163 +*/
1.164 +void TScheduleState2_StateAccessor::TestDueTimeSetDueTime()
1.165 + {
1.166 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0227 Test set and get due time APIs "));
1.167 +
1.168 + TScheduleState2 state;
1.169 +
1.170 + TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
1.171 + TTime time(date);
1.172 + TTsTime dueTime(time, EFalse); //TTsTime is Home time
1.173 +
1.174 + state.SetDueTime(dueTime);
1.175 + TEST(time == state.DueTime().GetLocalTime());
1.176 + }
1.177 +
1.178 +
1.179 +
1.180 +/**
1.181 +@file
1.182 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0228
1.183 +@SYMTestCaseDesc Checks SetPersists() and Persists() functions
1.184 +@SYMTestPriority low
1.185 +@SYMTestActions Creates an instance of TScheduleState2, calls SetPersists then Persists
1.186 + and checks the returned value is equal to the one set initially.
1.187 +@SYMTestExpectedResults The test must not fail.
1.188 +@SYMPREQ PREQ234
1.189 +*/
1.190 +void TScheduleState2_StateAccessor::TestPersistsSetPersists()
1.191 + {
1.192 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0228 "));
1.193 + TScheduleState2 state;
1.194 +
1.195 + //set Persists to Etrue
1.196 + state.SetPersists(ETrue);
1.197 + TEST(state.Persists());
1.198 +
1.199 + //set Persists to EFalse
1.200 + state.SetPersists(EFalse);
1.201 + TEST(!state.Persists());
1.202 + }
1.203 +
1.204 +
1.205 +
1.206 +/**
1.207 +@file
1.208 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0229
1.209 +@SYMTestCaseDesc Checks Enabled() and SetEnabled() functions
1.210 +@SYMTestPriority low
1.211 +@SYMTestActions Creates an instance TScheduleState2, calls SetEnabled() then Enabled()
1.212 + and checks the returned value is equal to the one set initially.
1.213 +@SYMTestExpectedResults The test must not fail.
1.214 +@SYMPREQ PREQ234
1.215 +*/
1.216 +void TScheduleState2_StateAccessor::TestEnabledSetEnabled()
1.217 + {
1.218 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0229 "));
1.219 + TScheduleState2 state;
1.220 +
1.221 + //ETrue
1.222 + state.SetEnabled(ETrue);
1.223 + TEST(state.Enabled());
1.224 +
1.225 + //EFlase
1.226 + state.SetEnabled(EFalse);
1.227 + TEST(!state.Enabled());
1.228 +
1.229 + }
1.230 +
1.231 +
1.232 +
1.233 +/**
1.234 +@file
1.235 +@SYMTestCaseID SYSLIB-SCHSVR-CT-0230
1.236 +@SYMTestCaseDesc Check the operator = works properly
1.237 +@SYMTestPriority low
1.238 +@SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor,
1.239 + then creates another instance of TScheduleState2 and assigns it the first instance
1.240 + of TScheduleState2. The tests make sure both instances are equal.
1.241 +@SYMTestExpectedResults The test must not fail.
1.242 +@SYMPREQ PREQ234
1.243 +*/
1.244 +void TScheduleState2_StateAccessor::TestOperatorEqual()
1.245 + {
1.246 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0230 Test overloaded equals operator "));
1.247 +
1.248 + const TName name(_L("name"));
1.249 + //set the current utc time to 8.55am, 15 May 2005 -Daylight savings apply on this date
1.250 + TDateTime date(2005, EMay, 15, 8, 55, 0, 0);
1.251 + TTime time(date);
1.252 + TTsTime dueTime(time, EFalse); //TTsTime is Home time
1.253 +
1.254 + TScheduleState2 state1(name, dueTime, ETrue, ETrue);
1.255 + TScheduleState2 state2 = state1;
1.256 +
1.257 + TEST(state1.iName == state2.iName);
1.258 + TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime() );
1.259 + TEST(state1.iFlags == state2.iFlags);
1.260 + TEST(state1.iReserved == state2.iReserved);
1.261 + }
1.262 +
1.263 +
1.264 +/**
1.265 +Runs all the tests.
1.266 +*/
1.267 +static void RunTestsL()
1.268 + {
1.269 + TheTest.Start(_L("=== Start TScheduleState2 tests \n"));
1.270 + TScheduleState2_StateAccessor* entry = new (ELeave) TScheduleState2_StateAccessor;
1.271 + CleanupStack::PushL(entry);
1.272 + entry->TestDefaultConstructor();
1.273 + entry->TestCopyConstructorOverloadedConstructor();
1.274 + entry->TestNameSetName();
1.275 + entry->TestDueTimeSetDueTime();
1.276 + entry->TestPersistsSetPersists();
1.277 + entry->TestEnabledSetEnabled();
1.278 + entry->TestOperatorEqual();
1.279 + CleanupStack::PopAndDestroy();
1.280 + }
1.281 +
1.282 +
1.283 +
1.284 +//***********************************************************************************
1.285 +GLDEF_C TInt E32Main()
1.286 + {
1.287 + CTrapCleanup* tc = CTrapCleanup::New();
1.288 + TEST(tc != NULL);
1.289 +
1.290 + __UHEAP_MARK;
1.291 +
1.292 + TInt err;
1.293 + TheTest.Title();
1.294 +
1.295 + TRAP(err, ::RunTestsL())
1.296 + TEST2(err, KErrNone);
1.297 +
1.298 + TheTest.End();
1.299 + TheTest.Close();
1.300 +
1.301 + __UHEAP_MARKEND;
1.302 +
1.303 + delete tc;
1.304 +
1.305 + return(KErrNone);
1.306 +
1.307 + }
1.308 +
1.309 +
1.310 +