moved java files for pre-convert

This commit is contained in:
Henry Schimke
2022-08-20 12:00:19 -05:00
parent 4997291cb8
commit 1901c96559
2757 changed files with 57224 additions and 0 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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link AddressBookParsedResult}.
*
* @author Sean Owen
*/
public final class AddressBookParsedResultTestCase 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) {
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());
}
}

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.Result;
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 CalendarParsedResult}.
*
* @author Sean Owen
*/
public final class CalendarParsedResultTestCase 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
Result fakeResult = new Result("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());
}
@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) {
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());
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());
}
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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link EmailAddressParsedResult}.
*
* @author Sean Owen
*/
public final class EmailAddressParsedResultTestCase 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) {
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());
}
}

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.Result;
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 ExpandedProductParsedResultTestCase 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);
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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link GeoParsedResult}.
*
* @author Sean Owen
*/
public final class GeoParsedResultTestCase 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) {
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link ISBNParsedResult}.
*
* @author Sean Owen
*/
public final class ISBNParsedResultTestCase extends Assert {
@Test
public void testISBN() {
doTest("9784567890123");
}
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());
}
}

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.Result;
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 ParsedResult}.
*
* @author Sean Owen
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class ParsedReaderResultTestCase extends Assert {
@Before
public void setUp() {
Locale.setDefault(Locale.ENGLISH);
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
@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.",
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
ParsedResultType.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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@Test
public void testUPCE() {
doTestResult("01234565", "01234565", ParsedResultType.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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@Test
public void testVEvent() {
// UTC times
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
"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" +
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
formatTime(2008, 5, 5, 23, 45, 55),
ParsedResultType.CALENDAR);
// Local times
doTestResult("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);
// Date only (all day event)
doTestResult("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);
// 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);
// 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(
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
ParsedResultType.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() {
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);
}
@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);
// Need to handle question mark in the subject
doTestResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.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.",
"212-555-1212\nHere's a longer message. Should be fine.",
ParsedResultType.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);
}
@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);
}
private static void doTestResult(String contents,
String goldenResult,
ParsedResultType type) {
doTestResult(contents, goldenResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
}
private static void doTestResult(String contents,
String goldenResult,
ParsedResultType type,
BarcodeFormat format) {
Result fakeResult = new Result(contents, null, null, format);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertNotNull(result);
assertSame(type, result.getType());
String displayResult = result.getDisplayResult();
assertEquals(goldenResult, displayResult);
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link ProductParsedResult}.
*
* @author Sean Owen
*/
public final class ProductParsedResultTestCase 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) {
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link SMSParsedResult}.
*
* @author Sean Owen
*/
public final class SMSMMSParsedResultTestCase 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) {
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link TelParsedResult}.
*
* @author Sean Owen
*/
public final class TelParsedResultTestCase 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) {
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link URIParsedResult}.
*
* @author Sean Owen
*/
public final class URIParsedResultTestCase extends Assert {
@Test
public void testBookmarkDocomo() {
doTest("MEBKM:URL:google.com;;", "http://google.com", null);
doTest("MEBKM:URL:http://google.com;;", "http://google.com", null);
doTest("MEBKM:URL:google.com;TITLE:Google;", "http://google.com", "Google");
}
@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) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertSame(ParsedResultType.URI, result.getType());
URIParsedResult uriResult = (URIParsedResult) result;
assertEquals(uri, uriResult.getURI());
assertEquals(title, uriResult.getTitle());
}
private static void 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());
}
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link VINParsedResult}.
*/
public final class VINParsedResultTestCase 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());
}
@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) {
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());
}
}

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.Result;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link WifiParsedResult}.
*
* @author Vikram Aggarwal
*/
public final class WifiParsedResultTestCase 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) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
// Ensure it is a wifi code
assertSame(ParsedResultType.WIFI, result.getType());
WifiParsedResult wifiResult = (WifiParsedResult) result;
assertEquals(ssid, wifiResult.getSsid());
assertEquals(password, wifiResult.getPassword());
assertEquals(type, wifiResult.getNetworkEncryption());
}
}