summaryrefslogtreecommitdiffstats
path: root/test/test_string.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-07-15 16:27:19 +0200
committerDavid Robillard <d@drobilla.net>2020-07-16 23:37:49 +0200
commit133de18003a7fe1d7ab4b88beeeef413d1eb28ac (patch)
tree4720a92b811032b0905b532d5df44706150ab0b8 /test/test_string.c
parent35177a5becb4955ad3c48eaabd83bcc0fa60ef94 (diff)
downloadlilv-133de18003a7fe1d7ab4b88beeeef413d1eb28ac.tar.gz
lilv-133de18003a7fe1d7ab4b88beeeef413d1eb28ac.tar.bz2
lilv-133de18003a7fe1d7ab4b88beeeef413d1eb28ac.zip
Split test suite up into several independent programs
Diffstat (limited to 'test/test_string.c')
-rw-r--r--test/test_string.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/test_string.c b/test/test_string.c
new file mode 100644
index 0000000..8d79327
--- /dev/null
+++ b/test/test_string.c
@@ -0,0 +1,94 @@
+/*
+ Copyright 2007-2020 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#define _POSIX_C_SOURCE 200809L /* for setenv */
+
+#undef NDEBUG
+
+#include "../src/lilv_internal.h"
+
+#ifdef _WIN32
+# include <windows.h>
+# define setenv(n, v, r) SetEnvironmentVariable((n), (v))
+# define unsetenv(n) SetEnvironmentVariable((n), NULL)
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main(void)
+{
+ char* s = NULL;
+
+ assert(!strcmp((s = lilv_dirname("/foo/bar")), "/foo"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("/foo/bar/")), "/foo"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("/foo///bar/")), "/foo"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("/foo///bar//")), "/foo"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("foo")), "."));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("/foo")), "/"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("/")), "/"));
+ free(s);
+ assert(!strcmp((s = lilv_dirname("//")), "/"));
+ free(s);
+ assert(!strcmp((s = lilv_path_relative_to("/a/b", "/a/")), "b"));
+ free(s);
+ assert(!strcmp((s = lilv_path_relative_to("/a", "/b/c/")), "/a"));
+ free(s);
+ assert(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/")), "../c"));
+ free(s);
+ assert(
+ !strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/e/")), "../../c"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join("/a", "b")), "/a/b"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join("/a", "/b")), "/a/b"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join("/a", NULL)), "/a/"));
+ free(s);
+ assert(!strcmp((s = lilv_path_join(NULL, "/b")), "/b"));
+ free(s);
+
+#ifndef _WIN32
+ setenv("LILV_TEST_1", "test", 1);
+ char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL);
+ assert(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test"));
+ free(s);
+ assert(!strcmp((s = lilv_expand("~")), getenv("HOME")));
+ free(s);
+ assert(!strcmp((s = lilv_expand("~foo")), "~foo"));
+ free(s);
+ assert(!strcmp((s = lilv_expand("~/foo")), home_foo));
+ free(s);
+ assert(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR"));
+ free(s);
+ free(home_foo);
+ unsetenv("LILV_TEST_1");
+#endif
+
+ return 0;
+}