Test program for libcheck and testing fork/vfork

Does Seer kill all inferiors after a "run/start"???
This commit is contained in:
Ernie Pasveer
2023-10-05 16:54:10 -05:00
parent b32d28fb83
commit d24bba5e3e
5 changed files with 108 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
check_money
+10
View File
@@ -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
+50
View File
@@ -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;
}
+35
View File
@@ -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);
}
+12
View File
@@ -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