Merge master.
[dcpomatic.git] / test / util_test.cc
index 40a2835f1515f68a47ba5b9981a812778ad10295..f5bf94c011464265754e59aeddde65dc44e09dc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
+/** @file  test/util_test.cc
+ *  @brief Test various utility methods.
+ */
+
 #include <boost/test/unit_test.hpp>
 #include "lib/util.h"
 #include "lib/exceptions.h"
@@ -54,6 +58,24 @@ BOOST_AUTO_TEST_CASE (md5_digest_test)
        BOOST_CHECK_THROW (md5_digest (p, shared_ptr<Job> ()), std::runtime_error);
 }
 
+/* Straightforward test of DCPTime::round_up */
+BOOST_AUTO_TEST_CASE (dcptime_round_up_test)
+{
+       BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 2), DCPTime (0));
+       BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 2), DCPTime (2));
+       BOOST_CHECK_EQUAL (DCPTime (2).round_up (DCPTime::HZ / 2), DCPTime (2));
+       BOOST_CHECK_EQUAL (DCPTime (3).round_up (DCPTime::HZ / 2), DCPTime (4));
+       
+       BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 42), DCPTime (0));
+       BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 42), DCPTime (42));
+       BOOST_CHECK_EQUAL (DCPTime (42).round_up (DCPTime::HZ / 42), DCPTime (42));
+       BOOST_CHECK_EQUAL (DCPTime (43).round_up (DCPTime::HZ / 42), DCPTime (84));
+
+       /* Check that rounding up to non-integer frame rates works */
+       BOOST_CHECK_EQUAL (DCPTime (45312).round_up (29.976), DCPTime (48045));
+}
+
+
 BOOST_AUTO_TEST_CASE (divide_with_round_test)
 {
        BOOST_CHECK_EQUAL (divide_with_round (0, 4), 0);
@@ -67,6 +89,12 @@ BOOST_AUTO_TEST_CASE (divide_with_round_test)
        BOOST_CHECK_EQUAL (divide_with_round (1000, 500), 2);
 }
 
+BOOST_AUTO_TEST_CASE (timecode_test)
+{
+       DCPTime t = DCPTime::from_seconds (2 * 60 * 60 + 4 * 60 + 31) + DCPTime::from_frames (19, 24);
+       BOOST_CHECK_EQUAL (t.timecode (24), "02:04:31:19");
+}
+
 BOOST_AUTO_TEST_CASE (seconds_to_approximate_hms_test)
 {
        BOOST_CHECK_EQUAL (seconds_to_approximate_hms (1), "1 second");