2 Copyright (C) 2020-2021 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/>.
22 /** @file test/zipper_test.cc
23 * @brief Test Zipper class.
24 * @ingroup selfcontained
28 #include "lib/exceptions.h"
29 #include "lib/zipper.h"
32 #include <boost/test/unit_test.hpp>
33 #include <boost/filesystem.hpp>
36 /** Basic test of Zipper working normally */
37 BOOST_AUTO_TEST_CASE (zipper_test1)
39 boost::system::error_code ec;
40 boost::filesystem::remove ("build/test/zipped.zip", ec);
42 Zipper zipper ("build/test/zipped.zip");
43 zipper.add ("foo.txt", "1234567890");
44 zipper.add ("bar.txt", "xxxxxxCCCCbbbbbbb1");
47 boost::filesystem::remove_all ("build/test/zipper_test1", ec);
48 #ifdef DCPOMATIC_WINDOWS
49 /* unzip on windows crashes every so often (with a return code -1073740940, for some reason)
50 * so try using the built-in tar which can unzip things.
52 boost::filesystem::create_directories ("build/test/zipper_test1");
53 int const r = system ("tar -xf build\\test\\zipped.zip -C build\\test\\zipper_test1");
55 int const r = system ("unzip build/test/zipped.zip -d build/test/zipper_test1");
57 BOOST_REQUIRE_EQUAL (r, 0);
59 BOOST_CHECK_EQUAL (dcp::file_to_string("build/test/zipper_test1/foo.txt"), "1234567890");
60 BOOST_CHECK_EQUAL (dcp::file_to_string("build/test/zipper_test1/bar.txt"), "xxxxxxCCCCbbbbbbb1");
64 /** Test failure when trying to overwrite a file */
65 BOOST_AUTO_TEST_CASE (zipper_test2, * boost::unit_test::depends_on("zipper_test1"))
67 BOOST_CHECK_THROW (Zipper("build/test/zipped.zip"), FileError);