Run all tests with lots of encoding threads.
[dcpomatic.git] / test / dcpomatic_time_test.cc
index 38b4d31a99c74d880e81c6e7969264ed07811683..5b58c369b047fe3a9b05ae10777d819258d302d3 100644 (file)
@@ -31,6 +31,7 @@
 
 using std::list;
 using std::cout;
+using namespace dcpomatic;
 
 BOOST_AUTO_TEST_CASE (dcpomatic_time_test)
 {
@@ -300,3 +301,40 @@ BOOST_AUTO_TEST_CASE (dcpomatic_time_period_coalesce_test5)
        BOOST_CHECK (q.front() == DCPTimePeriod(DCPTime(14), DCPTime(91)));
        BOOST_CHECK (q.back()  == DCPTimePeriod(DCPTime(100), DCPTime(106)));
 }
+
+/* Straightforward test of DCPTime::ceil */
+BOOST_AUTO_TEST_CASE (dcpomatic_time_ceil_test)
+{
+       BOOST_CHECK_EQUAL (DCPTime(0).ceil(DCPTime::HZ / 2).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(1).ceil(DCPTime::HZ / 2).get(), 2);
+       BOOST_CHECK_EQUAL (DCPTime(2).ceil(DCPTime::HZ / 2).get(), 2);
+       BOOST_CHECK_EQUAL (DCPTime(3).ceil(DCPTime::HZ / 2).get(), 4);
+
+       BOOST_CHECK_EQUAL (DCPTime(0).ceil(DCPTime::HZ / 42).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(1).ceil(DCPTime::HZ / 42).get(), 42);
+       BOOST_CHECK_EQUAL (DCPTime(42).ceil(DCPTime::HZ / 42).get(), 42);
+       BOOST_CHECK_EQUAL (DCPTime(43).ceil(DCPTime::HZ / 42).get(), 84);
+
+       /* Check that rounding up to non-integer frame rates works */
+       BOOST_CHECK_EQUAL (DCPTime(45312).ceil(29.976).get(), 48038);
+
+       /* Check another tricky case that used to fail */
+       BOOST_CHECK_EQUAL (DCPTime(212256039).ceil(23.976).get(), 212256256);
+}
+
+/* Straightforward test of DCPTime::floor */
+BOOST_AUTO_TEST_CASE (dcpomatic_time_floor_test)
+{
+       BOOST_CHECK_EQUAL (DCPTime(0).floor(DCPTime::HZ / 2).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(1).floor(DCPTime::HZ / 2).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(2).floor(DCPTime::HZ / 2).get(), 2);
+       BOOST_CHECK_EQUAL (DCPTime(3).floor(DCPTime::HZ / 2).get(), 2);
+
+       BOOST_CHECK_EQUAL (DCPTime(0).floor(DCPTime::HZ / 42).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(1).floor(DCPTime::HZ / 42).get(), 0);
+       BOOST_CHECK_EQUAL (DCPTime(42).floor(DCPTime::HZ / 42.0).get(), 42);
+       BOOST_CHECK_EQUAL (DCPTime(43).floor(DCPTime::HZ / 42.0).get(), 42);
+
+       /* Check that rounding down to non-integer frame rates works */
+       BOOST_CHECK_EQUAL (DCPTime(45312).floor(29.976).get(), 44836);
+}