mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 20:32:34 +00:00
move all Result to RXingResult
This commit is contained in:
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link AddressBookParsedResult}.
|
||||
* Tests {@link AddressBookParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookParsedResultTestCase extends Assert {
|
||||
public final class AddressBookParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testAddressBookDocomo() {
|
||||
@@ -149,21 +149,21 @@ public final class AddressBookParsedResultTestCase extends Assert {
|
||||
String[] urls,
|
||||
String birthday,
|
||||
String note) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
assertEquals(title, addressResult.getTitle());
|
||||
assertArrayEquals(names, addressResult.getNames());
|
||||
assertEquals(pronunciation, addressResult.getPronunciation());
|
||||
assertArrayEquals(addresses, addressResult.getAddresses());
|
||||
assertArrayEquals(emails, addressResult.getEmails());
|
||||
assertArrayEquals(phoneNumbers, addressResult.getPhoneNumbers());
|
||||
assertArrayEquals(phoneTypes, addressResult.getPhoneTypes());
|
||||
assertEquals(org, addressResult.getOrg());
|
||||
assertArrayEquals(urls, addressResult.getURLs());
|
||||
assertEquals(birthday, addressResult.getBirthday());
|
||||
assertEquals(note, addressResult.getNote());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.ADDRESSBOOK, result.getType());
|
||||
AddressBookParsedRXingResult addressRXingResult = (AddressBookParsedRXingResult) result;
|
||||
assertEquals(title, addressRXingResult.getTitle());
|
||||
assertArrayEquals(names, addressRXingResult.getNames());
|
||||
assertEquals(pronunciation, addressRXingResult.getPronunciation());
|
||||
assertArrayEquals(addresses, addressRXingResult.getAddresses());
|
||||
assertArrayEquals(emails, addressRXingResult.getEmails());
|
||||
assertArrayEquals(phoneNumbers, addressRXingResult.getPhoneNumbers());
|
||||
assertArrayEquals(phoneTypes, addressRXingResult.getPhoneTypes());
|
||||
assertEquals(org, addressRXingResult.getOrg());
|
||||
assertArrayEquals(urls, addressRXingResult.getURLs());
|
||||
assertEquals(birthday, addressRXingResult.getBirthday());
|
||||
assertEquals(note, addressRXingResult.getNote());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -28,11 +28,11 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link CalendarParsedResult}.
|
||||
* Tests {@link CalendarParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CalendarParsedResultTestCase extends Assert {
|
||||
public final class CalendarParsedRXingResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
@@ -142,11 +142,11 @@ public final class CalendarParsedResultTestCase extends Assert {
|
||||
@Test
|
||||
public void testBadGeo() {
|
||||
// Not parsed as VEVENT
|
||||
Result fakeResult = new Result("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
RXingResult fakeRXingResult = new RXingResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"GEO:-12.345\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR", null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,20 +223,20 @@ public final class CalendarParsedResultTestCase extends Assert {
|
||||
String[] attendees,
|
||||
double latitude,
|
||||
double longitude) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.CALENDAR, result.getType());
|
||||
CalendarParsedResult calResult = (CalendarParsedResult) result;
|
||||
assertEquals(description, calResult.getDescription());
|
||||
assertEquals(summary, calResult.getSummary());
|
||||
assertEquals(location, calResult.getLocation());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.CALENDAR, result.getType());
|
||||
CalendarParsedRXingResult calRXingResult = (CalendarParsedRXingResult) result;
|
||||
assertEquals(description, calRXingResult.getDescription());
|
||||
assertEquals(summary, calRXingResult.getSummary());
|
||||
assertEquals(location, calRXingResult.getLocation());
|
||||
DateFormat dateFormat = makeGMTFormat();
|
||||
assertEquals(startString, dateFormat.format(calResult.getStartTimestamp()));
|
||||
assertEquals(endString, calResult.getEndTimestamp() < 0L ? null : dateFormat.format(calResult.getEndTimestamp()));
|
||||
assertEquals(organizer, calResult.getOrganizer());
|
||||
assertArrayEquals(attendees, calResult.getAttendees());
|
||||
assertEqualOrNaN(latitude, calResult.getLatitude());
|
||||
assertEqualOrNaN(longitude, calResult.getLongitude());
|
||||
assertEquals(startString, dateFormat.format(calRXingResult.getStartTimestamp()));
|
||||
assertEquals(endString, calRXingResult.getEndTimestamp() < 0L ? null : dateFormat.format(calRXingResult.getEndTimestamp()));
|
||||
assertEquals(organizer, calRXingResult.getOrganizer());
|
||||
assertArrayEquals(attendees, calRXingResult.getAttendees());
|
||||
assertEqualOrNaN(latitude, calRXingResult.getLatitude());
|
||||
assertEqualOrNaN(longitude, calRXingResult.getLongitude());
|
||||
}
|
||||
|
||||
private static void assertEqualOrNaN(double expected, double actual) {
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link EmailAddressParsedResult}.
|
||||
* Tests {@link EmailAddressParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailAddressParsedResultTestCase extends Assert {
|
||||
public final class EmailAddressParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEmailAddress() {
|
||||
@@ -107,15 +107,15 @@ public final class EmailAddressParsedResultTestCase extends Assert {
|
||||
String[] bccs,
|
||||
String subject,
|
||||
String body) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.EMAIL_ADDRESS, result.getType());
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
assertArrayEquals(tos, emailResult.getTos());
|
||||
assertArrayEquals(ccs, emailResult.getCCs());
|
||||
assertArrayEquals(bccs, emailResult.getBCCs());
|
||||
assertEquals(subject, emailResult.getSubject());
|
||||
assertEquals(body, emailResult.getBody());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.EMAIL_ADDRESS, result.getType());
|
||||
EmailAddressParsedRXingResult emailRXingResult = (EmailAddressParsedRXingResult) result;
|
||||
assertArrayEquals(tos, emailRXingResult.getTos());
|
||||
assertArrayEquals(ccs, emailRXingResult.getCCs());
|
||||
assertArrayEquals(bccs, emailRXingResult.getBCCs());
|
||||
assertEquals(subject, emailRXingResult.getSubject());
|
||||
assertEquals(body, emailRXingResult.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,15 +38,15 @@ import java.util.Map;
|
||||
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
|
||||
* @author Agustín Delgado, Servinform, S.A.
|
||||
*/
|
||||
public final class ExpandedProductParsedResultTestCase extends Assert {
|
||||
public final class ExpandedProductParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testRSSExpanded() {
|
||||
Map<String,String> uncommonAIs = new HashMap<>();
|
||||
uncommonAIs.put("123", "544654");
|
||||
Result result =
|
||||
new Result("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED);
|
||||
ExpandedProductParsedResult o = new ExpandedProductResultParser().parse(result);
|
||||
RXingResult result =
|
||||
new RXingResult("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED);
|
||||
ExpandedProductParsedRXingResult o = new ExpandedProductRXingResultParser().parse(result);
|
||||
assertNotNull(o);
|
||||
assertEquals("66546", o.getProductID());
|
||||
assertNull(o.getSscc());
|
||||
|
||||
@@ -19,16 +19,16 @@ package com.google.zxing.client.result;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link GeoParsedResult}.
|
||||
* Tests {@link GeoParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GeoParsedResultTestCase extends Assert {
|
||||
public final class GeoParsedRXingResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
@@ -47,15 +47,15 @@ public final class GeoParsedResultTestCase extends Assert {
|
||||
double altitude,
|
||||
String query,
|
||||
String uri) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.GEO, result.getType());
|
||||
GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
assertEquals(latitude, geoResult.getLatitude(), EPSILON);
|
||||
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
|
||||
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
|
||||
assertEquals(query, geoResult.getQuery());
|
||||
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoResult.getGeoURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.GEO, result.getType());
|
||||
GeoParsedRXingResult geoRXingResult = (GeoParsedRXingResult) result;
|
||||
assertEquals(latitude, geoRXingResult.getLatitude(), EPSILON);
|
||||
assertEquals(longitude, geoRXingResult.getLongitude(), EPSILON);
|
||||
assertEquals(altitude, geoRXingResult.getAltitude(), EPSILON);
|
||||
assertEquals(query, geoRXingResult.getQuery());
|
||||
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoRXingResult.getGeoURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ISBNParsedResult}.
|
||||
* Tests {@link ISBNParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ISBNParsedResultTestCase extends Assert {
|
||||
public final class ISBNParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
@@ -34,11 +34,11 @@ public final class ISBNParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.EAN_13);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ISBN, result.getType());
|
||||
ISBNParsedResult isbnResult = (ISBNParsedResult) result;
|
||||
assertEquals(contents, isbnResult.getISBN());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.EAN_13);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.ISBN, result.getType());
|
||||
ISBNParsedRXingResult isbnRXingResult = (ISBNParsedRXingResult) result;
|
||||
assertEquals(contents, isbnRXingResult.getISBN());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -28,12 +28,12 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link ParsedResult}.
|
||||
* Tests {@link ParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ParsedReaderResultTestCase extends Assert {
|
||||
public final class ParsedReaderRXingResultTestCase extends Assert {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -43,208 +43,208 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testTextType() {
|
||||
doTestResult("", "", ParsedResultType.TEXT);
|
||||
doTestResult("foo", "foo", ParsedResultType.TEXT);
|
||||
doTestResult("Hi.", "Hi.", 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.",
|
||||
doTestRXingResult("", "", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("foo", "foo", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("Hi.", "Hi.", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("This is a test", "This is a test", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("This is a test\nwith newlines", "This is a test\nwith newlines",
|
||||
ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("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);
|
||||
ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookmarkType() {
|
||||
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);
|
||||
doTestRXingResult("MEBKM:URL:google.com;;", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:google.com;TITLE:Google;;", "Google\nhttp://google.com",
|
||||
ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
|
||||
ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:HTTPS://google.com;;", "HTTPS://google.com", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURLTOType() {
|
||||
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);
|
||||
doTestRXingResult("urlto:foo:bar.com", "foo\nhttp://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO:foo:bar.com", "foo\nhttp://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO::bar.com", "http://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO::http://bar.com", "http://bar.com", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailType() {
|
||||
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);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;;",
|
||||
"srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org\nStuff",
|
||||
ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailAddressType() {
|
||||
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.EMAIL_ADDRESS);
|
||||
doTestResult("srowen", "srowen", ParsedResultType.TEXT);
|
||||
doTestResult("Let's meet @ 2", "Let's meet @ 2", ParsedResultType.TEXT);
|
||||
doTestRXingResult("srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("mailto:srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MAILTO:srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("srowen@example", "srowen@example", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("srowen", "srowen", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("Let's meet @ 2", "Let's meet @ 2", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookType() {
|
||||
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);
|
||||
doTestRXingResult("MECARD:N:Sean Owen;;", "Sean Owen", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;;", "Sean Owen\n+12125551212",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;",
|
||||
"Sean Owen\n+12125551212\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n+12125551212\nsrowen@example.org\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("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", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:BDAY:19760520;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\n19760520", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:ORG:Google;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\nsrowen@example.org\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\nZXing Team", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("N:Sean Owen;TEL:+12125551212;;", "N:Sean Owen;TEL:+12125551212;;",
|
||||
ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookAUType() {
|
||||
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);
|
||||
doTestRXingResult("MEMORY:\r\n", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MEMORY:foo\r\nNAME1:Sean\r\n", "Sean\nfoo", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBizcard() {
|
||||
doTestResult("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12225551212;E:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\n123 Main St\n+12225551212\nsrowen@example.org", ParsedResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12225551212;E:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\n123 Main St\n+12225551212\nsrowen@example.org", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCA() {
|
||||
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
|
||||
doTestRXingResult("123456789012", "123456789012", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestRXingResult("1234567890123", "1234567890123", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestRXingResult("12345678901", "12345678901", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCE() {
|
||||
doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E);
|
||||
doTestRXingResult("01234565", "01234565", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_E);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEAN() {
|
||||
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);
|
||||
doTestRXingResult("00393157", "00393157", ParsedRXingResultType.PRODUCT, BarcodeFormat.EAN_8);
|
||||
doTestRXingResult("00393158", "00393158", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("5051140178499", "5051140178499", ParsedRXingResultType.PRODUCT, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("5051140178490", "5051140178490", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
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);
|
||||
doTestRXingResult("9784567890123", "9784567890123", ParsedRXingResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("9794567890123", "9794567890123", ParsedRXingResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("97845678901", "97845678901", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("97945678901", "97945678901", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURI() {
|
||||
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);
|
||||
doTestRXingResult("http://google.com", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com", "https://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("HTTP://google.com", "HTTP://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("http://google.com/foobar", "http://google.com/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443", "http://google.com:443", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443/", "http://google.com:443/", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443/foobar", "http://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("http://google.com:443/foobar", "http://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("ftp://google.com/fake", "ftp://google.com/fake", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("gopher://google.com/obsolete", "gopher://google.com/obsolete", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeo() {
|
||||
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:80.33,-32.3344,3.35", "80.33, -32.3344, 3.35m", ParsedResultType.GEO);
|
||||
doTestResult("geo", "geo", ParsedResultType.TEXT);
|
||||
doTestResult("geography", "geography", ParsedResultType.TEXT);
|
||||
doTestRXingResult("geo:1,2", "1.0, 2.0", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("GEO:1,2", "1.0, 2.0", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo:80.33,-32.3344,3.35", "80.33, -32.3344, 3.35m", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo", "geo", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("geography", "geography", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
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);
|
||||
doTestRXingResult("tel:+15551212", "+15551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("TEL:+15551212", "+15551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:212 555 1212", "212 555 1212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:2125551212", "2125551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:212-555-1212", "212-555-1212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel", "tel", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("telephone", "telephone", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCard() {
|
||||
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", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nEND:VCARD", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
"Sean Owen\n123 Main St", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVEvent() {
|
||||
// UTC times
|
||||
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
doTestRXingResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" + formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Local times
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
|
||||
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Date only (all day event)
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
|
||||
"DTEND:20080505\r\nEND:VEVENT", "foo\n" + formatDate(2008, 5, 4) + "\n" +
|
||||
formatDate(2008, 5, 5),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Start time only
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n" + formatDate(2008, 5, 4), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n" + formatDate(2008, 5, 4), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedRXingResultType.TEXT);
|
||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not CALENDAR
|
||||
// Make sure illegal entries without newlines don't crash
|
||||
doTestResult(
|
||||
doTestRXingResult(
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
ParsedResultType.URI);
|
||||
ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
private static String formatDate(int year, int month, int day) {
|
||||
@@ -263,68 +263,68 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
doTestResult("sms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("SMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("SMS:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212;via=999333", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMSTO() {
|
||||
doTestResult("SMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
doTestRXingResult("SMSTO:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:subject", "+15551212\nsubject", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:My message", "+15551212\nMy message", ParsedRXingResultType.SMS);
|
||||
// Need to handle question mark in the subject
|
||||
doTestResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedRXingResultType.SMS);
|
||||
// Need to handle colon in the subject
|
||||
doTestResult("smsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("smsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
doTestRXingResult("smsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.",
|
||||
ParsedResultType.SMS);
|
||||
ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMS() {
|
||||
doTestResult("mms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("MMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("MMS:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212;via=999333", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMSTO() {
|
||||
doTestResult("MMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("mmsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.", ParsedResultType.SMS);
|
||||
doTestRXingResult("MMSTO:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:subject", "+15551212\nsubject", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:My message", "+15551212\nMy message", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type) {
|
||||
doTestResult(contents, goldenResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
|
||||
private static void doTestRXingResult(String contents,
|
||||
String goldenRXingResult,
|
||||
ParsedRXingResultType type) {
|
||||
doTestRXingResult(contents, goldenRXingResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type,
|
||||
private static void doTestRXingResult(String contents,
|
||||
String goldenRXingResult,
|
||||
ParsedRXingResultType type,
|
||||
BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, format);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertNotNull(result);
|
||||
assertSame(type, result.getType());
|
||||
|
||||
String displayResult = result.getDisplayResult();
|
||||
assertEquals(goldenResult, displayResult);
|
||||
String displayRXingResult = result.getDisplayRXingResult();
|
||||
assertEquals(goldenRXingResult, displayRXingResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ProductParsedResult}.
|
||||
* Tests {@link ProductParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ProductParsedResultTestCase extends Assert {
|
||||
public final class ProductParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testProduct() {
|
||||
@@ -37,12 +37,12 @@ public final class ProductParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String normalized, BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.PRODUCT, result.getType());
|
||||
ProductParsedResult productResult = (ProductParsedResult) result;
|
||||
assertEquals(contents, productResult.getProductID());
|
||||
assertEquals(normalized, productResult.getNormalizedProductID());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, format);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.PRODUCT, result.getType());
|
||||
ProductParsedRXingResult productRXingResult = (ProductParsedRXingResult) result;
|
||||
assertEquals(contents, productRXingResult.getProductID());
|
||||
assertEquals(normalized, productRXingResult.getNormalizedProductID());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link SMSParsedResult}.
|
||||
* Tests {@link SMSParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSParsedResultTestCase extends Assert {
|
||||
public final class SMSMMSParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
@@ -52,15 +52,15 @@ public final class SMSMMSParsedResultTestCase extends Assert {
|
||||
String body,
|
||||
String via,
|
||||
String parsedURI) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.SMS, result.getType());
|
||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsResult.getNumbers());
|
||||
assertEquals(subject, smsResult.getSubject());
|
||||
assertEquals(body, smsResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsResult.getVias());
|
||||
assertEquals(parsedURI, smsResult.getSMSURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.SMS, result.getType());
|
||||
SMSParsedRXingResult smsRXingResult = (SMSParsedRXingResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsRXingResult.getNumbers());
|
||||
assertEquals(subject, smsRXingResult.getSubject());
|
||||
assertEquals(body, smsRXingResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsRXingResult.getVias());
|
||||
assertEquals(parsedURI, smsRXingResult.getSMSURI());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link TelParsedResult}.
|
||||
* Tests {@link TelParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TelParsedResultTestCase extends Assert {
|
||||
public final class TelParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
@@ -35,13 +35,13 @@ public final class TelParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String number, String title) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEL, result.getType());
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
assertEquals(number, telResult.getNumber());
|
||||
assertEquals(title, telResult.getTitle());
|
||||
assertEquals("tel:" + number, telResult.getTelURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEL, result.getType());
|
||||
TelParsedRXingResult telRXingResult = (TelParsedRXingResult) result;
|
||||
assertEquals(number, telRXingResult.getNumber());
|
||||
assertEquals(title, telRXingResult.getTitle());
|
||||
assertEquals("tel:" + number, telRXingResult.getTelURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link URIParsedResult}.
|
||||
* Tests {@link URIParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URIParsedResultTestCase extends Assert {
|
||||
public final class URIParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBookmarkDocomo() {
|
||||
@@ -116,25 +116,25 @@ public final class URIParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
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());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.URI, result.getType());
|
||||
URIParsedRXingResult uriRXingResult = (URIParsedRXingResult) result;
|
||||
assertEquals(uri, uriRXingResult.getURI());
|
||||
assertEquals(title, uriRXingResult.getTitle());
|
||||
}
|
||||
|
||||
private static void doTestNotUri(String text) {
|
||||
Result fakeResult = new Result(text, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
assertEquals(text, result.getDisplayResult());
|
||||
RXingResult fakeRXingResult = new RXingResult(text, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEXT, result.getType());
|
||||
assertEquals(text, result.getDisplayRXingResult());
|
||||
}
|
||||
|
||||
private static void doTestIsPossiblyMalicious(String uri, boolean malicious) {
|
||||
Result fakeResult = new Result(uri, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(malicious ? ParsedResultType.TEXT : ParsedResultType.URI, result.getType());
|
||||
RXingResult fakeRXingResult = new RXingResult(uri, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(malicious ? ParsedRXingResultType.TEXT : ParsedRXingResultType.URI, result.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link VINParsedResult}.
|
||||
* Tests {@link VINParsedRXingResult}.
|
||||
*/
|
||||
public final class VINParsedResultTestCase extends Assert {
|
||||
public final class VINParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNotVIN() {
|
||||
Result fakeResult = new Result("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
fakeResult = new Result("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
|
||||
result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
RXingResult fakeRXingResult = new RXingResult("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertEquals(ParsedRXingResultType.TEXT, result.getType());
|
||||
fakeRXingResult = new RXingResult("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
|
||||
result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertEquals(ParsedRXingResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,18 +53,18 @@ public final class VINParsedResultTestCase extends Assert {
|
||||
int year,
|
||||
char plant,
|
||||
String sequential) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.VIN, result.getType());
|
||||
VINParsedResult vinResult = (VINParsedResult) result;
|
||||
assertEquals(wmi, vinResult.getWorldManufacturerID());
|
||||
assertEquals(vds, vinResult.getVehicleDescriptorSection());
|
||||
assertEquals(vis, vinResult.getVehicleIdentifierSection());
|
||||
assertEquals(country, vinResult.getCountryCode());
|
||||
assertEquals(attributes, vinResult.getVehicleAttributes());
|
||||
assertEquals(year, vinResult.getModelYear());
|
||||
assertEquals(plant, vinResult.getPlantCode());
|
||||
assertEquals(sequential, vinResult.getSequentialNumber());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.CODE_39);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.VIN, result.getType());
|
||||
VINParsedRXingResult vinRXingResult = (VINParsedRXingResult) result;
|
||||
assertEquals(wmi, vinRXingResult.getWorldManufacturerID());
|
||||
assertEquals(vds, vinRXingResult.getVehicleDescriptorSection());
|
||||
assertEquals(vis, vinRXingResult.getVehicleIdentifierSection());
|
||||
assertEquals(country, vinRXingResult.getCountryCode());
|
||||
assertEquals(attributes, vinRXingResult.getVehicleAttributes());
|
||||
assertEquals(year, vinRXingResult.getModelYear());
|
||||
assertEquals(plant, vinRXingResult.getPlantCode());
|
||||
assertEquals(sequential, vinRXingResult.getSequentialNumber());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link WifiParsedResult}.
|
||||
* Tests {@link WifiParsedRXingResult}.
|
||||
*
|
||||
* @author Vikram Aggarwal
|
||||
*/
|
||||
public final class WifiParsedResultTestCase extends Assert {
|
||||
public final class WifiParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNoPassword() {
|
||||
@@ -79,15 +79,15 @@ public final class WifiParsedResultTestCase extends Assert {
|
||||
String ssid,
|
||||
String password,
|
||||
String type) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
|
||||
// Ensure it is a wifi code
|
||||
assertSame(ParsedResultType.WIFI, result.getType());
|
||||
WifiParsedResult wifiResult = (WifiParsedResult) result;
|
||||
assertSame(ParsedRXingResultType.WIFI, result.getType());
|
||||
WifiParsedRXingResult wifiRXingResult = (WifiParsedRXingResult) result;
|
||||
|
||||
assertEquals(ssid, wifiResult.getSsid());
|
||||
assertEquals(password, wifiResult.getPassword());
|
||||
assertEquals(type, wifiResult.getNetworkEncryption());
|
||||
assertEquals(ssid, wifiRXingResult.getSsid());
|
||||
assertEquals(password, wifiRXingResult.getPassword());
|
||||
assertEquals(type, wifiRXingResult.getNetworkEncryption());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user