SimGrid  3.18
Versatile Simulation of Distributed Systems
xbt_str_unit.cpp File Reference
#include <stdio.h>
#include "xbt.h"
#include <xbt/ex.hpp>
#include "xbt/str.h"

Macros

#define mytest(name, input, expected)
 
#define test_parse_error(function, name, variable, str)
 
#define test_parse_ok(function, name, variable, str, value)
 

Functions

 XBT_TEST_UNIT ("xbt_str_split_quoted", test_split_quoted, "Test the function xbt_str_split_quoted")
 
 XBT_TEST_UNIT ("xbt_str_parse", test_parse, "Test the parsing functions")
 

Macro Definition Documentation

◆ mytest

#define mytest (   name,
  input,
  expected 
)
Value:
a = static_cast<char**>(xbt_dynar_to_array(xbt_str_split_quoted(input))); \
s = xbt_str_join_array(a, "XXX"); \
xbt_test_assert(not strcmp(s, expected), "Input (%s) leads to (%s) instead of (%s)", input, s, expected); \
xbt_free(s); \
for (int i = 0; a[i] != nullptr; i++) \
xbt_free(a[i]); \
xbt_free(a);
xbt_dynar_t xbt_str_split_quoted(const char *s)
Splits a string into a dynar of strings, taking quotes into account.
Definition: xbt_str.cpp:174
static int input(void)
#define xbt_free(p)
like free
Definition: sysdep.h:114
void * xbt_dynar_to_array(xbt_dynar_t dynar)
Transform a dynar into a nullptr terminated array.
Definition: dynar.cpp:624
char * xbt_str_join_array(const char *const *strs, const char *sep)
Join a set of strings as a single string.
Definition: xbt_str.cpp:202
#define xbt_test_add(...)
Declare that a new test begins (printf-like parameters, describing the test)
Definition: cunit.h:104
const char * name
Definition: msg.h:201

◆ test_parse_error

#define test_parse_error (   function,
  name,
  variable,
  str 
)
Value:
do { \
xbt_test_add(name); \
try { \
variable = function(str, "Parse error"); \
xbt_test_fail("The test '%s' did not detect the problem",name ); \
} catch(xbt_ex& e) { \
if (e.category != arg_error) { \
xbt_test_exception(e); \
} \
} \
} while (0)
A legacy exception.
Definition: ex.hpp:64
const char * name
Definition: msg.h:201
Invalid argument.
Definition: ex.h:70
xbt_errcat_t category
Category (what went wrong)
Definition: ex.hpp:85

◆ test_parse_ok

#define test_parse_ok (   function,
  name,
  variable,
  str,
  value 
)
Value:
do { \
xbt_test_add(name); \
try { \
variable = function(str, "Parse error"); \
} catch(xbt_ex& e) { \
xbt_test_exception(e); \
} \
xbt_test_assert(variable == value, "Fail to parse '%s'", str); \
} while (0)
A legacy exception.
Definition: ex.hpp:64
const char char * value
Definition: msg.h:208
const char * name
Definition: msg.h:201

Function Documentation

◆ XBT_TEST_UNIT() [1/2]

XBT_TEST_UNIT ( "xbt_str_split_quoted"  ,
test_split_quoted  ,
"Test the function xbt_str_split_quoted  
)

◆ XBT_TEST_UNIT() [2/2]

XBT_TEST_UNIT ( "xbt_str_parse"  ,
test_parse  ,
"Test the parsing functions"   
)