Skip to content

Commit

Permalink
filterx: test repr_append()
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
  • Loading branch information
alltilla committed May 17, 2024
1 parent d14e060 commit e08e683
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 19 deletions.
3 changes: 3 additions & 0 deletions lib/filterx/tests/test_object_boolean.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ Test(filterx_boolean, test_filterx_boolean_repr)
{
FilterXObject *obj = filterx_boolean_new(TRUE);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("true", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("truetrue", repr->str);
filterx_object_unref(obj);
}

Expand Down
12 changes: 12 additions & 0 deletions lib/filterx/tests/test_object_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ Test(filterx_bytes, test_filterx_bytes_typecast_from_protobuf)
filterx_object_unref(obj);
}

Test(filterx_bytes, filterx_bytes_repr)
{
FilterXObject *obj = filterx_bytes_new("\0\1\2\3", 4);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("00010203", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("0001020300010203", repr->str);
filterx_object_unref(obj);
}

static void
setup(void)
{
Expand Down
7 changes: 4 additions & 3 deletions lib/filterx/tests/test_object_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,20 @@ Test(filterx_datetime, test_filterx_datetime_typecast_from_datetime)

Test(filterx_datetime, test_filterx_datetime_repr)
{
const gchar *test_time_str = "2024-03-18T12:34:13+234";
GPtrArray *args = g_ptr_array_new_with_free_func((GDestroyNotify) filterx_object_unref);
FilterXObject *in = filterx_string_new(test_time_str, -1);
FilterXObject *in = filterx_string_new("2024-03-18T12:34:13+234", -1);
g_ptr_array_add(args, in);

FilterXObject *obj = filterx_typecast_datetime(args);
cr_assert_not_null(obj);
cr_assert(filterx_object_is_type(obj, &FILTERX_TYPE_NAME(datetime)));

GString *repr = scratch_buffers_alloc();

g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("2024-03-18T12:34:13.000+01:00", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("2024-03-18T12:34:13.000+01:002024-03-18T12:34:13.000+01:00", repr->str);

g_ptr_array_free(args, TRUE);
filterx_object_unref(obj);
Expand Down
3 changes: 3 additions & 0 deletions lib/filterx/tests/test_object_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ Test(filterx_double, test_filterx_double_repr)
{
FilterXObject *obj = filterx_double_new(123.456);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("123.456", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("123.456123.456", repr->str);
filterx_object_unref(obj);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/filterx/tests/test_object_integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ Test(filterx_integer, test_filterx_integer_repr)
{
FilterXObject *obj = filterx_integer_new(65566);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("65566", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("6556665566", repr->str);
filterx_object_unref(obj);
}

Expand Down
25 changes: 25 additions & 0 deletions lib/filterx/tests/test_object_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "filterx/object-message-value.h"
#include "filterx/expr-function.h"
#include "apphook.h"
#include "scratch-buffers.h"

Test(filterx_json, test_filterx_object_json_from_repr)
{
Expand Down Expand Up @@ -164,6 +165,30 @@ Test(filterx_json, test_json_array_function)
filterx_object_unref(fobj);
}

Test(filterx_json, filterx_json_object_repr)
{
FilterXObject *obj = filterx_json_object_new_from_repr("{\"foo\": \"foovalue\"}", -1);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("{\"foo\":\"foovalue\"}", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("{\"foo\":\"foovalue\"}{\"foo\":\"foovalue\"}", repr->str);
filterx_object_unref(obj);
}

Test(filterx_json, filterx_json_array_repr)
{
FilterXObject *obj = filterx_json_array_new_from_repr("[\"foo\", \"bar\"]", -1);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(obj, repr));
cr_assert_str_eq("[\"foo\",\"bar\"]", repr->str);
cr_assert(filterx_object_repr_append(obj, repr));
cr_assert_str_eq("[\"foo\",\"bar\"][\"foo\",\"bar\"]", repr->str);
filterx_object_unref(obj);
}

static void
setup(void)
{
Expand Down
51 changes: 35 additions & 16 deletions lib/filterx/tests/test_object_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,52 +77,59 @@ Test(filterx_message, test_filterx_message_type_null_repr)
{
FilterXObject *fobj = filterx_message_value_new(NULL, 0, LM_VT_NULL);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("null", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("nullnull", repr->str);
filterx_object_unref(fobj);
}

Test(filterx_message, test_filterx_message_type_string_repr)
{
gchar *test_str = "any string";

FilterXObject *fobj = filterx_message_value_new(test_str, -1, LM_VT_STRING);
FilterXObject *fobj = filterx_message_value_new("any string", -1, LM_VT_STRING);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, repr->str);
cr_assert_str_eq("any string", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("any stringany string", repr->str);
filterx_object_unref(fobj);
}

Test(filterx_message, test_filterx_message_type_bytes_repr)
{
gchar *test_str = "any bytes";

FilterXObject *fobj = filterx_message_value_new(test_str, -1, LM_VT_BYTES);
FilterXObject *fobj = filterx_message_value_new("any bytes", -1, LM_VT_BYTES);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, repr->str);
cr_assert_str_eq("any bytes", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("any bytesany bytes", repr->str);
filterx_object_unref(fobj);
}

Test(filterx_message, test_filterx_message_type_protobuf_repr)
{
gchar *test_str = "not a valid protobuf!";

FilterXObject *fobj = filterx_message_value_new(test_str, -1, LM_VT_PROTOBUF);
FilterXObject *fobj = filterx_message_value_new("not a valid protobuf!", -1, LM_VT_PROTOBUF);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, repr->str);
cr_assert_str_eq("not a valid protobuf!", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("not a valid protobuf!not a valid protobuf!", repr->str);
filterx_object_unref(fobj);
}

Test(filterx_message, test_filterx_message_type_json_repr)
{
gchar *test_str = "{\"test\":\"json\"}";

FilterXObject *fobj = filterx_message_value_new(test_str, -1, LM_VT_JSON);
FilterXObject *fobj = filterx_message_value_new("{\"test\": \"json\"}", -1, LM_VT_JSON);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, repr->str);
cr_assert_str_eq("{\"test\": \"json\"}", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("{\"test\": \"json\"}{\"test\": \"json\"}", repr->str);
filterx_object_unref(fobj);
}

Expand All @@ -131,8 +138,11 @@ Test(filterx_message, test_filterx_message_type_boolean_repr)
gchar *val = "T";
FilterXObject *fobj = filterx_message_value_new(val, -1, LM_VT_BOOLEAN);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("true", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("truetrue", repr->str);
filterx_object_unref(fobj);
}

Expand All @@ -141,8 +151,11 @@ Test(filterx_message, test_filterx_message_type_int_repr)
gchar *val = "443";
FilterXObject *fobj = filterx_message_value_new(val, -1, LM_VT_INTEGER);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("443", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("443443", repr->str);
filterx_object_unref(fobj);
}

Expand All @@ -151,8 +164,11 @@ Test(filterx_message, test_filterx_message_type_double_repr)
gchar *val = "17.756";
FilterXObject *fobj = filterx_message_value_new(val, -1, LM_VT_DOUBLE);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("17.756", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("17.75617.756", repr->str);
filterx_object_unref(fobj);
}

Expand All @@ -161,8 +177,11 @@ Test(filterx_message, test_filterx_message_type_datetime_repr)
gchar *val = "1713520972.000000+02:00";
FilterXObject *fobj = filterx_message_value_new(val, -1, LM_VT_DATETIME);
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("2024-04-19T12:02:52.000+02:00", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("2024-04-19T12:02:52.000+02:002024-04-19T12:02:52.000+02:00", repr->str);
filterx_object_unref(fobj);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/filterx/tests/test_object_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ Test(filterx_null, test_filterx_object_null_repr)
{
FilterXObject *fobj = filterx_null_new();
GString *repr = scratch_buffers_alloc();
g_string_assign(repr, "foo");
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("null", repr->str);
cr_assert(filterx_object_repr_append(fobj, repr));
cr_assert_str_eq("nullnull", repr->str);
filterx_object_unref(fobj);
}

static void
Expand Down

0 comments on commit e08e683

Please sign in to comment.