From 4443319f4fc0a4186faaa25215fe932caa3b817f Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Wed, 29 Jun 2022 16:19:34 -0500 Subject: [PATCH] Add test suite for gargoyle_find_brand --- Makefile | 5 ++- include/gargoyle/test/sleuth.h | 9 +++++ test/runner.c | 15 +++++--- test/sleuth.c | 62 ++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 include/gargoyle/test/sleuth.h create mode 100644 test/sleuth.c diff --git a/Makefile b/Makefile index 9fa1020..16365cc 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,8 @@ LDFLAGS ?= -g -O1 LIB_CFLAGS ?= -fpic LIB_LDFLAGS ?= -shared GARGOYLE_OBJS := gargoyle scribe sleuth twine - -# temporary until there are tests for all source files -GARGOYLE_TEST_OBJS := runner twine +GARGOYLE_TEST_OBJS := runner sleuth twine +#GARGOYLE_TEST_OBJS := runner $(GARGOYLE_OBJS) .PHONY: all gargoyle init docs test clean diff --git a/include/gargoyle/test/sleuth.h b/include/gargoyle/test/sleuth.h new file mode 100644 index 0000000..2259ea0 --- /dev/null +++ b/include/gargoyle/test/sleuth.h @@ -0,0 +1,9 @@ +#ifndef GARGOYLE_TEST_SLEUTH_H_ +#define GARGOYLE_TEST_SLEUTH_H_ + +int init_suite_sleuth(void); +int clean_suite_sleuth(void); +void sleuth_test_find_brand(void); +void sleuth_test_find_emblem(void); + +#endif diff --git a/test/runner.c b/test/runner.c index 2a509b1..91993ce 100644 --- a/test/runner.c +++ b/test/runner.c @@ -1,5 +1,6 @@ #include #include +#include #include int main() { @@ -7,18 +8,24 @@ int main() { return CU_get_error(); } + CU_TestInfo sleuth_tests[] = { + { "gargoyle_find_brand", sleuth_test_find_brand }, +// { "gargoyle_find_emblem", sleuth_test_find_emblem }, + CU_TEST_INFO_NULL + }; + CU_TestInfo twine_tests[] = { { "gargoyle_is_sep", twine_test_is_sep }, { "gargoyle_is_eql", twine_test_is_eql }, { "gargoyle_cmp", twine_test_cmp }, { "gargoyle_cpy", twine_test_cpy }, - CU_TEST_INFO_NULL, + CU_TEST_INFO_NULL }; CU_SuiteInfo suites[] = { - // { "gargoyle", init_suite_gargoyle, clean_suite_gargoyle, NULL, NULL, gargoyle_tests }, - // { "scribe", init_suite_scribe, clean_suite_scribe, NULL, NULL, scribe_tests }, - // { "sleuth", init_suite_sleuth, clean_suite_sleuth, NULL, NULL, sleuth_tests }, +// { "gargoyle", init_suite_gargoyle, clean_suite_gargoyle, NULL, NULL, gargoyle_tests }, +// { "scribe", init_suite_scribe, clean_suite_scribe, NULL, NULL, scribe_tests }, + { "sleuth", init_suite_sleuth, clean_suite_sleuth, NULL, NULL, sleuth_tests }, { "twine", init_suite_twine, clean_suite_twine, NULL, NULL, twine_tests }, CU_SUITE_INFO_NULL, }; diff --git a/test/sleuth.c b/test/sleuth.c new file mode 100644 index 0000000..8cc02d4 --- /dev/null +++ b/test/sleuth.c @@ -0,0 +1,62 @@ +#include +#include +#include + +int init_suite_sleuth(void) { + return CUE_SUCCESS; +} + +int clean_suite_sleuth(void) { + return CUE_SUCCESS; +} + +void sleuth_test_find_brand(void) { + struct gargoyle_opt optv[] = { + { GARGOYLE_MK_OPT("foo"), 0, NULL, 0, GARGOYLE_TYPE_BOOL }, + { GARGOYLE_MK_OPT("bar"), 0, NULL, 0, GARGOYLE_TYPE_UINT } + }; + + uint16_t optc = sizeof(optv) / sizeof(struct gargoyle_opt); + + struct gargoyle_opt *opt = gargoyle_find_brand(optc, optv, "", NULL, 0, 0); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "foo", NULL, 0, 0); + CU_ASSERT_PTR_NOT_NULL(opt); + CU_ASSERT_NSTRING_EQUAL(opt->brand, "foo", opt->brand_sz); + + opt = gargoyle_find_brand(optc, optv, "no-foo", NULL, 0, 0); + CU_ASSERT_PTR_NOT_NULL(opt); + CU_ASSERT_NSTRING_EQUAL(opt->brand, "foo", opt->brand_sz); + + opt = gargoyle_find_brand(optc, optv, "no-foo", "", 0, 0); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "no_foo", NULL, 0, GARGOYLE_FLG_SYMBL); + CU_ASSERT_PTR_NOT_NULL(opt); + CU_ASSERT_NSTRING_EQUAL(opt->brand, "foo", opt->brand_sz); + + opt = gargoyle_find_brand(optc, optv, "no_foo", NULL, 0, GARGOYLE_FLG_ICASE); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "no_foo", NULL, 0, 0); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "No-Foo", NULL, 0, GARGOYLE_FLG_SYMBL); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "No-Foo", NULL, 0, GARGOYLE_FLG_ICASE); + CU_ASSERT_PTR_NOT_NULL(opt); + CU_ASSERT_NSTRING_EQUAL(opt->brand, "foo", opt->brand_sz); + + opt = gargoyle_find_brand(optc, optv, "No-Foo", NULL, 0, 0); + CU_ASSERT_PTR_NULL(opt); + + opt = gargoyle_find_brand(optc, optv, "NO_FOO", NULL, 0, GARGOYLE_FLG_FLXBL); + CU_ASSERT_PTR_NOT_NULL(opt); + CU_ASSERT_NSTRING_EQUAL(opt->brand, "foo", opt->brand_sz); +} + +void sleuth_test_find_emblem(void) { + CU_ASSERT_TRUE(1); +}