2 #include <boost/test/unit_test.hpp>
4 #include <zypp/base/GzStream.h>
5 #include <zypp/Pathname.h>
6 #include <zypp/base/InputStream.h>
8 BOOST_AUTO_TEST_CASE(gz_simple_read_write)
10 const zypp::Pathname file = zypp::Pathname(TESTS_BUILD_DIR) / "test.gz";
11 const std::string testString("HelloWorld");
14 zypp::ofgzstream strOut( file.c_str() );
15 BOOST_REQUIRE ( strOut.is_open() );
16 BOOST_REQUIRE ( !strOut.fail() );
17 BOOST_REQUIRE ( strOut.getbuf().canWrite() );
18 BOOST_REQUIRE ( !strOut.getbuf().canRead() );
20 BOOST_REQUIRE ( !strOut.fail() );
25 zypp::ifgzstream str( file.c_str() );
26 BOOST_REQUIRE ( str.is_open() );
27 BOOST_REQUIRE ( !str.fail() );
28 BOOST_REQUIRE ( !str.getbuf().canWrite() );
29 BOOST_REQUIRE ( str.getbuf().canRead() );
31 BOOST_REQUIRE ( !str.fail() );
32 BOOST_REQUIRE_EQUAL( test, testString );
36 zypp::InputStream iStr( file );
37 BOOST_REQUIRE( typeid( iStr.stream() ) == typeid( zypp::ifgzstream& ) );
41 BOOST_AUTO_TEST_CASE(gz_seek)
43 const zypp::Pathname file = zypp::Pathname(TESTS_BUILD_DIR) / "testseek.gz";
44 const std::string testString("Hello World!\nLet's see if seeking works!");
47 zypp::ofgzstream strOut( file.c_str() );
48 BOOST_REQUIRE( strOut.is_open() );
52 //gzseek only supports SEEK_SET (beg) and SEEK_CUR (cur), SEEK_END (end) is not supported
55 zypp::ifgzstream str( file.c_str() );
56 str.seekg( 6, std::ios_base::beg );
57 BOOST_REQUIRE ( !str.fail() );
58 BOOST_REQUIRE_EQUAL( str.tellg(), 6 );
60 BOOST_REQUIRE_EQUAL( test, "World!" );
61 BOOST_REQUIRE ( !str.fail() );
62 BOOST_REQUIRE_EQUAL( str.tellg(), 12 );
64 str.seekg( 7, std::ios_base::cur );
65 BOOST_REQUIRE ( !str.fail() );
66 BOOST_REQUIRE_EQUAL( str.tellg(), 19 );
68 BOOST_REQUIRE_EQUAL( test, "see" );
69 BOOST_REQUIRE ( !str.fail() );
70 BOOST_REQUIRE_EQUAL( str.tellg(), 22 );
72 str.seekg( 0, std::ios_base::beg );
73 BOOST_REQUIRE ( !str.fail() );
74 BOOST_REQUIRE_EQUAL( str.tellg(), 0 );
76 BOOST_REQUIRE ( !str.fail() );
77 BOOST_REQUIRE_EQUAL( str.tellg(), 5 );
78 BOOST_REQUIRE_EQUAL( test, "Hello" );