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>
|
||||
@@ -26,14 +26,7 @@ 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_COMPRESSION_MODE_COMPRESS;
|
||||
b_compressor_mode mode = B_COMPRESSOR_MODE_COMPRESS;
|
||||
|
||||
FILE *out_fp = fopen(argv[1], "wb");
|
||||
if (!out_fp) {
|
||||
@@ -43,7 +36,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
b_stream *out_stream = b_stream_open_fp(out_fp);
|
||||
b_cstream *cstream;
|
||||
b_cstream_open(out_stream, zstd, mode, &cstream);
|
||||
b_cstream_open(out_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
|
||||
const size_t source_len = strlen(source);
|
||||
bool compressed = false;
|
||||
@@ -81,7 +74,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_cstream_close(cstream);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(out_stream);
|
||||
fclose(out_fp);
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -14,14 +14,7 @@ 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_COMPRESSION_MODE_DECOMPRESS;
|
||||
b_compressor_mode mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
|
||||
FILE *in_fp = fopen(argv[1], "rb");
|
||||
if (!in_fp) {
|
||||
@@ -31,7 +24,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
b_stream *in_stream = b_stream_open_fp(in_fp);
|
||||
b_cstream *cstream;
|
||||
b_cstream_open(in_stream, zstd, mode, &cstream);
|
||||
b_cstream_open(in_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
|
||||
bool compressed = false;
|
||||
char buf[513];
|
||||
@@ -75,7 +68,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_cstream_close(cstream);
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(in_stream);
|
||||
fclose(in_fp);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -43,6 +43,7 @@ int main(void)
|
||||
b_ringbuffer_write(buf, s, s_len, &nr_written);
|
||||
read_available = b_ringbuffer_available_data_remaining(buf);
|
||||
write_available = b_ringbuffer_write_capacity_remaining(buf);
|
||||
printf("nr written: %zu\n", nr_written);
|
||||
printf("read available: %zu\n", read_available);
|
||||
printf("write available: %zu\n", write_available);
|
||||
assert(read_available == BUF_SIZE - 1);
|
||||
@@ -60,7 +61,7 @@ int main(void)
|
||||
assert(read_available == 0);
|
||||
assert(write_available == BUF_SIZE - 1);
|
||||
|
||||
b_ringbuffer_destroy(buf);
|
||||
b_ringbuffer_unref(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
b_serial_ctx *ctx = b_toml_serial_ctx_create();
|
||||
|
||||
b_dict *dict = b_dict_create();
|
||||
|
||||
@@ -29,10 +28,10 @@ int main(void)
|
||||
b_object_to_string(dict, b_stdout);
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_serial_ctx_serialise(ctx, B_SERIAL_FORMAT_JSON, dict, b_stdout, 0);
|
||||
b_serial_ctx_serialise(ctx, dict, b_stdout, 0);
|
||||
|
||||
b_dict_unref(dict);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
b_serial_ctx_unref(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -203,12 +203,10 @@ int main(void)
|
||||
b_stream *src = b_stdin;
|
||||
b_stream *dest = b_stdout;
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
b_serial_ctx *ctx = b_toml_serial_ctx_create();
|
||||
|
||||
b_object *data;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_TOML, src, &data, 0);
|
||||
b_status status = b_serial_ctx_deserialise(ctx, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
return 1;
|
||||
}
|
||||
@@ -217,7 +215,7 @@ int main(void)
|
||||
|
||||
b_stream_write_char(b_stdout, '\n');
|
||||
|
||||
b_serial_ctx_destroy(ctx);
|
||||
b_serial_ctx_unref(ctx);
|
||||
b_object_unref(data);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -19,12 +19,11 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
/* TODO re-implement json support */
|
||||
b_serial_ctx *ctx = NULL;
|
||||
|
||||
b_object *data;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_JSON, src, &data, 0);
|
||||
b_status status = b_serial_ctx_deserialise(ctx, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot read data\n");
|
||||
return -1;
|
||||
@@ -35,7 +34,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
b_object_unref(data);
|
||||
b_object_unref(src);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
b_serial_ctx_unref(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "blue/serial/toml.h"
|
||||
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <blue/serial.h>
|
||||
@@ -19,12 +21,10 @@ int main(int argc, const char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_serial_ctx *ctx;
|
||||
b_serial_ctx_create(&ctx);
|
||||
b_serial_ctx *ctx = b_toml_serial_ctx_create();
|
||||
|
||||
b_object *data = NULL;
|
||||
b_status status = b_serial_ctx_deserialise(
|
||||
ctx, B_SERIAL_FORMAT_TOML, src, &data, 0);
|
||||
b_status status = b_serial_ctx_deserialise(ctx, src, &data, 0);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "cannot read data\n");
|
||||
return -1;
|
||||
@@ -39,7 +39,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
b_object_unref(data);
|
||||
b_object_unref(src);
|
||||
b_serial_ctx_destroy(ctx);
|
||||
b_serial_ctx_unref(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user