summaryrefslogtreecommitdiff
path: root/app/bin/unittest/catalogtest.c
blob: 6025990684308328568d9c05e1898850a153a0e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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);
}