MeshLib C++ Docs
Loading...
Searching...
No Matches
TestMacros.h
Go to the documentation of this file.
1#pragma once
2
3#include "TestFunctions.h"
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <tgmath.h>
8
9#define RUN_TEST( func ) \
10 printf( "%s ...\n", #func ); \
11 { \
12 struct timespec ts1 = timespec_now(); \
13 func(); \
14 struct timespec ts2 = timespec_now(); \
15 struct timespec duration = timespec_get_duration( &ts1, &ts2 ); \
16 printf( "%s done (%.3f s)\n", #func, timespec_to_seconds( &duration ) ); \
17 }
18
19#define TEST_ASSERT( ... ) \
20 if ( !( __VA_ARGS__ ) ) \
21 { \
22 fprintf( stderr, "%s:%d: check failed: %s\n", __func__, __LINE__, ( #__VA_ARGS__ ) ); \
23 abort(); \
24 }
25
26#define TEST_ASSERT_INT_EQUAL( val, exp ) \
27 if ( !( val == exp ) ) \
28 { \
29 fprintf( stderr, "%s:%d: check failed: expected %d, got %d\n", __func__, __LINE__, exp, val ); \
30 abort(); \
31 }
32
33#define TEST_ASSERT_FLOAT_EQUAL_APPROX( val, exp, eps ) \
34 if ( !( fabs( val - exp ) <= eps ) ) \
35 { \
36 fprintf( stderr, "%s:%d: check failed: expected %f (delta %f), got %f (delta %f)\n", __func__, __LINE__, exp, eps, val, fabs( val - exp ) ); \
37 abort(); \
38 }