os/ossrv/glib/tests/uri-funcs.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#undef G_DISABLE_ASSERT
sl@0
    17
#undef G_LOG_DOMAIN
sl@0
    18
sl@0
    19
#include <glib.h>
sl@0
    20
#include <errno.h>
sl@0
    21
#define LOG_FILE "c:\\logs\\uri_funcs_log.txt"
sl@0
    22
#include "std_log_result.h"
sl@0
    23
#define LOG_FILENAME_LINE __FILE__, __LINE__
sl@0
    24
sl@0
    25
void create_xml(int result)
sl@0
    26
{
sl@0
    27
    if(result)
sl@0
    28
        assert_failed = 1;
sl@0
    29
    
sl@0
    30
    testResultXml("uri_funcs_log");
sl@0
    31
    close_log_file();
sl@0
    32
}
sl@0
    33
sl@0
    34
int main (int argc, char *argv[])
sl@0
    35
{
sl@0
    36
    gchar *uri = "http:\\\\www.no!ki@a.com";
sl@0
    37
    gchar *res_str = ":\\";
sl@0
    38
    char *p;
sl@0
    39
    char *q;
sl@0
    40
    char *escape_str;
sl@0
    41
    
sl@0
    42
    p = g_uri_parse_scheme(uri);
sl@0
    43
    
sl@0
    44
    if(p)
sl@0
    45
        {
sl@0
    46
        if(strcmp(p, "http"))
sl@0
    47
            {
sl@0
    48
            std_log(LOG_FILENAME_LINE,"g_uri_parse_scheme didnt work as expected");
sl@0
    49
            assert_failed = 1;
sl@0
    50
            }
sl@0
    51
        free(p);
sl@0
    52
        }
sl@0
    53
    else
sl@0
    54
        {
sl@0
    55
        std_log(LOG_FILENAME_LINE,"g_uri_parse_scheme returnd NULL. errno = %d", errno);
sl@0
    56
        assert_failed = 1;
sl@0
    57
        }
sl@0
    58
    
sl@0
    59
    
sl@0
    60
    //escape the uri
sl@0
    61
    escape_str = g_uri_escape_string(uri, res_str, TRUE);
sl@0
    62
    
sl@0
    63
    if(escape_str)
sl@0
    64
        {
sl@0
    65
        std_log(LOG_FILENAME_LINE, "escape string %s", escape_str);
sl@0
    66
        
sl@0
    67
        //convert back only a segment
sl@0
    68
        q = g_uri_unescape_segment(escape_str, escape_str+16, NULL);
sl@0
    69
        if(q)
sl@0
    70
            {
sl@0
    71
            std_log(LOG_FILENAME_LINE, "unescape segment string %s", q);
sl@0
    72
            if(strcmp(q, "http:\\\\www.no!"))
sl@0
    73
                {
sl@0
    74
                std_log(LOG_FILENAME_LINE,"g_uri_unescape_segment didnt work as expected");
sl@0
    75
                assert_failed = 1;
sl@0
    76
                }
sl@0
    77
            free(q);
sl@0
    78
            }
sl@0
    79
        else
sl@0
    80
            {
sl@0
    81
            std_log(LOG_FILENAME_LINE,"g_uri_unescape_segment returned NULL. errno = %d", errno);
sl@0
    82
            assert_failed = 1;
sl@0
    83
            }
sl@0
    84
        
sl@0
    85
        //convert back the whole string
sl@0
    86
        p = g_uri_unescape_string(escape_str, NULL);
sl@0
    87
        if(p)
sl@0
    88
            {
sl@0
    89
            std_log(LOG_FILENAME_LINE, "unescape string %s", p);
sl@0
    90
            
sl@0
    91
            //converted string should be same as original uri string
sl@0
    92
            if(strcmp(p, uri))
sl@0
    93
                {
sl@0
    94
                std_log(LOG_FILENAME_LINE,"g_uri_unescape_string returned NULL");
sl@0
    95
                assert_failed = 1;
sl@0
    96
                }
sl@0
    97
            
sl@0
    98
            free(p);
sl@0
    99
            }
sl@0
   100
        else
sl@0
   101
            {
sl@0
   102
            std_log(LOG_FILENAME_LINE,"g_uri_unescape_string returned NULL. errno = %d", errno);
sl@0
   103
            assert_failed = 1;
sl@0
   104
            }
sl@0
   105
        
sl@0
   106
        free(escape_str);
sl@0
   107
        }
sl@0
   108
    else
sl@0
   109
        {
sl@0
   110
        std_log(LOG_FILENAME_LINE,"g_uri_escape_string returned NULL. errno = %d", errno);
sl@0
   111
        assert_failed = 1;
sl@0
   112
        }
sl@0
   113
    
sl@0
   114
	if(assert_failed)
sl@0
   115
          std_log(LOG_FILENAME_LINE,"Test Failed");
sl@0
   116
    else
sl@0
   117
          std_log(LOG_FILENAME_LINE,"Test Successful");
sl@0
   118
	
sl@0
   119
    create_xml(0);
sl@0
   120
sl@0
   121
	return 0;
sl@0
   122
}