]> git.tdb.fi Git - libs/core.git/blobdiff - tests/timezone.cpp
Add unit tests
[libs/core.git] / tests / timezone.cpp
diff --git a/tests/timezone.cpp b/tests/timezone.cpp
new file mode 100644 (file)
index 0000000..c59cdd3
--- /dev/null
@@ -0,0 +1,48 @@
+#include <msp/time/units.h>
+#include <msp/time/timezone.h>
+#include <msp/test/test.h>
+
+using namespace std;
+using namespace Msp;
+
+class TimeZoneTests: public Test::RegisteredTest<TimeZoneTests>
+{
+public:
+       TimeZoneTests();
+
+       static const char *get_name() { return "TimeZone"; }
+
+private:
+       void utc();
+       void local();
+       void custom();
+};
+
+
+TimeZoneTests::TimeZoneTests()
+{
+       add(&TimeZoneTests::utc, "UTC");
+       add(&TimeZoneTests::local, "Local");
+       add(&TimeZoneTests::custom, "Custom");
+}
+
+void TimeZoneTests::utc()
+{
+       Time::TimeZone tz = Time::TimeZone::utc();
+       EXPECT_EQUAL(tz.get_name(), "UTC");
+       EXPECT_EQUAL(tz.get_offset(), Time::zero);
+}
+
+void TimeZoneTests::local()
+{
+       Time::TimeZone tz = Time::TimeZone::local();
+       info(format("'%s' %s", tz.get_name(), tz.get_offset()));
+}
+
+void TimeZoneTests::custom()
+{
+       Time::TimeZone tz1(120);
+       EXPECT_EQUAL(tz1.get_name(), "UTC+2");
+       Time::TimeZone tz2(345);
+       EXPECT_EQUAL(tz2.get_name(), "UTC+5:45");
+}