2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file test/zipper_test.cc
22 * @brief Test Zipper class.
23 * @ingroup selfcontained
26 #include "lib/zipper.h"
27 #include "lib/exceptions.h"
30 #include <boost/test/unit_test.hpp>
31 #include <boost/filesystem.hpp>
33 /** Basic test of Zipper working normally */
34 BOOST_AUTO_TEST_CASE (zipper_test1)
36 boost::system::error_code ec;
37 boost::filesystem::remove ("build/test/zipped.zip", ec);
39 Zipper zipper ("build/test/zipped.zip");
40 zipper.add ("foo.txt", "1234567890");
41 zipper.add ("bar.txt", "xxxxxxCCCCbbbbbbb1");
44 boost::filesystem::remove_all ("build/test/zipper_test1", ec);
45 #ifdef DCPOMATIC_WINDOWS
46 /* unzip on windows crashes every so often (with a return code -1073740940, for some reason)
47 * so try using the built-in tar which can unzip things.
49 boost::filesystem::create_directories ("build/test/zipper_test1");
50 int const r = system ("tar -xf build\\test\\zipped.zip -C build\\test\\zipper_test1");
52 int const r = system ("unzip build/test/zipped.zip -d build/test/zipper_test1");
54 BOOST_REQUIRE_EQUAL (r, 0);
56 BOOST_CHECK_EQUAL (dcp::file_to_string("build/test/zipper_test1/foo.txt"), "1234567890");
57 BOOST_CHECK_EQUAL (dcp::file_to_string("build/test/zipper_test1/bar.txt"), "xxxxxxCCCCbbbbbbb1");
61 /** Test failure when trying to overwrite a file */
62 BOOST_AUTO_TEST_CASE (zipper_test2, * boost::unit_test::depends_on("zipper_test1"))
64 BOOST_CHECK_THROW (Zipper("build/test/zipped.zip"), FileError);