Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stringify a bit
[simgrid.git] / src / xbt / cunit.cpp
index 0983062..87c869c 100644 (file)
@@ -9,13 +9,15 @@
 /* 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 */
 #include "xbt/cunit.h"
 #include "xbt/dynar.h"
 
+#define STRLEN 1024
+
 /* collection of all suites */
 static xbt_dynar_t _xbt_test_suites = nullptr;
 /* global statistics */
@@ -250,9 +252,6 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
   xbt_test_test_t test;
   xbt_test_log_t log;
 
-  unsigned int it_unit;
-  unsigned int it_test;
-
   if (suite == nullptr)
     return 0;
 
@@ -276,6 +275,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
 
   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;
@@ -297,6 +297,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
         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++;
@@ -455,32 +456,29 @@ static void apply_selection(char *selection)
   /* for the parsing */
   char *sel = selection;
   int done = 0;
-  char dir[1024];               /* the directive */
+  char dir[STRLEN]; /* the directive */
   /* iterators */
   unsigned int it_suite;
   xbt_test_suite_t suite;
   xbt_test_unit_t unit;
   unsigned int it_unit;
 
-  char suitename[512];
-  char unitname[512];
+  char suitename[STRLEN];
+  char unitname[STRLEN];
 
   if (not selection || selection[0] == '\0')
     return;
 
-  /*printf("Test selection: %s\n", selection); */
-
   /* First apply the selection */
   while (not done) {
     int enabling = 1;
 
     char *p = strchr(sel, ',');
     if (p) {
-      strncpy(dir, sel, p - sel);
-      dir[p - sel] = '\0';
+      snprintf(dir, STRLEN, "%.*s", (int)(p - sel), sel);
       sel = p + 1;
     } else {
-      strncpy(dir, sel,1024);
+      snprintf(dir, STRLEN, "%s", sel);
       done = 1;
     }
 
@@ -495,11 +493,10 @@ static void apply_selection(char *selection)
 
     p = strchr(dir, ':');
     if (p) {
-      strncpy(unitname, p + 1,512);
-      strncpy(suitename, dir, p - dir);
-      suitename[p - dir] = '\0';
+      snprintf(suitename, STRLEN, "%.*s", (int)(p - dir), dir);
+      snprintf(unitname, STRLEN, "%s", p + 1);
     } else {
-      strncpy(suitename, dir,512);
+      snprintf(suitename, STRLEN, "%s", dir);
       unitname[0] = '\0';
     }