诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
3.0 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curlcheck.h"
  23. static CURLcode unit_setup(void)
  24. {
  25. return CURLE_OK;
  26. }
  27. static void unit_stop(void)
  28. {
  29. }
  30. struct test {
  31. const char *in;
  32. int inlen;
  33. const char *out;
  34. int outlen;
  35. };
  36. UNITTEST_START
  37. {
  38. /* unescape, this => that */
  39. struct test list1[]={
  40. {"%61", 3, "a", 1},
  41. {"%61a", 4, "aa", 2},
  42. {"%61b", 4, "ab", 2},
  43. {"%6 1", 4, "%6 1", 4},
  44. {"%61", 1, "%", 1},
  45. {"%61", 2, "%6", 2},
  46. {"%6%a", 4, "%6%a", 4},
  47. {"%6a", 0, "j", 1},
  48. {"%FF", 0, "\xff", 1},
  49. {"%FF%00%ff", 9, "\xff\x00\xff", 3},
  50. {"%-2", 0, "%-2", 3},
  51. {"%FG", 0, "%FG", 3},
  52. {NULL, 0, NULL, 0} /* end of list marker */
  53. };
  54. /* escape, this => that */
  55. struct test list2[]={
  56. {"a", 1, "a", 1},
  57. {"/", 1, "%2F", 3},
  58. {"a=b", 3, "a%3Db", 5},
  59. {"a=b", 0, "a%3Db", 5},
  60. {"a=b", 1, "a", 1},
  61. {"a=b", 2, "a%3D", 4},
  62. {"1/./0", 5, "1%2F.%2F0", 9},
  63. {"-._~!#%&", 0, "-._~%21%23%25%26", 16},
  64. {"a", 2, "a%00", 4},
  65. {"a\xff\x01g", 4, "a%FF%01g", 8},
  66. {NULL, 0, NULL, 0} /* end of list marker */
  67. };
  68. int i;
  69. CURL *hnd;
  70. hnd = curl_easy_init();
  71. for(i=0; list1[i].in; i++) {
  72. int outlen;
  73. char *out = curl_easy_unescape(hnd,
  74. list1[i].in, list1[i].inlen,
  75. &outlen);
  76. fail_unless(out != NULL, "returned NULL!");
  77. fail_unless(outlen == list1[i].outlen, "wrong output length returned");
  78. fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
  79. "bad output data returned");
  80. printf("curl_easy_unescape test %d DONE\n", i);
  81. curl_free(out);
  82. }
  83. for(i=0; list2[i].in; i++) {
  84. char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
  85. int outlen = (int)strlen(out);
  86. fail_unless(out != NULL, "returned NULL!");
  87. fail_unless(outlen == list2[i].outlen, "wrong output length returned");
  88. fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
  89. "bad output data returned");
  90. printf("curl_easy_escape test %d DONE (%s)\n", i, out);
  91. curl_free(out);
  92. }
  93. curl_easy_cleanup(hnd);
  94. }
  95. UNITTEST_STOP