From c29465a97d5e46b8d9100bf94276df21cd1f21b3 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 5 May 2026 21:17:21 +0100 Subject: [PATCH] build: re-enable namespace-specific tests --- cmake/Templates.cmake | 11 + fx.collections/test/arrays.c | 10 +- fx.collections/test/numbers.c | 9 +- fx.collections/test/simple.c | 2 +- fx.collections/test/streams.c | 6 +- fx.collections/test/trees.c | 25 ++- fx.collections/test/unit-tests.c | 50 ----- fx.compression/test/mix-compress.c | 27 ++- fx.compression/test/mix-decompress.c | 29 ++- fx.compression/test/simple1.c | 27 ++- fx.compression/test/stream.c | 33 ++- fx.io/test/streams.c | 7 +- fx.io/test/unit-tests.c | 35 --- fx.serial/test/streams.c | 19 +- fx.serial/test/toml-decode.c | 68 +++--- fx.term/test/errors.c | 44 ++-- fx.term/test/printing.c | 13 +- fx/test/errors.c | 2 +- fx/test/hash.c | 69 ++++-- fx/test/randomise.c | 2 +- fx/test/ringbuffers.c | 2 +- fx/test/ropes.c | 2 +- fx/test/streams.c | 4 +- {fx.collections => fx}/test/strings.c | 13 +- {fx.collections => fx}/test/unicode-strings.c | 7 +- fx/test/unit-tests.c | 202 ------------------ {fx.collections => fx}/test/uuids.c | 2 +- 27 files changed, 273 insertions(+), 447 deletions(-) delete mode 100644 fx.collections/test/unit-tests.c delete mode 100644 fx.io/test/unit-tests.c rename {fx.collections => fx}/test/strings.c (74%) rename {fx.collections => fx}/test/unicode-strings.c (80%) delete mode 100644 fx/test/unit-tests.c rename {fx.collections => fx}/test/uuids.c (90%) diff --git a/cmake/Templates.cmake b/cmake/Templates.cmake index 2cfa27d..3590b31 100644 --- a/cmake/Templates.cmake +++ b/cmake/Templates.cmake @@ -45,6 +45,17 @@ function(add_fx_assembly) target_compile_definitions(${assembly_target_name} PRIVATE ${def}) endforeach (def) + foreach (ns ${arg_NAMESPACES}) + file(GLOB test_sources ${fx_source_root}/${ns}/test/*.c) + foreach (test_file ${test_sources}) + get_filename_component(test_name ${test_file} NAME_WE) + set(test_name ${ns}-${test_name}) + string(REPLACE "." "-" test_name ${test_name}) + add_executable(${test_name} ${test_file}) + target_link_libraries(${test_name} ${assembly_target_name}) + endforeach (test_file) + endforeach (ns) + set_target_properties(${assembly_target_name} PROPERTIES FOLDER "${assembly_name}") diff --git a/fx.collections/test/arrays.c b/fx.collections/test/arrays.c index a7facd0..d7d62ca 100644 --- a/fx.collections/test/arrays.c +++ b/fx.collections/test/arrays.c @@ -1,13 +1,13 @@ -#include -#include +#include +#include #include int main(void) { fx_array *array = fx_array_create(); - fx_array_append(array, FX_RV_INT(32)); - fx_array_append(array, FX_RV_INT(64)); - fx_array_append(array, FX_RV_INT(128)); + fx_array_append(array, fx_int_create(32)); + fx_array_append(array, fx_int_create(64)); + fx_array_append(array, fx_int_create(128)); fx_iterator *it = fx_iterator_begin(array); fx_foreach_ptr(fx_object, obj, it) diff --git a/fx.collections/test/numbers.c b/fx.collections/test/numbers.c index a904d8e..c26b655 100644 --- a/fx.collections/test/numbers.c +++ b/fx.collections/test/numbers.c @@ -1,11 +1,12 @@ -#include +#include #include int main(void) { - fx_number *number = fx_number_create_float(6.8); + fx_double *d = fx_double_create(6.8); + + printf("double=%lf\n", fx_double_get_value(d)); + fx_double_unref(d); - printf("number=%zd\n", FX_NUMBER_IVAL(number)); - fx_number_unref(number); return 0; } diff --git a/fx.collections/test/simple.c b/fx.collections/test/simple.c index 46b260c..e001aa5 100644 --- a/fx.collections/test/simple.c +++ b/fx.collections/test/simple.c @@ -1,4 +1,4 @@ -#include +#include int main(void) { diff --git a/fx.collections/test/streams.c b/fx.collections/test/streams.c index b89699c..df74b3c 100644 --- a/fx.collections/test/streams.c +++ b/fx.collections/test/streams.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include int main(int argc, const char **argv) diff --git a/fx.collections/test/trees.c b/fx.collections/test/trees.c index cca2efd..16d5cd6 100644 --- a/fx.collections/test/trees.c +++ b/fx.collections/test/trees.c @@ -1,8 +1,9 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #define NITEMS 16 @@ -23,18 +24,20 @@ FX_BST_DEFINE_SIMPLE_INSERT(struct bst_item, node, value, put_node) int main(void) { fx_dict *dict = fx_dict_create(); - fx_dict_put(dict, "hello", FX_RV_INT(32)); - fx_dict_put(dict, "world", FX_RV_INT(64)); - fx_dict_put(dict, "more", FX_RV_INT(128)); - fx_dict_put(dict, "other", FX_RV_INT(256)); + fx_dict_put(dict, "hello", fx_int_create(32)); + fx_dict_put(dict, "world", fx_int_create(64)); + fx_dict_put(dict, "more", fx_int_create(128)); + fx_dict_put(dict, "other", fx_int_create(256)); fx_iterator *it = fx_iterator_begin(dict); size_t i = 0; fx_foreach(fx_dict_item *, item, it) { - printf("item %zu: %s=%d\n", i++, fx_string_get_cstr(item->key), - fx_number_get_int(item->value)); + printf("item %zu: %s=%" PRIdPTR "\n", + i++, + fx_string_get_cstr(item->key), + fx_int_get_value(item->value)); } fx_iterator_unref(it); diff --git a/fx.collections/test/unit-tests.c b/fx.collections/test/unit-tests.c deleted file mode 100644 index d72732c..0000000 --- a/fx.collections/test/unit-tests.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -static void test_string_create(CuTest *tc) -{ - fx_string *str = fx_string_create(); - - CuAssertPtrNotNull(tc, str); - CuAssertIntEquals(tc, 0, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "", fx_string_get_cstr(str)); - - fx_string_unref(str); - - str = fx_string_create_from_c('A', 8); - - CuAssertPtrNotNull(tc, str); - CuAssertIntEquals(tc, 8, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "AAAAAAAA", fx_string_get_cstr(str)); - - fx_string_unref(str); - - str = fx_string_create_from_cstr("Hello, world!"); - - CuAssertPtrNotNull(tc, str); - CuAssertIntEquals(tc, 13, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "Hello, world!", fx_string_get_cstr(str)); - - fx_string_unref(str); -} - -static void test_string_length(CuTest *tc) -{ - const char *cstr = "Hello, \033[91;1mworld!"; - fx_string *s = fx_string_create_from_cstr(cstr); - - CuAssertIntEquals(tc, 13, fx_string_get_size(s, FX_STRLEN_IGNORE_ESC)); - CuAssertIntEquals(tc, 20, fx_string_get_size(s, FX_STRLEN_NORMAL)); - - fx_string_unref(s); -} - -CuSuite *get_all_tests(void) -{ - CuSuite *suite = CuSuiteNew(); - - SUITE_ADD_TEST(suite, test_string_create); - SUITE_ADD_TEST(suite, test_string_length); - - return suite; -} diff --git a/fx.compression/test/mix-compress.c b/fx.compression/test/mix-compress.c index f08a385..74255cd 100644 --- a/fx.compression/test/mix-compress.c +++ b/fx.compression/test/mix-compress.c @@ -1,9 +1,9 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -48,9 +48,13 @@ int main(int argc, const char **argv) size_t nr_written = 0; fx_status status = fx_cstream_write( - cstream, source, source_len, &nr_written); + cstream, + source, + source_len, + &nr_written); if (!FX_OK(status)) { - fprintf(stderr, "write error: %s\n", + fprintf(stderr, + "write error: %s\n", fx_status_description(status)); break; } @@ -59,14 +63,19 @@ int main(int argc, const char **argv) if (compressed) { fx_cstream_end_compressed_section( - cstream, &nr_written_compressed, &nr_written); + cstream, + &nr_written_compressed, + &nr_written); } size_t tx_total = 0; fx_cstream_tx_bytes(cstream, &tx_total); printf("iteration %d: wrote %zu (compressed) / %zu " "(uncompressed) / %zu (total) bytes (%s)\n", - i, nr_written_compressed, nr_written, tx_total, + i, + nr_written_compressed, + nr_written, + tx_total, compressed ? "compressed" : "uncompressed"); compressed = !compressed; diff --git a/fx.compression/test/mix-decompress.c b/fx.compression/test/mix-decompress.c index bcf2f64..79d5c97 100644 --- a/fx.compression/test/mix-decompress.c +++ b/fx.compression/test/mix-decompress.c @@ -1,9 +1,9 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -37,10 +37,14 @@ int main(int argc, const char **argv) memset(buf, 0x0, sizeof buf); size_t nr_read = 0; - fx_status status - = fx_cstream_read(cstream, buf, sizeof buf - 1, &nr_read); + fx_status status = fx_cstream_read( + cstream, + buf, + sizeof buf - 1, + &nr_read); if (!FX_OK(status)) { - fprintf(stderr, "write error: %s\n", + fprintf(stderr, + "write error: %s\n", fx_status_description(status)); break; } @@ -52,14 +56,19 @@ int main(int argc, const char **argv) size_t nr_read_compressed = 0; if (compressed) { fx_cstream_end_compressed_section( - cstream, &nr_read_compressed, &nr_read); + cstream, + &nr_read_compressed, + &nr_read); } size_t tx_total = 0; fx_cstream_tx_bytes(cstream, &tx_total); printf(" * iteration %d: read %zu (compressed) / %zu " "(uncompressed) / %zu (total) bytes (%s)\n", - i, nr_read_compressed, nr_read, tx_total, + i, + nr_read_compressed, + nr_read, + tx_total, compressed ? "compressed" : "uncompressed"); printf("%s\n", buf); diff --git a/fx.compression/test/simple1.c b/fx.compression/test/simple1.c index d8ee255..1fdca21 100644 --- a/fx.compression/test/simple1.c +++ b/fx.compression/test/simple1.c @@ -1,7 +1,7 @@ #include -#include -#include -#include +#include +#include +#include #include #include @@ -12,8 +12,10 @@ int refill_input_buffer(FILE *fp, fx_ringbuffer *dest) while (1) { void *buf; size_t capacity; - fx_status status - = fx_ringbuffer_open_write_buffer(dest, &buf, &capacity); + fx_status status = fx_ringbuffer_open_write_buffer( + dest, + &buf, + &capacity); if (status == FX_ERR_NO_SPACE) { break; } @@ -43,8 +45,10 @@ int flush_output_buffer(FILE *fp, fx_ringbuffer *src) while (1) { const void *buf; size_t capacity; - fx_status status - = fx_ringbuffer_open_read_buffer(src, &buf, &capacity); + fx_status status = fx_ringbuffer_open_read_buffer( + src, + &buf, + &capacity); if (status == FX_ERR_NO_DATA) { break; } @@ -68,7 +72,9 @@ int flush_output_buffer(FILE *fp, fx_ringbuffer *src) int main(int argc, const char **argv) { if (argc < 4) { - fprintf(stderr, "usage: %s \n", argv[0]); + fprintf(stderr, + "usage: %s \n", + argv[0]); return -1; } @@ -101,7 +107,10 @@ int main(int argc, const char **argv) size_t inbuf_size, outbuf_size; fx_compressor_get_buffer_size( - compressor_type, mode, &inbuf_size, &outbuf_size); + compressor_type, + mode, + &inbuf_size, + &outbuf_size); fx_ringbuffer *in = fx_ringbuffer_create(inbuf_size); fx_ringbuffer *out = fx_ringbuffer_create(outbuf_size); diff --git a/fx.compression/test/stream.c b/fx.compression/test/stream.c index c9244fd..259d3b2 100644 --- a/fx.compression/test/stream.c +++ b/fx.compression/test/stream.c @@ -1,9 +1,9 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -15,7 +15,10 @@ static int compress(fx_type_id compressor_type, FILE *in, FILE *out) fx_cstream *cstream; fx_status status = fx_cstream_open( - out_stream, compressor_type, FX_COMPRESSOR_MODE_COMPRESS, &cstream); + out_stream, + compressor_type, + FX_COMPRESSOR_MODE_COMPRESS, + &cstream); if (!FX_OK(status)) { fprintf(stderr, "cannot initialise compressor\n"); @@ -54,7 +57,10 @@ static int decompress(fx_type_id compressor_type, FILE *in, FILE *out) fx_cstream *cstream; fx_status status = fx_cstream_open( - in_stream, compressor_type, FX_COMPRESSOR_MODE_DECOMPRESS, &cstream); + in_stream, + compressor_type, + FX_COMPRESSOR_MODE_DECOMPRESS, + &cstream); if (!FX_OK(status)) { fprintf(stderr, "cannot initialise compressor\n"); @@ -66,9 +72,14 @@ static int decompress(fx_type_id compressor_type, FILE *in, FILE *out) char buf[4096]; while (1) { size_t r = 0; - fx_status status = fx_cstream_read(cstream, buf, sizeof buf, &r); + fx_status status = fx_cstream_read( + cstream, + buf, + sizeof buf, + &r); if (!FX_OK(status)) { - fprintf(stderr, "read error: %s\n", + fprintf(stderr, + "read error: %s\n", fx_status_description(status)); return -1; } @@ -94,7 +105,9 @@ static int decompress(fx_type_id compressor_type, FILE *in, FILE *out) int main(int argc, const char **argv) { if (argc < 4) { - fprintf(stderr, "usage: %s \n", argv[0]); + fprintf(stderr, + "usage: %s \n", + argv[0]); return -1; } diff --git a/fx.io/test/streams.c b/fx.io/test/streams.c index 8f49fe8..5aaa1fc 100644 --- a/fx.io/test/streams.c +++ b/fx.io/test/streams.c @@ -1,6 +1,6 @@ -#include #include #include +#include #include int main(int argc, const char **argv) @@ -8,7 +8,10 @@ int main(int argc, const char **argv) fx_file *dest; fx_path *path = fx_path_create_from_cstr("data.txt"); fx_result result = fx_file_open( - NULL, path, FX_FILE_WRITE_ONLY | FX_FILE_CREATE, &dest); + NULL, + path, + FX_FILE_WRITE_ONLY | FX_FILE_CREATE, + &dest); if (fx_result_is_error(result)) { fx_throw(result); return -1; diff --git a/fx.io/test/unit-tests.c b/fx.io/test/unit-tests.c deleted file mode 100644 index 2a058ac..0000000 --- a/fx.io/test/unit-tests.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -void test_path_1(CuTest *tc) -{ - fx_path *path = fx_path_create_from_cstr("C:\\hello\\world\\"); - char buf[512]; - fx_stringstream *str = fx_stringstream_create_with_buffer(buf, sizeof buf); - - fx_object_to_string(path, str); - - printf("%s\n", buf); - - fx_path *path2 = fx_path_create_from_cstr("path1\\path2\\"); - fx_path *path3 = fx_path_create_from_cstr("path3\\path4\\"); - - const fx_path *paths[] = {path, path2, path3}; - - fx_path *path4 = fx_path_join(paths, sizeof paths / sizeof paths[0]); - - fx_stringstream_reset_with_buffer(str, buf, sizeof buf); - fx_object_to_string(path4, str); - printf("%s\n", buf); -} - -CuSuite *get_all_tests(void) -{ - CuSuite *suite = CuSuiteNew(); - - SUITE_ADD_TEST(suite, test_path_1); - - return suite; -} diff --git a/fx.serial/test/streams.c b/fx.serial/test/streams.c index f52b0b9..131ce65 100644 --- a/fx.serial/test/streams.c +++ b/fx.serial/test/streams.c @@ -1,9 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include int main(void) @@ -13,9 +14,9 @@ int main(void) fx_dict *dict = fx_dict_create(); fx_array *array = fx_array_create(); - fx_array_append(array, FX_RV_INT(32)); - fx_array_append(array, FX_RV_INT(64)); - fx_array_append(array, FX_RV_INT(128)); + fx_array_append(array, fx_int_create(32)); + fx_array_append(array, fx_int_create(64)); + fx_array_append(array, fx_int_create(128)); fx_dict_put(dict, "numbers", FX_RV(array)); diff --git a/fx.serial/test/toml-decode.c b/fx.serial/test/toml-decode.c index 2acb645..db772b6 100644 --- a/fx.serial/test/toml-decode.c +++ b/fx.serial/test/toml-decode.c @@ -1,9 +1,12 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include void write_tagged_value(fx_object *data); @@ -50,50 +53,50 @@ void write_tagged_string(fx_string *data) fx_stream_write_cstr(fx_stdout, " }", NULL); } -void write_tagged_integer(fx_number *data) +void write_tagged_integer(fx_int *data) { fx_stream_write_cstr( fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL); - if (fx_number_is_inf_positive(data)) { + if (fx_int_is_inf_positive(data)) { fx_stream_write_cstr(fx_stdout, "inf", NULL); - } else if (fx_number_is_inf_negative(data)) { + } else if (fx_int_is_inf_negative(data)) { fx_stream_write_cstr(fx_stdout, "-inf", NULL); - } else if (fx_number_is_nan_positive(data)) { + } else if (fx_int_is_nan_positive(data)) { fx_stream_write_cstr(fx_stdout, "nan", NULL); - } else if (fx_number_is_nan_negative(data)) { + } else if (fx_int_is_nan_negative(data)) { fx_stream_write_cstr(fx_stdout, "-nan", NULL); } else { fx_stream_write_fmt( fx_stdout, NULL, "%lld", - fx_number_get_longlong(data), + fx_int_get_value(data), NULL); } fx_stream_write_cstr(fx_stdout, "\" }", NULL); } -void write_tagged_float(fx_number *data) +void write_tagged_float(fx_double *data) { fx_stream_write_cstr( fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL); - if (fx_number_is_inf_positive(data)) { + if (fx_double_is_inf_positive(data)) { fx_stream_write_cstr(fx_stdout, "inf", NULL); - } else if (fx_number_is_inf_negative(data)) { + } else if (fx_double_is_inf_negative(data)) { fx_stream_write_cstr(fx_stdout, "-inf", NULL); - } else if (fx_number_is_nan_positive(data)) { + } else if (fx_double_is_nan_positive(data)) { fx_stream_write_cstr(fx_stdout, "nan", NULL); - } else if (fx_number_is_nan_negative(data)) { + } else if (fx_double_is_nan_negative(data)) { fx_stream_write_cstr(fx_stdout, "-nan", NULL); } else { - double v = fx_number_get_double(data); + double v = fx_double_get_value(data); if ((v <= 0.00000001 && v > 0) || (v >= -0.00000001 && v < 0) || (v >= 1000000000) || (v <= -1000000000)) { fx_stream_write_fmt(fx_stdout, NULL, "%.15e", v, NULL); @@ -105,14 +108,13 @@ void write_tagged_float(fx_number *data) fx_stream_write_cstr(fx_stdout, "\" }", NULL); } -void write_tagged_bool(fx_number *data) +void write_tagged_bool(fx_bool *data) { - int v = fx_number_get_int8(data); fx_stream_write_fmt( fx_stdout, NULL, "{ \"type\": \"bool\", \"value\": \"%s\" }", - (v > 0) ? "true" : "false", + fx_bool_get_value(data) ? "true" : "false", NULL); } @@ -197,30 +199,18 @@ void write_tagged_value(fx_object *data) { if (fx_object_is_type(data, FX_TYPE_DICT)) { write_tagged_dict(data); - } else if (fx_object_is_type(data, FX_TYPE_ARRAY)) { write_tagged_array(data); - } else if (fx_object_is_type(data, FX_TYPE_STRING)) { write_tagged_string(data); - } else if (fx_object_is_type(data, FX_TYPE_DATETIME)) { write_tagged_datetime(data); - - } else if (fx_object_is_type(data, FX_TYPE_NUMBER)) { - switch (fx_number_get_number_type(data)) { - case FX_NUMBER_LONGLONG: - write_tagged_integer(data); - break; - case FX_NUMBER_INT8: - write_tagged_bool(data); - break; - case FX_NUMBER_DOUBLE: - write_tagged_float(data); - break; - default: - break; - } + } else if (fx_object_is_type(data, FX_TYPE_INT)) { + write_tagged_integer(data); + } else if (fx_object_is_type(data, FX_TYPE_BOOL)) { + write_tagged_bool(data); + } else if (fx_object_is_type(data, FX_TYPE_DOUBLE)) { + write_tagged_float(data); } } diff --git a/fx.term/test/errors.c b/fx.term/test/errors.c index dd9c4b6..b1dde7a 100644 --- a/fx.term/test/errors.c +++ b/fx.term/test/errors.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -17,21 +17,28 @@ static const fx_error_definition sample_errors[] = { FX_ERROR_DEFINITION(SAMPLE_OK, "OK", "Success"), FX_ERROR_DEFINITION(SAMPLE_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"), FX_ERROR_DEFINITION_TEMPLATE( - SAMPLE_ERR_FILE_READ_FAILED, "FILE_READ_FAILED", + SAMPLE_ERR_FILE_READ_FAILED, + "FILE_READ_FAILED", "Failed to read file @i[filepath]", FX_ERROR_TEMPLATE_PARAM( - "filepath", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")), + "filepath", + FX_ERROR_TEMPLATE_PARAM_STRING, + "%s")), }; static const fx_error_msg sample_error_msg[] = { FX_ERROR_MSG_TEMPLATE( - SAMPLE_MSG_A_TEMPLATED_MSG, "A templated message: @e[param1]", + SAMPLE_MSG_A_TEMPLATED_MSG, + "A templated message: @e[param1]", FX_ERROR_TEMPLATE_PARAM( - "param1", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")), + "param1", + FX_ERROR_TEMPLATE_PARAM_STRING, + "%s")), }; static const char *sample_code_to_string( - const struct fx_error_vendor *vendor, fx_error_status_code code) + const struct fx_error_vendor *vendor, + fx_error_status_code code) { switch (code) { case SAMPLE_OK: @@ -56,15 +63,22 @@ static fx_error_vendor sample_vendor = { static fx_result error_return_3(void) { fx_result err = fx_error_with_string( - &sample_vendor, SAMPLE_ERR_IO_FAILURE, + &sample_vendor, + SAMPLE_ERR_IO_FAILURE, "I/O failure while reading file"); fx_error_add_submsg_string( - err, FX_ERROR_SUBMSG_ERROR, "An @e{error} message"); + err, + FX_ERROR_SUBMSG_ERROR, + "An @e{error} message"); fx_error_add_submsg_string( - err, FX_ERROR_SUBMSG_WARNING, "A @w{warning} message"); + err, + FX_ERROR_SUBMSG_WARNING, + "A @w{warning} message"); fx_error_add_submsg_template( - err, FX_ERROR_SUBMSG_WARNING, SAMPLE_MSG_A_TEMPLATED_MSG, + err, + FX_ERROR_SUBMSG_WARNING, + SAMPLE_MSG_A_TEMPLATED_MSG, FX_ERROR_PARAM("param1", "Hello!")); return err; @@ -105,10 +119,12 @@ static fx_result some_operation(void) fx_result result = error_return_2(); if (fx_result_is_error(result)) { fx_result err = fx_error_with_template( - &sample_vendor, SAMPLE_ERR_FILE_READ_FAILED, + &sample_vendor, + SAMPLE_ERR_FILE_READ_FAILED, FX_ERROR_PARAM("filepath", "src/Manifest.json")); fx_error_add_submsg_string( - err, FX_ERROR_SUBMSG_INFO, + err, + FX_ERROR_SUBMSG_INFO, "An @i{informational} message"); fx_error_caused_by_fx_status(result, FX_ERR_IO_FAILURE); @@ -122,7 +138,9 @@ static fx_result some_operation(void) int main(void) { - fx_set_error_report_function(fx_enhanced_error_reporter, FX_ERROR_REPORT_ALL); + fx_set_error_report_function( + fx_enhanced_error_reporter, + FX_ERROR_REPORT_ALL); test(PARAM("Hello", 1), PARAM("Goodbye", 2)); diff --git a/fx.term/test/printing.c b/fx.term/test/printing.c index c6492fb..c61f54a 100644 --- a/fx.term/test/printing.c +++ b/fx.term/test/printing.c @@ -1,6 +1,6 @@ -#include +#include #include -#include +#include #include #define F_GREEN "[green]" @@ -62,7 +62,7 @@ int main(void) size_t len = fx_string_get_size(str, FX_STRLEN_IGNORE_MOD); printf("length = %zu\n", len); - fx_paragraph_format format = { 0 }; + fx_paragraph_format format = {0}; format.p_left_margin = 5; format.p_right_margin = 5; format.p_flags = FX_PARAGRAPH_DOUBLE_LINE_BREAK; @@ -72,8 +72,11 @@ int main(void) fx_i("An informational message\n\nWith multiple lines"); fx_warn("A warning message\nWith multiple lines"); fx_err("An error message\nWith multiple lines"); - - fx_printf("[red]formatting ignored: '%s'[reset]\n[dark_grey]dark text[reset]\n", "[blue]wow![reset]"); + + fx_printf( + "[red]formatting ignored: '%s'[reset]\n[dark_grey]dark " + "text[reset]\n", + "[blue]wow![reset]"); return 0; } diff --git a/fx/test/errors.c b/fx/test/errors.c index 23fa08d..a34e564 100644 --- a/fx/test/errors.c +++ b/fx/test/errors.c @@ -1,4 +1,4 @@ -#include +#include int main(void) { diff --git a/fx/test/hash.c b/fx/test/hash.c index 7da40dd..be58c00 100644 --- a/fx/test/hash.c +++ b/fx/test/hash.c @@ -1,10 +1,13 @@ -#include +#include #include #include static void print_digest( - const char *func_name, fx_hash_function func, const char *msg, - size_t msg_len, size_t digest_len) + const char *func_name, + fx_hash_function func, + const char *msg, + size_t msg_len, + size_t digest_len) { unsigned char digest[128]; @@ -27,8 +30,10 @@ static void print_digest( char digest_str[256]; for (size_t i = 0; i < digest_len; i++) { snprintf( - digest_str + (i * 2), sizeof digest_str - (i * 2), - "%02x", digest[i]); + digest_str + (i * 2), + sizeof digest_str - (i * 2), + "%02x", + digest[i]); } printf("%s(%s) = %s\n", func_name, msg, digest_str); @@ -44,30 +49,64 @@ int main(void) print_digest("MD5", FX_HASH_MD5, msg, msg_len, FX_DIGEST_LENGTH_MD5); print_digest("SHA1", FX_HASH_SHA1, msg, msg_len, FX_DIGEST_LENGTH_SHA1); print_digest( - "SHA224", FX_HASH_SHA2_224, msg, msg_len, FX_DIGEST_LENGTH_SHA2_224); + "SHA224", + FX_HASH_SHA2_224, + msg, + msg_len, + FX_DIGEST_LENGTH_SHA2_224); print_digest( - "SHA256", FX_HASH_SHA2_256, msg, msg_len, FX_DIGEST_LENGTH_SHA2_256); + "SHA256", + FX_HASH_SHA2_256, + msg, + msg_len, + FX_DIGEST_LENGTH_SHA2_256); print_digest( - "SHA384", FX_HASH_SHA2_384, msg, msg_len, FX_DIGEST_LENGTH_SHA2_384); + "SHA384", + FX_HASH_SHA2_384, + msg, + msg_len, + FX_DIGEST_LENGTH_SHA2_384); print_digest( - "SHA512", FX_HASH_SHA2_512, msg, msg_len, FX_DIGEST_LENGTH_SHA2_512); + "SHA512", + FX_HASH_SHA2_512, + msg, + msg_len, + FX_DIGEST_LENGTH_SHA2_512); print_digest( - "SHA3-224", FX_HASH_SHA3_224, msg, msg_len, + "SHA3-224", + FX_HASH_SHA3_224, + msg, + msg_len, FX_DIGEST_LENGTH_SHA3_224); print_digest( - "SHA3-256", FX_HASH_SHA3_256, msg, msg_len, + "SHA3-256", + FX_HASH_SHA3_256, + msg, + msg_len, FX_DIGEST_LENGTH_SHA3_256); print_digest( - "SHA3-384", FX_HASH_SHA3_384, msg, msg_len, + "SHA3-384", + FX_HASH_SHA3_384, + msg, + msg_len, FX_DIGEST_LENGTH_SHA3_384); print_digest( - "SHA3-512", FX_HASH_SHA3_512, msg, msg_len, + "SHA3-512", + FX_HASH_SHA3_512, + msg, + msg_len, FX_DIGEST_LENGTH_SHA3_512); print_digest( - "SHAKE128", FX_HASH_SHAKE128, msg, msg_len, + "SHAKE128", + FX_HASH_SHAKE128, + msg, + msg_len, FX_DIGEST_LENGTH_SHAKE128); print_digest( - "SHAKE256", FX_HASH_SHAKE256, msg, msg_len, + "SHAKE256", + FX_HASH_SHAKE256, + msg, + msg_len, FX_DIGEST_LENGTH_SHAKE256); return 0; diff --git a/fx/test/randomise.c b/fx/test/randomise.c index 2f59e68..516ebef 100644 --- a/fx/test/randomise.c +++ b/fx/test/randomise.c @@ -1,4 +1,4 @@ -#include +#include #include #define NRAND_NUMBERS 12 diff --git a/fx/test/ringbuffers.c b/fx/test/ringbuffers.c index eb1ab5c..4922295 100644 --- a/fx/test/ringbuffers.c +++ b/fx/test/ringbuffers.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/fx/test/ropes.c b/fx/test/ropes.c index 24dfc1a..5667d81 100644 --- a/fx/test/ropes.c +++ b/fx/test/ropes.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/fx/test/streams.c b/fx/test/streams.c index ca6c393..9386327 100644 --- a/fx/test/streams.c +++ b/fx/test/streams.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include int main(void) diff --git a/fx.collections/test/strings.c b/fx/test/strings.c similarity index 74% rename from fx.collections/test/strings.c rename to fx/test/strings.c index 66b864c..6b72f2c 100644 --- a/fx.collections/test/strings.c +++ b/fx/test/strings.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -8,21 +8,24 @@ int main(void) printf("-------------\n"); fx_string *str = fx_string_create_from_cstr("Hello, world!\n"); printf("%s\n", fx_string_get_cstr(str)); - printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL), + printf("len:%zu, max:%zu\n", + fx_string_get_size(str, FX_STRLEN_NORMAL), fx_string_get_capacity(str)); fx_string_insert_cstr(str, "WOW!", 4); printf("-------------\n"); printf("%s\n", fx_string_get_cstr(str)); - printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL), + printf("len:%zu, max:%zu\n", + fx_string_get_size(str, FX_STRLEN_NORMAL), fx_string_get_capacity(str)); fx_string_replace(str, 4, 4, "+"); printf("-------------\n"); printf("%s\n", fx_string_get_cstr(str)); - printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL), + printf("len:%zu, max:%zu\n", + fx_string_get_size(str, FX_STRLEN_NORMAL), fx_string_get_capacity(str)); printf("-------------\n"); diff --git a/fx.collections/test/unicode-strings.c b/fx/test/unicode-strings.c similarity index 80% rename from fx.collections/test/unicode-strings.c rename to fx/test/unicode-strings.c index 09dc242..99f6f4a 100644 --- a/fx.collections/test/unicode-strings.c +++ b/fx/test/unicode-strings.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -10,7 +10,8 @@ int main(void) const char *s = fx_string_get_cstr(str); printf("%s\n", s); printf("len: %zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL)); - printf("codepoints: %zu\n", fx_string_get_size(str, FX_STRLEN_CODEPOINTS)); + printf("codepoints: %zu\n", + fx_string_get_size(str, FX_STRLEN_CODEPOINTS)); const char *delims[] = {"в"}; size_t nr_delims = sizeof delims / sizeof delims[0]; diff --git a/fx/test/unit-tests.c b/fx/test/unit-tests.c deleted file mode 100644 index aa6c79c..0000000 --- a/fx/test/unit-tests.c +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -struct test_tree_node { - int value; - fx_bst_node node; -}; - -struct test_queue_entry { - int value; - fx_queue_entry entry; -}; - -FX_BST_DEFINE_SIMPLE_INSERT(struct test_tree_node, node, value, test_tree_insert); - -void test_bst_insert(CuTest *tc) -{ - fx_bst tree = {0}; - struct test_tree_node nodes[3] = {0}; - - for (int i = 0; i < sizeof nodes / sizeof *nodes; i++) { - nodes[i].value = i; - } - - test_tree_insert(&tree, &nodes[0]); - - CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left); - CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right); - CuAssertIntEquals(tc, 1, nodes[0].node.n_height); - - test_tree_insert(&tree, &nodes[1]); - - CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left); - CuAssertPtrEquals(tc, &nodes[1].node, nodes[0].node.n_right); - CuAssertIntEquals(tc, 2, nodes[0].node.n_height); - - CuAssertPtrEquals(tc, NULL, nodes[1].node.n_left); - CuAssertPtrEquals(tc, NULL, nodes[1].node.n_right); - CuAssertIntEquals(tc, 1, nodes[1].node.n_height); - - test_tree_insert(&tree, &nodes[2]); - - CuAssertPtrEquals(tc, &nodes[0].node, nodes[1].node.n_left); - CuAssertPtrEquals(tc, &nodes[2].node, nodes[1].node.n_right); - CuAssertIntEquals(tc, 2, nodes[1].node.n_height); - - CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left); - CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right); - CuAssertIntEquals(tc, 1, nodes[0].node.n_height); - - CuAssertPtrEquals(tc, NULL, nodes[2].node.n_left); - CuAssertPtrEquals(tc, NULL, nodes[2].node.n_right); - CuAssertIntEquals(tc, 1, nodes[2].node.n_height); -} - -void test_bst_iterate(CuTest *tc) -{ - static const size_t nr_nodes = 256; - srand(time(NULL)); - - fx_bst tree = {0}; - struct test_tree_node *nodes = calloc(nr_nodes, sizeof *nodes); - CuAssertPtrNotNull(tc, nodes); - - for (int i = 0; i < nr_nodes; i++) { - nodes[i].value = rand(); - test_tree_insert(&tree, &nodes[i]); - } - - int prev = -1; - fx_bst_node *bnode = fx_bst_first(&tree); - while (bnode) { - struct test_tree_node *node - = fx_unbox(struct test_tree_node, bnode, node); - CuAssertPtrNotNull(tc, node); - - if (prev == -1) { - prev = node->value; - bnode = fx_bst_next(bnode); - continue; - } - - CuAssertTrue(tc, prev <= node->value); - prev = node->value; - bnode = fx_bst_next(bnode); - } - - free(nodes); -} - -void test_queue_insert(CuTest *tc) -{ - struct test_queue_entry entries[5] = {0}; - for (int i = 0; i < sizeof entries / sizeof *entries; i++) { - entries[i].value = i; - } - - fx_queue q = FX_QUEUE_INIT; - - fx_queue_push_back(&q, &entries[0].entry); - fx_queue_push_back(&q, &entries[2].entry); - fx_queue_push_back(&q, &entries[4].entry); - fx_queue_insert_after(&q, &entries[3].entry, &entries[2].entry); - fx_queue_insert_before(&q, &entries[1].entry, &entries[2].entry); - - CuAssertPtrEquals(tc, NULL, entries[0].entry.qe_prev); - CuAssertPtrEquals(tc, &entries[1].entry, entries[0].entry.qe_next); - - CuAssertPtrEquals(tc, &entries[0].entry, entries[1].entry.qe_prev); - CuAssertPtrEquals(tc, &entries[2].entry, entries[1].entry.qe_next); - - CuAssertPtrEquals(tc, &entries[1].entry, entries[2].entry.qe_prev); - CuAssertPtrEquals(tc, &entries[3].entry, entries[2].entry.qe_next); - - CuAssertPtrEquals(tc, &entries[2].entry, entries[3].entry.qe_prev); - CuAssertPtrEquals(tc, &entries[4].entry, entries[3].entry.qe_next); - - CuAssertPtrEquals(tc, &entries[3].entry, entries[4].entry.qe_prev); - CuAssertPtrEquals(tc, NULL, entries[4].entry.qe_next); -} - -void test_queue_iterate(CuTest *tc) -{ - fx_queue q = FX_QUEUE_INIT; - struct test_queue_entry entries[32] = {0}; - - for (int i = 0; i < sizeof entries / sizeof *entries; i++) { - entries[i].value = i; - fx_queue_push_back(&q, &entries[i].entry); - } - - int prev = -1; - struct fx_queue_entry *entry = fx_queue_first(&q); - while (entry) { - struct test_queue_entry *e - = fx_unbox(struct test_queue_entry, entry, entry); - CuAssertPtrNotNull(tc, e); - - if (prev == -1) { - prev = e->value; - goto skip; - } - - CuAssertTrue(tc, prev < e->value); - prev = e->value; - skip: - entry = fx_queue_next(entry); - } -} - -void test_stringstream_1(CuTest *tc) -{ - char buf[1024]; - fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf); - - fx_stream_write_cstr(s, "hello", NULL); - fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3); - - char *end = fx_stringstream_steal(s); - fx_stringstream_unref(s); - - CuAssertStrEquals(tc, "hello(32 + 2.3)", end); -} - -void test_stringstream_2(CuTest *tc) -{ - char buf[1024]; - fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf); - - fx_stream_write_cstr(s, "{\n", NULL); - fx_stream_push_indent(s, 1); - - fx_stream_write_cstr(s, "a = 32,\n", NULL); - fx_stream_write_cstr(s, "b = 64\n", NULL); - - fx_stream_pop_indent(s); - fx_stream_write_cstr(s, "}", NULL); - - char *str = fx_stringstream_steal(s); - fx_stringstream_unref(s); - - CuAssertStrEquals(tc, "{\n a = 32,\n b = 64\n}", str); -} - -CuSuite *get_all_tests(void) -{ - CuSuite *suite = CuSuiteNew(); - - SUITE_ADD_TEST(suite, test_bst_insert); - SUITE_ADD_TEST(suite, test_bst_iterate); - SUITE_ADD_TEST(suite, test_queue_insert); - SUITE_ADD_TEST(suite, test_queue_iterate); - SUITE_ADD_TEST(suite, test_stringstream_1); - SUITE_ADD_TEST(suite, test_stringstream_2); - - return suite; -} diff --git a/fx.collections/test/uuids.c b/fx/test/uuids.c similarity index 90% rename from fx.collections/test/uuids.c rename to fx/test/uuids.c index 885230f..b27d660 100644 --- a/fx.collections/test/uuids.c +++ b/fx/test/uuids.c @@ -1,4 +1,4 @@ -#include +#include #include int main(void)