Bump to libdcp 1.8.2.
[libsub.git] / test / time_test.cc
index a4dae507237aa436a3e9f1643bc4d45080ed01f0..d103efc580eedb754e5f20c1bcae579c31f08c73 100644 (file)
@@ -20,6 +20,7 @@
 #include "sub_time.h"
 #include "exceptions.h"
 #include <boost/test/unit_test.hpp>
+#include <iostream>
 
 /* Check time construction */
 BOOST_AUTO_TEST_CASE (time_construction_test)
@@ -72,3 +73,27 @@ BOOST_AUTO_TEST_CASE (time_other_test)
        BOOST_CHECK_THROW (sub::Time::from_hmsf (2, 1, 58, 4).all_as_seconds(), sub::UnknownFrameRateError);
        BOOST_CHECK_CLOSE (sub::Time::from_hmsf (2, 1, 58, 4, sub::Rational (24, 1)).all_as_seconds(), 7318.1667, 0.001);
 }
+
+/* Check an addition case that gave an odd result */
+BOOST_AUTO_TEST_CASE (time_add_test)
+{
+       sub::Time t = sub::Time::from_hmsf (0, 4, 8, 208, sub::Rational(1000, 1));
+       t.add (sub::Time::from_frames(54641, sub::Rational(24, 1)));
+       BOOST_CHECK_EQUAL (t, sub::Time::from_hmsf (0, 42, 4, 916, sub::Rational(1000, 1)));
+}
+
+BOOST_AUTO_TEST_CASE (time_scale_test1)
+{
+       sub::Time t = sub::Time::from_hmsf (0, 0, 1, 0, sub::Rational(1000, 1));
+       t.scale (0.96);
+       BOOST_CHECK_EQUAL (t.seconds(), 0);
+       BOOST_CHECK_EQUAL (t.frames_at(sub::Rational(1000, 1)), 960);
+}
+
+BOOST_AUTO_TEST_CASE (time_scale_test2)
+{
+       sub::Time t = sub::Time::from_hmsf (0, 0, 2, 0, sub::Rational(1000, 1));
+       t.scale (0.96);
+       BOOST_CHECK_EQUAL (t.seconds(), 1);
+       BOOST_CHECK_EQUAL (t.frames_at(sub::Rational(1000, 1)), 920);
+}