diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:56:15 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-03-19 19:56:15 +0100 |
commit | 1542c122b3672fe83e027411ad2445772e2d0ed3 (patch) | |
tree | e535bc621bd7ffa9d5ce89e0d495df5d1c4ab6fd /app/bin/unittest/defaultstest.c | |
parent | 773810e6583142d7d15263e6481c42aebed6d7f1 (diff) | |
parent | d1a8285f818eb7e5c3d6a05709ea21a808490b8c (diff) |
Update upstream source from tag 'upstream/5.1.0'
Update to upstream version '5.1.0'
with Debian dir 93ca74b8b4602fce4c9c7740e0cfdde25f086673
Diffstat (limited to 'app/bin/unittest/defaultstest.c')
-rw-r--r-- | app/bin/unittest/defaultstest.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/app/bin/unittest/defaultstest.c b/app/bin/unittest/defaultstest.c new file mode 100644 index 0000000..d877f46 --- /dev/null +++ b/app/bin/unittest/defaultstest.c @@ -0,0 +1,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); +} |