|
| 1 | +package org.mozilla.mozstumbler.tests; |
| 2 | + |
| 3 | +import android.content.ContentValues; |
| 4 | +import android.content.SyncResult; |
| 5 | +import android.database.sqlite.SQLiteDatabase; |
| 6 | +import android.os.Handler; |
| 7 | +import android.os.Message; |
| 8 | +import android.test.ApplicationTestCase; |
| 9 | +import org.mozilla.mozstumbler.client.MainApp; |
| 10 | +import org.mozilla.mozstumbler.service.datahandling.Database; |
| 11 | +import org.mozilla.mozstumbler.service.datahandling.DatabaseContract; |
| 12 | + |
| 13 | +import java.util.concurrent.CountDownLatch; |
| 14 | + |
| 15 | +public class AppTest extends ApplicationTestCase<MainApp> { |
| 16 | + public AppTest() { |
| 17 | + super(MainApp.class); |
| 18 | + } |
| 19 | + |
| 20 | + SQLiteDatabase getStumblerDatabase() { |
| 21 | + String dbPath = Database.getFullPathToDb(this); |
| 22 | + assertTrue(dbPath != null); |
| 23 | + int endPos = dbPath.lastIndexOf('/'); |
| 24 | + dbPath = dbPath.substring(0, endPos) + "/" + Database.DATABASE_NAME; |
| 25 | + SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, 0); |
| 26 | + return db; |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + protected void setUp() throws Exception { |
| 31 | + createApplication(); |
| 32 | + MainApp app = getApplication(); |
| 33 | + } |
| 34 | + |
| 35 | + // for pausing to wait for asynctask |
| 36 | + final CountDownLatch signal = new CountDownLatch(1); |
| 37 | + |
| 38 | + public void testManyReportEntries() { |
| 39 | + // make sure every thing has time to load |
| 40 | + mHandler.sendMessageDelayed(mHandler.obtainMessage(), 250); |
| 41 | + |
| 42 | + try { |
| 43 | + signal.await(); |
| 44 | + } catch (Exception e) { |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + private Handler mHandler = new Handler() { |
| 49 | + public void handleMessage(Message m) { |
| 50 | + SQLiteDatabase db = getStumblerDatabase(); |
| 51 | + ContentValues values = new ContentValues(); |
| 52 | + values.put(DatabaseContract.Reports.TIME, 666); |
| 53 | + values.put(DatabaseContract.Reports.LAT, 0.0); |
| 54 | + values.put(DatabaseContract.Reports.LON, 0.0); |
| 55 | + values.put(DatabaseContract.Reports.ALTITUDE, 0); |
| 56 | + values.put(DatabaseContract.Reports.ACCURACY, 0); |
| 57 | + values.put(DatabaseContract.Reports.RADIO, "gsm"); |
| 58 | + values.put(DatabaseContract.Reports.CELL, "[{\"asu\":18,\"radio\":\"umts\",\"mnc\":720,\"psc\":426,\"cid\":2906773,\"mcc\":302,\"lac\":60013},{\"asu\":-81,\"radio\":\"umts\",\"mnc\":720,\"psc\":274,\"mcc\":302}]"); |
| 59 | + values.put(DatabaseContract.Reports.WIFI, "[{\"signal\":-76,\"key\":\"001e58eb0dcf\",\"frequency\":2437},{\"signal\":-86,\"key\":\"00223f026f0a\",\"frequency\":2437},{\"signal\":-55,\"key\":\"60a44cc82952\",\"frequency\":2417},{\"signal\":-88,\"key\":\"001e582594bf\",\"frequency\":2452},{\"signal\":-89,\"key\":\"0018f8f3d1c2\",\"frequency\":2437},{\"signal\":-83,\"key\":\"0023f89aebdf\",\"frequency\":2437},{\"signal\":-61,\"key\":\"00265ac972ef\",\"frequency\":2457}]"); |
| 60 | + values.put(DatabaseContract.Reports.CELL_COUNT, 2); |
| 61 | + values.put(DatabaseContract.Reports.WIFI_COUNT, 7); |
| 62 | + |
| 63 | + for (int i = 0; i < 10000; i++) { |
| 64 | + db.insert("reports", null, values); |
| 65 | + values.put(DatabaseContract.Reports.TIME, 666 + i); |
| 66 | + } |
| 67 | + |
| 68 | + signal.countDown(); |
| 69 | + } |
| 70 | + }; |
| 71 | +} |
0 commit comments