From: Gary Lockyer Date: Thu, 25 Oct 2018 01:38:31 +0000 (+1300) Subject: dsdb group audit tests: check_version improve diagnostics X-Git-Tag: tdb-1.3.17~1107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c952fc1273397c04fddf177bcd809551d6324bdd;p=thirdparty%2Fsamba.git dsdb group audit tests: check_version improve diagnostics Change check_version to display the expected, actual along with the line and name of the failing test, rather than the line in check_version Signed-off-by: Gary Lockyer Reviewed-by: Stefan Metzmacher --- diff --git a/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c b/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c index f7120add0d5..4d5ed604555 100644 --- a/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c +++ b/source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c @@ -272,23 +272,69 @@ static void _check_timestamp( } } +#define check_version(v, m, n)\ + _check_version(v, m, n, __FILE__, __LINE__); /* * Test helper to validate a version object. */ -static void check_version(struct json_t *version, int major, int minor) +static void _check_version( + struct json_t *version, + int major, + int minor, + const char* file, + const int line) { struct json_t *v = NULL; + int value; + + if (!json_is_object(version)) { + cm_print_error("version is not a JSON object\n"); + _fail(file, line); + } - assert_true(json_is_object(version)); - assert_int_equal(2, json_object_size(version)); + if (json_object_size(version) != 2) { + cm_print_error( + "Unexpected number of elements in version %zu != %d\n", + json_object_size(version), + 2); + _fail(file, line); + } + /* + * Validate the major version number element + */ v = json_object_get(version, "major"); - assert_non_null(v); - assert_int_equal(major, json_integer_value(v)); + if (v == NULL) { + cm_print_error( "No major element\n"); + _fail(file, line); + } + value = json_integer_value(v); + if (value != major) { + print_error( + "Unexpected major version number \"%d\" != \"%d\"\n", + value, + major); + _fail(file, line); + } + + /* + * Validate the minor version number element + */ v = json_object_get(version, "minor"); - assert_non_null(v); - assert_int_equal(minor, json_integer_value(v)); + if (v == NULL) { + cm_print_error( "No minor element\n"); + _fail(file, line); + } + + value = json_integer_value(v); + if (value != minor) { + print_error( + "Unexpected minor version number \"%d\" != \"%d\"\n", + value, + minor); + _fail(file, line); + } } /*