unit test api needs to be rewritten. crazy to assert functions with heap allocated memory or "in place"
manipulation.
This commit is contained in:
parent
64b6356e61
commit
9fa5c9eac9
5 changed files with 14 additions and 13 deletions
2
Makefile
2
Makefile
|
|
@ -24,7 +24,7 @@ all :
|
||||||
|
|
||||||
me :
|
me :
|
||||||
mkdir -p $(BUILD)
|
mkdir -p $(BUILD)
|
||||||
$(CC) $(CFLAGS) $(DEFS) $(SOURCES) -o $(BUILD)/arch
|
$(CC) $(CFLAGS) $(SOURCES) -o $(BUILD)/arch
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -fr $(BUILD)
|
rm -fr $(BUILD)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ raw_inotify :
|
||||||
$(CC) -linotifytools raw_inotify.c -o raw_inotify
|
$(CC) -linotifytools raw_inotify.c -o raw_inotify
|
||||||
|
|
||||||
path :
|
path :
|
||||||
$(CC) -D__DEBUG__ $(CFLAGS) ../src/common/path.c t_path.c -o test_path
|
$(CC) $(DEFS) $(CFLAGS) unit.c ../src/common/path.c t_path.c -o test_path
|
||||||
|
|
||||||
rbtree :
|
rbtree :
|
||||||
$(CC) $(DEFS) $(CFLAGS) unit.c ../src/common/rbtree.c t_rbtree.c -o test_rbtree
|
$(CC) $(DEFS) $(CFLAGS) unit.c ../src/common/rbtree.c t_rbtree.c -o test_rbtree
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "../src/common/rbtree.h"
|
#include "../src/common/rbtree.h"
|
||||||
#include "../src/common/debug.h"
|
#include "../src/common/debug.h"
|
||||||
|
|
|
||||||
10
test/unit.c
10
test/unit.c
|
|
@ -14,6 +14,16 @@ static inline char ranchr() {
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __assert_str(char *file, int line, char *func, char *a, char *b) {
|
||||||
|
|
||||||
|
if (a == NULL || b == NULL)
|
||||||
|
__uexit(file, line, func, "a or b is null\n", NULL);
|
||||||
|
|
||||||
|
if (strcmp(a, b) != 0)
|
||||||
|
__uexit(file, line, func, "\"%s\" != \"%s\"\n", a, b);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void utest_init_RNG() {
|
void utest_init_RNG() {
|
||||||
|
|
||||||
static unsigned char init = 0;
|
static unsigned char init = 0;
|
||||||
|
|
|
||||||
12
test/unit.h
12
test/unit.h
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#ifndef _UNIT_H
|
#ifndef _UNIT_H
|
||||||
|
|
||||||
#define _UNIT_H
|
#define _UNIT_H 1
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -15,15 +15,7 @@
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/* internal function. assert_* macros below expands to this */
|
/* internal function. assert_* macros below expands to this */
|
||||||
inline void __assert_str(char *file, int line, char *func, char *a, char *b) {
|
void __assert_str(char *file, int line, char *func, char *a, char *b);
|
||||||
|
|
||||||
if (a == NULL || b == NULL)
|
|
||||||
__uexit(file, line, func, "a or b is null\n", NULL);
|
|
||||||
|
|
||||||
if (strcmp(a, b) != 0)
|
|
||||||
__uexit(file, line, func, "\"%s\" != \"%s\"\n", a, b);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#define assert_string(a, b) __assert_str(__FILE__, __LINE__, __FUNCTION__, a, b)
|
#define assert_string(a, b) __assert_str(__FILE__, __LINE__, __FUNCTION__, a, b)
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue