Add a first test for BDateTime.

* We need to write more of those.
This commit is contained in:
Adrien Destugues 2014-06-16 08:49:36 +02:00
parent dbd4f8c46b
commit 4f88977f9a
4 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,55 @@
/*
* Copyright 2014, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#include "DateTimeTest.h"
#include <DateTime.h>
#include <cppunit/TestSuite.h>
class DateTimeTest : public BTestCase {
public:
DateTimeTest(std::string name = "");
void test(void);
};
DateTimeTest::DateTimeTest(std::string name)
:
BTestCase(name)
{
}
void
DateTimeTest::test()
{
BDateTime dateTime;
// Should be just one second before epoch
dateTime.SetTime_t(-1);
CPPUNIT_ASSERT(dateTime.IsValid());
CPPUNIT_ASSERT_EQUAL(59, dateTime.Time().Second());
CPPUNIT_ASSERT_EQUAL(59, dateTime.Time().Minute());
CPPUNIT_ASSERT_EQUAL(23, dateTime.Time().Hour());
CPPUNIT_ASSERT_EQUAL(31, dateTime.Date().Day());
CPPUNIT_ASSERT_EQUAL(12, dateTime.Date().Month());
CPPUNIT_ASSERT_EQUAL(1969, dateTime.Date().Year());
}
CppUnit::Test*
DateTimeTestSuite()
{
CppUnit::TestSuite* testSuite = new CppUnit::TestSuite();
testSuite->addTest(new DateTimeTest("BDateTime"));
return testSuite;
}

View File

@ -0,0 +1,15 @@
/*
* Copyright 2014, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _DATE_TIME_TEST_H_
#define _DATE_TIME_TEST_H_
#include "TestCase.h"
CppUnit::Test *DateTimeTestSuite();
#endif // _DATE_TIME_TEST_H_

View File

@ -29,6 +29,9 @@ UnitTestLib libsupporttest.so
AutolockLockerTest.cpp
AutolockLooperTest.cpp
# BDateTime
DateTimeTest.cpp
# BLocker (all in ./blocker)
LockerTest.cpp
BenaphoreLockCountTest1.cpp

View File

@ -10,6 +10,7 @@
#include "bstring/StringTest.h"
#include "bblockcache/BlockCacheTest.h"
#include "ByteOrderTest.h"
#include "DateTimeTest.h"
BTestSuite *
@ -20,6 +21,7 @@ getTestSuite()
// ##### Add test suites here #####
suite->addTest("BArchivable", ArchivableTestSuite());
suite->addTest("BAutolock", AutolockTestSuite());
suite->addTest("BDateTime", DateTimeTestSuite());
suite->addTest("BLocker", LockerTestSuite());
suite->addTest("BMemoryIO", MemoryIOTestSuite());
suite->addTest("BMallocIO", MallocIOTestSuite());