/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
- This program is free software; you can redistribute it and/or modify
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ libdcp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
*/
#include <boost/test/unit_test.hpp>
#include "dcp_time.h"
+#include "exceptions.h"
+
+using boost::optional;
/** Check that dcp::Time works */
BOOST_AUTO_TEST_CASE (dcp_time)
BOOST_CHECK_EQUAL (r.s, 8);
BOOST_CHECK_EQUAL (r.e, 3);
BOOST_CHECK_EQUAL (r.as_string(dcp::INTEROP), "03:06:08:003");
+ BOOST_CHECK_EQUAL (r.as_string(dcp::SMPTE), "03:06:08:03");
/* Another arbitrary tcr (30) */
a = dcp::Time (24, 12, 6, 3, 30);
/* Check rounding on conversion from seconds */
BOOST_CHECK_EQUAL (dcp::Time (80.990, 1000), dcp::Time (0, 1, 20, 990, 1000));
- /* Check rebase() */
+ /* Check rebase */
a = dcp::Time (1, 58, 56, 2, 25);
- BOOST_CHECK_EQUAL (a.rebase (250), dcp::Time (1, 58, 56, 20, 250));
+ BOOST_CHECK_EQUAL (a.rebase(250), dcp::Time(1, 58, 56, 20, 250));
b = dcp::Time (9, 12, 41, 17, 99);
- BOOST_CHECK_EQUAL (b.rebase (250), dcp::Time (9, 12, 41, 42, 250));
- /* We must round down in rebase() */
+ BOOST_CHECK_EQUAL (b.rebase(250), dcp::Time(9, 12, 41, 43, 250));
a = dcp::Time (0, 2, 57, 999, 1000);
- BOOST_CHECK_EQUAL (a.rebase (250), dcp::Time (0, 2, 57, 249, 250));
+ BOOST_CHECK_EQUAL (a.rebase(250), dcp::Time(0, 2, 58, 0, 250));
+ a = dcp::Time (0, 47, 9, 998, 1000);
+ BOOST_CHECK_EQUAL (a.rebase(250), dcp::Time(0, 47, 10, 0, 250));
+
+ /* Check some allowed constructions from string */
+
+ /* Interop type 1 */
+ a = dcp::Time ("01:23:45:123", optional<int>());
+ BOOST_CHECK_EQUAL (a, dcp::Time (1, 23, 45, 123, 250));
+ /* Interop type 2 */
+ a = dcp::Time ("01:23:45.123", optional<int>());
+ BOOST_CHECK_EQUAL (a, dcp::Time (1, 23, 45, 123, 1000));
+ /* SMPTE */
+ a = dcp::Time ("01:23:45:12", 250);
+ BOOST_CHECK_EQUAL (a, dcp::Time (1, 23, 45, 12, 250));
+
+ /* Check some disallowed constructions from string */
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:1234", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:1234:66", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23::123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01::45:123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time (":23:45:123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45.1234", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45.1234.66", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45.", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:.123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01::45.123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time (":23:45.123", optional<int>()), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:123", 250), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:123:66", 250), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23:45:", 250), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01:23::123", 250), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time ("01::45:123", 250), dcp::ReadError);
+ BOOST_CHECK_THROW (dcp::Time (":23:45:123", 250), dcp::ReadError);
+
+ /* Check operator< and operator> */
+ BOOST_CHECK (dcp::Time (3, 2, 3, 4, 24) < dcp::Time (3, 2, 3, 5, 24));
+ BOOST_CHECK (!(dcp::Time (3, 2, 3, 4, 24) < dcp::Time (3, 2, 3, 4, 24)));
+ BOOST_CHECK (dcp::Time (3, 2, 3, 5, 24) > dcp::Time (3, 2, 3, 4, 24));
+ BOOST_CHECK (!(dcp::Time (3, 2, 3, 4, 24) > dcp::Time (3, 2, 3, 4, 24)));
+ BOOST_CHECK (dcp::Time (6, 0, 0, 0, 24) < dcp::Time (7, 0, 0, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 6, 0, 0, 24) < dcp::Time (0, 7, 0, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 0, 6, 0, 24) < dcp::Time (0, 0, 7, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 0, 0, 6, 24) < dcp::Time (0, 0, 0, 7, 24));
+ BOOST_CHECK (dcp::Time (7, 0, 0, 0, 24) > dcp::Time (6, 0, 0, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 7, 0, 0, 24) > dcp::Time (0, 6, 0, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 0, 7, 0, 24) > dcp::Time (0, 0, 6, 0, 24));
+ BOOST_CHECK (dcp::Time (0, 0, 0, 7, 24) > dcp::Time (0, 0, 0, 6, 24));
}