Allow specification of the CPL ID to use in a DCP with _create (#2302).
[dcpomatic.git] / test / create_cli_test.cc
index 7bb21546e5799a46da15935b86305018c8433e46..71281a63e34630cc40d7684ee45ab4a17f6044b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -21,6 +21,7 @@
 #include "lib/create_cli.h"
 #include "lib/ratio.h"
 #include "lib/dcp_content_type.h"
+#include "test.h"
 #include <boost/test/unit_test.hpp>
 #include <boost/tokenizer.hpp>
 #include <boost/algorithm/string/predicate.hpp>
@@ -36,21 +37,19 @@ run (string cmd)
        boost::escaped_list_separator<char> els ("", " ", "\"\'");
        boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);
 
-       char** argv = new char*[256];
+       std::vector<char*> argv(256);
        int argc = 0;
 
        for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) {
                argv[argc++] = strdup (i->c_str());
        }
 
-       CreateCLI cc (argc, argv);
+       CreateCLI cc (argc, argv.data());
 
        for (int i = 0; i < argc; ++i) {
                free (argv[i]);
        }
 
-       delete[] argv;
-
        return cc;
 }
 
@@ -70,85 +69,125 @@ BOOST_AUTO_TEST_CASE (create_cli_test)
        cc = run ("dcpomatic2_create -h");
        BOOST_REQUIRE (cc.error);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --name frobozz --template bar");
+       cc = run ("dcpomatic2_create x --name frobozz --template bar");
        BOOST_CHECK (!cc.error);
        BOOST_CHECK_EQUAL (cc.name, "frobozz");
        BOOST_REQUIRE (cc.template_name);
        BOOST_CHECK_EQUAL (*cc.template_name, "bar");
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-content-type FTR");
+       cc = run ("dcpomatic2_create x --dcp-content-type FTR");
        BOOST_CHECK (!cc.error);
        BOOST_CHECK_EQUAL (cc.dcp_content_type, DCPContentType::from_isdcf_name("FTR"));
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-frame-rate 30");
+       cc = run ("dcpomatic2_create x --dcp-frame-rate 30");
        BOOST_CHECK (!cc.error);
        BOOST_REQUIRE (cc.dcp_frame_rate);
        BOOST_CHECK_EQUAL (*cc.dcp_frame_rate, 30);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio 185");
+       cc = run ("dcpomatic2_create x --container-ratio 185");
        BOOST_CHECK (!cc.error);
        BOOST_CHECK_EQUAL (cc.container_ratio, Ratio::from_id("185"));
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio XXX");
+       cc = run ("dcpomatic2_create x --container-ratio XXX");
        BOOST_CHECK (cc.error);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --content-ratio 239");
+       cc = run ("dcpomatic2_create x --still-length 42");
        BOOST_CHECK (!cc.error);
-       BOOST_CHECK_EQUAL (cc.content_ratio, Ratio::from_id("239"));
-
-       cc = run ("dcpomatic2_create x --content-ratio 240");
-       BOOST_CHECK (cc.error);
+       BOOST_CHECK_EQUAL (cc.still_length, 42);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --still-length 42");
+       cc = run ("dcpomatic2_create x --standard SMPTE");
        BOOST_CHECK (!cc.error);
-       BOOST_CHECK_EQUAL (cc.still_length, 42);
+       BOOST_CHECK_EQUAL (cc.standard, dcp::Standard::SMPTE);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTE");
+       cc = run ("dcpomatic2_create x --standard interop");
        BOOST_CHECK (!cc.error);
-       BOOST_CHECK_EQUAL (cc.standard, dcp::SMPTE);
+       BOOST_CHECK_EQUAL (cc.standard, dcp::Standard::INTEROP);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTEX");
+       cc = run ("dcpomatic2_create x --standard SMPTEX");
        BOOST_CHECK (cc.error);
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --config foo/bar");
+       cc = run ("dcpomatic2_create x --config foo/bar");
        BOOST_CHECK (!cc.error);
        BOOST_REQUIRE (cc.config_dir);
        BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --output fred/jim");
+       cc = run ("dcpomatic2_create x --output fred/jim");
        BOOST_CHECK (!cc.error);
        BOOST_REQUIRE (cc.output_dir);
        BOOST_CHECK_EQUAL (*cc.output_dir, "fred/jim");
 
-       cc = run ("dcpomatic2_create x --content-ratio 185 --outputX fred/jim");
+       cc = run ("dcpomatic2_create x --outputX fred/jim");
        BOOST_CHECK (cc.error);
 
-       cc = run ("dcpomatic2_create --content-ratio 185 --config foo/bar --still-length 42 --output flaps fred jim sheila");
+       cc = run ("dcpomatic2_create --config foo/bar --still-length 42 --output flaps fred jim sheila");
        BOOST_CHECK (!cc.error);
        BOOST_REQUIRE (cc.config_dir);
        BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
        BOOST_CHECK_EQUAL (cc.still_length, 42);
        BOOST_REQUIRE (cc.output_dir);
        BOOST_CHECK_EQUAL (*cc.output_dir, "flaps");
-       BOOST_REQUIRE_EQUAL (cc.content.size(), 3);
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
        BOOST_CHECK_EQUAL (cc.content[0].path, "fred");
-       BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_2D);
+       BOOST_CHECK_EQUAL (cc.content[0].frame_type, VideoFrameType::TWO_D);
        BOOST_CHECK_EQUAL (cc.content[1].path, "jim");
-       BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_2D);
+       BOOST_CHECK_EQUAL (cc.content[1].frame_type, VideoFrameType::TWO_D);
        BOOST_CHECK_EQUAL (cc.content[2].path, "sheila");
-       BOOST_CHECK_EQUAL (cc.content[2].frame_type, VIDEO_FRAME_TYPE_2D);
+       BOOST_CHECK_EQUAL (cc.content[2].frame_type, VideoFrameType::TWO_D);
 
-       cc = run ("dcpomatic2_create --content-ratio 185 --left-eye left.mp4 --right-eye right.mp4");
-       BOOST_REQUIRE_EQUAL (cc.content.size(), 2);
+       cc = run ("dcpomatic2_create --left-eye left.mp4 --right-eye right.mp4");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 2U);
        BOOST_CHECK_EQUAL (cc.content[0].path, "left.mp4");
-       BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_3D_LEFT);
+       BOOST_CHECK_EQUAL (cc.content[0].frame_type, VideoFrameType::THREE_D_LEFT);
        BOOST_CHECK_EQUAL (cc.content[1].path, "right.mp4");
-       BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_3D_RIGHT);
+       BOOST_CHECK_EQUAL (cc.content[1].frame_type, VideoFrameType::THREE_D_RIGHT);
        BOOST_CHECK_EQUAL (cc.fourk, false);
 
-       cc = run ("dcpomatic2_create --fourk --content-ratio 185 foo.mp4");
-       BOOST_REQUIRE_EQUAL (cc.content.size(), 1);
+       cc = run ("dcpomatic2_create --twok foo.mp4");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
+       BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
+       BOOST_CHECK_EQUAL (cc.twok, true);
+       BOOST_CHECK (!cc.error);
+
+       cc = run ("dcpomatic2_create --fourk foo.mp4");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
        BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
        BOOST_CHECK_EQUAL (cc.fourk, true);
        BOOST_CHECK (!cc.error);
+
+       cc = run ("dcpomatic2_create --j2k-bandwidth 120 foo.mp4");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
+       BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
+       BOOST_REQUIRE (cc.j2k_bandwidth);
+       BOOST_CHECK_EQUAL (*cc.j2k_bandwidth, 120000000);
+       BOOST_CHECK (!cc.error);
+
+       cc = run ("dcpomatic2_create --channel L fred.wav --channel R jim.wav sheila.wav");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
+       BOOST_CHECK_EQUAL (cc.content[0].path, "fred.wav");
+       BOOST_CHECK (cc.content[0].channel);
+       BOOST_CHECK (*cc.content[0].channel == dcp::Channel::LEFT);
+       BOOST_CHECK_EQUAL (cc.content[1].path, "jim.wav");
+       BOOST_CHECK (cc.content[1].channel);
+       BOOST_CHECK (*cc.content[1].channel == dcp::Channel::RIGHT);
+       BOOST_CHECK_EQUAL (cc.content[2].path, "sheila.wav");
+       BOOST_CHECK (!cc.content[2].channel);
+
+       cc = run ("dcpomatic2_create --channel foo fred.wav");
+       BOOST_REQUIRE (cc.error);
+       BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: foo is not valid for --channel"));
+
+       cc = run ("dcpomatic2_create fred.wav --gain -6 jim.wav --gain 2 sheila.wav");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
+       BOOST_CHECK_EQUAL (cc.content[0].path, "fred.wav");
+       BOOST_CHECK (!cc.content[0].gain);
+       BOOST_CHECK_EQUAL (cc.content[1].path, "jim.wav");
+       BOOST_CHECK_CLOSE (*cc.content[1].gain, -6, 0.001);
+       BOOST_CHECK_EQUAL (cc.content[2].path, "sheila.wav");
+       BOOST_CHECK_CLOSE (*cc.content[2].gain, 2, 0.001);
+
+       cc = run("dcpomatic2_create --cpl 123456-789-0 dcp");
+       BOOST_REQUIRE_EQUAL(cc.content.size(), 1U);
+       BOOST_CHECK_EQUAL(cc.content[0].path, "dcp");
+       BOOST_REQUIRE(static_cast<bool>(cc.content[0].cpl));
+       BOOST_CHECK_EQUAL(*cc.content[0].cpl, "123456-789-0");
 }