Added starting files for check unit tests

This commit is contained in:
Clay Dowling 2017-03-10 19:41:06 -05:00
parent 96d9751300
commit b635adc096
4 changed files with 69 additions and 1 deletions

3
c-check/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
test_gildedrose
golden_rose

View File

@ -12,7 +12,7 @@ CFLAGS = `pkg-config --cflags check` -g --std=c99 -D_POSIX_C_SOURCE=200809L
LIBS = `pkg-config --libs check`
# All files that should be part of your test should start with 'test'
TEST_SRC = `ls test*.[c\|h]`
TEST_SRC = $(wildcard test*.[c\|h])
TEST_BASE = $(basename ${TEST_SRC})
TEST_OBJECTS = $(addsuffix .o, ${TEST_BASE})

31
c-check/test_main.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <check.h>
Suite *suite_rose(void);
int main(int argc, char **argv)
{
Suite *s;
SRunner *runner;
int number_fails;
int forkme = 1;
if (argc > 1 && strcmp(argv[1], "--nofork") == 0) {
forkme = 0;
}
s = suite_rose();
runner = srunner_create(s);
if (0 == forkme) {
srunner_set_fork_status(runner, CK_NOFORK);
}
srunner_run_all(runner, CK_NORMAL);
number_fails = srunner_ntests_failed(runner);
srunner_free(runner);
return number_fails;
}

34
c-check/test_rose.c Normal file
View File

@ -0,0 +1,34 @@
#include <check.h>
#include "GildedRose.h"
START_TEST(roseFoo)
{
Item items[1];
init_item(items, "foo", 0, 0);
update_quality(items, 1);
ck_assert_str_eq("fixme", items[0].name);
}
END_TEST
TCase *tcase_rose(void)
{
TCase *tc;
tc = tcase_create("gilded-rose");
tcase_add_test(tc, roseFoo);
return tc;
}
Suite *suite_rose(void)
{
Suite *s;
s = suite_create("characterization-tests");
suite_add_tcase(s, tcase_rose());
return s;
}