From 71472defcf0728aaedf105c9d6b2de8cab247654 Mon Sep 17 00:00:00 2001 From: AlexisWilke Date: Sat, 25 Feb 2017 17:57:27 -0800 Subject: [PATCH] #5 Applied fix using lambda for throwing constructors in our tests. (Reference https://github.com/Zipios/Zipios/issues/5) Updated the README.md to include instructions on how to install each dependency. Fixed the FindCatch.cmake for Fedora, the catch.hpp is in a sub-folder. --- README.md | 47 +++++++++++++++++++++++++++++++++++++---- cmake/FindCatch.cmake | 4 ++++ debian/changelog | 10 +++++++++ src/backbuffer.hpp | 4 ++-- tests/backbuffer.cpp | 12 ++++++++--- tests/virtualseeker.cpp | 12 ++++++++--- tests/zipfile.cpp | 36 +++++++++++++++++++++++-------- 7 files changed, 104 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 98e0e22..9a5fd5f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Introduction -Zipios++ is a small C++ library for reading and writing zip files. The +Zipios is a small C++ library for reading and writing zip files. The structure and public interface are based (somewhat loosely) on the `java.util.zip` package. The streams created to access the individual entries in a zip file are based on the standard iostream library. -Zipios++ also provides a way for an application to support files from +Zipios also provides a way for an application to support files from multiple sources (e.g. from zip files or from ordinary directories) transparently. @@ -17,13 +17,49 @@ License (LGPL). Requires **zlib** ([http://www.zlib.org](http://www.zlib.org)). + # Debian/Ubuntu + sudo apt-get install zlib-dev + + # Fedora/RPM based systems + sudo dnf install zlib-devel + To run the automatic unit test suite you need **Catch** ([https://github.com/philsquared/Catch](https://github.com/philsquared/Catch)) + + # Debian/Ubuntu + sudo apt-get install catch + + # Fedora/RPM based systems + sudo dnf install catch-devel + The tests also require the *zip* command line tool. + # Debian/Ubuntu + sudo apt-get install zip + + # Fedora/RPM based systems + sudo dnf install zip + To build the projects, we use a C++ compiler (tested with **g++** and **clang**) as well as **cmake**. + # Debian/Ubuntu + sudo apt-get install g++ + sudo apt-get install cmake + + # Fedora/RPM based systems + sudo dnf install gcc-c++ + sudo dnf install cmake + +By default, the CMakeLists.txt knows to skip building the documentation. +This happens if `doxygen` and `graphviz` are not both installed. + + # Debian/Ubuntu + sudo apt-get install doxygen graphviz + + # Fedora/RPM based systems + sudo dnf install doxygen graphviz + # Installation @@ -37,7 +73,7 @@ The following options are supported: - `zipios_project_COVERAGE` (OFF by default) - `BUILD_ZIPIOS_TESTS` (ON by default) -In order to build Zipios++ as a static library, specify: +In order to build Zipios as a static library, specify: -DBUILD_SHARED_LIBS:BOOL=OFF @@ -56,6 +92,7 @@ the tests (i.e. nightly build). In that case you may turn them off with: -DBUILD_ZIPIOS_TESTS:BOOL=OFF + ## Unix Once you have `cmake` installed, you should be able to run the following @@ -68,6 +105,8 @@ under Unix: make make install +_(See the `zipios/dev/build` script for an example script.)_ + The project comes with a build script (see `dev/build`) that can be used to run those steps. It will assume that you do not mind to have your `BUILD` directory blown away and rebuilds everything. It also may setup various @@ -82,7 +121,7 @@ For details about available installation configurations of cmake packages refer to the CMake documentation online [http://www.cmake.org/](http://www.cmake.org/) -By default, `make install` installs the Zipios++ 2.1+ header files under +By default, `make install` installs the Zipios 2.1+ header files under `/usr/include/zipios/` and the library `libzipios.so` under `/usr/lib/`. You can choose another base path than `/usr/` using the following option on the `cmake` command line: diff --git a/cmake/FindCatch.cmake b/cmake/FindCatch.cmake index d5a7450..bb369b0 100644 --- a/cmake/FindCatch.cmake +++ b/cmake/FindCatch.cmake @@ -26,12 +26,16 @@ SET(CATCH_FOUND "NO") +# The PATH_SUFFXES is necessary under Fedora +# FIND_PATH(CATCH_INCLUDE_DIR catch.hpp PATHS ${CMAKE_SOURCE_DIR}/contrib /usr/local/include /usr/include + PATH_SUFFIXES + catch ) IF(CATCH_INCLUDE_DIR) diff --git a/debian/changelog b/debian/changelog index 279aac7..8ed586b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +zipios (2.1.5.0~xenial) xenial; urgency=high + + * Applied fix using lambda for throwing constructors in our tests. + (Reference https://github.com/Zipios/Zipios/issues/5) + * Updated the README.md to include instructions on how to install each + dependency. + * Fixed the FindCatch.cmake for Fedora, the catch.hpp is in a sub-folder. + + -- Alexis Wilke Sun, 19 Feb 2017 22:02:22 -0700 + zipios (2.1.4.0~xenial) xenial; urgency=high * Replaced readdir_r() with readdir(). diff --git a/src/backbuffer.hpp b/src/backbuffer.hpp index 370b4cd..4e52fc9 100644 --- a/src/backbuffer.hpp +++ b/src/backbuffer.hpp @@ -41,9 +41,9 @@ namespace zipios class BackBuffer : public ::zipios::buffer_t { public: - BackBuffer(std::istream& is, VirtualSeeker const& vs = VirtualSeeker(), ssize_t const chunk_size = 1024); + BackBuffer(std::istream & is, VirtualSeeker const & vs = VirtualSeeker(), ssize_t const chunk_size = 1024); - ssize_t readChunk(ssize_t& read_pointer); + ssize_t readChunk(ssize_t & read_pointer); private: VirtualSeeker m_vs; diff --git a/tests/backbuffer.cpp b/tests/backbuffer.cpp index 22e9a85..d843a0e 100644 --- a/tests/backbuffer.cpp +++ b/tests/backbuffer.cpp @@ -69,7 +69,9 @@ SCENARIO("BackBuffer read a file", "[BackBuffer]") { for(int i(-16); i <= 0; ++i) { - REQUIRE_THROWS_AS(zipios::BackBuffer bb(is, zipios::VirtualSeeker(), i), zipios::InvalidException); + REQUIRE_THROWS_AS([&](){ + zipios::BackBuffer bb(is, zipios::VirtualSeeker(), i); + }, zipios::InvalidException); } } @@ -77,9 +79,13 @@ SCENARIO("BackBuffer read a file", "[BackBuffer]") { is.close(); // first time the seek fails - REQUIRE_THROWS_AS(zipios::BackBuffer bb(is), zipios::IOException); + REQUIRE_THROWS_AS([&](){ + zipios::BackBuffer bb(is); + }, zipios::IOException); // second time the file is marked as invalid - REQUIRE_THROWS_AS(zipios::BackBuffer bb(is), zipios::InvalidException); + REQUIRE_THROWS_AS([&](){ + zipios::BackBuffer bb(is); + }, zipios::InvalidException); } } } diff --git a/tests/virtualseeker.cpp b/tests/virtualseeker.cpp index 1d3ade4..3a52b78 100644 --- a/tests/virtualseeker.cpp +++ b/tests/virtualseeker.cpp @@ -73,11 +73,17 @@ TEST_CASE("VirtualSeeker tests", "[zipios_common]") // note that the "gap" may be zero // attempt to create the seeker with invalid offsets - REQUIRE_THROWS_AS(zipios::VirtualSeeker vs(start_offset, -end), zipios::InvalidException); - REQUIRE_THROWS_AS(zipios::VirtualSeeker vs(-start_offset, -end), zipios::InvalidException); + REQUIRE_THROWS_AS([&](){ + zipios::VirtualSeeker vs(start_offset, -end); + }, zipios::InvalidException); + REQUIRE_THROWS_AS([&](){ + zipios::VirtualSeeker vs(-start_offset, -end); + }, zipios::InvalidException); if(start_offset != 0) { - REQUIRE_THROWS_AS(zipios::VirtualSeeker vs(-start_offset, end), zipios::InvalidException); + REQUIRE_THROWS_AS([&](){ + zipios::VirtualSeeker vs(-start_offset, end); + }, zipios::InvalidException); } // the end parameter to the VirtualSeeker is a "weird" position diff --git a/tests/zipfile.cpp b/tests/zipfile.cpp index c313a58..8a276b7 100644 --- a/tests/zipfile.cpp +++ b/tests/zipfile.cpp @@ -75,7 +75,9 @@ TEST_CASE("An Empty ZipFile", "[ZipFile] [FileCollection]") TEST_CASE("A ZipFile with an invalid name", "[ZipFile] [FileCollection]") { - REQUIRE_THROWS_AS(zipios::ZipFile zf("this/file/does/not/exists/so/the/constructor/throws"), zipios::IOException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("this/file/does/not/exists/so/the/constructor/throws"); + }, zipios::IOException); } @@ -92,7 +94,9 @@ TEST_CASE("A ZipFile with an invalid file", "[ZipFile] [FileCollection]") os << static_cast(rand()); } } - REQUIRE_THROWS_AS(zipios::ZipFile zf("invalid.zip"), zipios::FileCollectionException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("invalid.zip"); + }, zipios::FileCollectionException); } @@ -1240,7 +1244,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") // truncate the file to 'i' size truncate("file.zip", i); - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::FileCollectionException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::FileCollectionException); } } @@ -1267,7 +1273,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") size_t const five(5); truncate("file.zip", (22 + comment_len) - (rand() % std::min(five, comment_len) + 1)); - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::IOException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::IOException); } } @@ -1293,7 +1301,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") eocd.write(os); } - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::FileCollectionException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::FileCollectionException); } } @@ -1320,7 +1330,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") eocd.write(os); } - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::IOException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::IOException); } } @@ -1346,7 +1358,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") eocd.write(os); } - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::IOException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::IOException); } } @@ -1483,7 +1497,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") eocd.write(os); } - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::FileCollectionException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::FileCollectionException); } } @@ -1526,7 +1542,9 @@ TEST_CASE("Valid and Invalid ZipFile Archives", "[ZipFile] [FileCollection]") eocd.write(os); } - REQUIRE_THROWS_AS(zipios::ZipFile zf("file.zip"), zipios::FileCollectionException); + REQUIRE_THROWS_AS([&](){ + zipios::ZipFile zf("file.zip"); + }, zipios::FileCollectionException); } }