diff --git a/Makefile.am b/Makefile.am index 5aa1bfb..481a62c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,10 @@ EXTRA_DIST = ${top_srcdir}/README.md \ ${top_srcdir}/HACKING \ ${top_srcdir}/findstatic.pl \ ${top_srcdir}/tests/data/blobfile \ + ${top_srcdir}/tests/data/match \ + ${top_srcdir}/tests/data/match1 \ + ${top_srcdir}/tests/data/nomatch1 \ + ${top_srcdir}/tests/data/nomatch2 \ ${top_srcdir}/sgcheck.suppressions \ ${top_srcdir}/data/clr-boot-manager-booted.service \ ${top_srcdir}/compat/kernel_updater.sh \ diff --git a/tests/check-files.c b/tests/check-files.c index d6bff87..735ac4e 100644 --- a/tests/check-files.c +++ b/tests/check-files.c @@ -22,6 +22,40 @@ #include "log.h" #include "nica/files.h" +START_TEST(bootman_match_test) +{ + const char *source_match = TOP_DIR "/tests/data/match"; + const char *good_match = TOP_DIR "/tests/data/match1"; + const char *bad_match_data = TOP_DIR "/tests/data/nomatch1"; + const char *bad_match_len = TOP_DIR "/tests/data/nomatch2"; + /* In a clean environment, anyway. */ + const char *non_exist_path = "PATHTHATWONT@EXIST!"; + + /* Known good */ + fail_if(!cbm_files_match(source_match, good_match), "Known matches failed to match"); + + /* Known different data */ + fail_if(cbm_files_match(source_match, bad_match_data), + "Shouldn't match files with different data"); + + /* Known different data + length */ + fail_if(cbm_files_match(source_match, bad_match_len), + "Shouldn't match files with different length"); + + /* Known missing target, with source present */ + fail_if(cbm_files_match(source_match, non_exist_path), + "Shouldn't match with non existent target"); + + /* Known missing source with existing target */ + fail_if(cbm_files_match(non_exist_path, source_match), + "Shouldn't match with non existent source"); + + /* Known missing both */ + fail_if(cbm_files_match(non_exist_path, non_exist_path), + "Shouldn't match non existent files"); +} +END_TEST + START_TEST(bootman_uuid_test) { if (geteuid() != 0) { @@ -70,6 +104,7 @@ static Suite *core_suite(void) s = suite_create("bootman_files"); tc = tcase_create("bootman_files"); + tcase_add_test(tc, bootman_match_test); tcase_add_test(tc, bootman_uuid_test); tcase_add_test(tc, bootman_mount_test); tcase_add_test(tc, bootman_find_boot); diff --git a/tests/data/match b/tests/data/match new file mode 100644 index 0000000..5ffc4c7 --- /dev/null +++ b/tests/data/match @@ -0,0 +1 @@ +This file is for matching. diff --git a/tests/data/match1 b/tests/data/match1 new file mode 100644 index 0000000..5ffc4c7 --- /dev/null +++ b/tests/data/match1 @@ -0,0 +1 @@ +This file is for matching. diff --git a/tests/data/nomatch1 b/tests/data/nomatch1 new file mode 100644 index 0000000..44130f8 --- /dev/null +++ b/tests/data/nomatch1 @@ -0,0 +1 @@ +This file is for matching! diff --git a/tests/data/nomatch2 b/tests/data/nomatch2 new file mode 100644 index 0000000..908ee07 --- /dev/null +++ b/tests/data/nomatch2 @@ -0,0 +1 @@ +This file is for matching. It differs in length