Merge branch 'readonly-p4-donut' into donut

This commit is contained in:
Andy Stadler 2009-04-29 17:18:41 -07:00 committed by The Android Open Source Project
commit 972d7e389a
2 changed files with 97 additions and 18 deletions

View File

@ -411,10 +411,6 @@ public class LocalStore extends Store {
/**
* Set the visible limit for all folders in a given store.
*
* NOTE: <b>Does Not</b> update cached values for any held Folder objects. This is
* intended only for use at startup time. To reset the value for any given folder, use
* {@link LocalFolder#setVisibleLimit(int)}.
*
* @param visibleLimit the value to write to all folders. -1 may also be used as a marker.
*/
public void resetVisibleLimits(int visibleLimit) {
@ -604,11 +600,26 @@ public class LocalStore extends Store {
@Override
public int getUnreadMessageCount() throws MessagingException {
open(OpenMode.READ_WRITE);
if (!isOpen()) {
// opening it will read all columns including mUnreadMessageCount
open(OpenMode.READ_WRITE);
} else {
// already open. refresh from db in case another instance wrote to it
Cursor cursor = null;
try {
cursor = mDb.rawQuery("SELECT unread_count FROM folders WHERE folders.name = ?",
new String[] { mName });
cursor.moveToFirst();
mUnreadMessageCount = cursor.getInt(0);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
return mUnreadMessageCount;
}
public void setUnreadMessageCount(int unreadMessageCount) throws MessagingException {
open(OpenMode.READ_WRITE);
mUnreadMessageCount = Math.max(0, unreadMessageCount);
@ -617,11 +628,27 @@ public class LocalStore extends Store {
}
public int getVisibleLimit() throws MessagingException {
open(OpenMode.READ_WRITE);
if (!isOpen()) {
// opening it will read all columns including mVisibleLimit
open(OpenMode.READ_WRITE);
} else {
// already open. refresh from db in case another instance wrote to it
Cursor cursor = null;
try {
cursor = mDb.rawQuery(
"SELECT visible_limit FROM folders WHERE folders.name = ?",
new String[] { mName });
cursor.moveToFirst();
mVisibleLimit = cursor.getInt(0);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
return mVisibleLimit;
}
public void setVisibleLimit(int visibleLimit) throws MessagingException {
open(OpenMode.READ_WRITE);
mVisibleLimit = visibleLimit;

View File

@ -65,6 +65,8 @@ public class LocalStoreUnitTests extends AndroidTestCase {
private static final int DATABASE_VERSION = 23;
private static final String FOLDER_NAME = "TEST";
/* These values are provided by setUp() */
private String mLocalStoreUri = null;
private LocalStore mStore = null;
@ -83,7 +85,7 @@ public class LocalStoreUnitTests extends AndroidTestCase {
mLocalStoreUri = "local://localhost/" + getContext().getDatabasePath(dbName);
mStore = (LocalStore) LocalStore.newInstance(mLocalStoreUri, getContext(), null);
mFolder = (LocalStore.LocalFolder) mStore.getFolder("TEST");
mFolder = (LocalStore.LocalFolder) mStore.getFolder(FOLDER_NAME);
// This is needed for parsing mime messages
mCacheDir = getContext().getCacheDir();
@ -632,6 +634,47 @@ public class LocalStoreUnitTests extends AndroidTestCase {
assertEquals(failMessage, expectedUids, actualUids);
}
/**
* Test unread messages count
*/
public void testUnreadMessages() throws MessagingException {
mFolder.open(OpenMode.READ_WRITE, null);
// set up a 2nd folder to confirm independent storage
LocalStore.LocalFolder folder2 = (LocalStore.LocalFolder) mStore.getFolder("FOLDER-2");
assertFalse(folder2.exists());
folder2.create(FolderType.HOLDS_MESSAGES);
folder2.open(OpenMode.READ_WRITE, null);
// read and write, look for independent storage
mFolder.setUnreadMessageCount(400);
folder2.setUnreadMessageCount(425);
mFolder.close(false);
folder2.close(false);
mFolder.open(OpenMode.READ_WRITE, null);
folder2.open(OpenMode.READ_WRITE, null);
assertEquals(400, mFolder.getUnreadMessageCount());
assertEquals(425, folder2.getUnreadMessageCount());
}
/**
* Test unread messages count - concurrent access via two folder objects
*/
public void testUnreadMessagesConcurrent() throws MessagingException {
mFolder.open(OpenMode.READ_WRITE, null);
// set up a 2nd folder to confirm concurrent access
LocalStore.LocalFolder folder2 = (LocalStore.LocalFolder) mStore.getFolder(FOLDER_NAME);
assertTrue(folder2.exists());
folder2.open(OpenMode.READ_WRITE, null);
// read and write, look for concurrent storage
mFolder.setUnreadMessageCount(450);
assertEquals(450, folder2.getUnreadMessageCount());
}
/**
* Test visible limits support
*/
@ -657,6 +700,22 @@ public class LocalStoreUnitTests extends AndroidTestCase {
assertEquals(200, folder2.getVisibleLimit());
}
/**
* Test visible limits support - concurrent access via two folder objects
*/
public void testVisibleLimitsConcurrent() throws MessagingException {
mFolder.open(OpenMode.READ_WRITE, null);
// set up a 2nd folder to confirm concurrent access
LocalStore.LocalFolder folder2 = (LocalStore.LocalFolder) mStore.getFolder(FOLDER_NAME);
assertTrue(folder2.exists());
folder2.open(OpenMode.READ_WRITE, null);
// read and write, look for concurrent storage
mFolder.setVisibleLimit(300);
assertEquals(300, folder2.getVisibleLimit());
}
/**
* Test reset limits support
*/
@ -679,18 +738,11 @@ public class LocalStoreUnitTests extends AndroidTestCase {
folder2.open(OpenMode.READ_WRITE, null);
mStore.resetVisibleLimits(Email.VISIBLE_LIMIT_DEFAULT);
// NOTE: The open folders do not change, because resetVisibleLimits() resets the
// database only.
assertEquals(100, mFolder.getVisibleLimit());
assertEquals(200, folder2.getVisibleLimit());
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, mFolder.getVisibleLimit());
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, folder2.getVisibleLimit());
mFolder.close(false);
folder2.close(false);
mFolder.open(OpenMode.READ_WRITE, null);
folder2.open(OpenMode.READ_WRITE, null);
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, mFolder.getVisibleLimit());
assertEquals(Email.VISIBLE_LIMIT_DEFAULT, folder2.getVisibleLimit());
}
/**