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