X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fconfig_test.cc;h=103a6a58555ac0f181353afac8f6f257c14f495d;hb=4d795ebc688f711e8ff3e475537a85e941326cca;hp=6a65deb2e1a95f638dee2bb991aae5c92a094a51;hpb=ec2f9869126bb5fa19c21e5272456976e7b7ad8a;p=dcpomatic.git diff --git a/test/config_test.cc b/test/config_test.cc index 6a65deb2e..103a6a585 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -26,10 +26,10 @@ #include -using std::list; -using std::ofstream; using std::make_shared; +using std::ofstream; using std::string; +using std::vector; using boost::optional; @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test) boost::filesystem::copy_file ("test/data/2.14.cinemas.xml", dir / "cinemas.xml"); Config::instance(); try { - /* This will fail to write cinemas.xml since the link is to a non-existant directory */ + /* This will fail to write cinemas.xml since the link is to a non-existent directory */ Config::instance()->write(); } catch (...) {} @@ -196,6 +196,8 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test) BOOST_AUTO_TEST_CASE (config_keep_cinemas_if_making_new_config) { + ConfigRestorer cr; + boost::filesystem::path dir = "build/test/config_keep_cinemas_if_making_new_config"; Config::override_path = dir; Config::drop (); @@ -204,7 +206,7 @@ BOOST_AUTO_TEST_CASE (config_keep_cinemas_if_making_new_config) Config::instance()->write(); - Config::instance()->add_cinema(make_shared("My Great Cinema", list(), "", 0, 0)); + Config::instance()->add_cinema(make_shared("My Great Cinema", vector(), "", 0, 0)); Config::instance()->write(); boost::filesystem::copy_file (dir / "cinemas.xml", dir / "backup_for_test.xml"); @@ -213,6 +215,37 @@ BOOST_AUTO_TEST_CASE (config_keep_cinemas_if_making_new_config) boost::filesystem::remove (dir / "2.16" / "config.xml"); Config::instance(); - check_text_file (dir / "backup_for_test.xml", dir / "cinemas.xml.1"); + check_text_file(dir / "backup_for_test.xml", dir / "cinemas.xml"); +} + + +BOOST_AUTO_TEST_CASE(keep_config_if_cinemas_fail_to_load) +{ + ConfigRestorer cr; + + /* Make a new config */ + boost::filesystem::path dir = "build/test/keep_config_if_cinemas_fail_to_load"; + Config::override_path = dir; + Config::drop(); + boost::filesystem::remove_all(dir); + boost::filesystem::create_directories(dir); + Config::instance()->write(); + + auto const cinemas = dir / "cinemas.xml"; + + /* Back things up */ + boost::filesystem::copy_file(dir / "2.16" / "config.xml", dir / "config_backup_for_test.xml"); + boost::filesystem::copy_file(cinemas, dir / "cinemas_backup_for_test.xml"); + + /* Corrupt the cinemas */ + Config::drop(); + std::ofstream corrupt(cinemas.string().c_str()); + corrupt << "foo\n"; + corrupt.close(); + Config::instance(); + + /* We should have a new cinemas.xml and the old config.xml */ + check_text_file(dir / "2.16" / "config.xml", dir / "config_backup_for_test.xml"); + check_text_file(cinemas, dir / "cinemas_backup_for_test.xml"); }