summaryrefslogtreecommitdiff
path: root/app/bin/unittest/catalogtest.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
commitb55285a77da0e0b829e4ce8d7e09debaabc68e15 (patch)
treef622559ef65bbdd3e1c5bdb06098a8f89eec0563 /app/bin/unittest/catalogtest.c
parentd3897ce090dbeb220ed2c782f095597e417cf3cc (diff)
parentd1ae75703e1ed81d65ea16946dcdb77e7a13adc9 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'app/bin/unittest/catalogtest.c')
-rw-r--r--app/bin/unittest/catalogtest.c124
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