LCOV - code coverage report
Current view: top level - tests - catch_collectioncollection.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 516 516 100.0 %
Date: 2024-06-15 08:26:09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Zipios -- a small C++ library that provides easy access to .zip files.
       3             : 
       4             :   Copyright (C) 2000-2007  Thomas Sondergaard
       5             :   Copyright (c) 2015-2022  Made to Order Software Corp.  All Rights Reserved
       6             : 
       7             :   This library is free software; you can redistribute it and/or
       8             :   modify it under the terms of the GNU Lesser General Public
       9             :   License as published by the Free Software Foundation; either
      10             :   version 2.1 of the License, or (at your option) any later version.
      11             : 
      12             :   This library is distributed in the hope that it will be useful,
      13             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :   Lesser General Public License for more details.
      16             : 
      17             :   You should have received a copy of the GNU Lesser General Public
      18             :   License along with this library; if not, write to the Free Software
      19             :   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      20             : */
      21             : 
      22             : /** \file
      23             :  *
      24             :  * Zipios unit tests for the CollectionCollection class.
      25             :  */
      26             : 
      27             : #include "catch_main.hpp"
      28             : 
      29             : #include <zipios/collectioncollection.hpp>
      30             : #include <zipios/directorycollection.hpp>
      31             : #include <zipios/zipiosexceptions.hpp>
      32             : 
      33             : #include <fstream>
      34             : 
      35             : #include <string.h>
      36             : 
      37             : 
      38             : 
      39             : 
      40           9 : CATCH_SCENARIO("CollectionCollection with various tests", "[DirectoryCollection] [FileCollection]")
      41             : {
      42           9 :     zipios_test::safe_chdir cwd(SNAP_CATCH2_NAMESPACE::g_tmp_dir());
      43             : 
      44           9 :     CATCH_GIVEN("an empty collection collection")
      45             :     {
      46           9 :         zipios::CollectionCollection cc;
      47             : 
      48             :         // first, check that the object is setup as expected
      49           9 :         CATCH_START_SECTION("verify that the object looks as expected")
      50             :         {
      51             :             // an empty CollectionCollection is valid
      52           1 :             CATCH_REQUIRE(cc.isValid());
      53           1 :             CATCH_REQUIRE(cc.entries().empty());
      54           1 :             CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
      55           1 :             CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      56           1 :             CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
      57           1 :             CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      58           1 :             CATCH_REQUIRE(cc.getName() == "-");   // default name is "-"
      59           1 :             CATCH_REQUIRE(cc.size() == 0);
      60           1 :             cc.mustBeValid();
      61             : 
      62           1 :             zipios::CollectionCollection copy_constructor(cc);
      63           1 :             CATCH_REQUIRE(copy_constructor.isValid());
      64           1 :             CATCH_REQUIRE(copy_constructor.entries().empty());
      65           1 :             CATCH_REQUIRE_FALSE(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
      66           1 :             CATCH_REQUIRE_FALSE(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      67           1 :             CATCH_REQUIRE_FALSE(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
      68           1 :             CATCH_REQUIRE_FALSE(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      69           1 :             CATCH_REQUIRE(copy_constructor.getName() == "-");   // copy name as is
      70           1 :             CATCH_REQUIRE(copy_constructor.size() == 0);
      71           1 :             copy_constructor.mustBeValid();
      72             : 
      73           1 :             zipios::CollectionCollection copy_assignment;
      74           1 :             copy_assignment = cc;
      75           1 :             CATCH_REQUIRE(copy_assignment.isValid());
      76           1 :             CATCH_REQUIRE(copy_assignment.entries().empty());
      77           1 :             CATCH_REQUIRE_FALSE(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
      78           1 :             CATCH_REQUIRE_FALSE(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      79           1 :             CATCH_REQUIRE_FALSE(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
      80           1 :             CATCH_REQUIRE_FALSE(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      81           1 :             CATCH_REQUIRE(copy_assignment.getName() == "-");   // copy name as is
      82           1 :             CATCH_REQUIRE(copy_assignment.size() == 0);
      83           1 :             copy_assignment.mustBeValid();
      84             : 
      85           1 :             zipios::FileCollection::pointer_t clone(cc.clone());
      86           1 :             CATCH_REQUIRE(dynamic_cast<zipios::CollectionCollection *>(clone.get()));
      87           1 :             CATCH_REQUIRE(clone->isValid());
      88           1 :             CATCH_REQUIRE(clone->entries().empty());
      89           1 :             CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
      90           1 :             CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      91           1 :             CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
      92           1 :             CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
      93           1 :             CATCH_REQUIRE(clone->getName() == "-");   // copy name as is
      94           1 :             CATCH_REQUIRE(clone->size() == 0);
      95           1 :             clone->mustBeValid();
      96             : 
      97             :             // this works!
      98           1 :             cc.addCollection(clone);
      99             : 
     100             :             // however, adding a null pointer fails dramatically
     101           1 :             zipios::FileCollection::pointer_t null_pointer;
     102           2 :             CATCH_REQUIRE_THROWS_AS(cc.addCollection(null_pointer), zipios::InvalidException);
     103           1 :         }
     104           9 :         CATCH_END_SECTION()
     105             : 
     106           9 :         CATCH_WHEN("we add an existing directory collection")
     107             :         {
     108             :             // adding a collection to itself fails
     109           4 :             CATCH_REQUIRE_FALSE(cc.addCollection(cc));
     110             : 
     111             :             // create a directory tree starting in "tree"
     112           4 :             CATCH_REQUIRE(system("rm -rf tree") != -1); // clean up, just in case
     113           4 :             size_t start_count(rand() % 10 + 10); // pretty small, no need to waste too much time here
     114           8 :             zipios_test::file_t tree(zipios_test::file_t::type_t::DIRECTORY, start_count, "tree");
     115           8 :             zipios::DirectoryCollection dc("tree", true);
     116           4 :             CATCH_REQUIRE(cc.addCollection(dc));
     117             : 
     118           4 :             CATCH_THEN("it is valid and we can find all the files")
     119             :             {
     120           4 :                 CATCH_REQUIRE(cc.isValid());
     121           4 :                 CATCH_REQUIRE_FALSE(cc.entries().empty());
     122           4 :                 CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     123           4 :                 CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     124           4 :                 CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     125           4 :                 CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     126           4 :                 CATCH_REQUIRE(cc.getName() == "-");   // default name is "-"
     127           4 :                 CATCH_REQUIRE(cc.size() == tree.size());
     128           4 :                 cc.mustBeValid();
     129             : 
     130           4 :                 CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the tree (original)")
     131             :                 {
     132             :                     // this DirectoryCollection is recursive so we get ALL
     133             :                     // the files in the collection
     134           1 :                     zipios_test::file_t::filenames_t all_files(tree.get_all_filenames());
     135             : 
     136          18 :                     for(auto it(all_files.begin()); it != all_files.end(); ++it)
     137             :                     {
     138          17 :                         std::string const name(*it);
     139             : 
     140          17 :                         if(!name.empty() && name.back() == '/')  // Directory?
     141             :                         {
     142             :                             // directories cannot be attached to an istream
     143           3 :                             zipios::DirectoryCollection::stream_pointer_t is1a(dc.getInputStream(name));
     144           3 :                             CATCH_REQUIRE(!is1a);
     145           3 :                             zipios::CollectionCollection::stream_pointer_t is1b(cc.getInputStream(name));
     146           3 :                             CATCH_REQUIRE(!is1b);
     147             : 
     148             :                             // also test without the ending '/', just in case
     149           3 :                             zipios::DirectoryCollection::stream_pointer_t is2a(dc.getInputStream(name.substr(0, name.length() - 1)));
     150           3 :                             CATCH_REQUIRE(!is2a);
     151           3 :                             zipios::CollectionCollection::stream_pointer_t is2b(cc.getInputStream(name.substr(0, name.length() - 1)));
     152           3 :                             CATCH_REQUIRE(!is2b);
     153             : 
     154             :                             // now also test the getEntry() which works with MATCH
     155             :                             // or IGNORE -- prove it!
     156             :                             //
     157           3 :                             zipios::FileEntry::pointer_t entry_match_a(dc.getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     158           3 :                             CATCH_REQUIRE(entry_match_a);
     159           3 :                             zipios::FileEntry::pointer_t entry_match_b(cc.getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     160           3 :                             CATCH_REQUIRE(entry_match_b);
     161             : 
     162           3 :                             std::string::size_type pos(name.rfind('/', name.length() - 2));
     163           3 :                             if(pos == std::string::npos)
     164             :                             {
     165           1 :                                 pos = 0;
     166             :                             }
     167             :                             else
     168             :                             {
     169             :                                 ++pos; // LCOV_EXCL_LINE
     170             :                             }
     171           3 :                             zipios::FileEntry::pointer_t entry_ignore_a(cc.getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     172           3 :                             CATCH_REQUIRE(entry_ignore_a);
     173           3 :                             zipios::FileEntry::pointer_t entry_ignore_b(cc.getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     174           3 :                             CATCH_REQUIRE(entry_ignore_b);
     175           3 :                         }
     176             :                         else
     177             :                         {
     178             :                             // files must all work and we can read them and
     179             :                             // compare with the "real thing" and it is equal
     180             :                             //
     181             :                             // Note: we only test with cc and not dc, the dc
     182             :                             // test is present in the DirectoryCollection test
     183             :                             //
     184          14 :                             zipios::DirectoryCollection::stream_pointer_t is(cc.getInputStream(name));
     185          14 :                             CATCH_REQUIRE(is);
     186             : 
     187          14 :                             std::ifstream in(name, std::ios::in | std::ios::binary);
     188             : 
     189         108 :                             while(in && *is)
     190             :                             {
     191             :                                 char buf1[BUFSIZ], buf2[BUFSIZ];
     192             : 
     193          94 :                                 in.read(buf1, sizeof(buf1));
     194          94 :                                 std::streamsize sz1(in.gcount());
     195             : 
     196          94 :                                 is->read(buf2, sizeof(buf2));
     197          94 :                                 std::streamsize sz2(is->gcount());
     198             : 
     199          94 :                                 CATCH_REQUIRE(sz1 == sz2);
     200          94 :                                 CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     201             :                             }
     202             : 
     203          14 :                             CATCH_REQUIRE(!in);
     204          14 :                             CATCH_REQUIRE(!*is);
     205             : 
     206             :                             // now also test the getEntry() which works with MATCH
     207             :                             // or IGNORE -- prove it!
     208          14 :                             zipios::FileEntry::pointer_t entry_match_a(dc.getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     209          14 :                             CATCH_REQUIRE(entry_match_a);
     210          14 :                             zipios::FileEntry::pointer_t entry_match_b(cc.getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     211          14 :                             CATCH_REQUIRE(entry_match_b);
     212             : 
     213          14 :                             std::string::size_type pos(name.rfind('/'));
     214          14 :                             if(pos == std::string::npos)
     215             :                             {
     216             :                                 pos = 0; // LCOV_EXCL_LINE
     217             :                             }
     218             :                             else
     219             :                             {
     220          14 :                                 ++pos;
     221             :                             }
     222          14 :                             zipios::FileEntry::pointer_t entry_ignore_a(dc.getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     223          14 :                             CATCH_REQUIRE(entry_ignore_a);
     224          14 :                             zipios::FileEntry::pointer_t entry_ignore_b(cc.getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     225          14 :                             CATCH_REQUIRE(entry_ignore_b);
     226          14 :                         }
     227          17 :                     }
     228           1 :                 }
     229           4 :                 CATCH_END_SECTION()
     230             : 
     231           4 :                 zipios::CollectionCollection copy_constructor(cc);
     232           4 :                 CATCH_REQUIRE(copy_constructor.isValid());
     233           4 :                 CATCH_REQUIRE_FALSE(copy_constructor.entries().empty());
     234           4 :                 CATCH_REQUIRE_FALSE(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     235           4 :                 CATCH_REQUIRE_FALSE(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     236           4 :                 CATCH_REQUIRE_FALSE(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     237           4 :                 CATCH_REQUIRE_FALSE(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     238           4 :                 CATCH_REQUIRE(copy_constructor.getName() == "-");   // copy name as is
     239           4 :                 CATCH_REQUIRE(copy_constructor.size() == tree.size());
     240           4 :                 copy_constructor.mustBeValid();
     241             : 
     242           4 :                 CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the tree (copy constructor)")
     243             :                 {
     244             :                     // this DirectoryCollection is recursive so we get ALL
     245             :                     // the files in the collection
     246           1 :                     zipios_test::file_t::filenames_t all_files(tree.get_all_filenames());
     247             : 
     248          26 :                     for(auto it(all_files.begin()); it != all_files.end(); ++it)
     249             :                     {
     250          25 :                         std::string const name(*it);
     251             : 
     252          25 :                         if(!name.empty() && name.back() == '/')  // Directory?
     253             :                         {
     254             :                             // directories cannot be attached to an istream
     255           2 :                             zipios::CollectionCollection::stream_pointer_t is1(copy_constructor.getInputStream(name));
     256           2 :                             CATCH_REQUIRE(!is1);
     257             : 
     258             :                             // also test without the ending '/', just in case
     259           2 :                             zipios::CollectionCollection::stream_pointer_t is2(copy_constructor.getInputStream(name.substr(0, name.length() - 1)));
     260           2 :                             CATCH_REQUIRE(!is2);
     261             : 
     262             :                             // now also test the getEntry() which works with MATCH
     263             :                             // or IGNORE -- prove it!
     264             :                             //
     265           2 :                             zipios::FileEntry::pointer_t entry_match(copy_constructor.getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     266           2 :                             CATCH_REQUIRE(entry_match);
     267             : 
     268           2 :                             std::string::size_type pos(name.rfind('/', name.length() - 2));
     269           2 :                             if(pos == std::string::npos)
     270             :                             {
     271           1 :                                 pos = 0;
     272             :                             }
     273             :                             else
     274             :                             {
     275           1 :                                 ++pos;
     276             :                             }
     277           2 :                             zipios::FileEntry::pointer_t entry_ignore(copy_constructor.getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     278           2 :                             CATCH_REQUIRE(entry_ignore);
     279           2 :                         }
     280             :                         else
     281             :                         {
     282             :                             // files must all work and we can read them and
     283             :                             // compare with the "real thing" and it is equal
     284             :                             //
     285             :                             // Note: we only test with cc and not dc, the dc
     286             :                             // test is present in the DirectoryCollection test
     287             :                             //
     288          23 :                             zipios::DirectoryCollection::stream_pointer_t is(copy_constructor.getInputStream(name));
     289          23 :                             CATCH_REQUIRE(is);
     290             : 
     291          23 :                             std::ifstream in(name, std::ios::in | std::ios::binary);
     292             : 
     293         146 :                             while(in && *is)
     294             :                             {
     295             :                                 char buf1[BUFSIZ], buf2[BUFSIZ];
     296             : 
     297         123 :                                 in.read(buf1, sizeof(buf1));
     298         123 :                                 std::streamsize sz1(in.gcount());
     299             : 
     300         123 :                                 is->read(buf2, sizeof(buf2));
     301         123 :                                 std::streamsize sz2(is->gcount());
     302             : 
     303         123 :                                 CATCH_REQUIRE(sz1 == sz2);
     304         123 :                                 CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     305             :                             }
     306             : 
     307          23 :                             CATCH_REQUIRE(!in);
     308          23 :                             CATCH_REQUIRE(!*is);
     309             : 
     310             :                             // now also test the getEntry() which works with MATCH
     311             :                             // or IGNORE -- prove it!
     312          23 :                             zipios::FileEntry::pointer_t entry_match(copy_constructor.getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     313          23 :                             CATCH_REQUIRE(entry_match);
     314             : 
     315          23 :                             std::string::size_type pos(name.rfind('/'));
     316          23 :                             if(pos == std::string::npos)
     317             :                             {
     318             :                                 pos = 0; // LCOV_EXCL_LINE
     319             :                             }
     320             :                             else
     321             :                             {
     322          23 :                                 ++pos;
     323             :                             }
     324          23 :                             zipios::FileEntry::pointer_t entry_ignore(copy_constructor.getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     325          23 :                             CATCH_REQUIRE(entry_ignore);
     326          23 :                         }
     327          25 :                     }
     328           1 :                 }
     329           4 :                 CATCH_END_SECTION()
     330             : 
     331           4 :                 zipios::CollectionCollection copy_assignment;
     332           4 :                 copy_assignment = cc;
     333           4 :                 CATCH_REQUIRE(copy_assignment.isValid());
     334           4 :                 CATCH_REQUIRE_FALSE(copy_assignment.entries().empty());
     335           4 :                 CATCH_REQUIRE_FALSE(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     336           4 :                 CATCH_REQUIRE_FALSE(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     337           4 :                 CATCH_REQUIRE_FALSE(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     338           4 :                 CATCH_REQUIRE_FALSE(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     339           4 :                 CATCH_REQUIRE(copy_assignment.getName() == "-");   // copy name as is
     340           4 :                 CATCH_REQUIRE(copy_assignment.size() == tree.size());
     341           4 :                 copy_assignment.mustBeValid();
     342             : 
     343           4 :                 CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the tree (copy assignment)")
     344             :                 {
     345             :                     // this DirectoryCollection is recursive so we get ALL
     346             :                     // the files in the collection
     347           1 :                     zipios_test::file_t::filenames_t all_files(tree.get_all_filenames());
     348             : 
     349          22 :                     for(auto it(all_files.begin()); it != all_files.end(); ++it)
     350             :                     {
     351          21 :                         std::string const name(*it);
     352             : 
     353          21 :                         if(!name.empty() && name.back() == '/')  // Directory?
     354             :                         {
     355             :                             // directories cannot be attached to an istream
     356           2 :                             zipios::CollectionCollection::stream_pointer_t is1(copy_assignment.getInputStream(name));
     357           2 :                             CATCH_REQUIRE(!is1);
     358             : 
     359             :                             // also test without the ending '/', just in case
     360           2 :                             zipios::CollectionCollection::stream_pointer_t is2(copy_assignment.getInputStream(name.substr(0, name.length() - 1)));
     361           2 :                             CATCH_REQUIRE(!is2);
     362             : 
     363             :                             // now also test the getEntry() which works with MATCH
     364             :                             // or IGNORE -- prove it!
     365             :                             //
     366           2 :                             zipios::FileEntry::pointer_t entry_match(copy_assignment.getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     367           2 :                             CATCH_REQUIRE(entry_match);
     368             : 
     369           2 :                             std::string::size_type pos(name.rfind('/', name.length() - 2));
     370           2 :                             if(pos == std::string::npos)
     371             :                             {
     372           1 :                                 pos = 0;
     373             :                             }
     374             :                             else
     375             :                             {
     376             :                                 ++pos; // LCOV_EXCL_LINE
     377             :                             }
     378           2 :                             zipios::FileEntry::pointer_t entry_ignore(copy_assignment.getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     379           2 :                             CATCH_REQUIRE(entry_ignore);
     380           2 :                         }
     381             :                         else
     382             :                         {
     383             :                             // files must all work and we can read them and
     384             :                             // compare with the "real thing" and it is equal
     385             :                             //
     386          19 :                             zipios::DirectoryCollection::stream_pointer_t is(copy_assignment.getInputStream(name));
     387          19 :                             CATCH_REQUIRE(is);
     388             : 
     389          19 :                             std::ifstream in(name, std::ios::in | std::ios::binary);
     390             : 
     391         144 :                             while(in && *is)
     392             :                             {
     393             :                                 char buf1[BUFSIZ], buf2[BUFSIZ];
     394             : 
     395         125 :                                 in.read(buf1, sizeof(buf1));
     396         125 :                                 std::streamsize sz1(in.gcount());
     397             : 
     398         125 :                                 is->read(buf2, sizeof(buf2));
     399         125 :                                 std::streamsize sz2(is->gcount());
     400             : 
     401         125 :                                 CATCH_REQUIRE(sz1 == sz2);
     402         125 :                                 CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     403             :                             }
     404             : 
     405          19 :                             CATCH_REQUIRE(!in);
     406          19 :                             CATCH_REQUIRE(!*is);
     407             : 
     408             :                             // now also test the getEntry() which works with MATCH
     409             :                             // or IGNORE -- prove it!
     410          19 :                             zipios::FileEntry::pointer_t entry_match(copy_assignment.getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     411          19 :                             CATCH_REQUIRE(entry_match);
     412             : 
     413          19 :                             std::string::size_type pos(name.rfind('/'));
     414          19 :                             if(pos == std::string::npos)
     415             :                             {
     416             :                                 pos = 0; // LCOV_EXCL_LINE
     417             :                             }
     418             :                             else
     419             :                             {
     420          19 :                                 ++pos;
     421             :                             }
     422          19 :                             zipios::FileEntry::pointer_t entry_ignore(copy_assignment.getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     423          19 :                             CATCH_REQUIRE(entry_ignore);
     424          19 :                         }
     425          21 :                     }
     426           1 :                 }
     427           4 :                 CATCH_END_SECTION()
     428             : 
     429           4 :                 zipios::FileCollection::pointer_t clone(cc.clone());
     430           4 :                 CATCH_REQUIRE(dynamic_cast<zipios::CollectionCollection *>(clone.get()));
     431           4 :                 CATCH_REQUIRE(clone->isValid());
     432           4 :                 CATCH_REQUIRE_FALSE(clone->entries().empty());
     433           4 :                 CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     434           4 :                 CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     435           4 :                 CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     436           4 :                 CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     437           4 :                 CATCH_REQUIRE(clone->getName() == "-");   // copy name as is
     438           4 :                 CATCH_REQUIRE(clone->size() == tree.size());
     439           4 :                 clone->mustBeValid();
     440             : 
     441           4 :                 CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the tree (clone)")
     442             :                 {
     443             :                     // this DirectoryCollection is recursive so we get ALL
     444             :                     // the files in the collection
     445           1 :                     zipios_test::file_t::filenames_t all_files(tree.get_all_filenames());
     446             : 
     447          28 :                     for(auto it(all_files.begin()); it != all_files.end(); ++it)
     448             :                     {
     449          27 :                         std::string const name(*it);
     450             : 
     451          27 :                         if(!name.empty() && name.back() == '/')  // Directory?
     452             :                         {
     453             :                             // directories cannot be attached to an istream
     454           3 :                             zipios::CollectionCollection::stream_pointer_t is1(clone->getInputStream(name));
     455           3 :                             CATCH_REQUIRE(!is1);
     456             : 
     457             :                             // also test without the ending '/', just in case
     458           3 :                             zipios::CollectionCollection::stream_pointer_t is2(clone->getInputStream(name.substr(0, name.length() - 1)));
     459           3 :                             CATCH_REQUIRE(!is2);
     460             : 
     461             :                             // now also test the getEntry() which works with MATCH
     462             :                             // or IGNORE -- prove it!
     463             :                             //
     464           3 :                             zipios::FileEntry::pointer_t entry_match(clone->getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     465           3 :                             CATCH_REQUIRE(entry_match);
     466             : 
     467           3 :                             std::string::size_type pos(name.rfind('/', name.length() - 2));
     468           3 :                             if(pos == std::string::npos)
     469             :                             {
     470           1 :                                 pos = 0;
     471             :                             }
     472             :                             else
     473             :                             {
     474             :                                 ++pos; // LCOV_EXCL_LINE
     475             :                             }
     476           3 :                             zipios::FileEntry::pointer_t entry_ignore(clone->getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     477           3 :                             CATCH_REQUIRE(entry_ignore);
     478           3 :                         }
     479             :                         else
     480             :                         {
     481             :                             // files must all work and we can read them and
     482             :                             // compare with the "real thing" and it is equal
     483             :                             //
     484          24 :                             zipios::DirectoryCollection::stream_pointer_t is(clone->getInputStream(name));
     485          24 :                             CATCH_REQUIRE(is);
     486             : 
     487          24 :                             std::ifstream in(name, std::ios::in | std::ios::binary);
     488             : 
     489         153 :                             while(in && *is)
     490             :                             {
     491             :                                 char buf1[BUFSIZ], buf2[BUFSIZ];
     492             : 
     493         129 :                                 in.read(buf1, sizeof(buf1));
     494         129 :                                 std::streamsize sz1(in.gcount());
     495             : 
     496         129 :                                 is->read(buf2, sizeof(buf2));
     497         129 :                                 std::streamsize sz2(is->gcount());
     498             : 
     499         129 :                                 CATCH_REQUIRE(sz1 == sz2);
     500         129 :                                 CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     501             :                             }
     502             : 
     503          24 :                             CATCH_REQUIRE(!in);
     504          24 :                             CATCH_REQUIRE(!*is);
     505             : 
     506             :                             // now also test the getEntry() which works with MATCH
     507             :                             // or IGNORE -- prove it!
     508          24 :                             zipios::FileEntry::pointer_t entry_match(clone->getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     509          24 :                             CATCH_REQUIRE(entry_match);
     510             : 
     511          24 :                             std::string::size_type pos(name.rfind('/'));
     512          24 :                             if(pos == std::string::npos)
     513             :                             {
     514             :                                 pos = 0; // LCOV_EXCL_LINE
     515             :                             }
     516             :                             else
     517             :                             {
     518          24 :                                 ++pos;
     519             :                             }
     520          24 :                             zipios::FileEntry::pointer_t entry_ignore(clone->getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     521          24 :                             CATCH_REQUIRE(entry_ignore);
     522          24 :                         }
     523          27 :                     }
     524           1 :                 }
     525           4 :                 CATCH_END_SECTION()
     526           8 :             }
     527          13 :         }
     528             : 
     529           9 :         CATCH_WHEN("we add existing directories and another sub-collection")
     530             :         {
     531             :             // Build a collection that looks like this to verify that we
     532             :             // do have access to all the files in all collections:
     533             :             //
     534             :             //                                +---------------------------+
     535             :             //                                | CollectionCollection (cc) |
     536             :             //                                +---------------------------+
     537             :             //                                             |
     538             :             //              +------------------------------+-------------------------------+
     539             :             //              |                              |                               |
     540             :             //              v                              v                               v
     541             :             // +---------------------------+  +---------------------------+  +---------------------------+
     542             :             // | DirectoryCollection (dc1) |  | CollectionCollection (cc) |  | DirectoryCollection (dc2) |
     543             :             // +---------------------------+  +---------------------------+  +---------------------------+
     544             :             //                                             |
     545             :             //              +------------------------------+-------------------------------+
     546             :             //              |                              |                               |
     547             :             //              v                              v                               v
     548             :             // +---------------------------+  +---------------------------+  +---------------------------+
     549             :             // | DirectoryCollection (dc3) |  | DirectoryCollection (cc4) |  | DirectoryCollection (dc5) |
     550             :             // +---------------------------+  +---------------------------+  +---------------------------+
     551             :             //
     552             : 
     553             :             // create directory trees starting in "tree1", "tree2", ..., "tree5"
     554           3 :             CATCH_REQUIRE(system("rm -rf tree[1-5]")!=-1); // clean up, just in case
     555             : 
     556           3 :             zipios_test::file_t::vector_t tree;
     557           3 :             zipios::DirectoryCollection::vector_t dc;
     558           3 :             size_t total_size(0);
     559          18 :             for(int i(0); i < 5; ++i)
     560             :             {
     561          15 :                 size_t start_count(rand() % 5 + 5); // very small, we create 5 of them already!
     562          15 :                 std::string name("tree");
     563          15 :                 name += std::to_string(i + 1);
     564          15 :                 tree.push_back(zipios_test::file_t::pointer_t(new zipios_test::file_t(zipios_test::file_t::type_t::DIRECTORY, start_count, name)));
     565          15 :                 total_size += tree[i]->size();
     566          15 :                 dc.push_back(zipios::FileCollection::pointer_t(new zipios::DirectoryCollection(name, true)));
     567          15 :             }
     568             : 
     569             :             // build sub-collection first
     570           3 :             zipios::CollectionCollection sc;
     571           3 :             CATCH_REQUIRE(sc.addCollection(dc[2]));
     572           3 :             CATCH_REQUIRE(sc.size() == dc[2]->size());
     573           3 :             CATCH_REQUIRE(sc.addCollection(dc[3]));
     574           3 :             CATCH_REQUIRE(sc.size() == dc[2]->size() + dc[3]->size());
     575           3 :             CATCH_REQUIRE(sc.addCollection(dc[4]));
     576           3 :             CATCH_REQUIRE(sc.size() == dc[2]->size() + dc[3]->size() + dc[4]->size());
     577             : 
     578             :             // now add the collections to the main collection
     579           3 :             CATCH_REQUIRE(cc.addCollection(sc));
     580           3 :             CATCH_REQUIRE(cc.size() == dc[2]->size() + dc[3]->size() + dc[4]->size());
     581           3 :             CATCH_REQUIRE(cc.addCollection(dc[0]));
     582           3 :             CATCH_REQUIRE(cc.size() == dc[0]->size() + dc[2]->size() + dc[3]->size() + dc[4]->size());
     583           3 :             CATCH_REQUIRE(cc.addCollection(dc[1]));
     584           3 :             CATCH_REQUIRE(cc.size() == dc[0]->size() + dc[1]->size() + dc[2]->size() + dc[3]->size() + dc[4]->size());
     585             : 
     586             :             // now we have that tree as shown above, test it
     587             : 
     588           3 :             CATCH_THEN("it is valid and we can find all the files in all the collections")
     589             :             {
     590           2 :                 CATCH_REQUIRE(cc.isValid());
     591           2 :                 CATCH_REQUIRE_FALSE(cc.entries().empty());
     592           2 :                 CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     593           2 :                 CATCH_REQUIRE_FALSE(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     594           2 :                 CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     595           2 :                 CATCH_REQUIRE_FALSE(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     596           2 :                 CATCH_REQUIRE(cc.getName() == "-");   // default name is "-"
     597           2 :                 CATCH_REQUIRE(cc.size() == total_size);
     598           2 :                 cc.mustBeValid();
     599             : 
     600           2 :                 CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the collection of trees (original)")
     601             :                 {
     602             :                     // this DirectoryCollection are all recursive so we get
     603             :                     // ALL the files in the collection
     604           6 :                     for(int i(0); i < 5; ++i)
     605             :                     {
     606           5 :                         zipios_test::file_t::filenames_t all_files(tree[i]->get_all_filenames());
     607             : 
     608          48 :                         for(auto it(all_files.begin()); it != all_files.end(); ++it)
     609             :                         {
     610          43 :                             std::string const name(*it);
     611             : 
     612          43 :                             if(!name.empty() && name.back() == '/')  // Directory?
     613             :                             {
     614             :                                 // directories cannot be attached to an istream
     615           9 :                                 zipios::CollectionCollection::stream_pointer_t is1(cc.getInputStream(name));
     616           9 :                                 CATCH_REQUIRE(!is1);
     617             : 
     618             :                                 // also test without the ending '/', just in case
     619           9 :                                 zipios::CollectionCollection::stream_pointer_t is2(cc.getInputStream(name.substr(0, name.length() - 1)));
     620           9 :                                 CATCH_REQUIRE(!is2);
     621             : 
     622             :                                 // now also test the getEntry() which works with MATCH
     623             :                                 // or IGNORE -- prove it!
     624             :                                 //
     625           9 :                                 zipios::FileEntry::pointer_t entry_match(cc.getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     626           9 :                                 CATCH_REQUIRE(entry_match);
     627             : 
     628           9 :                                 std::string::size_type pos(name.rfind('/', name.length() - 2));
     629           9 :                                 if(pos == std::string::npos)
     630             :                                 {
     631           5 :                                     pos = 0;
     632             :                                 }
     633             :                                 else
     634             :                                 {
     635           4 :                                     ++pos;
     636             :                                 }
     637           9 :                                 zipios::FileEntry::pointer_t entry_ignore(cc.getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     638           9 :                                 CATCH_REQUIRE(entry_ignore);
     639           9 :                             }
     640             :                             else
     641             :                             {
     642             :                                 // files must all work and we can read them and
     643             :                                 // compare with the "real thing" and it is equal
     644             :                                 //
     645             :                                 // Note: we only test with cc and not dc, the dc
     646             :                                 // test is present in the DirectoryCollection test
     647             :                                 //
     648          34 :                                 zipios::DirectoryCollection::stream_pointer_t is(cc.getInputStream(name));
     649          34 :                                 CATCH_REQUIRE(is);
     650             : 
     651          34 :                                 std::ifstream in(name, std::ios::in | std::ios::binary);
     652             : 
     653         267 :                                 while(in && *is)
     654             :                                 {
     655             :                                     char buf1[BUFSIZ], buf2[BUFSIZ];
     656             : 
     657         233 :                                     in.read(buf1, sizeof(buf1));
     658         233 :                                     std::streamsize sz1(in.gcount());
     659             : 
     660         233 :                                     is->read(buf2, sizeof(buf2));
     661         233 :                                     std::streamsize sz2(is->gcount());
     662             : 
     663         233 :                                     CATCH_REQUIRE(sz1 == sz2);
     664         233 :                                     CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     665             :                                 }
     666             : 
     667          34 :                                 CATCH_REQUIRE(!in);
     668          34 :                                 CATCH_REQUIRE(!*is);
     669             : 
     670             :                                 // now also test the getEntry() which works with MATCH
     671             :                                 // or IGNORE -- prove it!
     672          34 :                                 zipios::FileEntry::pointer_t entry_match(cc.getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     673          34 :                                 CATCH_REQUIRE(entry_match);
     674             : 
     675          34 :                                 std::string::size_type pos(name.rfind('/'));
     676          34 :                                 if(pos == std::string::npos)
     677             :                                 {
     678             :                                     pos = 0; // LCOV_EXCL_LINE
     679             :                                 }
     680             :                                 else
     681             :                                 {
     682          34 :                                     ++pos;
     683             :                                 }
     684          34 :                                 zipios::FileEntry::pointer_t entry_ignore(cc.getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     685          34 :                                 CATCH_REQUIRE(entry_ignore);
     686          34 :                             }
     687          43 :                         }
     688           5 :                     }
     689             :                 }
     690           2 :                 CATCH_END_SECTION()
     691             : 
     692             :                 // skipping on the copy constructor and assignment since
     693             :                 // the clone use the same process (i.e. copy constructor)...
     694             : 
     695             :                 // in this case we want to create a clone, then delete
     696             :                 // it and make sure that our original is still fine
     697             :                 {
     698           2 :                     zipios::FileCollection::pointer_t clone(cc.clone());
     699           2 :                     CATCH_REQUIRE(dynamic_cast<zipios::CollectionCollection *>(clone.get()));
     700           2 :                     CATCH_REQUIRE(clone->isValid());
     701           2 :                     CATCH_REQUIRE_FALSE(clone->entries().empty());
     702           2 :                     CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH));
     703           2 :                     CATCH_REQUIRE_FALSE(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     704           2 :                     CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH));
     705           2 :                     CATCH_REQUIRE_FALSE(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE));
     706           2 :                     CATCH_REQUIRE(clone->getName() == "-");   // copy name as is
     707           2 :                     CATCH_REQUIRE(clone->size() == total_size);
     708           2 :                     clone->mustBeValid();
     709             : 
     710           2 :                     CATCH_START_SECTION("test the CollectionCollection::getInputStream() for each file in the tree (clone)")
     711             :                     {
     712           6 :                         for(int i(0); i < 5; ++i)
     713             :                         {
     714             :                             // this DirectoryCollection is recursive so we get ALL
     715             :                             // the files in the collection
     716           5 :                             zipios_test::file_t::filenames_t all_files(tree[i]->get_all_filenames());
     717             : 
     718          50 :                             for(auto it(all_files.begin()); it != all_files.end(); ++it)
     719             :                             {
     720          45 :                                 std::string const name(*it);
     721             : 
     722          45 :                                 if(!name.empty() && name.back() == '/')  // Directory?
     723             :                                 {
     724             :                                     // directories cannot be attached to an istream
     725          11 :                                     zipios::CollectionCollection::stream_pointer_t is1(clone->getInputStream(name));
     726          11 :                                     CATCH_REQUIRE(!is1);
     727             : 
     728             :                                     // also test without the ending '/', just in case
     729          11 :                                     zipios::CollectionCollection::stream_pointer_t is2(clone->getInputStream(name.substr(0, name.length() - 1)));
     730          11 :                                     CATCH_REQUIRE(!is2);
     731             : 
     732             :                                     // now also test the getEntry() which works with MATCH
     733             :                                     // or IGNORE -- prove it!
     734             :                                     //
     735          11 :                                     zipios::FileEntry::pointer_t entry_match(clone->getEntry(name.substr(0, name.length() - 1), zipios::FileCollection::MatchPath::MATCH));
     736          11 :                                     CATCH_REQUIRE(entry_match);
     737             : 
     738          11 :                                     std::string::size_type pos(name.rfind('/', name.length() - 2));
     739          11 :                                     if(pos == std::string::npos)
     740             :                                     {
     741           5 :                                         pos = 0;
     742             :                                     }
     743             :                                     else
     744             :                                     {
     745           6 :                                         ++pos;
     746             :                                     }
     747          11 :                                     zipios::FileEntry::pointer_t entry_ignore(clone->getEntry(name.substr(pos, name.length() - 1 - pos), zipios::FileCollection::MatchPath::IGNORE));
     748          11 :                                     CATCH_REQUIRE(entry_ignore);
     749          11 :                                 }
     750             :                                 else
     751             :                                 {
     752             :                                     // files must all work and we can read them and
     753             :                                     // compare with the "real thing" and it is equal
     754             :                                     //
     755          34 :                                     zipios::DirectoryCollection::stream_pointer_t is(clone->getInputStream(name));
     756          34 :                                     CATCH_REQUIRE(is);
     757             : 
     758          34 :                                     std::ifstream in(name, std::ios::in | std::ios::binary);
     759             : 
     760         236 :                                     while(in && *is)
     761             :                                     {
     762             :                                         char buf1[BUFSIZ], buf2[BUFSIZ];
     763             : 
     764         202 :                                         in.read(buf1, sizeof(buf1));
     765         202 :                                         std::streamsize sz1(in.gcount());
     766             : 
     767         202 :                                         is->read(buf2, sizeof(buf2));
     768         202 :                                         std::streamsize sz2(is->gcount());
     769             : 
     770         202 :                                         CATCH_REQUIRE(sz1 == sz2);
     771         202 :                                         CATCH_REQUIRE(memcmp(buf1, buf2, sz1) == 0);
     772             :                                     }
     773             : 
     774          34 :                                     CATCH_REQUIRE(!in);
     775          34 :                                     CATCH_REQUIRE(!*is);
     776             : 
     777             :                                     // now also test the getEntry() which works with MATCH
     778             :                                     // or IGNORE -- prove it!
     779          34 :                                     zipios::FileEntry::pointer_t entry_match(clone->getEntry(name, zipios::FileCollection::MatchPath::MATCH));
     780          34 :                                     CATCH_REQUIRE(entry_match);
     781             : 
     782          34 :                                     std::string::size_type pos(name.rfind('/'));
     783          34 :                                     if(pos == std::string::npos)
     784             :                                     {
     785             :                                         pos = 0; // LCOV_EXCL_LINE
     786             :                                     }
     787             :                                     else
     788             :                                     {
     789          34 :                                         ++pos;
     790             :                                     }
     791          34 :                                     zipios::FileEntry::pointer_t entry_ignore(clone->getEntry(name.substr(pos, name.length() - pos), zipios::FileCollection::MatchPath::IGNORE));
     792          34 :                                     CATCH_REQUIRE(entry_ignore);
     793          34 :                                 }
     794          45 :                             }
     795           5 :                         }
     796             :                     }
     797           2 :                     CATCH_END_SECTION()
     798           2 :                 }
     799           3 :             }
     800             : 
     801           3 :             CATCH_THEN("close that collectino of collection and it is now invalid")
     802             :             {
     803           1 :                 cc.close();
     804             : 
     805           1 :                 CATCH_REQUIRE_FALSE(cc.isValid());
     806           1 :                 CATCH_REQUIRE_THROWS_AS(cc.entries().empty(), zipios::InvalidStateException);
     807           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     808           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     809           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     810           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     811           1 :                 CATCH_REQUIRE_THROWS_AS(cc.getName(), zipios::InvalidStateException);   // default name is "-", but we should not return to test that
     812           1 :                 CATCH_REQUIRE_THROWS_AS(cc.size(), zipios::InvalidStateException);
     813           1 :                 CATCH_REQUIRE_THROWS_AS(cc.mustBeValid(), zipios::InvalidStateException);
     814           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(cc), zipios::InvalidStateException);
     815             : 
     816           1 :                 zipios::CollectionCollection copy_constructor(cc);
     817           1 :                 CATCH_REQUIRE_FALSE(copy_constructor.isValid());
     818           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.entries().empty(), zipios::InvalidStateException);
     819           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     820           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     821           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     822           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     823           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getName(), zipios::InvalidStateException);   // copy name as is
     824           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.size(), zipios::InvalidStateException);
     825           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.mustBeValid(), zipios::InvalidStateException);
     826           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.addCollection(cc), zipios::InvalidStateException);
     827           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(copy_constructor), zipios::InvalidStateException);
     828             : 
     829           1 :                 zipios::CollectionCollection copy_assignment;
     830           1 :                 copy_assignment = cc;
     831           1 :                 CATCH_REQUIRE_FALSE(copy_assignment.isValid());
     832           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.entries().empty(), zipios::InvalidStateException);
     833           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     834           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     835           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     836           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     837           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getName(), zipios::InvalidStateException);   // copy name as is
     838           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.size(), zipios::InvalidStateException);
     839           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.mustBeValid(), zipios::InvalidStateException);
     840           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.addCollection(cc), zipios::InvalidStateException);
     841           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(copy_assignment), zipios::InvalidStateException);
     842             : 
     843           1 :                 zipios::FileCollection::pointer_t clone(cc.clone());
     844           1 :                 CATCH_REQUIRE(dynamic_cast<zipios::CollectionCollection *>(clone.get()));
     845           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     846           1 :                 CATCH_REQUIRE_THROWS_AS(clone->entries().empty(), zipios::InvalidStateException);
     847           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     848           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     849           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     850           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     851           1 :                 CATCH_REQUIRE_THROWS_AS(clone->getName(), zipios::InvalidStateException);   // copy name as is
     852           1 :                 CATCH_REQUIRE_THROWS_AS(clone->size(), zipios::InvalidStateException);
     853           1 :                 CATCH_REQUIRE_THROWS_AS(clone->mustBeValid(), zipios::InvalidStateException);
     854           1 :                 CATCH_REQUIRE_THROWS_AS(dynamic_cast<zipios::CollectionCollection *>(clone.get())->addCollection(cc), zipios::InvalidStateException);
     855           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(*clone), zipios::InvalidStateException);
     856           4 :             }
     857          12 :         }
     858             : 
     859           9 :         CATCH_WHEN("closing the directory")
     860             :         {
     861           1 :             cc.close();
     862             : 
     863             :             // adding a collection to itself fails
     864           1 :             CATCH_REQUIRE_THROWS_AS(cc.addCollection(cc), zipios::InvalidStateException);
     865             : 
     866           1 :             CATCH_THEN("it is now invalid")
     867             :             {
     868           1 :                 CATCH_REQUIRE_FALSE(cc.isValid());
     869           1 :                 CATCH_REQUIRE_THROWS_AS(cc.entries().empty(), zipios::InvalidStateException);
     870           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     871           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     872           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     873           3 :                 CATCH_REQUIRE_THROWS_AS(cc.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     874           1 :                 CATCH_REQUIRE_THROWS_AS(cc.getName(), zipios::InvalidStateException);   // default name is "-"
     875           1 :                 CATCH_REQUIRE_THROWS_AS(cc.size(), zipios::InvalidStateException);
     876           1 :                 CATCH_REQUIRE_THROWS_AS(cc.mustBeValid(), zipios::InvalidStateException);
     877           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(cc), zipios::InvalidStateException);
     878             : 
     879           1 :                 zipios::CollectionCollection copy_constructor(cc);
     880           1 :                 CATCH_REQUIRE_FALSE(copy_constructor.isValid());
     881           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.entries().empty(), zipios::InvalidStateException);
     882           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     883           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     884           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     885           3 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     886           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.getName(), zipios::InvalidStateException);   // copy name as is
     887           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.size(), zipios::InvalidStateException);
     888           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.mustBeValid(), zipios::InvalidStateException);
     889           1 :                 CATCH_REQUIRE_THROWS_AS(copy_constructor.addCollection(cc), zipios::InvalidStateException);
     890           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(copy_constructor), zipios::InvalidStateException);
     891             : 
     892           1 :                 zipios::CollectionCollection copy_assignment;
     893           1 :                 copy_assignment = cc;
     894           1 :                 CATCH_REQUIRE_FALSE(copy_assignment.isValid());
     895           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.entries().empty(), zipios::InvalidStateException);
     896           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     897           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     898           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     899           3 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     900           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.getName(), zipios::InvalidStateException);   // copy name as is
     901           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.size(), zipios::InvalidStateException);
     902           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.mustBeValid(), zipios::InvalidStateException);
     903           1 :                 CATCH_REQUIRE_THROWS_AS(copy_assignment.addCollection(cc), zipios::InvalidStateException);
     904           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(copy_assignment), zipios::InvalidStateException);
     905             : 
     906           1 :                 zipios::FileCollection::pointer_t clone(cc.clone());
     907           1 :                 CATCH_REQUIRE(dynamic_cast<zipios::CollectionCollection *>(clone.get()));
     908           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     909           1 :                 CATCH_REQUIRE_THROWS_AS(clone->entries().empty(), zipios::InvalidStateException);
     910           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     911           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     912           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), zipios::InvalidStateException);
     913           3 :                 CATCH_REQUIRE_THROWS_AS(clone->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), zipios::InvalidStateException);
     914           1 :                 CATCH_REQUIRE_THROWS_AS(clone->getName(), zipios::InvalidStateException);   // copy name as is
     915           1 :                 CATCH_REQUIRE_THROWS_AS(clone->size(), zipios::InvalidStateException);
     916           1 :                 CATCH_REQUIRE_THROWS_AS(clone->mustBeValid(), zipios::InvalidStateException);
     917           1 :                 CATCH_REQUIRE_THROWS_AS(dynamic_cast<zipios::CollectionCollection *>(clone.get())->addCollection(cc), zipios::InvalidStateException);
     918           1 :                 CATCH_REQUIRE_THROWS_AS(cc.addCollection(*clone), zipios::InvalidStateException);
     919           2 :             }
     920           9 :         }
     921          18 :     }
     922           9 : }
     923             : 
     924             : 
     925             : // Local Variables:
     926             : // mode: cpp
     927             : // indent-tabs-mode: nil
     928             : // c-basic-offset: 4
     929             : // tab-width: 4
     930             : // End:
     931             : 
     932             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

Snap C++ | List of projects | List of versions