-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminunit.h
49 lines (41 loc) · 1.43 KB
/
minunit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _MINUNIT_H
#define _MINUNIT_H
/*
MinUnit unit testing "framework"
Copyright Jera Design
http://www.jera.com/techinfo/jtns/jtn002.html
Additional assertions Copyright Tony Brown 2011
License:
You may use the code in this tech note for any purpose, with the understanding that it comes with NO WARRANTY.
*/
#include <stdio.h>
#include <string.h>
char *t_name;
char *t_test;
char t_expected[1000];
#define STR(x) #x
#define mu_assert(message, test) do { t_test=STR(Expected test); if (!(test)) return message; } while (0)
#define mu_assert_equal_int(expected, result) do { t_test=mu_priv_assert_equal_l(expected,result); if(t_test) return t_test; } while (0)
#define mu_assert_equal_string(expected, result) do { t_test=mu_priv_assert_equal_s(expected,result); if(t_test) return t_test; } while (0)
#define mu_run_test(test) do { t_name=STR(test); char *message = test(); tests_run++; \
if (message) return message; } while (0)
extern int tests_run;
char *mu_priv_assert_equal_l( const long expected, const long result )
{
if (expected != result )
{
sprintf( t_expected, "Expected \"%ld\", got \"%ld\" ", expected, result );
return t_expected;
}
return 0;
}
char *mu_priv_assert_equal_s(const char *expected,const char *result )
{
if (strcmp(expected,result) != 0 )
{
sprintf( t_expected, "Expected \"%s\", got \"%s\" ", expected, result );
return t_expected;
}
return 0;
}
#endif