mirror of
https://github.com/epasveer/seer.git
synced 2026-08-30 00:50:42 +08:00
Test program for libcheck and testing fork/vfork
Does Seer kill all inferiors after a "run/start"???
This commit is contained in:
@@ -0,0 +1 @@
|
||||
check_money
|
||||
@@ -0,0 +1,10 @@
|
||||
.PHONY: all
|
||||
all: check_money
|
||||
|
||||
check_money: check_money.c money.c
|
||||
g++ -I/usr/local/include -L/usr/local/lib64 -lcheck -g -o check_money check_money.c money.c
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f check_money check_money.o money.o
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <check.h>
|
||||
#include "money.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
extern Money* money_create(int, const char*);
|
||||
|
||||
START_TEST(test_money_create) {
|
||||
|
||||
Money* m;
|
||||
|
||||
m = money_create(5, "USD");
|
||||
|
||||
ck_assert_int_eq(money_amount(m), 5);
|
||||
ck_assert_str_eq(money_currency(m), "USD");
|
||||
|
||||
money_free(m);
|
||||
|
||||
} END_TEST
|
||||
|
||||
|
||||
Suite* money_suite (void) {
|
||||
|
||||
Suite *s;
|
||||
TCase *tc_core;
|
||||
|
||||
s = suite_create("Money");
|
||||
|
||||
tc_core = tcase_create("Core");
|
||||
|
||||
tcase_add_test(tc_core, test_money_create);
|
||||
suite_add_tcase(s, tc_core);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
int no_failed = 0;
|
||||
|
||||
Suite* s = money_suite();
|
||||
SRunner* runner = srunner_create(s);
|
||||
|
||||
srunner_run_all(runner, CK_NORMAL);
|
||||
|
||||
no_failed = srunner_ntests_failed(runner);
|
||||
srunner_free(runner);
|
||||
|
||||
return (no_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "money.h"
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Money {
|
||||
int amount;
|
||||
char currency[132];
|
||||
};
|
||||
|
||||
Money* money_create (int amount, const char* currency) {
|
||||
|
||||
Money *m = (Money*)malloc(sizeof(Money));
|
||||
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m->amount = amount;
|
||||
strcpy(m->currency, currency);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
int money_amount (Money* m) {
|
||||
return m->amount;
|
||||
}
|
||||
|
||||
char* money_currency (Money* m) {
|
||||
return m->currency;
|
||||
}
|
||||
|
||||
void money_free (Money* m) {
|
||||
free(m);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef MONEY_H
|
||||
#define MONEY_H
|
||||
|
||||
typedef struct Money Money;
|
||||
|
||||
Money* create_money (int amount, const char* currenty);
|
||||
int money_amount (Money* m);
|
||||
char* money_currency (Money* m);
|
||||
void money_free (Money* m);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user