SimGrid  3.16
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 mytest_str(name, input, separator, 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_split_str", test_split_str, "test the function xbt_str_split_str")
 
 XBT_TEST_UNIT ("xbt_str_parse", test_parse, "Test the parsing functions")
 

Macro Definition Documentation

◆ mytest

#define mytest (   name,
  input,
  expected 
)
Value:
s = xbt_str_join(d, "XXX"); \
xbt_test_assert(not strcmp(s, expected), "Input (%s) leads to (%s) instead of (%s)", input, s, expected); \
free(s); \
xbt_dynar_free(&d);
static const char * name
Definition: msg.h:186
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:348
static int input(void)
char * xbt_str_join(xbt_dynar_t dynar, const char *sep)
Join a set of strings as a single string.
Definition: xbt_str.cpp:372
#define xbt_test_add(...)
Declare that a new test begins (printf-like parameters, describing the test)
Definition: cunit.h:106

◆ mytest_str

#define mytest_str (   name,
  input,
  separator,
  expected 
)
Value:
d = xbt_str_split_str(input, separator); \
s = xbt_str_join(d, "XXX"); \
xbt_test_assert(not strcmp(s, expected), "Input (%s) leads to (%s) instead of (%s)", input, s, expected); \
free(s); \
xbt_dynar_free(&d);
static const char * name
Definition: msg.h:186
static int input(void)
char * xbt_str_join(xbt_dynar_t dynar, const char *sep)
Join a set of strings as a single string.
Definition: xbt_str.cpp:372
#define xbt_test_add(...)
Declare that a new test begins (printf-like parameters, describing the test)
Definition: cunit.h:106
xbt_dynar_t xbt_str_split_str(const char *s, const char *sep)
This functions splits a string after using another string as separator For example Anot not B!not C s...
Definition: xbt_str.cpp:204

◆ 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)
static const char * name
Definition: msg.h:186
A legacy exception.
Definition: ex.hpp:64
Invalid argument.
Definition: ex.h:94
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)
static const char * name
Definition: msg.h:186
A legacy exception.
Definition: ex.hpp:64
static const char char * value
Definition: msg.h:190

Function Documentation

◆ XBT_TEST_UNIT() [1/3]

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

◆ XBT_TEST_UNIT() [2/3]

XBT_TEST_UNIT ( "xbt_str_split_str"  ,
test_split_str  ,
"test the function xbt_str_split_str  
)

◆ XBT_TEST_UNIT() [3/3]

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