glib/tests/list-env.c
changeset 59 09fa7c3c5079
child 72 403e7f6ed6c5
equal deleted inserted replaced
52:bf6a71c50e42 59:09fa7c3c5079
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #undef G_DISABLE_ASSERT
       
    17 #undef G_LOG_DOMAIN
       
    18 
       
    19 #include <glib.h>
       
    20 #include <errno.h>
       
    21 #define LOG_FILE "c:\\logs\\list_env_log.txt"
       
    22 #include "std_log_result.h"
       
    23 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    24 
       
    25 void create_xml(int result)
       
    26 {
       
    27     if(result)
       
    28         assert_failed = 1;
       
    29     
       
    30     testResultXml("list_env_log");
       
    31     close_log_file();
       
    32 }
       
    33 
       
    34 int main (int argc, char *argv[])
       
    35 {
       
    36     const gchar *variable1 = "TEST_VAR1";
       
    37     gchar *value1 = "testvalue1";
       
    38     const gchar *variable2 = "TEST_VAR2";
       
    39     gchar *value2 = "testvalue2";
       
    40     gchar **env_list;
       
    41     gint i, found = 0;
       
    42     guint no_of_variables =0;
       
    43     gboolean found_var1 = 0,  found_var2 = 0;
       
    44     	
       
    45     if(g_setenv (variable1, value1, TRUE) && g_setenv (variable2, value2, TRUE))
       
    46         {
       
    47         env_list = g_listenv();
       
    48         
       
    49         if(env_list)
       
    50             {
       
    51             no_of_variables = g_strv_length(env_list);
       
    52             
       
    53             if(no_of_variables)
       
    54                 {
       
    55                 for(i = 0; i<no_of_variables; i++)
       
    56                     {
       
    57                     gchar *data = env_list[i];
       
    58                     
       
    59                     if(g_strcmp0(data, variable1) == 0)
       
    60                         found_var1 = 1;
       
    61                     else if(g_strcmp0(data, variable2) == 0)
       
    62                         found_var2 = 1;
       
    63                     }
       
    64                 
       
    65                 if(!(found_var1 && found_var2))
       
    66                     {
       
    67                     std_log(LOG_FILENAME_LINE, "g_listenv failed");
       
    68                     assert_failed = 1;
       
    69                     }
       
    70                 }
       
    71             else
       
    72                 {
       
    73                 std_log(LOG_FILENAME_LINE, "g_listenv returned list is of length 0");
       
    74                 assert_failed = 1;
       
    75                 }
       
    76             
       
    77             g_strfreev(env_list);
       
    78             }
       
    79         else
       
    80             {
       
    81             std_log(LOG_FILENAME_LINE, "g_listenv returned NULL");
       
    82             assert_failed = 1;
       
    83             }
       
    84         }
       
    85     else
       
    86         {
       
    87         std_log(LOG_FILENAME_LINE, "setting env variable failed. errno = %d", errno);
       
    88         }
       
    89     
       
    90     if(assert_failed)
       
    91           std_log(LOG_FILENAME_LINE,"Test Failed");
       
    92     else
       
    93           std_log(LOG_FILENAME_LINE,"Test Successful");
       
    94 	
       
    95     create_xml(0);
       
    96 
       
    97 	return 0;
       
    98 }