2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "exceptions.h"
22 #include <boost/test/unit_test.hpp>
24 /* Check time construction */
25 BOOST_AUTO_TEST_CASE (time_construction_test)
28 sub::Time t = sub::Time::from_hms (3, 5, 7, 40);
29 BOOST_CHECK_EQUAL (t.hours(), 3);
30 BOOST_CHECK_EQUAL (t.minutes(), 5);
31 BOOST_CHECK_EQUAL (t.seconds(), 7);
32 BOOST_CHECK_EQUAL (t.milliseconds(), 40);
36 sub::Time t = sub::Time::from_hms (591353, 1, 2, 3);
37 BOOST_CHECK_EQUAL (t.hours(), 591353);
38 BOOST_CHECK_EQUAL (t.minutes(), 1);
39 BOOST_CHECK_EQUAL (t.seconds(), 2);
40 BOOST_CHECK_EQUAL (t.milliseconds(), 3);
44 /* Check time conversions */
45 BOOST_AUTO_TEST_CASE (time_conversion_test)
49 /* 40ms = 1 frame at 25fps */
50 p = sub::Time::from_hms (3, 5, 7, 40);
51 BOOST_CHECK_EQUAL (p.frames_at (sub::Rational (25, 1)), 1);
52 p = sub::Time::from_hmsf (3, 5, 7, 1, sub::Rational (25, 1));
53 BOOST_CHECK_EQUAL (p.milliseconds (), 40);
55 /* 120ms = 3 frames at 25fps */
56 p = sub::Time::from_hms (3, 5, 7, 120);
57 BOOST_CHECK_EQUAL (p.frames_at (sub::Rational (25, 1)), 3);
58 p = sub::Time::from_hmsf (3, 5, 7, 3, sub::Rational (25, 1));
59 BOOST_CHECK_EQUAL (p.milliseconds (), 120);
62 /* Check some operators */
63 BOOST_AUTO_TEST_CASE (time_operator_test)
65 BOOST_CHECK_EQUAL (sub::Time::from_hms (0, 0, 5, 198 * 4), sub::Time::from_hms (0, 0, 5, 198 * 4));
66 BOOST_CHECK (sub::Time::from_hms (0, 0, 55, 332) != sub::Time::from_hms (0, 0, 58, 332));
69 /* Check some other bits of Time */
70 BOOST_AUTO_TEST_CASE (time_other_test)
72 BOOST_CHECK_THROW (sub::Time::from_hmsf (2, 1, 58, 4).all_as_seconds(), sub::UnknownFrameRateError);
73 BOOST_CHECK_CLOSE (sub::Time::from_hmsf (2, 1, 58, 4, sub::Rational (24, 1)).all_as_seconds(), 7318.1667, 0.001);