Added a few unittests + bugfix in Yearmaster0.0.0-prefactoring
authorAndreas Waidler <[email protected]>
Mon, 18 May 2009 08:59:55 +0000 (18 08:59 +0000)
committerAndreas Waidler <[email protected]>
Wed, 27 May 2009 12:30:42 +0000 (27 14:30 +0200)
- Unit tests
  - TestTime
  - TestYear
- Fixed bug in Year.
- Updated .gitignore

13 files changed:
.gitignore
configure.ac
include/libdatetime/Time.hxx
src/Time.cxx
src/Year.cxx
tests/Makefile.am
tests/Time/Makefile.am [new file with mode: 0644]
tests/Time/TestTime.cxx [new file with mode: 0644]
tests/Time/TestTime.hxx [new file with mode: 0644]
tests/Year/Makefile.am [new file with mode: 0644]
tests/Year/TestYear.cxx [new file with mode: 0644]
tests/Year/TestYear.hxx [copied from src/Time.cxx with 52% similarity]
tests/testRegistry.cxx

index f0dc806..93ae22c 100644 (file)
@@ -33,3 +33,4 @@ doc/
 *~
 Doxyfile
 *.pc
+.libs
index c0c179d..a3d88d5 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT([libdatetime], [0.0.0], [Andreas Waidler])
+AC_INIT([libdatetime], [0.0.0], [<[email protected]>])
 AC_PREREQ(2.50)
 AM_INIT_AUTOMAKE([-Wall -Werror])
 AC_DEFINE_UNQUOTED(
@@ -220,7 +220,7 @@ AC_SUBST(CPPUNIT_CFLAGS)
 AC_SUBST(CPPUNIT_LIBS)
 #}}}
 # Conditionals#{{{
-AM_CONDITIONAL(can_run_tests, test "x${have_cppunit}" = xyes -a "x${have_pthreads}" = xyes)
+AM_CONDITIONAL(can_run_tests, test "x${have_cppunit}" = xyes)
 #}}}
 
 #AC_CONFIG_FILES([#{{{
@@ -231,6 +231,8 @@ AC_CONFIG_FILES([
     include/Makefile
     include/libdatetime/Makefile
     tests/Makefile
+    tests/Time/Makefile
+    tests/Year/Makefile
     ${PACKAGE}.pc
 ])
 #}}}
index 114b4ca..e21ffcf 100644 (file)
@@ -50,6 +50,26 @@ namespace libdatetime
       operator int() const;
 
 /*}}}*/
+      // Time& operator++();/*{{{*/
+
+      Time& operator++();
+
+/*}}}*/
+      // Time  operator++(int noop);/*{{{*/
+
+      Time  operator++(int noop);
+
+/*}}}*/
+      // Time& operator--();/*{{{*/
+
+      Time& operator--();
+
+/*}}}*/
+      // Time  operator--(int noop);/*{{{*/
+
+      Time  operator--(int noop);
+
+/*}}}*/
 
     private:
       // unsigned int _totalSeconds;/*{{{*/
index d0d0873..6135c1b 100644 (file)
@@ -59,6 +59,60 @@ namespace libdatetime
   }
 
 /*}}}*/
+  Time& Time::operator++()/*{{{*/
+  {
+    if (59 == _seconds) {
+      if (59 == _minutes) {
+        ++_hours;
+        _minutes = 0;
+      } else {
+        ++_minutes;
+      }
+      _seconds = 0;
+    } else {
+      ++_seconds;
+    }
+
+    return *this;
+  }
+
+/*}}}*/
+  Time Time::operator++(int noop)/*{{{*/
+  {
+    Time pre(*this);
+    ++(*this);
+
+    return pre;
+  }
+
+/*}}}*/
+  Time& Time::operator--()/*{{{*/
+  {
+    if (0 == _seconds) {
+      if (0 == _minutes) {
+        --_hours;
+        _minutes = 59;
+      } else {
+        --_minutes;
+      }
+      _seconds = 59;
+    } else {
+      --_seconds;
+    }
+
+    return *this;
+  }
+
+/*}}}*/
+  Time Time::operator--(int noop)/*{{{*/
+  {
+    Time pre(*this);
+    --(*this);
+
+    return pre;
+  }
+
+/*}}}*/
 }
 
 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
index 32995fb..053fdef 100644 (file)
@@ -40,7 +40,7 @@ namespace libdatetime
 /*}}}*/
   unsigned int Year::days() const/*{{{*/
   {
-    return isLeapYear() ? 366 : 355;
+    return isLeapYear() ? 366 : 365;
   }
 
 /*}}}*/
index 48c9a81..f4f6675 100644 (file)
@@ -1,12 +1,16 @@
 if can_run_tests
 
-# SUBDIRS =
+# SUBDIRS = Date DateTime Month Time Timestamp Year
+SUBDIRS = Time Year
+
 check_PROGRAMS = tests
 
 TESTS = tests
 tests_CPPFLAGS = -I$(top_srcdir)/include $(CPPUNIT_CFLAGS)
 tests_CXXFLAGS = $(CPPUNIT_LIBS)
-tests_LDADD = $(top_srcdir)/src/libdatetime.la 
+tests_LDADD = $(top_srcdir)/src/libdatetime.la \
+              $(top_srcdir)/tests/Time/libTime.la \
+              $(top_srcdir)/tests/Year/libYear.la 
 tests_SOURCES = main.cxx testRegistry.cxx
 
 else
diff --git a/tests/Time/Makefile.am b/tests/Time/Makefile.am
new file mode 100644 (file)
index 0000000..07b6035
--- /dev/null
@@ -0,0 +1,6 @@
+noinst_LTLIBRARIES = libTime.la
+libTime_la_CPPFLAGS = -I$(top_srcdir)/include $(CPPUNIT_CFLAGS)
+libTime_la_CXXFLAGS = $(CPPUNIT_LIBS)
+libTime_la_LIBADD = $(top_srcdir)/src/libdatetime.la
+libTime_la_SOURCES = TestTime.cxx
+noinst_HEADERS = TestTime.hxx
diff --git a/tests/Time/TestTime.cxx b/tests/Time/TestTime.cxx
new file mode 100644 (file)
index 0000000..32ca869
--- /dev/null
@@ -0,0 +1,169 @@
+/*{{{ LICENCE
+ *
+ * libdatetime
+ * Copyright (C) 2009 Andreas Waidler <[email protected]>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *}}}*/
+
+#include <TestTime.hxx>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <libdatetime/Time.hxx>
+
+void TestTime::setUp()/*{{{*/
+{
+}
+
+/*}}}*/
+void TestTime::tearDown()/*{{{*/
+{
+}
+
+/*}}}*/
+void TestTime::assert(libdatetime::Time& t,
+            unsigned int hours, unsigned int minutes, unsigned int seconds)/*{{{*/
+{
+  CPPUNIT_ASSERT_EQUAL(hours,   t.hours()  );
+  CPPUNIT_ASSERT_EQUAL(minutes, t.minutes());
+  CPPUNIT_ASSERT_EQUAL(seconds, t.seconds());
+}
+
+/*}}}*/
+void TestTime::testSeconds()/*{{{*/
+{
+  libdatetime::Time t(59);
+  assert(t, 0, 0, 59);
+}
+
+/*}}}*/
+void TestTime::testMinute()/*{{{*/
+{
+  libdatetime::Time t(60);
+  assert(t, 0, 1, 0);
+}
+
+/*}}}*/
+void TestTime::testMinutes()/*{{{*/
+{
+  libdatetime::Time t(3540);
+  assert(t, 0, 59, 0);
+}
+
+/*}}}*/
+void TestTime::testPreHour()/*{{{*/
+{
+  libdatetime::Time t(3599);
+  assert(t, 0, 59, 59);
+}
+
+/*}}}*/
+void TestTime::testHour()/*{{{*/
+{
+  libdatetime::Time t(3600);
+  assert(t, 1, 0, 0);
+}
+
+/*}}}*/
+void TestTime::testHours()/*{{{*/
+{
+  libdatetime::Time t(43200);
+  assert(t, 12, 0, 0);
+}
+
+/*}}}*/
+void TestTime::testConversion()/*{{{*/
+{
+  libdatetime::Time t(43266);
+  int i = t;
+  CPPUNIT_ASSERT_EQUAL(43266, i);
+}
+
+/*}}}*/
+void TestTime::testArithmeticOperators()/*{{{*/
+{
+  CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
+}
+
+/*}}}*/
+void TestTime::testAssignment()/*{{{*/
+{
+  libdatetime::Time t(42);
+  t = 60;
+  assert(t, 0, 1, 0);
+}
+
+/*}}}*/
+void TestTime::testRelationalOperators()/*{{{*/
+{
+  libdatetime::Time lhs(42);
+
+  CPPUNIT_ASSERT(lhs == 42);
+  CPPUNIT_ASSERT(lhs <= 42);
+  CPPUNIT_ASSERT(lhs >= 42);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != 42));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs <  42));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  42));
+
+  CPPUNIT_ASSERT(lhs != 62);
+  CPPUNIT_ASSERT(lhs <  62);
+  CPPUNIT_ASSERT(lhs <= 62);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == 62));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  62));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= 62));
+
+  libdatetime::Time rhse(42);
+  libdatetime::Time rhsgt(62);
+
+  CPPUNIT_ASSERT(lhs == rhse);
+  CPPUNIT_ASSERT(lhs <= rhse);
+  CPPUNIT_ASSERT(lhs >= rhse);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != rhse));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs <  rhse));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  rhse));
+
+  CPPUNIT_ASSERT(lhs != rhsgt);
+  CPPUNIT_ASSERT(lhs <  rhsgt);
+  CPPUNIT_ASSERT(lhs <= rhsgt);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == rhsgt));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  rhsgt));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= rhsgt));
+}
+
+/*}}}*/
+void TestTime::testCompoundAssignment()/*{{{*/
+{
+  CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
+}
+
+/*}}}*/
+void TestTime::testInDecrement()/*{{{*/
+{
+  libdatetime::Time inc(59);
+
+  assert(++inc, 0, 1, 0);
+  inc++;
+  assert(inc, 0, 1, 1);
+
+  libdatetime::Time dec(60);
+
+  assert(--dec, 0, 0, 59);
+  dec--;
+  assert(dec, 0, 0, 58);
+}
+
+/*}}}*/
+
+// Use no tabs at all; two spaces indentation; max. eighty chars per line.
+// vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker
diff --git a/tests/Time/TestTime.hxx b/tests/Time/TestTime.hxx
new file mode 100644 (file)
index 0000000..442395b
--- /dev/null
@@ -0,0 +1,69 @@
+/*{{{ LICENCE
+ *
+ * libdatetime
+ * Copyright (C) 2009 Andreas Waidler <[email protected]>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *}}}*/
+
+#ifndef TESTS_TESTTIME_HXX
+#define TESTS_TESTTIME_HXX
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <libdatetime/Time.hxx>
+
+class TestTime : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE(TestTime);
+    CPPUNIT_TEST(testSeconds);
+    CPPUNIT_TEST(testMinute);
+    CPPUNIT_TEST(testMinutes);
+    CPPUNIT_TEST(testPreHour);
+    CPPUNIT_TEST(testHour);
+    CPPUNIT_TEST(testHours);
+    CPPUNIT_TEST(testConversion);
+    CPPUNIT_TEST(testArithmeticOperators);
+    CPPUNIT_TEST(testAssignment);
+    CPPUNIT_TEST(testRelationalOperators);
+    CPPUNIT_TEST(testCompoundAssignment);
+    CPPUNIT_TEST(testInDecrement);
+  CPPUNIT_TEST_SUITE_END();
+
+  public:
+    void setUp();
+    void tearDown();
+
+    void assert(libdatetime::Time& t,
+                unsigned int hours, unsigned int minutes, unsigned int seconds);
+
+    void testSeconds();
+    void testMinute();
+    void testMinutes();
+    void testPreHour();
+    void testHour();
+    void testHours();
+    void testConversion();
+    void testComparison();
+    void testArithmeticOperators();
+    void testAssignment();
+    void testRelationalOperators();
+    void testCompoundAssignment();
+    void testInDecrement();
+};
+
+#endif // TESTS_TESTTIME_HXX
+
+// Use no tabs at all; two spaces indentation; max. eighty chars per line.
+// vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker
diff --git a/tests/Year/Makefile.am b/tests/Year/Makefile.am
new file mode 100644 (file)
index 0000000..6183286
--- /dev/null
@@ -0,0 +1,6 @@
+noinst_LTLIBRARIES = libYear.la
+libYear_la_CPPFLAGS = -I$(top_srcdir)/include $(CPPUNIT_CFLAGS)
+libYear_la_CXXFLAGS = $(CPPUNIT_LIBS)
+libYear_la_LIBADD = $(top_srcdir)/src/libdatetime.la
+libYear_la_SOURCES = TestYear.cxx
+noinst_HEADERS = TestYear.hxx
diff --git a/tests/Year/TestYear.cxx b/tests/Year/TestYear.cxx
new file mode 100644 (file)
index 0000000..3b74422
--- /dev/null
@@ -0,0 +1,186 @@
+/*{{{ LICENCE
+ *
+ * libdatetime
+ * Copyright (C) 2009 Andreas Waidler <[email protected]>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *}}}*/
+
+#include <TestYear.hxx>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <libdatetime/Year.hxx>
+#include <sstream>
+#include <string>
+#include <set>
+
+void TestYear::setUp()/*{{{*/
+{
+}
+
+/*}}}*/
+void TestYear::tearDown()/*{{{*/
+{
+}
+
+/*}}}*/
+
+void TestYear::testLeap()/*{{{*/
+{
+  std::set<int> leapYears;/*{{{*/
+  leapYears.insert(1972);
+  leapYears.insert(1976);
+  leapYears.insert(1980);
+  leapYears.insert(1984);
+  leapYears.insert(1988);
+  leapYears.insert(1992);
+  leapYears.insert(1996);
+  leapYears.insert(2000);
+  leapYears.insert(2004);
+  leapYears.insert(2008);
+  leapYears.insert(2012);
+  leapYears.insert(2016);
+  leapYears.insert(2020);
+  leapYears.insert(2024);
+  leapYears.insert(2028);
+  leapYears.insert(2032);
+  leapYears.insert(2036);
+  leapYears.insert(2040);
+  leapYears.insert(2044);
+  leapYears.insert(2048);
+  leapYears.insert(2052);
+  leapYears.insert(2056);
+  leapYears.insert(2060);
+  leapYears.insert(2064);
+  leapYears.insert(2068);
+  leapYears.insert(2072);
+  leapYears.insert(2076);
+  leapYears.insert(2080);
+  leapYears.insert(2084);
+  leapYears.insert(2088);
+  leapYears.insert(2092);
+  leapYears.insert(2096);
+
+/*}}}*/
+  std::set<int>::iterator it;
+  for (int i = 1970; i <= 2100; ++i)
+  {
+    it = leapYears.find(i);
+    bool isLeap = it != leapYears.end();
+
+    libdatetime::Year y(i);
+    CPPUNIT_ASSERT(y.isLeapYear() == isLeap);
+  }
+}
+
+/*}}}*/
+void TestYear::testDays()/*{{{*/
+{
+  libdatetime::Year leap(2000);
+  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(366), leap.days());
+  libdatetime::Year common(2007);
+  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(365), common.days());
+}
+
+/*}}}*/
+void TestYear::testSeconds()/*{{{*/
+{
+  libdatetime::Year leap(2000);
+  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(366*86400), leap.seconds());
+  libdatetime::Year common(2007);
+  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(365*86400), common.seconds());
+}
+
+/*}}}*/
+void TestYear::testConversion()/*{{{*/
+{
+  libdatetime::Year y(2000);
+  int i = y;
+  CPPUNIT_ASSERT_EQUAL(2000, i);
+}
+
+/*}}}*/
+void TestYear::testArithmeticOperators()/*{{{*/
+{
+  CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
+}
+
+/*}}}*/
+void TestYear::testAssignment()/*{{{*/
+{
+  libdatetime::Year y(0);
+  y = 1234;
+  CPPUNIT_ASSERT_EQUAL(1234, int(y));
+}
+
+/*}}}*/
+void TestYear::testRelationalOperators()/*{{{*/
+{
+  libdatetime::Year lhs(42);
+
+  CPPUNIT_ASSERT(lhs == 42);
+  CPPUNIT_ASSERT(lhs <= 42);
+  CPPUNIT_ASSERT(lhs >= 42);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != 42));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs <  42));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  42));
+
+  CPPUNIT_ASSERT(lhs != 62);
+  CPPUNIT_ASSERT(lhs <  62);
+  CPPUNIT_ASSERT(lhs <= 62);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == 62));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  62));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= 62));
+
+  libdatetime::Year rhse(42);
+  libdatetime::Year rhsgt(62);
+
+  CPPUNIT_ASSERT(lhs == rhse);
+  CPPUNIT_ASSERT(lhs <= rhse);
+  CPPUNIT_ASSERT(lhs >= rhse);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != rhse));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs <  rhse));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  rhse));
+
+  CPPUNIT_ASSERT(lhs != rhsgt);
+  CPPUNIT_ASSERT(lhs <  rhsgt);
+  CPPUNIT_ASSERT(lhs <= rhsgt);
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == rhsgt));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >  rhsgt));
+  CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= rhsgt));
+}
+
+/*}}}*/
+void TestYear::testCompoundAssignment()/*{{{*/
+{
+  CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
+}
+
+/*}}}*/
+void TestYear::testInDecrement()/*{{{*/
+{
+  libdatetime::Year y(2000);
+
+  CPPUNIT_ASSERT_EQUAL(2001, int(++y));
+  y++;
+  CPPUNIT_ASSERT_EQUAL(2002, int(y));
+  CPPUNIT_ASSERT_EQUAL(2001, int(--y));
+  y--;
+  CPPUNIT_ASSERT_EQUAL(2000, int(y));
+}
+
+/*}}}*/
+
+// Use no tabs at all; two spaces indentation; max. eighty chars per line.
+// vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker
similarity index 52%
copy from src/Time.cxx
copy to tests/Year/TestYear.hxx
index d0d0873..e7718bf 100644 (file)
  *
  *}}}*/
 
-#include <libdatetime/Time.hxx>
+#ifndef TESTS_TESTYEAR_HXX
+#define TESTS_TESTYEAR_HXX
 
-namespace libdatetime
-{
-  Time::Time(unsigned int seconds)/*{{{*/
-  : _totalSeconds(seconds)
-  , _hours(0)
-  , _minutes(0)
-  , _seconds(seconds)
-  {
-    _hours    = _seconds / (60 * 60);
-    _seconds -= _hours   *  60 * 60;
-
-    _minutes  = _seconds / 60;
-    _seconds -= _minutes * 60;
-  }
-
-/*}}}*/
-  unsigned int Time::hours() const/*{{{*/
-  {
-    return _hours;
-  }
-
-/*}}}*/
-  unsigned int Time::minutes() const/*{{{*/
-  {
-    return _minutes;
-  }
+#include <cppunit/extensions/HelperMacros.h>
 
-/*}}}*/
-  unsigned int Time::seconds() const/*{{{*/
-  {
-    return _seconds;
-  }
-
-/*}}}*/
-  Time::operator int() const/*{{{*/
-  {
-    return _totalSeconds;
-  }
-
-/*}}}*/
-}
+class TestYear : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE(TestYear);
+    CPPUNIT_TEST(testLeap);
+    CPPUNIT_TEST(testDays);
+    CPPUNIT_TEST(testSeconds);
+    CPPUNIT_TEST(testConversion);
+    CPPUNIT_TEST(testArithmeticOperators);
+    CPPUNIT_TEST(testAssignment);
+    CPPUNIT_TEST(testRelationalOperators);
+    CPPUNIT_TEST(testCompoundAssignment);
+    CPPUNIT_TEST(testInDecrement);
+  CPPUNIT_TEST_SUITE_END();
+
+  public:
+    void setUp();
+    void tearDown();
+
+    void testLeap();
+    void testDays();
+    void testSeconds();
+    void testConversion();
+    void testArithmeticOperators();
+    void testAssignment();
+    void testRelationalOperators();
+    void testCompoundAssignment();
+    void testInDecrement();
+};
+
+#endif // TESTS_TESTYEAR_HXX
 
 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker
index b60f090..e769e97 100644 (file)
@@ -2,12 +2,15 @@
 
 #include <cppunit/extensions/HelperMacros.h>
 
+#include <Time/TestTime.hxx>
+#include <Year/TestYear.hxx>
 
 /*}}}*/
 
 // Registering all unit tests here, to make them easier to disable and enable.
 
-// CPPUNIT_TEST_SUITE_REGISTRATION();
+CPPUNIT_TEST_SUITE_REGISTRATION(TestTime);
+CPPUNIT_TEST_SUITE_REGISTRATION(TestYear);
 
 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker