From b07263249914e71fb7838106c7f1bda2a4cc5507 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 2 May 2026 14:31:17 +0100 Subject: [PATCH] test: update tests --- test/ds/ds-units.c | 6 ++--- test/ds/strings.c | 6 ++--- test/ds/trees.c | 2 +- test/ds/unicode-strings.c | 2 +- test/json-read.c | 6 ++--- test/serial/toml-decode.c | 54 +++++++++++++++++++++++++++++---------- test/toml-read.c | 6 ++--- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/test/ds/ds-units.c b/test/ds/ds-units.c index c157158..d72732c 100644 --- a/test/ds/ds-units.c +++ b/test/ds/ds-units.c @@ -7,7 +7,7 @@ static void test_string_create(CuTest *tc) CuAssertPtrNotNull(tc, str); CuAssertIntEquals(tc, 0, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "", fx_string_ptr(str)); + CuAssertStrEquals(tc, "", fx_string_get_cstr(str)); fx_string_unref(str); @@ -15,7 +15,7 @@ static void test_string_create(CuTest *tc) CuAssertPtrNotNull(tc, str); CuAssertIntEquals(tc, 8, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "AAAAAAAA", fx_string_ptr(str)); + CuAssertStrEquals(tc, "AAAAAAAA", fx_string_get_cstr(str)); fx_string_unref(str); @@ -23,7 +23,7 @@ static void test_string_create(CuTest *tc) CuAssertPtrNotNull(tc, str); CuAssertIntEquals(tc, 13, fx_string_get_size(str, FX_STRLEN_NORMAL)); - CuAssertStrEquals(tc, "Hello, world!", fx_string_ptr(str)); + CuAssertStrEquals(tc, "Hello, world!", fx_string_get_cstr(str)); fx_string_unref(str); } diff --git a/test/ds/strings.c b/test/ds/strings.c index c8a8bf5..66b864c 100644 --- a/test/ds/strings.c +++ b/test/ds/strings.c @@ -7,21 +7,21 @@ int main(void) { printf("-------------\n"); fx_string *str = fx_string_create_from_cstr("Hello, world!\n"); - printf("%s\n", fx_string_ptr(str)); + printf("%s\n", fx_string_get_cstr(str)); 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_ptr(str)); + printf("%s\n", fx_string_get_cstr(str)); 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_ptr(str)); + printf("%s\n", fx_string_get_cstr(str)); printf("len:%zu, max:%zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL), fx_string_get_capacity(str)); printf("-------------\n"); diff --git a/test/ds/trees.c b/test/ds/trees.c index 5970ea2..cca2efd 100644 --- a/test/ds/trees.c +++ b/test/ds/trees.c @@ -33,7 +33,7 @@ int main(void) size_t i = 0; fx_foreach(fx_dict_item *, item, it) { - printf("item %zu: %s=%d\n", i++, fx_string_ptr(item->key), + printf("item %zu: %s=%d\n", i++, fx_string_get_cstr(item->key), fx_number_get_int(item->value)); } diff --git a/test/ds/unicode-strings.c b/test/ds/unicode-strings.c index 7976286..09dc242 100644 --- a/test/ds/unicode-strings.c +++ b/test/ds/unicode-strings.c @@ -7,7 +7,7 @@ int main(void) { printf("здравс\u26A0твуите\n"); fx_string *str = fx_string_create_from_cstr("здравствуите"); - const char *s = fx_string_ptr(str); + 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)); diff --git a/test/json-read.c b/test/json-read.c index ae46346..096db67 100644 --- a/test/json-read.c +++ b/test/json-read.c @@ -23,9 +23,9 @@ int main(int argc, const char **argv) fx_serial_ctx *ctx = NULL; fx_object *data; - fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0); - if (!FX_OK(status)) { - fprintf(stderr, "cannot read data\n"); + result = fx_serial_ctx_deserialise(ctx, src, &data, 0); + if (fx_result_is_error(result)) { + fx_throw(result); return -1; } diff --git a/test/serial/toml-decode.c b/test/serial/toml-decode.c index 7dcda01..2acb645 100644 --- a/test/serial/toml-decode.c +++ b/test/serial/toml-decode.c @@ -19,7 +19,12 @@ void write_raw_string(const fx_string *data) c -= 0x10000; long hi = 0xD800 | ((c >> 10) & 0x3FF); long lo = 0xDC00 | (c & 0x3FF); - fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x\\u%04x", hi, lo); + fx_stream_write_fmt( + fx_stdout, + NULL, + "\\u%04x\\u%04x", + hi, + lo); } else if (c <= 0x1F || c >= 0x7F) { fx_stream_write_fmt(fx_stdout, NULL, "\\u%04x", c); } else if (c == '\\' || c == '"') { @@ -35,7 +40,10 @@ void write_raw_string(const fx_string *data) void write_tagged_string(fx_string *data) { - fx_stream_write_cstr(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL); + fx_stream_write_cstr( + fx_stdout, + "{ \"type\": \"string\", \"value\": ", + NULL); write_raw_string(data); @@ -45,7 +53,9 @@ void write_tagged_string(fx_string *data) void write_tagged_integer(fx_number *data) { fx_stream_write_cstr( - fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL); + fx_stdout, + "{ \"type\": \"integer\", \"value\": \"", + NULL); if (fx_number_is_inf_positive(data)) { fx_stream_write_cstr(fx_stdout, "inf", NULL); @@ -57,7 +67,11 @@ void write_tagged_integer(fx_number *data) fx_stream_write_cstr(fx_stdout, "-nan", NULL); } else { fx_stream_write_fmt( - fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL); + fx_stdout, + NULL, + "%lld", + fx_number_get_longlong(data), + NULL); } fx_stream_write_cstr(fx_stdout, "\" }", NULL); @@ -66,7 +80,9 @@ void write_tagged_integer(fx_number *data) void write_tagged_float(fx_number *data) { fx_stream_write_cstr( - fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL); + fx_stdout, + "{ \"type\": \"float\", \"value\": \"", + NULL); if (fx_number_is_inf_positive(data)) { fx_stream_write_cstr(fx_stdout, "inf", NULL); @@ -93,8 +109,11 @@ void write_tagged_bool(fx_number *data) { int v = fx_number_get_int8(data); fx_stream_write_fmt( - fx_stdout, NULL, "{ \"type\": \"bool\", \"value\": \"%s\" }", - (v > 0) ? "true" : "false", NULL); + fx_stdout, + NULL, + "{ \"type\": \"bool\", \"value\": \"%s\" }", + (v > 0) ? "true" : "false", + NULL); } void write_tagged_datetime(fx_datetime *data) @@ -107,20 +126,26 @@ void write_tagged_datetime(fx_datetime *data) if (has_date && has_time) { fx_stream_write_cstr( - fx_stdout, localtime ? "datetime-local" : "datetime", NULL); + fx_stdout, + localtime ? "datetime-local" : "datetime", + NULL); } else if (has_date) { fx_stream_write_cstr( - fx_stdout, localtime ? "date-local" : "date", NULL); + fx_stdout, + localtime ? "date-local" : "date", + NULL); } else if (has_time) { fx_stream_write_cstr( - fx_stdout, localtime ? "time-local" : "time", NULL); + fx_stdout, + localtime ? "time-local" : "time", + NULL); } fx_stream_write_cstr(fx_stdout, "\", \"value\": \"", NULL); fx_string *new_data = fx_string_create(); fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data); - fx_stream_write_cstr(fx_stdout, fx_string_ptr(new_data), NULL); + fx_stream_write_cstr(fx_stdout, fx_string_get_cstr(new_data), NULL); fx_stream_write_cstr(fx_stdout, "\" }", NULL); @@ -207,9 +232,10 @@ int main(void) fx_serial_ctx *ctx = fx_toml_serial_ctx_create(); fx_object *data; - fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0); - if (!FX_OK(status)) { - return 1; + fx_result result = fx_serial_ctx_deserialise(ctx, src, &data, 0); + if (fx_result_is_error(result)) { + fx_throw(result); + return -1; } write_tagged_value(data); diff --git a/test/toml-read.c b/test/toml-read.c index 85a9b0e..87169cb 100644 --- a/test/toml-read.c +++ b/test/toml-read.c @@ -23,9 +23,9 @@ int main(int argc, const char **argv) fx_serial_ctx *ctx = fx_toml_serial_ctx_create(); fx_object *data = NULL; - fx_status status = fx_serial_ctx_deserialise(ctx, src, &data, 0); - if (!FX_OK(status)) { - fprintf(stderr, "cannot read data\n"); + result = fx_serial_ctx_deserialise(ctx, src, &data, 0); + if (fx_result_is_error(result)) { + fx_throw(result); return -1; }