X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Ftest%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fresult%2FURIParsedResultTestCase.java;h=ba54a32d768cf8ea67f4fed8edebcc0b29f8c9fe;hp=8376467ce9d3319cc37930a6d66ef7b8f47ca39c;hb=e5d03a79a458340b69a57914a352f0a8841cdf69;hpb=7d63fd5b1c4e8136b4ca5833445f9e587c85a400 diff --git a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java index 8376467c..ba54a32d 100644 --- a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java @@ -16,15 +16,53 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import org.junit.Assert; +import org.junit.Test; /** - * Tests {@link com.google.zxing.client.result.URIParsedResult}. + * Tests {@link URIParsedResult}. * * @author Sean Owen */ -public final class URIParsedResultTestCase extends TestCase { +public final class URIParsedResultTestCase extends Assert { + @Test + public void testBookmarkDocomo() { + doTest("MEBKM:URL:google.com;;", "http://google.com", null); + doTest("MEBKM:URL:http://google.com;;", "http://google.com", null); + doTest("MEBKM:URL:google.com;TITLE:Google;", "http://google.com", "Google"); + } + + @Test + public void testURI() { + doTest("google.com", "http://google.com", null); + doTest("http://google.com", "http://google.com", null); + doTest("https://google.com", "https://google.com", null); + doTest("google.com:443", "http://google.com:443", null); + doTest("https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com", + "https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com", + null); + } + + @Test + public void testURLTO() { + doTest("urlto::bar.com", "http://bar.com", null); + doTest("urlto::http://bar.com", "http://bar.com", null); + doTest("urlto:foo:bar.com", "http://bar.com", "foo"); + } + + @Test + public void testGarbage() { + String text = "Da65cV1g^>%^f0bAbPn1CJB6lV7ZY8hs0Sm:DXU0cd]GyEeWBz8]bUHLB"; + Result fakeResult = new Result(text, null, null, BarcodeFormat.QR_CODE); + ParsedResult result = ResultParser.parseResult(fakeResult); + assertSame(ParsedResultType.TEXT, result.getType()); + assertEquals(text, result.getDisplayResult()); + } + + @Test public void testIsPossiblyMalicious() { doTestIsPossiblyMalicious("http://google.com", false); doTestIsPossiblyMalicious("http://google.com@evil.com", true); @@ -34,7 +72,16 @@ public final class URIParsedResultTestCase extends TestCase { doTestIsPossiblyMalicious("http://google.com/foo@bar", false); } - private void doTestIsPossiblyMalicious(String uri, boolean expected) { + private static void doTest(String contents, String uri, String title) { + Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE); + ParsedResult result = ResultParser.parseResult(fakeResult); + assertSame(ParsedResultType.URI, result.getType()); + URIParsedResult uriResult = (URIParsedResult) result; + assertEquals(uri, uriResult.getURI()); + assertEquals(title, uriResult.getTitle()); + } + + private static void doTestIsPossiblyMalicious(String uri, boolean expected) { URIParsedResult result = new URIParsedResult(uri, null); assertEquals(expected, result.isPossiblyMaliciousURI()); }