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