#include <stdint.h>#include <stddef.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <gpxe/uri.h>Go to the source code of this file.
Data Structures | |
| struct | uri_test |
Defines | |
| #define | URI_MAX_LEN 1024 |
Functions | |
| static int | test_parse_unparse (const char *uri_string) |
| static int | test_resolve (const char *base_uri_string, const char *relative_uri_string, const char *resolved_uri_string) |
| int | uri_test (void) |
Variables | |
| static struct uri_test | uri_tests [] |
| #define URI_MAX_LEN 1024 |
| static int test_parse_unparse | ( | const char * | uri_string | ) | [static] |
Definition at line 35 of file uri_test.c.
References EINVAL, ENOMEM, NULL, parse_uri(), printf(), strcmp(), strerror(), unparse_uri(), URI_ALL, and URI_MAX_LEN.
Referenced by uri_test().
00035 { 00036 char buf[URI_MAX_LEN]; 00037 size_t len; 00038 struct uri *uri = NULL; 00039 int rc; 00040 00041 /* Parse and unparse URI */ 00042 uri = parse_uri ( uri_string ); 00043 if ( ! uri ) { 00044 rc = -ENOMEM; 00045 goto done; 00046 } 00047 len = unparse_uri ( buf, sizeof ( buf ), uri, URI_ALL ); 00048 00049 /* Compare result */ 00050 if ( strcmp ( buf, uri_string ) != 0 ) { 00051 printf ( "Unparse of \"%s\" produced \"%s\"\n", 00052 uri_string, buf ); 00053 rc = -EINVAL; 00054 goto done; 00055 } 00056 00057 rc = 0; 00058 00059 done: 00060 uri_put ( uri ); 00061 if ( rc ) { 00062 printf ( "URI parse-unparse of \"%s\" failed: %s\n", 00063 uri_string, strerror ( rc ) ); 00064 } 00065 return rc; 00066 }
| static int test_resolve | ( | const char * | base_uri_string, | |
| const char * | relative_uri_string, | |||
| const char * | resolved_uri_string | |||
| ) | [static] |
Definition at line 68 of file uri_test.c.
References EINVAL, ENOMEM, NULL, parse_uri(), printf(), resolve_uri(), strcmp(), strerror(), unparse_uri(), URI_ALL, and URI_MAX_LEN.
Referenced by uri_test().
00070 { 00071 struct uri *base_uri = NULL; 00072 struct uri *relative_uri = NULL; 00073 struct uri *resolved_uri = NULL; 00074 char buf[URI_MAX_LEN]; 00075 size_t len; 00076 int rc; 00077 00078 /* Parse URIs */ 00079 base_uri = parse_uri ( base_uri_string ); 00080 if ( ! base_uri ) { 00081 rc = -ENOMEM; 00082 goto done; 00083 } 00084 relative_uri = parse_uri ( relative_uri_string ); 00085 if ( ! relative_uri ) { 00086 rc = -ENOMEM; 00087 goto done; 00088 } 00089 00090 /* Resolve URI */ 00091 resolved_uri = resolve_uri ( base_uri, relative_uri ); 00092 if ( ! resolved_uri ) { 00093 rc = -ENOMEM; 00094 goto done; 00095 } 00096 00097 /* Compare result */ 00098 len = unparse_uri ( buf, sizeof ( buf ), resolved_uri, URI_ALL ); 00099 if ( strcmp ( buf, resolved_uri_string ) != 0 ) { 00100 printf ( "Resolution of \"%s\"+\"%s\" produced \"%s\"\n", 00101 base_uri_string, relative_uri_string, buf ); 00102 rc = -EINVAL; 00103 goto done; 00104 } 00105 00106 rc = 0; 00107 00108 done: 00109 uri_put ( base_uri ); 00110 uri_put ( relative_uri ); 00111 uri_put ( resolved_uri ); 00112 if ( rc ) { 00113 printf ( "URI resolution of \"%s\"+\"%s\" failed: %s\n", 00114 base_uri_string, relative_uri_string, 00115 strerror ( rc ) ); 00116 } 00117 return rc; 00118 }
| int uri_test | ( | void | ) |
Definition at line 120 of file uri_test.c.
References uri_test::base_uri_string, printf(), uri_test::relative_uri_string, uri_test::resolved_uri_string, strerror(), test_parse_unparse(), and test_resolve().
00120 { 00121 unsigned int i; 00122 struct uri_test *uri_test; 00123 int rc; 00124 int overall_rc = 0; 00125 00126 for ( i = 0 ; i < ( sizeof ( uri_tests ) / 00127 sizeof ( uri_tests[0] ) ) ; i++ ) { 00128 uri_test = &uri_tests[i]; 00129 rc = test_parse_unparse ( uri_test->base_uri_string ); 00130 if ( rc != 0 ) 00131 overall_rc = rc; 00132 rc = test_parse_unparse ( uri_test->relative_uri_string ); 00133 if ( rc != 0 ) 00134 overall_rc = rc; 00135 rc = test_parse_unparse ( uri_test->resolved_uri_string ); 00136 if ( rc != 0 ) 00137 overall_rc = rc; 00138 rc = test_resolve ( uri_test->base_uri_string, 00139 uri_test->relative_uri_string, 00140 uri_test->resolved_uri_string ); 00141 if ( rc != 0 ) 00142 overall_rc = rc; 00143 } 00144 00145 if ( overall_rc ) 00146 printf ( "URI tests failed: %s\n", strerror ( overall_rc ) ); 00147 return overall_rc; 00148 }
Initial value:
{
{ "http://www.fensystems.co.uk", "",
"http://www.fensystems.co.uk/" },
{ "http://etherboot.org/wiki/page1", "page2",
"http://etherboot.org/wiki/page2" },
{ "http://etherboot.org/wiki/page1", "../page3",
"http://etherboot.org/page3" },
{ "tftp://192.168.0.1/", "/tftpboot/vmlinuz",
"tftp://192.168.0.1/tftpboot/vmlinuz" },
{ "ftp://the%41nswer%3d:%34ty%32wo@ether%62oot.org:8080/p%41th/foo",
"to?%41=b#%43d",
"ftp://theAnswer%3d:4ty2wo@etherboot.org:8080/path/to?a=b#cd" },
}
Definition at line 16 of file uri_test.c.
1.5.7.1