Skip to content

Commit

Permalink
filterx: merge libtest/filterx and lib/filterx/tests/filterx-lib into…
Browse files Browse the repository at this point in the history
… libtest

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Apr 21, 2024
1 parent 49028c6 commit cefe449
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 139 deletions.
3 changes: 1 addition & 2 deletions lib/filterx/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ lib_filterx_tests_TESTS = \
lib/filterx/tests/test_type_registry \
lib/filterx/tests/test_filterx_object

EXTRA_DIST += lib/filterx/tests/CMakeLists.txt \
lib/filterx/tests/filterx-lib.h
EXTRA_DIST += lib/filterx/tests/CMakeLists.txt

check_PROGRAMS += ${lib_filterx_tests_TESTS}

Expand Down
37 changes: 0 additions & 37 deletions lib/filterx/tests/filterx-lib.h

This file was deleted.

14 changes: 1 addition & 13 deletions lib/filterx/tests/test_filterx_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "apphook.h"
#include "scratch-buffers.h"

#include "filterx-lib.h"
#include "libtest/filterx-lib.h"

static void
_assert_int_value_and_unref(FilterXObject *object, gint64 expected_value)
Expand Down Expand Up @@ -379,18 +379,6 @@ Test(filterx_expr, test_filterx_assign)
filterx_eval_set_context(NULL);
}

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_expr, test_filterx_setattr)
{
LogMessage *msg = create_sample_message();
Expand Down
2 changes: 2 additions & 0 deletions lib/filterx/tests/test_object_boolean.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-string.h"
#include "filterx/object-null.h"
#include "filterx/object-primitive.h"
Expand Down
14 changes: 2 additions & 12 deletions lib/filterx/tests/test_object_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,17 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-datetime.h"
#include "filterx/object-primitive.h"
#include "filterx/object-null.h"
#include "filterx/object-string.h"
#include "apphook.h"
#include "filterx-lib.h"
#include "scratch-buffers.h"
#include "filterx/expr-literal.h"
#include "filterx/expr-function.h"

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_datetime, test_filterx_object_datetime_marshals_to_the_stored_values)
{
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-string.h"
#include "filterx/object-null.h"
#include "filterx/object-primitive.h"

#include "apphook.h"
#include "scratch-buffers.h"

Expand Down
2 changes: 2 additions & 0 deletions lib/filterx/tests/test_object_integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-string.h"
#include "filterx/object-null.h"
#include "filterx/object-primitive.h"
Expand Down
15 changes: 2 additions & 13 deletions lib/filterx/tests/test_object_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,13 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-json.h"
#include "filterx/object-string.h"
#include "filterx/object-message-value.h"
#include "filterx/expr-function.h"
#include "apphook.h"
#include "filterx-lib.h"

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_json, test_filterx_object_json_from_repr)
{
Expand Down
15 changes: 2 additions & 13 deletions lib/filterx/tests/test_object_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#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)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_message, test_filterx_object_message_marshals_to_the_stored_values)
{
FilterXObject *fobj = filterx_message_value_new("True", 4, LM_VT_BOOLEAN);
Expand Down
15 changes: 2 additions & 13 deletions lib/filterx/tests/test_object_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-null.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)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_null, test_filterx_object_null_marshals_to_the_stored_values)
{
FilterXObject *fobj = filterx_null_new();
Expand Down
15 changes: 2 additions & 13 deletions lib/filterx/tests/test_object_primitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/filterx-object.h"
#include "filterx/object-primitive.h"
#include "filterx/object-message-value.h"
#include "apphook.h"
#include "filterx-lib.h"

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_object, test_filterx_object_construction_and_free)
{
Expand Down
15 changes: 2 additions & 13 deletions lib/filterx/tests/test_object_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,13 @@
*
*/
#include <criterion/criterion.h>
#include "libtest/filterx-lib.h"

#include "filterx/object-string.h"
#include "filterx/object-null.h"

#include "apphook.h"
#include "scratch-buffers.h"
#include "filterx-lib.h"

static void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}

Test(filterx_string, test_filterx_object_string_marshals_to_the_stored_values)
{
Expand Down
4 changes: 2 additions & 2 deletions libtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(LIBTEST_HEADERS
stopwatch.h
cr_template.h
grab-logging.h
filterx.h
filterx-lib.h
)

set(LIBTEST_SOURCES
Expand All @@ -28,7 +28,7 @@ set(LIBTEST_SOURCES
stopwatch.c
cr_template.c
grab-logging.c
filterx.c
filterx-lib.c
)

add_library(libtest STATIC ${LIBTEST_SOURCES})
Expand Down
6 changes: 3 additions & 3 deletions libtest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ libtest_libsyslog_ng_test_a_SOURCES = \
libtest/queue_utils_lib.h \
libtest/stopwatch.c \
libtest/stopwatch.h \
libtest/filterx.c \
libtest/filterx.h
libtest/filterx-lib.c \
libtest/filterx-lib.h

libtest_libsyslog_ng_test_a_CFLAGS = $(AM_CFLAGS) $(CRITERION_CFLAGS) $(JSON_CFLAGS)

Expand All @@ -50,7 +50,7 @@ libtestinclude_HEADERS = \
libtest/proto_lib.h \
libtest/queue_utils_lib.h \
libtest/stopwatch.h \
libtest/filterx.h
libtest/filterx-lib.h

pkgconfig_DATA += \
libtest/syslog-ng-test.pc
Expand Down
31 changes: 30 additions & 1 deletion libtest/filterx.c → libtest/filterx-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,38 @@
*
*/

#include "filterx.h"
#include <criterion/criterion.h>
#include "filterx-lib.h"
#include "filterx/object-json.h"

void
assert_marshaled_object(FilterXObject *obj, const gchar *repr, LogMessageValueType type)
{
GString *b = g_string_sized_new(0);
LogMessageValueType t;

/* check if we _overwrite_ the string with the marshalled value */
g_string_append(b, "PREFIX");

cr_assert(filterx_object_marshal(obj, b, &t) == TRUE);
cr_assert_str_eq(b->str, repr);
cr_assert_eq(t, type);
g_string_free(b, TRUE);
}

void
assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
}


FilterXObject *
filterx_test_dict_new(void)
{
Expand Down
7 changes: 5 additions & 2 deletions libtest/filterx.h → libtest/filterx-lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
*
*/

#ifndef LIBTEST_FILTERX_H_INCLUDED
#define LIBTEST_FILTERX_H_INCLUDED
#ifndef LIBTEST_FILTERX_LIB_H_INCLUDED
#define LIBTEST_FILTERX_LIB_H_INCLUDED

#include "filterx/filterx-object.h"

void assert_marshaled_object(FilterXObject *obj, const gchar *repr, LogMessageValueType type);
void assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr);

FILTERX_DECLARE_TYPE(test_dict);
FILTERX_DECLARE_TYPE(test_list);
FILTERX_DECLARE_TYPE(test_unknown_object);
Expand Down
2 changes: 1 addition & 1 deletion modules/json/tests/test_filterx_format_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <criterion/criterion.h>
#include "libtest/cr_template.h"
#include "libtest/filterx.h"
#include "libtest/filterx-lib.h"

#include "filterx-format-json.h"
#include "filterx/object-primitive.h"
Expand Down

0 comments on commit cefe449

Please sign in to comment.