Skip to content

Commit

Permalink
filterx: move primitive object tests to their respective test program
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Apr 21, 2024
1 parent cefe449 commit 75114c7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 85 deletions.
31 changes: 31 additions & 0 deletions lib/filterx/tests/test_object_boolean.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@
#include "apphook.h"
#include "scratch-buffers.h"

Test(filterx_boolean, test_filterx_primitive_bool_marshales_to_bool_repr)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
assert_marshaled_object(fobj, "true", LM_VT_BOOLEAN);
filterx_object_unref(fobj);
}

Test(filterx_boolean, test_filterx_primitive_bool_is_mapped_to_a_json_bool)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
assert_object_json_equals(fobj, "true");
filterx_object_unref(fobj);

fobj = filterx_boolean_new(FALSE);
assert_object_json_equals(fobj, "false");
filterx_object_unref(fobj);
}

Test(filterx_boolean, test_filterx_primitive_bool_is_truthy_if_true)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_boolean_new(0.0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

Test(filterx_boolean, test_filterx_boolean_typecast_null_args)
{
GPtrArray *args = NULL;
Expand Down
28 changes: 28 additions & 0 deletions lib/filterx/tests/test_object_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@
#include "apphook.h"
#include "scratch-buffers.h"


Test(filterx_double, test_filterx_primitive_double_marshales_to_double_repr)
{
FilterXObject *fobj = filterx_double_new(36.07);
assert_marshaled_object(fobj, "36.07", LM_VT_DOUBLE);
filterx_object_unref(fobj);
}

Test(filterx_double, test_filterx_primitive_double_is_mapped_to_a_json_float)
{
FilterXObject *fobj = filterx_double_new(36.0);
assert_object_json_equals(fobj, "36.0");
filterx_object_unref(fobj);
}

Test(filterx_double, test_filterx_primitive_double_is_truthy_if_nonzero)
{
FilterXObject *fobj = filterx_double_new(1);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_double_new(0.0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

Test(filterx_double, test_filterx_double_typecast_null_args)
{
GPtrArray *args = NULL;
Expand Down
29 changes: 29 additions & 0 deletions lib/filterx/tests/test_object_integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@
#include "apphook.h"
#include "scratch-buffers.h"



Test(filterx_integer, test_filterx_primitive_int_marshales_to_integer_repr)
{
FilterXObject *fobj = filterx_integer_new(36);
assert_marshaled_object(fobj, "36", LM_VT_INTEGER);
filterx_object_unref(fobj);
}

Test(filterx_integer, test_filterx_primitive_int_is_mapped_to_a_json_int)
{
FilterXObject *fobj = filterx_integer_new(36);
assert_object_json_equals(fobj, "36");
filterx_object_unref(fobj);
}

Test(filterx_integer, test_filterx_primitive_int_is_truthy_if_nonzero)
{
FilterXObject *fobj = filterx_integer_new(36);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_integer_new(0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

Test(filterx_integer, test_filterx_integer_typecast_null_args)
{
GPtrArray *args = NULL;
Expand Down
85 changes: 0 additions & 85 deletions lib/filterx/tests/test_object_primitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,91 +35,6 @@ Test(filterx_object, test_filterx_object_construction_and_free)
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_int_marshales_to_integer_repr)
{
FilterXObject *fobj = filterx_integer_new(36);
assert_marshaled_object(fobj, "36", LM_VT_INTEGER);
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_int_is_mapped_to_a_json_int)
{
FilterXObject *fobj = filterx_integer_new(36);
assert_object_json_equals(fobj, "36");
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_int_is_truthy_if_nonzero)
{
FilterXObject *fobj = filterx_integer_new(36);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_integer_new(0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_double_marshales_to_double_repr)
{
FilterXObject *fobj = filterx_double_new(36.07);
assert_marshaled_object(fobj, "36.07", LM_VT_DOUBLE);
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_double_is_mapped_to_a_json_float)
{
FilterXObject *fobj = filterx_double_new(36.0);
assert_object_json_equals(fobj, "36.0");
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_double_is_truthy_if_nonzero)
{
FilterXObject *fobj = filterx_double_new(1);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_double_new(0.0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_bool_marshales_to_bool_repr)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
assert_marshaled_object(fobj, "true", LM_VT_BOOLEAN);
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_bool_is_mapped_to_a_json_bool)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
assert_object_json_equals(fobj, "true");
filterx_object_unref(fobj);

fobj = filterx_boolean_new(FALSE);
assert_object_json_equals(fobj, "false");
filterx_object_unref(fobj);
}

Test(filterx_object, test_filterx_primitive_bool_is_truthy_if_true)
{
FilterXObject *fobj = filterx_boolean_new(TRUE);
cr_assert(filterx_object_truthy(fobj));
cr_assert_not(filterx_object_falsy(fobj));
filterx_object_unref(fobj);

fobj = filterx_boolean_new(0.0);
cr_assert_not(filterx_object_truthy(fobj));
cr_assert(filterx_object_falsy(fobj));
filterx_object_unref(fobj);
}

static void
setup(void)
{
Expand Down

0 comments on commit 75114c7

Please sign in to comment.