TDE core libraries
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.
 
 
 
 
 
 

1125 lines
55 KiB

  1. #include <config.h>
  2. #include <kurl.h>
  3. #include <stdio.h>
  4. #include <kapplication.h>
  5. #include <stdlib.h>
  6. #include <kdebug.h>
  7. #include <kglobal.h>
  8. #include <kcharsets.h>
  9. #include <tqtextcodec.h>
  10. #include <tqdatastream.h>
  11. #include <assert.h>
  12. #include <kcmdlineargs.h>
  13. static bool check(TQString txt, TQString a, TQString b)
  14. {
  15. if (a.isEmpty())
  16. a = TQString::null;
  17. if (b.isEmpty())
  18. b = TQString::null;
  19. if (a == b) {
  20. kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
  21. }
  22. else {
  23. kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
  24. exit(1);
  25. }
  26. return true;
  27. }
  28. void testAdjustPath()
  29. {
  30. KURL url1("file:///home/kde/");
  31. url1.adjustPath(0);
  32. check( "adjustPath(0)", url1.path(), "/home/kde/" );
  33. url1.adjustPath(-1);
  34. check( "adjustPath(-1) removes last slash", url1.path(), "/home/kde" );
  35. url1.adjustPath(-1);
  36. check( "adjustPath(-1) again", url1.path(), "/home/kde" );
  37. url1.adjustPath(1);
  38. check( "adjustPath(1)", url1.path(), "/home/kde/" );
  39. KURL url2("file:///home/kde//");
  40. url2.adjustPath(0);
  41. check( "adjustPath(0)", url2.path(), "/home/kde//" );
  42. url2.adjustPath(-1);
  43. check( "adjustPath(-1) removes all trailing slashes", url2.path(), "/home/kde" );
  44. url2.adjustPath(1);
  45. check( "adjustPath(1)", url2.path(), "/home/kde/" );
  46. KURL ftpurl1("ftp://ftp.kde.org/");
  47. ftpurl1.adjustPath(0);
  48. check( "adjustPath(0)", ftpurl1.path(), "/" );
  49. ftpurl1.adjustPath(-1);
  50. check( "adjustPath(-1) preserves last slash", ftpurl1.path(), "/" );
  51. KURL ftpurl2("ftp://ftp.kde.org///");
  52. ftpurl2.adjustPath(0);
  53. check( "adjustPath(0)", ftpurl2.path(), "///" );
  54. ftpurl2.adjustPath(-1);
  55. check( "adjustPath(-1) removes all but last slash", ftpurl2.path(), "/" );
  56. ftpurl2.adjustPath(1);
  57. check( "adjustPath(1)", ftpurl2.path(), "/" );
  58. // Equivalent tests written by the KDirLister maintainer :)
  59. KURL u3( TQCString("ftp://brade@ftp.kde.org///") );
  60. u3.adjustPath(-1);
  61. check("KURL::adjustPath()", u3.url(), "ftp://brade@ftp.kde.org/");
  62. KURL u4( TQCString("ftp://brade@ftp.kde.org/kde///") );
  63. u4.adjustPath(-1);
  64. check("KURL::adjustPath()", u4.url(), "ftp://brade@ftp.kde.org/kde");
  65. // applying adjustPath(-1) twice should not yield two different urls
  66. // (follows from the above test)
  67. KURL u5 = u4;
  68. u5.adjustPath(-1);
  69. check("KURL::adjustPath()", u5.url(), u4.url());
  70. }
  71. int main(int argc, char *argv[])
  72. {
  73. KApplication::disableAutoDcopRegistration();
  74. KCmdLineArgs::init( argc, argv, "kurltest", 0, 0, 0, 0 );
  75. KApplication app( false, false );
  76. KURL::List lst;
  77. KURL emptyURL;
  78. check( "KURL::isMalformed()", emptyURL.isMalformed() ? "TRUE":"FALSE", "TRUE");
  79. check( "KURL::isValid()", emptyURL.isValid() ? "TRUE":"FALSE", "FALSE");
  80. check( "KURL::isEmpty()", emptyURL.isEmpty() ? "TRUE":"FALSE", "TRUE");
  81. check( "prettyURL()", emptyURL.prettyURL(), "");
  82. check( "isLocalFile()", emptyURL.isLocalFile()?"TRUE":"FALSE", "FALSE" );
  83. emptyURL = "";
  84. check( "KURL::isMalformed()", emptyURL.isMalformed() ? "TRUE":"FALSE", "TRUE");
  85. check( "KURL::isValid()", emptyURL.isValid() ? "TRUE":"FALSE", "FALSE");
  86. check( "KURL::isEmpty()", emptyURL.isEmpty() ? "TRUE":"FALSE", "TRUE");
  87. KURL fileURL = "file:/";
  88. check( "KURL::isEmpty()", fileURL.isEmpty() ? "TRUE":"FALSE", "FALSE");
  89. fileURL = "file:///";
  90. check( "KURL::isEmpty()", fileURL.isEmpty() ? "TRUE":"FALSE", "FALSE");
  91. KURL baseURL ("hTTp://www.foo.bar:80" );
  92. check( "KURL::isValid()", baseURL.isValid() ? "TRUE":"FALSE", "TRUE");
  93. check( "KURL::protocol()", baseURL.protocol(), "http"); // lowercase
  94. KURL url1 ( baseURL, "//www1.foo.bar" );
  95. check( "KURL::host()", url1.host(), "www1.foo.bar");
  96. check( "KURL::url()", url1.url(), "http://www1.foo.bar");
  97. baseURL = "http://www.Abc.de";
  98. check( "KURL::host() is lowercase", baseURL.host(), "www.abc.de");
  99. baseURL = "donkey://Abc/DE";
  100. check( "KURL::host() is lowercase", baseURL.host(), "abc");
  101. baseURL = "http://www.foo.bar";
  102. KURL rel_url( baseURL, "/top//test/../test1/file.html" );
  103. check( "KURL::url()", rel_url.url(), "http://www.foo.bar/top//test1/file.html" );
  104. baseURL = "http://www.foo.bar/top//test2/file2.html";
  105. check( "KURL::url()", baseURL.url(), "http://www.foo.bar/top//test2/file2.html" );
  106. baseURL = "file:/usr/local/src/kde2/////tdelibs/kio";
  107. check( "KURL::url()", baseURL.url(), "file:///usr/local/src/kde2/////tdelibs/kio" );
  108. baseURL = "http://www.foo.bar";
  109. KURL rel_url2( baseURL, "mailto:bastian@kde.org" );
  110. check( "KURL::url()", rel_url2.url(), "mailto:bastian@kde.org" );
  111. baseURL = "mailto:bastian@kde.org?subject=hello";
  112. check( "KURL::url()", baseURL.url(), "mailto:bastian@kde.org?subject=hello" );
  113. baseURL = "file:/usr/local/src/kde2/tdelibs/kio/";
  114. KURL url2( baseURL, "../../////tdebase/konqueror" );
  115. check( "KURL::url()", url2.url(), "file:///usr/local/src/kde2/////tdebase/konqueror" );
  116. TQString u1 = "file:/home/dfaure/my#myref";
  117. url1 = u1;
  118. check("KURL::url()", url1.url(), "file:///home/dfaure/my#myref");
  119. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  120. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  121. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  122. check("KURL::htmlRef()", url1.htmlRef(), "myref");
  123. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
  124. u1 = "file:/home/dfaure/my#%2f";
  125. url1 = u1;
  126. check("KURL::url()", url1.url(), "file:///home/dfaure/my#%2f");
  127. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  128. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  129. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  130. check("KURL::encodedHtmlRef()", url1.ref(), "%2f");
  131. check("KURL::htmlRef()", url1.htmlRef(), "/");
  132. url1 = KURL(url1, "#%6a");
  133. check("KURL::url()", url1.url(), "file:///home/dfaure/my#%6a");
  134. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  135. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  136. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  137. check("KURL::encodedHtmlRef()", url1.ref(), "%6a");
  138. check("KURL::htmlRef()", url1.htmlRef(), "j");
  139. KURL dxOffEagle( KURL("http://something/other.html"), "newpage.html?[{\"foo: bar\"}]" );
  140. check("isValid", dxOffEagle.isValid() ? "OK" : "KO", "OK");
  141. check("url", dxOffEagle.url(), TQString("http://something/newpage.html?[{\"foo:%20bar\"}]") );
  142. KURL javascript( KURL("javascript:window.location+\"__flashplugin_unique__\"") );
  143. check("isValid", javascript.isValid() ? "OK" : "KO", "OK");
  144. check("url", javascript.url(), TQString("javascript:window.location+\"__flashplugin_unique__\"") );
  145. u1 = "file:///home/dfaure/my#myref";
  146. url1 = u1;
  147. check("KURL::url()", url1.url(), "file:///home/dfaure/my#myref");
  148. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  149. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  150. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  151. check("KURL::htmlRef()", url1.htmlRef(), "myref");
  152. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
  153. url1 = "gg:www.kde.org";
  154. check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "TRUE" );
  155. url1= "KDE";
  156. check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "FALSE" );
  157. url1= "$HOME/.trinity/share/config";
  158. check("KURL::isValid()", url1.isValid()?"TRUE":"FALSE", "FALSE" );
  159. u1 = "file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect";
  160. url1 = u1;
  161. check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect");
  162. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  163. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  164. check("KURL::htmlRef()", url1.htmlRef(), "TQObject::connect");
  165. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  166. check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
  167. url1 = KURL( TQCString( "http://www.kde.org/foo.cgi?foo=bar" ) );
  168. check("query", url1.query(), "?foo=bar" );
  169. url1.setQuery( "toto=titi&kde=rocks" );
  170. check("query", url1.query(), "?toto=titi&kde=rocks" );
  171. url1.setQuery( "?kde=rocks&a=b" );
  172. check("query", url1.query(), "?kde=rocks&a=b" );
  173. url1.setQuery( "?" );
  174. check("setQuery(\"?\") -> query", url1.query(), "?" );
  175. url1.setQuery( "" );
  176. check("setQuery(\"\") -> query", url1.query(), "?" );
  177. url1.setQuery( TQString::null );
  178. check("setQuery(TQString::null) -> query", url1.query(), TQString::null );
  179. u1 = "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect";
  180. url1 = u1;
  181. check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject::connect");
  182. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  183. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  184. check("KURL::htmlRef()", url1.htmlRef(), "TQObject::connect");
  185. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  186. check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
  187. u1 = "file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject:connect";
  188. url1 = u1;
  189. check("KURL::url()", url1.url(), "file:///opt/kde2/qt2/doc/html/showimg-main-cpp.html#TQObject:connect");
  190. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  191. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  192. check("KURL::htmlRef()", url1.htmlRef(), "TQObject:connect");
  193. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "no");
  194. check("KURL::upURL()", url1.upURL().url(), "file:///opt/kde2/qt2/doc/html/");
  195. u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/#myref";
  196. url1 = u1;
  197. check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/#myref");
  198. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  199. check("KURL::isLocalFile()", url1.isLocalFile() ? "yes" : "no", "no"); // Not strictly local!
  200. //check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "yes");
  201. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  202. //check("KURL::htmlRef()", url1.htmlRef(), "myref");
  203. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
  204. u1 = "error:/?error=14&errText=Unknown%20host%20asdfu.adgi.sdfgoi#http://asdfu.adgi.sdfgoi";
  205. url1 = u1;
  206. check("KURL::url()", url1.url(), "error:/?error=14&errText=Unknown%20host%20asdfu.adgi.sdfgoi#http://asdfu.adgi.sdfgoi");
  207. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  208. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  209. check("KURL::isLocalFile()", url1.isLocalFile() ? "yes" : "no", "no");
  210. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
  211. //check("KURL::htmlRef()", url1.htmlRef(), "myref");
  212. u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/";
  213. url1 = u1;
  214. check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
  215. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  216. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
  217. check("KURL::htmlRef()", url1.htmlRef(), "");
  218. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  219. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
  220. u1 = "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/";
  221. url1 = u1;
  222. check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
  223. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  224. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
  225. check("KURL::htmlRef()", url1.htmlRef(), "");
  226. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  227. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/");
  228. #if 0
  229. // This URL is broken, '#' should be escaped.
  230. u1 = "file:/home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#";
  231. url1 = u1;
  232. check("KURL::url()", url1.url(), "file:///home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#");
  233. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "no");
  234. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
  235. check("KURL::htmlRef()", url1.htmlRef(), "");
  236. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  237. check("KURL::prettyURL()", url1.upURL().url(), "file:///home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#");
  238. #endif
  239. u1 = "file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/README";
  240. url1 = u1;
  241. check("KURL::url()", url1.url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/README");
  242. check("KURL::hasRef()", url1.hasRef() ? "yes" : "no", "yes");
  243. check("KURL::hasHTMLRef()", url1.hasHTMLRef() ? "yes" : "no", "no");
  244. check("KURL::htmlRef()", url1.htmlRef(), "");
  245. check("KURL::hasSubURL()", url1.hasSubURL() ? "yes" : "no", "yes");
  246. check("KURL::upURL()", url1.upURL().url(), "file:///home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/");
  247. KURL notPretty("http://ferret.lmh.ox.ac.uk/%7Ekdecvs/");
  248. check("KURL::prettyURL()", notPretty.prettyURL(), "http://ferret.lmh.ox.ac.uk/~kdecvs/");
  249. KURL notPretty2("file:/home/test/directory%20with%20spaces");
  250. check("KURL::prettyURL()", notPretty2.prettyURL(), "file:///home/test/directory with spaces");
  251. KURL notPretty3("fish://foo/%23README%23");
  252. check("KURL::prettyURL()", notPretty3.prettyURL(), "fish://foo/%23README%23");
  253. KURL url15581("http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html");
  254. check("KURL::prettyURL()", url15581.prettyURL(), "http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html");
  255. check("KURL::url()", url15581.url(), "http://alain.knaff.linux.lu/bug-reports/kde/spaces%20in%20url.html");
  256. KURL url15582("http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html");
  257. check("KURL::prettyURL()", url15582.prettyURL(), "http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html");
  258. check("KURL::url()", url15582.url(), "http://alain.knaff.linux.lu/bug-reports/kde/percentage%25in%25url.html");
  259. KURL longUserName("http://thisisaverylongusername@foobar.com/");
  260. check("KURL::prettyURL()", longUserName.prettyURL(), "http://thisisaverylongusername@foobar.com/");
  261. check("KURL(KURL::prettyURL())", KURL(longUserName.prettyURL()).url(), "http://thisisaverylongusername@foobar.com/");
  262. KURL whitespaceInUser("http://google.com%20%20%20@foobar.com/");
  263. check("KURL::prettyURL()", whitespaceInUser.prettyURL(), "http://google.com%20%20%20@foobar.com/");
  264. KURL whitespaceInPath("http://www.google.com/foo%20bar/");
  265. check("KURL::prettyURL()", whitespaceInPath.prettyURL(), "http://www.google.com/foo bar/");
  266. KURL whitespaceInPath2("http://www.google.com/foo%20%20%20%20%20%20%20bar/");
  267. check("KURL::prettyURL()", whitespaceInPath2.prettyURL(),
  268. "http://www.google.com/foo%20%20%20%20%20%20 bar/");
  269. KURL carsten;
  270. carsten.setPath("/home/gis/src/kde/tdelibs/kfile/.#kfiledetailview.cpp.1.18");
  271. check("KURL::path()", carsten.path(), "/home/gis/src/kde/tdelibs/kfile/.#kfiledetailview.cpp.1.18");
  272. KURL charles;
  273. charles.setPath( "/home/charles/foo%20moo" );
  274. check("KURL::path()", charles.path(), "/home/charles/foo%20moo");
  275. KURL charles2("file:/home/charles/foo%20moo");
  276. check("KURL::path()", charles2.path(), "/home/charles/foo moo");
  277. KURL udir;
  278. printf("\n* Empty URL\n");
  279. check("KURL::url()", udir.url(), TQString::null);
  280. check("KURL::isEmpty()", udir.isEmpty() ? "ok" : "ko", "ok");
  281. check("KURL::isValid()", udir.isValid() ? "ok" : "ko", "ko");
  282. udir = udir.upURL();
  283. check("KURL::upURL()", udir.upURL().isEmpty() ? "ok" : "ko", "ok");
  284. udir.setPath("/home/dfaure/file.txt");
  285. printf("\n* URL is %s\n",udir.url().ascii());
  286. check("KURL::path()", udir.path(), "/home/dfaure/file.txt");
  287. check("KURL::url()", udir.url(), "file:///home/dfaure/file.txt");
  288. check("KURL::directory(false,false)", udir.directory(false,false), "/home/dfaure/");
  289. check("KURL::directory(true,false)", udir.directory(true,false), "/home/dfaure");
  290. KURL u2( TQCString("/home/dfaure/") );
  291. printf("\n* URL is %s\n",u2.url().ascii());
  292. // not ignoring trailing slash
  293. check("KURL::directory(false,false)", u2.directory(false,false), "/home/dfaure/");
  294. check("KURL::directory(true,false)", u2.directory(true,false), "/home/dfaure");
  295. // ignoring trailing slash
  296. check("KURL::directory(false,true)", u2.directory(false,true), "/home/");
  297. check("KURL::directory(true,true)", u2.directory(true,true), "/home");
  298. // cleanPath() tests (before cd() since cd uses that)
  299. u2.cleanPath();
  300. check("cleanPath(false)", u2.url(), "file:///home/dfaure/");
  301. u2.addPath( "/..//foo" );
  302. check("addPath", u2.url(), "file:///home/dfaure/..//foo");
  303. u2.cleanPath(false);
  304. check("cleanPath()", u2.url(), "file:///home//foo");
  305. u2.cleanPath(true);
  306. check("cleanPath()", u2.url(), "file:///home/foo");
  307. u2.cd("..");
  308. check("KURL::cd(\"..\")", u2.url(), "file:///home");
  309. u2.cd("thomas");
  310. check("KURL::cd(\"thomas\")", u2.url(), "file:///home/thomas");
  311. u2.cd("../");
  312. check("KURL::cd(\"../\")", u2.url(), "file:///home/");
  313. u2.cd("/opt/kde/bin/");
  314. check("KURL::cd(\"/opt/kde/bin/\")", u2.url(), "file:///opt/kde/bin/");
  315. u2 = "ftp://ftp.kde.org/";
  316. printf("\n* URL is %s\n",u2.url().ascii());
  317. u2.cd("pub");
  318. check("KURL::cd(\"pub\")", u2.url(), "ftp://ftp.kde.org/pub");
  319. u2 = u2.upURL();
  320. check("KURL::upURL()", u2.url(), "ftp://ftp.kde.org/");
  321. u2 = u1;
  322. printf("\n* URL is %s\n",u2.url().ascii());
  323. // setFileName
  324. u2.setFileName( "myfile.txt" );
  325. check("KURL::setFileName()", u2.url(), "file:///home/dfaure/myfile.txt");
  326. u2.setFileName( "myotherfile.txt" );
  327. check("KURL::setFileName()", u2.url(), "file:///home/dfaure/myotherfile.txt");
  328. // more tricky, renaming a directory (kpropsdlg.cc, line ~ 238)
  329. TQString tmpurl = "file:/home/dfaure/myolddir/";
  330. if ( tmpurl.at(tmpurl.length() - 1) == '/')
  331. // It's a directory, so strip the trailing slash first
  332. tmpurl.truncate( tmpurl.length() - 1);
  333. KURL newUrl = tmpurl;
  334. newUrl.setFileName( "mynewdir" );
  335. check("KURL::setFileName() special", newUrl.url(), "file:///home/dfaure/mynewdir");
  336. // addPath tests
  337. newUrl.addPath( "subdir" );
  338. check("KURL::addPath(\"subdir\")", newUrl.url(), "file:///home/dfaure/mynewdir/subdir");
  339. newUrl.addPath( "/foo/" );
  340. check("KURL::addPath(\"/foo/\")", newUrl.url(), "file:///home/dfaure/mynewdir/subdir/foo/");
  341. u2 = "http://www.kde.org"; // no path
  342. u2.addPath( "subdir" );
  343. check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir");
  344. u2.addPath( "" );
  345. check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir"); // unchanged
  346. // even more tricky
  347. u2 = "print:/specials/Print%20To%20File%20(PDF%2FAcrobat)";
  348. printf("\n* URL is %s\n",u2.url().ascii());
  349. check("KURL::path()", u2.path(), "/specials/Print To File (PDF/Acrobat)");
  350. check("KURL::fileName()", u2.fileName(), "Print To File (PDF/Acrobat)");
  351. u2.setFileName( "" );
  352. check("KURL::setFileName()", u2.url(), "print:/specials/");
  353. u2 = "file:/specials/Print";
  354. printf("\n* URL is %s\n",u2.url().ascii());
  355. check("KURL::path()", u2.path(), "/specials/Print");
  356. check("KURL::fileName()", u2.fileName(), "Print");
  357. u2.setFileName( "" );
  358. check("KURL::setFileName()", u2.url(), "file:///specials/");
  359. const char * u6 = "ftp://host/dir1/dir2/myfile.txt";
  360. printf("\n* URL is %s\n",u6);
  361. check("KURL::hasSubURL()", KURL(u6).hasSubURL() ? "yes" : "no", "no");
  362. lst.clear();
  363. lst = KURL::split( KURL(u6) );
  364. check("KURL::split()", lst.count()==1 ? "1" : "error", "1");
  365. check("KURL::split()", lst.first().url(), "ftp://host/dir1/dir2/myfile.txt");
  366. // cdUp code
  367. KURL lastUrl = lst.last();
  368. TQString dir = lastUrl.directory( true, true );
  369. check( "KURL::directory(true,true)", dir, "/dir1/dir2");
  370. /// Comparisons
  371. TQString ucmp1 = "ftp://ftp.de.kde.org/dir";
  372. TQString ucmp2 = "ftp://ftp.de.kde.org/dir/";
  373. check("urlcmp(only slash difference)", urlcmp(ucmp1,ucmp2)?"ko":"ok","ok");
  374. check("urlcmp(only slash difference, ignore_trailing)", urlcmp(ucmp1,ucmp2,true,false)?"ok":"ko","ok");
  375. TQString ucmp3 = "ftp://ftp.de.kde.org/dir/#";
  376. check("urlcmp(only hash difference)", urlcmp(ucmp2,ucmp3)?"ko":"ok","ok");
  377. check("urlcmp(only hash difference, ignore_ref)", urlcmp(ucmp2,ucmp3,false,true)?"ok":"ko","ok");
  378. check("urlcmp(slash and hash difference, ignore_trailing, ignore_ref)", urlcmp(ucmp2,ucmp3,true,true)?"ok":"ko","ok");
  379. check("urlcmp(empty, empty)", urlcmp("","",false,true)?"ok":"ko","ok");
  380. check("urlcmp(empty, empty)", urlcmp("","")?"ok":"ko","ok");
  381. check("urlcmp(empty, not empty)", urlcmp("",ucmp1)?"ok":"ko","ko");
  382. check("urlcmp(empty, not empty)", urlcmp("",ucmp1,false,true)?"ok":"ko","ko");
  383. check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1)?"ok":"ko","ko");
  384. check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1,false,true)?"ok":"ko","ko");
  385. KURL ftpUrl ( "ftp://ftp.de.kde.org" );
  386. printf("\n* URL is %s\n",ftpUrl.url().latin1());
  387. check("KURL::path()", ftpUrl.path(), TQString::null);
  388. ftpUrl = "ftp://ftp.de.kde.org/";
  389. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp.de.kde.org/host/subdir/") ? "yes" : "no", "yes");
  390. ftpUrl = "ftp://ftp/host/subdir/";
  391. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/") ? "yes" : "no", "yes");
  392. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir") ? "yes" : "no", "yes");
  393. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdi") ? "yes" : "no", "no");
  394. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/blah/") ? "yes" : "no", "yes");
  395. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/blah/subdir") ? "yes" : "no", "no");
  396. check("KURL::isParentOf()", ftpUrl.isParentOf( "file:////ftp/host/subdir/") ? "yes" : "no", "no");
  397. check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/subsub") ? "yes" : "no", "yes");
  398. // WABA: The following tests are to test the handling of relative URLs as
  399. // found on web-pages.
  400. KURL waba1( "http://www.website.com/directory/?hello#ref" );
  401. {
  402. KURL waba2( waba1, "relative.html");
  403. check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html");
  404. }
  405. {
  406. KURL waba2( waba1, "../relative.html");
  407. check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html");
  408. }
  409. {
  410. KURL waba2( waba1, "down/relative.html");
  411. check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html");
  412. }
  413. {
  414. KURL waba2( waba1, "/down/relative.html");
  415. check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html");
  416. }
  417. {
  418. KURL waba2( waba1, "//www.kde.org/relative.html");
  419. check("http: Relative URL, with host", waba2.url(), "http://www.kde.org/relative.html");
  420. }
  421. {
  422. KURL waba2( waba1, "relative.html?query=test&name=harry");
  423. check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry");
  424. waba2.removeQueryItem("query");
  425. check("http: Removing query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry");
  426. waba2.addQueryItem("age", "18");
  427. check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18");
  428. waba2.addQueryItem("age", "21");
  429. check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21");
  430. waba2.addQueryItem("fullname", "Harry Potter");
  431. check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21&fullname=Harry%20Potter");
  432. }
  433. {
  434. KURL waba2( waba1, "?query=test&name=harry");
  435. check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/?query=test&name=harry");
  436. }
  437. {
  438. KURL waba2( waba1, "relative.html#with_reference");
  439. check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference");
  440. }
  441. {
  442. KURL waba2( waba1, "#");
  443. check("http: Relative URL, with empty reference", waba2.url(), "http://www.website.com/directory/?hello#");
  444. }
  445. {
  446. KURL waba2( waba1, "");
  447. check("http: Empty relative URL", waba2.url(), "http://www.website.com/directory/?hello#ref");
  448. }
  449. {
  450. KURL base( "http://faure@www.kde.org" ); // no path
  451. KURL waba2( base, "filename.html");
  452. check("http: Relative URL, orig URL had no path", waba2.url(), "http://faure@www.kde.org/filename.html");
  453. }
  454. {
  455. KURL base( "http://faure:pass@www.kde.org:81?query" );
  456. KURL rel1( base, "http://www.kde.org/bleh/"); // same host
  457. check("http: Relative URL, orig URL had username", rel1.url(), "http://faure:pass@www.kde.org/bleh/");
  458. KURL rel2( base, "http://www.yahoo.org"); // different host
  459. check("http: Relative URL, orig URL had username", rel2.url(), "http://www.yahoo.org");
  460. }
  461. waba1 = "http://www.website.com/directory/filename?bla#blub";
  462. {
  463. KURL waba2( waba1, "relative.html");
  464. check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html");
  465. }
  466. {
  467. KURL waba2( waba1, "../relative.html");
  468. check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html");
  469. }
  470. {
  471. KURL waba2( waba1, "down/relative.html");
  472. check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html");
  473. }
  474. {
  475. KURL waba2( waba1, "/down/relative.html");
  476. check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html");
  477. }
  478. {
  479. KURL waba2( waba1, "relative.html?query=test&name=harry");
  480. check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry");
  481. }
  482. {
  483. KURL waba2( waba1, "?query=test&name=harry");
  484. check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/filename?query=test&name=harry");
  485. }
  486. {
  487. KURL waba2( waba1, "relative.html#with_reference");
  488. check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference");
  489. }
  490. {
  491. KURL waba2( waba1, "http:/relative.html"); // "rfc 1606 loophole"
  492. check("http: Strange relative URL", waba2.url(), "http://www.website.com/relative.html");
  493. }
  494. waba1.setUser("waldo");
  495. check("http: Set user", waba1.url(), "http://waldo@www.website.com/directory/filename?bla#blub");
  496. waba1.setUser("waldo/bastian");
  497. check("http: Set user with slash in it", waba1.url(), "http://waldo%2Fbastian@www.website.com/directory/filename?bla#blub");
  498. waba1.setRef( TQString::null );
  499. waba1.setPass( "pass" );
  500. waba1.setDirectory( "/foo" );
  501. waba1.setProtocol( "https" );
  502. waba1.setHost( "web.com" );
  503. waba1.setPort( 881 );
  504. check("http: setRef/setPass/setDirectory/setHost/setPort", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla");
  505. waba1.setDirectory( "/foo/" );
  506. check("http: setDirectory #2", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla");
  507. // Empty queries should be preserved!
  508. waba1 = "http://www.kde.org/cgi/test.cgi?";
  509. check("http: URL with empty query string", waba1.url(),
  510. "http://www.kde.org/cgi/test.cgi?");
  511. // Empty references should be preserved
  512. waba1 = "http://www.kde.org/cgi/test.cgi#";
  513. check("http: URL with empty reference string", waba1.url(),
  514. "http://www.kde.org/cgi/test.cgi#");
  515. check("hasRef()", waba1.hasRef()?"true":"false","true");
  516. check("hasHTMLRef()", waba1.hasHTMLRef()?"true":"false","true");
  517. check("encodedHtmlRef()", waba1.encodedHtmlRef(),TQString::null);
  518. // URLs who forgot to encode spaces in the query.
  519. waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value";
  520. check("http: URL with incorrect encoded query", waba1.url(),
  521. "http://www.kde.org/cgi/test.cgi?hello=My%20Value");
  522. // URL with ':' in query (':' should NOT be encoded!)
  523. waba1.setQuery("hello:My Value");
  524. check("http: URL with ':' in query", waba1.url(),
  525. "http://www.kde.org/cgi/test.cgi?hello:My%20Value");
  526. check("upURL() removes query", waba1.upURL().url(),
  527. "http://www.kde.org/cgi/test.cgi");
  528. // URLs who forgot to encode spaces in the query.
  529. waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value+20";
  530. check("http: URL with incorrect encoded query", waba1.url(),
  531. "http://www.kde.org/cgi/test.cgi?hello=My%20Value+20");
  532. // Urls without path (BR21387)
  533. waba1 = "http://meine.db24.de?link=home_c_login_login";
  534. check("http: URL with empty path string", waba1.url(),
  535. "http://meine.db24.de?link=home_c_login_login");
  536. check("http: URL with empty path string path", waba1.path(),
  537. "");
  538. check("http: URL with empty path string query", waba1.query(),
  539. "?link=home_c_login_login");
  540. waba1 = "http://a:389?b=c";
  541. check( "http: URL with port, query, and empty path; url", waba1.url(), "http://a:389?b=c" );
  542. check( "http: URL with port, query, and empty path; host", waba1.host(), "a" );
  543. check( "http: URL with port, query, and empty path; port", TQString::number( waba1.port() ), "389" );
  544. check( "http: URL with port, query, and empty path; path", waba1.path(), "" );
  545. check( "http: URL with port, query, and empty path; query", waba1.query(), "?b=c" );
  546. // Urls without path (BR21387)
  547. waba1 = "http://meine.db24.de#link=home_c_login_login";
  548. check("http: URL with empty path string", waba1.url(),
  549. "http://meine.db24.de#link=home_c_login_login");
  550. check("http: URL with empty path string path", waba1.path(),
  551. "");
  552. waba1 = "http://www.meinestadt.de&url_plain=http";
  553. check("http: URL with empty path string", waba1.host(),
  554. "www.meinestadt.de&url_plain=http");
  555. check("http: URL with empty path string", waba1.htmlURL(),
  556. "http://www.meinestadt.de&amp;url_plain=http");
  557. check("http: URL with empty path string", waba1.path(),
  558. "");
  559. waba1 = "http://a:389#b=c";
  560. check( "http: URL with port, ref, and empty path; url", waba1.url(), "http://a:389#b=c" );
  561. check( "http: URL with port, ref, and empty path; host", waba1.host(), "a" );
  562. check( "http: URL with port, ref, and empty path; port", TQString::number( waba1.port() ), "389" );
  563. check( "http: URL with port, ref, and empty path; path", waba1.path(), "" );
  564. check( "http: URL with port, ref, and empty path; ref", waba1.ref(), "b=c" );
  565. check( "http: URL with port, ref, and empty path; query", waba1.query(), "" );
  566. // IPV6
  567. waba1 = "http://[::FFFF:129.144.52.38]:81/index.html";
  568. check("http: IPV6 host", waba1.host(),
  569. "::ffff:129.144.52.38");
  570. check("http: IPV6 port", TQString("%1").arg(waba1.port()),
  571. "81");
  572. // IPV6
  573. waba1 = "http://waba:pass@[::FFFF:129.144.52.38]:81/index.html";
  574. check("http: IPV6 host", waba1.host(),
  575. "::ffff:129.144.52.38");
  576. check("http: IPV6 host", waba1.user(),
  577. "waba");
  578. check("http: IPV6 host", waba1.pass(),
  579. "pass");
  580. check("http: IPV6 port", TQString("%1").arg(waba1.port()),
  581. "81");
  582. // IPV6
  583. waba1 = "http://www.kde.org/cgi/test.cgi";
  584. waba1.setHost("::ffff:129.144.52.38");
  585. check("http: IPV6 host", waba1.url(),
  586. "http://[::ffff:129.144.52.38]/cgi/test.cgi");
  587. waba1 = "http://[::ffff:129.144.52.38]/cgi/test.cgi";
  588. assert( waba1.isValid() );
  589. // IPV6 without path
  590. waba1 = "http://[::ffff:129.144.52.38]?query";
  591. assert( waba1.isValid() );
  592. check("http: IPV6 without path", waba1.url(),
  593. "http://[::ffff:129.144.52.38]?query");
  594. check("http: IPV6 without path; query", waba1.query(),
  595. "?query");
  596. waba1 = "http://[::ffff:129.144.52.38]#ref";
  597. assert( waba1.isValid() );
  598. check("http: IPV6 without path", waba1.url(),
  599. "http://[::ffff:129.144.52.38]#ref");
  600. check("http: IPV6 without path; ref", waba1.ref(),
  601. "ref");
  602. // IPV6 without path but with a port
  603. waba1 = "http://[::ffff:129.144.52.38]:81?query";
  604. assert( waba1.isValid() );
  605. check("http: IPV6 without path", waba1.url(),
  606. "http://[::ffff:129.144.52.38]:81?query");
  607. check("http: IPV6 without path; port", TQString::number( waba1.port() ), "81" );
  608. check("http: IPV6 without path; query", waba1.query(), "?query");
  609. waba1 = "http://[::ffff:129.144.52.38]:81#ref";
  610. assert( waba1.isValid() );
  611. check("http: IPV6 without path", waba1.url(),
  612. "http://[::ffff:129.144.52.38]:81#ref");
  613. check("http: IPV6 without path; port", TQString::number( waba1.port() ), "81" );
  614. check("http: IPV6 without path; ref", waba1.ref(), "ref");
  615. // Streaming operators
  616. KURL origURL( "http://www.website.com/directory/?#ref" );
  617. waba1 = "http://[::ffff:129.144.52.38]:81?query";
  618. TQByteArray buffer;
  619. {
  620. TQDataStream stream( buffer, IO_WriteOnly );
  621. stream << origURL
  622. << KURL( "file:" ) // an invalid one
  623. << waba1; // the IPv6 one
  624. }
  625. {
  626. TQDataStream stream( buffer, IO_ReadOnly );
  627. KURL restoredURL;
  628. stream >> restoredURL;
  629. check( "Streaming valid URL", origURL.url(), restoredURL.url() );
  630. stream >> restoredURL;
  631. check( "Streaming invalid URL", restoredURL.isValid()?"valid":"malformed", "malformed" );
  632. check( "Streaming invalid URL", restoredURL.url(), "file:" );
  633. stream >> restoredURL;
  634. check( "Streaming ipv6 URL with query", restoredURL.url(), waba1.url() );
  635. }
  636. // Broken stuff
  637. waba1 = "file:a";
  638. check("Broken stuff #1 path", waba1.path(), "a");
  639. check("Broken stuff #1 fileName(false)", waba1.fileName(false), "a");
  640. check("Broken stuff #1 fileName(true)", waba1.fileName(true), "a");
  641. check("Broken stuff #1 directory(false, false)", waba1.directory(false, false), "");
  642. check("Broken stuff #1 directory(true, false)", waba1.directory(true, false), "");
  643. check("Broken stuff #1 directory(false, true)", waba1.directory(true, true), "");
  644. waba1 = "file:a/";
  645. check("Broken stuff #2 path", waba1.path(), "a/");
  646. check("Broken stuff #2 fileName(false)", waba1.fileName(false), "");
  647. check("Broken stuff #2 fileName(true)", waba1.fileName(true), "a");
  648. check("Broken stuff #2 directory(false, false)", waba1.directory(false, false), "a/");
  649. check("Broken stuff #2 directory(true, false)", waba1.directory(true, false), "a");
  650. check("Broken stuff #2 directory(false, true)", waba1.directory(true, true), "");
  651. waba1 = "file:";
  652. check("Broken stuff #3 empty", waba1.isEmpty()?"EMPTY":"NOT", "NOT");
  653. check("Broken stuff #3 valid", waba1.isValid()?"VALID":"MALFORMED", "MALFORMED");
  654. check("Broken stuff #3 path", waba1.path(), "");
  655. check("Broken stuff #3 fileName(false)", waba1.fileName(false), "");
  656. check("Broken stuff #3 fileName(true)", waba1.fileName(true), "");
  657. check("Broken stuff #3 directory(false, false)", waba1.directory(false, false), "");
  658. check("Broken stuff #3 directory(true, false)", waba1.directory(true, false), "");
  659. check("Broken stuff #3 directory(false, true)", waba1.directory(true, true), "");
  660. KURL broken;
  661. broken.setPath( TQString::null );
  662. check("Broken stuff #4 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
  663. // It's valid: because isValid refers to parsing, not to what happens afterwards.
  664. check("Broken stuff #4 valid", broken.isValid()?"VALID":"MALFORMED", "VALID");
  665. check("Broken stuff #4 path", broken.path(), "");
  666. broken = "file://"; // just because coolo wondered
  667. check("Broken stuff #5 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
  668. check("Broken stuff #5 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
  669. check("Broken stuff #5 path", broken.path(), "");
  670. broken = "file";
  671. check("Broken stuff #6 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
  672. broken = "/";
  673. check("Broken stuff #7 valid", broken.isValid()?"VALID":"MALFORMED", "VALID");
  674. check("Broken stuff #7 path", broken.path(), "/" );
  675. check("Broken stuff #7 url", broken.url(), "file:///" );
  676. check("Broken stuff #7 file", broken.protocol(), "file" );
  677. broken = "LABEL=USB_STICK"; // 71430, can we use KURL for this?
  678. check("Broken stuff #6 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED");
  679. check("Broken stuff #6 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT");
  680. check("Broken stuff #6 path", broken.path(), "");
  681. #if 0 // BROKEN?
  682. // UNC like names
  683. KURL unc1("FILE://localhost/home/root");
  684. check("UNC, with localhost", unc1.path(), "/home/root");
  685. check("UNC, with localhost", unc1.url(), "file:///home/root");
  686. #endif
  687. KURL unc2("file:///home/root");
  688. check("UNC, with empty host", unc2.path(), "/home/root");
  689. check("UNC, with empty host", unc2.url(), "file:///home/root");
  690. {
  691. KURL unc3("FILE://remotehost/home/root");
  692. #if 0 // BROKEN?
  693. check("UNC, with remote host", unc3.path(), "//remotehost/home/root");
  694. #endif
  695. check("UNC, with remote host", unc3.url(), "file://remotehost/home/root");
  696. KURL url2("file://atlas/dfaure");
  697. check("KURL::host()", url2.host(), "atlas");
  698. check("KURL::path()", url2.path(), "/dfaure");
  699. //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba
  700. //KURL url3("file:////atlas/dfaure");
  701. //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba
  702. KURL url4(url2, "//remotehost/home/root");
  703. check("KURL::host()", url4.host(), "remotehost");
  704. check("KURL::path()", url4.path(), "/home/root");
  705. }
  706. KURL umail1 ( "mailto:faure@kde.org" );
  707. check("mailto: URL, general form", umail1.protocol(), "mailto");
  708. check("mailto: URL, general form", umail1.path(), "faure@kde.org");
  709. check("mailto: URL, is relative", KURL::isRelativeURL("mailto:faure@kde.org") ? "true" : "false", "false");
  710. KURL umail2 ( "mailto:Faure David <faure@kde.org>" );
  711. check("mailto: URL, general form", umail2.protocol(), "mailto");
  712. check("mailto: URL, general form", umail2.path(), "Faure David <faure@kde.org>");
  713. check("isRelativeURL(\"mailto:faure@kde.org\")", KURL::isRelativeURL("mailto:faure@kde.org") ? "yes" : "no", "no");
  714. KURL umail3 ( "mailto:" );
  715. check("mailto: invalid URL", umail3.isValid()?"valid":"malformed", "malformed");
  716. check("man: URL, is relative", KURL::isRelativeURL("man:mmap") ? "true" : "false", "false");
  717. check("javascript: URL, is relative", KURL::isRelativeURL("javascript:doSomething()") ? "true" : "false", "false");
  718. // more isRelative
  719. check("file: URL, is relative", KURL::isRelativeURL("file:///blah") ? "true" : "false", "false");
  720. check("/path, is relative", KURL::isRelativeURL("/path") ? "true" : "false", "true"); // arguable, but necessary for KURL( baseURL, "//www1.foo.bar" );
  721. check("something, is relative", KURL::isRelativeURL("something") ? "true" : "false", "true");
  722. KURL about("about:konqueror");
  723. check("about:",about.path(),"konqueror");
  724. KURL ulong("https://swww.gad.de:443/servlet/CookieAccepted?MAIL=s@gad.de&VER=25901");
  725. check("host",ulong.host(),"swww.gad.de");
  726. check("path",ulong.path(),"/servlet/CookieAccepted");
  727. #if TQT_VERSION < 300
  728. qt_set_locale_codec( KGlobal::charsets()->codecForName( "iso-8859-1" ) );
  729. #else
  730. TQTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "iso-8859-1" ) );
  731. #endif
  732. TQString raw = "data:text/html,%00%2540%00";
  733. check("data URL: encode-decode of %00", KURL(raw).url(), raw );
  734. // UTF8 tests
  735. KURL uloc("/home/dfaure/konqtests/Matériel");
  736. check("url",uloc.url().latin1(),"file:///home/dfaure/konqtests/Mat%E9riel");
  737. check("pretty",uloc.prettyURL(),"file:///home/dfaure/konqtests/Matériel"); // escaping the letter would be correct too
  738. check("pretty + strip",uloc.prettyURL(0, KURL::StripFileProtocol),"/home/dfaure/konqtests/Matériel"); // escaping the letter would be correct too
  739. // 106 is MIB for UTF-8
  740. check("UTF8",uloc.url(0, 106),"file:///home/dfaure/konqtests/Mat%C3%A9riel");
  741. uloc = KURL("file:///home/dfaure/konqtests/Mat%C3%A9riel", 106);
  742. check("UTF8 path", uloc.path(), "/home/dfaure/konqtests/Matériel");
  743. check("encodedPathAndQuery", uloc.encodedPathAndQuery(), "/home/dfaure/konqtests/Mat%E9riel");
  744. // fromPathOrURL tests
  745. uloc = KURL::fromPathOrURL( "/home/dfaure/konqtests/Mat%E9riel" );
  746. check("fromPathOrURL path", uloc.path(), "/home/dfaure/konqtests/Mat%E9riel");
  747. uloc = KURL::fromPathOrURL( "http://www.kde.org" );
  748. check("pathOrURL url", uloc.pathOrURL(), uloc.url() );
  749. uloc = KURL::fromPathOrURL( "www.kde.org" );
  750. check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
  751. uloc = KURL::fromPathOrURL( "index.html" );
  752. check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
  753. uloc = KURL::fromPathOrURL( "" );
  754. check("fromPathOrURL malformed", uloc.isValid()?"valid":"malformed", "malformed");
  755. // pathOrURL tests
  756. uloc = KURL::fromPathOrURL( "/home/dfaure/konqtests/Mat%E9riel" );
  757. check("pathOrURL path", uloc.pathOrURL(), uloc.path() );
  758. uloc = "http://www.kde.org";
  759. check("pathOrURL url", uloc.url(), "http://www.kde.org");
  760. uloc = "file:///home/dfaure/konq%20tests/Mat%E9riel#ref";
  761. check("pathOrURL local file with ref", uloc.pathOrURL(), "file:///home/dfaure/konq tests/Matériel#ref" );
  762. uloc = "file:///home/dfaure/konq%20tests/Mat%E9riel?query";
  763. check("pathOrURL local file with query", uloc.pathOrURL(), "file:///home/dfaure/konq tests/Matériel?query" );
  764. uloc = KURL::fromPathOrURL( "/home/dfaure/file#with#hash" );
  765. check("pathOrURL local path with #", uloc.pathOrURL(), "/home/dfaure/file#with#hash" );
  766. testAdjustPath();
  767. #if TQT_VERSION < 300
  768. qt_set_locale_codec( KGlobal::charsets()->codecForName( "koi8-r" ) );
  769. #else
  770. TQTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "koi8-r" ) );
  771. #endif
  772. baseURL = "file:/home/coolo";
  773. KURL russian = baseURL.directory(false, true) + TQString::fromLocal8Bit( "ÆÇÎ7" );
  774. check( "russian", russian.url(), "file:///home/%C6%C7%CE7" );
  775. KURL tobi1("http://some.host.net/path/to/file#fragmentPrecedes?theQuery");
  776. check("wrong order of query and hypertext reference #1", tobi1.ref(), "fragmentPrecedes");
  777. check("wrong order of query and hypertext reference #2", tobi1.query(), "?theQuery");
  778. tobi1 = "http://host.net/path/?#http://brokenäadsfküpoij31ü029muß2890zupycÜ*!*'O´+ß0i";
  779. check("zero-length query",tobi1.query(),"?");
  780. tobi1 = "http://host.net/path/#no-query";
  781. check("no query", tobi1.query(),"");
  782. check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "/path/");
  783. tobi1 = "http://host.net/path?myfirstquery#andsomeReference";
  784. tobi1.setEncodedPathAndQuery("another/path/?another&query");
  785. check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query");
  786. check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path/"); // with trailing slash
  787. check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "another/path/?another&query");
  788. tobi1.setEncodedPathAndQuery("another/path?another&query");
  789. check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query");
  790. check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path"); // without trailing slash
  791. check("encodedPathAndQuery", tobi1.encodedPathAndQuery(), "another/path?another&query");
  792. KURL theKow = "http://www.google.de/search?q=frerich&hlx=xx&hl=de&empty=&lr=lang+de&test=%2B%20%3A%25";
  793. check("queryItem (first item)", theKow.queryItem("q"), "frerich");
  794. check("queryItem (middle item)", theKow.queryItem("hl"), "de");
  795. check("queryItem (last item)", theKow.queryItem("lr"), "lang de");
  796. check("queryItem (invalid item)", theKow.queryItem("InterstellarCounselor"), TQString::null);
  797. check("queryItem (empty item)", theKow.queryItem("empty"), "");
  798. check("queryItem (item with encoded chars)", theKow.queryItem("test"), "+ :%");
  799. check("encodedPathAndQuery", theKow.encodedPathAndQuery(), "/search?q=frerich&hlx=xx&hl=de&empty=&lr=lang+de&test=%2B%20%3A%25");
  800. // checks for queryItems(), which returns a TQMap<TQString,TQString>:
  801. KURL queryUrl( "mailto:Marc%20Mutz%20%3cmutz@kde.org%3E?"
  802. "Subject=subscribe+me&"
  803. "body=subscribe+mutz%40kde.org&"
  804. "Cc=majordomo%40lists.kde.org" );
  805. check("queryItems (c.s. keys)",
  806. TQStringList(queryUrl.queryItems().keys()).join(", "),
  807. "Cc, Subject, body" );
  808. check("queryItems (c.i.s. keys)",
  809. TQStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).keys()).join(", "),
  810. "body, cc, subject" );
  811. check("queryItems (values; c.s. keys)",
  812. TQStringList(queryUrl.queryItems().values()).join(", "),
  813. "majordomo@lists.kde.org, subscribe me, subscribe mutz@kde.org" );
  814. check("queryItems (values; c.i.s. keys)",
  815. TQStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).values()).join(", "),
  816. "subscribe mutz@kde.org, majordomo@lists.kde.org, subscribe me" );
  817. KURL umlaut1("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
  818. check("umlaut1.url()", umlaut1.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
  819. KURL umlaut2("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel", 106);
  820. check("umlaut2.url()", umlaut2.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel");
  821. // Needed for #49616
  822. check( "encode_string('C++')", KURL::encode_string( "C++" ), "C%2B%2B" );
  823. check( "decode_string('C%2B%2B')", KURL::decode_string( "C%2B%2B" ), "C++" );
  824. check( "decode_string('C%00A')", KURL::decode_string( "C%00%A" ), "C" ); // we stop at %00
  825. check( "encode_string('%')", KURL::encode_string( "%" ), "%25" );
  826. check( "encode_string(':')", KURL::encode_string( ":" ), "%3A" );
  827. KURL amantia( "http://%E1.foo.de" );
  828. check("amantia.isValid()", amantia.isValid() ? "true" : "false", "true");
  829. #ifdef HAVE_IDNA_H
  830. check("amantia.url()", amantia.url(), "http://xn--80a.foo.de"); // Non-ascii is allowed in IDN domain names.
  831. #else
  832. check("amantia.url()", amantia.url(), "http://?.foo.de"); // why not
  833. #endif
  834. KURL thiago( TQString::fromUtf8( "http://\303\244.de" ) ); // ä in utf8
  835. check("thiago.isValid()", thiago.isValid() ? "true" : "false", "true");
  836. #ifdef HAVE_IDNA_H
  837. check("thiago.url()", thiago.url(), "http://xn--4ca.de"); // Non-ascii is allowed in IDN domain names.
  838. #else
  839. check("thiago.url()", thiago.url(), TQString::fromUtf8( "http://\303\244.de" ) );
  840. #endif
  841. KURL smb("smb://domain;username:password@server/share");
  842. check("smb.isValid()", smb.isValid() ? "true" : "false", "true");
  843. check("smb.user()", smb.user(), "domain;username");
  844. smb = "smb:/";
  845. check("smb:/", smb.isValid()?"VALID":"MALFORMED", "VALID");
  846. smb = "smb://"; // kurl.cpp rev 1.106
  847. check("smb://", smb.isValid()?"VALID":"MALFORMED", "MALFORMED");
  848. smb = "smb://host";
  849. check("smb://host", smb.isValid()?"VALID":"MALFORMED", "VALID");
  850. smb = "smb:///";
  851. check("smb:///", smb.isValid()?"VALID":"MALFORMED", "VALID");
  852. KURL weird;
  853. weird = "http://strange<hostname>/";
  854. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  855. weird = "http://strange<username>@strange<hostname>/";
  856. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  857. weird = "http://strange<username>@ok_hostname/";
  858. check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
  859. check("weird.host()", weird.host(), "ok_hostname");
  860. weird = "http://strange;hostname/";
  861. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  862. weird = "http://strange;username@strange;hostname/";
  863. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  864. weird = "http://strange;username@ok_hostname/";
  865. check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
  866. check("weird.host()", weird.host(), "ok_hostname");
  867. weird = "http://strange;username:password@strange;hostname/";
  868. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  869. weird = "http://strange;username:password@ok_hostname/";
  870. check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
  871. check("weird.host()", weird.host(), "ok_hostname");
  872. weird = "http://[strange;hostname]/";
  873. check("weird.isValid()", weird.isValid() ? "true" : "false", "false");
  874. weird = "http://[::fff:1:23]/";
  875. check("weird.isValid()", weird.isValid() ? "true" : "false", "true");
  876. check("weird.host()", weird.host(), "::fff:1:23");
  877. KURL com1("http://server.com/dir/", ".");
  878. check("com1.url()", com1.url(), "http://server.com/dir/");
  879. KURL com2("http://server.com/dir/blubb/", "blah/");
  880. check("com2.url()", com2.url(), "http://server.com/dir/blubb/blah/");
  881. KURL utf8_1("audiocd:/By%20Name/15%20Geantra%C3%AE.wav", 106);
  882. check("utf8_1.fileName()", utf8_1.fileName(), TQString::fromLatin1("15 Geantraî.wav"));
  883. KURL utf8_2("audiocd:/By%20Name/15%2fGeantra%C3%AE.wav", 106);
  884. check("utf8_2.fileName()", utf8_2.fileName(), TQString::fromLatin1("15/Geantraî.wav"));
  885. KURL url_newline_1("http://www.foo.bar/foo/bar\ngnork");
  886. check("url_newline_1.url()", url_newline_1.url(), TQString::fromLatin1("http://www.foo.bar/foo/bar%0Agnork"));
  887. KURL url_newline_2("http://www.foo.bar/foo?bar\ngnork");
  888. check("url_newline_2.url()", url_newline_2.url(), TQString::fromLatin1("http://www.foo.bar/foo?bar%0Agnork"));
  889. KURL local_file_1("file://localhost/my/file");
  890. check("local_file_1.isLocalFile()", local_file_1.isLocalFile() ? "true" : "false", "true");
  891. KURL local_file_2("file://www.kde.org/my/file");
  892. check("local_file_2.isLocalFile()", local_file_2.isLocalFile() ? "true" : "false", "false");
  893. KURL local_file_3;
  894. local_file_3.setHost(getenv("HOSTNAME"));
  895. local_file_3.setPath("/my/file");
  896. printf("\nURL=%s\n", local_file_3.url().latin1());
  897. check("local_file_3.isLocalFile()", local_file_3.isLocalFile() ? "true" : "false", "true");
  898. KURL local_file_4("file:///my/file");
  899. check("local_file_4.isLocalFile()", local_file_4.isLocalFile() ? "true" : "false", "true");
  900. KURL local_file_5;
  901. local_file_5.setPath("/foo?bar");
  902. check("local_file_5.url()", local_file_5.url(), "file:///foo%3Fbar");
  903. TQString basePath = "/home/bastian";
  904. check("relativePath(\"/home/bastian\", \"/home/bastian\")", KURL::relativePath(basePath, "/home/bastian"), "./");
  905. bool b;
  906. check("relativePath(\"/home/bastian\", \"/home/bastian/src/plugins\")", KURL::relativePath(basePath, "/home/bastian/src/plugins", &b), "./src/plugins");
  907. check("Is a subdirectory?", b ? "true" : "false", "true");
  908. check("relativePath(\"/home/bastian\", \"./src/plugins\")", KURL::relativePath(basePath, "./src/plugins"), "./src/plugins");
  909. check("relativePath(\"/home/bastian\", \"/home/waba/src/plugins\")", KURL::relativePath(basePath, "/home/waba/src/plugins", &b), "../waba/src/plugins");
  910. check("Is a subdirectory?", b ? "true" : "false", "false");
  911. check("relativePath(\"/home/bastian\", \"/\")", KURL::relativePath(basePath, "/"), "../../");
  912. check("relativePath(\"/\", \"/\")", KURL::relativePath("/", "/"), "./");
  913. check("relativePath(\"/\", \"/home/bastian\")", KURL::relativePath("/", "/home/bastian"), "./home/bastian");
  914. check("relativePath(\"\", \"/home/bastian\")", KURL::relativePath("", "/home/bastian"), "/home/bastian");
  915. baseURL = "http://www.kde.org/index.html";
  916. check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html#help\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html#help"), "#help");
  917. check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html?help=true\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html?help=true"), "index.html?help=true");
  918. check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/contact.html"), "contact.html");
  919. check("relativeURL(\"http://www.kde.org/index.html\", \"ftp://ftp.kde.org/pub/kde\")", KURL::relativeURL(baseURL, "ftp://ftp.kde.org/pub/kde"), "ftp://ftp.kde.org/pub/kde");
  920. check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html"), "./");
  921. baseURL = "http://www.kde.org/info/index.html";
  922. check("relativeURL(\"http://www.kde.org/info/index.html\", \"http://www.kde.org/bugs/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/bugs/contact.html"), "../bugs/contact.html");
  923. baseURL = "ptal://mlc:usb:PC_970";
  924. check("isValid()?", baseURL.isValid() ? "true" : "false", "false");
  925. check("url()", baseURL.url(), "ptal://mlc:usb:PC_970");
  926. baseURL = "http://mlc:80/";
  927. check("isValid()?", baseURL.isValid() ? "true" : "false", "true");
  928. check("port()?", TQString::number(baseURL.port()), "80");
  929. check("path()?", baseURL.path(), "/");
  930. baseURL = "ptal://mlc:usb@PC_970"; // User=mlc, password=usb, host=PC_970
  931. check("isValid()?", baseURL.isValid() ? "true" : "false", "true");
  932. check("host()?", baseURL.host(), "pc_970");
  933. check("user()?", baseURL.user(), "mlc");
  934. check("pass()?", baseURL.pass(), "usb");
  935. weird = "ftp://user%40host.com@ftp.host.com/var/www/";
  936. check("user()?", weird.user(), "user@host.com" );
  937. check("host()?", weird.host(), "ftp.host.com" );
  938. KURL up = weird.upURL();
  939. check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/var/");
  940. up = up.upURL();
  941. check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/");
  942. up = up.upURL();
  943. check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/"); // unchanged
  944. KURL ldap = "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)";
  945. check("host()?", ldap.host(), "host.com");
  946. check("port()?", TQString("%1").arg(ldap.port()), "6666");
  947. check("path()?", ldap.path(), "/o=University of Michigan,c=US");
  948. check("query()?", ldap.query(), "??sub?(cn=Babs%20Jensen)");
  949. check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)");
  950. ldap.setQuery("??sub?(cn=Karl%20Marx)");
  951. check("query()?", ldap.query(), "??sub?(cn=Karl%20Marx)");
  952. check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Karl%20Marx)");
  953. KURL leo = "data:text/html,http://www.invalid/";
  954. check("data URL: isValid", leo.isValid()?"valid":"malformed", "valid" );
  955. check("data URL: protocol", leo.protocol(), "data" );
  956. check("data URL: url", leo.url(), "data:text/html,http://www.invalid/" );
  957. check("data URL: path", leo.path(), "text/html,http://www.invalid/" );
  958. // URI Mode tests
  959. url1 = "http://www.foobar.com/";
  960. check("KURL(\"http://www.foobar.com/\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::URL));
  961. url1 = "mailto:user@host.com";
  962. check("KURL(\"mailto:user@host.com\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::Mailto));
  963. check("KURL(\"mailto:user@host.com\").url()", url1.url(), "mailto:user@host.com");
  964. check("KURL(\"mailto:user@host.com\").url(0, 106)", url1.url(0, 106), "mailto:user@host.com");
  965. url1 = "data:text/plain,foobar?gazonk=flarp";
  966. check("KURL(\"data:text/plain,foobar?gazonk=flarp\").uriMode()", TQString::number(url1.uriMode()), TQString::number(KURL::RawURI));
  967. check("KURL(\"data:text/plain,foobar?gazonk=flarp\").path()", url1.path(), "text/plain,foobar?gazonk=flarp");
  968. url1 = "mailto:User@Host.COM?subject=Hello";
  969. check("KURL(\"mailto:User@Host.COM?subject=Hello\").path()", url1.path(), "User@host.com");
  970. KURL emptyUserTest1("http://www.foobar.com/");
  971. KURL emptyUserTest2("http://www.foobar.com/");
  972. emptyUserTest2.setUser("");
  973. check("Empty vs. null fields: user", emptyUserTest1==emptyUserTest2?"TRUE":"FALSE","TRUE");
  974. emptyUserTest2.setPass("");
  975. check("Empty vs. null fields: password", emptyUserTest1==emptyUserTest2?"TRUE":"FALSE","TRUE");
  976. printf("\nTest OK !\n");
  977. }