meson: work around meson not passing on the threads dependency when link_with is...
[glib.git] / tests / env-test.c
blobedf7edda71d38f93d472dcf9a7ace4f2cf851f10
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 #undef G_DISABLE_ASSERT
26 #undef G_LOG_DOMAIN
28 #ifdef GLIB_COMPILATION
29 #undef GLIB_COMPILATION
30 #endif
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
36 #include <glib.h>
38 int
39 main (int argc, char *argv[])
41 gboolean result;
42 const gchar *data;
43 gchar *variable = "TEST_G_SETENV";
44 gchar *value1 = "works";
45 gchar *value2 = "again";
47 data = g_getenv (variable);
48 g_assert (data == NULL && "TEST_G_SETENV already set");
50 result = g_setenv (variable, value1, TRUE);
51 g_assert (result && "g_setenv() failed");
53 data = g_getenv (variable);
54 g_assert (data != NULL && "g_getenv() returns NULL");
55 g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value");
57 result = g_setenv (variable, value2, FALSE);
58 g_assert (result && "g_setenv() failed");
60 data = g_getenv (variable);
61 g_assert (data != NULL && "g_getenv() returns NULL");
62 g_assert (strcmp (data, value2) != 0 && "g_setenv() always overwrites");
63 g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value");
65 result = g_setenv (variable, value2, TRUE);
66 g_assert (result && "g_setenv() failed");
68 data = g_getenv (variable);
69 g_assert (data != NULL && "g_getenv() returns NULL");
70 g_assert (strcmp (data, value1) != 0 && "g_setenv() doesn't overwrite");
71 g_assert (strcmp (data, value2) == 0 && "g_getenv() returns wrong value");
73 g_unsetenv (variable);
74 data = g_getenv (variable);
75 g_assert (data == NULL && "g_unsetenv() doesn't work");
77 #if 0
78 /* We can't test this, because it's an illegal argument that
79 * we g_return_if_fail for.
81 result = g_setenv ("foo=bar", "baz", TRUE);
82 g_assert (!result && "g_setenv() accepts '=' in names");
83 #endif
85 result = g_setenv ("foo", "bar=baz", TRUE);
86 g_assert (result && "g_setenv() doesn't accept '=' in values");
87 #if 0
88 /* While glibc supports '=' in names in getenv(), SUS doesn't say anything about it,
89 * and Solaris doesn't support it.
91 data = g_getenv ("foo=bar");
92 g_assert (strcmp (data, "baz") == 0 && "g_getenv() doesn't support '=' in names");
93 #endif
94 data = g_getenv ("foo");
95 g_assert (strcmp (data, "bar=baz") == 0 && "g_getenv() doesn't support '=' in values");
97 #if 0
98 /* We can't test this, because it's an illegal argument that
99 * we g_return_if_fail for. Plus how would we check for failure,
100 * since we can't set the value...
102 g_unsetenv ("foo=bar");
103 #endif
104 g_unsetenv ("foo");
105 data = g_getenv ("foo");
106 g_assert (data == NULL && "g_unsetenv() doesn't support '=' in values");
108 return 0;