remotetests.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*##############################################################################
  2. Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifdef _USE_CPPUNIT
  14. #include "unittests.hpp"
  15. #ifdef _USE_URIPARSER
  16. // =============================================================== URI parser
  17. #include "uri.hpp"
  18. class URITests : public CppUnit::TestFixture
  19. {
  20. CPPUNIT_TEST_SUITE( URITests );
  21. CPPUNIT_TEST(testURIError);
  22. CPPUNIT_TEST(testURIUnknwon);
  23. CPPUNIT_TEST(testURILocal);
  24. CPPUNIT_TEST(testURIDali);
  25. CPPUNIT_TEST_SUITE_END();
  26. const IContextLogger &logctx;
  27. void test_uri(const char * str, bool shouldBeURI, URISchemeType scheme=URIScheme_error, const char * server=NULL, const char * path=NULL)
  28. {
  29. bool isURI = URI::isURI(str);
  30. ASSERT(isURI == shouldBeURI);
  31. if (!isURI)
  32. return;
  33. // Now, validate URI
  34. try
  35. {
  36. URI res(str);
  37. ASSERT(res.getScheme() == scheme);
  38. // No need to validate the rest
  39. if (scheme == URIScheme_error)
  40. return;
  41. StringBuffer response;
  42. res.appendServerStr(response);
  43. ASSERT(strcmp(response.str(), server) == 0);
  44. response.clear();
  45. res.appendPathStr(response);
  46. ASSERT(strcmp(response.str(), path) == 0);
  47. }
  48. catch (IException *e)
  49. {
  50. StringBuffer buf;
  51. logctx.CTXLOG("Exception: %s", e->errorMessage(buf).str());
  52. e->Release();
  53. ASSERT(false); // Check exception log
  54. }
  55. }
  56. public:
  57. URITests() : logctx(queryDummyContextLogger()) {}
  58. void testURIError() {
  59. test_uri("You, shall not, pass!", false);
  60. test_uri("http://almost there...", false);
  61. }
  62. void testURIUnknwon() {
  63. test_uri("ftp://www.hpccsystems.com/", true);
  64. test_uri("gopher://www.hpccsystems.com/", true);
  65. test_uri("https://www.hpccsystems.com:443/", true);
  66. test_uri("http://user:passwd@www.hpccsystems.com:8080/my/path?is=full#of-stuff", true);
  67. }
  68. void testURILocal() {
  69. test_uri("file:///opt/HPCCSystems/examples/IMDB/ActorsInMovies.ecl", true, URIScheme_file, "", "/opt/HPCCSystems/examples/IMDB/ActorsInMovies.ecl");
  70. }
  71. void testURIDali() {
  72. // Dali file types
  73. test_uri("hpcc://mydali/path/to/file", true, URIScheme_hpcc, "mydali", "path/to/file");
  74. test_uri("hpcc://mydali/path/to/superfile?super", true, URIScheme_hpcc, "mydali", "path/to/superfile?super");
  75. test_uri("hpcc://mydali/path/to/superfile?super#subname", true, URIScheme_hpcc, "mydali", "path/to/superfile?super#subname");
  76. test_uri("hpcc://mydali/path/to/streamfile?stream", true, URIScheme_hpcc, "mydali", "path/to/streamfile?stream");
  77. test_uri("hpcc://mydali/path/to/streamfile?stream#047", true, URIScheme_hpcc, "mydali", "path/to/streamfile?stream#47");
  78. // Variations in Dali location
  79. test_uri("hpcc://mydali:7070/path/to/file", true, URIScheme_hpcc, "mydali:7070", "path/to/file");
  80. test_uri("hpcc://user@mydali:7070/path/to/file", true, URIScheme_hpcc, "user@mydali:7070", "path/to/file");
  81. test_uri("hpcc://user@mydali/path/to/file", true, URIScheme_hpcc, "user@mydali", "path/to/file");
  82. test_uri("hpcc://user:passwd@mydali:7070/path/to/file", true, URIScheme_hpcc, "user:passwd@mydali:7070", "path/to/file");
  83. test_uri("hpcc://user:passwd@mydali/path/to/file", true, URIScheme_hpcc, "user:passwd@mydali", "path/to/file");
  84. }
  85. };
  86. CPPUNIT_TEST_SUITE_REGISTRATION( URITests );
  87. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URITests, "URI" );
  88. #endif // _USE_URIPARSER
  89. #endif // _USE_CPPUNIT