nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GLIB - Library of useful routines for C programming |
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
||
3 | * |
||
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. |
||
8 | * |
||
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. |
||
13 | * |
||
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/>. |
||
16 | */ |
||
17 | |||
18 | /* |
||
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/. |
||
23 | */ |
||
24 | |||
25 | #undef G_DISABLE_ASSERT |
||
26 | #undef G_LOG_DOMAIN |
||
27 | |||
28 | #ifdef GLIB_COMPILATION |
||
29 | #undef GLIB_COMPILATION |
||
30 | #endif |
||
31 | |||
32 | #include <stdio.h> |
||
33 | #include <stdlib.h> |
||
34 | #include <string.h> |
||
35 | |||
36 | #include <glib.h> |
||
37 | |||
38 | int |
||
39 | main (int argc, char *argv[]) |
||
40 | { |
||
41 | gboolean result; |
||
42 | const gchar *data; |
||
43 | gchar *variable = "TEST_G_SETENV"; |
||
44 | gchar *value1 = "works"; |
||
45 | gchar *value2 = "again"; |
||
46 | |||
47 | data = g_getenv (variable); |
||
48 | g_assert (data == NULL && "TEST_G_SETENV already set"); |
||
49 | |||
50 | result = g_setenv (variable, value1, TRUE); |
||
51 | g_assert (result && "g_setenv() failed"); |
||
52 | |||
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"); |
||
56 | |||
57 | result = g_setenv (variable, value2, FALSE); |
||
58 | g_assert (result && "g_setenv() failed"); |
||
59 | |||
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"); |
||
64 | |||
65 | result = g_setenv (variable, value2, TRUE); |
||
66 | g_assert (result && "g_setenv() failed"); |
||
67 | |||
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"); |
||
72 | |||
73 | g_unsetenv (variable); |
||
74 | data = g_getenv (variable); |
||
75 | g_assert (data == NULL && "g_unsetenv() doesn't work"); |
||
76 | |||
77 | #if 0 |
||
78 | /* We can't test this, because it's an illegal argument that |
||
79 | * we g_return_if_fail for. |
||
80 | */ |
||
81 | result = g_setenv ("foo=bar", "baz", TRUE); |
||
82 | g_assert (!result && "g_setenv() accepts '=' in names"); |
||
83 | #endif |
||
84 | |||
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. |
||
90 | */ |
||
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"); |
||
96 | |||
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... |
||
101 | */ |
||
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"); |
||
107 | |||
108 | return 0; |
||
109 | } |