8#include <cgreen/cgreen.h>
9#include <cgreen/mocks.h>
21Ensure (compressutils, can_compress_and_uncompress_without_header)
23 const char *testdata =
"TEST-12345-12345-TEST";
25 unsigned long compressed_len = 0;
27 gvm_compress (testdata, strlen (testdata) + 1, &compressed_len);
28 assert_that (compressed_len, is_greater_than (0));
29 assert_that (compressed, is_not_null);
30 assert_that (compressed, is_not_equal_to_string (testdata));
32 unsigned long uncompressed_len;
35 assert_that (uncompressed_len, is_equal_to (strlen (testdata) + 1));
36 assert_that (uncompressed, is_equal_to_string (testdata));
38 g_free (uncompressed);
41Ensure (compressutils, can_compress_and_uncompress_with_header)
43 const char *testdata =
"TEST-12345-12345-TEST";
45 unsigned long compressed_len;
48 assert_that (compressed_len, is_greater_than (0));
49 assert_that (compressed, is_not_null);
50 assert_that (compressed, is_not_equal_to_string (testdata));
52 assert_that (compressed[0], is_equal_to ((
char) 0x1f));
53 assert_that (compressed[1], is_equal_to ((
char) 0x8b));
54 assert_that (compressed[2], is_equal_to (8));
56 unsigned long uncompressed_len;
59 assert_that (uncompressed_len, is_equal_to (strlen (testdata) + 1));
60 assert_that (uncompressed, is_equal_to_string (testdata));
62 g_free (uncompressed);
65Ensure (compressutils, can_uncompress_using_reader)
67 const char *testdata =
"TEST-12345-12345-TEST";
68 unsigned long compressed_len;
72 char compressed_filename[35] =
"/tmp/gvm_gzip_test_XXXXXX";
73 int compressed_fd = mkstemp (compressed_filename);
74 (void) !write (compressed_fd, compressed, compressed_len);
75 close (compressed_fd);
79 assert_that (stream, is_not_null);
81 gchar *uncompressed = g_malloc0 (30);
82 (void) !fread (uncompressed, 1, 30, stream);
83 assert_that (uncompressed, is_equal_to_string (testdata));
84 g_free (uncompressed);
86 assert_that (fclose (stream), is_equal_to (0));
89Ensure (compressutils, can_uncompress_using_fd_reader)
91 const char *testdata =
"TEST-12345-12345-TEST";
92 unsigned long compressed_len;
96 char compressed_filename[35] =
"/tmp/gvm_gzip_test_XXXXXX";
97 int compressed_fd = mkstemp (compressed_filename);
98 (void) !write (compressed_fd, compressed, compressed_len);
99 close (compressed_fd);
102 compressed_fd = open (compressed_filename, O_RDONLY);
105 assert_that (stream, is_not_null);
107 gchar *uncompressed = g_malloc0 (30);
108 (void) !fread (uncompressed, 1, 30, stream);
109 assert_that (uncompressed, is_equal_to_string (testdata));
110 g_free (uncompressed);
112 assert_that (fclose (stream), is_equal_to (0));
122 suite = create_test_suite ();
124 add_test_with_context (suite, compressutils,
125 can_compress_and_uncompress_without_header);
126 add_test_with_context (suite, compressutils,
127 can_compress_and_uncompress_with_header);
128 add_test_with_context (suite, compressutils, can_uncompress_using_reader);
129 add_test_with_context (suite, compressutils, can_uncompress_using_fd_reader);
132 ret = run_single_test (suite, argv[1], create_text_reporter ());
134 ret = run_test_suite (suite, create_text_reporter ());
136 destroy_test_suite (suite);
Functions related to data compression (gzip format.).
FILE * gvm_gzip_open_file_reader_fd(int fd)
Opens a gzip file as a FILE* stream for reading and decompression.
void * gvm_uncompress(const void *src, unsigned long srclen, unsigned long *dstlen)
Uncompresses data in src buffer.
void * gvm_compress(const void *src, unsigned long srclen, unsigned long *dstlen)
Compresses data in src buffer.
FILE * gvm_gzip_open_file_reader(const char *path)
Opens a gzip file as a FILE* stream for reading and decompression.
void * gvm_compress_gzipheader(const void *src, unsigned long srclen, unsigned long *dstlen)
Compresses data in src buffer, gzip format compatible.
BeforeEach(compressutils)
int main(int argc, char **argv)
Ensure(compressutils, can_compress_and_uncompress_without_header)