sl@0: /* GLIB - Library of useful routines for C programming sl@0: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald sl@0: * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: */ sl@0: sl@0: /* sl@0: * Modified by the GLib Team and others 1997-2000. See the AUTHORS sl@0: * file for a list of people on the GLib Team. See the ChangeLog sl@0: * files for a list of changes. These files are distributed with sl@0: * GLib at ftp://ftp.gtk.org/pub/gtk/. sl@0: */ sl@0: sl@0: #include "config.h" sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #ifdef GLIB_COMPILATION sl@0: #undef GLIB_COMPILATION sl@0: #endif sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: #ifdef HAVE_UNISTD_H sl@0: #include sl@0: #endif sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: sl@0: int sl@0: main (int argc, char *argv[]) sl@0: { sl@0: gboolean result; sl@0: const gchar *data; sl@0: gchar *variable = "TEST_G_SETENV"; sl@0: gchar *value1 = "works"; sl@0: gchar *value2 = "again"; sl@0: sl@0: #ifdef SYMBIAN sl@0: g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: data = g_getenv (variable); sl@0: g_assert (data == NULL && "TEST_G_SETENV already set"); sl@0: sl@0: result = g_setenv (variable, value1, TRUE); sl@0: g_assert (result && "g_setenv() failed"); sl@0: sl@0: data = g_getenv (variable); sl@0: g_assert (data != NULL && "g_getenv() returns NULL"); sl@0: g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value"); sl@0: sl@0: result = g_setenv (variable, value2, FALSE); sl@0: g_assert (result && "g_setenv() failed"); sl@0: sl@0: data = g_getenv (variable); sl@0: g_assert (data != NULL && "g_getenv() returns NULL"); sl@0: g_assert (strcmp (data, value2) != 0 && "g_setenv() always overwrites"); sl@0: g_assert (strcmp (data, value1) == 0 && "g_getenv() returns wrong value"); sl@0: sl@0: result = g_setenv (variable, value2, TRUE); sl@0: g_assert (result && "g_setenv() failed"); sl@0: sl@0: data = g_getenv (variable); sl@0: g_assert (data != NULL && "g_getenv() returns NULL"); sl@0: g_assert (strcmp (data, value1) != 0 && "g_setenv() doesn't overwrite"); sl@0: g_assert (strcmp (data, value2) == 0 && "g_getenv() returns wrong value"); sl@0: sl@0: g_unsetenv (variable); sl@0: data = g_getenv (variable); sl@0: g_assert (data == NULL && "g_unsetenv() doesn't work"); sl@0: sl@0: #if 0 sl@0: /* We can't test this, because it's an illegal argument that sl@0: * we g_return_if_fail for. sl@0: */ sl@0: result = g_setenv ("foo=bar", "baz", TRUE); sl@0: g_assert (!result && "g_setenv() accepts '=' in names"); sl@0: #endif sl@0: sl@0: result = g_setenv ("foo", "bar=baz", TRUE); sl@0: g_assert (result && "g_setenv() doesn't accept '=' in values"); sl@0: #if 0 sl@0: /* While glibc supports '=' in names in getenv(), SUS doesn't say anything about it, sl@0: * and Solaris doesn't support it. sl@0: */ sl@0: data = g_getenv ("foo=bar"); sl@0: g_assert (strcmp (data, "baz") == 0 && "g_getenv() doesn't support '=' in names"); sl@0: #endif sl@0: data = g_getenv ("foo"); sl@0: g_assert (strcmp (data, "bar=baz") == 0 && "g_getenv() doesn't support '=' in values"); sl@0: sl@0: #if 0 sl@0: /* We can't test this, because it's an illegal argument that sl@0: * we g_return_if_fail for. Plus how would we check for failure, sl@0: * since we can't set the value... sl@0: */ sl@0: g_unsetenv ("foo=bar"); sl@0: #endif sl@0: g_unsetenv ("foo"); sl@0: data = g_getenv ("foo"); sl@0: g_assert (data == NULL && "g_unsetenv() doesn't support '=' in values"); sl@0: sl@0: #if SYMBIAN sl@0: testResultXml("env-test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: sl@0: return 0; sl@0: }