From 96659a17aec334f4cf0df76914c229b079705acc Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 30 Dec 2008 15:31:25 +0000 Subject: [PATCH] Add more unit tests for client.result, and more small code tweaks. git-svn-id: http://zxing.googlecode.com/svn/trunk@809 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../client/android/AndroidHttpClient.java | 2 +- .../zxing/client/android/CaptureActivity.java | 6 +- .../google/zxing/client/android/Contents.java | 8 ++ .../google/zxing/client/android/Intents.java | 15 ++++ .../zxing/client/android/QRCodeEncoder.java | 63 +++++++------- .../android/SearchBookContentsActivity.java | 8 +- .../android/YUVMonochromeBitmapSource.java | 5 ++ .../result/AddressBookResultHandler.java | 4 +- .../client/android/result/ResultHandler.java | 8 +- .../android/result/ResultHandlerFactory.java | 3 + .../client/androidtest/BenchmarkActivity.java | 2 +- .../client/androidtest/BenchmarkItem.java | 4 +- .../client/androidtest/BenchmarkThread.java | 2 +- .../RGBMonochromeBitmapSource.java | 11 ++- .../zxing/client/androidtest/SaveThread.java | 2 +- .../zxing/client/result/GeoParsedResult.java | 18 ++-- .../zxing/client/result/GeoResultParser.java | 14 ++-- .../client/result/URLTOResultParser.java | 2 +- core/src/com/google/zxing/oned/ITFReader.java | 4 +- .../qrcode/decoder/FormatInformation.java | 2 +- .../AddressBookParsedResultTestCase.java | 82 +++++++++++++++++++ .../result/CalendarParsedResultTestCase.java | 56 +++++++++++++ .../EmailAddressParsedResultTestCase.java | 53 ++++++++++++ .../result/GeoParsedResultTestCase.java | 45 ++++++++++ .../result/ISBNParsedResultTestCase.java | 42 ++++++++++ .../result/ParsedReaderResultTestCase.java | 11 ++- .../result/ProductParsedResultTestCase.java | 46 +++++++++++ .../result/SMSMMSParsedResultTestCase.java | 54 ++++++++++++ .../result/TelParsedResultTestCase.java | 45 ++++++++++ .../result/URIParsedResultTestCase.java | 34 +++++++- .../common/AbstractBlackBoxTestCase.java | 4 +- .../ReedSolomonEncoderQRCodeTestCase.java | 4 +- .../zxing/qrcode/QRCodeWriterTestCase.java | 4 +- .../qrcode/decoder/DataMaskTestCase.java | 2 +- .../zxing/qrcode/decoder/VersionTestCase.java | 2 +- .../zxing/qrcode/encoder/EncoderTestCase.java | 14 ++-- .../zxing/client/j2se/ImageConverter.java | 2 +- 37 files changed, 591 insertions(+), 92 deletions(-) create mode 100644 core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java create mode 100644 core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java diff --git a/android/src/com/google/zxing/client/android/AndroidHttpClient.java b/android/src/com/google/zxing/client/android/AndroidHttpClient.java index b1368794..d53207cf 100644 --- a/android/src/com/google/zxing/client/android/AndroidHttpClient.java +++ b/android/src/com/google/zxing/client/android/AndroidHttpClient.java @@ -355,7 +355,7 @@ public final class AndroidHttpClient implements HttpClient { } if (level < Log.VERBOSE || level > Log.ASSERT) { throw new IllegalArgumentException("Level is out of range [" - + Log.VERBOSE + ".." + Log.ASSERT + "]"); + + Log.VERBOSE + ".." + Log.ASSERT + ']'); } curlConfiguration = new LoggingConfiguration(name, level); diff --git a/android/src/com/google/zxing/client/android/CaptureActivity.java b/android/src/com/google/zxing/client/android/CaptureActivity.java index 820213c7..6192f15f 100755 --- a/android/src/com/google/zxing/client/android/CaptureActivity.java +++ b/android/src/com/google/zxing/client/android/CaptureActivity.java @@ -320,7 +320,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal } if (mCopyToClipboard) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(displayContents); } } @@ -372,7 +372,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal mStatusView.setBackgroundColor(getResources().getColor(R.color.transparent)); if (mCopyToClipboard) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(resultHandler.getDisplayContents()); } @@ -436,7 +436,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal mMediaPlayer.start(); } if (mVibrate) { - Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } } diff --git a/android/src/com/google/zxing/client/android/Contents.java b/android/src/com/google/zxing/client/android/Contents.java index fa11b34e..04470aa8 100755 --- a/android/src/com/google/zxing/client/android/Contents.java +++ b/android/src/com/google/zxing/client/android/Contents.java @@ -20,6 +20,9 @@ import android.provider.Contacts; public final class Contents { + private Contents() { + } + /** * 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_128 = "CODE_128"; public static final String QR_CODE = "QR_CODE"; + private Format() { + } } public static final class Type { @@ -79,6 +84,9 @@ public final class Contents { * intent.putExtra(Intents.Encode.DATA, bundle); */ public static final String LOCATION = "LOCATION_TYPE"; + + private Type() { + } } // These are new constants in Contacts.Intents.Insert for Android 1.1. diff --git a/android/src/com/google/zxing/client/android/Intents.java b/android/src/com/google/zxing/client/android/Intents.java index 0d135429..39a86637 100755 --- a/android/src/com/google/zxing/client/android/Intents.java +++ b/android/src/com/google/zxing/client/android/Intents.java @@ -18,6 +18,9 @@ package com.google.zxing.client.android; public final class Intents { + private Intents() { + } + public static final class Scan { /** * 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. */ public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; + + private Scan() { + } } public static final class Encode { @@ -87,6 +93,9 @@ public final class Intents { * Contents.Type. */ public static final String TYPE = "ENCODE_TYPE"; + + private Encode() { + } } public static final class SearchBookContents { @@ -107,6 +116,9 @@ public final class Intents { * An optional field which is the text to search for. */ public static final String QUERY = "QUERY"; + + private SearchBookContents() { + } } public static final class Share { @@ -115,6 +127,9 @@ public final class Intents { * display onscreen for a friend to scan with their phone. */ public static final String ACTION = "com.google.zxing.client.android.SHARE"; + + private Share() { + } } } diff --git a/android/src/com/google/zxing/client/android/QRCodeEncoder.java b/android/src/com/google/zxing/client/android/QRCodeEncoder.java index 3ba3f1dc..49420436 100755 --- a/android/src/com/google/zxing/client/android/QRCodeEncoder.java +++ b/android/src/com/google/zxing/client/android/QRCodeEncoder.java @@ -32,8 +32,6 @@ import com.google.zxing.common.ByteMatrix; public final class QRCodeEncoder { - private static final String TAG = "QRCodeEncoder"; - private final Activity mActivity; private String mContents; private String mDisplayContents; @@ -74,31 +72,31 @@ public final class QRCodeEncoder { } if (type.equals(Contents.Type.TEXT)) { - String string = intent.getStringExtra(Intents.Encode.DATA); - if (string != null && string.length() > 0) { - mContents = string; - mDisplayContents = string; + String data = intent.getStringExtra(Intents.Encode.DATA); + if (data != null && data.length() > 0) { + mContents = data; + mDisplayContents = data; mTitle = mActivity.getString(R.string.contents_text); } } else if (type.equals(Contents.Type.EMAIL)) { - String string = intent.getStringExtra(Intents.Encode.DATA); - if (string != null && string.length() > 0) { - mContents = "mailto:" + string; - mDisplayContents = string; + String data = intent.getStringExtra(Intents.Encode.DATA); + if (data != null && data.length() > 0) { + mContents = "mailto:" + data; + mDisplayContents = data; mTitle = mActivity.getString(R.string.contents_email); } } else if (type.equals(Contents.Type.PHONE)) { - String string = intent.getStringExtra(Intents.Encode.DATA); - if (string != null && string.length() > 0) { - mContents = "tel:" + string; - mDisplayContents = PhoneNumberUtils.formatNumber(string); + String data = intent.getStringExtra(Intents.Encode.DATA); + if (data != null && data.length() > 0) { + mContents = "tel:" + data; + mDisplayContents = PhoneNumberUtils.formatNumber(data); mTitle = mActivity.getString(R.string.contents_phone); } } else if (type.equals(Contents.Type.SMS)) { - String string = intent.getStringExtra(Intents.Encode.DATA); - if (string != null && string.length() > 0) { - mContents = "sms:" + string; - mDisplayContents = PhoneNumberUtils.formatNumber(string); + String data = intent.getStringExtra(Intents.Encode.DATA); + if (data != null && data.length() > 0) { + mContents = "sms:" + data; + mDisplayContents = PhoneNumberUtils.formatNumber(data); mTitle = mActivity.getString(R.string.contents_sms); } } else if (type.equals(Contents.Type.CONTACT)) { @@ -106,25 +104,25 @@ public final class QRCodeEncoder { if (bundle != null) { String name = bundle.getString(Contacts.Intents.Insert.NAME); if (name != null && name.length() > 0) { - mContents = "MECARD:N:" + name + ";"; + mContents = "MECARD:N:" + name + ';'; mDisplayContents = name; String address = bundle.getString(Contacts.Intents.Insert.POSTAL); if (address != null && address.length() > 0) { - mContents += "ADR:" + address + ";"; - mDisplayContents += "\n" + address; + mContents += "ADR:" + address + ';'; + mDisplayContents += '\n' + address; } for (int x = 0; x < Contents.PHONE_KEYS.length; x++) { String phone = bundle.getString(Contents.PHONE_KEYS[x]); if (phone != null && phone.length() > 0) { - mContents += "TEL:" + phone + ";"; - mDisplayContents += "\n" + PhoneNumberUtils.formatNumber(phone); + mContents += "TEL:" + phone + ';'; + mDisplayContents += '\n' + PhoneNumberUtils.formatNumber(phone); } } for (int x = 0; x < Contents.EMAIL_KEYS.length; x++) { String email = bundle.getString(Contents.EMAIL_KEYS[x]); if (email != null && email.length() > 0) { - mContents += "EMAIL:" + email + ";"; - mDisplayContents += "\n" + email; + mContents += "EMAIL:" + email + ';'; + mDisplayContents += '\n' + email; } } mContents += ";"; @@ -134,10 +132,10 @@ public final class QRCodeEncoder { } else if (type.equals(Contents.Type.LOCATION)) { Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA); if (bundle != null) { - float latitude = bundle.getFloat("LAT", Float.MAX_VALUE); - float longitude = bundle.getFloat("LONG", Float.MAX_VALUE); - if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) { - mContents = "geo:" + latitude + "," + longitude; + double latitude = bundle.getDouble("LAT", Double.NaN); + double longitude = bundle.getDouble("LONG", Double.NaN); + if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) { + mContents = "geo:" + latitude + ',' + longitude; mDisplayContents = latitude + "," + longitude; 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 String TAG = "EncodeThread"; + private final String mContents; private final Handler mHandler; private final int mPixelResolution; - public EncodeThread(String contents, Handler handler, int pixelResolution) { + EncodeThread(String contents, Handler handler, int pixelResolution) { mContents = contents; mHandler = handler; mPixelResolution = pixelResolution; @@ -169,7 +169,8 @@ public final class QRCodeEncoder { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { 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); } } diff --git a/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java b/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java index 1da0c1db..8d68910e 100644 --- a/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java +++ b/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java @@ -198,7 +198,7 @@ public final class SearchBookContentsActivity extends Activity { try { String pageNumber = json.getString("page_number"); if (pageNumber.length() > 0) { - pageNumber = getString(R.string.msg_sbc_page) + " " + pageNumber; + pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber; } else { // This can happen for text on the jacket, and possibly other reasons. pageNumber = getString(R.string.msg_sbc_unknown_page); @@ -214,7 +214,7 @@ public final class SearchBookContentsActivity extends Activity { snippet = snippet.replaceAll("'", "'"); snippet = snippet.replaceAll(""", "\""); } else { - snippet = "(" + getString(R.string.msg_sbc_snippet_unavailable) + ")"; + snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')'; valid = false; } return new SearchBookContentsResult(pageNumber, snippet, valid); @@ -231,7 +231,7 @@ public final class SearchBookContentsActivity extends Activity { private final Handler mHandler; 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; mQuery = query; mHandler = handler; @@ -305,7 +305,7 @@ public final class SearchBookContentsActivity extends Activity { 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. // Once Jeff fixes the HTTP response, remove this hardcoded value and go back to getting // the encoding dynamically. diff --git a/android/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java b/android/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java index 86d39545..cda9929d 100755 --- a/android/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java +++ b/android/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java @@ -47,10 +47,12 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource { assert (crop.height() <= dataHeight); } + @Override public int getHeight() { return mCrop.height(); } + @Override public int getWidth() { return mCrop.width(); } @@ -63,10 +65,12 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource { * @param y The y coordinate to fetch within crop * @return The luminance as an int, from 0-255 */ + @Override protected int getLuminance(int x, int y) { return mYUVData[(y + mCrop.top) * mDataWidth + x + mCrop.left] & 0xff; } + @Override protected int[] getLuminanceRow(int y, int[] row) { int width = getWidth(); if (row == null || row.length < width) { @@ -79,6 +83,7 @@ final class YUVMonochromeBitmapSource extends BaseMonochromeBitmapSource { return row; } + @Override protected int[] getLuminanceColumn(int x, int[] column) { int height = getHeight(); if (column == null || column.length < height) { diff --git a/android/src/com/google/zxing/client/android/result/AddressBookResultHandler.java b/android/src/com/google/zxing/client/android/result/AddressBookResultHandler.java index a91e6355..37a96f62 100644 --- a/android/src/com/google/zxing/client/android/result/AddressBookResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/AddressBookResultHandler.java @@ -35,7 +35,7 @@ public final class AddressBookResultHandler extends ResultHandler { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd"); 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 // 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) { contents.append("\n("); contents.append(pronunciation); - contents.append(")"); + contents.append(')'); } ParsedResult.maybeAppend(result.getTitle(), contents); diff --git a/android/src/com/google/zxing/client/android/result/ResultHandler.java b/android/src/com/google/zxing/client/android/result/ResultHandler.java index ffbdf81f..af0ab9c4 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandler.java @@ -45,7 +45,7 @@ public abstract class ResultHandler { protected final ParsedResult mResult; private final Activity mActivity; - public ResultHandler(Activity activity, ParsedResult result) { + protected ResultHandler(Activity activity, ParsedResult result) { mResult = result; mActivity = activity; } @@ -119,7 +119,7 @@ public abstract class ResultHandler { launchIntent(intent); } - private long calculateMilliseconds(String when) { + private static long calculateMilliseconds(String when) { if (when.length() == 8) { // Only contains year/month/day Date date; @@ -237,14 +237,14 @@ public abstract class ResultHandler { public final void searchMap(String address, String title) { String query = address; 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)))); } public final void getDirections(float latitude, float longitude) { 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) { diff --git a/android/src/com/google/zxing/client/android/result/ResultHandlerFactory.java b/android/src/com/google/zxing/client/android/result/ResultHandlerFactory.java index 4d501b0e..3a2277cb 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandlerFactory.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandlerFactory.java @@ -24,6 +24,9 @@ import com.google.zxing.client.result.ResultParser; public final class ResultHandlerFactory { + private ResultHandlerFactory() { + } + public static ResultHandler makeResultHandler(Activity activity, Result rawResult) { ParsedResult result = parseResult(rawResult); ParsedResultType type = result.getType(); diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java index 60145727..f2daa33a 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java @@ -76,7 +76,7 @@ public final class BenchmarkActivity extends Activity { } }; - private void handleBenchmarkDone(Message message) { + private static void handleBenchmarkDone(Message message) { List items = (List) message.obj; int count = 0; for (int x = 0; x < items.size(); x++) { diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java index 1827e704..4cb418c4 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkItem.java @@ -21,7 +21,7 @@ import com.google.zxing.BarcodeFormat; public final class BenchmarkItem { private final String mPath; - private int[] mTimes; + private final int[] mTimes; private int mPosition; private boolean mDecoded; private BarcodeFormat mFormat; @@ -50,7 +50,7 @@ public final class BenchmarkItem { @Override public String toString() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: "); result.append(mPath); result.append(" ("); diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkThread.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkThread.java index 560e5c85..26d2cc21 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkThread.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkThread.java @@ -64,7 +64,7 @@ final class BenchmarkThread extends Thread { String[] files = file.list(); Arrays.sort(files); for (int x = 0; x < files.length; x++) { - walkTree(file.getAbsolutePath() + "/" + files[x], items); + walkTree(file.getAbsolutePath() + '/' + files[x], items); } } else { BenchmarkItem item = decode(path); diff --git a/androidtest/src/com/google/zxing/client/androidtest/RGBMonochromeBitmapSource.java b/androidtest/src/com/google/zxing/client/androidtest/RGBMonochromeBitmapSource.java index d877f90e..5db6ab93 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/RGBMonochromeBitmapSource.java +++ b/androidtest/src/com/google/zxing/client/androidtest/RGBMonochromeBitmapSource.java @@ -24,9 +24,9 @@ import java.io.FileNotFoundException; public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource { - private int mWidth; - private int mHeight; - private byte[] mLuminances; + private final int mWidth; + private final int mHeight; + private final byte[] mLuminances; public RGBMonochromeBitmapSource(String path) throws FileNotFoundException { Bitmap bitmap = BitmapFactory.decodeFile(path); @@ -62,18 +62,22 @@ public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource } } + @Override public int getHeight() { return mHeight; } + @Override public int getWidth() { return mWidth; } + @Override protected int getLuminance(int x, int y) { return mLuminances[y * mWidth + x] & 0xff; } + @Override protected int[] getLuminanceRow(int y, int[] row) { int width = mWidth; if (row == null || row.length < width) { @@ -86,6 +90,7 @@ public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource return row; } + @Override protected int[] getLuminanceColumn(int x, int[] column) { int width = mWidth; int height = mHeight; diff --git a/androidtest/src/com/google/zxing/client/androidtest/SaveThread.java b/androidtest/src/com/google/zxing/client/androidtest/SaveThread.java index b04af514..16928589 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/SaveThread.java +++ b/androidtest/src/com/google/zxing/client/androidtest/SaveThread.java @@ -102,7 +102,7 @@ final class SaveThread extends Thread { message.sendToTarget(); } - private OutputStream getNewPhotoOutputStream() { + private static OutputStream getNewPhotoOutputStream() { File sdcard = new File("/sdcard"); if (sdcard.exists()) { File barcodes = new File(sdcard, "barcodes"); diff --git a/core/src/com/google/zxing/client/result/GeoParsedResult.java b/core/src/com/google/zxing/client/result/GeoParsedResult.java index 6adf0fb7..aabebcd6 100644 --- a/core/src/com/google/zxing/client/result/GeoParsedResult.java +++ b/core/src/com/google/zxing/client/result/GeoParsedResult.java @@ -22,11 +22,11 @@ package com.google.zxing.client.result; public final class GeoParsedResult extends ParsedResult { private final String geoURI; - private final float latitude; - private final float longitude; - private final float altitude; + private final double latitude; + private final double longitude; + 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); this.geoURI = geoURI; this.latitude = latitude; @@ -41,21 +41,21 @@ public final class GeoParsedResult extends ParsedResult { /** * @return latitude in degrees */ - public float getLatitude() { + public double getLatitude() { return latitude; } /** * @return longitude in degrees */ - public float getLongitude() { + public double getLongitude() { return longitude; } /** * @return altitude in meters. If not specified, in the geo URI, returns 0.0 */ - public float getAltitude() { + public double getAltitude() { return altitude; } @@ -87,8 +87,8 @@ public final class GeoParsedResult extends ParsedResult { if (altitude > 0.0f) { // 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. - float altitudeInFeet = altitude * 3.28f; - int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f); + double altitudeInFeet = altitude * 3.28; + int altitudeInKFeet = (int) (altitudeInFeet / 1000.0); // 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 int logBaseTwo = 0; diff --git a/core/src/com/google/zxing/client/result/GeoResultParser.java b/core/src/com/google/zxing/client/result/GeoResultParser.java index b1d36e7d..b404188b 100644 --- a/core/src/com/google/zxing/client/result/GeoResultParser.java +++ b/core/src/com/google/zxing/client/result/GeoResultParser.java @@ -48,16 +48,16 @@ final class GeoResultParser extends ResultParser { if (latitudeEnd < 0) { return null; } - float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd)); + double latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd)); int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1); - float longitude; - float altitude; // in meters + double longitude; + double altitude; // in meters if (longitudeEnd < 0) { - longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1)); - altitude = 0.0f; + longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1)); + altitude = 0.0; } else { - longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd)); - altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1)); + longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd)); + altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1)); } return new GeoParsedResult(rawText, latitude, longitude, altitude); } diff --git a/core/src/com/google/zxing/client/result/URLTOResultParser.java b/core/src/com/google/zxing/client/result/URLTOResultParser.java index c65a4f9a..0ccd638d 100644 --- a/core/src/com/google/zxing/client/result/URLTOResultParser.java +++ b/core/src/com/google/zxing/client/result/URLTOResultParser.java @@ -39,7 +39,7 @@ final class URLTOResultParser { if (titleEnd < 0) { return null; } - String title = rawText.substring(6, titleEnd); + String title = titleEnd <= 6 ? null : rawText.substring(6, titleEnd); String uri = rawText.substring(titleEnd + 1); return new URIParsedResult(uri, title); } diff --git a/core/src/com/google/zxing/oned/ITFReader.java b/core/src/com/google/zxing/oned/ITFReader.java index d7db263f..8895f602 100644 --- a/core/src/com/google/zxing/oned/ITFReader.java +++ b/core/src/com/google/zxing/oned/ITFReader.java @@ -199,7 +199,7 @@ public final class ITFReader extends AbstractOneDReader { * @return index of the first black line. * @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 endStart = 0; while (endStart < width) { @@ -266,7 +266,7 @@ public final class ITFReader extends AbstractOneDReader { * ints * @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 // a single method. diff --git a/core/src/com/google/zxing/qrcode/decoder/FormatInformation.java b/core/src/com/google/zxing/qrcode/decoder/FormatInformation.java index f9cbefec..34a73560 100644 --- a/core/src/com/google/zxing/qrcode/decoder/FormatInformation.java +++ b/core/src/com/google/zxing/qrcode/decoder/FormatInformation.java @@ -112,7 +112,7 @@ final class FormatInformation { return doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR); } - private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) throws ReaderException { + private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) { // Unmask: int unmaskedFormatInfo = rawFormatInfo ^ FORMAT_INFO_MASK_QR; // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing diff --git a/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java new file mode 100644 index 00000000..870654b7 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java new file mode 100644 index 00000000..4054ab08 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java new file mode 100644 index 00000000..dfb37c45 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java new file mode 100644 index 00000000..d40e0f50 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java new file mode 100644 index 00000000..63763404 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java b/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java index 4133aa92..eef5816d 100644 --- a/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java @@ -104,12 +104,21 @@ public final class ParsedReaderResultTestCase extends TestCase { 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("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A); doTestResult("12345678901", "12345678901", ParsedResultType.TEXT); } + public void testUPCE() { + doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E); + } + public void testEAN() { doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8); doTestResult("00393158", "00393158", ParsedResultType.TEXT); diff --git a/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java new file mode 100644 index 00000000..07f85417 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java new file mode 100644 index 00000000..9af3ec50 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java @@ -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()); + } + +} diff --git a/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java new file mode 100644 index 00000000..3a219f11 --- /dev/null +++ b/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java @@ -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()); + } + +} \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java index 8376467c..1207fbd6 100644 --- a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java @@ -17,14 +17,35 @@ 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.URIParsedResult}. + * Tests {@link URIParsedResult}. * * @author Sean Owen */ 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() { doTestIsPossiblyMalicious("http://google.com", false); doTestIsPossiblyMalicious("http://google.com@evil.com", true); @@ -34,7 +55,16 @@ public final class URIParsedResultTestCase extends TestCase { 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); assertEquals(expected, result.isPossiblyMaliciousURI()); } diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index 9e3ccde9..8707b828 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -192,14 +192,14 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { if (!expectedFormat.equals(result.getBarcodeFormat())) { System.out.println("Format mismatch: expected '" + expectedFormat + "' but got '" + - result.getBarcodeFormat() + "'" + suffix); + result.getBarcodeFormat() + '\'' + suffix); return false; } String resultText = result.getText(); if (!expectedText.equals(resultText)) { System.out.println("Mismatch: expected '" + expectedText + "' but got '" + resultText + - "'" + suffix); + '\'' + suffix); return false; } return true; diff --git a/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonEncoderQRCodeTestCase.java b/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonEncoderQRCodeTestCase.java index 1d66b69a..ba22b60f 100644 --- a/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonEncoderQRCodeTestCase.java +++ b/core/test/src/com/google/zxing/common/reedsolomon/ReedSolomonEncoderQRCodeTestCase.java @@ -27,10 +27,10 @@ public final class ReedSolomonEncoderQRCodeTestCase extends AbstractReedSolomonT * Tests example given in ISO 18004, Annex I */ public void testISO18004Example() { - int[] dataBytes = new int[] { + int[] dataBytes = { 0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 }; - int[] expectedECBytes = new int[] { + int[] expectedECBytes = { 0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87, 0x2C, 0x55 }; doTestQRCodeEncoding(dataBytes, expectedECBytes); diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeWriterTestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeWriterTestCase.java index 7ca97d3d..c50b7da3 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeWriterTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeWriterTestCase.java @@ -105,7 +105,7 @@ public final class QRCodeWriterTestCase extends TestCase { assertNotNull(goldenResult); QRCodeWriter writer = new QRCodeWriter(); - Hashtable hints = new Hashtable(); + Hashtable hints = new Hashtable(); hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel); ByteMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution, 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 // and cell phones. We expect pixel-perfect results, because the error correction level is known, // 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, "renderer-test-01.png"); diff --git a/core/test/src/com/google/zxing/qrcode/decoder/DataMaskTestCase.java b/core/test/src/com/google/zxing/qrcode/decoder/DataMaskTestCase.java index c7df2c2c..41a8ddaf 100644 --- a/core/test/src/com/google/zxing/qrcode/decoder/DataMaskTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/decoder/DataMaskTestCase.java @@ -110,7 +110,7 @@ public final class DataMaskTestCase extends TestCase { } } - private static interface MaskCondition { + private interface MaskCondition { boolean isMasked(int i, int j); } diff --git a/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java b/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java index 33755be7..c92d872c 100644 --- a/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java @@ -57,7 +57,7 @@ public final class VersionTestCase extends TestCase { } } - public void testDecodeVersionInformation() throws ReaderException { + public void testDecodeVersionInformation() { // Spot check assertEquals(7, Version.decodeVersionInformation(0x07C94).getVersionNumber()); assertEquals(12, Version.decodeVersionInformation(0x0C762).getVersionNumber()); diff --git a/core/test/src/com/google/zxing/qrcode/encoder/EncoderTestCase.java b/core/test/src/com/google/zxing/qrcode/encoder/EncoderTestCase.java index ca3ac1f2..37c998d8 100644 --- a/core/test/src/com/google/zxing/qrcode/encoder/EncoderTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/encoder/EncoderTestCase.java @@ -125,7 +125,7 @@ public final class EncoderTestCase extends TestCase { assertEquals(expected, qrCode.toString()); } - public void testAppendModeInfo() throws WriterException { + public void testAppendModeInfo() { BitVector bits = new BitVector(); Encoder.appendModeInfo(Mode.NUMERIC, bits); assertEquals("0001", bits.toString()); @@ -444,9 +444,9 @@ public final class EncoderTestCase extends TestCase { // http://www.swetake.com/qr/qr9.html 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); - final int[] expected = { + int[] expected = { 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61 }; 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}; 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 }; assertEquals(expected.length, ecBytes.size()); @@ -468,9 +468,9 @@ public final class EncoderTestCase extends TestCase { } { // 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); - final int[] expected = { + int[] expected = { 0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213 }; assertEquals(expected.length, ecBytes.size()); diff --git a/javase/src/com/google/zxing/client/j2se/ImageConverter.java b/javase/src/com/google/zxing/client/j2se/ImageConverter.java index 3a839d5e..5b5a5a40 100644 --- a/javase/src/com/google/zxing/client/j2se/ImageConverter.java +++ b/javase/src/com/google/zxing/client/j2se/ImageConverter.java @@ -158,7 +158,7 @@ public final class ImageConverter { name = name.substring(0, dotpos); } String suffix = (sMethod == BlackPointEstimationMethod.ROW_SAMPLING) ? "row" : "2d"; - result = new File(name + "_converted_" + suffix + "." + FORMAT); + result = new File(name + "_converted_" + suffix + '.' + FORMAT); } return result; } -- 2.20.1