Skip to content

Commit

Permalink
filterx: message_value repr unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: shifter <[email protected]>
  • Loading branch information
bshifter committed Apr 19, 2024
1 parent 1021849 commit d033ab5
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions lib/filterx/tests/test_object_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "filterx/object-message-value.h"
#include "apphook.h"
#include "filterx-lib.h"
#include "scratch-buffers.h"

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
Expand Down Expand Up @@ -83,6 +84,100 @@ Test(filterx_message, test_filterx_object_value_maps_to_the_right_json_value)
filterx_object_unref(fobj);
}

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();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("null", 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);
GString *repr = scratch_buffers_alloc();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, 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);
GString *repr = scratch_buffers_alloc();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, 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);
GString *repr = scratch_buffers_alloc();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, 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);
GString *repr = scratch_buffers_alloc();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq(test_str, repr->str);
filterx_object_unref(fobj);
}

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();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("true", repr->str);
filterx_object_unref(fobj);
}

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();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("443", repr->str);
filterx_object_unref(fobj);
}

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();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("17.756", repr->str);
filterx_object_unref(fobj);
}

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();
cr_assert(filterx_object_repr(fobj, repr));
cr_assert_str_eq("2024-04-19T12:02:52.000+02:00", repr->str);
filterx_object_unref(fobj);
}


static void
setup(void)
{
Expand All @@ -92,6 +187,7 @@ setup(void)
static void
teardown(void)
{
scratch_buffers_explicit_gc();
app_shutdown();
}

Expand Down

0 comments on commit d033ab5

Please sign in to comment.