-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert_support.c
67 lines (62 loc) · 2.63 KB
/
assert_support.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// vim: ts=2 noet spell foldlevel=0 foldmethod=syntax :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ut_assertStatement(int result, const char *statement, const char * filename, int line) {
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %s\n", filename, line, statement);
}
return 1== result? 0: 1;
}
int ut_assertStatementOptInt(const int real, const int expect, const int result, const char *operator, char * filename, int line) {
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %d %s %d\n", filename, line,real, operator, expect);
}
return 1== result? 0: 1;
}
int ut_assertStatementOptLong(const long real, const long expect,const int result, const char *operator, char * filename, int line) {
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %ld %s %ld\n", filename, line,real, operator, expect);
}
return 1== result? 0: 1;
}
int ut_assertStatementOptFloat(const float real, const float expect,const int result, const char *operator, char * filename, int line) {
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %g %s %g\n", filename, line,real, operator, expect);
}
return 1== result? 0: 1;
}
int ut_assertStatementOptDouble(const double real, const double expect,const int result, const char *operator, char * filename, int line) {
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %g %s %g\n", filename, line,real, operator, expect);
}
return 1== result? 0: 1;
}
static int ut_assertStatementEqStr_nulls(const char *real, const char *expected, const char *statement, char * filename, int line) {
if ( (real == expected)) {
return 0;
}
fprintf(stderr, "%s:%d:0 statement failed: %s: expected '%s' but was '%s'\n", filename, line,
statement, NULL==expected? "NULL": expected, NULL == real? "NULL": real);
return 1;
}
static void showFirstCharacterDifference(const char *expected, const char *real) {
int i=0;
while (*expected == *real) {
i++; expected++; real++;
}
fprintf(stderr, "first difference at offset %d, char is '%c' expected '%c'", i, *real, *expected);
}
int ut_assertStatementEqStr(const char *real, const char *expected, const char *statement, char * filename, int line) {
if (NULL == real || NULL == expected) {
return ut_assertStatementEqStr_nulls(real, expected, statement, filename,line);
}
int result = 0 ==strcmp(real,expected);
if (!result) {
fprintf(stderr, "%s:%d:0 statement failed: %s: expected '%s' but was '%s': ", filename, line,
statement, expected, real);
showFirstCharacterDifference(expected,real);
fprintf(stderr, "\n");
}
return 1== result? 0: 1;
}