glib/tests/list-env.c
author hgs
Thu, 14 Oct 2010 14:15:50 +0530
changeset 72 403e7f6ed6c5
parent 50 79045913e4e9
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
//
hgs
parents:
diff changeset
    15
hgs
parents:
diff changeset
    16
#undef G_DISABLE_ASSERT
hgs
parents:
diff changeset
    17
#undef G_LOG_DOMAIN
hgs
parents:
diff changeset
    18
72
hgs
parents: 50
diff changeset
    19
#include <sys/stat.h>
50
hgs
parents:
diff changeset
    20
#include <glib.h>
hgs
parents:
diff changeset
    21
#include <errno.h>
72
hgs
parents: 50
diff changeset
    22
#include <glib/gprintf.h>
hgs
parents: 50
diff changeset
    23
#ifdef __SYMBIAN32__
hgs
parents: 50
diff changeset
    24
#include "mrt2_glib2_test.h"
hgs
parents: 50
diff changeset
    25
#endif /*__SYMBIAN32__*/
50
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
int main (int argc, char *argv[])
hgs
parents:
diff changeset
    28
{
hgs
parents:
diff changeset
    29
    const gchar *variable1 = "TEST_VAR1";
hgs
parents:
diff changeset
    30
    gchar *value1 = "testvalue1";
hgs
parents:
diff changeset
    31
    const gchar *variable2 = "TEST_VAR2";
hgs
parents:
diff changeset
    32
    gchar *value2 = "testvalue2";
hgs
parents:
diff changeset
    33
    gchar **env_list;
hgs
parents:
diff changeset
    34
    gint i, found = 0;
hgs
parents:
diff changeset
    35
    guint no_of_variables =0;
hgs
parents:
diff changeset
    36
    gboolean found_var1 = 0,  found_var2 = 0;
72
hgs
parents: 50
diff changeset
    37
    #ifdef __SYMBIAN32__
hgs
parents: 50
diff changeset
    38
    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);
hgs
parents: 50
diff changeset
    39
    g_set_print_handler(mrtPrintHandler);
hgs
parents: 50
diff changeset
    40
    #endif /*__SYMBIAN32__*/
hgs
parents: 50
diff changeset
    41
    
hgs
parents: 50
diff changeset
    42
    g_print("Test list-env Start");
50
hgs
parents:
diff changeset
    43
    if(g_setenv (variable1, value1, TRUE) && g_setenv (variable2, value2, TRUE))
hgs
parents:
diff changeset
    44
        {
hgs
parents:
diff changeset
    45
        env_list = g_listenv();
hgs
parents:
diff changeset
    46
        
hgs
parents:
diff changeset
    47
        if(env_list)
hgs
parents:
diff changeset
    48
            {
hgs
parents:
diff changeset
    49
            no_of_variables = g_strv_length(env_list);
hgs
parents:
diff changeset
    50
            
hgs
parents:
diff changeset
    51
            if(no_of_variables)
hgs
parents:
diff changeset
    52
                {
hgs
parents:
diff changeset
    53
                for(i = 0; i<no_of_variables; i++)
hgs
parents:
diff changeset
    54
                    {
hgs
parents:
diff changeset
    55
                    gchar *data = env_list[i];
hgs
parents:
diff changeset
    56
                    
hgs
parents:
diff changeset
    57
                    if(g_strcmp0(data, variable1) == 0)
hgs
parents:
diff changeset
    58
                        found_var1 = 1;
hgs
parents:
diff changeset
    59
                    else if(g_strcmp0(data, variable2) == 0)
hgs
parents:
diff changeset
    60
                        found_var2 = 1;
hgs
parents:
diff changeset
    61
                    }
hgs
parents:
diff changeset
    62
                
hgs
parents:
diff changeset
    63
                if(!(found_var1 && found_var2))
hgs
parents:
diff changeset
    64
                    {
72
hgs
parents: 50
diff changeset
    65
                    g_print( "g_listenv failed");
50
hgs
parents:
diff changeset
    66
                    assert_failed = 1;
hgs
parents:
diff changeset
    67
                    }
hgs
parents:
diff changeset
    68
                }
hgs
parents:
diff changeset
    69
            else
hgs
parents:
diff changeset
    70
                {
72
hgs
parents: 50
diff changeset
    71
                g_print( "g_listenv returned list is of length 0");
50
hgs
parents:
diff changeset
    72
                assert_failed = 1;
hgs
parents:
diff changeset
    73
                }
hgs
parents:
diff changeset
    74
            
hgs
parents:
diff changeset
    75
            g_strfreev(env_list);
hgs
parents:
diff changeset
    76
            }
hgs
parents:
diff changeset
    77
        else
hgs
parents:
diff changeset
    78
            {
72
hgs
parents: 50
diff changeset
    79
            g_print( "g_listenv returned NULL");
50
hgs
parents:
diff changeset
    80
            assert_failed = 1;
hgs
parents:
diff changeset
    81
            }
hgs
parents:
diff changeset
    82
        }
hgs
parents:
diff changeset
    83
    else
hgs
parents:
diff changeset
    84
        {
72
hgs
parents: 50
diff changeset
    85
        g_print( "setting env variable failed. errno = %d", errno);
50
hgs
parents:
diff changeset
    86
        }
hgs
parents:
diff changeset
    87
    
hgs
parents:
diff changeset
    88
    if(assert_failed)
72
hgs
parents: 50
diff changeset
    89
          g_print("Test list-env Failed");
50
hgs
parents:
diff changeset
    90
    else
72
hgs
parents: 50
diff changeset
    91
          g_print("Test list-env Successful");
50
hgs
parents:
diff changeset
    92
	
72
hgs
parents: 50
diff changeset
    93
    #if __SYMBIAN32__
hgs
parents: 50
diff changeset
    94
    testResultXml("list-env");
hgs
parents: 50
diff changeset
    95
    #endif /* EMULATOR */
50
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
	return 0;
hgs
parents:
diff changeset
    98
}