test: update tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/function.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -72,35 +72,16 @@ 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;
|
||||
}
|
||||
|
||||
size_t inbuf_size, outbuf_size;
|
||||
b_compression_function_get_buffer_size(
|
||||
zstd, mode, &inbuf_size, &outbuf_size);
|
||||
|
||||
b_ringbuffer *in = b_ringbuffer_create(inbuf_size);
|
||||
b_ringbuffer *out = b_ringbuffer_create(outbuf_size);
|
||||
|
||||
if (!in || !out) {
|
||||
fprintf(stderr, "memory allocation failure");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *in_fp = fopen(argv[2], "rb");
|
||||
if (!in_fp) {
|
||||
fprintf(stderr, "cannot open input file %s\n", argv[2]);
|
||||
@@ -114,15 +95,25 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor *compressor;
|
||||
b_status status = b_compressor_create(zstd, mode, in, out, &compressor);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot initialise compressor\n");
|
||||
fclose(in_fp);
|
||||
fclose(out_fp);
|
||||
b_status status = B_SUCCESS;
|
||||
b_type compressor_type = B_TYPE_ZSTD_COMPRESSOR;
|
||||
b_compressor *compressor = b_object_create(compressor_type);
|
||||
|
||||
size_t inbuf_size, outbuf_size;
|
||||
b_compressor_get_buffer_size(
|
||||
compressor_type, mode, &inbuf_size, &outbuf_size);
|
||||
|
||||
b_ringbuffer *in = b_ringbuffer_create(inbuf_size);
|
||||
b_ringbuffer *out = b_ringbuffer_create(outbuf_size);
|
||||
|
||||
if (!in || !out) {
|
||||
fprintf(stderr, "memory allocation failure");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_set_buffer(compressor, in, out);
|
||||
b_compressor_set_mode(compressor, mode);
|
||||
|
||||
int ret = 0;
|
||||
while (1) {
|
||||
ret = refill_input_buffer(in_fp, in);
|
||||
@@ -157,7 +148,7 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mode == B_COMPRESSION_MODE_COMPRESS) {
|
||||
if (mode == B_COMPRESSOR_MODE_COMPRESS) {
|
||||
while (!b_compressor_eof(compressor)) {
|
||||
status = b_compressor_end(compressor);
|
||||
if (!B_OK(status)) {
|
||||
@@ -180,13 +171,13 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_compressor_destroy(compressor);
|
||||
b_compressor_unref(compressor);
|
||||
|
||||
fclose(in_fp);
|
||||
fclose(out_fp);
|
||||
|
||||
b_ringbuffer_destroy(in);
|
||||
b_ringbuffer_destroy(out);
|
||||
b_ringbuffer_unref(in);
|
||||
b_ringbuffer_unref(out);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user