utest.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

Go to the source code of this file.

Macros

#define PASS   2
 
#define WARN   1
 
#define FAIL   0
 
#define ASSERT_TRUE(x)
 
#define ASSERT_FALSE(x)
 
#define EXPECT_TRUE(x)
 
#define EXPECT_FALSE(x)
 
#define ASSERT_EQ(x, y, tol)
 
#define EXPECT_EQ(x, y, tol)
 
#define ASSERT_LT(x, y)
 
#define EXPECT_LT(x, y)
 

Functions

void setup ()
 
void register_all_tests ()
 
void register_test (void(*testfn)(void), char *name)
 

Variables

int test_state
 

Macro Definition Documentation

◆ ASSERT_EQ

#define ASSERT_EQ (   x,
  y,
  tol 
)
Value:
{ \
double err = fabs(1.0-(x)/(y)); \
if(err > (tol)) { \
test_state = FAIL; \
printf("\x1b[31mASSERT_EQ( %.3e , %.3e , %.3e ) failed ( err = %.3e ):\x1b[0m\n %s, line %d.\n", \
x, y, tol, err, __FILE__, __LINE__); \
return; \
} \
} \
#define FAIL
Definition: utest.h:47

◆ ASSERT_FALSE

#define ASSERT_FALSE (   x)
Value:
{ \
if((x)) { \
test_state = FAIL; \
printf("\x1b[31mASSERT_FALSE( %d ) failed:\x1b[0m\n %s, line %d.\n", \
x, __FILE__, __LINE__); \
return; \
} \
} \
#define FAIL
Definition: utest.h:47

◆ ASSERT_LT

#define ASSERT_LT (   x,
 
)
Value:
{ \
if((x) >= (y)) { \
test_state = FAIL; \
printf("\x1b[31mASSERT_LT( %.3e , %.3e ) failed:\x1b[0m\n %s, line %d.\n", \
x, y, __FILE__, __LINE__); \
return; \
} \
} \
#define FAIL
Definition: utest.h:47

◆ ASSERT_TRUE

#define ASSERT_TRUE (   x)
Value:
{ \
if(!(x)) { \
test_state = FAIL; \
printf("\x1b[31mASSERT_TRUE( %d ) failed:\x1b[0m\n %s, line %d.\n", \
x, __FILE__, __LINE__); \
return; \
} \
} \
#define FAIL
Definition: utest.h:47

◆ EXPECT_EQ

#define EXPECT_EQ (   x,
  y,
  tol 
)
Value:
{ \
double err = fabs(1.0-(x)/(y)); \
if(err > (tol)) { \
test_state = WARN; \
printf("\x1b[33mEXPECT_EQ( %.3e , %.3e , %.3e ) failed ( err = %.3e ):\x1b[0m\n %s, line %d.\n", \
x, y, tol, err, __FILE__, __LINE__); \
} \
} \
#define WARN
Definition: utest.h:46

◆ EXPECT_FALSE

#define EXPECT_FALSE (   x)
Value:
{ \
if((x)) { \
test_state = WARN; \
printf("\x1b[33mEXPECT_FALSE( %d ) failed:\x1b[0m\n %s, line %d.\n", \
x, __FILE__, __LINE__); \
} \
} \
#define WARN
Definition: utest.h:46

◆ EXPECT_LT

#define EXPECT_LT (   x,
 
)
Value:
{ \
if((x) >= (y)) { \
test_state = WARN; \
printf("\x1b[33mEXPECT_LT( %.3e , %.3e ) failed:\x1b[0m\n %s, line %d.\n", \
x, y, __FILE__, __LINE__); \
} \
} \
#define WARN
Definition: utest.h:46

◆ EXPECT_TRUE

#define EXPECT_TRUE (   x)
Value:
{ \
if(!(x)) { \
test_state = WARN; \
printf("\x1b[33mEXPECT_TRUE( %d ) failed:\x1b[0m\n %s, line %d.\n", \
x, __FILE__, __LINE__); \
} \
} \
#define WARN
Definition: utest.h:46

◆ FAIL

#define FAIL   0

◆ PASS

#define PASS   2

◆ WARN

#define WARN   1

Function Documentation

◆ register_all_tests()

void register_all_tests ( )

◆ register_test()

void register_test ( void(*)(void)  testfn,
char *  name 
)

◆ setup()

void setup ( )

Variable Documentation

◆ test_state

int test_state