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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory>
  4. #include <string>
  5. #include "../../src/URL.h"
  6. void test_parser(std::string url, std::string scheme, std::string userinfo,
  7. std::string host, int port, std::string path, std::string query, std::string fragment) {
  8. //std::unique_ptr<URL>
  9. std::tuple<std::unique_ptr<URL>,enum URIParseError> result = parseUri(url);
  10. if (std::get<1>(result) != URI_PARSE_ERROR_NONE) {
  11. // TODO We probably wanna handle this better..
  12. std::cerr << "error parsing uri" << std::endl;
  13. return;
  14. }
  15. std::unique_ptr<URL> uri = std::move(std::get<0>(result));
  16. if (uri->scheme == scheme && uri->userinfo == userinfo &&
  17. uri->host == host && uri->port == port &&
  18. uri->path == path && uri->query == query && uri->fragment == fragment) {
  19. std::cout << "noice" << std::endl;
  20. } else {
  21. std::cout << "nope" << std::endl;
  22. std::cout << uri->scheme << " vs " << scheme << std::endl;
  23. std::cout << uri->userinfo << " vs " << userinfo << std::endl;
  24. std::cout << uri->host << " vs " << host << std::endl;
  25. std::cout << uri->port << " vs " << port << std::endl;
  26. std::cout << uri->path << " vs " << path << std::endl;
  27. std::cout << uri->query << " vs " << query << std::endl;
  28. std::cout << uri->fragment << " vs " << fragment << std::endl;
  29. }
  30. }
  31. int main(void) {
  32. test_parser("HTTP://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", "");
  33. test_parser("http://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", "");
  34. test_parser("http://www.example.org:8080/", "http", "", "www.example.org", 8080, "/", "", "");
  35. test_parser("http://www.example.org/", "http", "", "www.example.org", 80, "/", "", "");
  36. test_parser("http://www.example.org", "http", "", "www.example.org", 80, "/", "", "");
  37. //test_parser("http://www.example.org//", "http", "", "www.example.org", 80, "/", "", "");
  38. test_parser("http://www.example.org/this/path", "http", "", "www.example.org", 80, "/this/path", "", "");
  39. test_parser("http://www.example.org:/this/path", "http", "", "www.example.org", 80, "/this/path", "", "");
  40. test_parser("http://username:password@www.example.org:/this/path", "http", "username:password", "www.example.org", 80, "/this/path", "", "");
  41. test_parser("http://username:password@www.example.org/", "http", "username:password", "www.example.org", 80, "/", "", "");
  42. test_parser("http://username:passwor:d@www.example.org/", "http", "username:passwor:d", "www.example.org", 80, "/", "", "");
  43. test_parser("http://username:passwor:d@www.example.org:9090/", "http", "username:passwor:d", "www.example.org", 9090, "/", "", "");
  44. test_parser("http://username:passwor:d@www.example.org:9090/this/path?query", "http", "username:passwor:d", "www.example.org", 9090, "/this/path", "query", "");
  45. test_parser("http://www.example.org:9090/this/path?query", "http", "", "www.example.org", 9090, "/this/path", "query", "");
  46. test_parser("http://www.example.org/this/path?query", "http", "", "www.example.org", 80, "/this/path", "query", "");
  47. test_parser("http://www.example.org?query", "http", "", "www.example.org", 80, "/", "query", "");
  48. }