dsdb group audit tests: check_version improve diagnostics
authorGary Lockyer <gary@catalyst.net.nz>
Thu, 25 Oct 2018 01:38:31 +0000 (14:38 +1300)
committerStefan Metzmacher <metze@samba.org>
Tue, 30 Oct 2018 15:40:13 +0000 (16:40 +0100)
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 <gary@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/samdb/ldb_modules/tests/test_group_audit.c

index f7120ad..4d5ed60 100644 (file)
@@ -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);
+       }
 }
 
 /*