diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-04-10 07:58:32 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-04-10 09:00:35 +0200 |
| commit | 2a97bbd1ea9db1975364b6ee96e527b2c9c8bae7 (patch) | |
| tree | 1fd6ca8799721c220c1efa7aa2ce00aaefd2b3c5 /tests | |
| parent | 95a5e7e4884b93703ddd42cd02a23a626b482449 (diff) | |
| download | cgeo-2a97bbd1ea9db1975364b6ee96e527b2c9c8bae7.zip cgeo-2a97bbd1ea9db1975364b6ee96e527b2c9c8bae7.tar.gz cgeo-2a97bbd1ea9db1975364b6ee96e527b2c9c8bae7.tar.bz2 | |
Use the Android-provided API to stream-decode base64-encoded data
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/res/raw/small_file.bin | bin | 0 -> 409 bytes | |||
| -rw-r--r-- | tests/src/cgeo/geocaching/ImageUtilsTest.java | 30 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/res/raw/small_file.bin b/tests/res/raw/small_file.bin Binary files differnew file mode 100644 index 0000000..df5b053 --- /dev/null +++ b/tests/res/raw/small_file.bin diff --git a/tests/src/cgeo/geocaching/ImageUtilsTest.java b/tests/src/cgeo/geocaching/ImageUtilsTest.java new file mode 100644 index 0000000..c67d340 --- /dev/null +++ b/tests/src/cgeo/geocaching/ImageUtilsTest.java @@ -0,0 +1,30 @@ +package cgeo.geocaching; + +import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; +import cgeo.geocaching.test.R; +import cgeo.geocaching.utils.ImageUtils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +public class ImageUtilsTest extends AbstractResourceInstrumentationTestCase { + + private static final String icon64 = "iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAABGdBTUEAALGPC/xhBQAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAABAElEQVQY002NvUpDQRQG52yEILn+IAYCClaS4tqKtZ1dbHwNuaS00dYmQmrfwMZGRBAtrMQHSCMpTCMqaIx6k909e6wCme4bPhhhhuc8d8PxeC+ZPW33++9T72ZPvdFow1SvStX9We8sz2U6FlQPLUYqqkW30VgGsKJAbur1g5pzXYMosC5giEgy+6hAtUzpqLLq3O8q7M6bbZkqmpKllExUa9+q2gvhbJrKLrLsdkVkxwABShg9eN86nUzunXU6AD/O+2EMgdJ7fAiY92EtxjcAJ+02JyKNkNLmawj9xxiLlxAu/2JcWoQmwBxAFT4Hqq1rs687GADnx9DMnOsD/AMJ54Nj8e9zcgAAAABJRU5ErkJggg=="; + + public void testBase64decoding() throws IOException { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageUtils.decodeBase64ToStream(icon64, outputStream); + final byte[] decodedImage = outputStream.toByteArray(); + outputStream.close(); + assertEquals("decoded image has the right size", 409, decodedImage.length); + final InputStream originalStream = getResourceStream(R.raw.small_file); + final byte[] originalImage = new byte[409]; + assertEquals("original image has the right size (consistency check)", 409, originalStream.read(originalImage)); + originalStream.close(); + assertTrue("decoded base64 image is similar to original file data", + Arrays.equals(originalImage, decodedImage)); + } + +} |
