summaryrefslogtreecommitdiff
path: root/app/bin/unittest/pathstest.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:56:15 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:56:15 +0100
commit1542c122b3672fe83e027411ad2445772e2d0ed3 (patch)
treee535bc621bd7ffa9d5ce89e0d495df5d1c4ab6fd /app/bin/unittest/pathstest.c
parent773810e6583142d7d15263e6481c42aebed6d7f1 (diff)
parentd1a8285f818eb7e5c3d6a05709ea21a808490b8c (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/pathstest.c')
-rw-r--r--app/bin/unittest/pathstest.c121
1 files changed, 121 insertions, 0 deletions
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 <stdarg.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <dynstring.h>
+#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);
+}