dsdb group audit tests: check_timestamp improve diagnostics
authorGary Lockyer <gary@catalyst.net.nz>
Thu, 25 Oct 2018 00:28:09 +0000 (13:28 +1300)
committerStefan Metzmacher <metze@samba.org>
Tue, 30 Oct 2018 15:40:13 +0000 (16:40 +0100)
Change check_timestamp to display the expected, actual along with the
line and name of the failing test, rather than the line in
check_timestamp.

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 743ce206bc0e5e5db73428ae85820ff3c01602ef..f7120add0d5143d3fcb6868e5d7fd3d7e3253e89 100644 (file)
@@ -199,10 +199,16 @@ static void _check_group_change_message(
        }
 }
 
+#define check_timestamp(b, t)\
+       _check_timestamp(b, t, __FILE__, __LINE__);
 /*
  * Test helper to check ISO 8601 timestamps for validity
  */
-static void check_timestamp(time_t before, const char *timestamp)
+static void _check_timestamp(
+       time_t before,
+       const char *timestamp,
+       const char *file,
+       const int line)
 {
        int rc;
        int usec, tz;
@@ -238,10 +244,32 @@ static void check_timestamp(time_t before, const char *timestamp)
        actual = mktime(&tm);
 
        /*
-        * The timestamp should be before <= actual <= after
+        * The time stamp should be before <= actual <= after
         */
-       assert_true(difftime(actual, before) >= 0);
-       assert_true(difftime(after, actual) >= 0);
+       if (difftime(actual, before) < 0) {
+               char buffer[40];
+               strftime(buffer,
+                        sizeof(buffer)-1,
+                        "%Y-%m-%dT%T",
+                        localtime(&before));
+               cm_print_error(
+                   "time stamp \"%s\" is before start time \"%s\"\n",
+                   timestamp,
+                   buffer);
+               _fail(file, line);
+       }
+       if (difftime(after, actual) < 0) {
+               char buffer[40];
+               strftime(buffer,
+                        sizeof(buffer)-1,
+                        "%Y-%m-%dT%T",
+                        localtime(&after));
+               cm_print_error(
+                   "time stamp \"%s\" is after finish time \"%s\"\n",
+                   timestamp,
+                   buffer);
+               _fail(file, line);
+       }
 }
 
 /*