⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path-test.c

📁 subversion-1.4.5.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
                  svn_test_opts_t *opts,                  apr_pool_t *pool){  /* We have to code the IRIs like this because the compiler might translate     character and string literals outside of ASCII to some character set,     but here we are hard-coding UTF-8.  But we all read UTF-8 codes like     poetry, don't we. */  static const char p1[] = {    '\x66', '\x69', '\x6C', '\x65', '\x3A', '\x2F', '\x2F', '\x2F',    '\x72', '\xC3', '\xA4', '\x6B', '\x73', '\x6D', '\xC3', '\xB6', '\x72',    '\x67', '\xC3', '\xA5', '\x73', '\0' };  static const char p2[] = {    '\x66', '\x69', '\x6C', '\x65', '\x3A', '\x2F', '\x2F', '\x2F',    '\x61', '\x62', '\x25', '\x32', '\x30', '\x63', '\x64', '\0' };  static const char *paths[2][2] = {    { p1,      "file:///r%C3%A4ksm%C3%B6rg%C3%A5s" },    { p2,      "file:///ab%20cd" }  };  int i;  *msg = "test svn_path_uri_from_iri";  if (msg_only)    return SVN_NO_ERROR;  for (i = 0; i < 2; ++i)    {      const char *uri = svn_path_uri_from_iri(paths[i][0], pool);      if (strcmp(paths[i][1], uri) != 0)        return svn_error_createf          (SVN_ERR_TEST_FAILED, NULL,           "svn_path_uri_from_iri on '%s' returned '%s' instead of '%s'",           paths[i][0], uri, paths[i][1]);      if (strcmp(paths[i][0], uri) == 0          && paths[i][0] != uri)        return svn_error_createf          (SVN_ERR_TEST_FAILED, NULL,           "svn_path_uri_from_iri on '%s' returned identical but not same"           " string", paths[i][0]);    }  return SVN_NO_ERROR;}static svn_error_t *test_join(const char **msg,          svn_boolean_t msg_only,          svn_test_opts_t *opts,          apr_pool_t *pool){  int i;  char *result;  static const char * const joins[][3] = {    { "abc", "def", "abc/def" },    { "a", "def", "a/def" },    { "a", "d", "a/d" },    { "/", "d", "/d" },    { "/abc", "d", "/abc/d" },    { "/abc", "def", "/abc/def" },    { "/abc", "/def", "/def" },    { "/abc", "/d", "/d" },    { "/abc", "/", "/" },    { SVN_EMPTY_PATH, "/", "/" },    { "/", SVN_EMPTY_PATH, "/" },    { SVN_EMPTY_PATH, "abc", "abc" },    { "abc", SVN_EMPTY_PATH, "abc" },    { SVN_EMPTY_PATH, "/abc", "/abc" },    { SVN_EMPTY_PATH, SVN_EMPTY_PATH, SVN_EMPTY_PATH },  };  *msg = "test svn_path_join(_many)";  if (msg_only)    return SVN_NO_ERROR;  for (i = sizeof(joins) / sizeof(joins[0]); i--; )    {      const char *base = joins[i][0];      const char *comp = joins[i][1];      const char *expect = joins[i][2];      result = svn_path_join(base, comp, pool);      if (strcmp(result, expect))        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                 "svn_path_join(\"%s\", \"%s\") returned "                                 "\"%s\". expected \"%s\"",                                 base, comp, result, expect);      result = svn_path_join_many(pool, base, comp, NULL);      if (strcmp(result, expect))        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                 "svn_path_join_many(\"%s\", \"%s\") returned "                                 "\"%s\". expected \"%s\"",                                 base, comp, result, expect);    }#define TEST_MANY(args, expect) \  result = svn_path_join_many args ; \  if (strcmp(result, expect) != 0) \    return svn_error_createf(SVN_ERR_TEST_FAILED, NULL, \                             "svn_path_join_many" #args " returns \"%s\". " \                             "expected \"%s\"", \                             result, expect); \  else  TEST_MANY((pool, "abc", NULL), "abc");  TEST_MANY((pool, "/abc", NULL), "/abc");  TEST_MANY((pool, "/", NULL), "/");  TEST_MANY((pool, "abc", "def", "ghi", NULL), "abc/def/ghi");  TEST_MANY((pool, "abc", "/def", "ghi", NULL), "/def/ghi");  TEST_MANY((pool, "/abc", "def", "ghi", NULL), "/abc/def/ghi");  TEST_MANY((pool, "abc", "def", "/ghi", NULL), "/ghi");  TEST_MANY((pool, "/", "def", "/ghi", NULL), "/ghi");  TEST_MANY((pool, "/", "/def", "/ghi", NULL), "/ghi");  TEST_MANY((pool, SVN_EMPTY_PATH, "def", "ghi", NULL), "def/ghi");  TEST_MANY((pool, "abc", SVN_EMPTY_PATH, "ghi", NULL), "abc/ghi");  TEST_MANY((pool, "abc", "def", SVN_EMPTY_PATH, NULL), "abc/def");  TEST_MANY((pool, SVN_EMPTY_PATH, "def", SVN_EMPTY_PATH, NULL), "def");  TEST_MANY((pool, SVN_EMPTY_PATH, SVN_EMPTY_PATH, "ghi", NULL), "ghi");  TEST_MANY((pool, "abc", SVN_EMPTY_PATH, SVN_EMPTY_PATH, NULL), "abc");  TEST_MANY((pool, SVN_EMPTY_PATH, "def", "/ghi", NULL), "/ghi");  TEST_MANY((pool, SVN_EMPTY_PATH, SVN_EMPTY_PATH, "/ghi", NULL), "/ghi");  TEST_MANY((pool, "/", "def", "ghi", NULL), "/def/ghi");  TEST_MANY((pool, "abc", "/", "ghi", NULL), "/ghi");  TEST_MANY((pool, "abc", "def", "/", NULL), "/");  TEST_MANY((pool, "/", "/", "ghi", NULL), "/ghi");  TEST_MANY((pool, "/", "/", "/", NULL), "/");  TEST_MANY((pool, "/", SVN_EMPTY_PATH, "ghi", NULL), "/ghi");  TEST_MANY((pool, "/", "def", SVN_EMPTY_PATH, NULL), "/def");  TEST_MANY((pool, SVN_EMPTY_PATH, "/", "ghi", NULL), "/ghi");  TEST_MANY((pool, "/", SVN_EMPTY_PATH, SVN_EMPTY_PATH, NULL), "/");  TEST_MANY((pool, SVN_EMPTY_PATH, "/", SVN_EMPTY_PATH, NULL), "/");  TEST_MANY((pool, SVN_EMPTY_PATH, SVN_EMPTY_PATH, "/", NULL), "/");  /* ### probably need quite a few more tests... */  return SVN_NO_ERROR;}static svn_error_t *test_basename(const char **msg,              svn_boolean_t msg_only,              svn_test_opts_t *opts,              apr_pool_t *pool){  int i;  char *result;  static const char * const paths[][2] = {    { "abc", "abc" },    { "/abc", "abc" },    { "/abc", "abc" },    { "/x/abc", "abc" },    { "/xx/abc", "abc" },    { "/xx/abc", "abc" },    { "/xx/abc", "abc" },    { "a", "a" },    { "/a", "a" },    { "/b/a", "a" },    { "/b/a", "a" },    { "/", "/" },    { SVN_EMPTY_PATH, SVN_EMPTY_PATH }  };  *msg = "test svn_path_basename";  if (msg_only)    return SVN_NO_ERROR;  for (i = sizeof(paths) / sizeof(paths[0]); i--; )    {      const char *path = paths[i][0];      const char *expect = paths[i][1];      result = svn_path_basename(path, pool);      if (strcmp(result, expect))        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                 "svn_path_basename(\"%s\") returned "                                 "\"%s\". expected \"%s\"",                                 path, result, expect);    }  return SVN_NO_ERROR;}static svn_error_t *test_decompose(const char **msg,               svn_boolean_t msg_only,               svn_test_opts_t *opts,               apr_pool_t *pool){  static const char * const paths[] = {    "/", "/", NULL,    "foo", "foo", NULL,    "/foo", "/", "foo", NULL,    "/foo/bar", "/", "foo", "bar", NULL,    "foo/bar", "foo", "bar", NULL,    /* Are these canonical? Should the middle bits produce SVN_EMPTY_PATH? */    "foo/bar", "foo", "bar", NULL,    NULL,  };  int i = 0;  *msg = "test svn_path_decompose";  if (msg_only)    return SVN_NO_ERROR;  for (;;)    {      if (! paths[i])        break;      else        {          apr_array_header_t *components = svn_path_decompose(paths[i], pool);          int j;          for (j = 0; j < components->nelts; ++j)            {              const char *component = APR_ARRAY_IDX(components, j, const char*);              if (! paths[i+j+1])                return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                         "svn_path_decompose(\"%s\") returned "                                         "unexpected component \"%s\"",                                         paths[i], component);              if (strcmp(component, paths[i+j+1]))                 return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                         "svn_path_decompose(\"%s\") returned "                                         "\"%s\" expected \"%s\"",                                         paths[i], component, paths[i+j+1]);            }          if (paths[i+j+1])            return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                     "svn_path_decompose(\"%s\") failed "                                     "to return \"%s\"",                                     paths[i], paths[i+j+1]);          i += components->nelts + 2;        }    }  return SVN_NO_ERROR;}static svn_error_t *test_canonicalize(const char **msg,                  svn_boolean_t msg_only,                  svn_test_opts_t *opts,                  apr_pool_t *pool){  const char *paths[][2] = {    { "",                     "" },    { ".",                    "" },    { "/",                    "/" },    { "/.",                   "/" },    { "./",                   "" },    { "./.",                  "" },    { "//",                   "/" },    { "/////",                "/" },    { "./././.",              "" },    { "////././.",            "/" },    { "foo",                  "foo" },    { ".foo",                 ".foo" },    { "foo.",                 "foo." },    { "/foo",                 "/foo" },    { "foo/",                 "foo" },    { "foo./",                "foo." },    { "foo./.",               "foo." },    { "foo././/.",            "foo." },    { "/foo/bar",             "/foo/bar" },    { "foo/..",               "foo/.." },    { "foo/../",              "foo/.." },    { "foo/../.",             "foo/.." },    { "foo//.//bar",          "foo/bar" },    { "///foo",               "/foo" },    { "/.//./.foo",           "/.foo" },    { ".///.foo",             ".foo" },    { "../foo",               "../foo" },    { "../../foo/",           "../../foo" },    { "../../foo/..",         "../../foo/.." },    { "/../../",              "/../.." },    { "http://hst",           "http://hst" },    { "http://hst/foo/../bar","http://hst/foo/../bar" },    { "http://hst/",          "http://hst" },#if defined(WIN32) || defined(__CYGWIN__)    /* We permit UNC paths on Windows.  By definition UNC     * paths must have two components so we should remove the     * double slash if there is only one component. */    { "//hst/foo",            "//hst/foo" },    { "//hst",                "/hst" },    { "//hst/./",             "/hst" },#endif /* WIN32 or Cygwin */    { NULL, NULL }  };  int i;  *msg = "test svn_path_canonicalize";  if (msg_only)    return SVN_NO_ERROR;  i = 0;  while (paths[i][0])    {      const char *canonical = svn_path_canonicalize(paths[i][0], pool);      if (strcmp(canonical, paths[i][1]))        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                 "svn_path_canonicalize(\"%s\") returned "                                 "\"%s\" expected \"%s\"",                                 paths[i][0], canonical, paths[i][1]);      ++i;    }  return SVN_NO_ERROR;}static svn_error_t *test_remove_component(const char **msg,                      svn_boolean_t msg_only,                      svn_test_opts_t *opts,                      apr_pool_t *pool){  const char *paths[][2] = {    { "",                     "" },    { "/",                    "/" },    { "foo",                  "" },    { "foo/bar",              "foo" },    { "/foo/bar",             "/foo" },    { "/foo",                 "/" },    { NULL, NULL }  };  int i;  svn_stringbuf_t *buf;  *msg = "test svn_path_remove_component";  if (msg_only)    return SVN_NO_ERROR;  buf = svn_stringbuf_create("", pool);    i = 0;  while (paths[i][0])    {      svn_stringbuf_set(buf, paths[i][0]);      svn_path_remove_component(buf);            if (strcmp(buf->data, paths[i][1]))        return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,                                 "svn_path_remove_component(\"%s\") returned "                                 "\"%s\" expected \"%s\"",                                 paths[i][0], buf->data, paths[i][1]);      ++i;    }  return SVN_NO_ERROR;}/* The test table.  */struct svn_test_descriptor_t test_funcs[] =  {    SVN_TEST_NULL,    SVN_TEST_PASS(test_path_is_child),    SVN_TEST_PASS(test_path_split),    SVN_TEST_PASS(test_is_url),    SVN_TEST_PASS(test_is_uri_safe),    SVN_TEST_PASS(test_uri_encode),    SVN_TEST_PASS(test_uri_decode),    SVN_TEST_PASS(test_uri_autoescape),    SVN_TEST_PASS(test_uri_from_iri),    SVN_TEST_PASS(test_join),    SVN_TEST_PASS(test_basename),    SVN_TEST_PASS(test_decompose),    SVN_TEST_PASS(test_canonicalize),    SVN_TEST_PASS(test_remove_component),    SVN_TEST_NULL  };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -