From 30709b09689b2257412433dad2efc282fc51380f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 21 Nov 2021 19:49:20 +0100 Subject: [PATCH] =?UTF-8?q?test:=20add=20a=20test=20binary=20for=20foot,?= =?UTF-8?q?=20using=20the=20=E2=80=98check=E2=80=99=20test=20framework?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meson.build | 1 + tests/meson.build | 14 +++++++++++ tests/test-foot.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/test-foot.c diff --git a/meson.build b/meson.build index 39237a33..dbbd0ebc 100644 --- a/meson.build +++ b/meson.build @@ -84,6 +84,7 @@ wayland_cursor = dependency('wayland-cursor') xkb = dependency('xkbcommon', version: '>=1.0.0') fontconfig = dependency('fontconfig') utf8proc = dependency('libutf8proc', required: get_option('grapheme-clustering')) +check = dependency('check', required: false) if utf8proc.found() add_project_arguments('-DFOOT_GRAPHEME_CLUSTERING=1', language: 'c') diff --git a/tests/meson.build b/tests/meson.build index 4fe52c7d..386f99bc 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -6,3 +6,17 @@ config_test = executable( dependencies: [pixman, xkb, fontconfig, fcft, tllist]) test('config', config_test) + +if check.found() + foot_test = executable( + 'test-foot', + 'test-foot.c', + '../config.c', '../config.h', + '../tokenize.c', '../tokenize.h', + '../user-notification.c', '../user-notification.h', + wl_proto_headers, + dependencies: [check, pixman, xkb, fcft], + link_with: [common] + ) + test('foot', foot_test) +endif diff --git a/tests/test-foot.c b/tests/test-foot.c new file mode 100644 index 00000000..7a62270b --- /dev/null +++ b/tests/test-foot.c @@ -0,0 +1,61 @@ +#include +#include "../config.h" +#include "../user-notification.h" + +static struct config conf = {0}; +static user_notifications_t user_notifications = tll_init(); + +static void +conf_setup(void) +{ + memset(&conf, 0, sizeof(conf)); +} + +static void +conf_teardown(void) +{ + config_free(conf); +} + +static void +user_notifications_setup(void) +{ + ck_assert_int_eq(tll_length(user_notifications), 0); +} + +static void +user_notifications_teardown(void) +{ + user_notifications_free(&user_notifications); +} + +START_TEST(config_invalid_path) +{ + bool success = config_load( + &conf, "/invalid-path", &user_notifications, NULL, true); + ck_assert(!success); +} + +static Suite * +foot_suite(void) +{ + Suite *suite = suite_create("foot"); + TCase *config = tcase_create("config"); + tcase_add_checked_fixture(config, &conf_setup, &conf_teardown); + tcase_add_checked_fixture( + config, &user_notifications_setup, &user_notifications_teardown); + tcase_add_test(config, config_invalid_path); + suite_add_tcase(suite, config); + return suite; +} + +int +main(int argc, const char *const *argv) +{ + Suite *suite = foot_suite(); + SRunner *runner = srunner_create(suite); + srunner_run_all(runner, CK_NORMAL); + int failed = srunner_ntests_failed(runner); + srunner_free(runner); + return failed; +}