diff --git a/lib/filterx/tests/Makefile.am b/lib/filterx/tests/Makefile.am index 38196a6503b..c6b56569d30 100644 --- a/lib/filterx/tests/Makefile.am +++ b/lib/filterx/tests/Makefile.am @@ -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} diff --git a/lib/filterx/tests/filterx-lib.h b/lib/filterx/tests/filterx-lib.h deleted file mode 100644 index 04ac879a008..00000000000 --- a/lib/filterx/tests/filterx-lib.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2023 Balazs Scheidler - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As an additional exemption you are allowed to compile & link against the - * OpenSSL libraries as published by the OpenSSL project. See the file - * COPYING for details. - * - */ - -static 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); -} diff --git a/lib/filterx/tests/test_filterx_expr.c b/lib/filterx/tests/test_filterx_expr.c index 925adba3ec4..6f518e69c7a 100644 --- a/lib/filterx/tests/test_filterx_expr.c +++ b/lib/filterx/tests/test_filterx_expr.c @@ -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) @@ -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(); diff --git a/lib/filterx/tests/test_object_boolean.c b/lib/filterx/tests/test_object_boolean.c index f10f834a4d8..a4423651028 100644 --- a/lib/filterx/tests/test_object_boolean.c +++ b/lib/filterx/tests/test_object_boolean.c @@ -21,6 +21,8 @@ * */ #include +#include "libtest/filterx-lib.h" + #include "filterx/object-string.h" #include "filterx/object-null.h" #include "filterx/object-primitive.h" diff --git a/lib/filterx/tests/test_object_datetime.c b/lib/filterx/tests/test_object_datetime.c index 3ab05a420da..391f88cf9fa 100644 --- a/lib/filterx/tests/test_object_datetime.c +++ b/lib/filterx/tests/test_object_datetime.c @@ -21,27 +21,17 @@ * */ #include +#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) { diff --git a/lib/filterx/tests/test_object_double.c b/lib/filterx/tests/test_object_double.c index 67c396508b5..e5ad6f23a59 100644 --- a/lib/filterx/tests/test_object_double.c +++ b/lib/filterx/tests/test_object_double.c @@ -21,10 +21,11 @@ * */ #include +#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" diff --git a/lib/filterx/tests/test_object_integer.c b/lib/filterx/tests/test_object_integer.c index 73237f84e31..bb9d6066e92 100644 --- a/lib/filterx/tests/test_object_integer.c +++ b/lib/filterx/tests/test_object_integer.c @@ -21,6 +21,8 @@ * */ #include +#include "libtest/filterx-lib.h" + #include "filterx/object-string.h" #include "filterx/object-null.h" #include "filterx/object-primitive.h" diff --git a/lib/filterx/tests/test_object_json.c b/lib/filterx/tests/test_object_json.c index a7aa11a6447..12bf69643df 100644 --- a/lib/filterx/tests/test_object_json.c +++ b/lib/filterx/tests/test_object_json.c @@ -21,24 +21,13 @@ * */ #include +#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) { diff --git a/lib/filterx/tests/test_object_message.c b/lib/filterx/tests/test_object_message.c index fad0da89d7c..946d600c395 100644 --- a/lib/filterx/tests/test_object_message.c +++ b/lib/filterx/tests/test_object_message.c @@ -21,23 +21,12 @@ * */ #include +#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); diff --git a/lib/filterx/tests/test_object_null.c b/lib/filterx/tests/test_object_null.c index f020861765c..0f17d5b3061 100644 --- a/lib/filterx/tests/test_object_null.c +++ b/lib/filterx/tests/test_object_null.c @@ -21,23 +21,12 @@ * */ #include +#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(); diff --git a/lib/filterx/tests/test_object_primitive.c b/lib/filterx/tests/test_object_primitive.c index 33ee98f2951..768749763d7 100644 --- a/lib/filterx/tests/test_object_primitive.c +++ b/lib/filterx/tests/test_object_primitive.c @@ -21,23 +21,12 @@ * */ #include +#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) { diff --git a/lib/filterx/tests/test_object_string.c b/lib/filterx/tests/test_object_string.c index 66c9739898b..a552e7a224f 100644 --- a/lib/filterx/tests/test_object_string.c +++ b/lib/filterx/tests/test_object_string.c @@ -21,24 +21,13 @@ * */ #include +#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) { diff --git a/libtest/CMakeLists.txt b/libtest/CMakeLists.txt index b8018a38213..17ca1479baa 100644 --- a/libtest/CMakeLists.txt +++ b/libtest/CMakeLists.txt @@ -11,7 +11,7 @@ set(LIBTEST_HEADERS stopwatch.h cr_template.h grab-logging.h - filterx.h + filterx-lib.h ) set(LIBTEST_SOURCES @@ -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}) diff --git a/libtest/Makefile.am b/libtest/Makefile.am index e23f02838c8..642c9747418 100644 --- a/libtest/Makefile.am +++ b/libtest/Makefile.am @@ -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) @@ -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 diff --git a/libtest/filterx.c b/libtest/filterx-lib.c similarity index 79% rename from libtest/filterx.c rename to libtest/filterx-lib.c index 2c80895a40c..c1b916792e7 100644 --- a/libtest/filterx.c +++ b/libtest/filterx-lib.c @@ -21,9 +21,38 @@ * */ -#include "filterx.h" +#include +#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) { diff --git a/libtest/filterx.h b/libtest/filterx-lib.h similarity index 84% rename from libtest/filterx.h rename to libtest/filterx-lib.h index 63bff0a5bc9..deeea89fc7b 100644 --- a/libtest/filterx.h +++ b/libtest/filterx-lib.h @@ -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); diff --git a/modules/json/tests/test_filterx_format_json.c b/modules/json/tests/test_filterx_format_json.c index 6b440c68cff..956e5b252a4 100644 --- a/modules/json/tests/test_filterx_format_json.c +++ b/modules/json/tests/test_filterx_format_json.c @@ -22,7 +22,7 @@ #include #include "libtest/cr_template.h" -#include "libtest/filterx.h" +#include "libtest/filterx-lib.h" #include "filterx-format-json.h" #include "filterx/object-primitive.h"