summaryrefslogtreecommitdiff
path: root/app/bin/unittest/defaultstest.c
blob: d877f463548310897fe8d80ff6274cb1eed9a7f7 (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
/** \file PathsTest.c
* Unit tests for the paths module
*/

#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>

#include "common.h"

#include "../appdefaults.c"

struct appDefault tests[] = {
	{"akey"},
	{"hkey"},
	{"mkey"},
	{"zkey"}
};


const char *libDir ="Parameter/directory/";

/**
 * A dummy for the real MakePath function 
 */

void
MakeFullpath( char **result, ...)
{
    *result = libDir;
}

#define TESTARRAYSIZE (sizeof(tests) / sizeof(tests[0]) )

struct appDefault test1[] = {
	{ "akey" }
};

#define TEST1ARRAYSIZE (sizeof(test1) / sizeof(test1[0]) )


int
wPrefGetIntegerBasic(const char *section, const char *name, long *result, long defaultValue)
{
	*result = defaultValue;
	return(TRUE);
}

int
wPrefGetFloatBasic(const char *section, const char *name, double *result, double defaultValue)
{
	*result = defaultValue;
	return(TRUE);
}

const char * wPrefGetStringBasic(const char *section, const char *name)
{
	return(NULL);
}

static void BinarySearch(void **state)
{
	int result;
	(void)state;

	result = binarySearch(tests, 0, TESTARRAYSIZE-1, "nokey");
	assert_int_equal(result, -1);

	result = binarySearch(tests, 0, TESTARRAYSIZE-1, "akey");
	assert_int_equal(result, 0);

	result = binarySearch(tests, 1, TESTARRAYSIZE-1, "mkey");
	assert_int_equal(result, 2);

	result = binarySearch(tests, 0, TESTARRAYSIZE-1, "zkey");
	assert_int_equal(result, 3);

	result = binarySearch(test1, 0, TEST1ARRAYSIZE-1, "akey");
	assert_int_equal(result, 0);

	result = binarySearch(test1, 0, TEST1ARRAYSIZE-1, "zkey");
	assert_int_equal(result, -1);

}

static void GetDefaults(void **state)
{
	double value = 0.0;
	long intValue = 0;
	(void)state;

	wPrefGetIntegerExt("DialogItem", "cmdopt-preselect", &intValue, 2);
	assert_int_equal(intValue, 1);

	wPrefGetIntegerExt("DialogItem", "cmdopt-preselect", &intValue, 2);
	assert_int_equal(intValue, 2);

}

int main(void)
{
    const struct CMUnitTest tests[] = {
		cmocka_unit_test(BinarySearch),
		cmocka_unit_test(GetDefaults)
    };
    return cmocka_run_group_tests(tests, NULL, NULL);
}