1 27 package org.htmlparser.tests.lexerTests; 28 29 import java.io.IOException ; 30 import java.net.URL ; 31 import java.net.URLConnection ; 32 33 import org.htmlparser.lexer.Page; 34 import org.htmlparser.tests.ParserTestCase; 35 import org.htmlparser.util.ParserException; 36 37 public class PageTests extends ParserTestCase 38 { 39 static 40 { 41 System.setProperty ("org.htmlparser.tests.lexerTests.PageTests", "PageTests"); 42 } 43 44 50 public static final String DEFAULT_CHARSET = "ISO-8859-1"; 51 52 55 static final String BASEURI = "http://a/b/c/d;p?q"; 56 57 60 public static Page mPage; 61 static 62 { 63 mPage = new Page (); 64 mPage.setBaseUrl (BASEURI); 65 } 66 67 70 public PageTests (String name) 71 { 72 super (name); 73 } 74 75 78 public void testNull () throws ParserException 79 { 80 try 81 { 82 new Page ((URLConnection )null); 83 assertTrue ("null value in constructor", false); 84 } 85 catch (IllegalArgumentException iae) 86 { 87 } 89 90 try 91 { 92 new Page ((String )null); 93 assertTrue ("null value in constructor", false); 94 } 95 catch (IllegalArgumentException iae) 96 { 97 } 99 } 100 101 104 public void testURLConnection () throws ParserException, IOException 105 { 106 String link; 107 URL url; 108 109 link = "http://www.ibm.com/jp/"; 110 url = new URL (link); 111 new Page (url.openConnection ()); 112 } 113 114 117 public void testBadURLConnection () throws IOException 118 { 119 String link; 120 URL url; 121 122 link = "http://www.bigbogosity.org/"; 123 url = new URL (link); 124 try 125 { 126 new Page (url.openConnection ()); 127 } 128 catch (ParserException pe) 129 { 130 } 132 } 133 134 140 144 168 public void test1 () throws ParserException 169 { 170 assertEquals ("test1 failed", "https:h", mPage.getAbsoluteURL ("https:h")); 171 } 172 public void test2 () throws ParserException 173 { 174 assertEquals ("test2 failed", "http://a/b/c/g", mPage.getAbsoluteURL ("g")); 175 } 176 public void test3 () throws ParserException 177 { 178 assertEquals ("test3 failed", "http://a/b/c/g", mPage.getAbsoluteURL ("./g")); 179 } 180 public void test4 () throws ParserException 181 { 182 assertEquals ("test4 failed", "http://a/b/c/g/", mPage.getAbsoluteURL ("g/")); 183 } 184 public void test5 () throws ParserException 185 { 186 assertEquals ("test5 failed", "http://a/g", mPage.getAbsoluteURL ("/g")); 187 } 188 public void test6 () throws ParserException 189 { 190 assertEquals ("test6 failed", "http://g", mPage.getAbsoluteURL ("//g")); 191 } 192 public void test7 () throws ParserException 193 { 194 assertEquals ("test7 failed", "http://a/b/c/?y", mPage.getAbsoluteURL ("?y")); 195 } 196 public void test8 () throws ParserException 197 { 198 assertEquals ("test8 failed", "http://a/b/c/g?y", mPage.getAbsoluteURL ("g?y")); 199 } 200 public void test9 () throws ParserException 201 { 202 assertEquals ("test9 failed", "https:h", mPage.getAbsoluteURL ("https:h")); 203 } 204 public void test10 () throws ParserException 205 { 206 assertEquals ("test10 failed", "https:h", mPage.getAbsoluteURL ("https:h")); 207 } 208 public void test11 () throws ParserException 210 { 211 assertEquals ("test11 failed", "http://a/b/c/g#s", mPage.getAbsoluteURL ("g#s")); 212 } 213 public void test12 () throws ParserException 214 { 215 assertEquals ("test12 failed", "http://a/b/c/g?y#s", mPage.getAbsoluteURL ("g?y#s")); 216 } 217 public void test13 () throws ParserException 218 { 219 assertEquals ("test13 failed", "http://a/b/c/;x", mPage.getAbsoluteURL (";x")); 220 } 221 public void test14 () throws ParserException 222 { 223 assertEquals ("test14 failed", "http://a/b/c/g;x", mPage.getAbsoluteURL ("g;x")); 224 } 225 public void test15 () throws ParserException 226 { 227 assertEquals ("test15 failed", "http://a/b/c/g;x?y#s", mPage.getAbsoluteURL ("g;x?y#s")); 228 } 229 public void test16 () throws ParserException 230 { 231 assertEquals ("test16 failed", "http://a/b/c/", mPage.getAbsoluteURL (".")); 232 } 233 public void test17 () throws ParserException 234 { 235 assertEquals ("test17 failed", "http://a/b/c/", mPage.getAbsoluteURL ("./")); 236 } 237 public void test18 () throws ParserException 238 { 239 assertEquals ("test18 failed", "http://a/b/", mPage.getAbsoluteURL ("..")); 240 } 241 public void test19 () throws ParserException 242 { 243 assertEquals ("test19 failed", "http://a/b/", mPage.getAbsoluteURL ("../")); 244 } 245 public void test20 () throws ParserException 246 { 247 assertEquals ("test20 failed", "http://a/b/g", mPage.getAbsoluteURL ("../g")); 248 } 249 public void test21 () throws ParserException 250 { 251 assertEquals ("test21 failed", "http://a/", mPage.getAbsoluteURL ("../..")); 252 } 253 public void test22 () throws ParserException 254 { 255 assertEquals ("test22 failed", "http://a/g", mPage.getAbsoluteURL ("../../g")); 256 } 257 258 322 public void test23 () throws ParserException 331 { 332 assertEquals ("test23 failed", "http://a/g", mPage.getAbsoluteURL ("../../../g")); 333 } 334 public void test24 () throws ParserException 335 { 336 assertEquals ("test24 failed", "http://a/g", mPage.getAbsoluteURL ("../../../../g")); 337 } 338 public void test25 () throws ParserException 339 { 340 assertEquals ("test25 failed", "http://a/./g", mPage.getAbsoluteURL ("/./g")); 341 } 342 public void test26 () throws ParserException 343 { 344 assertEquals ("test26 failed", "http://a/../g", mPage.getAbsoluteURL ("/../g")); 345 } 346 public void test27 () throws ParserException 347 { 348 assertEquals ("test27 failed", "http://a/b/c/g.", mPage.getAbsoluteURL ("g.")); 349 } 350 public void test28 () throws ParserException 351 { 352 assertEquals ("test28 failed", "http://a/b/c/.g", mPage.getAbsoluteURL (".g")); 353 } 354 public void test29 () throws ParserException 355 { 356 assertEquals ("test29 failed", "http://a/b/c/g..", mPage.getAbsoluteURL ("g..")); 357 } 358 public void test30 () throws ParserException 359 { 360 assertEquals ("test30 failed", "http://a/b/c/..g", mPage.getAbsoluteURL ("..g")); 361 } 362 public void test31 () throws ParserException 363 { 364 assertEquals ("test31 failed", "http://a/b/g", mPage.getAbsoluteURL ("./../g")); 365 } 366 public void test32 () throws ParserException 367 { 368 assertEquals ("test32 failed", "http://a/b/c/g/", mPage.getAbsoluteURL ("./g/.")); 369 } 370 public void test33 () throws ParserException 371 { 372 assertEquals ("test33 failed", "http://a/b/c/g/h", mPage.getAbsoluteURL ("g/./h")); 373 } 374 public void test34 () throws ParserException 375 { 376 assertEquals ("test34 failed", "http://a/b/c/h", mPage.getAbsoluteURL ("g/../h")); 377 } 378 public void test35 () throws ParserException 379 { 380 assertEquals ("test35 failed", "http://a/b/c/g;x=1/y", mPage.getAbsoluteURL ("g;x=1/./y")); 381 } 382 public void test36 () throws ParserException 383 { 384 assertEquals ("test36 failed", "http://a/b/c/y", mPage.getAbsoluteURL ("g;x=1/../y")); 385 } 386 public void test37 () throws ParserException 387 { 388 assertEquals ("test37 failed", "http://a/b/c/g?y/./x", mPage.getAbsoluteURL ("g?y/./x")); 389 } 390 public void test38 () throws ParserException 391 { 392 assertEquals ("test38 failed", "http://a/b/c/g?y/../x", mPage.getAbsoluteURL ("g?y/../x")); 393 } 394 public void test39 () throws ParserException 395 { 396 assertEquals ("test39 failed", "http://a/b/c/g#s/./x", mPage.getAbsoluteURL ("g#s/./x")); 397 } 398 public void test40 () throws ParserException 399 { 400 assertEquals ("test40 failed", "http://a/b/c/g#s/../x", mPage.getAbsoluteURL ("g#s/../x")); 401 } 402 public void test41 () throws ParserException 407 { 408 assertEquals ("test41 failed", "http://a/b/c/g", mPage.getAbsoluteURL ("http:g")); 409 } 410 411 } | Popular Tags |