Add more unit tests for client.result, and more small code tweaks.

git-svn-id: https://zxing.googlecode.com/svn/trunk@809 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-12-30 15:31:25 +00:00
parent 36b4456516
commit 9433c5955b
37 changed files with 591 additions and 92 deletions

View file

@ -355,7 +355,7 @@ public final class AndroidHttpClient implements HttpClient {
} }
if (level < Log.VERBOSE || level > Log.ASSERT) { if (level < Log.VERBOSE || level > Log.ASSERT) {
throw new IllegalArgumentException("Level is out of range [" throw new IllegalArgumentException("Level is out of range ["
+ Log.VERBOSE + ".." + Log.ASSERT + "]"); + Log.VERBOSE + ".." + Log.ASSERT + ']');
} }
curlConfiguration = new LoggingConfiguration(name, level); curlConfiguration = new LoggingConfiguration(name, level);

View file

@ -320,7 +320,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
} }
if (mCopyToClipboard) { if (mCopyToClipboard) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(displayContents); clipboard.setText(displayContents);
} }
} }
@ -372,7 +372,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
mStatusView.setBackgroundColor(getResources().getColor(R.color.transparent)); mStatusView.setBackgroundColor(getResources().getColor(R.color.transparent));
if (mCopyToClipboard) { if (mCopyToClipboard) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(resultHandler.getDisplayContents()); clipboard.setText(resultHandler.getDisplayContents());
} }
@ -436,7 +436,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
mMediaPlayer.start(); mMediaPlayer.start();
} }
if (mVibrate) { if (mVibrate) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION); vibrator.vibrate(VIBRATE_DURATION);
} }
} }

View file

@ -20,6 +20,9 @@ import android.provider.Contacts;
public final class Contents { public final class Contents {
private Contents() {
}
/** /**
* All the formats we know about. * All the formats we know about.
*/ */
@ -31,6 +34,8 @@ public final class Contents {
public static final String CODE_39 = "CODE_39"; public static final String CODE_39 = "CODE_39";
public static final String CODE_128 = "CODE_128"; public static final String CODE_128 = "CODE_128";
public static final String QR_CODE = "QR_CODE"; public static final String QR_CODE = "QR_CODE";
private Format() {
}
} }
public static final class Type { public static final class Type {
@ -79,6 +84,9 @@ public final class Contents {
* intent.putExtra(Intents.Encode.DATA, bundle); * intent.putExtra(Intents.Encode.DATA, bundle);
*/ */
public static final String LOCATION = "LOCATION_TYPE"; public static final String LOCATION = "LOCATION_TYPE";
private Type() {
}
} }
// These are new constants in Contacts.Intents.Insert for Android 1.1. // These are new constants in Contacts.Intents.Insert for Android 1.1.

View file

@ -18,6 +18,9 @@ package com.google.zxing.client.android;
public final class Intents { public final class Intents {
private Intents() {
}
public static final class Scan { public static final class Scan {
/** /**
* Send this intent to open the Barcodes app in scanning mode, find a barcode, and return * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return
@ -64,6 +67,9 @@ public final class Intents {
* See Contents.Format for possible values. * See Contents.Format for possible values.
*/ */
public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT";
private Scan() {
}
} }
public static final class Encode { public static final class Encode {
@ -87,6 +93,9 @@ public final class Intents {
* Contents.Type. * Contents.Type.
*/ */
public static final String TYPE = "ENCODE_TYPE"; public static final String TYPE = "ENCODE_TYPE";
private Encode() {
}
} }
public static final class SearchBookContents { public static final class SearchBookContents {
@ -107,6 +116,9 @@ public final class Intents {
* An optional field which is the text to search for. * An optional field which is the text to search for.
*/ */
public static final String QUERY = "QUERY"; public static final String QUERY = "QUERY";
private SearchBookContents() {
}
} }
public static final class Share { public static final class Share {
@ -115,6 +127,9 @@ public final class Intents {
* display onscreen for a friend to scan with their phone. * display onscreen for a friend to scan with their phone.
*/ */
public static final String ACTION = "com.google.zxing.client.android.SHARE"; public static final String ACTION = "com.google.zxing.client.android.SHARE";
private Share() {
}
} }
} }

View file

@ -32,8 +32,6 @@ import com.google.zxing.common.ByteMatrix;
public final class QRCodeEncoder { public final class QRCodeEncoder {
private static final String TAG = "QRCodeEncoder";
private final Activity mActivity; private final Activity mActivity;
private String mContents; private String mContents;
private String mDisplayContents; private String mDisplayContents;
@ -74,31 +72,31 @@ public final class QRCodeEncoder {
} }
if (type.equals(Contents.Type.TEXT)) { if (type.equals(Contents.Type.TEXT)) {
String string = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (string != null && string.length() > 0) { if (data != null && data.length() > 0) {
mContents = string; mContents = data;
mDisplayContents = string; mDisplayContents = data;
mTitle = mActivity.getString(R.string.contents_text); mTitle = mActivity.getString(R.string.contents_text);
} }
} else if (type.equals(Contents.Type.EMAIL)) { } else if (type.equals(Contents.Type.EMAIL)) {
String string = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (string != null && string.length() > 0) { if (data != null && data.length() > 0) {
mContents = "mailto:" + string; mContents = "mailto:" + data;
mDisplayContents = string; mDisplayContents = data;
mTitle = mActivity.getString(R.string.contents_email); mTitle = mActivity.getString(R.string.contents_email);
} }
} else if (type.equals(Contents.Type.PHONE)) { } else if (type.equals(Contents.Type.PHONE)) {
String string = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (string != null && string.length() > 0) { if (data != null && data.length() > 0) {
mContents = "tel:" + string; mContents = "tel:" + data;
mDisplayContents = PhoneNumberUtils.formatNumber(string); mDisplayContents = PhoneNumberUtils.formatNumber(data);
mTitle = mActivity.getString(R.string.contents_phone); mTitle = mActivity.getString(R.string.contents_phone);
} }
} else if (type.equals(Contents.Type.SMS)) { } else if (type.equals(Contents.Type.SMS)) {
String string = intent.getStringExtra(Intents.Encode.DATA); String data = intent.getStringExtra(Intents.Encode.DATA);
if (string != null && string.length() > 0) { if (data != null && data.length() > 0) {
mContents = "sms:" + string; mContents = "sms:" + data;
mDisplayContents = PhoneNumberUtils.formatNumber(string); mDisplayContents = PhoneNumberUtils.formatNumber(data);
mTitle = mActivity.getString(R.string.contents_sms); mTitle = mActivity.getString(R.string.contents_sms);
} }
} else if (type.equals(Contents.Type.CONTACT)) { } else if (type.equals(Contents.Type.CONTACT)) {
@ -106,25 +104,25 @@ public final class QRCodeEncoder {
if (bundle != null) { if (bundle != null) {
String name = bundle.getString(Contacts.Intents.Insert.NAME); String name = bundle.getString(Contacts.Intents.Insert.NAME);
if (name != null && name.length() > 0) { if (name != null && name.length() > 0) {
mContents = "MECARD:N:" + name + ";"; mContents = "MECARD:N:" + name + ';';
mDisplayContents = name; mDisplayContents = name;
String address = bundle.getString(Contacts.Intents.Insert.POSTAL); String address = bundle.getString(Contacts.Intents.Insert.POSTAL);
if (address != null && address.length() > 0) { if (address != null && address.length() > 0) {
mContents += "ADR:" + address + ";"; mContents += "ADR:" + address + ';';
mDisplayContents += "\n" + address; mDisplayContents += '\n' + address;
} }
for (int x = 0; x < Contents.PHONE_KEYS.length; x++) { for (int x = 0; x < Contents.PHONE_KEYS.length; x++) {
String phone = bundle.getString(Contents.PHONE_KEYS[x]); String phone = bundle.getString(Contents.PHONE_KEYS[x]);
if (phone != null && phone.length() > 0) { if (phone != null && phone.length() > 0) {
mContents += "TEL:" + phone + ";"; mContents += "TEL:" + phone + ';';
mDisplayContents += "\n" + PhoneNumberUtils.formatNumber(phone); mDisplayContents += '\n' + PhoneNumberUtils.formatNumber(phone);
} }
} }
for (int x = 0; x < Contents.EMAIL_KEYS.length; x++) { for (int x = 0; x < Contents.EMAIL_KEYS.length; x++) {
String email = bundle.getString(Contents.EMAIL_KEYS[x]); String email = bundle.getString(Contents.EMAIL_KEYS[x]);
if (email != null && email.length() > 0) { if (email != null && email.length() > 0) {
mContents += "EMAIL:" + email + ";"; mContents += "EMAIL:" + email + ';';
mDisplayContents += "\n" + email; mDisplayContents += '\n' + email;
} }
} }
mContents += ";"; mContents += ";";
@ -134,10 +132,10 @@ public final class QRCodeEncoder {
} else if (type.equals(Contents.Type.LOCATION)) { } else if (type.equals(Contents.Type.LOCATION)) {
Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA); Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA);
if (bundle != null) { if (bundle != null) {
float latitude = bundle.getFloat("LAT", Float.MAX_VALUE); double latitude = bundle.getDouble("LAT", Double.NaN);
float longitude = bundle.getFloat("LONG", Float.MAX_VALUE); double longitude = bundle.getDouble("LONG", Double.NaN);
if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) { if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
mContents = "geo:" + latitude + "," + longitude; mContents = "geo:" + latitude + ',' + longitude;
mDisplayContents = latitude + "," + longitude; mDisplayContents = latitude + "," + longitude;
mTitle = mActivity.getString(R.string.contents_location); mTitle = mActivity.getString(R.string.contents_location);
} }
@ -148,11 +146,13 @@ public final class QRCodeEncoder {
private static final class EncodeThread extends Thread { private static final class EncodeThread extends Thread {
private static final String TAG = "EncodeThread";
private final String mContents; private final String mContents;
private final Handler mHandler; private final Handler mHandler;
private final int mPixelResolution; private final int mPixelResolution;
public EncodeThread(String contents, Handler handler, int pixelResolution) { EncodeThread(String contents, Handler handler, int pixelResolution) {
mContents = contents; mContents = contents;
mHandler = handler; mHandler = handler;
mPixelResolution = pixelResolution; mPixelResolution = pixelResolution;
@ -169,7 +169,8 @@ public final class QRCodeEncoder {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
int grey = array[y][x] & 0xff; int grey = array[y][x] & 0xff;
pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey; //pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;
pixels[y * width + x] = 0xff000000 | (0x00010101 * grey);
} }
} }

View file

@ -198,7 +198,7 @@ public final class SearchBookContentsActivity extends Activity {
try { try {
String pageNumber = json.getString("page_number"); String pageNumber = json.getString("page_number");
if (pageNumber.length() > 0) { if (pageNumber.length() > 0) {
pageNumber = getString(R.string.msg_sbc_page) + " " + pageNumber; pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
} else { } else {
// This can happen for text on the jacket, and possibly other reasons. // This can happen for text on the jacket, and possibly other reasons.
pageNumber = getString(R.string.msg_sbc_unknown_page); pageNumber = getString(R.string.msg_sbc_unknown_page);
@ -214,7 +214,7 @@ public final class SearchBookContentsActivity extends Activity {
snippet = snippet.replaceAll("&#39;", "'"); snippet = snippet.replaceAll("&#39;", "'");
snippet = snippet.replaceAll("&quot;", "\""); snippet = snippet.replaceAll("&quot;", "\"");
} else { } else {
snippet = "(" + getString(R.string.msg_sbc_snippet_unavailable) + ")"; snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
valid = false; valid = false;
} }
return new SearchBookContentsResult(pageNumber, snippet, valid); return new SearchBookContentsResult(pageNumber, snippet, valid);
@ -231,7 +231,7 @@ public final class SearchBookContentsActivity extends Activity {
private final Handler mHandler; private final Handler mHandler;
private final String mUserAgent; private final String mUserAgent;
public NetworkThread(String isbn, String query, Handler handler, String userAgent) { NetworkThread(String isbn, String query, Handler handler, String userAgent) {
mISBN = isbn; mISBN = isbn;
mQuery = query; mQuery = query;
mHandler = handler; mHandler = handler;
@ -305,7 +305,7 @@ public final class SearchBookContentsActivity extends Activity {
return cookie; return cookie;
} }
private String getEncoding(HttpEntity entity) { private static String getEncoding(HttpEntity entity) {
// FIXME: The server is returning ISO-8859-1 but the content is actually windows-1252. // FIXME: The server is returning ISO-8859-1 but the content is actually windows-1252.
// Once Jeff fixes the HTTP response, remove this hardcoded value and go back to getting // Once Jeff fixes the HTTP response, remove this hardcoded value and go back to getting
// the encoding dynamically. // the encoding dynamically.

View file

@ -47,10 +47,12 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource {
assert (crop.height() <= dataHeight); assert (crop.height() <= dataHeight);
} }
@Override
public int getHeight() { public int getHeight() {
return mCrop.height(); return mCrop.height();
} }
@Override
public int getWidth() { public int getWidth() {
return mCrop.width(); return mCrop.width();
} }
@ -63,10 +65,12 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource {
* @param y The y coordinate to fetch within crop * @param y The y coordinate to fetch within crop
* @return The luminance as an int, from 0-255 * @return The luminance as an int, from 0-255
*/ */
@Override
protected int getLuminance(int x, int y) { protected int getLuminance(int x, int y) {
return mYUVData[(y + mCrop.top) * mDataWidth + x + mCrop.left] & 0xff; return mYUVData[(y + mCrop.top) * mDataWidth + x + mCrop.left] & 0xff;
} }
@Override
protected int[] getLuminanceRow(int y, int[] row) { protected int[] getLuminanceRow(int y, int[] row) {
int width = getWidth(); int width = getWidth();
if (row == null || row.length < width) { if (row == null || row.length < width) {
@ -79,6 +83,7 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource {
return row; return row;
} }
@Override
protected int[] getLuminanceColumn(int x, int[] column) { protected int[] getLuminanceColumn(int x, int[] column) {
int height = getHeight(); int height = getHeight();
if (column == null || column.length < height) { if (column == null || column.length < height) {

View file

@ -35,7 +35,7 @@ public final class AddressBookResultHandler extends ResultHandler {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd"); private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
private final boolean[] mFields; private final boolean[] mFields;
private int mButtonCount; private final int mButtonCount;
// This takes all the work out of figuring out which buttons/actions should be in which // This takes all the work out of figuring out which buttons/actions should be in which
// positions, based on which fields are present in this barcode. // positions, based on which fields are present in this barcode.
@ -139,7 +139,7 @@ public final class AddressBookResultHandler extends ResultHandler {
if (pronunciation != null && pronunciation.length() > 0) { if (pronunciation != null && pronunciation.length() > 0) {
contents.append("\n("); contents.append("\n(");
contents.append(pronunciation); contents.append(pronunciation);
contents.append(")"); contents.append(')');
} }
ParsedResult.maybeAppend(result.getTitle(), contents); ParsedResult.maybeAppend(result.getTitle(), contents);

View file

@ -45,7 +45,7 @@ public abstract class ResultHandler {
protected final ParsedResult mResult; protected final ParsedResult mResult;
private final Activity mActivity; private final Activity mActivity;
public ResultHandler(Activity activity, ParsedResult result) { protected ResultHandler(Activity activity, ParsedResult result) {
mResult = result; mResult = result;
mActivity = activity; mActivity = activity;
} }
@ -119,7 +119,7 @@ public abstract class ResultHandler {
launchIntent(intent); launchIntent(intent);
} }
private long calculateMilliseconds(String when) { private static long calculateMilliseconds(String when) {
if (when.length() == 8) { if (when.length() == 8) {
// Only contains year/month/day // Only contains year/month/day
Date date; Date date;
@ -237,14 +237,14 @@ public abstract class ResultHandler {
public final void searchMap(String address, String title) { public final void searchMap(String address, String title) {
String query = address; String query = address;
if (title != null && title.length() > 0) { if (title != null && title.length() > 0) {
query = query + " (" + title + ")"; query = query + " (" + title + ')';
} }
launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query)))); launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query))));
} }
public final void getDirections(float latitude, float longitude) { public final void getDirections(float latitude, float longitude) {
launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google." + launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google." +
LocaleManager.getCountryTLD() + "/maps?f=d&daddr=" + latitude + "," + longitude))); LocaleManager.getCountryTLD() + "/maps?f=d&daddr=" + latitude + ',' + longitude)));
} }
public final void openProductSearch(String upc) { public final void openProductSearch(String upc) {

View file

@ -24,6 +24,9 @@ import com.google.zxing.client.result.ResultParser;
public final class ResultHandlerFactory { public final class ResultHandlerFactory {
private ResultHandlerFactory() {
}
public static ResultHandler makeResultHandler(Activity activity, Result rawResult) { public static ResultHandler makeResultHandler(Activity activity, Result rawResult) {
ParsedResult result = parseResult(rawResult); ParsedResult result = parseResult(rawResult);
ParsedResultType type = result.getType(); ParsedResultType type = result.getType();

View file

@ -76,7 +76,7 @@ public final class BenchmarkActivity extends Activity {
} }
}; };
private void handleBenchmarkDone(Message message) { private static void handleBenchmarkDone(Message message) {
List<BenchmarkItem> items = (List<BenchmarkItem>) message.obj; List<BenchmarkItem> items = (List<BenchmarkItem>) message.obj;
int count = 0; int count = 0;
for (int x = 0; x < items.size(); x++) { for (int x = 0; x < items.size(); x++) {

View file

@ -21,7 +21,7 @@ import com.google.zxing.BarcodeFormat;
public final class BenchmarkItem { public final class BenchmarkItem {
private final String mPath; private final String mPath;
private int[] mTimes; private final int[] mTimes;
private int mPosition; private int mPosition;
private boolean mDecoded; private boolean mDecoded;
private BarcodeFormat mFormat; private BarcodeFormat mFormat;
@ -50,7 +50,7 @@ public final class BenchmarkItem {
@Override @Override
public String toString() { public String toString() {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: "); result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: ");
result.append(mPath); result.append(mPath);
result.append(" ("); result.append(" (");

View file

@ -64,7 +64,7 @@ final class BenchmarkThread extends Thread {
String[] files = file.list(); String[] files = file.list();
Arrays.sort(files); Arrays.sort(files);
for (int x = 0; x < files.length; x++) { for (int x = 0; x < files.length; x++) {
walkTree(file.getAbsolutePath() + "/" + files[x], items); walkTree(file.getAbsolutePath() + '/' + files[x], items);
} }
} else { } else {
BenchmarkItem item = decode(path); BenchmarkItem item = decode(path);

View file

@ -24,9 +24,9 @@ import java.io.FileNotFoundException;
public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource { public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource {
private int mWidth; private final int mWidth;
private int mHeight; private final int mHeight;
private byte[] mLuminances; private final byte[] mLuminances;
public RGBMonochromeBitmapSource(String path) throws FileNotFoundException { public RGBMonochromeBitmapSource(String path) throws FileNotFoundException {
Bitmap bitmap = BitmapFactory.decodeFile(path); Bitmap bitmap = BitmapFactory.decodeFile(path);
@ -62,18 +62,22 @@ public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource
} }
} }
@Override
public int getHeight() { public int getHeight() {
return mHeight; return mHeight;
} }
@Override
public int getWidth() { public int getWidth() {
return mWidth; return mWidth;
} }
@Override
protected int getLuminance(int x, int y) { protected int getLuminance(int x, int y) {
return mLuminances[y * mWidth + x] & 0xff; return mLuminances[y * mWidth + x] & 0xff;
} }
@Override
protected int[] getLuminanceRow(int y, int[] row) { protected int[] getLuminanceRow(int y, int[] row) {
int width = mWidth; int width = mWidth;
if (row == null || row.length < width) { if (row == null || row.length < width) {
@ -86,6 +90,7 @@ public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource
return row; return row;
} }
@Override
protected int[] getLuminanceColumn(int x, int[] column) { protected int[] getLuminanceColumn(int x, int[] column) {
int width = mWidth; int width = mWidth;
int height = mHeight; int height = mHeight;

View file

@ -102,7 +102,7 @@ final class SaveThread extends Thread {
message.sendToTarget(); message.sendToTarget();
} }
private OutputStream getNewPhotoOutputStream() { private static OutputStream getNewPhotoOutputStream() {
File sdcard = new File("/sdcard"); File sdcard = new File("/sdcard");
if (sdcard.exists()) { if (sdcard.exists()) {
File barcodes = new File(sdcard, "barcodes"); File barcodes = new File(sdcard, "barcodes");

View file

@ -22,11 +22,11 @@ package com.google.zxing.client.result;
public final class GeoParsedResult extends ParsedResult { public final class GeoParsedResult extends ParsedResult {
private final String geoURI; private final String geoURI;
private final float latitude; private final double latitude;
private final float longitude; private final double longitude;
private final float altitude; private final double altitude;
GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) { GeoParsedResult(String geoURI, double latitude, double longitude, double altitude) {
super(ParsedResultType.GEO); super(ParsedResultType.GEO);
this.geoURI = geoURI; this.geoURI = geoURI;
this.latitude = latitude; this.latitude = latitude;
@ -41,21 +41,21 @@ public final class GeoParsedResult extends ParsedResult {
/** /**
* @return latitude in degrees * @return latitude in degrees
*/ */
public float getLatitude() { public double getLatitude() {
return latitude; return latitude;
} }
/** /**
* @return longitude in degrees * @return longitude in degrees
*/ */
public float getLongitude() { public double getLongitude() {
return longitude; return longitude;
} }
/** /**
* @return altitude in meters. If not specified, in the geo URI, returns 0.0 * @return altitude in meters. If not specified, in the geo URI, returns 0.0
*/ */
public float getAltitude() { public double getAltitude() {
return altitude; return altitude;
} }
@ -87,8 +87,8 @@ public final class GeoParsedResult extends ParsedResult {
if (altitude > 0.0f) { if (altitude > 0.0f) {
// Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a // Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
// view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on. // view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
float altitudeInFeet = altitude * 3.28f; double altitudeInFeet = altitude * 3.28;
int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f); int altitudeInKFeet = (int) (altitudeInFeet / 1000.0);
// No Math.log() available here, so compute log base 2 the old fashioned way // No Math.log() available here, so compute log base 2 the old fashioned way
// Here logBaseTwo will take on a value between 0 and 18 actually // Here logBaseTwo will take on a value between 0 and 18 actually
int logBaseTwo = 0; int logBaseTwo = 0;

View file

@ -48,16 +48,16 @@ final class GeoResultParser extends ResultParser {
if (latitudeEnd < 0) { if (latitudeEnd < 0) {
return null; return null;
} }
float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd)); double latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1); int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
float longitude; double longitude;
float altitude; // in meters double altitude; // in meters
if (longitudeEnd < 0) { if (longitudeEnd < 0) {
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1)); longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1));
altitude = 0.0f; altitude = 0.0;
} else { } else {
longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd)); longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1)); altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1));
} }
return new GeoParsedResult(rawText, latitude, longitude, altitude); return new GeoParsedResult(rawText, latitude, longitude, altitude);
} }

View file

@ -39,7 +39,7 @@ final class URLTOResultParser {
if (titleEnd < 0) { if (titleEnd < 0) {
return null; return null;
} }
String title = rawText.substring(6, titleEnd); String title = titleEnd <= 6 ? null : rawText.substring(6, titleEnd);
String uri = rawText.substring(titleEnd + 1); String uri = rawText.substring(titleEnd + 1);
return new URIParsedResult(uri, title); return new URIParsedResult(uri, title);
} }

View file

@ -199,7 +199,7 @@ public final class ITFReader extends AbstractOneDReader {
* @return index of the first black line. * @return index of the first black line.
* @throws ReaderException Throws exception if no black lines are found in the row * @throws ReaderException Throws exception if no black lines are found in the row
*/ */
private int skipWhiteSpace(BitArray row) throws ReaderException { private static int skipWhiteSpace(BitArray row) throws ReaderException {
int width = row.getSize(); int width = row.getSize();
int endStart = 0; int endStart = 0;
while (endStart < width) { while (endStart < width) {
@ -266,7 +266,7 @@ public final class ITFReader extends AbstractOneDReader {
* ints * ints
* @throws ReaderException if pattern is not found * @throws ReaderException if pattern is not found
*/ */
int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException { static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException {
// TODO: This is very similar to implementation in AbstractUPCEANReader. Consider if they can be merged to // TODO: This is very similar to implementation in AbstractUPCEANReader. Consider if they can be merged to
// a single method. // a single method.

View file

@ -112,7 +112,7 @@ final class FormatInformation {
return doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR); return doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR);
} }
private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) throws ReaderException { private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) {
// Unmask: // Unmask:
int unmaskedFormatInfo = rawFormatInfo ^ FORMAT_INFO_MASK_QR; int unmaskedFormatInfo = rawFormatInfo ^ FORMAT_INFO_MASK_QR;
// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing

View file

@ -0,0 +1,82 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
import java.util.Arrays;
/**
* Tests {@link AddressBookParsedResult}.
*
* @author Sean Owen
*/
public final class AddressBookParsedResultTestCase extends TestCase {
public void testAddressBookDocomo() {
doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"}, 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,
"google.com", null, "ZXing Team");
}
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, "foo");
}
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, "123 Main St", null, null, null, null, null, null);
}
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, "123 Main St", new String[] {"srowen@example.org"},
new String[] {"+12125551212"}, "Google", null, null, null);
}
private static void doTest(String contents,
String title,
String[] names,
String pronunciation,
String address,
String[] emails,
String[] phoneNumbers,
String org,
String url,
String birthday,
String note) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertEquals(ParsedResultType.ADDRESSBOOK, result.getType());
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
assertEquals(title, addressResult.getTitle());
assertTrue(Arrays.equals(names, addressResult.getNames()));
assertEquals(pronunciation, addressResult.getPronunciation());
assertEquals(address, addressResult.getAddress());
assertTrue(Arrays.equals(emails, addressResult.getEmails()));
assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
assertEquals(org, addressResult.getOrg());
assertEquals(url, addressResult.getURL());
assertEquals(birthday, addressResult.getBirthday());
assertEquals(note, addressResult.getNote());
}
}

View file

@ -0,0 +1,56 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link CalendarParsedResult}.
*
* @author Sean Owen
*/
public final class CalendarParsedResultTestCase extends TestCase {
public void testVEvent() {
doTest(
"BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nDTEND:20080505T234555Z\r\n" +
"END:VEVENT\r\nEND:VCALENDAR",
null, "foo", null, "20080504T123456Z", "20080505T234555Z", null);
}
private static void doTest(String contents,
String title,
String summary,
String location,
String start,
String end,
String attendee) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertEquals(ParsedResultType.CALENDAR, result.getType());
CalendarParsedResult calResult = (CalendarParsedResult) result;
assertEquals(title, calResult.getTitle());
assertEquals(summary, calResult.getSummary());
assertEquals(location, calResult.getLocation());
assertEquals(start, calResult.getStart());
assertEquals(end, calResult.getEnd());
assertEquals(attendee, calResult.getAttendee());
}
}

View file

@ -0,0 +1,53 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link EmailAddressParsedResult}.
*
* @author Sean Owen
*/
public final class EmailAddressParsedResultTestCase extends TestCase {
public void testEmailAddress() {
doTest("srowen@example.org", "srowen@example.org", null, null);
doTest("mailto:srowen@example.org", "srowen@example.org", null, null);
}
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");
}
private static void doTest(String contents, String email, String subject, String body) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertEquals(ParsedResultType.EMAIL_ADDRESS, result.getType());
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
assertEquals(email, emailResult.getEmailAddress());
assertEquals("mailto:" + email, emailResult.getMailtoURI());
assertEquals(subject, emailResult.getSubject());
assertEquals(body, emailResult.getBody());
}
}

View file

@ -0,0 +1,45 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link com.google.zxing.client.result.GeoParsedResult}.
*
* @author Sean Owen
*/
public final class GeoParsedResultTestCase extends TestCase {
public void testGeo() {
doTest("geo:1,2", 1.0, 2.0, 0.0);
doTest("geo:100.33,-32.3344,3.35", 100.33, -32.3344, 3.35);
}
private static void doTest(String contents, double latitude, double longitude, double altitude) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertEquals(ParsedResultType.GEO, result.getType());
GeoParsedResult geoResult = (GeoParsedResult) result;
assertEquals(latitude, geoResult.getLatitude());
assertEquals(longitude, geoResult.getLongitude());
assertEquals(altitude, geoResult.getAltitude());
}
}

View file

@ -0,0 +1,42 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link ISBNParsedResult}.
*
* @author Sean Owen
*/
public final class ISBNParsedResultTestCase extends TestCase {
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);
assertEquals(ParsedResultType.ISBN, result.getType());
ISBNParsedResult isbnResult = (ISBNParsedResult) result;
assertEquals(contents, isbnResult.getISBN());
}
}

View file

@ -104,12 +104,21 @@ public final class ParsedReaderResultTestCase extends TestCase {
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK); doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK);
} }
public void testUPC() { 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);
}
public void testUPCA() {
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A); doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A); doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT); doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
} }
public void testUPCE() {
doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E);
}
public void testEAN() { public void testEAN() {
doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8); doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
doTestResult("00393158", "00393158", ParsedResultType.TEXT); doTestResult("00393158", "00393158", ParsedResultType.TEXT);

View file

@ -0,0 +1,46 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link ProductParsedResult}.
*
* @author Sean Owen
*/
public final class ProductParsedResultTestCase extends TestCase {
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);
assertEquals(ParsedResultType.PRODUCT, result.getType());
ProductParsedResult productResult = (ProductParsedResult) result;
assertEquals(contents, productResult.getProductID());
assertEquals(normalized, productResult.getNormalizedProductID());
}
}

View file

@ -0,0 +1,54 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link SMSParsedResult}.
*
* @author Sean Owen
*/
public final class SMSMMSParsedResultTestCase extends TestCase {
public void testSMS() {
doTest("sms:+15551212", "+15551212", null, null, null);
doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333");
}
public void testMMS() {
doTest("mms:+15551212", "+15551212", null, null, null);
doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333");
}
private static void doTest(String contents, String number, String subject, String body, String via) {
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
ParsedResult result = ResultParser.parseResult(fakeResult);
assertEquals(ParsedResultType.SMS, result.getType());
SMSParsedResult smsResult = (SMSParsedResult) result;
assertEquals(number, smsResult.getNumber());
assertEquals(subject, smsResult.getSubject());
assertEquals(body, smsResult.getBody());
assertEquals(via, smsResult.getVia());
assertEquals("sms:" + number, smsResult.getSMSURI());
}
}

View file

@ -0,0 +1,45 @@
/*
* 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 junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/**
* Tests {@link TelParsedResult}.
*
* @author Sean Owen
*/
public final class TelParsedResultTestCase extends TestCase {
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);
assertEquals(ParsedResultType.TEL, result.getType());
TelParsedResult telResult = (TelParsedResult) result;
assertEquals(number, telResult.getNumber());
assertEquals(title, telResult.getTitle());
assertEquals("tel:" + number, telResult.getTelURI());
}
}

View file

@ -17,14 +17,35 @@
package com.google.zxing.client.result; package com.google.zxing.client.result;
import junit.framework.TestCase; import junit.framework.TestCase;
import com.google.zxing.Result;
import com.google.zxing.BarcodeFormat;
/** /**
* Tests {@link com.google.zxing.client.result.URIParsedResult}. * Tests {@link URIParsedResult}.
* *
* @author Sean Owen * @author Sean Owen
*/ */
public final class URIParsedResultTestCase extends TestCase { public final class URIParsedResultTestCase extends TestCase {
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");
}
public void testURI() {
doTest("google.com", "http://google.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);
}
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");
}
public void testIsPossiblyMalicious() { public void testIsPossiblyMalicious() {
doTestIsPossiblyMalicious("http://google.com", false); doTestIsPossiblyMalicious("http://google.com", false);
doTestIsPossiblyMalicious("http://google.com@evil.com", true); doTestIsPossiblyMalicious("http://google.com@evil.com", true);
@ -34,7 +55,16 @@ public final class URIParsedResultTestCase extends TestCase {
doTestIsPossiblyMalicious("http://google.com/foo@bar", false); doTestIsPossiblyMalicious("http://google.com/foo@bar", false);
} }
private void doTestIsPossiblyMalicious(String uri, boolean expected) { 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);
assertEquals(ParsedResultType.URI, result.getType());
URIParsedResult uriResult = (URIParsedResult) result;
assertEquals(uri, uriResult.getURI());
assertEquals(title, uriResult.getTitle());
}
private static void doTestIsPossiblyMalicious(String uri, boolean expected) {
URIParsedResult result = new URIParsedResult(uri, null); URIParsedResult result = new URIParsedResult(uri, null);
assertEquals(expected, result.isPossiblyMaliciousURI()); assertEquals(expected, result.isPossiblyMaliciousURI());
} }

View file

@ -192,14 +192,14 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
if (!expectedFormat.equals(result.getBarcodeFormat())) { if (!expectedFormat.equals(result.getBarcodeFormat())) {
System.out.println("Format mismatch: expected '" + expectedFormat + "' but got '" + System.out.println("Format mismatch: expected '" + expectedFormat + "' but got '" +
result.getBarcodeFormat() + "'" + suffix); result.getBarcodeFormat() + '\'' + suffix);
return false; return false;
} }
String resultText = result.getText(); String resultText = result.getText();
if (!expectedText.equals(resultText)) { if (!expectedText.equals(resultText)) {
System.out.println("Mismatch: expected '" + expectedText + "' but got '" + resultText + System.out.println("Mismatch: expected '" + expectedText + "' but got '" + resultText +
"'" + suffix); '\'' + suffix);
return false; return false;
} }
return true; return true;

View file

@ -27,10 +27,10 @@ public final class ReedSolomonEncoderQRCodeTestCase extends AbstractReedSolomonT
* Tests example given in ISO 18004, Annex I * Tests example given in ISO 18004, Annex I
*/ */
public void testISO18004Example() { public void testISO18004Example() {
int[] dataBytes = new int[] { int[] dataBytes = {
0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11,
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }; 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 };
int[] expectedECBytes = new int[] { int[] expectedECBytes = {
0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87,
0x2C, 0x55 }; 0x2C, 0x55 };
doTestQRCodeEncoding(dataBytes, expectedECBytes); doTestQRCodeEncoding(dataBytes, expectedECBytes);

View file

@ -105,7 +105,7 @@ public final class QRCodeWriterTestCase extends TestCase {
assertNotNull(goldenResult); assertNotNull(goldenResult);
QRCodeWriter writer = new QRCodeWriter(); QRCodeWriter writer = new QRCodeWriter();
Hashtable hints = new Hashtable(); Hashtable<EncodeHintType,Object> hints = new Hashtable<EncodeHintType,Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel); hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel);
ByteMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution, ByteMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution,
resolution, hints); resolution, hints);
@ -121,7 +121,7 @@ public final class QRCodeWriterTestCase extends TestCase {
// Golden images are generated with "qrcode_sample.cc". The images are checked with both eye balls // Golden images are generated with "qrcode_sample.cc". The images are checked with both eye balls
// and cell phones. We expect pixel-perfect results, because the error correction level is known, // and cell phones. We expect pixel-perfect results, because the error correction level is known,
// and the pixel dimensions matches exactly. // and the pixel dimensions matches exactly.
public void testRegressionTest() throws WriterException, IOException { public void testRegressionTest() throws WriterException {
compareToGoldenFile("http://www.google.com/", ErrorCorrectionLevel.M, 99, compareToGoldenFile("http://www.google.com/", ErrorCorrectionLevel.M, 99,
"renderer-test-01.png"); "renderer-test-01.png");

View file

@ -110,7 +110,7 @@ public final class DataMaskTestCase extends TestCase {
} }
} }
private static interface MaskCondition { private interface MaskCondition {
boolean isMasked(int i, int j); boolean isMasked(int i, int j);
} }

View file

@ -57,7 +57,7 @@ public final class VersionTestCase extends TestCase {
} }
} }
public void testDecodeVersionInformation() throws ReaderException { public void testDecodeVersionInformation() {
// Spot check // Spot check
assertEquals(7, Version.decodeVersionInformation(0x07C94).getVersionNumber()); assertEquals(7, Version.decodeVersionInformation(0x07C94).getVersionNumber());
assertEquals(12, Version.decodeVersionInformation(0x0C762).getVersionNumber()); assertEquals(12, Version.decodeVersionInformation(0x0C762).getVersionNumber());

View file

@ -125,7 +125,7 @@ public final class EncoderTestCase extends TestCase {
assertEquals(expected, qrCode.toString()); assertEquals(expected, qrCode.toString());
} }
public void testAppendModeInfo() throws WriterException { public void testAppendModeInfo() {
BitVector bits = new BitVector(); BitVector bits = new BitVector();
Encoder.appendModeInfo(Mode.NUMERIC, bits); Encoder.appendModeInfo(Mode.NUMERIC, bits);
assertEquals("0001", bits.toString()); assertEquals("0001", bits.toString());
@ -444,9 +444,9 @@ public final class EncoderTestCase extends TestCase {
// http://www.swetake.com/qr/qr9.html // http://www.swetake.com/qr/qr9.html
public void testGenerateECBytes() { public void testGenerateECBytes() {
{ {
final byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236}; byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17); ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17);
final int[] expected = { int[] expected = {
42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61
}; };
assertEquals(expected.length, ecBytes.size()); assertEquals(expected.length, ecBytes.size());
@ -455,10 +455,10 @@ public final class EncoderTestCase extends TestCase {
} }
} }
{ {
final byte[] dataBytes = {67, 70, 22, 38, 54, 70, 86, 102, 118, byte[] dataBytes = {67, 70, 22, 38, 54, 70, 86, 102, 118,
(byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214}; (byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 18); ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 18);
final int[] expected = { int[] expected = {
175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187 175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187
}; };
assertEquals(expected.length, ecBytes.size()); assertEquals(expected.length, ecBytes.size());
@ -468,9 +468,9 @@ public final class EncoderTestCase extends TestCase {
} }
{ {
// High-order zero cofficient case. // High-order zero cofficient case.
final byte[] dataBytes = {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17}; byte[] dataBytes = {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17); ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17);
final int[] expected = { int[] expected = {
0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213 0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213
}; };
assertEquals(expected.length, ecBytes.size()); assertEquals(expected.length, ecBytes.size());

View file

@ -158,7 +158,7 @@ public final class ImageConverter {
name = name.substring(0, dotpos); name = name.substring(0, dotpos);
} }
String suffix = (sMethod == BlackPointEstimationMethod.ROW_SAMPLING) ? "row" : "2d"; String suffix = (sMethod == BlackPointEstimationMethod.ROW_SAMPLING) ? "row" : "2d";
result = new File(name + "_converted_" + suffix + "." + FORMAT); result = new File(name + "_converted_" + suffix + '.' + FORMAT);
} }
return result; return result;
} }