<----------__________________
all_tests()
{
..... .. . . ..
mu_run_test(test_path_simlify); 1、_________-------->/*src/url.c*/
. . . . .
}
1 、 ____________--------------->
test_path_simplify(void )
2161 {
2162 static struct {
2163 char *test, *result;
2164 enum url_scheme scheme; /* 2、__________----------->in the src/url.c */
2165 bool should_modify;
2166 } tests[] = {
2167 { "", "", SCHEME_HTTP, false },
2168 { ".", "", SCHEME_HTTP, true },
2169 { "./", "", SCHEME_HTTP, true },
2170 { "..", "", SCHEME_HTTP, true },
2171 { "../", "", SCHEME_HTTP, true },
. . . . . .
}
2195 int i;
2196
2197 for (i = 0; i < countof (tests); i++)
2198 {
2199 const char *message;
2200 char *test = tests.test;
2201 char *expected_result = tests.result;
2202 enum url_scheme scheme = tests.scheme;
2203 bool expected_change = tests.should_modify;
2204 message = run_test (test, expected_result, scheme, expected_change); /*3、____----->/src/url.c*/
2205 if (message) return message;
2206 }
2207 return NULL;
2208 }
2、_________--------->
enum url_scheme{
SCHEME_HTTP,
#ifdef HAVE_SSL
SCHEME_HTTPS,
#endif
SCHEME_FTP,
SCHEME_INVALID
};
3、______--------->
static const char *
run_test(char *test, char *expected_result, enum url_scheme sheme, bool expected_chagnge)
{
2135 {
2136 char *test_copy = xstrdup (test); /*4、______----------->/lib/xmalloc.c*/
2137 bool modified = path_simplify (scheme, test_copy); /*7_____------->/src/urc.c*/
2138
2139 if (0 != strcmp (test_copy, expected_result))
2140 {
2141 printf ("Failed path_simplify(\"%s\"): expected \"%s\", got \"%s\". \n",
2142 test, expected_result, test_copy);
2143 mu_assert ("", 0);
2144 }
2145 if (modified != expected_change)
2146 {
2147 if (expected_change)
2148 printf ("Expected modification with path_simplify(\"%s\").\n",
2149 test);
2150 else
2151 printf ("Expected no modification with path_simplify(\"%s\").\n",
2152 test);
2153 }
2154 xfree (test_copy);
2155 mu_assert ("", modified == expected_change);
2156 return NULL;
2157 }
4________---------->
char *xstrdup( char const *string)
{
return xmemdup(string, strlen(string) + 1); /*5、___--->/lib/xmalloc.c*/
}
5、 ______----->
xmemdup(void const *p, size_t s)
{
return memcpy(xmalloc(s), p, s); /*6、___________-------> /lib/xmalloc.c*/
6、_____----------->
void *xmalloc (size_t n)
{
void *p = malloc(n); /*从堆中分配目的先检查是否会出现栈不够*/
if ( ! p && n ! = 0)
xalloc_die(); /*7、 ______________-----------> /lib/xmalloc.c*/
return p;
}
7、___________________--------------------->
void xalloc_die(void )
{
error(exit_failure, 0, "%s", _(memory exhausted"));
abort( );
}
7、_____----------->
static bool path_simplify (enum url_scheme scheme, char *path) /*函数为路径选择规则,就不讲了*/
此检查可以结束了。
阅读(659) | 评论(0) | 转发(0) |