Rework command-line parser for dcpomatic_create to allow options v2.13.103
authorCarl Hetherington <cth@carlh.net>
Wed, 16 Jan 2019 00:36:00 +0000 (00:36 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 16 Jan 2019 23:18:24 +0000 (23:18 +0000)
to be specified per content.  Use this to support 3D.

src/lib/create_cli.cc [new file with mode: 0644]
src/lib/create_cli.h [new file with mode: 0644]
src/lib/wscript
src/tools/dcpomatic_create.cc
test/create_cli_test.cc [new file with mode: 0644]
test/wscript

diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc
new file mode 100644 (file)
index 0000000..94e984f
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "create_cli.h"
+#include "dcp_content_type.h"
+#include "ratio.h"
+#include "compose.hpp"
+#include <dcp/raw_convert.h>
+#include <string>
+
+#include <iostream>
+
+using std::string;
+using std::cout;
+using boost::optional;
+
+string CreateCLI::_help =
+       "\nSyntax: %1 [OPTION] <CONTENT> [OPTION] [<CONTENT> ...]\n"
+       "  -v, --version                 show DCP-o-matic version\n"
+       "  -h, --help                    show this help\n"
+       "  -n, --name <name>             film name\n"
+       "  -t, --template <name>         template name\n"
+       "  -e, --encrypt                 make an encrypted DCP\n"
+       "  -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
+       "  -f, --dcp-frame-rate <rate>   set DCP video frame rate (otherwise guessed from content)\n"
+       "      --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
+       "      --content-ratio <ratio>   119, 133, 137, 138, 166, 178, 185 or 239\n"
+       "  -s, --still-length <n>        number of seconds that still content should last\n"
+       "      --standard <standard>     SMPTE or interop (default SMPTE)\n"
+       "      --no-use-isdcf-name       do not use an ISDCF name; use the specified name unmodified\n"
+       "      --no-sign                 do not sign the DCP\n"
+       "      --config <dir>            directory containing config.xml and cinemas.xml\n"
+       "  -o, --output <dir>            output directory\n"
+       "      --threed                  make a 3D DCP\n"
+       "      --left-eye                next piece of content is for the left eye\n"
+       "      --right-eye               next piece of content is for the right eye\n";
+
+template <class T>
+void
+argument_option (int& n, int argc, char* argv[], string short_name, string long_name, bool* claimed, optional<string>* error, T* out)
+{
+       string const a = argv[n];
+       if (a != short_name && a != long_name) {
+               return;
+       }
+
+       if ((n + 1) >= argc) {
+               **error = String::compose("%1: option %2 requires an argument", argv[0], long_name);
+               return;
+       }
+
+       *out = dcp::raw_convert<T>(string(argv[++n]));
+       *claimed = true;
+}
+
+CreateCLI::CreateCLI (int argc, char* argv[])
+       : version (false)
+       , encrypt (false)
+       , threed (false)
+       , dcp_content_type (0)
+       , dcp_frame_rate (24)
+       , container_ratio (0)
+       , content_ratio (0)
+       , still_length (10)
+       , standard (dcp::SMPTE)
+       , no_use_isdcf_name (false)
+       , no_sign (false)
+{
+       string dcp_content_type_string = "TST";
+       string content_ratio_string;
+       string container_ratio_string;
+       string standard_string = "SMPTE";
+       int dcp_frame_rate_int = 0;
+       string template_name_string;
+       string config_dir_string;
+       string output_dir_string;
+       VideoFrameType next_frame_type = VIDEO_FRAME_TYPE_2D;
+
+       int i = 1;
+       while (i < argc) {
+               string const a = argv[i];
+               bool claimed = false;
+
+               if (a == "-v" || a == "--version") {
+                       version = true;
+                       return;
+               } else if (a == "-h" || a == "--help") {
+                       error = "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
+                               "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
+                               "will be written to stdout.\n" + String::compose(_help, argv[0]);
+                       return;
+               }
+
+               if (a == "-e" || a == "--encrypt") {
+                       encrypt = claimed = true;
+               } else if (a == "--no-use-isdcf-name") {
+                       no_use_isdcf_name = claimed = true;
+               } else if (a == "--no-sign") {
+                       no_sign = claimed = true;
+               } else if (a == "--threed") {
+                       threed = claimed = true;
+               } else if (a == "--left-eye") {
+                       next_frame_type = VIDEO_FRAME_TYPE_3D_LEFT;
+                       claimed = true;
+               } else if (a == "--right-eye") {
+                       next_frame_type = VIDEO_FRAME_TYPE_3D_RIGHT;
+                       claimed = true;
+               }
+
+               argument_option(i, argc, argv, "-n", "--name",             &claimed, &error, &name);
+               argument_option(i, argc, argv, "-t", "--template",         &claimed, &error, &template_name_string);
+               argument_option(i, argc, argv, "-c", "--dcp-content-type", &claimed, &error, &dcp_content_type_string);
+               argument_option(i, argc, argv, "-f", "--dcp-frame-rate",   &claimed, &error, &dcp_frame_rate_int);
+               argument_option(i, argc, argv, "",   "--container-ratio",  &claimed, &error, &container_ratio_string);
+               argument_option(i, argc, argv, "",   "--content-ratio",    &claimed, &error, &content_ratio_string);
+               argument_option(i, argc, argv, "-s", "--still-length",     &claimed, &error, &still_length);
+               argument_option(i, argc, argv, "",   "--standard",         &claimed, &error, &standard_string);
+               argument_option(i, argc, argv, "",   "--config",           &claimed, &error, &config_dir_string);
+               argument_option(i, argc, argv, "-o", "--output",           &claimed, &error, &output_dir_string);
+
+               if (!claimed) {
+                       if (a.length() > 2 && a.substr(0, 2) == "--") {
+                               error = String::compose("%1: unrecognised option '%2'", argv[0], a) + String::compose(_help, argv[0]);
+                               return;
+                       } else {
+                               Content c;
+                               c.path = a;
+                               c.frame_type = next_frame_type;
+                               content.push_back (c);
+                               next_frame_type = VIDEO_FRAME_TYPE_2D;
+                       }
+               }
+
+               ++i;
+       }
+
+       if (!config_dir_string.empty()) {
+               config_dir = config_dir_string;
+       }
+
+       if (!output_dir_string.empty()) {
+               output_dir = output_dir_string;
+       }
+
+       if (!template_name_string.empty()) {
+               template_name = template_name_string;
+       }
+
+       if (dcp_frame_rate_int) {
+               dcp_frame_rate = dcp_frame_rate_int;
+       }
+
+       dcp_content_type = DCPContentType::from_isdcf_name(dcp_content_type_string);
+       if (!dcp_content_type) {
+               error = String::compose("%1: unrecognised DCP content type '%2'", argv[0], dcp_content_type_string);
+               return;
+       }
+
+       if (content_ratio_string.empty()) {
+               error = String::compose("%1: missing required option --content-ratio", argv[0]);
+               return;
+       }
+
+       content_ratio = Ratio::from_id (content_ratio_string);
+       if (!content_ratio) {
+               error = String::compose("%1: unrecognised content ratio %2", content_ratio_string);
+               return;
+       }
+
+       if (container_ratio_string.empty()) {
+               container_ratio_string = content_ratio_string;
+       }
+
+       container_ratio = Ratio::from_id (container_ratio_string);
+       if (!container_ratio) {
+               error = String::compose("%1: unrecognised container ratio %2", argv[0], container_ratio_string);
+               return;
+       }
+
+       if (standard_string != "SMPTE" && standard_string != "interop") {
+               error = String::compose("%1: standard must be SMPTE or interop", argv[0]);
+               return;
+       }
+
+       if (content.empty()) {
+               error = String::compose("%1: no content specified", argv[0]);
+               return;
+       }
+
+       if (name.empty()) {
+               name = content[0].path.leaf().string();
+       }
+}
diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h
new file mode 100644 (file)
index 0000000..1f1cb3c
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "types.h"
+#include <dcp/types.h>
+#include <boost/optional.hpp>
+#include <boost/filesystem.hpp>
+#include <vector>
+
+class DCPContentType;
+class Ratio;
+
+class CreateCLI
+{
+public:
+       CreateCLI (int argc, char* argv[]);
+
+       struct Content {
+               boost::filesystem::path path;
+               VideoFrameType frame_type;
+       };
+
+       bool version;
+       std::string name;
+       boost::optional<std::string> template_name;
+       bool encrypt;
+       bool threed;
+       DCPContentType const * dcp_content_type;
+       boost::optional<int> dcp_frame_rate;
+       Ratio const * container_ratio;
+       Ratio const * content_ratio;
+       int still_length;
+       dcp::Standard standard;
+       bool no_use_isdcf_name;
+       bool no_sign;
+       boost::optional<boost::filesystem::path> config_dir;
+       boost::optional<boost::filesystem::path> output_dir;
+       boost::optional<std::string> error;
+       std::vector<Content> content;
+
+private:
+       static std::string _help;
+};
index b78f093cfcaa32bc4bb785a6292cac15c2c82068..9e20131a8d7fd463f30c49abbfacc80af1d1533a 100644 (file)
@@ -51,6 +51,7 @@ sources = """
           config.cc
           content.cc
           content_factory.cc
+          create_cli.cc
           cross.cc
           crypto.cc
           curl_uploader.cc
index 4519d8b995e2266feeec156ff87191f338c3366b..9331602d588e54b9129ca9d593a3cb95edb78a8a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -32,6 +32,8 @@
 #include "lib/cross.h"
 #include "lib/config.h"
 #include "lib/dcp_content.h"
+#include "lib/create_cli.h"
+#include "lib/version.h"
 #include <dcp/exceptions.h>
 #include <libxml++/libxml++.h>
 #include <boost/filesystem.hpp>
@@ -51,37 +53,6 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
 
-static void
-syntax (string n)
-{
-       cerr << "Syntax: " << n << " [OPTION] <CONTENT> [<CONTENT> ...]\n"
-            << "  -v, --version                 show DCP-o-matic version\n"
-            << "  -h, --help                    show this help\n"
-            << "  -n, --name <name>             film name\n"
-            << "  -t, --template <name>         template name\n"
-            << "  -e, --encrypt                 make an encrypted DCP\n"
-            << "  -c, --dcp-content-type <type> FTR, SHR, TLR, TST, XSN, RTG, TSR, POL, PSA or ADV\n"
-            << "  -f, --dcp-frame-rate <rate>   set DCP video frame rate (otherwise guessed from content)\n"
-            << "      --container-ratio <ratio> 119, 133, 137, 138, 166, 178, 185 or 239\n"
-            << "      --content-ratio <ratio>   119, 133, 137, 138, 166, 178, 185 or 239\n"
-            << "  -s, --still-length <n>        number of seconds that still content should last\n"
-            << "      --standard <standard>     SMPTE or interop (default SMPTE)\n"
-            << "      --no-use-isdcf-name       do not use an ISDCF name; use the specified name unmodified\n"
-            << "      --no-sign                 do not sign the DCP\n"
-            << "      --config <dir>            directory containing config.xml and cinemas.xml\n"
-            << "  -o, --output <dir>            output directory\n";
-}
-
-static void
-help (string n)
-{
-       cerr << "Create a film directory (ready for making a DCP) or metadata file from some content files.\n"
-            << "A film directory will be created if -o or --output is specified, otherwise a metadata file\n"
-            << "will be written to stdout.\n";
-
-       syntax (n);
-}
-
 class SimpleSignalManager : public SignalManager
 {
 public:
@@ -97,164 +68,40 @@ main (int argc, char* argv[])
        dcpomatic_setup_path_encoding ();
        dcpomatic_setup ();
 
-       string name;
-       optional<string> template_name;
-       bool encrypt = false;
-       DCPContentType const * dcp_content_type = DCPContentType::from_isdcf_name ("TST");
-       optional<int> dcp_frame_rate;
-       Ratio const * container_ratio = 0;
-       Ratio const * content_ratio = 0;
-       int still_length = 10;
-       dcp::Standard standard = dcp::SMPTE;
-       optional<boost::filesystem::path> output;
-       bool sign = true;
-       bool use_isdcf_name = true;
-       optional<boost::filesystem::path> config;
-
-       int option_index = 0;
-       while (true) {
-               static struct option long_options[] = {
-                       { "version", no_argument, 0, 'v'},
-                       { "help", no_argument, 0, 'h'},
-                       { "name", required_argument, 0, 'n'},
-                       { "template", required_argument, 0, 't'},
-                       { "encrypt", no_argument, 0, 'e'},
-                       { "dcp-content-type", required_argument, 0, 'c'},
-                       { "dcp-frame-rate", required_argument, 0, 'f'},
-                       { "container-ratio", required_argument, 0, 'A'},
-                       { "content-ratio", required_argument, 0, 'B'},
-                       { "still-length", required_argument, 0, 's'},
-                       { "standard", required_argument, 0, 'C'},
-                       { "no-use-isdcf-name", no_argument, 0, 'D'},
-                       { "no-sign", no_argument, 0, 'E'},
-                       { "output", required_argument, 0, 'o'},
-                       { "config", required_argument, 0, 'F'},
-                       { 0, 0, 0, 0}
-               };
-
-               int c = getopt_long (argc, argv, "vhn:t:ec:f:A:B:C:s:o:DEF:", long_options, &option_index);
-               if (c == -1) {
-                       break;
-               }
-
-               switch (c) {
-               case 'v':
-                       cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
-                       exit (EXIT_SUCCESS);
-               case 'h':
-                       help (argv[0]);
-                       exit (EXIT_SUCCESS);
-               case 'n':
-                       name = optarg;
-                       break;
-               case 't':
-                       template_name = optarg;
-                       break;
-               case 'e':
-                       encrypt = true;
-                       break;
-               case 'c':
-                       dcp_content_type = DCPContentType::from_isdcf_name (optarg);
-                       if (dcp_content_type == 0) {
-                               cerr << "Bad DCP content type.\n";
-                               syntax (argv[0]);
-                               exit (EXIT_FAILURE);
-                       }
-                       break;
-               case 'f':
-                       dcp_frame_rate = atoi (optarg);
-                       break;
-               case 'A':
-                       container_ratio = Ratio::from_id (optarg);
-                       if (container_ratio == 0) {
-                               cerr << "Bad container ratio.\n";
-                               syntax (argv[0]);
-                               exit (EXIT_FAILURE);
-                       }
-                       break;
-               case 'B':
-                       content_ratio = Ratio::from_id (optarg);
-                       if (content_ratio == 0) {
-                               cerr << "Bad content ratio " << optarg << ".\n";
-                               syntax (argv[0]);
-                               exit (EXIT_FAILURE);
-                       }
-                       break;
-               case 'C':
-                       if (strcmp (optarg, "interop") == 0) {
-                               standard = dcp::INTEROP;
-                       } else if (strcmp (optarg, "SMPTE") != 0) {
-                               cerr << "Bad standard " << optarg << ".\n";
-                               syntax (argv[0]);
-                               exit (EXIT_FAILURE);
-                       }
-                       break;
-               case 'D':
-                       use_isdcf_name = false;
-                       break;
-               case 'E':
-                       sign = false;
-                       break;
-               case 'F':
-                       config = optarg;
-                       break;
-               case 's':
-                       still_length = atoi (optarg);
-                       break;
-               case 'o':
-                       output = optarg;
-                       break;
-               case '?':
-                       syntax (argv[0]);
-                       exit (EXIT_FAILURE);
-               }
+       CreateCLI cc (argc, argv);
+       if (cc.error) {
+               cerr << *cc.error << "\n";
+               exit (1);
        }
 
-       if (optind > argc) {
-               help (argv[0]);
-               exit (EXIT_FAILURE);
+       if (cc.version) {
+               cerr << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
+               exit (1);
        }
 
-       if (config) {
-               Config::override_path = *config;
-       }
-
-       if (!content_ratio) {
-               cerr << argv[0] << ": missing required option --content-ratio.\n";
-               exit (EXIT_FAILURE);
-       }
-
-       if (!container_ratio) {
-               container_ratio = content_ratio;
-       }
-
-       if (optind == argc) {
-               cerr << argv[0] << ": no content specified.\n";
-               exit (EXIT_FAILURE);
+       if (cc.config_dir) {
+               Config::override_path = *cc.config_dir;
        }
 
        signal_manager = new SimpleSignalManager ();
-
-       if (name.empty ()) {
-               name = boost::filesystem::path (argv[optind]).leaf().string ();
-       }
+       JobManager* jm = JobManager::instance ();
 
        try {
-               shared_ptr<Film> film (new Film (output));
-               if (template_name) {
-                       film->use_template (template_name.get());
+               shared_ptr<Film> film (new Film(cc.output_dir));
+               if (cc.template_name) {
+                       film->use_template (cc.template_name.get());
                }
-               film->set_name (name);
+               film->set_name (cc.name);
 
-               film->set_container (container_ratio);
-               film->set_dcp_content_type (dcp_content_type);
-               film->set_interop (standard == dcp::INTEROP);
-               film->set_use_isdcf_name (use_isdcf_name);
-               film->set_signed (sign);
-               film->set_encrypted (encrypt);
+               film->set_container (cc.container_ratio);
+               film->set_dcp_content_type (cc.dcp_content_type);
+               film->set_interop (cc.standard == dcp::INTEROP);
+               film->set_use_isdcf_name (!cc.no_use_isdcf_name);
+               film->set_signed (!cc.no_sign);
+               film->set_encrypted (cc.encrypt);
 
-               for (int i = optind; i < argc; ++i) {
-                       boost::filesystem::path const can = boost::filesystem::canonical (argv[i]);
+               BOOST_FOREACH (CreateCLI::Content i, cc.content) {
+                       boost::filesystem::path const can = boost::filesystem::canonical (i.path);
                        list<shared_ptr<Content> > content;
 
                        if (boost::filesystem::exists (can / "ASSETMAP") || (boost::filesystem::exists (can / "ASSETMAP.xml"))) {
@@ -265,48 +112,48 @@ main (int argc, char* argv[])
                        }
 
                        BOOST_FOREACH (shared_ptr<Content> j, content) {
-                               if (j->video) {
-                                       j->video->set_scale (VideoContentScale (content_ratio));
-                               }
                                film->examine_and_add_content (j);
                        }
-               }
 
-               JobManager* jm = JobManager::instance ();
+                       while (jm->work_to_do ()) {
+                               dcpomatic_sleep (1);
+                       }
 
-               while (jm->work_to_do ()) {
-                       dcpomatic_sleep (1);
-               }
+                       while (signal_manager->ui_idle() > 0) {}
 
-               while (signal_manager->ui_idle() > 0) {}
+                       BOOST_FOREACH (shared_ptr<Content> j, content) {
+                               if (j->video) {
+                                       j->video->set_scale (VideoContentScale(cc.content_ratio));
+                                       j->video->set_frame_type (i.frame_type);
+                               }
+                       }
+               }
 
-               if (dcp_frame_rate) {
-                       film->set_video_frame_rate (*dcp_frame_rate);
+               if (cc.dcp_frame_rate) {
+                       film->set_video_frame_rate (*cc.dcp_frame_rate);
                }
 
-               ContentList content = film->content ();
-               for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
-                       shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
+               BOOST_FOREACH (shared_ptr<Content> i, film->content()) {
+                       shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
                        if (ic && ic->still()) {
-                               ic->video->set_length (still_length * 24);
+                               ic->video->set_length (cc.still_length * 24);
                        }
                }
 
                if (jm->errors ()) {
-                       list<shared_ptr<Job> > jobs = jm->get ();
-                       for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) {
-                               if ((*i)->finished_in_error ()) {
-                                       cerr << (*i)->error_summary () << "\n"
-                                            << (*i)->error_details () << "\n";
+                       BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
+                               if (i->finished_in_error()) {
+                                       cerr << i->error_summary() << "\n"
+                                            << i->error_details() << "\n";
                                }
                        }
                        exit (EXIT_FAILURE);
                }
 
-               if (output) {
+               if (cc.output_dir) {
                        film->write_metadata ();
                } else {
-                       film->metadata()->write_to_stream_formatted (cout, "UTF-8");
+                       film->metadata()->write_to_stream_formatted(cout, "UTF-8");
                }
        } catch (exception& e) {
                cerr << argv[0] << ": " << e.what() << "\n";
diff --git a/test/create_cli_test.cc b/test/create_cli_test.cc
new file mode 100644 (file)
index 0000000..15fe625
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "lib/create_cli.h"
+#include "lib/ratio.h"
+#include "lib/dcp_content_type.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <iostream>
+
+using std::string;
+
+static CreateCLI
+run (string cmd)
+{
+       /* This approximates the logic which splits command lines up into argc/argv */
+
+       boost::escaped_list_separator<char> els ("", " ", "\"\'");
+       boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);
+
+       char** argv = new char*[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);
+
+       for (int i = 0; i < argc; ++i) {
+               free (argv[i]);
+       }
+
+       delete[] argv;
+
+       return cc;
+}
+
+BOOST_AUTO_TEST_CASE (create_cli_test)
+{
+       CreateCLI cc = run ("dcpomatic2_create --version");
+       BOOST_CHECK (!cc.error);
+       BOOST_CHECK (cc.version);
+
+       cc = run ("dcpomatic2_create --versionX");
+       BOOST_REQUIRE (cc.error);
+       BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: unrecognised option '--versionX'"));
+
+       cc = run ("dcpomatic2_create --help");
+       BOOST_REQUIRE (cc.error);
+
+       cc = run ("dcpomatic2_create -h");
+       BOOST_REQUIRE (cc.error);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --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");
+       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");
+       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");
+       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");
+       BOOST_CHECK (cc.error);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --content-ratio 239");
+       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);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --still-length 42");
+       BOOST_CHECK (!cc.error);
+       BOOST_CHECK_EQUAL (cc.still_length, 42);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTE");
+       BOOST_CHECK (!cc.error);
+       BOOST_CHECK_EQUAL (cc.standard, dcp::SMPTE);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTEX");
+       BOOST_CHECK (cc.error);
+
+       cc = run ("dcpomatic2_create x --content-ratio 185 --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");
+       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");
+       BOOST_CHECK (cc.error);
+
+       cc = run ("dcpomatic2_create --content-ratio 185 --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_CHECK_EQUAL (cc.content[0].path, "fred");
+       BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_2D);
+       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[2].path, "sheila");
+       BOOST_CHECK_EQUAL (cc.content[2].frame_type, VIDEO_FRAME_TYPE_2D);
+
+       cc = run ("dcpomatic2_create --content-ratio 185 --left-eye left.mp4 --right-eye right.mp4");
+       BOOST_REQUIRE_EQUAL (cc.content.size(), 2);
+       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[1].path, "right.mp4");
+       BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_3D_RIGHT);
+}
index 396c713d12639dbf0bc6d7ad0753926a3b9fbfdf..8059ae2d35244d9aa0b003eb98afc99c309dd40d 100644 (file)
@@ -57,6 +57,7 @@ def build(bld):
                  colour_conversion_test.cc
                  config_test.cc
                  content_test.cc
+                 create_cli_test.cc
                  crypto_test.cc
                  dcpomatic_time_test.cc
                  dcp_playback_test.cc