LCOV - code coverage report
Current view: top level - tests - catch_directoryentry.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1344 1344 100.0 %
Date: 2024-06-15 08:26:09 Functions: 3 3 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 DirectoryEntry class.
      25             :  */
      26             : 
      27             : #include "catch_main.hpp"
      28             : 
      29             : #include <zipios/directoryentry.hpp>
      30             : #include <zipios/zipiosexceptions.hpp>
      31             : #include <zipios/dosdatetime.hpp>
      32             : 
      33             : #include <fstream>
      34             : 
      35             : #include <sys/stat.h>
      36             : #include <unistd.h>
      37             : 
      38             : 
      39             : /** \brief Local definitions used globally in the DirectoryEntry tests.
      40             :  *
      41             :  */
      42             : namespace
      43             : {
      44             : 
      45             : 
      46             : /** \brief Expected level defined as a variable.
      47             :  *
      48             :  * This definition is used because otherwise catch fails seeing the
      49             :  * definition as a global and the linkage fails.
      50             :  */
      51             : zipios::FileEntry::CompressionLevel const g_expected_level(zipios::FileEntry::COMPRESSION_LEVEL_DEFAULT);
      52             : 
      53             : /** \brief Directories make use of level 'none'.
      54             :  *
      55             :  * This value is to verify that the compression level of a directory
      56             :  * is properly defined.
      57             :  */
      58             : zipios::FileEntry::CompressionLevel const g_directory_level(zipios::FileEntry::COMPRESSION_LEVEL_NONE);
      59             : 
      60             : 
      61             : } // no name namespace
      62             : 
      63             : 
      64          12 : CATCH_SCENARIO("DirectoryEntry_with_invalid_paths", "[DirectoryEntry][FileEntry]")
      65             : {
      66          12 :     CATCH_GIVEN("test a fantom file (path that \"cannot\" exists) and no comment")
      67             :     {
      68          24 :         zipios::DirectoryEntry de(zipios::FilePath("/this/file/really/should/not/exist/period.txt"), "");
      69             : 
      70             :         // first, check that the object is setup as expected
      71          12 :         CATCH_START_SECTION("verify that the object looks as expected")
      72             :         {
      73           1 :             CATCH_REQUIRE(de.isEqual(de));
      74           1 :             CATCH_REQUIRE(de.getComment().empty());
      75           1 :             CATCH_REQUIRE(de.getCompressedSize() == 0);
      76           1 :             CATCH_REQUIRE(de.getCrc() == 0);
      77           1 :             CATCH_REQUIRE(de.getEntryOffset() == 0);
      78           1 :             CATCH_REQUIRE(de.getExtra().empty());
      79           1 :             CATCH_REQUIRE(de.getHeaderSize() == 0);
      80           1 :             CATCH_REQUIRE(de.getLevel() == g_expected_level);
      81           1 :             CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
      82           1 :             CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
      83           1 :             CATCH_REQUIRE(de.getFileName() == "period.txt");
      84           1 :             CATCH_REQUIRE(de.getSize() == 0);
      85           1 :             CATCH_REQUIRE(de.getTime() == 0);  // invalid date
      86           1 :             CATCH_REQUIRE(de.getUnixTime() == 0);
      87           1 :             CATCH_REQUIRE_FALSE(de.hasCrc());
      88           1 :             CATCH_REQUIRE_FALSE(de.isDirectory());
      89           1 :             CATCH_REQUIRE_FALSE(de.isValid());
      90           1 :             CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
      91             : 
      92           1 :             CATCH_REQUIRE_THROWS_AS(de.read(std::cin), zipios::IOException);
      93           1 :             CATCH_REQUIRE_THROWS_AS(de.write(std::cout), zipios::IOException);
      94             : 
      95           1 :             zipios::FileEntry::pointer_t null_entry;
      96             : //            CATCH_REQUIRE_FALSE(de.isEqual(*null_entry));  // here we are passing a NULL reference which most people think is something impossible to do...
      97             :             //CATCH_REQUIRE_FALSE(null_entry->isEqual(de)); -- that would obviously crash!
      98             : 
      99           2 :             zipios::DirectoryEntry empty(zipios::FilePath(""), "");
     100           1 :             CATCH_REQUIRE_FALSE(de.isEqual(empty));
     101           1 :             CATCH_REQUIRE_FALSE(empty.isEqual(de));
     102             : 
     103             :             // attempt a clone now, should have the same content
     104           1 :             zipios::DirectoryEntry::pointer_t clone(de.clone());
     105             : 
     106           1 :             CATCH_REQUIRE(clone->getComment().empty());
     107           1 :             CATCH_REQUIRE(clone->getCompressedSize() == 0);
     108           1 :             CATCH_REQUIRE(clone->getCrc() == 0);
     109           1 :             CATCH_REQUIRE(clone->getEntryOffset() == 0);
     110           1 :             CATCH_REQUIRE(clone->getExtra().empty());
     111           1 :             CATCH_REQUIRE(clone->getHeaderSize() == 0);
     112           1 :             CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     113           1 :             CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     114           1 :             CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     115           1 :             CATCH_REQUIRE(clone->getFileName() == "period.txt");
     116           1 :             CATCH_REQUIRE(clone->getSize() == 0);
     117           1 :             CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     118           1 :             CATCH_REQUIRE(clone->getUnixTime() == 0);
     119           1 :             CATCH_REQUIRE_FALSE(clone->hasCrc());
     120           1 :             CATCH_REQUIRE_FALSE(clone->isDirectory());
     121           1 :             CATCH_REQUIRE_FALSE(clone->isValid());
     122           1 :             CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     123           1 :             CATCH_REQUIRE(clone->isEqual(de));
     124           1 :             CATCH_REQUIRE(de.isEqual(*clone));
     125           1 :         }
     126          12 :         CATCH_END_SECTION()
     127             : 
     128          12 :         CATCH_WHEN("setting the comment")
     129             :         {
     130           1 :             de.setComment("new comment");
     131             : 
     132           1 :             CATCH_THEN("we can read it and nothing else changed")
     133             :             {
     134           1 :                 CATCH_REQUIRE(de.getComment() == "new comment");
     135           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     136           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     137           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     138           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     139           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     140           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     141           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     142           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     143           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     144           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     145           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     146           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     147           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     148           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     149           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     150           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     151             : 
     152           2 :                 zipios::DirectoryEntry other(zipios::FilePath("another/path"), "");
     153           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     154           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     155             : 
     156             :                 // attempt a clone now, should have the same content
     157           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     158             : 
     159           1 :                 CATCH_REQUIRE(clone->getComment() == "new comment");
     160           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     161           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     162           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     163           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     164           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     165           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     166           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     167           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     168           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     169           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     170           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     171           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     172           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     173           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     174           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     175           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     176           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     177           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     178           2 :             }
     179          12 :         }
     180             : 
     181          12 :         CATCH_WHEN("setting the compressed size")
     182             :         {
     183             :             // zero would not really prove anything so skip such
     184             :             // (although it may be extremely rare...)
     185             :             size_t r;
     186             :             do
     187             :             {
     188           1 :                 r = zipios_test::rand_size_t();
     189             :             }
     190           1 :             while(r == 0);
     191           1 :             de.setCompressedSize(r);
     192             : 
     193           1 :             CATCH_THEN("we ignore it")
     194             :             {
     195           1 :                 CATCH_REQUIRE(de.getComment().empty());
     196           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     197           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     198           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     199           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     200           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     201           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     202           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     203           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     204           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     205           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     206           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     207           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     208           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     209           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     210           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     211           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     212             : 
     213           2 :                 zipios::DirectoryEntry same(zipios::FilePath("/this/file/really/should/not/exist/period.txt"), "");
     214           1 :                 CATCH_REQUIRE(de.isEqual(same));
     215           1 :                 CATCH_REQUIRE(same.isEqual(de));
     216             : 
     217           2 :                 zipios::DirectoryEntry other(zipios::FilePath("this/file/really/should/not/exist/period.txt"), "");
     218           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     219           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     220             : 
     221             :                 // attempt a clone now, should have the same content
     222           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     223             : 
     224           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     225           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     226           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     227           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     228           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     229           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     230           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     231           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     232           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     233           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     234           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     235           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     236           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     237           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     238           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     239           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     240           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     241           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     242           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     243           2 :             }
     244          12 :         }
     245             : 
     246          12 :         CATCH_WHEN("setting the CRC")
     247             :         {
     248             :             // zero would not really prove anything so skip such
     249             :             uint32_t r;
     250             :             do
     251             :             {
     252           1 :                 r = rand();
     253             :             }
     254           1 :             while(r == 0);
     255           1 :             de.setCrc(rand());
     256             : 
     257           1 :             CATCH_THEN("we ignore it")
     258             :             {
     259           1 :                 CATCH_REQUIRE(de.getComment().empty());
     260           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     261           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     262           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     263           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     264           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     265           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     266           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     267           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     268           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     269           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     270           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     271           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     272           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     273           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     274           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     275           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     276             : 
     277           2 :                 zipios::DirectoryEntry other(zipios::FilePath("/this/file/really/should/not/exist/period"), "");
     278           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     279           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     280             : 
     281             :                 // attempt a clone now, should have the same content
     282           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     283             : 
     284           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     285           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     286           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     287           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     288           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     289           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     290           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     291           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     292           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     293           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     294           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     295           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     296           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     297           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     298           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     299           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     300           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     301           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     302           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     303           2 :             }
     304          12 :         }
     305             : 
     306          12 :         CATCH_WHEN("setting an extra buffer")
     307             :         {
     308             :             // zero would not really prove anything so skip such
     309           1 :             zipios::FileEntry::buffer_t b;
     310           1 :             uint32_t size(rand() % 100 + 20);
     311          91 :             for(uint32_t i(0); i < size; ++i)
     312             :             {
     313          90 :                 b.push_back(rand());
     314             :             }
     315           1 :             de.setExtra(b);
     316             : 
     317           1 :             CATCH_THEN("we ignore it")
     318             :             {
     319           1 :                 CATCH_REQUIRE(de.getComment().empty());
     320           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     321           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     322           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     323           1 :                 CATCH_REQUIRE_FALSE(de.getExtra().empty());
     324           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     325           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     326           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     327           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     328           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     329           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     330           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     331           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     332           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     333           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     334           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     335           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     336           1 :                 CATCH_REQUIRE(de.getExtra() == b);
     337             : 
     338           2 :                 zipios::DirectoryEntry other(zipios::FilePath("period.txt"), "");
     339           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     340           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     341             : 
     342             :                 // attempt a clone now, should have the same content
     343           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     344             : 
     345           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     346           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     347           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     348           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     349           1 :                 CATCH_REQUIRE_FALSE(clone->getExtra().empty());
     350           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     351           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     352           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     353           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     354           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     355           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     356           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     357           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     358           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     359           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     360           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     361           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     362           1 :                 CATCH_REQUIRE(clone->getExtra() == b);
     363           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     364           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     365           2 :             }
     366          13 :         }
     367             : 
     368          12 :         CATCH_START_SECTION("setting an invalid level")
     369             :         {
     370        2002 :             for(zipios::FileEntry::CompressionLevel level(-1000); level <= 1000; ++level)
     371             :             {
     372        2001 :                 if(level >= -3 && level <= 100)
     373             :                 {
     374             :                     // this is considered valid
     375         104 :                     de.setLevel(level);
     376             : 
     377         104 :                     CATCH_REQUIRE(de.getComment().empty());
     378         104 :                     CATCH_REQUIRE(de.getCompressedSize() == 0);
     379         104 :                     CATCH_REQUIRE(de.getCrc() == 0);
     380         104 :                     CATCH_REQUIRE(de.getEntryOffset() == 0);
     381         104 :                     CATCH_REQUIRE(de.getExtra().empty());
     382         104 :                     CATCH_REQUIRE(de.getHeaderSize() == 0);
     383         104 :                     CATCH_REQUIRE(de.getLevel() == level);
     384         104 :                     CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     385         104 :                     CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     386         104 :                     CATCH_REQUIRE(de.getFileName() == "period.txt");
     387         104 :                     CATCH_REQUIRE(de.getSize() == 0);
     388         104 :                     CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     389         104 :                     CATCH_REQUIRE(de.getUnixTime() == 0);
     390         104 :                     CATCH_REQUIRE_FALSE(de.hasCrc());
     391         104 :                     CATCH_REQUIRE_FALSE(de.isDirectory());
     392         104 :                     CATCH_REQUIRE_FALSE(de.isValid());
     393         104 :                     CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     394             : 
     395         208 :                     zipios::DirectoryEntry other(zipios::FilePath("/file/really/should/not/exist/period.txt"), "");
     396         104 :                     CATCH_REQUIRE_FALSE(de.isEqual(other));
     397         104 :                     CATCH_REQUIRE_FALSE(other.isEqual(de));
     398             : 
     399             :                     // attempt a clone now, should have the same content
     400         104 :                     zipios::DirectoryEntry::pointer_t clone(de.clone());
     401             : 
     402         104 :                     CATCH_REQUIRE(clone->getComment().empty());
     403         104 :                     CATCH_REQUIRE(clone->getCompressedSize() == 0);
     404         104 :                     CATCH_REQUIRE(clone->getCrc() == 0);
     405         104 :                     CATCH_REQUIRE(clone->getEntryOffset() == 0);
     406         104 :                     CATCH_REQUIRE(clone->getExtra().empty());
     407         104 :                     CATCH_REQUIRE(clone->getHeaderSize() == 0);
     408         104 :                     CATCH_REQUIRE(clone->getLevel() == level);
     409         104 :                     CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     410         104 :                     CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     411         104 :                     CATCH_REQUIRE(clone->getFileName() == "period.txt");
     412         104 :                     CATCH_REQUIRE(clone->getSize() == 0);
     413         104 :                     CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     414         104 :                     CATCH_REQUIRE(clone->getUnixTime() == 0);
     415         104 :                     CATCH_REQUIRE_FALSE(clone->hasCrc());
     416         104 :                     CATCH_REQUIRE_FALSE(clone->isDirectory());
     417         104 :                     CATCH_REQUIRE_FALSE(clone->isValid());
     418         104 :                     CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     419         104 :                     CATCH_REQUIRE(clone->isEqual(de));
     420         104 :                     CATCH_REQUIRE(de.isEqual(*clone));
     421         104 :                 }
     422             :                 else
     423             :                 {
     424        1897 :                     CATCH_REQUIRE_THROWS_AS(de.setLevel(level), zipios::InvalidStateException);
     425             :                 }
     426             :             }
     427             :         }
     428          12 :         CATCH_END_SECTION()
     429             : 
     430          12 :         CATCH_START_SECTION("setting an invalid method")
     431             :         {
     432             :             // WARNING: the StorageMethod is a uint8_t so testing
     433             :             //          with negative and such would wrap the number...
     434             :             //          (i.e. no need to do more than the following)
     435         257 :             for(int i(0); i < 256; ++i)
     436             :             {
     437         256 :                 switch(i)
     438             :                 {
     439           2 :                 case 0: // Stored
     440             :                 case 8: // Deflated
     441           2 :                     break;
     442             : 
     443         254 :                 default:
     444         254 :                     CATCH_REQUIRE_THROWS_AS(de.setMethod(static_cast<zipios::StorageMethod>(i)), zipios::InvalidStateException);
     445         254 :                     break;
     446             : 
     447             :                 }
     448             :             }
     449             :         }
     450          12 :         CATCH_END_SECTION()
     451             : 
     452          12 :         CATCH_WHEN("setting the method")
     453             :         {
     454             :             // set a method other than STORED, which is 0
     455             :             // in the newer version, though, the set only accepts
     456             :             // with STORED and DEFLATED
     457             :             //
     458           1 :             zipios::StorageMethod storage_method(zipios::StorageMethod::DEFLATED);
     459           1 :             de.setMethod(storage_method);
     460             : 
     461           1 :             CATCH_THEN("we ignore it")
     462             :             {
     463           1 :                 CATCH_REQUIRE(de.getComment().empty());
     464           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     465           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     466           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     467           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     468           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     469           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     470           1 :                 CATCH_REQUIRE(de.getMethod() == storage_method);
     471           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     472           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     473           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     474           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     475           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     476           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     477           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     478           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     479           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     480             : 
     481           2 :                 zipios::DirectoryEntry other(zipios::FilePath("/file/really/should/not/exist/period.txt"), "");
     482           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     483           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     484             : 
     485             :                 // attempt a clone now, should have the same content
     486           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     487             : 
     488           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     489           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     490           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     491           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     492           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     493           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     494           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     495           1 :                 CATCH_REQUIRE(clone->getMethod() == storage_method);
     496           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     497           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     498           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     499           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     500           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     501           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     502           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     503           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     504           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     505           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     506           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     507           2 :             }
     508          12 :         }
     509             : 
     510          12 :         CATCH_WHEN("setting the uncompressed size")
     511             :         {
     512             :             // zero would not really prove anything so skip such
     513             :             // (although it may be extremely rare...)
     514             :             size_t r;
     515             :             do
     516             :             {
     517           1 :                 r = zipios_test::rand_size_t();
     518             :             }
     519           1 :             while(r == 0);
     520           1 :             de.setSize(r);
     521             : 
     522           1 :             CATCH_THEN("we take it as is")
     523             :             {
     524           1 :                 CATCH_REQUIRE(de.getComment().empty());
     525           1 :                 CATCH_REQUIRE(de.getCompressedSize() == r);
     526           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     527           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     528           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     529           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     530           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     531           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     532           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     533           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     534           1 :                 CATCH_REQUIRE(de.getSize() == r);
     535           1 :                 CATCH_REQUIRE(de.getTime() == 0);  // invalid date
     536           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     537           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     538           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     539           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     540           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (" + std::to_string(r) + " bytes)");
     541             : 
     542           2 :                 zipios::DirectoryEntry other(zipios::FilePath("really/.should"), "");
     543           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     544           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     545             : 
     546             :                 // attempt a clone now, should have the same content
     547           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     548             : 
     549           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     550           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == r);
     551           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     552           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     553           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     554           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     555           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     556           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     557           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     558           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     559           1 :                 CATCH_REQUIRE(clone->getSize() == r);
     560           1 :                 CATCH_REQUIRE(clone->getTime() == 0);  // invalid date
     561           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     562           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     563           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     564           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     565           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (" + std::to_string(r) + " bytes)");
     566           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     567           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     568           2 :             }
     569          12 :         }
     570             : 
     571             : #if INTPTR_MAX != INT32_MAX
     572             : // at this time only check on 64 bit computers because the DOS date can
     573             : // go out of range in a Unix date when we're on a 32 bit computer
     574          12 :         CATCH_WHEN("setting the DOS time")
     575             :         {
     576             :             // DOS time numbers are not linear so we test until we get one
     577             :             // that works...
     578             :             //
     579           1 :             std::time_t t((static_cast<std::time_t>(zipios_test::rand_size_t())) % (4354848000LL - 315561600LL) + 315561600);
     580           1 :             zipios::DOSDateTime r;
     581           1 :             r.setUnixTimestamp(t);
     582           1 :             de.setTime(r.getDOSDateTime());
     583             : 
     584           1 :             CATCH_THEN("we take it as is")
     585             :             {
     586           1 :                 CATCH_REQUIRE(de.getComment().empty());
     587           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     588           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     589           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     590           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     591           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     592           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     593           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     594           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     595           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     596           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     597           1 :                 CATCH_REQUIRE(de.getTime() == r.getDOSDateTime());
     598           1 :                 CATCH_REQUIRE(de.getUnixTime() == r.getUnixTimestamp());
     599           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     600           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     601           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     602           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     603             : 
     604           2 :                 zipios::DirectoryEntry other(zipios::FilePath("other-name.txt"), "");
     605           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     606           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     607             : 
     608             :                 // attempt a clone now, should have the same content
     609           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     610             : 
     611           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     612           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     613           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     614           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     615           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     616           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     617           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     618           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     619           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     620           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     621           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     622           1 :                 CATCH_REQUIRE(clone->getTime() == r.getDOSDateTime());
     623           1 :                 CATCH_REQUIRE(clone->getUnixTime() == r.getUnixTimestamp());
     624           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     625           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     626           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     627           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     628           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     629           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     630           2 :             }
     631          12 :         }
     632             : 
     633          12 :         CATCH_WHEN("setting the Unix time")
     634             :         {
     635             :             // DOS time are limited to a smaller range and on every other
     636             :             // second so we get a valid DOS time and convert it to a Unix time
     637           1 :             std::time_t r((static_cast<std::time_t>(zipios_test::rand_size_t())) % (4354848000LL - 315561600LL) + 315561600);
     638           1 :             de.setUnixTime(r);
     639             : 
     640           1 :             zipios::DOSDateTime dt;
     641           1 :             dt.setUnixTimestamp(r);
     642             : 
     643           1 :             CATCH_THEN("we take it as is")
     644             :             {
     645           1 :                 CATCH_REQUIRE(de.getComment().empty());
     646           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     647           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     648           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     649           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     650           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     651           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     652           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     653           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     654           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     655           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     656           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     657           1 :                 CATCH_REQUIRE(de.getUnixTime() == r);
     658           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     659           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     660           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     661           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     662             : 
     663           2 :                 zipios::DirectoryEntry other(zipios::FilePath("path/incorrect"), "");
     664           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     665           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     666             : 
     667             :                 // attempt a clone now, should have the same content
     668           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     669             : 
     670           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     671           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     672           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     673           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     674           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     675           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     676           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     677           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     678           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     679           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     680           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     681           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
     682           1 :                 CATCH_REQUIRE(clone->getUnixTime() == r);
     683           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     684           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     685           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     686           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     687           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     688           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     689           2 :             }
     690          12 :         }
     691             : #endif
     692             : 
     693          12 :         CATCH_WHEN("setting the entry offset")
     694             :         {
     695             :             // DOS time are limited to a smaller range and on every other
     696             :             // second so we get a valid DOS time and convert it to a Unix time
     697           1 :             std::streampos r(zipios_test::rand_size_t());
     698           1 :             de.setEntryOffset(r);
     699             : 
     700           1 :             CATCH_THEN("we retrieve the same value")
     701             :             {
     702           1 :                 CATCH_REQUIRE(de.getComment().empty());
     703           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
     704           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
     705           1 :                 CATCH_REQUIRE(de.getEntryOffset() == r);
     706           1 :                 CATCH_REQUIRE(de.getExtra().empty());
     707           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     708           1 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     709           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     710           1 :                 CATCH_REQUIRE(de.getName() == "/this/file/really/should/not/exist/period.txt");
     711           1 :                 CATCH_REQUIRE(de.getFileName() == "period.txt");
     712           1 :                 CATCH_REQUIRE(de.getSize() == 0);
     713           1 :                 CATCH_REQUIRE(de.getTime() == 0);
     714           1 :                 CATCH_REQUIRE(de.getUnixTime() == 0);
     715           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     716           1 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     717           1 :                 CATCH_REQUIRE_FALSE(de.isValid());
     718           1 :                 CATCH_REQUIRE(de.toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     719             : 
     720           2 :                 zipios::DirectoryEntry other(zipios::FilePath("path/incorrect"), "");
     721           1 :                 CATCH_REQUIRE_FALSE(de.isEqual(other));
     722           1 :                 CATCH_REQUIRE_FALSE(other.isEqual(de));
     723             : 
     724             :                 // attempt a clone now, should have the same content
     725           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     726             : 
     727           1 :                 CATCH_REQUIRE(clone->getComment().empty());
     728           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
     729           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     730           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == r);
     731           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
     732           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     733           1 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     734           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     735           1 :                 CATCH_REQUIRE(clone->getName() == "/this/file/really/should/not/exist/period.txt");
     736           1 :                 CATCH_REQUIRE(clone->getFileName() == "period.txt");
     737           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
     738           1 :                 CATCH_REQUIRE(clone->getTime() == 0);
     739           1 :                 CATCH_REQUIRE(clone->getUnixTime() == 0);
     740           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     741           1 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     742           1 :                 CATCH_REQUIRE_FALSE(clone->isValid());
     743           1 :                 CATCH_REQUIRE(clone->toString() == "/this/file/really/should/not/exist/period.txt (0 bytes)");
     744           1 :                 CATCH_REQUIRE(clone->isEqual(de));
     745           1 :                 CATCH_REQUIRE(de.isEqual(*clone));
     746           2 :             }
     747          12 :         }
     748          24 :     }
     749          12 : }
     750             : 
     751             : 
     752           1 : CATCH_TEST_CASE("DirectoryEntry_with_one_valid_file", "[DirectoryEntry][FileEntry]")
     753             : {
     754           1 :     zipios_test::safe_chdir cwd(SNAP_CATCH2_NAMESPACE::g_tmp_dir());
     755             : 
     756          11 :     for(int i(0); i < 10; ++i)
     757             :     {
     758          20 :         zipios_test::auto_unlink_t auto_unlink("filepath-test.txt", true);
     759             : 
     760             :         // create a random file
     761          10 :         int const file_size(rand() % 100 + 20);
     762             :         {
     763             :             // create a file
     764          10 :             std::ofstream f("filepath-test.txt", std::ios::out | std::ios::binary);
     765         843 :             for(int j(0); j < file_size; ++j)
     766             :             {
     767         833 :                 char const c(rand());
     768         833 :                 f << c;
     769             :             }
     770          10 :         }
     771             : 
     772             :         {
     773          20 :             zipios::DirectoryEntry de(zipios::FilePath("filepath-test.txt"), "");
     774             : 
     775             :             struct stat file_stats;
     776          10 :             CATCH_REQUIRE(stat("filepath-test.txt", &file_stats) == 0);
     777          10 :             zipios::DOSDateTime dt;
     778          10 :             dt.setUnixTimestamp(file_stats.st_mtime);
     779             : 
     780             :             {
     781          10 :                 CATCH_REQUIRE(de.getComment().empty());
     782          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
     783          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
     784          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     785          10 :                 CATCH_REQUIRE(de.getExtra().empty());
     786          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     787          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     788          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     789          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
     790          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
     791          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
     792          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     793          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
     794          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     795          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     796          10 :                 CATCH_REQUIRE(de.isValid());
     797          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
     798             : 
     799             :                 // attempt a clone now, should have the same content
     800          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     801             : 
     802          10 :                 CATCH_REQUIRE(clone->getComment().empty());
     803          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
     804          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     805          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     806          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
     807          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     808          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     809          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     810          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
     811          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
     812          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
     813          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
     814          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
     815          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     816          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     817          10 :                 CATCH_REQUIRE(clone->isValid());
     818          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
     819          10 :             }
     820             : 
     821             :             {
     822          10 :                 de.setComment("new comment");
     823             : 
     824          10 :                 CATCH_REQUIRE(de.getComment() == "new comment");
     825          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
     826          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
     827          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     828          10 :                 CATCH_REQUIRE(de.getExtra().empty());
     829          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     830          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     831          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     832          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
     833          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
     834          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
     835          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     836          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
     837          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     838          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     839          10 :                 CATCH_REQUIRE(de.isValid());
     840          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     841             : 
     842             :                 // attempt a clone now, should have the same content
     843          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     844             : 
     845          10 :                 CATCH_REQUIRE(clone->getComment() == "new comment");
     846          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
     847          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     848          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     849          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
     850          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     851          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     852          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     853          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
     854          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
     855          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
     856          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
     857          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
     858          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     859          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     860          10 :                 CATCH_REQUIRE(clone->isValid());
     861          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     862             : 
     863          10 :                 de.setComment("");
     864          10 :             }
     865             : 
     866             :             {
     867             :                 // zero would not really prove anything so skip such
     868             :                 // (although it may be extremely rare...)
     869             :                 size_t r;
     870             :                 do
     871             :                 {
     872          10 :                     r = zipios_test::rand_size_t();
     873             :                 }
     874          10 :                 while(r == 0);
     875          10 :                 de.setCompressedSize(r);
     876             : 
     877          10 :                 CATCH_REQUIRE(de.getComment().empty());
     878          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
     879          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
     880          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     881          10 :                 CATCH_REQUIRE(de.getExtra().empty());
     882          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     883          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     884          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     885          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
     886          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
     887          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
     888          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     889          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
     890          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     891          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     892          10 :                 CATCH_REQUIRE(de.isValid());
     893          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     894             : 
     895             :                 // attempt a clone now, should have the same content
     896          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     897             : 
     898          10 :                 CATCH_REQUIRE(clone->getComment().empty());
     899          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
     900          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     901          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     902          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
     903          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     904          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     905          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     906          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
     907          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
     908          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
     909          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
     910          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
     911          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     912          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     913          10 :                 CATCH_REQUIRE(clone->isValid());
     914          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     915          10 :             }
     916             : 
     917             :             {
     918             :                 // zero would not really prove anything so skip such
     919             :                 uint32_t r;
     920             :                 do
     921             :                 {
     922          10 :                     r = rand();
     923             :                 }
     924          10 :                 while(r == 0);
     925          10 :                 de.setCrc(rand());
     926             : 
     927          10 :                 CATCH_REQUIRE(de.getComment().empty());
     928          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
     929          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
     930          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     931          10 :                 CATCH_REQUIRE(de.getExtra().empty());
     932          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     933          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     934          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     935          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
     936          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
     937          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
     938          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     939          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
     940          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     941          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     942          10 :                 CATCH_REQUIRE(de.isValid());
     943          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     944             : 
     945             :                 // attempt a clone now, should have the same content
     946          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     947             : 
     948          10 :                 CATCH_REQUIRE(clone->getComment().empty());
     949          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
     950          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
     951          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
     952          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
     953          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
     954          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
     955          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
     956          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
     957          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
     958          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
     959          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
     960          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
     961          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
     962          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
     963          10 :                 CATCH_REQUIRE(clone->isValid());
     964          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     965          10 :             }
     966             : 
     967             :             {
     968             :                 // zero would not really prove anything so skip such
     969          10 :                 zipios::FileEntry::buffer_t b;
     970          10 :                 uint32_t size(rand() % 100 + 20);
     971         861 :                 for(uint32_t j(0); j < size; ++j)
     972             :                 {
     973         851 :                     b.push_back(rand());
     974             :                 }
     975          10 :                 de.setExtra(b);
     976             : 
     977          10 :                 CATCH_REQUIRE(de.getComment().empty());
     978          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
     979          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
     980          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
     981          10 :                 CATCH_REQUIRE_FALSE(de.getExtra().empty());
     982          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
     983          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
     984          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
     985          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
     986          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
     987          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
     988          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
     989          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
     990          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
     991          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
     992          10 :                 CATCH_REQUIRE(de.isValid());
     993          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
     994          10 :                 CATCH_REQUIRE(de.getExtra() == b);
     995             : 
     996             :                 // attempt a clone now, should have the same content
     997          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
     998             : 
     999          10 :                 CATCH_REQUIRE(clone->getComment().empty());
    1000          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
    1001          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1002          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1003          10 :                 CATCH_REQUIRE_FALSE(clone->getExtra().empty());
    1004          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1005          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
    1006          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1007          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
    1008          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
    1009          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
    1010          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1011          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1012          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1013          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
    1014          10 :                 CATCH_REQUIRE(clone->isValid());
    1015          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_stats.st_size) + " bytes)");
    1016          10 :                 CATCH_REQUIRE(clone->getExtra() == b);
    1017             : 
    1018             :                 // reset the buffer
    1019          10 :                 de.setExtra(zipios::FileEntry::buffer_t());
    1020          10 :             }
    1021             : 
    1022          10 :             CATCH_START_SECTION("setting all levels, including many invalid ones")
    1023             :             {
    1024        2002 :                 for(zipios::FileEntry::CompressionLevel level(-1000); level <= 1000; ++level)
    1025             :                 {
    1026        2001 :                     if(level >= -3 && level <= 100)
    1027             :                     {
    1028             :                         // this is considered valid for a standard file
    1029         104 :                         de.setLevel(level);
    1030             : 
    1031         104 :                         CATCH_REQUIRE(de.getComment().empty());
    1032         104 :                         CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
    1033         104 :                         CATCH_REQUIRE(de.getCrc() == 0);
    1034         104 :                         CATCH_REQUIRE(de.getEntryOffset() == 0);
    1035         104 :                         CATCH_REQUIRE(de.getExtra().empty());
    1036         104 :                         CATCH_REQUIRE(de.getHeaderSize() == 0);
    1037         104 :                         CATCH_REQUIRE(de.getLevel() == level);
    1038         104 :                         CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1039         104 :                         CATCH_REQUIRE(de.getName() == "filepath-test.txt");
    1040         104 :                         CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
    1041         104 :                         CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
    1042         104 :                         CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1043         104 :                         CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1044         104 :                         CATCH_REQUIRE_FALSE(de.hasCrc());
    1045         104 :                         CATCH_REQUIRE_FALSE(de.isDirectory());
    1046         104 :                         CATCH_REQUIRE(de.isValid());
    1047         104 :                         CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1048         104 :                     }
    1049             :                     else
    1050             :                     {
    1051        1897 :                         CATCH_REQUIRE_THROWS_AS(de.setLevel(level), zipios::InvalidStateException);
    1052             :                     }
    1053             :                 }
    1054             : 
    1055             :                 // restore before continuing test
    1056           1 :                 de.setLevel(g_expected_level);
    1057             :             }
    1058          10 :             CATCH_END_SECTION()
    1059             : 
    1060             :             {
    1061             :                 // set a method other than STORED, which is 1, so just us % 8 instead of % 9 and do a +1
    1062          10 :                 de.setMethod(zipios::StorageMethod::DEFLATED);
    1063             : 
    1064          10 :                 CATCH_REQUIRE(de.getComment().empty());
    1065          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
    1066          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1067          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1068          10 :                 CATCH_REQUIRE(de.getExtra().empty());
    1069          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1070          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
    1071          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::DEFLATED);
    1072          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
    1073          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
    1074          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
    1075          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1076          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1077          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1078          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
    1079          10 :                 CATCH_REQUIRE(de.isValid());
    1080          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1081             : 
    1082             :                 // attempt a clone now, should have the same content
    1083          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1084             : 
    1085          10 :                 CATCH_REQUIRE(clone->getComment().empty());
    1086          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
    1087          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1088          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1089          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1090          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1091          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
    1092          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::DEFLATED);
    1093          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
    1094          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
    1095          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
    1096          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1097          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1098          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1099          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
    1100          10 :                 CATCH_REQUIRE(clone->isValid());
    1101          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1102          10 :             }
    1103             : 
    1104             :             {
    1105             :                 // zero would not really prove anything so skip such
    1106             :                 // (although it may be extremely rare...)
    1107             :                 size_t r;
    1108             :                 {
    1109          10 :                     r = zipios_test::rand_size_t();
    1110             :                 }
    1111          10 :                 while(r == 0);
    1112          10 :                 de.setSize(r);
    1113             : 
    1114          10 :                 CATCH_REQUIRE(de.getComment().empty());
    1115          10 :                 CATCH_REQUIRE(de.getCompressedSize() == r);
    1116          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1117          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1118          10 :                 CATCH_REQUIRE(de.getExtra().empty());
    1119          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1120          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
    1121          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::DEFLATED);
    1122          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
    1123          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
    1124          10 :                 CATCH_REQUIRE(de.getSize() == r);
    1125          10 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1126          10 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1127          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1128          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
    1129          10 :                 CATCH_REQUIRE(de.isValid());
    1130          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(r) + " bytes)");
    1131             : 
    1132             :                 // attempt a clone now, should have the same content
    1133          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1134             : 
    1135          10 :                 CATCH_REQUIRE(clone->getComment().empty());
    1136          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == r);
    1137          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1138          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1139          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1140          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1141          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
    1142          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::DEFLATED);
    1143          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
    1144          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
    1145          10 :                 CATCH_REQUIRE(clone->getSize() == r);
    1146          10 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1147          10 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1148          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1149          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
    1150          10 :                 CATCH_REQUIRE(clone->isValid());
    1151          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(r) + " bytes)");
    1152             : 
    1153          10 :                 de.setSize(file_size);
    1154          10 :             }
    1155             : 
    1156             : #if INTPTR_MAX != INT32_MAX
    1157             : // at this time only check on 64 bit computers because the DOS date can
    1158             : // go out of range in a Unix date when we're on a 32 bit computer
    1159             :             {
    1160             :                 // DOS time numbers are not linear so we use a Unix date and
    1161             :                 // convert to DOS time (since we know our converter works)
    1162             :                 //
    1163             :                 // Jan 1, 1980 at 00:00:00  is  315561600   (min)
    1164             :                 // Dec 31, 2107 at 23:59:59  is 4354847999  (max)
    1165          10 :                 std::time_t t(static_cast<std::time_t>(zipios_test::rand_size_t()) % (4354848000LL - 315561600LL) + 315561600);
    1166          10 :                 zipios::DOSDateTime r;
    1167          10 :                 r.setUnixTimestamp(t);
    1168          10 :                 de.setTime(r.getDOSDateTime());
    1169             : 
    1170          10 :                 CATCH_REQUIRE(de.getComment().empty());
    1171          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
    1172          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1173          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1174          10 :                 CATCH_REQUIRE(de.getExtra().empty());
    1175          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1176          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
    1177          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::DEFLATED);
    1178          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
    1179          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
    1180          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
    1181          10 :                 CATCH_REQUIRE(de.getTime() == r.getDOSDateTime());
    1182          10 :                 CATCH_REQUIRE(de.getUnixTime() == r.getUnixTimestamp()); // WARNING: this is not always equal to t because setTime() may use the next even second
    1183          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1184          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
    1185          10 :                 CATCH_REQUIRE(de.isValid());
    1186          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1187             : 
    1188             :                 // attempt a clone now, should have the same content
    1189          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1190             : 
    1191          10 :                 CATCH_REQUIRE(clone->getComment().empty());
    1192          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
    1193          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1194          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1195          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1196          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1197          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
    1198          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::DEFLATED);
    1199          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
    1200          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
    1201          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
    1202          10 :                 CATCH_REQUIRE(clone->getTime() == r.getDOSDateTime());
    1203          10 :                 CATCH_REQUIRE(clone->getUnixTime() == r.getUnixTimestamp());
    1204          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1205          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
    1206          10 :                 CATCH_REQUIRE(clone->isValid());
    1207          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1208          10 :             }
    1209             : 
    1210             :             {
    1211             :                 // DOS time are limited to a smaller range and on every other
    1212             :                 // second so we get a valid DOS time and convert it to a Unix time
    1213          10 :                 std::time_t r(static_cast<std::time_t>(zipios_test::rand_size_t()) % (4354848000LL - 315561600LL) + 315561600);
    1214          10 :                 zipios::DOSDateTime dr;
    1215          10 :                 dr.setUnixTimestamp(r);
    1216          10 :                 de.setUnixTime(r);
    1217             : 
    1218          10 :                 CATCH_REQUIRE(de.getComment().empty());
    1219          10 :                 CATCH_REQUIRE(de.getCompressedSize() == static_cast<std::size_t>(file_size));
    1220          10 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1221          10 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1222          10 :                 CATCH_REQUIRE(de.getExtra().empty());
    1223          10 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1224          10 :                 CATCH_REQUIRE(de.getLevel() == g_expected_level);
    1225          10 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::DEFLATED);
    1226          10 :                 CATCH_REQUIRE(de.getName() == "filepath-test.txt");
    1227          10 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test.txt");
    1228          10 :                 CATCH_REQUIRE(de.getSize() == static_cast<std::size_t>(file_size));
    1229          10 :                 CATCH_REQUIRE(de.getTime() == dr.getDOSDateTime());
    1230          10 :                 CATCH_REQUIRE(de.getUnixTime() == r);
    1231          10 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1232          10 :                 CATCH_REQUIRE_FALSE(de.isDirectory());
    1233          10 :                 CATCH_REQUIRE(de.isValid());
    1234          10 :                 CATCH_REQUIRE(de.toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1235             : 
    1236             :                 // attempt a clone now, should have the same content
    1237          10 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1238             : 
    1239          10 :                 CATCH_REQUIRE(clone->getComment().empty());
    1240          10 :                 CATCH_REQUIRE(clone->getCompressedSize() == static_cast<std::size_t>(file_size));
    1241          10 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1242          10 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1243          10 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1244          10 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1245          10 :                 CATCH_REQUIRE(clone->getLevel() == g_expected_level);
    1246          10 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::DEFLATED);
    1247          10 :                 CATCH_REQUIRE(clone->getName() == "filepath-test.txt");
    1248          10 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test.txt");
    1249          10 :                 CATCH_REQUIRE(clone->getSize() == static_cast<std::size_t>(file_size));
    1250          10 :                 CATCH_REQUIRE(clone->getTime() == dr.getDOSDateTime());
    1251          10 :                 CATCH_REQUIRE(clone->getUnixTime() == r);
    1252          10 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1253          10 :                 CATCH_REQUIRE_FALSE(clone->isDirectory());
    1254          10 :                 CATCH_REQUIRE(clone->isValid());
    1255          10 :                 CATCH_REQUIRE(clone->toString() == "filepath-test.txt (" + std::to_string(file_size) + " bytes)");
    1256          10 :             }
    1257             : #endif
    1258          10 :         }
    1259          10 :     }
    1260           1 : }
    1261             : 
    1262             : 
    1263          10 : CATCH_SCENARIO("DirectoryEntry for a valid directory", "[DirectoryEntry] [FileEntry]")
    1264             : {
    1265          10 :     zipios_test::safe_chdir cwd(SNAP_CATCH2_NAMESPACE::g_tmp_dir());
    1266             : 
    1267          10 :     CATCH_GIVEN("test an existing directory and no comment")
    1268             :     {
    1269             :         // make sure the directory is gone before re-creating it
    1270          10 :         CATCH_REQUIRE(system("rm -rf filepath-test") == 0);
    1271             : 
    1272             :         // create a directory
    1273          10 :         CATCH_REQUIRE(mkdir("filepath-test", 0777) == 0);
    1274             : 
    1275          20 :         zipios::DirectoryEntry de(zipios::FilePath("filepath-test"), "");
    1276             : 
    1277             :         struct stat file_stats;
    1278          10 :         CATCH_REQUIRE(stat("filepath-test", &file_stats) == 0);
    1279             : 
    1280          10 :         zipios::DOSDateTime dt;
    1281          10 :         dt.setUnixTimestamp(file_stats.st_mtime);
    1282             : 
    1283             :         // first, check that the object is setup as expected
    1284          10 :         CATCH_START_SECTION("verify that the object looks as expected")
    1285             :         {
    1286           1 :             CATCH_REQUIRE(de.getComment().empty());
    1287           1 :             CATCH_REQUIRE(de.getCompressedSize() == 0);
    1288           1 :             CATCH_REQUIRE(de.getCrc() == 0);
    1289           1 :             CATCH_REQUIRE(de.getEntryOffset() == 0);
    1290           1 :             CATCH_REQUIRE(de.getExtra().empty());
    1291           1 :             CATCH_REQUIRE(de.getHeaderSize() == 0);
    1292           1 :             CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1293           1 :             CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1294           1 :             CATCH_REQUIRE(de.getName() == "filepath-test");
    1295           1 :             CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1296           1 :             CATCH_REQUIRE(de.getSize() == 0);
    1297           1 :             CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1298           1 :             CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1299           1 :             CATCH_REQUIRE_FALSE(de.hasCrc());
    1300           1 :             CATCH_REQUIRE(de.isDirectory());
    1301           1 :             CATCH_REQUIRE(de.isValid());
    1302           1 :             CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1303             : 
    1304             :             // attempt a clone now, should have the same content
    1305           1 :             zipios::DirectoryEntry::pointer_t clone(de.clone());
    1306             : 
    1307           1 :             CATCH_REQUIRE(clone->getComment().empty());
    1308           1 :             CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1309           1 :             CATCH_REQUIRE(clone->getCrc() == 0);
    1310           1 :             CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1311           1 :             CATCH_REQUIRE(clone->getExtra().empty());
    1312           1 :             CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1313           1 :             CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1314           1 :             CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1315           1 :             CATCH_REQUIRE(clone->getName() == "filepath-test");
    1316           1 :             CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1317           1 :             CATCH_REQUIRE(clone->getSize() == 0);
    1318           1 :             CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1319           1 :             CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1320           1 :             CATCH_REQUIRE_FALSE(clone->hasCrc());
    1321           1 :             CATCH_REQUIRE(clone->isDirectory());
    1322           1 :             CATCH_REQUIRE(clone->isValid());
    1323           1 :             CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1324           1 :         }
    1325          10 :         CATCH_END_SECTION()
    1326             : 
    1327          10 :         CATCH_WHEN("setting the comment")
    1328             :         {
    1329           1 :             de.setComment("new comment");
    1330             : 
    1331           1 :             CATCH_THEN("we can read it and nothing else changed")
    1332             :             {
    1333           1 :                 CATCH_REQUIRE(de.getComment() == "new comment");
    1334           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1335           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1336           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1337           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1338           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1339           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1340           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1341           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1342           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1343           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1344           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1345           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1346           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1347           1 :                 CATCH_REQUIRE(de.isDirectory());
    1348           1 :                 CATCH_REQUIRE(de.isValid());
    1349           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1350             : 
    1351             :                 // attempt a clone now, should have the same content
    1352           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1353             : 
    1354           1 :                 CATCH_REQUIRE(clone->getComment() == "new comment");
    1355           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1356           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1357           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1358           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1359           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1360           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1361           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1362           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1363           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1364           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1365           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1366           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1367           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1368           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1369           1 :                 CATCH_REQUIRE(clone->isValid());
    1370           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1371           2 :             }
    1372          10 :         }
    1373             : 
    1374          10 :         CATCH_WHEN("setting the compressed size")
    1375             :         {
    1376             :             // zero would not really prove anything so skip such
    1377             :             // (although it may be extremely rare...)
    1378             :             size_t r;
    1379             :             do
    1380             :             {
    1381           1 :                 r = zipios_test::rand_size_t();
    1382             :             }
    1383           1 :             while(r == 0);
    1384           1 :             de.setCompressedSize(r);
    1385             : 
    1386           1 :             CATCH_THEN("we ignore it")
    1387             :             {
    1388           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1389           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1390           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1391           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1392           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1393           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1394           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1395           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1396           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1397           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1398           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1399           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1400           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1401           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1402           1 :                 CATCH_REQUIRE(de.isDirectory());
    1403           1 :                 CATCH_REQUIRE(de.isValid());
    1404           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1405             : 
    1406             :                 // attempt a clone now, should have the same content
    1407           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1408             : 
    1409           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1410           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1411           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1412           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1413           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1414           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1415           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1416           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1417           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1418           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1419           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1420           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1421           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1422           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1423           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1424           1 :                 CATCH_REQUIRE(clone->isValid());
    1425           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1426           2 :             }
    1427          10 :         }
    1428             : 
    1429          10 :         CATCH_WHEN("setting the CRC")
    1430             :         {
    1431             :             // zero would not really prove anything so skip such
    1432             :             uint32_t r;
    1433             :             do
    1434             :             {
    1435           1 :                 r = rand();
    1436             :             }
    1437           1 :             while(r == 0);
    1438           1 :             de.setCrc(rand());
    1439             : 
    1440           1 :             CATCH_THEN("we ignore it")
    1441             :             {
    1442           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1443           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1444           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1445           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1446           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1447           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1448           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1449           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1450           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1451           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1452           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1453           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1454           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1455           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1456           1 :                 CATCH_REQUIRE(de.isDirectory());
    1457           1 :                 CATCH_REQUIRE(de.isValid());
    1458           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1459             : 
    1460             :                 // attempt a clone now, should have the same content
    1461           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1462             : 
    1463           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1464           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1465           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1466           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1467           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1468           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1469           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1470           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1471           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1472           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1473           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1474           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1475           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1476           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1477           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1478           1 :                 CATCH_REQUIRE(clone->isValid());
    1479           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1480           2 :             }
    1481          10 :         }
    1482             : 
    1483          10 :         CATCH_WHEN("setting an extra buffer")
    1484             :         {
    1485             :             // zero would not really prove anything so skip such
    1486           1 :             zipios::FileEntry::buffer_t b;
    1487           1 :             uint32_t size(rand() % 100 + 20);
    1488          60 :             for(uint32_t i(0); i < size; ++i)
    1489             :             {
    1490          59 :                 b.push_back(rand());
    1491             :             }
    1492           1 :             de.setExtra(b);
    1493             : 
    1494           1 :             CATCH_THEN("we ignore it")
    1495             :             {
    1496           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1497           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1498           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1499           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1500           1 :                 CATCH_REQUIRE_FALSE(de.getExtra().empty());
    1501           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1502           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1503           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1504           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1505           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1506           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1507           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1508           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1509           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1510           1 :                 CATCH_REQUIRE(de.isDirectory());
    1511           1 :                 CATCH_REQUIRE(de.isValid());
    1512           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1513           1 :                 CATCH_REQUIRE(de.getExtra() == b);
    1514             : 
    1515             :                 // attempt a clone now, should have the same content
    1516           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1517             : 
    1518           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1519           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1520           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1521           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1522           1 :                 CATCH_REQUIRE_FALSE(clone->getExtra().empty());
    1523           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1524           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1525           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1526           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1527           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1528           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1529           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1530           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1531           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1532           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1533           1 :                 CATCH_REQUIRE(clone->isValid());
    1534           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1535           1 :                 CATCH_REQUIRE(clone->getExtra() == b);
    1536           2 :             }
    1537          11 :         }
    1538             : 
    1539          10 :         CATCH_START_SECTION("setting all levels, including many invalid ones")
    1540             :         {
    1541        2002 :             for(zipios::FileEntry::CompressionLevel level(-1000); level <= 1000; ++level)
    1542             :             {
    1543             :                 // directories do not accept values from 1 to 100
    1544        2001 :                 if(level >= -3 && level <= 0)
    1545             :                 {
    1546             :                     // this is considered valid for a standard file
    1547           4 :                     de.setLevel(level);
    1548             : 
    1549           4 :                     CATCH_REQUIRE(de.getComment().empty());
    1550           4 :                     CATCH_REQUIRE(de.getCompressedSize() == 0);
    1551           4 :                     CATCH_REQUIRE(de.getCrc() == 0);
    1552           4 :                     CATCH_REQUIRE(de.getEntryOffset() == 0);
    1553           4 :                     CATCH_REQUIRE(de.getExtra().empty());
    1554           4 :                     CATCH_REQUIRE(de.getHeaderSize() == 0);
    1555           4 :                     CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1556           4 :                     CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1557           4 :                     CATCH_REQUIRE(de.getName() == "filepath-test");
    1558           4 :                     CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1559           4 :                     CATCH_REQUIRE(de.getSize() == 0);
    1560           4 :                     CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1561           4 :                     CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1562           4 :                     CATCH_REQUIRE_FALSE(de.hasCrc());
    1563           4 :                     CATCH_REQUIRE(de.isDirectory());
    1564           4 :                     CATCH_REQUIRE(de.isValid());
    1565           4 :                     CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1566           4 :                 }
    1567             :                 else
    1568             :                 {
    1569        1997 :                     CATCH_REQUIRE_THROWS_AS(de.setLevel(level), zipios::InvalidStateException);
    1570             :                 }
    1571             :             }
    1572             : 
    1573             :             // restore before continuing test
    1574           1 :             de.setLevel(g_expected_level);
    1575             :         }
    1576          10 :         CATCH_END_SECTION()
    1577             : 
    1578          10 :         CATCH_WHEN("setting the method")
    1579             :         {
    1580             :             // set to DEFLATED which has no effect because the de is a
    1581             :             // directory and directories accept DEFLATED but ignore it
    1582           1 :             de.setMethod(zipios::StorageMethod::DEFLATED);
    1583             : 
    1584           1 :             CATCH_THEN("we ignore it")
    1585             :             {
    1586           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1587           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1588           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1589           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1590           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1591           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1592           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1593           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1594           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1595           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1596           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1597           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1598           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1599           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1600           1 :                 CATCH_REQUIRE(de.isDirectory());
    1601           1 :                 CATCH_REQUIRE(de.isValid());
    1602           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1603             : 
    1604             :                 // attempt a clone now, should have the same content
    1605           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1606             : 
    1607           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1608           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1609           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1610           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1611           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1612           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1613           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1614           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1615           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1616           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1617           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1618           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1619           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1620           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1621           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1622           1 :                 CATCH_REQUIRE(clone->isValid());
    1623           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1624           2 :             }
    1625          10 :         }
    1626             : 
    1627          10 :         CATCH_WHEN("setting the uncompressed size")
    1628             :         {
    1629             :             // zero would not really prove anything so skip such
    1630             :             // (although it may be extremely rare...)
    1631             :             size_t r;
    1632             :             do
    1633             :             {
    1634           1 :                 r = zipios_test::rand_size_t();
    1635             :             }
    1636           1 :             while(r == 0);
    1637           1 :             de.setSize(r);
    1638             : 
    1639           1 :             CATCH_THEN("we take it as is")
    1640             :             {
    1641           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1642           1 :                 CATCH_REQUIRE(de.getCompressedSize() == r);
    1643           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1644           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1645           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1646           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1647           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1648           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1649           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1650           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1651           1 :                 CATCH_REQUIRE(de.getSize() == r);
    1652           1 :                 CATCH_REQUIRE(de.getTime() == dt.getDOSDateTime());
    1653           1 :                 CATCH_REQUIRE(de.getUnixTime() == file_stats.st_mtime);
    1654           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1655           1 :                 CATCH_REQUIRE(de.isDirectory());
    1656           1 :                 CATCH_REQUIRE(de.isValid());
    1657           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1658             : 
    1659             :                 // attempt a clone now, should have the same content
    1660           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1661             : 
    1662           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1663           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == r);
    1664           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1665           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1666           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1667           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1668           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1669           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1670           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1671           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1672           1 :                 CATCH_REQUIRE(clone->getSize() == r);
    1673           1 :                 CATCH_REQUIRE(clone->getTime() == dt.getDOSDateTime());
    1674           1 :                 CATCH_REQUIRE(clone->getUnixTime() == file_stats.st_mtime);
    1675           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1676           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1677           1 :                 CATCH_REQUIRE(clone->isValid());
    1678           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1679           2 :             }
    1680          10 :         }
    1681             : 
    1682             : #if INTPTR_MAX != INT32_MAX
    1683             : // at this time only check on 64 bit computers because the DOS date can
    1684             : // go out of range in a Unix date when we're on a 32 bit computer
    1685          10 :         CATCH_WHEN("setting the DOS time")
    1686             :         {
    1687             :             // DOS time numbers are not linear so we test until we get one
    1688             :             // that works...
    1689           1 :             std::time_t t(static_cast<std::time_t>(zipios_test::rand_size_t()) % (4354848000LL - 315561600LL) + 315561600);
    1690           1 :             zipios::DOSDateTime r;
    1691           1 :             r.setUnixTimestamp(t);
    1692           1 :             de.setTime(r.getDOSDateTime());
    1693             : 
    1694           1 :             CATCH_THEN("we take it as is")
    1695             :             {
    1696           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1697           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1698           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1699           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1700           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1701           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1702           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1703           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1704           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1705           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1706           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1707           1 :                 CATCH_REQUIRE(de.getTime() == r.getDOSDateTime());
    1708           1 :                 CATCH_REQUIRE(de.getUnixTime() == r.getUnixTimestamp());
    1709           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1710           1 :                 CATCH_REQUIRE(de.isDirectory());
    1711           1 :                 CATCH_REQUIRE(de.isValid());
    1712           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1713             : 
    1714             :                 // attempt a clone now, should have the same content
    1715           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1716             : 
    1717           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1718           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1719           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1720           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1721           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1722           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1723           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1724           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1725           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1726           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1727           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1728           1 :                 CATCH_REQUIRE(clone->getTime() == r.getDOSDateTime());
    1729           1 :                 CATCH_REQUIRE(clone->getUnixTime() == r.getUnixTimestamp());
    1730           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1731           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1732           1 :                 CATCH_REQUIRE(clone->isValid());
    1733           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1734           2 :             }
    1735          10 :         }
    1736             : 
    1737          10 :         CATCH_WHEN("setting the Unix time")
    1738             :         {
    1739             :             // DOS time are limited to a smaller range and on every other
    1740             :             // second so we get a valid DOS time and convert it to a Unix time
    1741           1 :             std::time_t r(static_cast<std::time_t>(zipios_test::rand_size_t()) % (4354848000LL - 315561600LL) + 315561600);
    1742           1 :             de.setUnixTime(r);
    1743             : 
    1744           1 :             zipios::DOSDateTime dr;
    1745           1 :             dr.setUnixTimestamp(r);
    1746             : 
    1747           1 :             CATCH_THEN("we take it as is")
    1748             :             {
    1749           1 :                 CATCH_REQUIRE(de.getComment().empty());
    1750           1 :                 CATCH_REQUIRE(de.getCompressedSize() == 0);
    1751           1 :                 CATCH_REQUIRE(de.getCrc() == 0);
    1752           1 :                 CATCH_REQUIRE(de.getEntryOffset() == 0);
    1753           1 :                 CATCH_REQUIRE(de.getExtra().empty());
    1754           1 :                 CATCH_REQUIRE(de.getHeaderSize() == 0);
    1755           1 :                 CATCH_REQUIRE(de.getLevel() == g_directory_level);
    1756           1 :                 CATCH_REQUIRE(de.getMethod() == zipios::StorageMethod::STORED);
    1757           1 :                 CATCH_REQUIRE(de.getName() == "filepath-test");
    1758           1 :                 CATCH_REQUIRE(de.getFileName() == "filepath-test");
    1759           1 :                 CATCH_REQUIRE(de.getSize() == 0);
    1760           1 :                 CATCH_REQUIRE(de.getTime() == dr.getDOSDateTime());
    1761           1 :                 CATCH_REQUIRE(de.getUnixTime() == r);
    1762           1 :                 CATCH_REQUIRE_FALSE(de.hasCrc());
    1763           1 :                 CATCH_REQUIRE(de.isDirectory());
    1764           1 :                 CATCH_REQUIRE(de.isValid());
    1765           1 :                 CATCH_REQUIRE(de.toString() == "filepath-test (directory)");
    1766             : 
    1767             :                 // attempt a clone now, should have the same content
    1768           1 :                 zipios::DirectoryEntry::pointer_t clone(de.clone());
    1769             : 
    1770           1 :                 CATCH_REQUIRE(clone->getComment().empty());
    1771           1 :                 CATCH_REQUIRE(clone->getCompressedSize() == 0);
    1772           1 :                 CATCH_REQUIRE(clone->getCrc() == 0);
    1773           1 :                 CATCH_REQUIRE(clone->getEntryOffset() == 0);
    1774           1 :                 CATCH_REQUIRE(clone->getExtra().empty());
    1775           1 :                 CATCH_REQUIRE(clone->getHeaderSize() == 0);
    1776           1 :                 CATCH_REQUIRE(clone->getLevel() == g_directory_level);
    1777           1 :                 CATCH_REQUIRE(clone->getMethod() == zipios::StorageMethod::STORED);
    1778           1 :                 CATCH_REQUIRE(clone->getName() == "filepath-test");
    1779           1 :                 CATCH_REQUIRE(clone->getFileName() == "filepath-test");
    1780           1 :                 CATCH_REQUIRE(clone->getSize() == 0);
    1781           1 :                 CATCH_REQUIRE(clone->getTime() == dr.getDOSDateTime());
    1782           1 :                 CATCH_REQUIRE(clone->getUnixTime() == r);
    1783           1 :                 CATCH_REQUIRE_FALSE(clone->hasCrc());
    1784           1 :                 CATCH_REQUIRE(clone->isDirectory());
    1785           1 :                 CATCH_REQUIRE(clone->isValid());
    1786           1 :                 CATCH_REQUIRE(clone->toString() == "filepath-test (directory)");
    1787           2 :             }
    1788          10 :         }
    1789             : #endif
    1790             : 
    1791          10 :         rmdir("filepath-test");
    1792          20 :     }
    1793          10 : }
    1794             : 
    1795             : 
    1796             : 
    1797             : 
    1798             : // Local Variables:
    1799             : // mode: cpp
    1800             : // indent-tabs-mode: nil
    1801             : // c-basic-offset: 4
    1802             : // tab-width: 4
    1803             : // End:
    1804             : 
    1805             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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