Added golden results to all of our result parsing unit tests, uncovering and fixing a few subtle bugs in the process. I also expanded a few of them which were lean.

git-svn-id: https://zxing.googlecode.com/svn/trunk@796 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-12-19 20:20:54 +00:00
parent 280bb12e34
commit f50dcf6d27
3 changed files with 187 additions and 102 deletions

View file

@ -48,7 +48,7 @@ public abstract class ParsedResult {
}
public static void maybeAppend(String value, StringBuffer result) {
if (value != null) {
if (value != null && value.length() > 0) {
// Don't add a newline before the first value
if (result.length() > 0) {
result.append('\n');
@ -60,10 +60,12 @@ public abstract class ParsedResult {
public static void maybeAppend(String[] value, StringBuffer result) {
if (value != null) {
for (int i = 0; i < value.length; i++) {
if (result.length() > 0) {
result.append('\n');
if (value[i] != null && value[i].length() > 0) {
if (result.length() > 0) {
result.append('\n');
}
result.append(value[i]);
}
result.append(value[i]);
}
}
}

View file

@ -69,8 +69,8 @@ public final class URIParsedResult extends ParsedResult {
public String getDisplayResult() {
StringBuffer result = new StringBuffer();
maybeAppend(uri, result);
maybeAppend(title, result);
maybeAppend(uri, result);
return result.toString();
}
@ -83,6 +83,9 @@ public final class URIParsedResult extends ParsedResult {
if (protocolEnd < 0) {
// No protocol, assume http
uri = "http://" + uri;
} else if (isColonFollowedByPortNumber(uri, protocolEnd)) {
// Found a colon, but it looks like it is after the host, so the protocol is still missing
uri = "http://" + uri;
} else {
// Lowercase protocol to avoid problems
uri = uri.substring(0, protocolEnd).toLowerCase() + uri.substring(protocolEnd);
@ -90,5 +93,21 @@ public final class URIParsedResult extends ParsedResult {
return uri;
}
private static boolean isColonFollowedByPortNumber(String uri, int protocolEnd) {
int nextSlash = uri.indexOf('/', protocolEnd + 1);
if (nextSlash < 0) {
nextSlash = uri.length();
}
if (nextSlash <= protocolEnd + 1) {
return false;
}
for (int x = protocolEnd + 1; x < nextSlash; x++) {
if (uri.charAt(x) < '0' || uri.charAt(x) > '9') {
return false;
}
}
return true;
}
}

View file

@ -24,165 +24,224 @@ import junit.framework.TestCase;
* Tests {@link ParsedResult}.
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class ParsedReaderResultTestCase extends TestCase {
public void testTextType() {
doTestResult("foo", ParsedResultType.TEXT);
doTestResult("", ParsedResultType.TEXT);
doTestResult("This is a test", ParsedResultType.TEXT);
doTestResult("", "", ParsedResultType.TEXT);
doTestResult("foo", "foo", ParsedResultType.TEXT);
doTestResult("This is a test", "This is a test", ParsedResultType.TEXT);
doTestResult("This is a test\nwith newlines", "This is a test\nwith newlines",
ParsedResultType.TEXT);
doTestResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
ParsedResultType.TEXT);
}
public void testBookmarkType() {
doTestResult("MEBKM:URL:google.com;;", ParsedResultType.URI);
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", ParsedResultType.URI);
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", ParsedResultType.URI);
doTestResult("MEBKM:URL:http://google.com;;", ParsedResultType.URI);
doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedResultType.URI);
doTestResult("MEBKM:URL:google.com;;", "http://google.com", ParsedResultType.URI);
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", "Google\nhttp://google.com",
ParsedResultType.URI);
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
ParsedResultType.URI);
doTestResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedResultType.URI);
doTestResult("MEBKM:URL:HTTPS://google.com;;", "https://google.com", ParsedResultType.URI);
}
public void testURLTOType() {
doTestResult("urlto:foo:bar.com", ParsedResultType.URI);
doTestResult("URLTO:foo:bar.com", ParsedResultType.URI);
doTestResult("URLTO::bar.com", ParsedResultType.URI);
doTestResult("URLTO::http://bar.com", ParsedResultType.URI);
doTestResult("urlto:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
doTestResult("URLTO:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
doTestResult("URLTO::bar.com", "http://bar.com", ParsedResultType.URI);
doTestResult("URLTO::http://bar.com", "http://bar.com", ParsedResultType.URI);
}
public void testEmailType() {
doTestResult("MATMSG:TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS);
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
doTestResult("MATMSG:TO:srowen@example.org;;",
"srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org\nStuff",
ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
}
public void testEmailAddressType() {
doTestResult("srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("mailto:srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MAILTO:srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("srowen@example", ParsedResultType.TEXT);
doTestResult("srowen", ParsedResultType.TEXT);
doTestResult("Let's meet @ 2", ParsedResultType.TEXT);
doTestResult("srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("mailto:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("MAILTO:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
doTestResult("srowen@example", "srowen@example", ParsedResultType.TEXT);
doTestResult("srowen", "srowen", ParsedResultType.TEXT);
doTestResult("Let's meet @ 2", "Let's meet @ 2", ParsedResultType.TEXT);
}
public void testAddressBookType() {
doTestResult("MECARD:N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedResultType.ADDRESSBOOK);
doTestResult("N:Sean Owen;TEL:+12125551212;;", ParsedResultType.TEXT);
doTestResult("MECARD:N:Sean Owen;;", "Sean Owen", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", "Sean Owen\n+12125551212",
ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;",
"Sean Owen\n+12125551212\ngoogle.com", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
"Sean Owen\n+12125551212\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:ADR:76 9th Ave;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
"Sean Owen\n76 9th Ave\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:BDAY:19760520;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
"Sean Owen\nsrowen@example.org\ngoogle.com\n19760520", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:ORG:Google;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
"Sean Owen\nGoogle\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
doTestResult("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
"Sean Owen\nsrowen@example.org\ngoogle.com\nZXing Team", ParsedResultType.ADDRESSBOOK);
doTestResult("N:Sean Owen;TEL:+12125551212;;", "N:Sean Owen;TEL:+12125551212;;",
ParsedResultType.TEXT);
}
public void testAddressBookAUType() {
doTestResult("MEMORY:\r\n", ParsedResultType.ADDRESSBOOK);
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", ParsedResultType.ADDRESSBOOK);
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", ParsedResultType.ADDRESSBOOK);
doTestResult("MEMORY:\r\n", "", ParsedResultType.ADDRESSBOOK);
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", "Sean\nfoo", ParsedResultType.ADDRESSBOOK);
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK);
}
public void testUPC() {
doTestResult("123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("12345678901", ParsedResultType.TEXT);
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
}
public void testEAN() {
doTestResult("00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
doTestResult("00393158", ParsedResultType.TEXT);
doTestResult("5051140178499", ParsedResultType.PRODUCT, BarcodeFormat.EAN_13);
doTestResult("5051140178490", ParsedResultType.TEXT);
doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
doTestResult("00393158", "00393158", ParsedResultType.TEXT);
doTestResult("5051140178499", "5051140178499", ParsedResultType.PRODUCT, BarcodeFormat.EAN_13);
doTestResult("5051140178490", "5051140178490", ParsedResultType.TEXT);
}
public void testISBN() {
doTestResult("9784567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
doTestResult("9794567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
doTestResult("97845678901", ParsedResultType.TEXT);
doTestResult("97945678901", ParsedResultType.TEXT);
doTestResult("9784567890123", "9784567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
doTestResult("9794567890123", "9794567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
doTestResult("97845678901", "97845678901", ParsedResultType.TEXT);
doTestResult("97945678901", "97945678901", ParsedResultType.TEXT);
}
public void testURI() {
doTestResult("http://google.com", ParsedResultType.URI);
doTestResult("google.com", ParsedResultType.URI);
doTestResult("https://google.com", ParsedResultType.URI);
doTestResult("HTTP://google.com", ParsedResultType.URI);
doTestResult("http://google.com/foobar", ParsedResultType.URI);
doTestResult("https://google.com:443/foobar", ParsedResultType.URI);
doTestResult("google.com:443/foobar", ParsedResultType.URI);
doTestResult("http://google.com", "http://google.com", ParsedResultType.URI);
doTestResult("google.com", "http://google.com", ParsedResultType.URI);
doTestResult("https://google.com", "https://google.com", ParsedResultType.URI);
doTestResult("HTTP://google.com", "http://google.com", ParsedResultType.URI);
doTestResult("http://google.com/foobar", "http://google.com/foobar", ParsedResultType.URI);
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar",
ParsedResultType.URI);
doTestResult("google.com:443", "http://google.com:443", ParsedResultType.URI);
doTestResult("google.com:443/", "http://google.com:443/", ParsedResultType.URI);
doTestResult("google.com:443/foobar", "http://google.com:443/foobar", ParsedResultType.URI);
doTestResult("http://google.com:443/foobar", "http://google.com:443/foobar",
ParsedResultType.URI);
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar",
ParsedResultType.URI);
doTestResult("ftp://google.com/fake", "ftp://google.com/fake", ParsedResultType.URI);
doTestResult("gopher://google.com/obsolete", "gopher://google.com/obsolete",
ParsedResultType.URI);
}
public void testGeo() {
doTestResult("geo:1,2", ParsedResultType.GEO);
doTestResult("GEO:1,2", ParsedResultType.GEO);
doTestResult("geo:1,2,3", ParsedResultType.GEO);
doTestResult("geo:100.33,-32.3344,3.35", ParsedResultType.GEO);
doTestResult("geography", ParsedResultType.TEXT);
doTestResult("geo:1,2", "1.0, 2.0", ParsedResultType.GEO);
doTestResult("GEO:1,2", "1.0, 2.0", ParsedResultType.GEO);
doTestResult("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedResultType.GEO);
doTestResult("geo:100.33,-32.3344,3.35", "100.33, -32.3344, 3.35m", ParsedResultType.GEO);
doTestResult("geo", "geo", ParsedResultType.TEXT);
doTestResult("geography", "geography", ParsedResultType.TEXT);
}
public void testTel() {
doTestResult("tel:+15551212", ParsedResultType.TEL);
doTestResult("TEL:+15551212", ParsedResultType.TEL);
doTestResult("tel:212 555 1212", ParsedResultType.TEL);
doTestResult("tel:2125551212", ParsedResultType.TEL);
doTestResult("tel:212-555-1212", ParsedResultType.TEL);
doTestResult("telephone", ParsedResultType.TEXT);
doTestResult("tel:+15551212", "+15551212", ParsedResultType.TEL);
doTestResult("TEL:+15551212", "+15551212", ParsedResultType.TEL);
doTestResult("tel:212 555 1212", "212 555 1212", ParsedResultType.TEL);
doTestResult("tel:2125551212", "2125551212", ParsedResultType.TEL);
doTestResult("tel:212-555-1212", "212-555-1212", ParsedResultType.TEL);
doTestResult("tel", "tel", ParsedResultType.TEXT);
doTestResult("telephone", "telephone", ParsedResultType.TEXT);
}
public void testVCard() {
doTestResult("BEGIN:VCARD\r\nEND:VCARD", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\n" +
"END:VCARD", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD", ParsedResultType.URI); // yeah we end up guessing "URI" here
doTestResult("BEGIN:VCARD\r\nEND:VCARD", "", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
"Sean Owen\n123 Main St", ParsedResultType.ADDRESSBOOK);
doTestResult("BEGIN:VCARD", "begin:VCARD",
ParsedResultType.URI); // yeah we end up guessing "URI" here
}
public void testVEvent() {
// UTC times
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR", ParsedResultType.CALENDAR);
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
"foo\n20080504T123456Z\n20080505T234555Z",
ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT", ParsedResultType.CALENDAR);
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n20080504T123456Z\n20080505T234555Z",
ParsedResultType.CALENDAR);
// Local times
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
"DTEND:20080505T234555\r\nEND:VEVENT", ParsedResultType.CALENDAR);
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\n20080504T123456\n20080505T234555",
ParsedResultType.CALENDAR);
// Date only (all day event)
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
"DTEND:20080505\r\nEND:VEVENT", ParsedResultType.CALENDAR);
"DTEND:20080505\r\nEND:VEVENT", "foo\n20080504\n20080505", ParsedResultType.CALENDAR);
// Start time only
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
ParsedResultType.CALENDAR);
"foo\n20080504T123456Z", ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
ParsedResultType.CALENDAR);
"foo\n20080504T123456", ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
"foo\n20080504", ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
// Make sure illegal entries without newlines don't crash
doTestResult("BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
doTestResult(
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
"begin:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
ParsedResultType.URI);
doTestResult("BEGIN:VEVENT", ParsedResultType.URI); // See above note on why this is URI
// See above note on why this is URI
doTestResult("BEGIN:VEVENT", "begin:VEVENT", ParsedResultType.URI);
}
public void testSMS() {
doTestResult("sms:+15551212", ParsedResultType.SMS);
doTestResult("SMS:+15551212", ParsedResultType.SMS);
doTestResult("SMSTO:+15551212", ParsedResultType.SMS);
doTestResult("smsto:+15551212", ParsedResultType.SMS);
doTestResult("sms:+15551212;via=999333", ParsedResultType.SMS);
doTestResult("sms:+15551212?subject=foo&body=bar", ParsedResultType.SMS);
doTestResult("sms:+15551212:subject", ParsedResultType.SMS);
doTestResult("sms:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("SMS:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("SMSTO:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("smsto:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("sms:+15551212;via=999333", "+15551212\n999333", ParsedResultType.SMS);
doTestResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
doTestResult("sms:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
doTestResult("sms:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
// Need to handle question mark in the subject
doTestResult("sms:+15551212:What's up?", ParsedResultType.SMS);
doTestResult("sms:212-555-1212:Here's a longer message. Should be fine.", ParsedResultType.SMS);
doTestResult("sms:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
// Need to handle colon in the subject
doTestResult("sms:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
ParsedResultType.SMS);
doTestResult("sms:212-555-1212:Here's a longer message. Should be fine.",
"212-555-1212\nHere's a longer message. Should be fine.",
ParsedResultType.SMS);
}
public void testMMS() {
doTestResult("mms:+15551212", ParsedResultType.SMS);
doTestResult("MMS:+15551212", ParsedResultType.SMS);
doTestResult("MMSTO:+15551212", ParsedResultType.SMS);
doTestResult("mmsto:+15551212", ParsedResultType.SMS);
doTestResult("mms:+15551212;via=999333", ParsedResultType.SMS);
doTestResult("mms:+15551212?subject=foo&body=bar", ParsedResultType.SMS);
doTestResult("mms:+15551212:subject", ParsedResultType.SMS);
doTestResult("mms:+15551212:What's up?", ParsedResultType.SMS);
doTestResult("mms:212-555-1212:Here's a longer message. Should be fine.", ParsedResultType.SMS);
doTestResult("mms:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("MMS:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("MMSTO:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("mmsto:+15551212", "+15551212", ParsedResultType.SMS);
doTestResult("mms:+15551212;via=999333", "+15551212\n999333", ParsedResultType.SMS);
doTestResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
doTestResult("mms:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
doTestResult("mms:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
doTestResult("mms:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
doTestResult("mms:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
ParsedResultType.SMS);
doTestResult("mms:212-555-1212:Here's a longer message. Should be fine.",
"212-555-1212\nHere's a longer message. Should be fine.", ParsedResultType.SMS);
}
/*
@ -218,15 +277,20 @@ public final class ParsedReaderResultTestCase extends TestCase {
}
*/
private static void doTestResult(String text, ParsedResultType type) {
doTestResult(text, type, null);
private static void doTestResult(String contents, String goldenResult, ParsedResultType type) {
doTestResult(contents, goldenResult, type, null);
}
private static void doTestResult(String text, ParsedResultType type, BarcodeFormat format) {
Result fakeResult = new Result(text, null, null, format);
private static void doTestResult(String contents, String goldenResult, ParsedResultType type,
BarcodeFormat format) {
Result fakeResult = new Result(contents, null, null, format);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertNotNull(result);
assertEquals(type, result.getType());
String displayResult = result.getDisplayResult();
assertTrue("Expected:\n" + goldenResult + "\nbut got:\n" + displayResult,
goldenResult.equals(displayResult));
}
/*