/* cunit - A little C Unit facility */
-/* Copyright (c) 2005-2014. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2005-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* At some point we should use https://github.com/google/googletest instead */
#include "src/internal_config.h"
-#include <stdio.h>
+#include <cstdio>
#include <xbt/ex.hpp>
#include "xbt/sysdep.h" /* bvprintf */
static void xbt_test_unit_dump(xbt_test_unit_t unit)
{
if (unit) {
- xbt_test_test_t test;
- unsigned int it_test;
fprintf(stderr, " UNIT %s: %s (%s)\n", unit->name, unit->title, (unit->enabled ? "enabled" : "disabled"));
- if (unit->enabled)
+ if (unit->enabled) {
+ xbt_test_test_t test;
+ unsigned int it_test;
xbt_dynar_foreach(unit->tests, it_test, test)
xbt_test_test_dump(test);
+ }
} else {
fprintf(stderr, " unit=nullptr\n");
}
xbt_test_suite_t suite = xbt_new0(struct s_xbt_test_suite, 1);
va_list ap;
- if (!_xbt_test_suites)
+ if (_xbt_test_suites == nullptr)
_xbt_test_suites = xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free);
va_start(ap, fmt);
xbt_test_suite_t xbt_test_suite_by_name(const char *name, const char *fmt, ...)
{
xbt_test_suite_t suite;
- unsigned int it_suite;
-
char *bufname;
va_list ap;
- if (_xbt_test_suites)
+ if (_xbt_test_suites) {
+ unsigned int it_suite;
xbt_dynar_foreach(_xbt_test_suites, it_suite, suite)
if (not strcmp(suite->name, name))
return suite;
+ }
va_start(ap, fmt);
bufname = bvprintf(fmt, ap);
void xbt_test_suite_dump(xbt_test_suite_t suite)
{
if (suite) {
- xbt_test_unit_t unit;
- unsigned int it_unit;
fprintf(stderr, "TESTSUITE %s: %s (%s)\n", suite->name, suite->title, suite->enabled ? "enabled" : "disabled");
- if (suite->enabled)
+ if (suite->enabled) {
+ xbt_test_unit_t unit;
+ unsigned int it_unit;
xbt_dynar_foreach(suite->units, it_unit, unit)
xbt_test_unit_dump(unit);
+ }
} else {
- fprintf(stderr, "TESTSUITE IS nullptr!\n");
+ fprintf(stderr, "TESTSUITE IS NULL!\n");
}
}
xbt_test_test_t test;
xbt_test_log_t log;
- const char *file;
- int line;
- char *cp;
- unsigned int it_unit;
- unsigned int it_test;
- unsigned int it_log;
-
- int first = 1; /* for result pretty printing */
-
if (suite == nullptr)
return 0;
if (suite->enabled) {
/* iterate through all tests */
+ unsigned int it_unit;
xbt_dynar_foreach(suite->units, it_unit, unit) {
/* init unit case counters */
unit->nb_tests = 0;
unit->test_expect = 0;
/* display unit title */
- cp = bprintf(" Unit: %s ......................................"
- "......................................", unit->title);
+ char* cp = bprintf(" Unit: %s ......................................"
+ "......................................",
+ unit->title);
cp[70] = '\0';
fprintf(stderr, "%s", cp);
free(cp);
unit->func();
/* iterate through all performed tests to determine status */
+ unsigned int it_test;
xbt_dynar_foreach(unit->tests, it_test, test) {
if (test->ignored) {
unit->test_ignore++;
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 != nullptr ? test->file : unit->file);
- line = (test->line != 0 ? test->line : unit->line);
+ const char* file = (test->file != nullptr ? test->file : unit->file);
+ int line = (test->line != 0 ? test->line : unit->line);
const char* resname;
if (test->ignored)
resname = " SKIP";
fprintf(stderr, " %s: %s [%s:%d]\n", resname, test->title, file, line);
if ((test->expected_failure && not test->failed) || (not test->expected_failure && test->failed)) {
+ unsigned int it_log;
xbt_dynar_foreach(test->logs, it_log, log) {
file = (log->file != nullptr ? log->file : file);
line = (log->line != 0 ? log->line : line);
/* print test suite summary */
if (suite->enabled) {
+ int first = 1; /* for result pretty printing */
+
fprintf(stderr," =====================================================================%s\n",
(suite->nb_units ? (suite->unit_failed ? "== FAILED" : "====== OK") :
(suite->unit_disabled ? " DISABLED" : "==== SKIP")));