Throw an exception on making a DCP with no reels.
authorCarl Hetherington <cth@carlh.net>
Sun, 13 Dec 2020 20:22:00 +0000 (21:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 Jan 2021 19:13:22 +0000 (20:13 +0100)
src/cpl.cc
src/exceptions.cc
src/exceptions.h
test/cpl_ratings_test.cc

index b19d6d89bb6c4de4601c3e0a045f855a61ad679a..22abfb69b824348ccaf463861b9b7431771cdcfc 100644 (file)
@@ -198,6 +198,10 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
 
        auto reel_list = root->add_child ("ReelList");
 
+       if (_reels.empty()) {
+               throw NoReelsError ();
+       }
+
        bool first = true;
        for (auto i: _reels) {
                auto asset_list = i->write_to_cpl (reel_list, standard);
index ebe8609a0d5932966f3cf89a9d2783bb5561b6fd..37e699e6adb6836035685940c9c32e657c588f71 100644 (file)
@@ -169,3 +169,11 @@ UnknownChannelIdError::UnknownChannelIdError (std::string id)
 {
 
 }
+
+
+NoReelsError::NoReelsError ()
+       : runtime_error ("Cannot make a DCP when no reels have been added")
+{
+
+}
+
index b9bcfd3783a2e9772b1c9b19933b823e0fbfe0af..76a66808d3a83caa524576081380e8b9913b1382 100644 (file)
@@ -283,6 +283,12 @@ public:
 };
 
 
+class NoReelsError : public std::runtime_error
+{
+public:
+       NoReelsError ();
+};
+
 }
 
 #endif
index 931359b4ad8a5f57ae8163df0c8de4577deabce6..1cb6394eb34e3d611e47a5c92dca52c4e5bf949e 100644 (file)
@@ -38,6 +38,7 @@
 using std::list;
 using std::string;
 using std::vector;
+using std::shared_ptr;
 
 BOOST_AUTO_TEST_CASE (cpl_ratings)
 {
@@ -48,6 +49,9 @@ BOOST_AUTO_TEST_CASE (cpl_ratings)
        ratings.push_back (dcp::Rating("http://www.movielabs.com/md/ratings/GB/BBFC/1/12A%3C/Agency", "12A"));
        cpl.set_ratings (ratings);
 
+       shared_ptr<dcp::Reel> reel(new dcp::Reel());
+       cpl.add (reel);
+
        cpl.write_xml ("build/test/cpl_ratings.xml", dcp::SMPTE, std::shared_ptr<dcp::CertificateChain>());
 
        list<string> ignore;
@@ -81,7 +85,12 @@ BOOST_AUTO_TEST_CASE (cpl_ratings)
                "      <Label>12A</Label>\n"
                "    </Rating>\n"
                "  </RatingList>\n"
-               "  <ReelList/>\n"
+               "  <ReelList>\n"
+               "    <Reel>\n"
+               "      <Id>urn:uuid:56a781ed-ace3-4cdf-8391-93b1bcea54eb</Id>\n"
+               "      <AssetList/>\n"
+               "    </Reel>\n"
+               "  </ReelList>\n"
                "</CompositionPlaylist>\n",
                ignore
                );