Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[xbt] Move throwpoint out of xbt_ex in WithContextException
[simgrid.git] / src / xbt / cunit.cpp
index 1cfd7f8..e9439c2 100644 (file)
 #include "src/internal_config.h"
 #include <stdio.h>
 
 #include "src/internal_config.h"
 #include <stdio.h>
 
+#include <xbt/ex.hpp>
 #include "xbt/sysdep.h"         /* bvprintf */
 #include "xbt/cunit.h"
 #include "xbt/dynar.h"
 
 /* collection of all suites */
 #include "xbt/sysdep.h"         /* bvprintf */
 #include "xbt/cunit.h"
 #include "xbt/dynar.h"
 
 /* collection of all suites */
-static xbt_dynar_t _xbt_test_suites = NULL;
+static xbt_dynar_t _xbt_test_suites = nullptr;
 /* global statistics */
 static int _xbt_test_nb_tests = 0;
 static int _xbt_test_test_failed = 0;
 /* global statistics */
 static int _xbt_test_nb_tests = 0;
 static int _xbt_test_test_failed = 0;
@@ -35,7 +36,7 @@ static int _xbt_test_suite_ignore = 0;
 static int _xbt_test_suite_disabled = 0;
 
 /* Context */
 static int _xbt_test_suite_disabled = 0;
 
 /* Context */
-xbt_test_unit_t _xbt_test_current_unit = NULL;
+xbt_test_unit_t _xbt_test_current_unit = nullptr;
 
 /* test suite test log */
 typedef struct s_xbt_test_log {
 
 /* test suite test log */
 typedef struct s_xbt_test_log {
@@ -49,7 +50,7 @@ static void xbt_test_log_dump(xbt_test_log_t log)
   if (log)
     fprintf(stderr, "      log %p(%s:%d)=%s\n", log, log->file, log->line, log->text);
   else
   if (log)
     fprintf(stderr, "      log %p(%s:%d)=%s\n", log, log->file, log->line, log->text);
   else
-    fprintf(stderr, "      log=NULL\n");
+    fprintf(stderr, "      log=nullptr\n");
 }
 
 /* test suite test check */
 }
 
 /* test suite test check */
@@ -73,7 +74,7 @@ static void xbt_test_test_dump(xbt_test_test_t test)
     xbt_dynar_foreach(test->logs, it_log, log)
         xbt_test_log_dump(log);
   } else
     xbt_dynar_foreach(test->logs, it_log, log)
         xbt_test_log_dump(log);
   } else
-    fprintf(stderr, "    test=NULL\n");
+    fprintf(stderr, "    test=nullptr\n");
 }
 
 /* test suite test unit */
 }
 
 /* test suite test unit */
@@ -100,7 +101,7 @@ static void xbt_test_unit_dump(xbt_test_unit_t unit)
       xbt_dynar_foreach(unit->tests, it_test, test)
           xbt_test_test_dump(test);
   } else {
       xbt_dynar_foreach(unit->tests, it_test, test)
           xbt_test_test_dump(test);
   } else {
-    fprintf(stderr, "  unit=NULL\n");
+    fprintf(stderr, "  unit=nullptr\n");
   }
 }
 
   }
 }
 
@@ -121,7 +122,7 @@ static void xbt_test_suite_free(void *s)
 {
   xbt_test_suite_t suite = *(xbt_test_suite_t *) s;
 
 {
   xbt_test_suite_t suite = *(xbt_test_suite_t *) s;
 
-  if (suite == NULL)
+  if (suite == nullptr)
     return;
   xbt_dynar_free(&suite->units);
   free(suite->title);
     return;
   xbt_dynar_free(&suite->units);
   free(suite->title);
@@ -190,7 +191,7 @@ xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, ...)
   va_start(ap, fmt);
   bufname = bvprintf(fmt, ap);
   va_end(ap);
   va_start(ap, fmt);
   bufname = bvprintf(fmt, ap);
   va_end(ap);
-  suite = xbt_test_suite_new(name, bufname, NULL);
+  suite = xbt_test_suite_new(name, bufname, nullptr);
   free(bufname);
 
   return suite;
   free(bufname);
 
   return suite;
@@ -206,7 +207,7 @@ void xbt_test_suite_dump(xbt_test_suite_t suite)
       xbt_dynar_foreach(suite->units, it_unit, unit)
           xbt_test_unit_dump(unit);
   } else {
       xbt_dynar_foreach(suite->units, it_unit, unit)
           xbt_test_unit_dump(unit);
   } else {
-    fprintf(stderr, "TESTSUITE IS NULL!\n");
+    fprintf(stderr, "TESTSUITE IS nullptr!\n");
   }
 }
 
   }
 }
 
@@ -226,7 +227,7 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name, ts_test_cb_t
   va_end(ap);
   unit->name = (char *) name;
   unit->func = func;
   va_end(ap);
   unit->name = (char *) name;
   unit->func = func;
-  unit->file = NULL;
+  unit->file = nullptr;
   unit->line = 0;
   unit->enabled = 1;
   unit->tests = xbt_dynar_new(sizeof(xbt_test_test_t), xbt_test_test_free);
   unit->line = 0;
   unit->enabled = 1;
   unit->tests = xbt_dynar_new(sizeof(xbt_test_test_t), xbt_test_test_free);
@@ -249,7 +250,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
 
   int first = 1;                /* for result pretty printing */
 
 
   int first = 1;                /* for result pretty printing */
 
-  if (suite == NULL)
+  if (suite == nullptr)
     return 0;
 
   /* suite title pretty-printing */
     return 0;
 
   /* suite title pretty-printing */
@@ -320,14 +321,14 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
           fprintf(stderr, ".... skip\n");       /* shouldn't happen, but I'm a bit lost with this logic */
         }
         xbt_dynar_foreach(unit->tests, it_test, test) {
           fprintf(stderr, ".... skip\n");       /* shouldn't happen, but I'm a bit lost with this logic */
         }
         xbt_dynar_foreach(unit->tests, it_test, test) {
-          file = (test->file != NULL ? test->file : unit->file);
+          file = (test->file != nullptr ? test->file : unit->file);
           line = (test->line != 0 ? test->line : unit->line);
           fprintf(stderr, "      %s: %s [%s:%d]\n", (test->ignored ? " SKIP" : (test->expected_failure
                   ? (test-> failed ? "EFAIL" : "EPASS") : (test->failed ? " FAIL" : " PASS"))),test->title, file, line);
 
           if ((test->expected_failure && !test->failed) || (!test->expected_failure && test->failed)) {
             xbt_dynar_foreach(test->logs, it_log, log) {
           line = (test->line != 0 ? test->line : unit->line);
           fprintf(stderr, "      %s: %s [%s:%d]\n", (test->ignored ? " SKIP" : (test->expected_failure
                   ? (test-> failed ? "EFAIL" : "EPASS") : (test->failed ? " FAIL" : " PASS"))),test->title, file, line);
 
           if ((test->expected_failure && !test->failed) || (!test->expected_failure && test->failed)) {
             xbt_dynar_foreach(test->logs, it_log, log) {
-              file = (log->file != NULL ? log->file : file);
+              file = (log->file != nullptr ? log->file : file);
               line = (log->line != 0 ? log->line : line);
               fprintf(stderr, "             %s:%d: %s\n", file, line, log->text);
             }
               line = (log->line != 0 ? log->line : line);
               fprintf(stderr, "             %s:%d: %s\n", file, line, log->text);
             }
@@ -669,7 +670,7 @@ void _xbt_test_fail(const char *file, int line, const char *fmt, ...)
 
 void xbt_test_exception(xbt_ex_t e)
 {
 
 void xbt_test_exception(xbt_ex_t e)
 {
-  _xbt_test_fail(e.file, e.line, "Exception %s raised: %s", xbt_ex_catname(e.category), e.what());
+  _xbt_test_fail(e.throwPoint().file, e.throwPoint().line, "Exception %s raised: %s", xbt_ex_catname(e.category), e.what());
 }
 
 void xbt_test_expect_failure(void)
 }
 
 void xbt_test_expect_failure(void)