summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-04-15 21:33:07 +0200
committerDavid Robillard <d@drobilla.net>2019-04-15 23:03:12 +0200
commite688e49e365b9c62426c11fa92698c45d615cb02 (patch)
tree525e4a95d4f2f7f85cdbe7006bd45360c4504197 /test
parentb9978e87e34bbf930d09a80b8f4eb6d541726dd0 (diff)
downloadlilv-e688e49e365b9c62426c11fa92698c45d615cb02.tar.gz
lilv-e688e49e365b9c62426c11fa92698c45d615cb02.tar.bz2
lilv-e688e49e365b9c62426c11fa92698c45d615cb02.zip
Use putenv instead of setenv in unit tests on Windows
This makes things work on Windows, because only putenv changes the environment of the current process.
Diffstat (limited to 'test')
-rw-r--r--test/lilv_test.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/test/lilv_test.c b/test/lilv_test.c
index e54c84f..72a7f43 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -186,6 +186,21 @@ cleanup(void)
delete_bundle();
}
+static void
+set_env(const char* name, const char* value)
+{
+#ifdef _WIN32
+ // setenv on Windows does not modify the current process' environment
+ const size_t len = strlen(name) + 1 + strlen(value) + 1;
+ char* str = (char*)calloc(1, len);
+ snprintf(str, len, "%s=%s", name, value);
+ putenv(str);
+ free(str);
+#else
+ setenv(name, value, 1);
+#endif
+}
+
/*****************************************************************************/
#define TEST_CASE(name) { #name, test_##name }
@@ -1159,43 +1174,43 @@ test_port(void)
lilv_node_free(name);
// Exact language match
- setenv("LANG", "fr_FR", 1);
+ set_env("LANG", "de_DE");
name = lilv_port_get_name(plug, p);
TEST_ASSERT(!strcmp(lilv_node_as_string(name), "Laden"));
lilv_node_free(name);
// Exact language match (with charset suffix)
- setenv("LANG", "fr_CA.utf8", 1);
+ set_env("LANG", "de_AT.utf8");
name = lilv_port_get_name(plug, p);
TEST_ASSERT(!strcmp(lilv_node_as_string(name), "Geschaeft"));
lilv_node_free(name);
// Partial language match (choose value translated for different country)
- setenv("LANG", "fr_BE", 1);
+ set_env("LANG", "de_CH");
name = lilv_port_get_name(plug, p);
TEST_ASSERT((!strcmp(lilv_node_as_string(name), "Laden"))
||(!strcmp(lilv_node_as_string(name), "Geschaeft")));
lilv_node_free(name);
// Partial language match (choose country-less language tagged value)
- setenv("LANG", "es_MX", 1);
+ set_env("LANG", "es_MX");
name = lilv_port_get_name(plug, p);
TEST_ASSERT(!strcmp(lilv_node_as_string(name), "tienda"));
lilv_node_free(name);
// No language match (choose untranslated value)
- setenv("LANG", "cn", 1);
+ set_env("LANG", "cn");
name = lilv_port_get_name(plug, p);
TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
lilv_node_free(name);
// Invalid language
- setenv("LANG", "1!", 1);
+ set_env("LANG", "1!");
name = lilv_port_get_name(plug, p);
TEST_ASSERT(!strcmp(lilv_node_as_string(name), "store"));
lilv_node_free(name);
- setenv("LANG", "en_CA.utf-8", 1);
+ set_env("LANG", "en_CA.utf-8");
// Language tagged value with no untranslated values
LilvNode* rdfs_comment = lilv_new_uri(world, LILV_NS_RDFS "comment");
@@ -1207,14 +1222,14 @@ test_port(void)
lilv_node_free(comment);
lilv_nodes_free(comments);
- setenv("LANG", "fr", 1);
+ set_env("LANG", "fr");
comments = lilv_port_get_value(plug, p, rdfs_comment);
TEST_ASSERT(!strcmp(lilv_node_as_string(lilv_nodes_get_first(comments)),
"commentaires"));
lilv_nodes_free(comments);
- setenv("LANG", "cn", 1);
+ set_env("LANG", "cn");
comments = lilv_port_get_value(plug, p, rdfs_comment);
TEST_ASSERT(!comments);
@@ -1222,7 +1237,7 @@ test_port(void)
lilv_node_free(rdfs_comment);
- setenv("LANG", "C", 1); // Reset locale
+ set_env("LANG", "C"); // Reset locale
LilvScalePoints* points = lilv_port_get_scale_points(plug, p);
TEST_ASSERT(lilv_scale_points_size(points) == 2);
@@ -2276,7 +2291,7 @@ main(int argc, char* argv[])
printf("Syntax: %s\n", argv[0]);
return 0;
}
- setenv("LANG", "C", 1);
+ set_env("LANG", "C");
init_tests();
run_tests();
cleanup();