summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-01-05 20:03:43 +0000
committerCarl Hetherington <cth@carlh.net>2018-01-05 20:03:43 +0000
commitad59559fdd19f89852eebd94299691e6091ff02f (patch)
treefcdbebfdfd0b25f2a071d0104450748f4ac56f64 /test
parent66469adf1bd6e5c288542dda601a66b22d955794 (diff)
Backup more than one config on failure to load.
Diffstat (limited to 'test')
-rw-r--r--test/config_test.cc90
-rw-r--r--test/wscript1
2 files changed, 91 insertions, 0 deletions
diff --git a/test/config_test.cc b/test/config_test.cc
new file mode 100644
index 000000000..25e8c7d9d
--- /dev/null
+++ b/test/config_test.cc
@@ -0,0 +1,90 @@
+/*
+ Copyright (C) 2018 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/config.h"
+#include <boost/test/unit_test.hpp>
+#include <fstream>
+
+using std::ofstream;
+
+static void
+rewrite_bad_config ()
+{
+ boost::system::error_code ec;
+ boost::filesystem::remove ("build/test/config.xml", ec);
+
+ Config::test_path = "build/test";
+ ofstream f ("build/test/config.xml");
+ f << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<Config>\n"
+ << "<Foo></Foo>\n"
+ << "</Config>\n";
+ f.close ();
+}
+
+
+BOOST_AUTO_TEST_CASE (config_backup_test)
+{
+ Config::drop();
+
+ boost::system::error_code ec;
+ boost::filesystem::remove ("build/test/config.xml.1", ec);
+ boost::filesystem::remove ("build/test/config.xml.2", ec);
+ boost::filesystem::remove ("build/test/config.xml.3", ec);
+ boost::filesystem::remove ("build/test/config.xml.4", ec);
+ boost::filesystem::remove ("build/test/config.xml.5", ec);
+ boost::filesystem::remove ("build/test/config.xml.5", ec);
+
+ rewrite_bad_config();
+
+ Config::instance();
+
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.1"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.2"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.3"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.4"));
+
+ Config::drop();
+ rewrite_bad_config();
+ Config::instance();
+
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.1"));
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.2"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.3"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.4"));
+
+ Config::drop();
+ rewrite_bad_config();
+ Config::instance();
+
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.1"));
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.2"));
+ BOOST_CHECK ( boost::filesystem::exists ("build/test/config.xml.3"));
+ BOOST_CHECK (!boost::filesystem::exists ("build/test/config.xml.4"));
+
+ Config::drop();
+ rewrite_bad_config();
+ Config::instance();
+
+ BOOST_CHECK (boost::filesystem::exists ("build/test/config.xml.1"));
+ BOOST_CHECK (boost::filesystem::exists ("build/test/config.xml.2"));
+ BOOST_CHECK (boost::filesystem::exists ("build/test/config.xml.3"));
+ BOOST_CHECK (boost::filesystem::exists ("build/test/config.xml.4"));
+}
diff --git a/test/wscript b/test/wscript
index ecbc32fab..f0533cfa1 100644
--- a/test/wscript
+++ b/test/wscript
@@ -52,6 +52,7 @@ def build(bld):
butler_test.cc
client_server_test.cc
colour_conversion_test.cc
+ config_test.cc
content_test.cc
dcpomatic_time_test.cc
dcp_subtitle_test.cc