Added a few unittests + bugfix in Year
[libdatetime.git] / tests / Time / TestTime.cxx
blob32ca8696ca4f737d8fc8996f90a50ebc0cf3ac30
1 /*{{{ LICENCE
3 * libdatetime
4 * Copyright (C) 2009 Andreas Waidler <arandes@programmers.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *}}}*/
20 #include <TestTime.hxx>
21 #include <cppunit/extensions/HelperMacros.h>
23 #include <libdatetime/Time.hxx>
25 void TestTime::setUp()/*{{{*/
29 /*}}}*/
30 void TestTime::tearDown()/*{{{*/
34 /*}}}*/
35 void TestTime::assert(libdatetime::Time& t,
36 unsigned int hours, unsigned int minutes, unsigned int seconds)/*{{{*/
38 CPPUNIT_ASSERT_EQUAL(hours, t.hours() );
39 CPPUNIT_ASSERT_EQUAL(minutes, t.minutes());
40 CPPUNIT_ASSERT_EQUAL(seconds, t.seconds());
43 /*}}}*/
44 void TestTime::testSeconds()/*{{{*/
46 libdatetime::Time t(59);
47 assert(t, 0, 0, 59);
50 /*}}}*/
51 void TestTime::testMinute()/*{{{*/
53 libdatetime::Time t(60);
54 assert(t, 0, 1, 0);
57 /*}}}*/
58 void TestTime::testMinutes()/*{{{*/
60 libdatetime::Time t(3540);
61 assert(t, 0, 59, 0);
64 /*}}}*/
65 void TestTime::testPreHour()/*{{{*/
67 libdatetime::Time t(3599);
68 assert(t, 0, 59, 59);
71 /*}}}*/
72 void TestTime::testHour()/*{{{*/
74 libdatetime::Time t(3600);
75 assert(t, 1, 0, 0);
78 /*}}}*/
79 void TestTime::testHours()/*{{{*/
81 libdatetime::Time t(43200);
82 assert(t, 12, 0, 0);
85 /*}}}*/
86 void TestTime::testConversion()/*{{{*/
88 libdatetime::Time t(43266);
89 int i = t;
90 CPPUNIT_ASSERT_EQUAL(43266, i);
93 /*}}}*/
94 void TestTime::testArithmeticOperators()/*{{{*/
96 CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
99 /*}}}*/
100 void TestTime::testAssignment()/*{{{*/
102 libdatetime::Time t(42);
103 t = 60;
104 assert(t, 0, 1, 0);
107 /*}}}*/
108 void TestTime::testRelationalOperators()/*{{{*/
110 libdatetime::Time lhs(42);
112 CPPUNIT_ASSERT(lhs == 42);
113 CPPUNIT_ASSERT(lhs <= 42);
114 CPPUNIT_ASSERT(lhs >= 42);
115 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != 42));
116 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs < 42));
117 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs > 42));
119 CPPUNIT_ASSERT(lhs != 62);
120 CPPUNIT_ASSERT(lhs < 62);
121 CPPUNIT_ASSERT(lhs <= 62);
122 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == 62));
123 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs > 62));
124 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= 62));
126 libdatetime::Time rhse(42);
127 libdatetime::Time rhsgt(62);
129 CPPUNIT_ASSERT(lhs == rhse);
130 CPPUNIT_ASSERT(lhs <= rhse);
131 CPPUNIT_ASSERT(lhs >= rhse);
132 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs != rhse));
133 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs < rhse));
134 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs > rhse));
136 CPPUNIT_ASSERT(lhs != rhsgt);
137 CPPUNIT_ASSERT(lhs < rhsgt);
138 CPPUNIT_ASSERT(lhs <= rhsgt);
139 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs == rhsgt));
140 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs > rhsgt));
141 CPPUNIT_ASSERT_ASSERTION_FAIL(CPPUNIT_ASSERT(lhs >= rhsgt));
144 /*}}}*/
145 void TestTime::testCompoundAssignment()/*{{{*/
147 CPPUNIT_FAIL("TODO: Add Timespan class/calculations.");
150 /*}}}*/
151 void TestTime::testInDecrement()/*{{{*/
153 libdatetime::Time inc(59);
155 assert(++inc, 0, 1, 0);
156 inc++;
157 assert(inc, 0, 1, 1);
159 libdatetime::Time dec(60);
161 assert(--dec, 0, 0, 59);
162 dec--;
163 assert(dec, 0, 0, 58);
166 /*}}}*/
168 // Use no tabs at all; two spaces indentation; max. eighty chars per line.
169 // vim: et ts=2 sw=2 sts=2 tw=80 fdm=marker