test: update tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/function.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <stdio.h>
|
||||
@@ -9,13 +9,13 @@
|
||||
|
||||
#define BUF_SIZE 32
|
||||
|
||||
static int compress(const b_compression_function *func, FILE *in, FILE *out)
|
||||
static int compress(b_type compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
b_stream *out_stream = b_stream_open_fp(out);
|
||||
|
||||
b_cstream *cstream;
|
||||
b_status status = b_cstream_open(
|
||||
out_stream, func, B_COMPRESSION_MODE_COMPRESS, &cstream);
|
||||
out_stream, compressor_type, B_COMPRESSOR_MODE_COMPRESS, &cstream);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot initialise compressor\n");
|
||||
@@ -42,19 +42,19 @@ static int compress(const b_compression_function *func, FILE *in, FILE *out)
|
||||
}
|
||||
|
||||
b_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
b_cstream_close(cstream);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(out_stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decompress(const b_compression_function *func, FILE *in, FILE *out)
|
||||
static int decompress(b_type compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
b_stream *in_stream = b_stream_open_fp(in);
|
||||
|
||||
b_cstream *cstream;
|
||||
b_status status = b_cstream_open(
|
||||
in_stream, func, B_COMPRESSION_MODE_DECOMPRESS, &cstream);
|
||||
in_stream, compressor_type, B_COMPRESSOR_MODE_DECOMPRESS, &cstream);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot initialise compressor\n");
|
||||
@@ -85,7 +85,7 @@ static int decompress(const b_compression_function *func, FILE *in, FILE *out)
|
||||
}
|
||||
|
||||
b_cstream_end_compressed_section(cstream, NULL, NULL);
|
||||
b_cstream_close(cstream);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(in_stream);
|
||||
|
||||
return 0;
|
||||
@@ -98,18 +98,11 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const b_compression_function *zstd
|
||||
= b_compression_function_get_by_id(B_COMPRESSOR_FUNCTION_ZSTD);
|
||||
if (!zstd) {
|
||||
fprintf(stderr, "zstd support not enabled\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compression_mode mode;
|
||||
b_compressor_mode mode;
|
||||
if (!strcmp(argv[1], "C")) {
|
||||
mode = B_COMPRESSION_MODE_COMPRESS;
|
||||
mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
} else if (!strcmp(argv[1], "D")) {
|
||||
mode = B_COMPRESSION_MODE_DECOMPRESS;
|
||||
mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
} else {
|
||||
fprintf(stderr, "invalid mode %s\n", argv[1]);
|
||||
return -1;
|
||||
@@ -130,11 +123,11 @@ int main(int argc, const char **argv)
|
||||
|
||||
int ret = 0;
|
||||
switch (mode) {
|
||||
case B_COMPRESSION_MODE_COMPRESS:
|
||||
ret = compress(zstd, in_fp, out_fp);
|
||||
case B_COMPRESSOR_MODE_COMPRESS:
|
||||
ret = compress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
break;
|
||||
case B_COMPRESSION_MODE_DECOMPRESS:
|
||||
ret = decompress(zstd, in_fp, out_fp);
|
||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
||||
ret = decompress(B_TYPE_ZSTD_COMPRESSOR, in_fp, out_fp);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
|
||||
Reference in New Issue
Block a user