diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 21:26:53 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 21:26:53 +0200 |
commit | df247efec654e512242e4f4f1b0212034f9e01fe (patch) | |
tree | 25c02e16957f3aa613af30c140fd8e8a3d52fda6 /app/bin/unittest/catalogtest.c | |
parent | d0b6a8a4ec298024f14f704f9e40a6f9d324ccf3 (diff) | |
parent | a5ade52caa489cf0a713e0f02b764000d203140e (diff) |
Merge branch 'release/debian/1%5.2.0Beta2.1-1' into masterHEADdebian/1%5.2.0Beta2.1-1master
Diffstat (limited to 'app/bin/unittest/catalogtest.c')
-rw-r--r-- | app/bin/unittest/catalogtest.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/app/bin/unittest/catalogtest.c b/app/bin/unittest/catalogtest.c new file mode 100644 index 0000000..6025990 --- /dev/null +++ b/app/bin/unittest/catalogtest.c @@ -0,0 +1,124 @@ +/** \file catalog.c +* Unit tests for part catalog management +*/ + +#include <malloc.h> +#include <stdarg.h> +#include <stddef.h> +#include <string.h> +#include <stdio.h> +#include <setjmp.h> +#include <cmocka.h> + +#include "../include/partcatalog.h" + +TrackLibrary *trackLib; +CatalogEntry *catalog; + + +// some dummy functions to suppress linking problems +wGetUserHomeDir() +{ + +} + +wPrefSetString() +{ + +} + +wPrefGetString() +{ + +} + +AbortProg() +{ + +} + +static void +CreateLib(void **state) +{ + (void)state; + trackLib = CreateLibrary("."); + assert_non_null((void *)trackLib); +} + +static void ScanEmptyDir(void **state) +{ + (void)state; + bool success; + EmptyCatalog(trackLib->catalog); + success = GetTrackFiles(trackLib, "//"); + assert_false(success); +} + +static void ScanTestFiles(void **state) +{ + (void)state; + bool success; + EmptyCatalog(trackLib->catalog); + success = GetTrackFiles(trackLib, "."); + assert_true(success); +} + +static void CreateIndex(void **state) +{ + (void)state; + unsigned int words = CreateLibraryIndex(trackLib); + assert_true(words > 0); +} + +static void SearchNothing(void **state) +{ + (void)state; + unsigned int files = SearchLibrary(trackLib, "djfhdkljhf", catalog); + assert_true(files == 0); + EmptyCatalog(catalog); +} + +static void SearchSingle(void **state) +{ + (void)state; + int files = SearchLibrary(trackLib, "peco", catalog ); + assert_true(files==1); + EmptyCatalog(catalog); +} + +static void SearchMultiple(void **state) +{ + (void)state; + int files = SearchLibrary(trackLib, "atlas", catalog); + assert_true(files == 2); + EmptyCatalog(catalog); +} + +static void FilterTest(void **state) +{ + (void)state; + bool res; + + res = FilterKeyword("test"); + assert_false(res); + assert_true(FilterKeyword("&")); + assert_false(FilterKeyword("n")); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(CreateLib), + cmocka_unit_test(ScanEmptyDir), + cmocka_unit_test(ScanTestFiles), + cmocka_unit_test(CreateIndex), + cmocka_unit_test(SearchNothing), + cmocka_unit_test(SearchSingle), + cmocka_unit_test(SearchMultiple), + cmocka_unit_test(FilterTest), + }; + + catalog = InitCatalog(); + + return cmocka_run_group_tests(tests, NULL, NULL); +}
\ No newline at end of file |