xref: /haiku/src/tests/kits/support/DateTimeTest.cpp (revision 4f88977f9ab60d7d71594887565595e40e6df0a8)
1 /*
2  * Copyright 2014, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "DateTimeTest.h"
8 
9 #include <DateTime.h>
10 
11 #include <cppunit/TestSuite.h>
12 
13 
14 class DateTimeTest : public BTestCase {
15 	public:
16 		DateTimeTest(std::string name = "");
17 
18 		void test(void);
19 };
20 
21 
DateTimeTest(std::string name)22 DateTimeTest::DateTimeTest(std::string name)
23 	:
24 	BTestCase(name)
25 {
26 }
27 
28 
29 void
test()30 DateTimeTest::test()
31 {
32 	BDateTime dateTime;
33 
34 	// Should be just one second before epoch
35 	dateTime.SetTime_t(-1);
36 
37 	CPPUNIT_ASSERT(dateTime.IsValid());
38 	CPPUNIT_ASSERT_EQUAL(59, dateTime.Time().Second());
39 	CPPUNIT_ASSERT_EQUAL(59, dateTime.Time().Minute());
40 	CPPUNIT_ASSERT_EQUAL(23, dateTime.Time().Hour());
41 	CPPUNIT_ASSERT_EQUAL(31, dateTime.Date().Day());
42 	CPPUNIT_ASSERT_EQUAL(12, dateTime.Date().Month());
43 	CPPUNIT_ASSERT_EQUAL(1969, dateTime.Date().Year());
44 }
45 
46 
47 CppUnit::Test*
DateTimeTestSuite()48 DateTimeTestSuite()
49 {
50 	CppUnit::TestSuite* testSuite = new CppUnit::TestSuite();
51 
52 	testSuite->addTest(new DateTimeTest("BDateTime"));
53 
54 	return testSuite;
55 }
56