remotetests.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*##############################################################################
  2. Copyright (C) 2012 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifdef _USE_CPPUNIT
  15. #include "jlib.hpp"
  16. #include "jlog.hpp"
  17. #include "uri.hpp"
  18. #include <cppunit/extensions/TestFactoryRegistry.h>
  19. #include <cppunit/ui/text/TestRunner.h>
  20. #include <cppunit/extensions/HelperMacros.h>
  21. // CPPUNIT_ASSERT is too slow, even when not matching failure
  22. #define ASSERT(a) { if (!(a)) CPPUNIT_ASSERT(a); }
  23. // =============================================================== jURI - URI parser
  24. class URITests : public CppUnit::TestFixture
  25. {
  26. CPPUNIT_TEST_SUITE( URITests );
  27. CPPUNIT_TEST(testURIError);
  28. CPPUNIT_TEST(testURIUnknwon);
  29. CPPUNIT_TEST(testURILocal);
  30. CPPUNIT_TEST(testURIDali);
  31. CPPUNIT_TEST_SUITE_END();
  32. const IContextLogger &logctx;
  33. void test_uri(const char * str, bool shouldBeURI, URISchemeType scheme=URIScheme_error, const char * server=NULL, const char * path=NULL)
  34. {
  35. bool isURI = URI::isURI(str);
  36. ASSERT(isURI == shouldBeURI);
  37. if (!isURI)
  38. return;
  39. // Now, validate URI
  40. try
  41. {
  42. URI res(str);
  43. ASSERT(res.getScheme() == scheme);
  44. // No need to validate the rest
  45. if (scheme == URIScheme_error)
  46. return;
  47. StringBuffer response;
  48. res.appendServerStr(response);
  49. ASSERT(strcmp(response.str(), server) == 0);
  50. response.clear();
  51. res.appendPathStr(response);
  52. ASSERT(strcmp(response.str(), path) == 0);
  53. }
  54. catch (IException *e)
  55. {
  56. StringBuffer buf;
  57. logctx.CTXLOG("Exception: %s", e->errorMessage(buf).str());
  58. e->Release();
  59. ASSERT(false); // Check exception log
  60. }
  61. }
  62. public:
  63. URITests() : logctx(queryDummyContextLogger()) {}
  64. void testURIError() {
  65. test_uri("You, shall not, pass!", false);
  66. test_uri("http://almost there...", false);
  67. }
  68. void testURIUnknwon() {
  69. test_uri("ftp://www.hpccsystems.com/", true);
  70. test_uri("gopher://www.hpccsystems.com/", true);
  71. test_uri("https://www.hpccsystems.com:443/", true);
  72. test_uri("http://user:passwd@www.hpccsystems.com:8080/my/path?is=full#of-stuff", true);
  73. }
  74. void testURILocal() {
  75. test_uri("file:///opt/HPCCSystems/examples/IMDB/ActorsInMovies.ecl", true, URIScheme_file, "", "/opt/HPCCSystems/examples/IMDB/ActorsInMovies.ecl");
  76. }
  77. void testURIDali() {
  78. // Dali file types
  79. test_uri("hpcc://mydali/path/to/file", true, URIScheme_hpcc, "mydali", "path/to/file");
  80. test_uri("hpcc://mydali/path/to/superfile?super", true, URIScheme_hpcc, "mydali", "path/to/superfile?super");
  81. test_uri("hpcc://mydali/path/to/superfile?super#subname", true, URIScheme_hpcc, "mydali", "path/to/superfile?super#subname");
  82. test_uri("hpcc://mydali/path/to/streamfile?stream", true, URIScheme_hpcc, "mydali", "path/to/streamfile?stream");
  83. test_uri("hpcc://mydali/path/to/streamfile?stream#047", true, URIScheme_hpcc, "mydali", "path/to/streamfile?stream#47");
  84. // Variations in Dali location
  85. test_uri("hpcc://mydali:7070/path/to/file", true, URIScheme_hpcc, "mydali:7070", "path/to/file");
  86. test_uri("hpcc://user@mydali:7070/path/to/file", true, URIScheme_hpcc, "user@mydali:7070", "path/to/file");
  87. test_uri("hpcc://user@mydali/path/to/file", true, URIScheme_hpcc, "user@mydali", "path/to/file");
  88. test_uri("hpcc://user:passwd@mydali:7070/path/to/file", true, URIScheme_hpcc, "user:passwd@mydali:7070", "path/to/file");
  89. test_uri("hpcc://user:passwd@mydali/path/to/file", true, URIScheme_hpcc, "user:passwd@mydali", "path/to/file");
  90. }
  91. };
  92. CPPUNIT_TEST_SUITE_REGISTRATION( URITests );
  93. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URITests, "URITests" );
  94. #endif // _USE_CPPUNIT