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

Binary file not shown.

View File

@@ -1,169 +0,0 @@
/*
* 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

@@ -1,250 +0,0 @@
/*
* 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

@@ -1,121 +0,0 @@
/*
* 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

@@ -1,66 +0,0 @@
/*
* 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

@@ -1,61 +0,0 @@
/*
* 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

@@ -1,44 +0,0 @@
/*
* 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

@@ -1,330 +0,0 @@
/*
* 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

@@ -1,48 +0,0 @@
/*
* 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

@@ -1,66 +0,0 @@
/*
* 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

@@ -1,47 +0,0 @@
/*
* 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

@@ -1,140 +0,0 @@
/*
* 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

@@ -1,70 +0,0 @@
/*
* 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

@@ -1,93 +0,0 @@
/*
* 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());
}
}

Binary file not shown.

View File

@@ -1,48 +0,0 @@
/*
* 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.common;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Sean Owen
*/
public final class BitSourceTestCase extends Assert {
@Test
public void testSource() {
byte[] bytes = {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5};
BitSource source = new BitSource(bytes);
assertEquals(40, source.available());
assertEquals(0, source.readBits(1));
assertEquals(39, source.available());
assertEquals(0, source.readBits(6));
assertEquals(33, source.available());
assertEquals(1, source.readBits(1));
assertEquals(32, source.available());
assertEquals(2, source.readBits(8));
assertEquals(24, source.available());
assertEquals(12, source.readBits(10));
assertEquals(14, source.available());
assertEquals(16, source.readBits(8));
assertEquals(6, source.available());
assertEquals(5, source.readBits(6));
assertEquals(0, source.available());
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.common;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Sean Owen
*/
public final class PerspectiveTransformTestCase extends Assert {
private static final float EPSILON = 1.0E-4f;
@Test
public void testSquareToQuadrilateral() {
PerspectiveTransform pt = PerspectiveTransform.squareToQuadrilateral(
2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f);
assertPointEquals(2.0f, 3.0f, 0.0f, 0.0f, pt);
assertPointEquals(10.0f, 4.0f, 1.0f, 0.0f, pt);
assertPointEquals(4.0f, 9.0f, 0.0f, 1.0f, pt);
assertPointEquals(16.0f, 15.0f, 1.0f, 1.0f, pt);
assertPointEquals(6.535211f, 6.8873234f, 0.5f, 0.5f, pt);
assertPointEquals(48.0f, 42.42857f, 1.5f, 1.5f, pt);
}
@Test
public void testQuadrilateralToQuadrilateral() {
PerspectiveTransform pt = PerspectiveTransform.quadrilateralToQuadrilateral(
2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f,
103.0f, 110.0f, 300.0f, 120.0f, 290.0f, 270.0f, 150.0f, 280.0f);
assertPointEquals(103.0f, 110.0f, 2.0f, 3.0f, pt);
assertPointEquals(300.0f, 120.0f, 10.0f, 4.0f, pt);
assertPointEquals(290.0f, 270.0f, 16.0f, 15.0f, pt);
assertPointEquals(150.0f, 280.0f, 4.0f, 9.0f, pt);
assertPointEquals(7.1516876f, -64.60185f, 0.5f, 0.5f, pt);
assertPointEquals(328.09116f, 334.16385f, 50.0f, 50.0f, pt);
}
private static void assertPointEquals(float expectedX,
float expectedY,
float sourceX,
float sourceY,
PerspectiveTransform pt) {
float[] points = {sourceX, sourceY};
pt.transformPoints(points);
assertEquals(expectedX, points[0], EPSILON);
assertEquals(expectedY, points[1], EPSILON);
}
}

View File

@@ -1,71 +0,0 @@
/*
* 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.common.detector;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link MathUtils}.
*/
public final class MathUtilsTestCase extends Assert {
private static final float EPSILON = 1.0E-8f;
@Test
public void testRound() {
assertEquals(-1, MathUtils.round(-1.0f));
assertEquals(0, MathUtils.round(0.0f));
assertEquals(1, MathUtils.round(1.0f));
assertEquals(2, MathUtils.round(1.9f));
assertEquals(2, MathUtils.round(2.1f));
assertEquals(3, MathUtils.round(2.5f));
assertEquals(-2, MathUtils.round(-1.9f));
assertEquals(-2, MathUtils.round(-2.1f));
assertEquals(-3, MathUtils.round(-2.5f)); // This differs from Math.round()
assertEquals(Integer.MAX_VALUE, MathUtils.round(Integer.MAX_VALUE));
assertEquals(Integer.MIN_VALUE, MathUtils.round(Integer.MIN_VALUE));
assertEquals(Integer.MAX_VALUE, MathUtils.round(Float.POSITIVE_INFINITY));
assertEquals(Integer.MIN_VALUE, MathUtils.round(Float.NEGATIVE_INFINITY));
assertEquals(0, MathUtils.round(Float.NaN));
}
@Test
public void testDistance() {
assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1.0f, 2.0f, 3.0f, 4.0f), EPSILON);
assertEquals(0.0f, MathUtils.distance(1.0f, 2.0f, 1.0f, 2.0f), EPSILON);
assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1, 2, 3, 4), EPSILON);
assertEquals(0.0f, MathUtils.distance(1, 2, 1, 2), EPSILON);
}
@Test
public void testSum() {
assertEquals(0, MathUtils.sum(new int[] {}));
assertEquals(1, MathUtils.sum(new int[] {1}));
assertEquals(4, MathUtils.sum(new int[] {1, 3}));
assertEquals(0, MathUtils.sum(new int[] {-1, 1}));
}
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2018 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.common.reedsolomon;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests {@link GenericGFPoly}.
*/
public final class GenericGFPolyTestCase extends Assert {
private static final GenericGF FIELD = GenericGF.QR_CODE_FIELD_256;
@Test
public void testPolynomialString() {
assertEquals("0", FIELD.getZero().toString());
assertEquals("-1", FIELD.buildMonomial(0, -1).toString());
GenericGFPoly p = new GenericGFPoly(FIELD, new int[] {3, 0, -2, 1, 1});
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
p = new GenericGFPoly(FIELD, new int[] {3});
assertEquals("a^25", p.toString());
}
@Test
public void testZero() {
assertEquals(FIELD.getZero(),FIELD.buildMonomial(1, 0));
assertEquals(FIELD.getZero(), FIELD.buildMonomial(1, 2).multiply(0));
}
@Test
public void testEvaluate() {
assertEquals(3, FIELD.buildMonomial(0, 3).evaluateAt(0));
}
}

View File

@@ -1,525 +0,0 @@
/*
* Copyright 2013 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.common.reedsolomon;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Random;
/**
* @author Rustam Abdullaev
*/
public final class ReedSolomonTestCase extends Assert {
private static final int DECODER_RANDOM_TEST_ITERATIONS = 3;
private static final int DECODER_TEST_ITERATIONS = 10;
@Test
public void testDataMatrix() {
// real life test cases
testEncodeDecode(GenericGF.DATA_MATRIX_FIELD_256,
new int[] { 142, 164, 186 }, new int[] { 114, 25, 5, 88, 102 });
testEncodeDecode(GenericGF.DATA_MATRIX_FIELD_256,
new int[] {
0x69, 0x75, 0x75, 0x71, 0x3B, 0x30, 0x30, 0x64,
0x70, 0x65, 0x66, 0x2F, 0x68, 0x70, 0x70, 0x68,
0x6D, 0x66, 0x2F, 0x64, 0x70, 0x6E, 0x30, 0x71,
0x30, 0x7B, 0x79, 0x6A, 0x6F, 0x68, 0x30, 0x81,
0xF0, 0x88, 0x1F, 0xB5
},
new int[] {
0x1C, 0x64, 0xEE, 0xEB, 0xD0, 0x1D, 0x00, 0x03,
0xF0, 0x1C, 0xF1, 0xD0, 0x6D, 0x00, 0x98, 0xDA,
0x80, 0x88, 0xBE, 0xFF, 0xB7, 0xFA, 0xA9, 0x95
});
// synthetic test cases
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 10, 240);
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 128, 127);
testEncodeDecodeRandom(GenericGF.DATA_MATRIX_FIELD_256, 220, 35);
}
@Test
public void testQRCode() {
// Test case from example given in ISO 18004, Annex I
testEncodeDecode(GenericGF.QR_CODE_FIELD_256,
new int[] {
0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11,
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11
},
new int[] {
0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87,
0x2C, 0x55
});
testEncodeDecode(GenericGF.QR_CODE_FIELD_256,
new int[] {
0x72, 0x67, 0x2F, 0x77, 0x69, 0x6B, 0x69, 0x2F,
0x4D, 0x61, 0x69, 0x6E, 0x5F, 0x50, 0x61, 0x67,
0x65, 0x3B, 0x3B, 0x00, 0xEC, 0x11, 0xEC, 0x11,
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11
},
new int[] {
0xD8, 0xB8, 0xEF, 0x14, 0xEC, 0xD0, 0xCC, 0x85,
0x73, 0x40, 0x0B, 0xB5, 0x5A, 0xB8, 0x8B, 0x2E,
0x08, 0x62
});
// real life test cases
// synthetic test cases
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 10, 240);
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 128, 127);
testEncodeDecodeRandom(GenericGF.QR_CODE_FIELD_256, 220, 35);
}
@Test
public void testAztec() {
// real life test cases
testEncodeDecode(GenericGF.AZTEC_PARAM,
new int[] { 0x5, 0x6 }, new int[] { 0x3, 0x2, 0xB, 0xB, 0x7 });
testEncodeDecode(GenericGF.AZTEC_PARAM,
new int[] { 0x0, 0x0, 0x0, 0x9 }, new int[] { 0xA, 0xD, 0x8, 0x6, 0x5, 0x6 });
testEncodeDecode(GenericGF.AZTEC_PARAM,
new int[] { 0x2, 0x8, 0x8, 0x7 }, new int[] { 0xE, 0xC, 0xA, 0x9, 0x6, 0x8 });
testEncodeDecode(GenericGF.AZTEC_DATA_6, new int[] {
0x9, 0x32, 0x1, 0x29, 0x2F, 0x2, 0x27, 0x25, 0x1, 0x1B },
new int[] {
0x2C, 0x2, 0xD, 0xD, 0xA, 0x16, 0x28, 0x9, 0x22, 0xA, 0x14
});
testEncodeDecode(GenericGF.AZTEC_DATA_8,
new int[] {
0xE0, 0x86, 0x42, 0x98, 0xE8, 0x4A, 0x96, 0xC6,
0xB9, 0xF0, 0x8C, 0xA7, 0x4A, 0xDA, 0xF8, 0xCE,
0xB7, 0xDE, 0x88, 0x64, 0x29, 0x8E, 0x84, 0xA9,
0x6C, 0x6B, 0x9F, 0x08, 0xCA, 0x74, 0xAD, 0xAF,
0x8C, 0xEB, 0x7C, 0x10, 0xC8, 0x53, 0x1D, 0x09,
0x52, 0xD8, 0xD7, 0x3E, 0x11, 0x94, 0xE9, 0x5B,
0x5F, 0x19, 0xD6, 0xFB, 0xD1, 0x0C, 0x85, 0x31,
0xD0, 0x95, 0x2D, 0x8D, 0x73, 0xE1, 0x19, 0x4E,
0x95, 0xB5, 0xF1, 0x9D, 0x6F
},
new int[] {
0x31, 0xD7, 0x04, 0x46, 0xB2, 0xC1, 0x06, 0x94,
0x17, 0xE5, 0x0C, 0x2B, 0xA3, 0x99, 0x15, 0x7F,
0x16, 0x3C, 0x66, 0xBA, 0x33, 0xD9, 0xE8, 0x87,
0x86, 0xBB, 0x4B, 0x15, 0x4E, 0x4A, 0xDE, 0xD4,
0xED, 0xA1, 0xF8, 0x47, 0x2A, 0x50, 0xA6, 0xBC,
0x53, 0x7D, 0x29, 0xFE, 0x06, 0x49, 0xF3, 0x73,
0x9F, 0xC1, 0x75
});
testEncodeDecode(GenericGF.AZTEC_DATA_10,
new int[] {
0x15C, 0x1E1, 0x2D5, 0x02E, 0x048, 0x1E2, 0x037, 0x0CD,
0x02E, 0x056, 0x26A, 0x281, 0x1C2, 0x1A6, 0x296, 0x045,
0x041, 0x0AA, 0x095, 0x2CE, 0x003, 0x38F, 0x2CD, 0x1A2,
0x036, 0x1AD, 0x04E, 0x090, 0x271, 0x0D3, 0x02E, 0x0D5,
0x2D4, 0x032, 0x2CA, 0x281, 0x0AA, 0x04E, 0x024, 0x2D3,
0x296, 0x281, 0x0E2, 0x08A, 0x1AA, 0x28A, 0x280, 0x07C,
0x286, 0x0A1, 0x1D0, 0x1AD, 0x154, 0x032, 0x2C2, 0x1C1,
0x145, 0x02B, 0x2D4, 0x2B0, 0x033, 0x2D5, 0x276, 0x1C1,
0x282, 0x10A, 0x2B5, 0x154, 0x003, 0x385, 0x20F, 0x0C4,
0x02D, 0x050, 0x266, 0x0D5, 0x033, 0x2D5, 0x276, 0x1C1,
0x0D4, 0x2A0, 0x08F, 0x0C4, 0x024, 0x20F, 0x2E2, 0x1AD,
0x154, 0x02E, 0x056, 0x26A, 0x281, 0x090, 0x1E5, 0x14E,
0x0CF, 0x2B6, 0x1C1, 0x28A, 0x2A1, 0x04E, 0x0D5, 0x003,
0x391, 0x122, 0x286, 0x1AD, 0x2D4, 0x028, 0x262, 0x2EA,
0x0A2, 0x004, 0x176, 0x295, 0x201, 0x0D5, 0x024, 0x20F,
0x116, 0x0C1, 0x056, 0x095, 0x213, 0x004, 0x1EA, 0x28A,
0x02A, 0x234, 0x2CE, 0x037, 0x157, 0x0D3, 0x262, 0x026,
0x262, 0x2A0, 0x086, 0x106, 0x2A1, 0x126, 0x1E5, 0x266,
0x26A, 0x2A1, 0x0E6, 0x1AA, 0x281, 0x2B6, 0x271, 0x154,
0x02F, 0x0C4, 0x02D, 0x213, 0x0CE, 0x003, 0x38F, 0x2CD,
0x1A2, 0x036, 0x1B5, 0x26A, 0x086, 0x280, 0x086, 0x1AA,
0x2A1, 0x226, 0x1AD, 0x0CF, 0x2A6, 0x292, 0x2C6, 0x022,
0x1AA, 0x256, 0x0D5, 0x02D, 0x050, 0x266, 0x0D5, 0x004,
0x176, 0x295, 0x201, 0x0D3, 0x055, 0x031, 0x2CD, 0x2EA,
0x1E2, 0x261, 0x1EA, 0x28A, 0x004, 0x145, 0x026, 0x1A6,
0x1C6, 0x1F5, 0x2CE, 0x034, 0x051, 0x146, 0x1E1, 0x0B0,
0x1B0, 0x261, 0x0D5, 0x025, 0x142, 0x1C0, 0x07C, 0x0B0,
0x1E6, 0x081, 0x044, 0x02F, 0x2CF, 0x081, 0x290, 0x0A2,
0x1A6, 0x281, 0x0CD, 0x155, 0x031, 0x1A2, 0x086, 0x262,
0x2A1, 0x0CD, 0x0CA, 0x0E6, 0x1E5, 0x003, 0x394, 0x0C5,
0x030, 0x26F, 0x053, 0x0C1, 0x1B6, 0x095, 0x2D4, 0x030,
0x26F, 0x053, 0x0C0, 0x07C, 0x2E6, 0x295, 0x143, 0x2CD,
0x2CE, 0x037, 0x0C9, 0x144, 0x2CD, 0x040, 0x08E, 0x054,
0x282, 0x022, 0x2A1, 0x229, 0x053, 0x0D5, 0x262, 0x027,
0x26A, 0x1E8, 0x14D, 0x1A2, 0x004, 0x26A, 0x296, 0x281,
0x176, 0x295, 0x201, 0x0E2, 0x2C4, 0x143, 0x2D4, 0x026,
0x262, 0x2A0, 0x08F, 0x0C4, 0x031, 0x213, 0x2B5, 0x155,
0x213, 0x02F, 0x143, 0x121, 0x2A6, 0x1AD, 0x2D4, 0x034,
0x0C5, 0x026, 0x295, 0x003, 0x396, 0x2A1, 0x176, 0x295,
0x201, 0x0AA, 0x04E, 0x004, 0x1B0, 0x070, 0x275, 0x154,
0x026, 0x2C1, 0x2B3, 0x154, 0x2AA, 0x256, 0x0C1, 0x044,
0x004, 0x23F
},
new int[] {
0x379, 0x099, 0x348, 0x010, 0x090, 0x196, 0x09C, 0x1FF,
0x1B0, 0x32D, 0x244, 0x0DE, 0x201, 0x386, 0x163, 0x11F,
0x39B, 0x344, 0x3FE, 0x02F, 0x188, 0x113, 0x3D9, 0x102,
0x04A, 0x2E1, 0x1D1, 0x18E, 0x077, 0x262, 0x241, 0x20D,
0x1B8, 0x11D, 0x0D0, 0x0A5, 0x29C, 0x24D, 0x3E7, 0x006,
0x2D0, 0x1B7, 0x337, 0x178, 0x0F1, 0x1E0, 0x00B, 0x01E,
0x0DA, 0x1C6, 0x2D9, 0x00D, 0x28B, 0x34A, 0x252, 0x27A,
0x057, 0x0CA, 0x2C2, 0x2E4, 0x3A6, 0x0E3, 0x22B, 0x307,
0x174, 0x292, 0x10C, 0x1ED, 0x2FD, 0x2D4, 0x0A7, 0x051,
0x34F, 0x07A, 0x1D5, 0x01D, 0x22E, 0x2C2, 0x1DF, 0x08F,
0x105, 0x3FE, 0x286, 0x2A2, 0x3B1, 0x131, 0x285, 0x362,
0x315, 0x13C, 0x0F9, 0x1A2, 0x28D, 0x246, 0x1B3, 0x12C,
0x2AD, 0x0F8, 0x222, 0x0EC, 0x39F, 0x358, 0x014, 0x229,
0x0C8, 0x360, 0x1C2, 0x031, 0x098, 0x041, 0x3E4, 0x046,
0x332, 0x318, 0x2E3, 0x24E, 0x3E2, 0x1E1, 0x0BE, 0x239,
0x306, 0x3A5, 0x352, 0x351, 0x275, 0x0ED, 0x045, 0x229,
0x0BF, 0x05D, 0x253, 0x1BE, 0x02E, 0x35A, 0x0E4, 0x2E9,
0x17A, 0x166, 0x03C, 0x007
});
testEncodeDecode(GenericGF.AZTEC_DATA_12,
new int[] {
0x571, 0xE1B, 0x542, 0xE12, 0x1E2, 0x0DC, 0xCD0, 0xB85,
0x69A, 0xA81, 0x709, 0xA6A, 0x584, 0x510, 0x4AA, 0x256,
0xCE0, 0x0F8, 0xFB3, 0x5A2, 0x0D9, 0xAD1, 0x389, 0x09C,
0x4D3, 0x0B8, 0xD5B, 0x503, 0x2B2, 0xA81, 0x2A8, 0x4E0,
0x92D, 0x3A5, 0xA81, 0x388, 0x8A6, 0xAA8, 0xAA0, 0x07C,
0xA18, 0xA17, 0x41A, 0xD55, 0x032, 0xB09, 0xC15, 0x142,
0xBB5, 0x2B0, 0x0CE, 0xD59, 0xD9C, 0x1A0, 0x90A, 0xAD5,
0x540, 0x0F8, 0x583, 0xCC4, 0x0B4, 0x509, 0x98D, 0x50C,
0xED5, 0x9D9, 0xC13, 0x52A, 0x023, 0xCC4, 0x092, 0x0FB,
0x89A, 0xD55, 0x02E, 0x15A, 0x6AA, 0x049, 0x079, 0x54E,
0x33E, 0xB67, 0x068, 0xAA8, 0x44E, 0x354, 0x03E, 0x452,
0x2A1, 0x9AD, 0xB50, 0x289, 0x8AE, 0xA28, 0x804, 0x5DA,
0x958, 0x04D, 0x509, 0x20F, 0x458, 0xC11, 0x589, 0x584,
0xC04, 0x7AA, 0x8A0, 0xAA3, 0x4B3, 0x837, 0x55C, 0xD39,
0x882, 0x698, 0xAA0, 0x219, 0x06A, 0x852, 0x679, 0x666,
0x9AA, 0xA13, 0x99A, 0xAA0, 0x6B6, 0x9C5, 0x540, 0xBCC,
0x40B, 0x613, 0x338, 0x03E, 0x3EC, 0xD68, 0x836, 0x6D6,
0x6A2, 0x1A8, 0x021, 0x9AA, 0xA86, 0x266, 0xB4C, 0xFA9,
0xA92, 0xB18, 0x226, 0xAA5, 0x635, 0x42D, 0x142, 0x663,
0x540, 0x45D, 0xA95, 0x804, 0xD31, 0x543, 0x1B3, 0x6EA,
0x78A, 0x617, 0xAA8, 0xA01, 0x145, 0x099, 0xA67, 0x19F,
0x5B3, 0x834, 0x145, 0x467, 0x84B, 0x06C, 0x261, 0x354,
0x255, 0x09C, 0x01F, 0x0B0, 0x798, 0x811, 0x102, 0xFB3,
0xC81, 0xA40, 0xA26, 0x9A8, 0x133, 0x555, 0x0C5, 0xA22,
0x1A6, 0x2A8, 0x4CD, 0x328, 0xE67, 0x940, 0x3E5, 0x0C5,
0x0C2, 0x6F1, 0x4CC, 0x16D, 0x895, 0xB50, 0x309, 0xBC5,
0x330, 0x07C, 0xB9A, 0x955, 0x0EC, 0xDB3, 0x837, 0x325,
0x44B, 0x344, 0x023, 0x854, 0xA08, 0x22A, 0x862, 0x914,
0xCD5, 0x988, 0x279, 0xA9E, 0x853, 0x5A2, 0x012, 0x6AA,
0x5A8, 0x15D, 0xA95, 0x804, 0xE2B, 0x114, 0x3B5, 0x026,
0x98A, 0xA02, 0x3CC, 0x40C, 0x613, 0xAD5, 0x558, 0x4C2,
0xF50, 0xD21, 0xA99, 0xADB, 0x503, 0x431, 0x426, 0xA54,
0x03E, 0x5AA, 0x15D, 0xA95, 0x804, 0xAA1, 0x380, 0x46C,
0x070, 0x9D5, 0x540, 0x9AC, 0x1AC, 0xD54, 0xAAA, 0x563,
0x044, 0x401, 0x220, 0x9F1, 0x4F0, 0xDAA, 0x170, 0x90F,
0x106, 0xE66, 0x85C, 0x2B4, 0xD54, 0x0B8, 0x4D3, 0x52C,
0x228, 0x825, 0x512, 0xB67, 0x007, 0xC7D, 0x9AD, 0x106,
0xCD6, 0x89C, 0x484, 0xE26, 0x985, 0xC6A, 0xDA8, 0x195,
0x954, 0x095, 0x427, 0x049, 0x69D, 0x2D4, 0x09C, 0x445,
0x355, 0x455, 0x003, 0xE50, 0xC50, 0xBA0, 0xD6A, 0xA81,
0x958, 0x4E0, 0xA8A, 0x15D, 0xA95, 0x806, 0x76A, 0xCEC,
0xE0D, 0x048, 0x556, 0xAAA, 0x007, 0xC2C, 0x1E6, 0x205,
0xA28, 0x4CC, 0x6A8, 0x676, 0xACE, 0xCE0, 0x9A9, 0x501,
0x1E6, 0x204, 0x907, 0xDC4, 0xD6A, 0xA81, 0x70A, 0xD35,
0x502, 0x483, 0xCAA, 0x719, 0xF5B, 0x383, 0x455, 0x422,
0x71A, 0xA01, 0xF22, 0x915, 0x0CD, 0x6DA, 0x814, 0x4C5,
0x751, 0x440, 0x22E, 0xD4A, 0xC02, 0x6A8, 0x490, 0x7A2,
0xC60, 0x8AC, 0x4AC, 0x260, 0x23D, 0x545, 0x055, 0x1A5,
0x9C1, 0xBAA, 0xE69, 0xCC4, 0x134, 0xC55, 0x010, 0xC83,
0x542, 0x933, 0xCB3, 0x34D, 0x550, 0x9CC, 0xD55, 0x035,
0xB4E, 0x2AA, 0x05E, 0x620, 0x5B0, 0x999, 0xC01, 0xF1F,
0x66B, 0x441, 0xB36, 0xB35, 0x10D, 0x401, 0x0CD, 0x554,
0x313, 0x35A, 0x67D, 0x4D4, 0x958, 0xC11, 0x355, 0x2B1,
0xAA1, 0x68A, 0x133, 0x1AA, 0x022, 0xED4, 0xAC0, 0x269,
0x8AA, 0x18D, 0x9B7, 0x53C, 0x530, 0xBD5, 0x450, 0x08A,
0x284, 0xCD3, 0x38C, 0xFAD, 0x9C1, 0xA0A, 0x2A3, 0x3C2,
0x583, 0x613, 0x09A, 0xA12, 0xA84, 0xE00, 0xF85, 0x83C,
0xC40, 0x888, 0x17D, 0x9E4, 0x0D2, 0x051, 0x34D, 0x409,
0x9AA, 0xA86, 0x2D1, 0x10D, 0x315, 0x426, 0x699, 0x473,
0x3CA, 0x01F, 0x286, 0x286, 0x137, 0x8A6, 0x60B, 0x6C4,
0xADA, 0x818, 0x4DE, 0x299, 0x803, 0xE5C, 0xD4A, 0xA87,
0x66D, 0x9C1, 0xB99, 0x2A2, 0x59A, 0x201, 0x1C2, 0xA50,
0x411, 0x543, 0x148, 0xA66, 0xACC, 0x413, 0xCD4, 0xF42,
0x9AD, 0x100, 0x935, 0x52D, 0x40A, 0xED4, 0xAC0, 0x271,
0x588, 0xA1D, 0xA81, 0x34C, 0x550, 0x11E, 0x620, 0x630,
0x9D6, 0xAAA, 0xC26, 0x17A, 0x869, 0x0D4, 0xCD6, 0xDA8,
0x1A1, 0x8A1, 0x352, 0xA01, 0xF2D, 0x50A, 0xED4, 0xAC0,
0x255, 0x09C, 0x023, 0x603, 0x84E, 0xAAA, 0x04D, 0x60D,
0x66A, 0xA55, 0x52B, 0x182, 0x220, 0x091, 0x00F, 0x8A7,
0x86D, 0x50B, 0x848, 0x788, 0x373, 0x342, 0xE15, 0xA6A,
0xA05, 0xC26, 0x9A9, 0x611, 0x441, 0x2A8, 0x95B, 0x380,
0x3E3, 0xECD, 0x688, 0x366, 0xB44, 0xE24, 0x271, 0x34C,
0x2E3, 0x56D, 0x40C, 0xACA, 0xA04, 0xAA1, 0x382, 0x4B4,
0xE96, 0xA04, 0xE22, 0x29A, 0xAA2, 0xA80, 0x1F2, 0x862,
0x85D, 0x06B, 0x554, 0x0CA, 0xC27, 0x054, 0x50A, 0xED4,
0xAC0, 0x33B, 0x567, 0x670, 0x682, 0x42A, 0xB55, 0x500,
0x3E1, 0x60F, 0x310, 0x2D1, 0x426, 0x635, 0x433, 0xB56,
0x767, 0x04D, 0x4A8, 0x08F, 0x310, 0x248, 0x3EE, 0x26B,
0x554, 0x0B8, 0x569, 0xAA8, 0x124, 0x1E5, 0x538, 0xCFA,
0xD9C, 0x1A2, 0xAA1, 0x138, 0xD50, 0x0F9, 0x148, 0xA86,
0x6B6, 0xD40, 0xA26, 0x2BA, 0x8A2, 0x011, 0x76A, 0x560,
0x135, 0x424, 0x83D, 0x163, 0x045, 0x625, 0x613, 0x011,
0xEAA, 0x282, 0xA8D, 0x2CE, 0x0DD, 0x573, 0x4E6, 0x209,
0xA62, 0xA80, 0x864, 0x1AA, 0x149, 0x9E5, 0x99A, 0x6AA,
0x84E, 0x66A, 0xA81, 0xADA, 0x715, 0x502, 0xF31, 0x02D,
0x84C, 0xCE0, 0x0F8, 0xFB3, 0x5A2, 0x0D9, 0xB59, 0xA88,
0x6A0, 0x086, 0x6AA, 0xA18, 0x99A, 0xD33, 0xEA6, 0xA4A,
0xC60, 0x89A, 0xA95, 0x8D5, 0x0B4, 0x509, 0x98D, 0x501,
0x176, 0xA56, 0x013, 0x4C5, 0x50C, 0x6CD, 0xBA9, 0xE29,
0x85E, 0xAA2, 0x804, 0x514, 0x266, 0x99C, 0x67D, 0x6CE,
0x0D0, 0x515, 0x19E, 0x12C, 0x1B0, 0x984, 0xD50, 0x954,
0x270, 0x07C, 0x2C1, 0xE62, 0x044, 0x40B, 0xECF, 0x206,
0x902, 0x89A, 0x6A0, 0x4CD, 0x554, 0x316, 0x888, 0x698,
0xAA1, 0x334, 0xCA3, 0x99E, 0x500, 0xF94, 0x314, 0x309,
0xBC5, 0x330, 0x5B6, 0x256, 0xD40, 0xC26, 0xF14, 0xCC0,
0x1F2, 0xE6A, 0x554, 0x3B3, 0x6CE, 0x0DC, 0xC95, 0x12C,
0xD10, 0x08E, 0x152, 0x820, 0x8AA, 0x18A, 0x453, 0x356,
0x620, 0x9E6, 0xA7A, 0x14D, 0x688, 0x049, 0xAA9, 0x6A0,
0x576, 0xA56, 0x013, 0x8AC, 0x450, 0xED4, 0x09A, 0x62A,
0x808, 0xF31, 0x031, 0x84E, 0xB55, 0x561, 0x30B, 0xD43,
0x486, 0xA66, 0xB6D, 0x40D, 0x0C5, 0x09A, 0x950, 0x0F9,
0x6A8, 0x576, 0xA56, 0x012, 0xA84, 0xE01, 0x1B0, 0x1C2,
0x755, 0x502, 0x6B0, 0x6B3, 0x552, 0xAA9, 0x58C, 0x111,
0x004, 0x882, 0x7C5, 0x3C3, 0x6A8, 0x5C2, 0x43C, 0x41B,
0x99A, 0x170, 0xAD3, 0x550, 0x2E1, 0x34D, 0x4B0, 0x8A2,
0x095, 0x44A, 0xD9C, 0x01F, 0x1F6, 0x6B4, 0x41B, 0x35A,
0x271, 0x213, 0x89A, 0x617, 0x1AB, 0x6A0, 0x656, 0x550,
0x255, 0x09C, 0x125, 0xA74, 0xB50, 0x271, 0x114, 0xD55,
0x154, 0x00F, 0x943, 0x142, 0xE83, 0x5AA, 0xA06, 0x561,
0x382, 0xA28, 0x576, 0xA56, 0x019, 0xDAB, 0x3B3, 0x834,
0x121, 0x55A, 0xAA8, 0x01F, 0x0B0, 0x798, 0x816, 0x8A1,
0x331, 0xAA1, 0x9DA, 0xB3B, 0x382, 0x6A5, 0x404, 0x798,
0x812, 0x41F, 0x713, 0x5AA, 0xA05, 0xC2B, 0x4D5, 0x409,
0x20F, 0x2A9, 0xC67, 0xD6C, 0xE0D, 0x155, 0x089, 0xC6A,
0x807, 0xC8A, 0x454, 0x335, 0xB6A, 0x051, 0x315, 0xD45,
0x100, 0x8BB, 0x52B, 0x009, 0xAA1, 0x241, 0xE8B, 0x182,
0x2B1, 0x2B0, 0x980, 0x8F5, 0x514, 0x154, 0x696, 0x706,
0xEAB, 0x9A7, 0x310, 0x4D3, 0x154, 0x043, 0x20D, 0x50A,
0x4CF, 0x2CC, 0xD35, 0x542, 0x733, 0x554, 0x0D6, 0xD38,
0xAA8, 0x179, 0x881, 0x6C2, 0x667, 0x007, 0xC7D, 0x9AD,
0x106, 0xCDA, 0xCD4, 0x435, 0x004, 0x335, 0x550, 0xC4C,
0xD69, 0x9F5, 0x352, 0x563, 0x044, 0xD54, 0xAC6, 0xA85,
0xA28, 0x4CC, 0x6A8, 0x08B, 0xB52, 0xB00, 0x9A6, 0x2A8,
0x636, 0x6DD, 0x4F1, 0x4C2, 0xF55, 0x140, 0x228, 0xA13,
0x34C, 0xE33, 0xEB6, 0x706, 0x828, 0xA8C, 0xF09, 0x60D,
0x84C, 0x26A, 0x84A, 0xA13, 0x803, 0xE16, 0x0F3, 0x102,
0x220, 0x5F6, 0x790, 0x348, 0x144, 0xD35, 0x026, 0x6AA,
0xA18, 0xB44, 0x434, 0xC55, 0x099, 0xA65, 0x1CC, 0xF28,
0x07C, 0xA18, 0xA18, 0x4DE, 0x299, 0x82D, 0xB12, 0xB6A,
0x061, 0x378, 0xA66, 0x00F, 0x973, 0x52A, 0xA1D, 0x9B6,
0x706, 0xE64, 0xA89, 0x668, 0x804, 0x70A, 0x941, 0x045,
0x50C, 0x522, 0x99A, 0xB31, 0x04F, 0x353, 0xD0A, 0x6B4,
0x402, 0x4D5, 0x4B5, 0x02B, 0xB52, 0xB00, 0x9C5, 0x622,
0x876, 0xA04, 0xD31, 0x540, 0x479, 0x881, 0x8C2, 0x75A,
0xAAB, 0x098, 0x5EA, 0x1A4, 0x353, 0x35B, 0x6A0, 0x686,
0x284, 0xD4A, 0x807, 0xCB5, 0x42B, 0xB52, 0xB00, 0x954,
0x270, 0x08D, 0x80E, 0x13A, 0xAA8, 0x135, 0x835, 0x9AA,
0x801, 0xF14, 0xF0D, 0xAA1, 0x709, 0x0F1, 0x06E, 0x668,
0x5C2, 0xB4D, 0x540, 0xB84, 0xD35, 0x2C2, 0x288, 0x255,
0x12B, 0x670, 0x07C, 0x7D9, 0xAD1, 0x06C, 0xD68, 0x9C4,
0x84E, 0x269, 0x85C, 0x6AD, 0xA81, 0x959, 0x540, 0x954,
0x270, 0x496, 0x9D2, 0xD40, 0x9C4, 0x453, 0x554, 0x550,
0x03E, 0x50C, 0x50B, 0xA0D, 0x6AA, 0x819, 0x584, 0xE0A,
0x8A1, 0x5DA, 0x958, 0x067, 0x6AC, 0xECE, 0x0D0, 0x485,
0x56A, 0xAA0, 0x07C, 0x2C1, 0xE62, 0x05A, 0x284, 0xCC6,
0xA86, 0x76A, 0xCEC, 0xE09, 0xA95, 0x011, 0xE62, 0x049,
0x07D, 0xC4D, 0x6AA, 0x817, 0x0AD, 0x355, 0x024, 0x83C,
0xAA7, 0x19F, 0x5B3, 0x834, 0x554, 0x227, 0x1AA, 0x01F,
0x229, 0x150, 0xCD6, 0xDA8, 0x144, 0xC57, 0x514, 0x402,
0x2ED, 0x4AC, 0x026, 0xA84, 0x907, 0xA2C, 0x608, 0xAC4,
0xAC2, 0x602, 0x3D5, 0x450, 0x551, 0xA59, 0xC1B, 0xAAE,
0x69C, 0xC41, 0x34C, 0x550, 0x10C, 0x835, 0x429, 0x33C,
0xB33, 0x4D5, 0x509, 0xCCD, 0x550, 0x35B, 0x4E2, 0xAA0,
0x5E6, 0x205, 0xB09, 0x99C, 0x09F
},
new int[] {
0xD54, 0x221, 0x154, 0x7CD, 0xBF3, 0x112, 0x89B, 0xC5E,
0x9CD, 0x07E, 0xFB6, 0x78F, 0x7FA, 0x16F, 0x377, 0x4B4,
0x62D, 0x475, 0xBC2, 0x861, 0xB72, 0x9D0, 0x76A, 0x5A1,
0x22A, 0xF74, 0xDBA, 0x8B1, 0x139, 0xDCD, 0x012, 0x293,
0x705, 0xA34, 0xDD5, 0x3D2, 0x7F8, 0x0A6, 0x89A, 0x346,
0xCE0, 0x690, 0x40E, 0xFF3, 0xC4D, 0x97F, 0x9C9, 0x016,
0x73A, 0x923, 0xBCE, 0xFA9, 0xE6A, 0xB92, 0x02A, 0x07C,
0x04B, 0x8D5, 0x753, 0x42E, 0x67E, 0x87C, 0xEE6, 0xD7D,
0x2BF, 0xFB2, 0xFF8, 0x42F, 0x4CB, 0x214, 0x779, 0x02D,
0x606, 0xA02, 0x08A, 0xD4F, 0xB87, 0xDDF, 0xC49, 0xB51,
0x0E9, 0xF89, 0xAEF, 0xC92, 0x383, 0x98D, 0x367, 0xBD3,
0xA55, 0x148, 0x9DB, 0x913, 0xC79, 0x6FF, 0x387, 0x6EA,
0x7FA, 0xC1B, 0x12D, 0x303, 0xBCA, 0x503, 0x0FB, 0xB14,
0x0D4, 0xAD1, 0xAFC, 0x9DD, 0x404, 0x145, 0x6E5, 0x8ED,
0xF94, 0xD72, 0x645, 0xA21, 0x1A8, 0xABF, 0xC03, 0x91E,
0xD53, 0x48C, 0x471, 0x4E4, 0x408, 0x33C, 0x5DF, 0x73D,
0xA2A, 0x454, 0xD77, 0xC48, 0x2F5, 0x96A, 0x9CF, 0x047,
0x611, 0xE92, 0xC2F, 0xA98, 0x56D, 0x919, 0x615, 0x535,
0x67A, 0x8C1, 0x2E2, 0xBC4, 0xBE8, 0x328, 0x04F, 0x257,
0x3F9, 0xFA5, 0x477, 0x12E, 0x94B, 0x116, 0xEF7, 0x65F,
0x6B3, 0x915, 0xC64, 0x9AF, 0xB6C, 0x6A2, 0x50D, 0xEA3,
0x26E, 0xC23, 0x817, 0xA42, 0x71A, 0x9DD, 0xDA8, 0x84D,
0x3F3, 0x85B, 0xB00, 0x1FC, 0xB0A, 0xC2F, 0x00C, 0x095,
0xC58, 0x0E3, 0x807, 0x962, 0xC4B, 0x29A, 0x6FC, 0x958,
0xD29, 0x59E, 0xB14, 0x95A, 0xEDE, 0xF3D, 0xFB8, 0x0E5,
0x348, 0x2E7, 0x38E, 0x56A, 0x410, 0x3B1, 0x4B0, 0x793,
0xAB7, 0x0BC, 0x648, 0x719, 0xE3E, 0xFB4, 0x3B4, 0xE5C,
0x950, 0xD2A, 0x50B, 0x76F, 0x8D2, 0x3C7, 0xECC, 0x87C,
0x53A, 0xBA7, 0x4C3, 0x148, 0x437, 0x820, 0xECD, 0x660,
0x095, 0x2F4, 0x661, 0x6A4, 0xB74, 0x5F3, 0x1D2, 0x7EC,
0x8E2, 0xA40, 0xA6F, 0xFC3, 0x3BE, 0x1E9, 0x52C, 0x233,
0x173, 0x4EF, 0xA7C, 0x40B, 0x14C, 0x88D, 0xF30, 0x8D9,
0xBDB, 0x0A6, 0x940, 0xD46, 0xB2B, 0x03E, 0x46A, 0x641,
0xF08, 0xAFF, 0x496, 0x68A, 0x7A4, 0x0BA, 0xD43, 0x515,
0xB26, 0xD8F, 0x05C, 0xD6E, 0xA2C, 0xF25, 0x628, 0x4E5,
0x81D, 0xA2A, 0x1FF, 0x302, 0xFBD, 0x6D9, 0x711, 0xD8B,
0xE5C, 0x5CF, 0x42E, 0x008, 0x863, 0xB6F, 0x1E1, 0x3DA,
0xACE, 0x82B, 0x2DB, 0x7EB, 0xC15, 0x79F, 0xA79, 0xDAF,
0x00D, 0x2F6, 0x0CE, 0x370, 0x7E8, 0x9E6, 0x89F, 0xAE9,
0x175, 0xA95, 0x06B, 0x9DF, 0xAFF, 0x45B, 0x823, 0xAA4,
0xC79, 0x773, 0x886, 0x854, 0x0A5, 0x6D1, 0xE55, 0xEBB,
0x518, 0xE50, 0xF8F, 0x8CC, 0x834, 0x388, 0xCD2, 0xFC1,
0xA55, 0x1F8, 0xD1F, 0xE08, 0xF93, 0x362, 0xA22, 0x9FA,
0xCE5, 0x3C3, 0xDD4, 0xC53, 0xB94, 0xAD0, 0x6EB, 0x68D,
0x660, 0x8FC, 0xBCD, 0x914, 0x16F, 0x4C0, 0x134, 0xE1A,
0x76F, 0x9CB, 0x660, 0xEA0, 0x320, 0x15A, 0xCE3, 0x7E8,
0x03E, 0xB9A, 0xC90, 0xA14, 0x256, 0x1A8, 0x639, 0x7C6,
0xA59, 0xA65, 0x956, 0x9E4, 0x592, 0x6A9, 0xCFF, 0x4DC,
0xAA3, 0xD2A, 0xFDE, 0xA87, 0xBF5, 0x9F0, 0xC32, 0x94F,
0x675, 0x9A6, 0x369, 0x648, 0x289, 0x823, 0x498, 0x574,
0x8D1, 0xA13, 0xD1A, 0xBB5, 0xA19, 0x7F7, 0x775, 0x138,
0x949, 0xA4C, 0xE36, 0x126, 0xC85, 0xE05, 0xFEE, 0x962,
0x36D, 0x08D, 0xC76, 0x1E1, 0x1EC, 0x8D7, 0x231, 0xB68,
0x03C, 0x1DE, 0x7DF, 0x2B1, 0x09D, 0xC81, 0xDA4, 0x8F7,
0x6B9, 0x947, 0x9B0
});
// synthetic test cases
testEncodeDecodeRandom(GenericGF.AZTEC_PARAM, 2, 5); // compact mode message
testEncodeDecodeRandom(GenericGF.AZTEC_PARAM, 4, 6); // full mode message
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_6, 10, 7);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_6, 20, 12);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_8, 20, 11);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_8, 128, 127);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_10, 128, 128);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_10, 768, 255);
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_12, 3072, 1023);
}
public static void corrupt(int[] received, int howMany, Random random, int max) {
BitSet corrupted = new BitSet(received.length);
for (int j = 0; j < howMany; j++) {
int location = random.nextInt(received.length);
int value = random.nextInt(max);
if (corrupted.get(location) || received[location] == value) {
j--;
} else {
corrupted.set(location);
received[location] = value;
}
}
}
private static void testEncodeDecodeRandom(GenericGF field, int dataSize, int ecSize) {
assertTrue("Invalid data size for " + field, dataSize > 0 && dataSize <= field.getSize() - 3);
assertTrue("Invalid ECC size for " + field, ecSize > 0 && ecSize + dataSize <= field.getSize());
ReedSolomonEncoder encoder = new ReedSolomonEncoder(field);
int[] message = new int[dataSize + ecSize];
int[] dataWords = new int[dataSize];
int[] ecWords = new int[ecSize];
Random random = getPseudoRandom();
int iterations = field.getSize() > 256 ? 1 : DECODER_RANDOM_TEST_ITERATIONS;
for (int i = 0; i < iterations; i++) {
// generate random data
for (int k = 0; k < dataSize; k++) {
dataWords[k] = random.nextInt(field.getSize());
}
// generate ECC words
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
encoder.encode(message, ecWords.length);
System.arraycopy(message, dataSize, ecWords, 0, ecSize);
// check to see if Decoder can fix up to ecWords/2 random errors
testDecoder(field, dataWords, ecWords);
}
}
private static void testEncodeDecode(GenericGF field, int[] dataWords, int[] ecWords) {
testEncoder(field, dataWords, ecWords);
testDecoder(field, dataWords, ecWords);
}
private static void testEncoder(GenericGF field, int[] dataWords, int[] ecWords) {
ReedSolomonEncoder encoder = new ReedSolomonEncoder(field);
int[] messageExpected = new int[dataWords.length + ecWords.length];
int[] message = new int[dataWords.length + ecWords.length];
System.arraycopy(dataWords, 0, messageExpected, 0, dataWords.length);
System.arraycopy(ecWords, 0, messageExpected, dataWords.length, ecWords.length);
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
encoder.encode(message, ecWords.length);
assertDataEquals("Encode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed",
messageExpected, message);
}
private static void testDecoder(GenericGF field, int[] dataWords, int[] ecWords) {
ReedSolomonDecoder decoder = new ReedSolomonDecoder(field);
int[] message = new int[dataWords.length + ecWords.length];
int maxErrors = ecWords.length / 2;
Random random = getPseudoRandom();
int iterations = field.getSize() > 256 ? 1 : DECODER_TEST_ITERATIONS;
for (int j = 0; j < iterations; j++) {
for (int i = 0; i < ecWords.length; i++) {
if (i > 10 && i < ecWords.length / 2 - 10) {
// performance improvement - skip intermediate cases in long-running tests
i += ecWords.length / 10;
}
System.arraycopy(dataWords, 0, message, 0, dataWords.length);
System.arraycopy(ecWords, 0, message, dataWords.length, ecWords.length);
corrupt(message, i, random, field.getSize());
try {
decoder.decode(message, ecWords.length);
} catch (ReedSolomonException e) {
// fail only if maxErrors exceeded
assertTrue("Decode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed at " +
i + " errors: " + e,
i > maxErrors);
// else stop
break;
}
if (i < maxErrors) {
assertDataEquals("Decode in " + field + " (" + dataWords.length + ',' + ecWords.length + ") failed at " +
i + " errors",
dataWords,
message);
}
}
}
}
private static void assertDataEquals(String message, int[] expected, int[] received) {
for (int i = 0; i < expected.length; i++) {
if (expected[i] != received[i]) {
fail(message + ". Mismatch at " + i + ". Expected " + arrayToString(expected) + ", got " +
arrayToString(Arrays.copyOf(received, expected.length)));
}
}
}
private static String arrayToString(int[] data) {
StringBuilder sb = new StringBuilder("{");
for (int i = 0; i < data.length; i++) {
sb.append(String.format(i > 0 ? ",%X" : "%X", data[i]));
}
return sb.append('}').toString();
}
private static Random getPseudoRandom() {
return new Random(0xDEADBEEF);
}
}