glib/tests/uri-funcs.c
author hgs
Thu, 14 Oct 2010 14:15:50 +0530
changeset 70 62ed7a7d9e0b
parent 50 79045913e4e9
child 72 403e7f6ed6c5
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
hgs
parents:
diff changeset
    19
#include <glib.h>
hgs
parents:
diff changeset
    20
#include <errno.h>
hgs
parents:
diff changeset
    21
#define LOG_FILE "c:\\logs\\uri_funcs_log.txt"
hgs
parents:
diff changeset
    22
#include "std_log_result.h"
hgs
parents:
diff changeset
    23
#define LOG_FILENAME_LINE __FILE__, __LINE__
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
void create_xml(int result)
hgs
parents:
diff changeset
    26
{
hgs
parents:
diff changeset
    27
    if(result)
hgs
parents:
diff changeset
    28
        assert_failed = 1;
hgs
parents:
diff changeset
    29
    
hgs
parents:
diff changeset
    30
    testResultXml("uri_funcs_log");
hgs
parents:
diff changeset
    31
    close_log_file();
hgs
parents:
diff changeset
    32
}
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
int main (int argc, char *argv[])
hgs
parents:
diff changeset
    35
{
hgs
parents:
diff changeset
    36
    gchar *uri = "http:\\\\www.no!ki@a.com";
hgs
parents:
diff changeset
    37
    gchar *res_str = ":\\";
hgs
parents:
diff changeset
    38
    char *p;
hgs
parents:
diff changeset
    39
    char *q;
hgs
parents:
diff changeset
    40
    char *escape_str;
hgs
parents:
diff changeset
    41
    
hgs
parents:
diff changeset
    42
    p = g_uri_parse_scheme(uri);
hgs
parents:
diff changeset
    43
    
hgs
parents:
diff changeset
    44
    if(p)
hgs
parents:
diff changeset
    45
        {
hgs
parents:
diff changeset
    46
        if(strcmp(p, "http"))
hgs
parents:
diff changeset
    47
            {
hgs
parents:
diff changeset
    48
            std_log(LOG_FILENAME_LINE,"g_uri_parse_scheme didnt work as expected");
hgs
parents:
diff changeset
    49
            assert_failed = 1;
hgs
parents:
diff changeset
    50
            }
hgs
parents:
diff changeset
    51
        free(p);
hgs
parents:
diff changeset
    52
        }
hgs
parents:
diff changeset
    53
    else
hgs
parents:
diff changeset
    54
        {
hgs
parents:
diff changeset
    55
        std_log(LOG_FILENAME_LINE,"g_uri_parse_scheme returnd NULL. errno = %d", errno);
hgs
parents:
diff changeset
    56
        assert_failed = 1;
hgs
parents:
diff changeset
    57
        }
hgs
parents:
diff changeset
    58
    
hgs
parents:
diff changeset
    59
    
hgs
parents:
diff changeset
    60
    //escape the uri
hgs
parents:
diff changeset
    61
    escape_str = g_uri_escape_string(uri, res_str, TRUE);
hgs
parents:
diff changeset
    62
    
hgs
parents:
diff changeset
    63
    if(escape_str)
hgs
parents:
diff changeset
    64
        {
hgs
parents:
diff changeset
    65
        std_log(LOG_FILENAME_LINE, "escape string %s", escape_str);
hgs
parents:
diff changeset
    66
        
hgs
parents:
diff changeset
    67
        //convert back only a segment
hgs
parents:
diff changeset
    68
        q = g_uri_unescape_segment(escape_str, escape_str+16, NULL);
hgs
parents:
diff changeset
    69
        if(q)
hgs
parents:
diff changeset
    70
            {
hgs
parents:
diff changeset
    71
            std_log(LOG_FILENAME_LINE, "unescape segment string %s", q);
hgs
parents:
diff changeset
    72
            if(strcmp(q, "http:\\\\www.no!"))
hgs
parents:
diff changeset
    73
                {
hgs
parents:
diff changeset
    74
                std_log(LOG_FILENAME_LINE,"g_uri_unescape_segment didnt work as expected");
hgs
parents:
diff changeset
    75
                assert_failed = 1;
hgs
parents:
diff changeset
    76
                }
hgs
parents:
diff changeset
    77
            free(q);
hgs
parents:
diff changeset
    78
            }
hgs
parents:
diff changeset
    79
        else
hgs
parents:
diff changeset
    80
            {
hgs
parents:
diff changeset
    81
            std_log(LOG_FILENAME_LINE,"g_uri_unescape_segment returned NULL. errno = %d", errno);
hgs
parents:
diff changeset
    82
            assert_failed = 1;
hgs
parents:
diff changeset
    83
            }
hgs
parents:
diff changeset
    84
        
hgs
parents:
diff changeset
    85
        //convert back the whole string
hgs
parents:
diff changeset
    86
        p = g_uri_unescape_string(escape_str, NULL);
hgs
parents:
diff changeset
    87
        if(p)
hgs
parents:
diff changeset
    88
            {
hgs
parents:
diff changeset
    89
            std_log(LOG_FILENAME_LINE, "unescape string %s", p);
hgs
parents:
diff changeset
    90
            
hgs
parents:
diff changeset
    91
            //converted string should be same as original uri string
hgs
parents:
diff changeset
    92
            if(strcmp(p, uri))
hgs
parents:
diff changeset
    93
                {
hgs
parents:
diff changeset
    94
                std_log(LOG_FILENAME_LINE,"g_uri_unescape_string returned NULL");
hgs
parents:
diff changeset
    95
                assert_failed = 1;
hgs
parents:
diff changeset
    96
                }
hgs
parents:
diff changeset
    97
            
hgs
parents:
diff changeset
    98
            free(p);
hgs
parents:
diff changeset
    99
            }
hgs
parents:
diff changeset
   100
        else
hgs
parents:
diff changeset
   101
            {
hgs
parents:
diff changeset
   102
            std_log(LOG_FILENAME_LINE,"g_uri_unescape_string returned NULL. errno = %d", errno);
hgs
parents:
diff changeset
   103
            assert_failed = 1;
hgs
parents:
diff changeset
   104
            }
hgs
parents:
diff changeset
   105
        
hgs
parents:
diff changeset
   106
        free(escape_str);
hgs
parents:
diff changeset
   107
        }
hgs
parents:
diff changeset
   108
    else
hgs
parents:
diff changeset
   109
        {
hgs
parents:
diff changeset
   110
        std_log(LOG_FILENAME_LINE,"g_uri_escape_string returned NULL. errno = %d", errno);
hgs
parents:
diff changeset
   111
        assert_failed = 1;
hgs
parents:
diff changeset
   112
        }
hgs
parents:
diff changeset
   113
    
hgs
parents:
diff changeset
   114
	if(assert_failed)
hgs
parents:
diff changeset
   115
          std_log(LOG_FILENAME_LINE,"Test Failed");
hgs
parents:
diff changeset
   116
    else
hgs
parents:
diff changeset
   117
          std_log(LOG_FILENAME_LINE,"Test Successful");
hgs
parents:
diff changeset
   118
	
hgs
parents:
diff changeset
   119
    create_xml(0);
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
	return 0;
hgs
parents:
diff changeset
   122
}