From 24ac0e48970058f88f69f04480e53ae4cdb609fa Mon Sep 17 00:00:00 2001 From: Pradana Aumars Date: Thu, 3 Jun 2021 00:34:12 +0200 Subject: [PATCH] Add test for calibrate.replace_text --- tests/Makefile.am | 3 ++- tests/check_calibrate.c | 34 +++++++++++++++++++++++++++++++--- tests/check_check.c | 1 + tests/check_check.h | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index ff6f232..ea4bc98 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,9 +5,10 @@ noinst_PROGRAMS = \ check_check check_check_SOURCES = \ + check_check.c \ check_file_t.c \ check_exception_t.c \ - check_check.c + check_calibrate.c check_check_CFLAGS= $(CFLAGS) $(CHECK_CFLAGS) check_check_LDFLAGS= $(LDFLAGS) $(CHECK_LIBS) check_check_LDADD = $(top_builddir)/src/libmodetw.la diff --git a/tests/check_calibrate.c b/tests/check_calibrate.c index f4aff47..5a73b94 100644 --- a/tests/check_calibrate.c +++ b/tests/check_calibrate.c @@ -1,8 +1,36 @@ +#include #include - +#include "check_check.h" #include "../src/calibrate.h" +#include "../src/file_t.h" -START_TEST(test_calibrate) +START_TEST(test_replace_text) { - + exception_t *e; + file_t *f; + e = exception_init(); + f = file_init("samples/1.txt", FILEPATH_RELATIVE, e); + char *path = file_abs(f); + ck_assert(replace_text(path, "ABC", "123", "ASCII", e)); + ck_assert(exception_null(e)); + ck_assert(replace_text(path, "123", "ABC", "ASCII", e)); + ck_assert(exception_null(e)); + file_close(f); + exception_free(e); + free(path); +} + +Suite* +calibrate_suite(void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create ("calibrate"); + tc_core = tcase_create ("core"); + + tcase_add_test(tc_core, test_replace_text); + suite_add_tcase(s, tc_core); + + return s; } diff --git a/tests/check_check.c b/tests/check_check.c index d0033c5..964e838 100644 --- a/tests/check_check.c +++ b/tests/check_check.c @@ -9,6 +9,7 @@ main(void) sr = srunner_create(file_t_suite()); srunner_add_suite(sr, exception_t_suite()); + srunner_add_suite(sr, calibrate_suite()); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); diff --git a/tests/check_check.h b/tests/check_check.h index 291a44f..fccdcd3 100644 --- a/tests/check_check.h +++ b/tests/check_check.h @@ -5,5 +5,6 @@ Suite* file_t_suite(void); Suite* exception_t_suite(void); +Suite* calibrate_suite(void); #endif