Skip to content

Commit

Permalink
#5 Applied fix using lambda for throwing constructors in our tests. (…
Browse files Browse the repository at this point in the history
…Reference #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.
  • Loading branch information
AlexisWilke committed Feb 26, 2017
1 parent 704eb38 commit 71472de
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 21 deletions.
47 changes: 43 additions & 4 deletions 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.

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions cmake/FindCatch.cmake
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions 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 <alexis@m2osw.com> Sun, 19 Feb 2017 22:02:22 -0700

zipios (2.1.4.0~xenial) xenial; urgency=high

* Replaced readdir_r() with readdir().
Expand Down
4 changes: 2 additions & 2 deletions src/backbuffer.hpp
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions tests/backbuffer.cpp
Expand Up @@ -69,17 +69,23 @@ 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);
}
}

THEN("we close the file and we get an exception")
{
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);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions tests/virtualseeker.cpp
Expand Up @@ -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
Expand Down
36 changes: 27 additions & 9 deletions tests/zipfile.cpp
Expand Up @@ -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);
}


Expand All @@ -92,7 +94,9 @@ TEST_CASE("A ZipFile with an invalid file", "[ZipFile] [FileCollection]")
os << static_cast<char>(rand());
}
}
REQUIRE_THROWS_AS(zipios::ZipFile zf("invalid.zip"), zipios::FileCollectionException);
REQUIRE_THROWS_AS([&](){
zipios::ZipFile zf("invalid.zip");
}, zipios::FileCollectionException);
}


Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 71472de

Please sign in to comment.