test-compress.c revision c552d602ae784c0261ceeb46ace30e6189f38bb2
/***
This file is part of systemd
Copyright 2014 Ronny Chevalier
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "compress.h"
#include "util.h"
#include "macro.h"
#ifdef HAVE_XZ
# define XZ_OK 0
#else
# define XZ_OK -EPROTONOSUPPORT
#endif
#ifdef HAVE_LZ4
# define LZ4_OK 0
#else
# define LZ4_OK -EPROTONOSUPPORT
#endif
static void test_compress_decompress(int compression,
const char *data,
bool may_fail) {
char compressed[512];
int r;
log_info("/* testing %s %s blob compression/decompression */",
if (r == -ENOBUFS) {
} else {
assert(r == 0);
assert(r == 0);
}
assert(r < 0);
/* make sure to have the minimal lz4 compressed size */
assert(r < 0);
assert(r < 0);
}
static void test_decompress_startswith(int compression,
const char *data,
bool may_fail) {
char compressed[512];
int r;
log_info("/* testing decompress_startswith with %s on %s text*/",
if (r == -ENOBUFS) {
return;
}
assert(r == 0);
(void **) &decompressed,
&usize,
(void **) &decompressed,
&usize,
(void **) &decompressed,
&usize,
"barbarbar", 9, ' ') == 0);
(void **) &decompressed,
&usize,
}
static void test_compress_stream(int compression,
const char* cat,
const char *srcfile) {
char pattern[] = "/tmp/systemd-test.xz.XXXXXX",
pattern2[] = "/tmp/systemd-test.xz.XXXXXX";
int r;
log_debug("/* testing %s compression */",
log_debug("/* test compression */");
if (cat) {
}
log_debug("/* test decompression */");
assert(r == 0);
log_debug("/* test faulty decompression */");
}
const char text[] =
"text\0foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
"foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
#ifdef HAVE_XZ
#else
log_info("/* XZ test skipped */");
#endif
#ifdef HAVE_LZ4
/* Produced stream is not compatible with lz4 binary, skip lz4cat check. */
#else
log_info("/* LZ4 test skipped */");
#endif
return 0;
}