51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "RuntimeClock.h"
|
|
|
|
#include <cmath>
|
|
#include <iostream>
|
|
|
|
namespace
|
|
{
|
|
int gFailures = 0;
|
|
|
|
void Expect(bool condition, const char* message)
|
|
{
|
|
if (condition)
|
|
return;
|
|
|
|
std::cerr << "FAIL: " << message << "\n";
|
|
++gFailures;
|
|
}
|
|
|
|
void TestUtcSecondsOfDay()
|
|
{
|
|
const RuntimeClockSnapshot midnight = MakeRuntimeClockSnapshot(0);
|
|
Expect(midnight.utcTimeSeconds == 0.0, "Unix epoch starts at UTC midnight");
|
|
|
|
const RuntimeClockSnapshot midday = MakeRuntimeClockSnapshot(12 * 3600 + 34 * 60 + 56);
|
|
Expect(midday.utcTimeSeconds == 45296.0, "UTC time of day is seconds since midnight");
|
|
}
|
|
|
|
void TestOffsetLooksLikeTimezoneOffset()
|
|
{
|
|
const RuntimeClockSnapshot snapshot = MakeRuntimeClockSnapshot(12 * 3600);
|
|
Expect(std::fmod(snapshot.utcOffsetSeconds, 60.0) == 0.0, "UTC offset is minute-aligned");
|
|
Expect(snapshot.utcOffsetSeconds >= -14.0 * 3600.0 && snapshot.utcOffsetSeconds <= 14.0 * 3600.0,
|
|
"UTC offset is in the normal timezone range");
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
TestUtcSecondsOfDay();
|
|
TestOffsetLooksLikeTimezoneOffset();
|
|
|
|
if (gFailures != 0)
|
|
{
|
|
std::cerr << gFailures << " RuntimeClock test failure(s).\n";
|
|
return 1;
|
|
}
|
|
|
|
std::cout << "RuntimeClock tests passed.\n";
|
|
return 0;
|
|
}
|