From 53b2ca8f62d25c0b764c5640d50c379f2260fbc3 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 4 Feb 2019 13:18:04 -0300 Subject: [PATCH] validate: Force LC_NUMERIC to C as it is required by our expression parser And... add some expression parser unit tests --- validate/gst/validate/validate.c | 4 ++ validate/tests/check/meson.build | 3 +- .../tests/check/validate/expression_parser.c | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 validate/tests/check/validate/expression_parser.c diff --git a/validate/gst/validate/validate.c b/validate/gst/validate/validate.c index 61ee313df0..82599f2222 100644 --- a/validate/gst/validate/validate.c +++ b/validate/gst/validate/validate.c @@ -29,6 +29,8 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include /* for LC_NUMERIC */ + #include /* For g_stat () */ #include @@ -301,6 +303,8 @@ gst_validate_init (void) _priv_start_time = gst_util_get_timestamp (); _Q_VALIDATE_MONITOR = g_quark_from_static_string ("validate-monitor"); + setlocale (LC_NUMERIC, "C"); + /* init the report system (can be called multiple times) */ gst_validate_report_init (); diff --git a/validate/tests/check/meson.build b/validate/tests/check/meson.build index 471a6733a2..5956213289 100644 --- a/validate/tests/check/meson.build +++ b/validate/tests/check/meson.build @@ -4,7 +4,8 @@ validate_tests = [ ['validate/monitoring'], ['validate/reporting'], ['validate/overrides'], - ['validate/scenario'] + ['validate/scenario'], + ['validate/expression_parser'], ] test_defines = [ diff --git a/validate/tests/check/validate/expression_parser.c b/validate/tests/check/validate/expression_parser.c new file mode 100644 index 0000000000..76a8f2f62b --- /dev/null +++ b/validate/tests/check/validate/expression_parser.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +static int +get_var (const gchar * name, double *value, gpointer udata) +{ + *value = (double) GPOINTER_TO_INT (udata); + + return 1; +} + +GST_START_TEST (test_expression_parser) +{ + fail_unless_equals_float (gst_validate_utils_parse_expression ("10 / 2", NULL, + NULL, NULL), 5.0); + + fail_unless_equals_float (gst_validate_utils_parse_expression ("10 / 0.5", + NULL, NULL, NULL), 20); + + fail_unless_equals_float (gst_validate_utils_parse_expression + ("100, (10 / 0.1)", NULL, NULL, NULL), 1); + + fail_unless_equals_float (gst_validate_utils_parse_expression + ("min(10, (duration - 0.1) / 0.1)", get_var, GINT_TO_POINTER (1), NULL), + 9); +} + +GST_END_TEST; + +static Suite * +gst_validate_suite (void) +{ + Suite *s = suite_create ("registry"); + TCase *tc_chain = tcase_create ("registry"); + suite_add_tcase (s, tc_chain); + + if (atexit (gst_validate_deinit) != 0) { + GST_ERROR ("failed to set gst_validate_deinit as exit function"); + } + + g_setenv ("GST_VALIDATE_REPORTING_DETAILS", "all", TRUE); + gst_validate_init (); + tcase_add_test (tc_chain, test_expression_parser); + gst_validate_deinit (); + + return s; +} + +GST_CHECK_MAIN (gst_validate);