diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/ImageUtilsTest.java | 30 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java | 33 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/sensors/SensorsTest.java (renamed from tests/src/cgeo/geocaching/compatibility/CompatibilityTest.java) | 15 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/utils/MiscUtilsTest.java | 54 |
4 files changed, 109 insertions, 23 deletions
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)); + } + +} diff --git a/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java index 05b4ee1..7607ad0 100644 --- a/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java +++ b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java @@ -1,8 +1,11 @@ package cgeo.geocaching.files; -import com.jayway.android.robotium.solo.Solo; +import cgeo.geocaching.Intents; + +import com.robotium.solo.Solo; import android.annotation.TargetApi; +import android.content.Intent; import android.os.Build; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.Suppress; @@ -11,8 +14,7 @@ import android.widget.CheckBox; import java.util.ArrayList; @TargetApi(Build.VERSION_CODES.FROYO) -@Suppress() -/* This test breaks the continuous integration server, do not run it for now. */ +@Suppress public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<SimpleDirChooser> { private Solo solo; @@ -24,9 +26,14 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim @Override public void setUp() throws Exception { super.setUp(); + setActivityIntent(new Intent().putExtra(Intents.EXTRA_START_DIR, "").putExtra(SimpleDirChooser.EXTRA_CHOOSE_FOR_WRITING, false)); solo = new Solo(getInstrumentation(), getActivity()); } + public ArrayList<CheckBox> getCurrentCheckBoxes() { + return solo.getCurrentViews(CheckBox.class); + } + public void testSingleSelection() throws InterruptedException { // normally our activity should be ready, but we already had Jenkins report no checkboxes right here at the beginning solo.waitForActivity(solo.getCurrentActivity().getClass().getSimpleName(), 2000); @@ -37,11 +44,11 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim // according to the documentation, automatic pauses only happen in the clickXYZ() methods. // Therefore lets introduce a manual pause after the scrolling methods. - final int lastIndex = solo.getCurrentCheckBoxes().size() - 1; + final int lastIndex = getCurrentCheckBoxes().size() - 1; solo.clickOnCheckBox(lastIndex); - assertTrue(solo.getCurrentCheckBoxes().get(lastIndex).isChecked()); - assertFalse(solo.getCurrentCheckBoxes().get(0).isChecked()); + assertTrue(solo.isCheckBoxChecked(lastIndex)); + assertFalse(solo.isCheckBoxChecked(0)); assertChecked("Clicked last checkbox", 1); solo.scrollUp(); @@ -54,23 +61,23 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim pause(); solo.clickOnCheckBox(0); assertChecked("Clicked first checkbox", 1); - assertTrue(solo.getCurrentCheckBoxes().get(0).isChecked()); + assertTrue(solo.isCheckBoxChecked(0)); solo.clickOnCheckBox(1); assertChecked("Clicked second checkbox", 1); - assertTrue(solo.getCurrentCheckBoxes().get(1).isChecked()); + assertTrue(solo.isCheckBoxChecked(1)); } private static void pause() throws InterruptedException { - Thread.sleep(500); + Thread.sleep(100); } private void assertChecked(String message, int expectedChecked) { - int checked = 0; - final ArrayList<CheckBox> boxes = solo.getCurrentCheckBoxes(); + final ArrayList<CheckBox> boxes = getCurrentCheckBoxes(); assertNotNull("Could not get checkboxes", boxes); assertTrue("There are no checkboxes", boxes.size() > 1); - for (CheckBox checkBox : boxes) { - if (checkBox.isChecked()) { + int checked = 0; + for (int i = 0; i < boxes.size(); i++) { + if (solo.isCheckBoxChecked(i)) { checked++; } } diff --git a/tests/src/cgeo/geocaching/compatibility/CompatibilityTest.java b/tests/src/cgeo/geocaching/sensors/SensorsTest.java index 5857e46..87ff1de 100644 --- a/tests/src/cgeo/geocaching/compatibility/CompatibilityTest.java +++ b/tests/src/cgeo/geocaching/sensors/SensorsTest.java @@ -1,16 +1,16 @@ -package cgeo.geocaching.compatibility; +package cgeo.geocaching.sensors; import cgeo.geocaching.MainActivity; -import android.test.ActivityInstrumentationTestCase2; - import junit.framework.Assert; -public class CompatibilityTest extends ActivityInstrumentationTestCase2<MainActivity> { +import android.test.ActivityInstrumentationTestCase2; + +public class SensorsTest extends ActivityInstrumentationTestCase2<MainActivity> { private MainActivity activity; - public CompatibilityTest() { + public SensorsTest() { super(MainActivity.class); } @@ -20,11 +20,6 @@ public class CompatibilityTest extends ActivityInstrumentationTestCase2<MainActi activity = getActivity(); } - public static void testDataChanged() { - // This should not raise an exception in any Android version - Compatibility.dataChanged("cgeo.geocaching"); - } - public void testGetDirectionNow() { final float angle = DirectionProvider.getDirectionNow(1.0f); Assert.assertTrue(angle == 1.0f || angle == 91.0f || angle == 181.0f || angle == 271.0f); diff --git a/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java new file mode 100644 index 0000000..2ee99c4 --- /dev/null +++ b/tests/src/cgeo/geocaching/utils/MiscUtilsTest.java @@ -0,0 +1,54 @@ +package cgeo.geocaching.utils; + +import junit.framework.TestCase; + +import java.util.LinkedList; +import java.util.List; + +public class MiscUtilsTest extends TestCase { + + public static void testBufferEmpty() { + for (final List<String> s: MiscUtils.buffer(new LinkedList<String>(), 10)) { + fail("empty collection should not iterate"); + } + } + + public static void testMultiple() { + final List<Integer> list = new LinkedList<Integer>(); + for (int i = 0; i < 50; i++) { + list.add(i); + } + int count = 0; + for (final List<Integer> subList: MiscUtils.buffer(list, 10)) { + assertEquals("each sublist has the right size", 10, subList.size()); + assertEquals("sublist has the right content", count * 10, (int) subList.get(0)); + count++; + } + assertEquals("there are the right number of sublists", 5, count); + } + + public static void testNonMultiple() { + final List<Integer> list = new LinkedList<Integer>(); + for (int i = 0; i < 48; i++) { + list.add(i); + } + int count = 0; + for (final List<Integer> subList: MiscUtils.buffer(list, 10)) { + assertTrue("each sublist has no more than the allowed number of arguments", subList.size() <= 10); + count += subList.size(); + } + assertEquals("all the elements were seen", 48, count); + } + + public static void testArguments() { + try { + MiscUtils.buffer(new LinkedList<Integer>(), 0); + fail("an exception should be raised"); + } catch (final IllegalArgumentException e) { + // Ok + } catch (final Exception e) { + fail("bad exception raised: " + e); + } + } + +} |
