Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.db; |
michael@0 | 5 | |
michael@0 | 6 | import org.mozilla.gecko.background.sync.helpers.HistoryHelpers; |
michael@0 | 7 | import org.mozilla.gecko.sync.repositories.NullCursorException; |
michael@0 | 8 | import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataExtender; |
michael@0 | 9 | import org.mozilla.gecko.sync.repositories.android.ClientsDatabase; |
michael@0 | 10 | import org.mozilla.gecko.sync.repositories.domain.ClientRecord; |
michael@0 | 11 | import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; |
michael@0 | 12 | import org.mozilla.gecko.sync.setup.Constants; |
michael@0 | 13 | |
michael@0 | 14 | import android.database.Cursor; |
michael@0 | 15 | import android.test.AndroidTestCase; |
michael@0 | 16 | |
michael@0 | 17 | public class TestCachedSQLiteOpenHelper extends AndroidTestCase { |
michael@0 | 18 | |
michael@0 | 19 | protected ClientsDatabase clientsDB; |
michael@0 | 20 | protected AndroidBrowserHistoryDataExtender extender; |
michael@0 | 21 | |
michael@0 | 22 | public void setUp() { |
michael@0 | 23 | clientsDB = new ClientsDatabase(mContext); |
michael@0 | 24 | extender = new AndroidBrowserHistoryDataExtender(mContext); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | public void tearDown() { |
michael@0 | 28 | clientsDB.close(); |
michael@0 | 29 | extender.close(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | public void testUnclosedDatabasesDontInteract() throws NullCursorException { |
michael@0 | 33 | // clientsDB gracefully does its thing and closes. |
michael@0 | 34 | clientsDB.wipeClientsTable(); |
michael@0 | 35 | ClientRecord record = new ClientRecord(); |
michael@0 | 36 | String profileConst = Constants.DEFAULT_PROFILE; |
michael@0 | 37 | clientsDB.store(profileConst, record); |
michael@0 | 38 | clientsDB.close(); |
michael@0 | 39 | |
michael@0 | 40 | // extender does its thing but still hasn't closed. |
michael@0 | 41 | HistoryRecord h = HistoryHelpers.createHistory1(); |
michael@0 | 42 | extender.store(h.guid, h.visits); |
michael@0 | 43 | |
michael@0 | 44 | // Ensure items in the clientsDB are still accessible nonetheless. |
michael@0 | 45 | Cursor cur = null; |
michael@0 | 46 | try { |
michael@0 | 47 | cur = clientsDB.fetchAllClients(); |
michael@0 | 48 | assertTrue(cur.moveToFirst()); |
michael@0 | 49 | assertEquals(1, cur.getCount()); |
michael@0 | 50 | } finally { |
michael@0 | 51 | if (cur != null) { |
michael@0 | 52 | cur.close(); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | } |