From d1a8285f818eb7e5c3d6a05709ea21a808490b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 19 Mar 2018 19:55:58 +0100 Subject: New upstream version 5.1.0 --- app/bin/unittest/CMakeLists.txt | 21 ++++++- app/bin/unittest/defaultstest.c | 110 ++++++++++++++++++++++++++++++++++++ app/bin/unittest/pathstest.c | 121 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 app/bin/unittest/defaultstest.c create mode 100644 app/bin/unittest/pathstest.c (limited to 'app/bin/unittest') diff --git a/app/bin/unittest/CMakeLists.txt b/app/bin/unittest/CMakeLists.txt index b6d2bc5..32e2ddb 100644 --- a/app/bin/unittest/CMakeLists.txt +++ b/app/bin/unittest/CMakeLists.txt @@ -9,4 +9,23 @@ target_link_libraries(dxfformattest dynstring ${LIBS}) -add_test(DXFOutputTest dxfformattest) \ No newline at end of file +add_test(DXFOutputTest dxfformattest) + +add_executable( pathstest + pathstest.c + ) + +target_link_libraries(pathstest + dynstring + ${LIBS}) + +add_test(PathsTest pathstest) + +add_executable( defaultstest + defaultstest.c + ) + +target_link_libraries(defaultstest + ${LIBS}) + +add_test(DefaultsTest defaultstest) 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 +#include +#include +#include +#include +#include + +#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); +} diff --git a/app/bin/unittest/pathstest.c b/app/bin/unittest/pathstest.c new file mode 100644 index 0000000..b7e792e --- /dev/null +++ b/app/bin/unittest/pathstest.c @@ -0,0 +1,121 @@ +/** \file PathsTest.c +* Unit tests for the paths module +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include "../paths.h" + +#ifdef WINDOWS +#define TESTPATH "C:\\Test\\Path" +#define TESTFILENAME "file.test" +#define TESTFILE TESTPATH "\\" TESTFILENAME +#define TESTPATH2 "D:\\Root" +#define TESTFILE2 TESTPATH2 "\\file2." + +#define TESTRELATIVEPATH "Test\\Path" +#define DEFAULTPATH "C:\\Default\\Path" +#else +#define TESTPATH "/Test/Path" +#define TESTFILENAME "file.test" +#define TESTFILE TESTPATH "/" TESTFILENAME +#define TESTPATH2 "/Root" +#define TESTFILE2 TESTPATH2 "/file2." + +#define TESTRELATIVEPATH "Test/Path" +#define DEFAULTPATH "/Default/Path" + +#endif //WINDOWS +void +wPrefSetString(const char *section, const char *key, const char *value) +{} + +char *wPrefGetStringExt(const char *section, const char *key) +{ + return(NULL); +} + +const char *wGetUserHomeDir(void) +{ + return(DEFAULTPATH); +} + +#include "../paths.c" + +static void SetGetPath(void **state) +{ + char *string; + (void)state; + + string = GetCurrentPath("Test"); + assert_string_equal(string, DEFAULTPATH); + + SetCurrentPath("Test", TESTFILE ); + string = GetCurrentPath("Test"); + assert_string_equal(string, TESTPATH); + + SetCurrentPath("Test", TESTFILE2); + string = GetCurrentPath("Test"); + assert_string_equal(string, TESTPATH2); +} + +static void Makepath(void **state) +{ + (void)state; + char *path; + +#ifdef WINDOWS + MakeFullpath(&path, + "C:", + TESTRELATIVEPATH, + TESTFILENAME, + NULL); + + assert_string_equal(path, "C:" TESTRELATIVEPATH "\\" TESTFILENAME); +#else + MakeFullpath(&path, + TESTRELATIVEPATH, + TESTFILENAME, + NULL); + + assert_string_equal(path, TESTRELATIVEPATH "/" TESTFILENAME); +#endif // WINDOWS + + free(path); + +#ifdef WINDOWS + MakeFullpath(&path, + "C:", + "test", + "\\subdir", + TESTFILENAME, + NULL); + assert_string_equal(path, "C:test\\subdir\\" TESTFILENAME); +#else + MakeFullpath(&path, + "test", + "/subdir", + TESTFILENAME, + NULL); + assert_string_equal(path, "test/subdir/" TESTFILENAME); + +#endif // WINDOWS + + + free(path); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(SetGetPath), + cmocka_unit_test(Makepath), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} -- cgit v1.2.3