13 #include <cxxtest/TestSuite.h>
42 TS_ASSERT_DIFFERS( thisTimestamp.
asDouble(), 0.0 );
43 TS_ASSERT_DIFFERS( thisTimestamp,
Timestamp( 0.0 ) );
48 Timestamp thisTimestamp(
"1970-01-01T00:00:00.000000Z" );
50 TS_ASSERT_EQUALS( thisTimestamp.
asDouble(), 0 );
52 thisTimestamp =
"1970-01-01T00:00:00.015625Z";
53 TS_ASSERT_EQUALS( thisTimestamp.asDouble(), 0.015625 );
55 thisTimestamp =
"2009-02-13T23:31:30Z";
56 TS_ASSERT_EQUALS( thisTimestamp.asDouble(), 1234567890.0 );
58 thisTimestamp =
"02/13/2009 23:31:30";
59 TS_ASSERT_EQUALS( thisTimestamp.asDouble(), 1234567890.0 );
68 TS_ASSERT_EQUALS( thisTimestamp.
asDouble(), param );
69 TS_ASSERT_EQUALS( thisTimestamp,
Timestamp( param ) );
77 Timestamp timestampOne( 100.0 ), timestampTwo( timestampOne );
79 TS_ASSERT_EQUALS( timestampOne.asDouble(), timestampTwo.
asDouble() );
80 TS_ASSERT_EQUALS( timestampOne, timestampTwo );
91 Timestamp timestampOne( 100.0 ), timestampTwo( 1234567890.0 );
93 TS_ASSERT_DIFFERS( timestampOne, timestampTwo );
94 timestampOne = timestampTwo;
95 TS_ASSERT_EQUALS( timestampOne, timestampTwo );
108 double A = 123456.0, B = 2042322342.0;
112 TS_ASSERT_DIFFERS( timestampOne.
asDouble(), B );
113 TS_ASSERT_DIFFERS( timestampOne,
Timestamp( B ) );
115 TS_ASSERT_EQUALS( timestampOne.
asDouble(), B );
116 TS_ASSERT_EQUALS( timestampOne,
Timestamp( B ) );
121 Timestamp timestampOne( 2042322342.0 ), timestampTwo( 1.0 );
123 TS_ASSERT_DIFFERS( timestampOne, timestampTwo );
124 timestampOne = timestampTwo.
asDouble();
125 TS_ASSERT_EQUALS( timestampOne, timestampTwo );
134 double A = 12345.6, B = 92245.0;
138 timestampOne += timespanTwo;
150 double A = 12345.6, B = 92245.0;
154 timestampOne -= timespanTwo;
171 double A = 244332234.224325234;
172 double B = 1433453234.2342223;
174 Timestamp timestampA( A ), timestampB( B );
175 Timespan timespanA( A ), timespanB( B );
190 double B = 1033453234.2342223,
191 A = 2044332234.224325234;
192 Timestamp timestampA( A ), timestampB( B );
197 TS_ASSERT( timestampA > timestampB );
198 TS_ASSERT( !( timestampA < timestampB ) );
199 TS_ASSERT( timestampA >= timestampB );
200 TS_ASSERT( !( timestampA <= timestampB ) );
202 timestampB = timestampA;
203 TS_ASSERT( timestampA >= timestampB );
204 TS_ASSERT( timestampB >= timestampA );
213 const Timespan ACCEPTABLE_ERROR_SECONDS( 0.01 );
217 timestampNow += sleepTimestamp;
223 TS_ASSERT_DELTA( timestampAfter, timestampNow, ACCEPTABLE_ERROR_SECONDS );
228 const Timespan ACCEPTABLE_ERROR_SECONDS( 0.1 );
234 TS_ASSERT_DELTA( timestampNow, timestampNowToo, ACCEPTABLE_ERROR_SECONDS );
240 Timestamp timestampOne( 0.0 ), timestampTwo( 3661.001 );
253 Timestamp timestampNow, timestampBefore, timestampAfter;
255 struct tm * timeinfo;
258 TS_ASSERT( timestampNow > 0.0 );
260 rawtime = timestampNow.
asTimeT();
261 timeinfo = gmtime( &rawtime );
264 timestampNow.
toString( bufferNow, 79 );
267 strftime( buffer, 80,
"%Y-%m-%dT%H:%M:%S", timeinfo );
269 TS_ASSERT_SAME_DATA( bufferNow, buffer, 19 );
298 double param = 100.0;
301 TS_ASSERT_EQUALS( thisTimespan.
asDouble(), param );
302 TS_ASSERT_EQUALS( thisTimespan,
Timespan( param ) );
310 Timespan timespanOne( 100.0 ), timespanTwo( timespanOne );
312 TS_ASSERT_EQUALS( timespanOne.asDouble(), timespanTwo.
asDouble() );
313 TS_ASSERT_EQUALS( timespanOne, timespanTwo );
324 Timestamp timespanOne( 100.0 ), timespanTwo( 1234567890.0 );
326 TS_ASSERT_DIFFERS( timespanOne, timespanTwo );
327 TS_ASSERT_DIFFERS( timespanOne.asDouble(), timespanTwo.
asDouble() );
328 timespanOne = timespanTwo;
329 TS_ASSERT_EQUALS( timespanOne, timespanTwo );
330 TS_ASSERT_EQUALS( timespanOne.asDouble(), timespanTwo.
asDouble() );
343 double A = 123456.0, B = 2042322342.0;
347 TS_ASSERT_DIFFERS( timespanOne.
asDouble(), B );
349 TS_ASSERT_EQUALS( timespanOne.asDouble(), B );
354 Timestamp timespanOne( 2042322342.0 ), timespanTwo( 1.0 );
356 TS_ASSERT_DIFFERS( timespanOne, timespanTwo );
357 timespanOne = timespanTwo.
asDouble();
358 TS_ASSERT_EQUALS( timespanOne, timespanTwo );
373 Timespan timespanA( A ), timespanB( B );
390 Timespan timespanA( A ), timespanB( B );
395 TS_ASSERT( timespanA > timespanB );
396 TS_ASSERT( !( timespanA < timespanB ) );
397 TS_ASSERT( timespanA >= timespanB );
398 TS_ASSERT( !( timespanA <= timespanB ) );
400 timespanB = timespanA;
401 TS_ASSERT( timespanA >= timespanB );
402 TS_ASSERT( timespanB >= timespanA );
411 const Timespan ACCEPTABLE_ERROR_SECONDS( 0.025 );
412 Timestamp timestampBefore, timestampAfter;
419 sleptFor = timestampAfter - timestampBefore;
421 TS_ASSERT_DELTA( sleepTimestamp, sleptFor, ACCEPTABLE_ERROR_SECONDS );
432 TS_ASSERT( strstr( buffer,
"1234.5678" ) );
static const Timespan ZERO_TIMESPAN
Constant value to represent instant of time.
Definition: Timestamp.h:255
void testSetOperatorOne(void)
Set operator.
Definition: Timestamp_Test.h:106
const double DOUBLE_FUDGE
Definition: Timestamp_Test.h:17
time_t asTimeT() const
Definition: Timestamp.h:97
void testCopyOperator(void)
Copy operator.
Definition: Timestamp_Test.h:322
void testSleepNow(void)
Test the sleepTill function.
Definition: Timestamp_Test.h:210
void testAdditionAndSubtraction(void)
Standard addition/subtraction functions.
Definition: Timestamp_Test.h:368
virtual double asDouble() const
Accessor, convert to double.
Definition: Timestamp.cpp:826
void testInPlaceAdditionToTimespan(void)
In-place addition operator to timespan Tests:Create to timestamp objects with params A timespan B...
Definition: Timestamp_Test.h:132
void testToString(void)
Definition: Timestamp_Test.h:251
void testInquality(void)
Inequality operator.
Definition: Timestamp_Test.h:385
Timespan class, represents a delta of time.
Definition: Timestamp.h:248
void testSetOperatorOne(void)
Set operator.
Definition: Timestamp_Test.h:341
const char * toString(char *buf, int buflen, int precision=3) const
Writes the Timestamp as to a unsigned char buffer.
Definition: Timestamp.cpp:418
static Timespan Minutes(int min)
Static allows creation of Timespans denominated in minutes.
Definition: Timestamp.h:313
void testSetOperatorTwo(void)
Definition: Timestamp_Test.h:352
Unit Tests for class Timestamp.
Definition: Timestamp_Test.h:25
void testNow(void)
Definition: Timestamp_Test.h:226
void testAdditionAndSubtraction(void)
Standard addition/subtraction functions.
Definition: Timestamp_Test.h:169
void testConstructorDoubleArg(void)
Tests:Create a new object with double param, Expect asDouble() == param.
Definition: Timestamp_Test.h:296
void testConstructorNoArguments(void)
Tests:Create a new object w/o params.
Definition: Timestamp_Test.h:33
void testWholeUnits(void)
Test whole units.
Definition: Timestamp_Test.h:238
static const Timestamp NOT_SET_TIME
Constant value to represent "no time".
Definition: Timestamp.h:37
void sleepFor(void) const
Sleep for the timespan.
Definition: Timestamp.cpp:951
const Timespan TIMESPAN_FUDGE(DOUBLE_FUDGE)
static Timestamp Now()
Static for current time for use on RHS.
Definition: Timestamp.cpp:362
void testConstructorDoubleArg(void)
Definition: Timestamp_Test.h:63
void testConstructorCopyArg(void)
Constructor with copy param testsCreate new object copied from another object.
Definition: Timestamp_Test.h:308
void testConstructorStringArg(void)
Definition: Timestamp_Test.h:46
static Timespan Seconds(double sec)
Static allows creation of Timespans denominated in seconds (as a float) This function originally took...
Definition: Timestamp.h:307
void testConstructorCopyArg(void)
Constructor with copy param testsCreate new object copied from another object.
Definition: Timestamp_Test.h:75
void sleepTill()
Sleep until the given time.
Definition: Timestamp.cpp:386
void testToString(void)
Definition: Timestamp_Test.h:425
const char * toString(char *buf, int buflen, int precision=3) const
Writes the Timespan to a unsigned char buffer.
Definition: Timestamp.cpp:963
Unit Tests for class Timespan.
Definition: Timestamp_Test.h:279
virtual double asDouble() const
Accessor, convert to double.
Definition: Timestamp.cpp:127
void testInquality(void)
Inequality operator.
Definition: Timestamp_Test.h:188
void testSleepFor(void)
Test the sleepFor function.
Definition: Timestamp_Test.h:408
void testConstructorNoArguments(void)
Tests:Create a new object w/o params.
Definition: Timestamp_Test.h:285
void testInPlaceSubtractionByTimespan(void)
In-place subtraction operator to timespan Tests:Create to timestamp objects with params A timespan B...
Definition: Timestamp_Test.h:148
void testCopyOperator(void)
Copy operator.
Definition: Timestamp_Test.h:89
Contains the Timestamp and Timespan class declarations.
static Timespan Hours(int hour)
Static allows creation of Timespans denominated in hours.
Definition: Timestamp.h:319
Represents absolute times.
Definition: Timestamp.h:31
void testSetOperatorTwo(void)
Definition: Timestamp_Test.h:119
static Timespan Milliseconds(float msec)
Static allows creation of Timespans denominated in milliseconds.
Definition: Timestamp.h:298