diff --git a/tests/hellocheck/.gitignore b/tests/hellocheck/.gitignore new file mode 100644 index 0000000..f0513fa --- /dev/null +++ b/tests/hellocheck/.gitignore @@ -0,0 +1 @@ +check_money diff --git a/tests/hellocheck/Makefile b/tests/hellocheck/Makefile new file mode 100644 index 0000000..654b830 --- /dev/null +++ b/tests/hellocheck/Makefile @@ -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 + diff --git a/tests/hellocheck/check_money.c b/tests/hellocheck/check_money.c new file mode 100644 index 0000000..c30de49 --- /dev/null +++ b/tests/hellocheck/check_money.c @@ -0,0 +1,50 @@ +#include +#include "money.h" +#include + +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; +} + diff --git a/tests/hellocheck/money.c b/tests/hellocheck/money.c new file mode 100644 index 0000000..ba5132f --- /dev/null +++ b/tests/hellocheck/money.c @@ -0,0 +1,35 @@ +#include "money.h" +#include +#include + +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); +} + diff --git a/tests/hellocheck/money.h b/tests/hellocheck/money.h new file mode 100644 index 0000000..a7dfa51 --- /dev/null +++ b/tests/hellocheck/money.h @@ -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 +