2009-07-06 17:49:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email.provider;
|
|
|
|
|
|
|
|
import com.android.email.provider.EmailContent.Account;
|
2009-07-16 23:03:40 +00:00
|
|
|
import com.android.email.provider.EmailContent.Attachment;
|
2009-07-06 17:49:38 +00:00
|
|
|
import com.android.email.provider.EmailContent.Mailbox;
|
|
|
|
import com.android.email.provider.EmailContent.Message;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import junit.framework.Assert;
|
|
|
|
|
|
|
|
public class ProviderTestUtils extends Assert {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No constructor - statics only
|
|
|
|
*/
|
|
|
|
private ProviderTestUtils() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an account for test purposes
|
|
|
|
*/
|
|
|
|
public static Account setupAccount(String name, boolean saveIt, Context context) {
|
|
|
|
Account account = new Account();
|
|
|
|
|
|
|
|
account.mDisplayName = name;
|
|
|
|
account.mEmailAddress = name + "@android.com";
|
|
|
|
account.mSyncKey = "sync-key-" + name;
|
|
|
|
account.mSyncLookback = 1;
|
2009-07-22 22:13:30 +00:00
|
|
|
account.mSyncInterval = EmailContent.Account.CHECK_INTERVAL_NEVER;
|
2009-07-06 17:49:38 +00:00
|
|
|
account.mHostAuthKeyRecv = 2;
|
|
|
|
account.mHostAuthKeySend = 3;
|
|
|
|
account.mFlags = 4;
|
|
|
|
account.mIsDefault = true;
|
|
|
|
account.mCompatibilityUuid = "test-uid-" + name;
|
|
|
|
account.mSenderName = name;
|
|
|
|
account.mRingtoneUri = "content://ringtone-" + name;
|
2009-07-17 23:29:35 +00:00
|
|
|
account.mProtocolVersion = "2.5" + name;
|
2009-08-18 19:14:15 +00:00
|
|
|
account.mNewMessageCount = 5 + name.length();
|
2009-07-06 17:49:38 +00:00
|
|
|
|
|
|
|
if (saveIt) {
|
2009-07-22 22:13:30 +00:00
|
|
|
account.save(context);
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
|
|
|
return account;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a mailbox for test purposes
|
|
|
|
*/
|
|
|
|
public static Mailbox setupMailbox(String name, long accountId, boolean saveIt,
|
|
|
|
Context context) {
|
|
|
|
Mailbox box = new Mailbox();
|
|
|
|
|
|
|
|
box.mDisplayName = name;
|
|
|
|
box.mServerId = "serverid-" + name;
|
|
|
|
box.mParentServerId = "parent-serverid-" + name;
|
|
|
|
box.mAccountKey = accountId;
|
|
|
|
box.mType = Mailbox.TYPE_MAIL;
|
|
|
|
box.mDelimiter = 1;
|
|
|
|
box.mSyncKey = "sync-key-" + name;
|
|
|
|
box.mSyncLookback = 2;
|
2009-07-22 22:13:30 +00:00
|
|
|
box.mSyncInterval = EmailContent.Account.CHECK_INTERVAL_NEVER;
|
2009-07-06 17:49:38 +00:00
|
|
|
box.mSyncTime = 3;
|
2009-07-30 18:41:31 +00:00
|
|
|
// Should always be saved as zero
|
|
|
|
box.mUnreadCount = 0;
|
2009-07-06 17:49:38 +00:00
|
|
|
box.mFlagVisible = true;
|
|
|
|
box.mFlags = 5;
|
|
|
|
box.mVisibleLimit = 6;
|
|
|
|
|
|
|
|
if (saveIt) {
|
2009-07-22 22:13:30 +00:00
|
|
|
box.save(context);
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a message for test purposes
|
2009-07-30 18:41:31 +00:00
|
|
|
*
|
2009-07-06 17:49:38 +00:00
|
|
|
* TODO: body
|
|
|
|
* TODO: attachments
|
|
|
|
*/
|
|
|
|
public static Message setupMessage(String name, long accountId, long mailboxId,
|
|
|
|
boolean addBody, boolean saveIt, Context context) {
|
|
|
|
Message message = new Message();
|
|
|
|
|
|
|
|
message.mDisplayName = name;
|
|
|
|
message.mTimeStamp = 1;
|
|
|
|
message.mSubject = "subject " + name;
|
|
|
|
message.mFlagRead = true;
|
|
|
|
message.mFlagLoaded = Message.NOT_LOADED;
|
|
|
|
message.mFlagFavorite = true;
|
|
|
|
message.mFlagAttachment = true;
|
|
|
|
message.mFlags = 2;
|
|
|
|
|
|
|
|
message.mServerId = "serverid " + name;
|
|
|
|
message.mServerIntId = 0;
|
|
|
|
message.mClientId = "clientid " + name;
|
|
|
|
message.mMessageId = "messageid " + name;
|
|
|
|
|
|
|
|
message.mMailboxKey = mailboxId;
|
|
|
|
message.mAccountKey = accountId;
|
|
|
|
|
|
|
|
message.mFrom = "from " + name;
|
|
|
|
message.mTo = "to " + name;
|
|
|
|
message.mCc = "cc " + name;
|
|
|
|
message.mBcc = "bcc " + name;
|
|
|
|
message.mReplyTo = "replyto " + name;
|
|
|
|
|
|
|
|
if (addBody) {
|
|
|
|
message.mText = "body text " + name;
|
|
|
|
message.mHtml = "body html " + name;
|
2009-09-02 06:19:12 +00:00
|
|
|
message.mTextReply = "reply text " + name;
|
|
|
|
message.mHtmlReply = "reply html " + name;
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (saveIt) {
|
2009-07-22 22:13:30 +00:00
|
|
|
message.save(context);
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2009-07-16 23:03:40 +00:00
|
|
|
/**
|
|
|
|
* Create a test attachment. A few fields are specified by params, and all other fields
|
|
|
|
* are generated using pseudo-unique values.
|
2009-07-30 18:41:31 +00:00
|
|
|
*
|
2009-07-16 23:03:40 +00:00
|
|
|
* @param messageId the message to attach to
|
|
|
|
* @param fileName the "file" to indicate in the attachment
|
|
|
|
* @param length the "length" of the attachment
|
|
|
|
* @param saveIt if true, write the new attachment directly to the DB
|
|
|
|
* @param context use this context
|
|
|
|
*/
|
|
|
|
public static Attachment setupAttachment(long messageId, String fileName, long length,
|
|
|
|
boolean saveIt, Context context) {
|
|
|
|
Attachment att = new Attachment();
|
|
|
|
att.mSize = length;
|
|
|
|
att.mFileName = fileName;
|
|
|
|
att.mContentId = "contentId " + fileName;
|
|
|
|
att.mContentUri = "contentUri " + fileName;
|
|
|
|
att.mMessageKey = messageId;
|
|
|
|
att.mMimeType = "mimeType " + fileName;
|
|
|
|
att.mLocation = "location " + fileName;
|
|
|
|
att.mEncoding = "encoding " + fileName;
|
|
|
|
if (saveIt) {
|
2009-07-22 22:13:30 +00:00
|
|
|
att.save(context);
|
2009-07-16 23:03:40 +00:00
|
|
|
}
|
|
|
|
return att;
|
|
|
|
}
|
|
|
|
|
2009-07-30 18:41:31 +00:00
|
|
|
private static void assertEmailContentEqual(String caller, EmailContent expect,
|
2009-07-17 23:29:35 +00:00
|
|
|
EmailContent actual) {
|
|
|
|
if (expect == actual) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(caller + " mId", expect.mId, actual.mId);
|
|
|
|
assertEquals(caller + " mBaseUri", expect.mBaseUri, actual.mBaseUri);
|
|
|
|
}
|
|
|
|
|
2009-07-06 17:49:38 +00:00
|
|
|
/**
|
|
|
|
* Compare two accounts for equality
|
2009-07-30 18:41:31 +00:00
|
|
|
*
|
2009-07-06 17:49:38 +00:00
|
|
|
* TODO: check host auth?
|
|
|
|
*/
|
|
|
|
public static void assertAccountEqual(String caller, Account expect, Account actual) {
|
|
|
|
if (expect == actual) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-17 23:29:35 +00:00
|
|
|
assertEmailContentEqual(caller, expect, actual);
|
2009-07-06 17:49:38 +00:00
|
|
|
assertEquals(caller + " mDisplayName", expect.mDisplayName, actual.mDisplayName);
|
|
|
|
assertEquals(caller + " mEmailAddress", expect.mEmailAddress, actual.mEmailAddress);
|
|
|
|
assertEquals(caller + " mSyncKey", expect.mSyncKey, actual.mSyncKey);
|
|
|
|
|
|
|
|
assertEquals(caller + " mSyncLookback", expect.mSyncLookback, actual.mSyncLookback);
|
2009-07-22 22:13:30 +00:00
|
|
|
assertEquals(caller + " mSyncInterval", expect.mSyncInterval, actual.mSyncInterval);
|
2009-07-06 17:49:38 +00:00
|
|
|
assertEquals(caller + " mHostAuthKeyRecv", expect.mHostAuthKeyRecv,
|
|
|
|
actual.mHostAuthKeyRecv);
|
|
|
|
assertEquals(caller + " mHostAuthKeySend", expect.mHostAuthKeySend,
|
|
|
|
actual.mHostAuthKeySend);
|
|
|
|
assertEquals(caller + " mFlags", expect.mFlags, actual.mFlags);
|
|
|
|
assertEquals(caller + " mIsDefault", expect.mIsDefault, actual.mIsDefault);
|
|
|
|
assertEquals(caller + " mCompatibilityUuid", expect.mCompatibilityUuid,
|
|
|
|
actual.mCompatibilityUuid);
|
|
|
|
assertEquals(caller + " mSenderName", expect.mSenderName, actual.mSenderName);
|
|
|
|
assertEquals(caller + " mRingtoneUri", expect.mRingtoneUri, actual.mRingtoneUri);
|
2009-07-17 23:29:35 +00:00
|
|
|
assertEquals(caller + " mProtocolVersion", expect.mProtocolVersion,
|
|
|
|
actual.mProtocolVersion);
|
2009-08-18 19:14:15 +00:00
|
|
|
assertEquals(caller + " mNewMessageCount", expect.mNewMessageCount,
|
|
|
|
actual.mNewMessageCount);
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two mailboxes for equality
|
|
|
|
*/
|
|
|
|
public static void assertMailboxEqual(String caller, Mailbox expect, Mailbox actual) {
|
|
|
|
if (expect == actual) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-17 23:29:35 +00:00
|
|
|
assertEmailContentEqual(caller, expect, actual);
|
2009-07-06 17:49:38 +00:00
|
|
|
assertEquals(caller + " mDisplayName", expect.mDisplayName, actual.mDisplayName);
|
|
|
|
assertEquals(caller + " mServerId", expect.mServerId, actual.mServerId);
|
|
|
|
assertEquals(caller + " mParentServerId", expect.mParentServerId, actual.mParentServerId);
|
|
|
|
assertEquals(caller + " mAccountKey", expect.mAccountKey, actual.mAccountKey);
|
|
|
|
assertEquals(caller + " mType", expect.mType, actual.mType);
|
|
|
|
assertEquals(caller + " mDelimiter", expect.mDelimiter, actual.mDelimiter);
|
|
|
|
assertEquals(caller + " mSyncKey", expect.mSyncKey, actual.mSyncKey);
|
|
|
|
assertEquals(caller + " mSyncLookback", expect.mSyncLookback, actual.mSyncLookback);
|
2009-07-22 22:13:30 +00:00
|
|
|
assertEquals(caller + " mSyncInterval", expect.mSyncInterval, actual.mSyncInterval);
|
2009-07-06 17:49:38 +00:00
|
|
|
assertEquals(caller + " mSyncTime", expect.mSyncTime, actual.mSyncTime);
|
|
|
|
assertEquals(caller + " mUnreadCount", expect.mUnreadCount, actual.mUnreadCount);
|
|
|
|
assertEquals(caller + " mFlagVisible", expect.mFlagVisible, actual.mFlagVisible);
|
|
|
|
assertEquals(caller + " mFlags", expect.mFlags, actual.mFlags);
|
|
|
|
assertEquals(caller + " mVisibleLimit", expect.mVisibleLimit, actual.mVisibleLimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two messages for equality
|
2009-07-30 18:41:31 +00:00
|
|
|
*
|
2009-07-06 17:49:38 +00:00
|
|
|
* TODO: body?
|
|
|
|
* TODO: attachments?
|
|
|
|
*/
|
|
|
|
public static void assertMessageEqual(String caller, Message expect, Message actual) {
|
|
|
|
if (expect == actual) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-17 23:29:35 +00:00
|
|
|
assertEmailContentEqual(caller, expect, actual);
|
2009-07-06 17:49:38 +00:00
|
|
|
assertEquals(caller + " mDisplayName", expect.mDisplayName, actual.mDisplayName);
|
|
|
|
assertEquals(caller + " mTimeStamp", expect.mTimeStamp, actual.mTimeStamp);
|
|
|
|
assertEquals(caller + " mSubject", expect.mSubject, actual.mSubject);
|
|
|
|
assertEquals(caller + " mFlagRead = false", expect.mFlagRead, actual.mFlagRead);
|
|
|
|
assertEquals(caller + " mFlagLoaded", expect.mFlagLoaded, actual.mFlagLoaded);
|
|
|
|
assertEquals(caller + " mFlagFavorite", expect.mFlagFavorite, actual.mFlagFavorite);
|
|
|
|
assertEquals(caller + " mFlagAttachment", expect.mFlagAttachment, actual.mFlagAttachment);
|
|
|
|
assertEquals(caller + " mFlags", expect.mFlags, actual.mFlags);
|
|
|
|
|
|
|
|
assertEquals(caller + " mServerId", expect.mServerId, actual.mServerId);
|
|
|
|
assertEquals(caller + " mServerIntId", expect.mServerIntId, actual.mServerIntId);
|
|
|
|
assertEquals(caller + " mClientId", expect.mClientId, actual.mClientId);
|
|
|
|
assertEquals(caller + " mMessageId", expect.mMessageId, actual.mMessageId);
|
|
|
|
|
|
|
|
assertEquals(caller + " mMailboxKey", expect.mMailboxKey, actual.mMailboxKey);
|
|
|
|
assertEquals(caller + " mAccountKey", expect.mAccountKey, actual.mAccountKey);
|
|
|
|
|
|
|
|
assertEquals(caller + " mFrom", expect.mFrom, actual.mFrom);
|
|
|
|
assertEquals(caller + " mTo", expect.mTo, actual.mTo);
|
|
|
|
assertEquals(caller + " mCc", expect.mCc, actual.mCc);
|
|
|
|
assertEquals(caller + " mBcc", expect.mBcc, actual.mBcc);
|
|
|
|
assertEquals(caller + " mReplyTo", expect.mReplyTo, actual.mReplyTo);
|
|
|
|
|
|
|
|
assertEquals(caller + " mText", expect.mText, actual.mText);
|
|
|
|
assertEquals(caller + " mHtml", expect.mHtml, actual.mHtml);
|
2009-09-02 06:19:12 +00:00
|
|
|
assertEquals(caller + " mTextReply", expect.mTextReply, actual.mTextReply);
|
|
|
|
assertEquals(caller + " mHtmlReply", expect.mHtmlReply, actual.mHtmlReply);
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|
2009-07-16 23:03:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare to attachments for equality
|
2009-07-30 18:41:31 +00:00
|
|
|
*
|
2009-07-16 23:03:40 +00:00
|
|
|
* TODO: file / content URI mapping? Compare the actual files?
|
|
|
|
*/
|
|
|
|
public static void assertAttachmentEqual(String caller, Attachment expect, Attachment actual) {
|
|
|
|
if (expect == actual) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-17 23:29:35 +00:00
|
|
|
assertEmailContentEqual(caller, expect, actual);
|
2009-07-16 23:03:40 +00:00
|
|
|
assertEquals(caller + " mSize", expect.mSize, actual.mSize);
|
|
|
|
assertEquals(caller + " mFileName", expect.mFileName, actual.mFileName);
|
|
|
|
assertEquals(caller + " mContentId", expect.mContentId, actual.mContentId);
|
|
|
|
assertEquals(caller + " mContentUri", expect.mContentUri, actual.mContentUri);
|
|
|
|
assertEquals(caller + " mMessageKey", expect.mMessageKey, actual.mMessageKey);
|
|
|
|
assertEquals(caller + " mMimeType", expect.mMimeType, actual.mMimeType);
|
|
|
|
assertEquals(caller + " mLocation", expect.mLocation, actual.mLocation);
|
|
|
|
assertEquals(caller + " mEncoding", expect.mEncoding, actual.mEncoding);
|
|
|
|
}
|
2009-07-06 17:49:38 +00:00
|
|
|
}
|