git.fiddlerwoaroof.com
test_util.h
7684972a
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
a26b1d7c
 #ifndef _TESTUTIL_H
 #define _TESTUTIL_H
 
8ab94c71
 #include <cstring>
 #include <cstdio>
a26b1d7c
 #define check(assertion, msg) \
     if (!(assertion)) { \
       fprintf(stderr, "assertion failed: %s\n", msg); \
       return 0; \
     }
 
 #define checkint(expected, actual, name) \
     check(expected == actual, name " should be " #expected)
 
 #define checkstr(expected, actual, name) \
469d5639
     check(!strcmp(expected, actual), name " should be '" expected "'")
a26b1d7c
 
704ed597
 #define RESET_VARS_START void __reset_vars() {
 
 #define RESET_VARS_END }
d509a3b6
 
e4bb67f3
 #define test(NAME) \
     { \
       int result = NAME (); \
       if (!result) { \
           fprintf(stderr, "test failed: %s\n", #NAME); \
           return 0; \
       } \
     }
 
a26b1d7c
 #define succeed() return 1
9dd224b0
 #define fail() return 0
a26b1d7c
 
 #endif