move client test cases

This commit is contained in:
Henry Schimke
2022-09-01 14:12:20 -05:00
parent 177c8dbfb4
commit 9290e560f1
20 changed files with 0 additions and 759 deletions

View File

@@ -0,0 +1,169 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link AddressBookParsedRXingResult}.
*
* @author Sean Owen
*/
public final class AddressBookParsedRXingResultTestCase extends Assert {
@Test
public void testAddressBookDocomo() {
doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"},
null, null, null, null, null, null, null, null, null);
doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null, null,
new String[] {"google.com"}, null, "ZXing Team");
}
@Test
public void testAddressBookAU() {
doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, null, "foo");
}
@Test
public void testVCard() {
doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"},
null, null, null, null, null, null, null);
}
@Test
public void testVCardFullN() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;T;Mr.;Esq.\r\nEND:VCARD",
null, new String[] {"Mr. Sean T Owen Esq."}, null, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardFullN2() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean;;;\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardFullN3() {
doTest("BEGIN:VCARD\r\nVERSION:2.1\r\nN:;Sean;;;\r\nEND:VCARD",
null, new String[] {"Sean"}, null, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardCaseInsensitive() {
doTest("begin:vcard\r\nadr;HOME:123 Main St\r\nVersion:2.1\r\nn:Owen;Sean\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"},
null, null, null, null, null, null, null);
}
@Test
public void testEscapedVCard() {
doTest("BEGIN:VCARD\r\nADR;HOME:123\\;\\\\ Main\\, St\\nHome\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, new String[] {"123;\\ Main, St\nHome"},
null, null, null, null, null, null, null);
}
@Test
public void testBizcard() {
doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, new String[] {"srowen@example.org"},
new String[] {"+12125551212"}, null, "Google", null, null, null);
}
@Test
public void testSeveralAddresses() {
doTest("MECARD:N:Foo Bar;ORG:Company;TEL:5555555555;EMAIL:foo.bar@xyz.com;ADR:City, 10001;" +
"ADR:City, 10001;NOTE:This is the memo.;;",
null, new String[] {"Foo Bar"}, null, new String[] {"City, 10001", "City, 10001"},
new String[] {"foo.bar@xyz.com"},
new String[] {"5555555555" }, null, "Company", null, null, "This is the memo.");
}
@Test
public void testQuotedPrintable() {
doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
"=38=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
"=4F=20=36=39=39=\r\n" +
"=39=39;;;\r\nEND:VCARD",
null, null, null, new String[] {"88 Lynbrook\r\nCO 69999"},
null, null, null, null, null, null, null);
}
@Test
public void testVCardEscape() {
doTest("BEGIN:VCARD\r\nNOTE:foo\\nbar\r\nEND:VCARD",
null, null, null, null, null, null, null, null, null, null, "foo\nbar");
doTest("BEGIN:VCARD\r\nNOTE:foo\\;bar\r\nEND:VCARD",
null, null, null, null, null, null, null, null, null, null, "foo;bar");
doTest("BEGIN:VCARD\r\nNOTE:foo\\\\bar\r\nEND:VCARD",
null, null, null, null, null, null, null, null, null, null, "foo\\bar");
doTest("BEGIN:VCARD\r\nNOTE:foo\\,bar\r\nEND:VCARD",
null, null, null, null, null, null, null, null, null, null, "foo,bar");
}
@Test
public void testVCardValueURI() {
doTest("BEGIN:VCARD\r\nTEL;VALUE=uri:tel:+1-555-555-1212\r\nEND:VCARD",
null, null, null, null, null, new String[] { "+1-555-555-1212" }, new String[] { null },
null, null, null, null);
doTest("BEGIN:VCARD\r\nN;VALUE=text:Owen;Sean\r\nEND:VCARD",
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null, null);
}
@Test
public void testVCardTypes() {
doTest("BEGIN:VCARD\r\nTEL;HOME:\r\nTEL;WORK:10\r\nTEL:20\r\nTEL;CELL:30\r\nEND:VCARD",
null, null, null, null, null, new String[] { "10", "20", "30" },
new String[] { "WORK", null, "CELL" }, null, null, null, null);
}
private static void doTest(String contents,
String title,
String[] names,
String pronunciation,
String[] addresses,
String[] emails,
String[] phoneNumbers,
String[] phoneTypes,
String org,
String[] urls,
String birthday,
String note) {
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());
}
}

View File

@@ -0,0 +1,250 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;
/**
* Tests {@link CalendarParsedRXingResult}.
*
* @author Sean Owen
*/
public final class CalendarParsedRXingResultTestCase extends Assert {
private static final double EPSILON = 1.0E-10;
private static DateFormat makeGMTFormat() {
DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format;
}
@Before
public void setUp() {
Locale.setDefault(Locale.ENGLISH);
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@Test
public void testStartEnd() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", "20080505T234555Z");
}
@Test
public void testNoVCalendar() {
doTest(
"BEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\n" +
"END:VEVENT",
null, null, null, "20080504T123456Z", "20080505T234555Z");
}
@Test
public void testStart() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", null);
}
@Test
public void testDuration() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DURATION:P1D\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", "20080505T123456Z");
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DURATION:P1DT2H3M4S\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", "20080505T143800Z");
}
@Test
public void testSummary() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"SUMMARY:foo\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, "foo", null, "20080504T123456Z", null);
}
@Test
public void testLocation() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"LOCATION:Miami\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, "Miami", "20080504T123456Z", null);
}
@Test
public void testDescription() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DESCRIPTION:This is a test\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
"This is a test", null, null, "20080504T123456Z", null);
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"DESCRIPTION:This is a test\r\n\t with a continuation\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
"This is a test with a continuation", null, null, "20080504T123456Z", null);
}
@Test
public void testGeo() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"GEO:-12.345;-45.678\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", null, null, null, -12.345, -45.678);
}
@Test
public void testBadGeo() {
// Not parsed as VEVENT
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);
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
assertSame(ParsedRXingResultType.TEXT, result.getType());
}
@Test
public void testOrganizer() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"ORGANIZER:mailto:bob@example.org\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", null, "bob@example.org", null, Double.NaN, Double.NaN);
}
@Test
public void testAttendees() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
"DTSTART:20080504T123456Z\r\n" +
"ATTENDEE:mailto:bob@example.org\r\n" +
"ATTENDEE:mailto:alice@example.org\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, null, null, "20080504T123456Z", null, null,
new String[] {"bob@example.org", "alice@example.org"}, Double.NaN, Double.NaN);
}
@Test
public void testVEventEscapes() {
doTest("BEGIN:VEVENT\n" +
"CREATED:20111109T110351Z\n" +
"LAST-MODIFIED:20111109T170034Z\n" +
"DTSTAMP:20111109T170034Z\n" +
"UID:0f6d14ef-6cb7-4484-9080-61447ccdf9c2\n" +
"SUMMARY:Summary line\n" +
"CATEGORIES:Private\n" +
"DTSTART;TZID=Europe/Vienna:20111110T110000\n" +
"DTEND;TZID=Europe/Vienna:20111110T120000\n" +
"LOCATION:Location\\, with\\, escaped\\, commas\n" +
"DESCRIPTION:Meeting with a friend\\nlook at homepage first\\n\\n\n" +
" \\n\n" +
"SEQUENCE:1\n" +
"X-MOZ-GENERATION:1\n" +
"END:VEVENT",
"Meeting with a friend\nlook at homepage first\n\n\n \n",
"Summary line",
"Location, with, escaped, commas",
"20111110T110000Z",
"20111110T120000Z");
}
@Test
public void testAllDayValueDate() {
doTest("BEGIN:VEVENT\n" +
"DTSTART;VALUE=DATE:20111110\n" +
"DTEND;VALUE=DATE:20111110\n" +
"END:VEVENT",
null, null, null, "20111110T000000Z", "20111110T000000Z");
}
private static void doTest(String contents,
String description,
String summary,
String location,
String startString,
String endString) {
doTest(contents, description, summary, location, startString, endString, null, null, Double.NaN, Double.NaN);
}
private static void doTest(String contents,
String description,
String summary,
String location,
String startString,
String endString,
String organizer,
String[] attendees,
double latitude,
double longitude) {
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(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) {
if (Double.isNaN(expected)) {
assertTrue(Double.isNaN(actual));
} else {
assertEquals(expected, actual, EPSILON);
}
}
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link EmailAddressParsedRXingResult}.
*
* @author Sean Owen
*/
public final class EmailAddressParsedRXingResultTestCase extends Assert {
@Test
public void testEmailAddress() {
doTest("srowen@example.org", "srowen@example.org", null, null);
doTest("mailto:srowen@example.org", "srowen@example.org", null, null);
}
@Test
public void testTos() {
doTest("mailto:srowen@example.org,bob@example.org",
new String[] {"srowen@example.org", "bob@example.org"},
null, null, null, null);
doTest("mailto:?to=srowen@example.org,bob@example.org",
new String[] {"srowen@example.org", "bob@example.org"},
null, null, null, null);
}
@Test
public void testCCs() {
doTest("mailto:?cc=srowen@example.org",
null,
new String[] {"srowen@example.org"},
null, null, null);
doTest("mailto:?cc=srowen@example.org,bob@example.org",
null,
new String[] {"srowen@example.org", "bob@example.org"},
null, null, null);
}
@Test
public void testBCCs() {
doTest("mailto:?bcc=srowen@example.org",
null, null,
new String[] {"srowen@example.org"},
null, null);
doTest("mailto:?bcc=srowen@example.org,bob@example.org",
null, null,
new String[] {"srowen@example.org", "bob@example.org"},
null, null);
}
@Test
public void testAll() {
doTest("mailto:bob@example.org?cc=foo@example.org&bcc=srowen@example.org&subject=baz&body=buzz",
new String[] {"bob@example.org"},
new String[] {"foo@example.org"},
new String[] {"srowen@example.org"},
"baz",
"buzz");
}
@Test
public void testEmailDocomo() {
doTest("MATMSG:TO:srowen@example.org;;", "srowen@example.org", null, null);
doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org", "Stuff", null);
doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", "srowen@example.org",
"Stuff", "This is some text");
}
@Test
public void testSMTP() {
doTest("smtp:srowen@example.org", "srowen@example.org", null, null);
doTest("SMTP:srowen@example.org", "srowen@example.org", null, null);
doTest("smtp:srowen@example.org:foo", "srowen@example.org", "foo", null);
doTest("smtp:srowen@example.org:foo:bar", "srowen@example.org", "foo", "bar");
}
private static void doTest(String contents,
String to,
String subject,
String body) {
doTest(contents, new String[] {to}, null, null, subject, body);
}
private static void doTest(String contents,
String[] tos,
String[] ccs,
String[] bccs,
String subject,
String body) {
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());
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* These authors would like to acknowledge the Spanish Ministry of Industry,
* Tourism and Trade, for the support in the project TSI020301-2008-2
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
* Mobile Dynamic Environments", led by Treelogic
* ( http://www.treelogic.com/ ):
*
* http://www.piramidepse.com/
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
* @author Agustín Delgado, Servinform, S.A.
*/
public final class ExpandedProductParsedRXingResultTestCase extends Assert {
@Test
public void testRSSExpanded() {
Map<String,String> uncommonAIs = new HashMap<>();
uncommonAIs.put("123", "544654");
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());
assertNull(o.getLotNumber());
assertNull(o.getProductionDate());
assertEquals("001205", o.getPackagingDate());
assertNull(o.getBestBeforeDate());
assertNull(o.getExpirationDate());
assertEquals("6544", o.getWeight());
assertEquals("KG", o.getWeightType());
assertEquals("2", o.getWeightIncrement());
assertEquals("5", o.getPrice());
assertEquals("2", o.getPriceIncrement());
assertEquals("445", o.getPriceCurrency());
assertEquals(uncommonAIs, o.getUncommonAIs());
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import java.util.Locale;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link GeoParsedRXingResult}.
*
* @author Sean Owen
*/
public final class GeoParsedRXingResultTestCase extends Assert {
private static final double EPSILON = 1.0E-10;
@Test
public void testGeo() {
doTest("geo:1,2", 1.0, 2.0, 0.0, null, "geo:1.0,2.0");
doTest("geo:80.33,-32.3344,3.35", 80.33, -32.3344, 3.35, null, null);
doTest("geo:-20.33,132.3344,0.01", -20.33, 132.3344, 0.01, null, null);
doTest("geo:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
doTest("GEO:-20.33,132.3344,0.01?q=foobar", -20.33, 132.3344, 0.01, "q=foobar", null);
}
private static void doTest(String contents,
double latitude,
double longitude,
double altitude,
String query,
String uri) {
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());
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link ISBNParsedRXingResult}.
*
* @author Sean Owen
*/
public final class ISBNParsedRXingResultTestCase extends Assert {
@Test
public void testISBN() {
doTest("9784567890123");
}
private static void doTest(String contents) {
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());
}
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
/**
* Tests {@link ParsedRXingResult}.
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class ParsedReaderRXingResultTestCase extends Assert {
@Before
public void setUp() {
Locale.setDefault(Locale.ENGLISH);
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@Test
public void testTextType() {
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.",
ParsedRXingResultType.TEXT);
}
@Test
public void testBookmarkType() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
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() {
doTestRXingResult("01234565", "01234565", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_E);
}
@Test
public void testEAN() {
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() {
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() {
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() {
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() {
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() {
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
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),
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),
ParsedRXingResultType.CALENDAR);
// Local times
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),
ParsedRXingResultType.CALENDAR);
// Date only (all day event)
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),
ParsedRXingResultType.CALENDAR);
// Start time only
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
doTestRXingResult(
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
ParsedRXingResultType.URI);
}
private static String formatDate(int year, int month, int day) {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, day);
return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(cal.getTime());
}
private static String formatTime(int year, int month, int day, int hour, int min, int sec) {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, day, hour, min, sec);
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).format(cal.getTime());
}
@Test
public void testSMS() {
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() {
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
doTestRXingResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedRXingResultType.SMS);
// Need to handle colon in the subject
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.",
ParsedRXingResultType.SMS);
}
@Test
public void testMMS() {
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() {
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 doTestRXingResult(String contents,
String goldenRXingResult,
ParsedRXingResultType type) {
doTestRXingResult(contents, goldenRXingResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
}
private static void doTestRXingResult(String contents,
String goldenRXingResult,
ParsedRXingResultType type,
BarcodeFormat format) {
RXingResult fakeRXingResult = new RXingResult(contents, null, null, format);
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
assertNotNull(result);
assertSame(type, result.getType());
String displayRXingResult = result.getDisplayRXingResult();
assertEquals(goldenRXingResult, displayRXingResult);
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link ProductParsedRXingResult}.
*
* @author Sean Owen
*/
public final class ProductParsedRXingResultTestCase extends Assert {
@Test
public void testProduct() {
doTest("123456789012", "123456789012", BarcodeFormat.UPC_A);
doTest("00393157", "00393157", BarcodeFormat.EAN_8);
doTest("5051140178499", "5051140178499", BarcodeFormat.EAN_13);
doTest("01234565", "012345000065", BarcodeFormat.UPC_E);
}
private static void doTest(String contents, String normalized, BarcodeFormat format) {
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());
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link SMSParsedRXingResult}.
*
* @author Sean Owen
*/
public final class SMSMMSParsedRXingResultTestCase extends Assert {
@Test
public void testSMS() {
doTest("sms:+15551212", "+15551212", null, null, null, "sms:+15551212");
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
"sms:+15551212?body=bar&subject=foo");
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333",
"sms:+15551212;via=999333");
}
@Test
public void testMMS() {
doTest("mms:+15551212", "+15551212", null, null, null, "sms:+15551212");
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null,
"sms:+15551212?body=bar&subject=foo");
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333",
"sms:+15551212;via=999333");
}
private static void doTest(String contents,
String number,
String subject,
String body,
String via,
String parsedURI) {
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());
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link TelParsedRXingResult}.
*
* @author Sean Owen
*/
public final class TelParsedRXingResultTestCase extends Assert {
@Test
public void testTel() {
doTest("tel:+15551212", "+15551212", null);
doTest("tel:2125551212", "2125551212", null);
}
private static void doTest(String contents, String number, String title) {
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());
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link URIParsedRXingResult}.
*
* @author Sean Owen
*/
public final class URIParsedRXingResultTestCase 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");
}
@SuppressWarnings("checkstyle:lineLength")
@Test
public void testURI() {
doTest("google.com", "http://google.com", null);
doTest("123.com", "http://123.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);
doTest("otpauth://remoteaccess?devaddr=00%a1b2%c3d4&devname=foo&key=bar",
"otpauth://remoteaccess?devaddr=00%a1b2%c3d4&devname=foo&key=bar",
null);
doTest("s3://amazon.com:8123", "s3://amazon.com:8123", null);
doTest("HTTP://R.BEETAGG.COM/?12345", "HTTP://R.BEETAGG.COM/?12345", null);
}
@Test
public void testNotURI() {
doTestNotUri("google.c");
doTestNotUri(".com");
doTestNotUri(":80/");
doTestNotUri("ABC,20.3,AB,AD");
doTestNotUri("http://google.com?q=foo bar");
doTestNotUri("12756.501");
doTestNotUri("google.50");
doTestNotUri("foo.bar.bing.baz.foo.bar.bing.baz");
}
@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() {
doTestNotUri("Da65cV1g^>%^f0bAbPn1CJB6lV7ZY8hs0Sm:DXU0cd]GyEeWBz8]bUHLB");
doTestNotUri("DEA\u0003\u0019M\u0006\u0000\bå\u0000‡HO\u0000X$\u0001\u0000\u001Fwfc\u0007!þ“˜" +
"\u0013\u0013¾Z{ùÎÝڗZ§¨+y_zbñk\u00117¸\u000E†Ü\u0000\u0000\u0000\u0000" +
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000£.ux");
}
@Test
public void testIsPossiblyMalicious() {
doTestIsPossiblyMalicious("http://google.com", false);
doTestIsPossiblyMalicious("http://google.com@evil.com", true);
doTestIsPossiblyMalicious("http://google.com:@evil.com", true);
doTestIsPossiblyMalicious("google.com:@evil.com", false);
doTestIsPossiblyMalicious("https://google.com:443", false);
doTestIsPossiblyMalicious("https://google.com:443/", false);
doTestIsPossiblyMalicious("https://evil@google.com:443", true);
doTestIsPossiblyMalicious("http://google.com/foo@bar", false);
doTestIsPossiblyMalicious("http://google.com/@@", false);
}
@Test
public void testMaliciousUnicode() {
doTestIsPossiblyMalicious("https://google.com\u2215.evil.com/stuff", true);
doTestIsPossiblyMalicious("\u202ehttps://dylankatz.com/moc.elgoog.www//:sptth", true);
}
@Test
public void testExotic() {
doTest("bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", "bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", null);
doTest("BTCTX:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
"BTCTX:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
null);
doTest("opc.tcp://test.samplehost.com:4841", "opc.tcp://test.samplehost.com:4841", null);
}
private static void doTest(String contents, String uri, String title) {
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) {
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) {
RXingResult fakeRXingResult = new RXingResult(uri, null, null, BarcodeFormat.QR_CODE);
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
assertSame(malicious ? ParsedRXingResultType.TEXT : ParsedRXingResultType.URI, result.getType());
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2014 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link VINParsedRXingResult}.
*/
public final class VINParsedRXingResultTestCase extends Assert {
@Test
public void testNotVIN() {
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
public void testVIN() {
doTest("1M8GDM9AXKP042788", "1M8", "GDM9AX", "KP042788", "US", "GDM9A", 1989, 'P', "042788");
doTest("I1M8GDM9AXKP042788", "1M8", "GDM9AX", "KP042788", "US", "GDM9A", 1989, 'P', "042788");
doTest("LJCPCBLCX11000237", "LJC", "PCBLCX", "11000237", "CN", "PCBLC", 2001, '1', "000237");
}
private static void doTest(String contents,
String wmi,
String vds,
String vis,
String country,
String attributes,
int year,
char plant,
String sequential) {
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());
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.result;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.RXingResult;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link WifiParsedRXingResult}.
*
* @author Vikram Aggarwal
*/
public final class WifiParsedRXingResultTestCase extends Assert {
@Test
public void testNoPassword() {
doTest("WIFI:S:NoPassword;P:;T:;;", "NoPassword", null, "nopass");
doTest("WIFI:S:No Password;P:;T:;;", "No Password", null, "nopass");
}
@Test
public void testWep() {
doTest("WIFI:S:TenChars;P:0123456789;T:WEP;;", "TenChars", "0123456789", "WEP");
doTest("WIFI:S:TenChars;P:abcde56789;T:WEP;;", "TenChars", "abcde56789", "WEP");
// Non hex should not fail at this level
doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
// Escaped semicolons
doTest("WIFI:S:Ten\\;\\;Chars;P:0123456789;T:WEP;;", "Ten;;Chars", "0123456789", "WEP");
// Escaped colons
doTest("WIFI:S:Ten\\:\\:Chars;P:0123456789;T:WEP;;", "Ten::Chars", "0123456789", "WEP");
// TODO(vikrama) Need a test for SB as well.
}
/**
* Put in checks for the length of the password for wep.
*/
@Test
public void testWpa() {
doTest("WIFI:S:TenChars;P:wow;T:WPA;;", "TenChars", "wow", "WPA");
doTest("WIFI:S:TenChars;P:space is silent;T:WPA;;", "TenChars", "space is silent", "WPA");
doTest("WIFI:S:TenChars;P:hellothere;T:WEP;;", "TenChars", "hellothere", "WEP");
// Escaped semicolons
doTest("WIFI:S:TenChars;P:hello\\;there;T:WEP;;", "TenChars", "hello;there", "WEP");
// Escaped colons
doTest("WIFI:S:TenChars;P:hello\\:there;T:WEP;;", "TenChars", "hello:there", "WEP");
}
@Test
public void testEscape() {
doTest("WIFI:T:WPA;S:test;P:my_password\\\\;;", "test", "my_password\\", "WPA");
doTest("WIFI:T:WPA;S:My_WiFi_SSID;P:abc123/;;", "My_WiFi_SSID", "abc123/", "WPA");
doTest("WIFI:T:WPA;S:\"foo\\;bar\\\\baz\";;", "\"foo;bar\\baz\"", null, "WPA");
doTest("WIFI:T:WPA;S:test;P:\\\"abcd\\\";;", "test", "\"abcd\"", "WPA");
}
/**
* Given the string contents for the barcode, check that it matches our expectations
*/
private static void doTest(String contents,
String ssid,
String password,
String type) {
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
// Ensure it is a wifi code
assertSame(ParsedRXingResultType.WIFI, result.getType());
WifiParsedRXingResult wifiRXingResult = (WifiParsedRXingResult) result;
assertEquals(ssid, wifiRXingResult.getSsid());
assertEquals(password, wifiRXingResult.getPassword());
assertEquals(type, wifiRXingResult.getNetworkEncryption());
}
}