77
88#include <cgreen/cgreen.h>
99#include <cgreen/mocks.h>
10+ #include <fcntl.h>
1011
1112Describe (compressutils );
1213BeforeEach (compressutils )
@@ -79,6 +80,30 @@ Ensure (compressutils, can_uncompress_using_reader)
7980 assert_that (fclose (stream ), is_equal_to (0 ));
8081}
8182
83+ Ensure (compressutils , can_uncompress_using_fd_reader )
84+ {
85+ const char * testdata = "TEST-12345-12345-TEST" ;
86+ size_t compressed_len ;
87+ char * compressed =
88+ gvm_compress_gzipheader (testdata , strlen (testdata ) + 1 , & compressed_len );
89+
90+ char compressed_filename [35 ] = "/tmp/gvm_gzip_test_XXXXXX" ;
91+ int compressed_fd = mkstemp (compressed_filename );
92+ write (compressed_fd , compressed , compressed_len );
93+ close (compressed_fd );
94+
95+ compressed_fd = open (compressed_filename , O_RDONLY );
96+
97+ FILE * stream = gvm_gzip_open_file_reader_fd (compressed_fd );
98+ assert_that (stream , is_not_null );
99+
100+ gchar * uncompressed = g_malloc0 (30 );
101+ fread (uncompressed , 1 , 30 , stream );
102+ assert_that (uncompressed , is_equal_to_string (testdata ));
103+
104+ assert_that (fclose (stream ), is_equal_to (0 ));
105+ }
106+
82107/* Test suite. */
83108int
84109main (int argc , char * * argv )
@@ -92,9 +117,10 @@ main (int argc, char **argv)
92117 add_test_with_context (suite , compressutils ,
93118 can_compress_and_uncompress_with_header );
94119 add_test_with_context (suite , compressutils , can_uncompress_using_reader );
120+ add_test_with_context (suite , compressutils , can_uncompress_using_fd_reader );
95121
96122 if (argc > 1 )
97123 return run_single_test (suite , argv [1 ], create_text_reporter ());
98124
99125 return run_test_suite (suite , create_text_reporter ());
100- }
126+ }
0 commit comments