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 various stream and buffer classes. 25 : */ 26 : 27 : #include "catch_main.hpp" 28 : 29 : #include <zipios/zipfile.hpp> 30 : #include <zipios/zipiosexceptions.hpp> 31 : 32 : #include <src/filterinputstreambuf.hpp> 33 : #include <src/filteroutputstreambuf.hpp> 34 : 35 : #include <fstream> 36 : 37 : #include <unistd.h> 38 : #include <string.h> 39 : 40 : 41 : 42 : 43 : 44 2 : CATCH_TEST_CASE("input_filter", "[Buffer]") 45 : { 46 2 : zipios_test::safe_chdir cwd(SNAP_CATCH2_NAMESPACE::g_tmp_dir()); 47 : 48 2 : CATCH_START_SECTION("input_filter: Valid input stream buffer") 49 : { 50 2 : zipios_test::auto_unlink_t auto_unlink("input.buf", true); 51 : { 52 1 : std::ofstream out("input.buf", std::ios::out | std::ios::binary); 53 1 : out << "Test file" << std::endl; 54 1 : } 55 : 56 1 : std::unique_ptr<std::ifstream> in_ptr(new std::ifstream("input.buf", std::ios::in | std::ios::binary)); 57 1 : std::unique_ptr<zipios::FilterInputStreambuf> buf_ptr(new zipios::FilterInputStreambuf(in_ptr->rdbuf())); 58 1 : CATCH_REQUIRE(buf_ptr != nullptr); 59 1 : } 60 2 : CATCH_END_SECTION() 61 : 62 2 : CATCH_START_SECTION("input_filter: Invalid input stream buffer") 63 : { 64 2 : CATCH_REQUIRE_THROWS_AS(new zipios::FilterInputStreambuf(nullptr), zipios::InvalidStateException); 65 : } 66 2 : CATCH_END_SECTION() 67 2 : } 68 : 69 : 70 2 : CATCH_TEST_CASE("output_filter", "[Buffer]") 71 : { 72 2 : zipios_test::safe_chdir cwd(SNAP_CATCH2_NAMESPACE::g_tmp_dir()); 73 : 74 2 : CATCH_START_SECTION("output_filter: Valid output stream buffer") 75 : { 76 2 : zipios_test::auto_unlink_t auto_unlink("output.buf", true); 77 : 78 1 : std::ofstream out("output.buf", std::ios::out | std::ios::binary); 79 1 : std::unique_ptr<zipios::FilterOutputStreambuf> buf_ptr(new zipios::FilterOutputStreambuf(out.rdbuf())); 80 1 : CATCH_REQUIRE(buf_ptr != nullptr); 81 1 : } 82 2 : CATCH_END_SECTION() 83 : 84 2 : CATCH_START_SECTION("output_filter: Invalid output stream buffer") 85 : { 86 2 : CATCH_REQUIRE_THROWS_AS(new zipios::FilterOutputStreambuf(nullptr), zipios::InvalidStateException); 87 : } 88 2 : CATCH_END_SECTION() 89 2 : } 90 : 91 : 92 : 93 : 94 : 95 : // Local Variables: 96 : // mode: cpp 97 : // indent-tabs-mode: nil 98 : // c-basic-offset: 4 99 : // tab-width: 4 100 : // End: 101 : 102 : // vim: ts=4 sw=4 et