diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-05-30 21:11:44 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-05-30 21:11:44 +0200 |
commit | 6407e680ddf503e9e1dad9ca94ad081febb1a4c7 (patch) | |
tree | 43f4438d1b0f31d89a964e2d978d51a87c08ad7d /src/instrumentationTest/de/test/antennapod | |
parent | 55224e516406dc50985f1f48fb9d86aad726bc98 (diff) | |
download | AntennaPod-6407e680ddf503e9e1dad9ca94ad081febb1a4c7.zip |
Added UI test classes
Diffstat (limited to 'src/instrumentationTest/de/test/antennapod')
-rw-r--r-- | src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java | 24 | ||||
-rw-r--r-- | src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java | 93 |
2 files changed, 117 insertions, 0 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java new file mode 100644 index 000000000..5dc119a88 --- /dev/null +++ b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java @@ -0,0 +1,24 @@ +package instrumentationTest.de.test.antennapod.ui; + +import android.test.ActivityInstrumentationTestCase2; +import com.robotium.solo.Solo; +import de.danoeh.antennapod.activity.MainActivity; + +/** + * User interface tests for MainActivity + */ +public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { + + private Solo solo; + + public MainActivityTest(Class<MainActivity> activityClass) { + super(activityClass); + } + + @Override + protected void setUp() throws Exception { + solo = new Solo(getInstrumentation(), getActivity()); + } + + +} diff --git a/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java b/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java new file mode 100644 index 000000000..9fd5c4d77 --- /dev/null +++ b/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java @@ -0,0 +1,93 @@ +package instrumentationTest.de.test.antennapod.ui; + +import android.content.Context; +import android.graphics.Bitmap; +import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.FeedImage; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.feed.FeedMedia; +import instrumentationTest.de.test.antennapod.util.service.download.HTTPBin; +import instrumentationTest.de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; +import junit.framework.Assert; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Utility methods for UI tests + */ +public class UITestUtils { + + private static final String DATA_FOLDER = "test/UITestUtils"; + + public static final int NUM_FEEDS = 10; + public static final int NUM_ITEMS_PER_FEED = 20; + + + private Context context; + private HTTPBin server; + private File destDir; + private File hostedFeedDir; + + public UITestUtils(Context context) { + this.context = context; + } + + + public void setup() throws IOException { + destDir = context.getExternalFilesDir(DATA_FOLDER); + destDir.mkdir(); + hostedFeedDir = new File(destDir, "hostedFeeds"); + hostedFeedDir.mkdir(); + Assert.assertTrue(destDir.exists()); + Assert.assertTrue(hostedFeedDir.exists()); + server.start(); + } + + public void tearDown() throws IOException { + FileUtils.deleteDirectory(destDir); + server.stop(); + } + + private String hostFeed(Feed feed) throws IOException { + File feedFile = new File(hostedFeedDir, feed.getTitle()); + FileOutputStream out = new FileOutputStream(feedFile); + RSS2Generator generator = new RSS2Generator(); + generator.writeFeed(feed, out, "UTF-8", 0); + out.close(); + int id = server.serveFile(feedFile); + Assert.assertTrue(id != -1); + return String.format("http://127.0.0.1/files/%d", id); + } + + private File newBitmapFile(String name) throws IOException { + File imgFile = new File(destDir, name); + Bitmap bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.ARGB_8888); + FileOutputStream out = new FileOutputStream(imgFile); + bitmap.compress(Bitmap.CompressFormat.PNG, 1, out); + out.close(); + return imgFile; + } + + public void addFeedData() throws IOException { + for (int i = 0; i < NUM_FEEDS; i++) { + FeedImage image = new FeedImage(0, "image " + i, newBitmapFile("image" + i).getAbsolutePath(), "http://example.com/feed" + i + "/image", true); + Feed feed = new Feed(0, new Date(), "Title " + i, "http://example.com/" + i, "Description of feed " + i, + "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, + "http://example.com/feed/src/" + i, false); + feed.setDownload_url(hostFeed(feed)); + + // create items + List<FeedItem> items = new ArrayList<FeedItem>(); + for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) { + FeedItem item = new FeedItem(0, "item" + j, "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), true, feed); + items.add(item); + } + } + } +} |