anode-utils-test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009-2010 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include "../anode.h"
  19. #include "../misc.h"
  20. static const char *testuris[22] = {
  21. "http://www.test.com",
  22. "http://www.test.com/",
  23. "http://www.test.com/path/to/something",
  24. "http://[email protected]",
  25. "http://[email protected]/path/to/something",
  26. "http://user:[email protected]/path/to/something",
  27. "http://www.test.com/path/to/something?query=foo&bar=baz",
  28. "http://www.test.com/path/to/something#fragment",
  29. "http://www.test.com/path/to/something?query=foo&bar=baz#fragment",
  30. "http://user:[email protected]/path/to/something#fragment",
  31. "http://user:[email protected]/path/to/something?query=foo&bar=baz#fragment",
  32. "http://@www.test.com/",
  33. "http://:@www.test.com/",
  34. "http://www.test.com:8080/path/to/something",
  35. "http://user:[email protected]:8080/path/to/something?query=foo#fragment",
  36. "http://",
  37. "http://www.test.com/path/to/something?#",
  38. "http://www.test.com/path/to/something?#fragment",
  39. "http:",
  40. "http",
  41. "mailto:[email protected]",
  42. ""
  43. };
  44. int main(int argc,char **argv)
  45. {
  46. int i,r;
  47. char reconstbuf[2048];
  48. char *reconst;
  49. AnodeURI uri;
  50. for(i=0;i<22;++i) {
  51. printf("\"%s\":\n",testuris[i]);
  52. r = AnodeURI_parse(&uri,testuris[i]);
  53. if (r) {
  54. printf(" error: %d\n",r);
  55. } else {
  56. printf(" scheme: %s\n",uri.scheme);
  57. printf(" username: %s\n",uri.username);
  58. printf(" password: %s\n",uri.password);
  59. printf(" host: %s\n",uri.host);
  60. printf(" port: %d\n",uri.port);
  61. printf(" path: %s\n",uri.path);
  62. printf(" query: %s\n",uri.query);
  63. printf(" fragment: %s\n",uri.fragment);
  64. }
  65. reconst = AnodeURI_to_string(&uri,reconstbuf,sizeof(reconstbuf));
  66. printf("Reconstituted URI: %s\n",reconst ? reconst : "(null)");
  67. printf("\n");
  68. }
  69. return 0;
  70. }