glib/gwin32.c: Silence a Deprecation Warning
[glib.git] / tests / env-test.c
blob1b2e2193ba10217846d684f0ded5bc54c90afc29
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 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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
28 #undef G_LOG_DOMAIN
30 #ifdef GLIB_COMPILATION
31 #undef GLIB_COMPILATION
32 #endif
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
38 #include <glib.h>
40 int
41 main (int argc, char *argv[])
43 gboolean result;
44 const gchar *data;
45 gchar *variable = "TEST_G_SETENV";
46 gchar *value1 = "works";
47 gchar *value2 = "again";
49 data = g_getenv (variable);
50 g_assert (data == NULL && "TEST_G_SETENV already set");
52 result = g_setenv (variable, value1, TRUE);
53 g_assert (result && "g_setenv() failed");
55 data = g_getenv (variable);
56 g_assert (data != NULL && "g_getenv() returns NULL");
57 g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value");
59 result = g_setenv (variable, value2, FALSE);
60 g_assert (result && "g_setenv() failed");
62 data = g_getenv (variable);
63 g_assert (data != NULL && "g_getenv() returns NULL");
64 g_assert (strcmp (data, value2) != 0 && "g_setenv() always overwrites");
65 g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value");
67 result = g_setenv (variable, value2, TRUE);
68 g_assert (result && "g_setenv() failed");
70 data = g_getenv (variable);
71 g_assert (data != NULL && "g_getenv() returns NULL");
72 g_assert (strcmp (data, value1) != 0 && "g_setenv() doesn't overwrite");
73 g_assert (strcmp (data, value2) == 0 && "g_getenv() returns wrong value");
75 g_unsetenv (variable);
76 data = g_getenv (variable);
77 g_assert (data == NULL && "g_unsetenv() doesn't work");
79 #if 0
80 /* We can't test this, because it's an illegal argument that
81 * we g_return_if_fail for.
83 result = g_setenv ("foo=bar", "baz", TRUE);
84 g_assert (!result && "g_setenv() accepts '=' in names");
85 #endif
87 result = g_setenv ("foo", "bar=baz", TRUE);
88 g_assert (result && "g_setenv() doesn't accept '=' in values");
89 #if 0
90 /* While glibc supports '=' in names in getenv(), SUS doesn't say anything about it,
91 * and Solaris doesn't support it.
93 data = g_getenv ("foo=bar");
94 g_assert (strcmp (data, "baz") == 0 && "g_getenv() doesn't support '=' in names");
95 #endif
96 data = g_getenv ("foo");
97 g_assert (strcmp (data, "bar=baz") == 0 && "g_getenv() doesn't support '=' in values");
99 #if 0
100 /* We can't test this, because it's an illegal argument that
101 * we g_return_if_fail for. Plus how would we check for failure,
102 * since we can't set the value...
104 g_unsetenv ("foo=bar");
105 #endif
106 g_unsetenv ("foo");
107 data = g_getenv ("foo");
108 g_assert (data == NULL && "g_unsetenv() doesn't support '=' in values");
110 return 0;