00001 #ifndef hpp_ValidationTests_hpp
00002 #define hpp_ValidationTests_hpp
00003
00004
00005 #include "../Network/URLHandler.hpp"
00006
00007 #include "TestVectors.hpp"
00008
00009
00010 namespace Tests
00011 {
00012 struct ValidationTest
00013 {
00015 bool testURLValidation()
00016 {
00017 Network::URL url("http://www.google.fr/some/path/to/index.html");
00018 Network::URL url2("http://www.google.fr/index.html");
00019 if (url.getScheme() != "http") return false;
00020 if (url.getAuthority() != "www.google.fr") return false;
00021 if (url.getPath() != "/some/path/to/index.html") return false;
00022 if ((url2 = url.appendRelativePath("image/directory")).getPath() != "/some/path/to/image/directory/") return false;
00023 url = url2;
00024 if ((url2 = url.appendRelativePath("../")).getPath() != "/some/path/to/image/") return false;
00025 url = url2;
00026 if ((url2 = url.appendRelativePath("../../../../../hiddenStuff.htm")).getPath() != "/hiddenStuff.htm") return false;
00027 url = url2;
00028 if ((url2 = url.appendRelativePath("/some/image.htm")).getPath() != "/some/image.htm") return false;
00029 url = url2;
00030 if ((url2 = url.appendRelativePath("image.jpg")).getPath() != "/some/image.jpg") return false;
00031 url = url2;
00032 if ((url2 = url.appendRelativePath("../index.html")).getPath() != "/index.html") return false;
00033 url = url2;
00034 if (url2.appendRelativePath("/a/b/c/./../../g").getPath() != "/a/g") return false;
00035 if (url.appendRelativePath("/./index.html").getPath() != "/index.html") return false;
00036
00037
00038 return true;
00039 }
00040 };
00041
00042 void createValidationTests(Test::Vector & xVector, Bstrlib::String & results)
00043 {
00044 typedef Bstrlib::String String;
00045 xVector.addUnitToTest(Test::MakeLineDelimiter("Network object validation testing"));
00046 {
00047 ValidationTest xVT;
00048 xVector.addUnitToTest(Test::MakeUnitTest(MakeTestName( "Test URL handler" ), xVT, &ValidationTest::testURLValidation));
00049 xVector.testLastInsertedVectors(results);
00050 }
00051 }
00052 }
00053
00054
00055 #endif
00056