summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorMartin Hibdon <mhibdon@google.com>2014-06-03 11:18:46 -0700
committerMartin Hibdon <mhibdon@google.com>2014-06-04 11:45:34 -0700
commitbb0141b49e7eff978fa445249dc888461ea581e3 (patch)
treea5596d5705d549c090bf1e3dc90ebf8428511c56 /tests/src
parent91107a2bf135a14168d7d54f4ff87835a30377c2 (diff)
downloadandroid_packages_apps_Exchange-bb0141b49e7eff978fa445249dc888461ea581e3.tar.gz
android_packages_apps_Exchange-bb0141b49e7eff978fa445249dc888461ea581e3.tar.bz2
android_packages_apps_Exchange-bb0141b49e7eff978fa445249dc888461ea581e3.zip
Delete obsolete code
ExchangeService was only being used for GalSearch. That code has been moved EasService. Other services, EasAccountService, EasOutboxService, and EasSyncService are no longer used and have been removed, along with a bunch of other unused helper classes. Change-Id: I25c7e53896125818cfd6d3e3bf630ff671f142d1
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/exchange/EasAccountServiceTests.java79
-rw-r--r--tests/src/com/android/exchange/EasOutboxServiceTests.java43
-rw-r--r--tests/src/com/android/exchange/EasSyncServiceTests.java131
-rw-r--r--tests/src/com/android/exchange/ExchangeServiceAccountTests.java123
-rw-r--r--tests/src/com/android/exchange/ExchangeServiceTest.java60
-rw-r--r--tests/src/com/android/exchange/RequestTests.java61
-rw-r--r--tests/src/com/android/exchange/adapter/AttachmentLoaderTests.java40
-rw-r--r--tests/src/com/android/exchange/adapter/EmailSyncAdapterTests.java305
-rw-r--r--tests/src/com/android/exchange/adapter/FolderSyncParserTests.java375
-rw-r--r--tests/src/com/android/exchange/adapter/ProvisionParserTests.java3
-rw-r--r--tests/src/com/android/exchange/adapter/SyncAdapterTestCase.java115
-rw-r--r--tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java6
12 files changed, 2 insertions, 1339 deletions
diff --git a/tests/src/com/android/exchange/EasAccountServiceTests.java b/tests/src/com/android/exchange/EasAccountServiceTests.java
deleted file mode 100644
index eafd0f99..00000000
--- a/tests/src/com/android/exchange/EasAccountServiceTests.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2011 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.exchange;
-
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.EasAccountServiceTests exchange
- */
-@SmallTest
-public class EasAccountServiceTests extends AndroidTestCase {
-
- Context mMockContext;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mMockContext = getContext();
- }
-
- public void testResetHeartbeats() {
- EasAccountService svc = new EasAccountService();
- // Test case in which the minimum and force heartbeats need to come up
- svc.mPingMaxHeartbeat = 1000;
- svc.mPingMinHeartbeat = 200;
- svc.mPingHeartbeat = 300;
- svc.mPingForceHeartbeat = 100;
- svc.mPingHeartbeatDropped = true;
- svc.resetHeartbeats(400);
- assertEquals(400, svc.mPingMinHeartbeat);
- assertEquals(1000, svc.mPingMaxHeartbeat);
- assertEquals(400, svc.mPingHeartbeat);
- assertEquals(400, svc.mPingForceHeartbeat);
- assertFalse(svc.mPingHeartbeatDropped);
-
- // Test case in which the force heartbeat needs to come up
- svc.mPingMaxHeartbeat = 1000;
- svc.mPingMinHeartbeat = 200;
- svc.mPingHeartbeat = 100;
- svc.mPingForceHeartbeat = 100;
- svc.mPingHeartbeatDropped = true;
- svc.resetHeartbeats(150);
- assertEquals(200, svc.mPingMinHeartbeat);
- assertEquals(1000, svc.mPingMaxHeartbeat);
- assertEquals(150, svc.mPingHeartbeat);
- assertEquals(150, svc.mPingForceHeartbeat);
- assertFalse(svc.mPingHeartbeatDropped);
-
- // Test case in which the maximum needs to come down
- svc.mPingMaxHeartbeat = 1000;
- svc.mPingMinHeartbeat = 200;
- svc.mPingHeartbeat = 800;
- svc.mPingForceHeartbeat = 100;
- svc.mPingHeartbeatDropped = true;
- svc.resetHeartbeats(600);
- assertEquals(200, svc.mPingMinHeartbeat);
- assertEquals(600, svc.mPingMaxHeartbeat);
- assertEquals(600, svc.mPingHeartbeat);
- assertEquals(100, svc.mPingForceHeartbeat);
- assertFalse(svc.mPingHeartbeatDropped);
- }
-}
diff --git a/tests/src/com/android/exchange/EasOutboxServiceTests.java b/tests/src/com/android/exchange/EasOutboxServiceTests.java
deleted file mode 100644
index 56c2147c..00000000
--- a/tests/src/com/android/exchange/EasOutboxServiceTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2010 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.exchange;
-
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.emailcommon.provider.Mailbox;
-import com.android.exchange.EasOutboxService.OriginalMessageInfo;
-import com.android.exchange.utility.ExchangeTestCase;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.EasOutboxServiceTests exchange
- */
-@MediumTest
-public class EasOutboxServiceTests extends ExchangeTestCase {
-
- public void testGenerateSmartSendCmd() {
- EasOutboxService svc = new EasOutboxService(mProviderContext, new Mailbox());
- // Test encoding of collection id; colon should be preserved
- OriginalMessageInfo info = new OriginalMessageInfo(0, "1339085683659694034", "Mail:^f");
- String cmd = svc.generateSmartSendCmd(true, info);
- assertEquals("SmartReply&ItemId=1339085683659694034&CollectionId=Mail:%5Ef", cmd);
- // Test encoding of item id
- info = new OriginalMessageInfo(0, "14:&3", "6");
- cmd = svc.generateSmartSendCmd(false, info);
- assertEquals("SmartForward&ItemId=14:%263&CollectionId=6", cmd);
- }
-}
diff --git a/tests/src/com/android/exchange/EasSyncServiceTests.java b/tests/src/com/android/exchange/EasSyncServiceTests.java
deleted file mode 100644
index 150b1f1b..00000000
--- a/tests/src/com/android/exchange/EasSyncServiceTests.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2009 Marc Blank
- * Licensed to 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.exchange;
-
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Base64;
-
-import com.android.emailcommon.provider.Account;
-
-import org.apache.http.Header;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpRequestBase;
-
-import java.io.IOException;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.EasSyncServiceTests exchange
- */
-@SmallTest
-public class EasSyncServiceTests extends AndroidTestCase {
- static private final String USER = "user";
- static private final String PASSWORD = "password";
- static private final String HOST = "xxx.host.zzz";
- static private final String ID = "id";
-
- Context mMockContext;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mMockContext = getContext();
- }
-
- public void testAddHeaders() {
- HttpRequestBase method = new HttpPost();
- EasSyncService svc = new EasSyncService();
- svc.mAuthString = "auth";
- svc.mProtocolVersion = "12.1";
- svc.mAccount = null;
- // With second argument false, there should be no header
- svc.setHeaders(method, false);
- Header[] headers = method.getHeaders("X-MS-PolicyKey");
- assertEquals(0, headers.length);
- // With second argument true, there should always be a header
- // The value will be "0" without an account
- method.removeHeaders("X-MS-PolicyKey");
- svc.setHeaders(method, true);
- headers = method.getHeaders("X-MS-PolicyKey");
- assertEquals(1, headers.length);
- assertEquals("0", headers[0].getValue());
- // With an account, but null security key, the header's value should be "0"
- Account account = new Account();
- account.mSecuritySyncKey = null;
- svc.mAccount = account;
- method.removeHeaders("X-MS-PolicyKey");
- svc.setHeaders(method, true);
- headers = method.getHeaders("X-MS-PolicyKey");
- assertEquals(1, headers.length);
- assertEquals("0", headers[0].getValue());
- // With an account and security key, the header's value should be the security key
- account.mSecuritySyncKey = "key";
- svc.mAccount = account;
- method.removeHeaders("X-MS-PolicyKey");
- svc.setHeaders(method, true);
- headers = method.getHeaders("X-MS-PolicyKey");
- assertEquals(1, headers.length);
- assertEquals("key", headers[0].getValue());
- }
-
- public void testGetProtocolVersionDouble() {
- assertEquals(Eas.SUPPORTED_PROTOCOL_EX2003_DOUBLE,
- Eas.getProtocolVersionDouble(Eas.SUPPORTED_PROTOCOL_EX2003));
- assertEquals(Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE,
- Eas.getProtocolVersionDouble(Eas.SUPPORTED_PROTOCOL_EX2007));
- assertEquals(Eas.SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE,
- Eas.getProtocolVersionDouble(Eas.SUPPORTED_PROTOCOL_EX2007_SP1));
- }
-
- private EasSyncService setupService(String user) {
- EasSyncService svc = new EasSyncService();
- svc.mUserName = user;
- svc.mPassword = PASSWORD;
- svc.mDeviceId = ID;
- svc.mHostAddress = HOST;
- return svc;
- }
-
- public void testMakeUriString() throws IOException {
- // Simple user name and command
- EasSyncService svc = setupService(USER);
- String uriString = svc.makeUriString("Sync", null);
- // These next two should now be cached
- assertNotNull(svc.mAuthString);
- assertNotNull(svc.mUserString);
- assertEquals("Basic " + Base64.encodeToString((USER+":"+PASSWORD).getBytes(),
- Base64.NO_WRAP), svc.mAuthString);
- assertEquals("&User=" + USER + "&DeviceId=" + ID + "&DeviceType=" +
- EasSyncService.DEVICE_TYPE, svc.mUserString);
- assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=Sync" +
- svc.mUserString, uriString);
- // User name that requires encoding
- String user = "name_with_underscore@foo%bar.com";
- svc = setupService(user);
- uriString = svc.makeUriString("Sync", null);
- assertEquals("Basic " + Base64.encodeToString((user+":"+PASSWORD).getBytes(),
- Base64.NO_WRAP), svc.mAuthString);
- String safeUserName = "name_with_underscore%40foo%25bar.com";
- assertEquals("&User=" + safeUserName + "&DeviceId=" + ID + "&DeviceType=" +
- EasSyncService.DEVICE_TYPE, svc.mUserString);
- assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=Sync" +
- svc.mUserString, uriString);
- }
-}
diff --git a/tests/src/com/android/exchange/ExchangeServiceAccountTests.java b/tests/src/com/android/exchange/ExchangeServiceAccountTests.java
deleted file mode 100644
index 4056968e..00000000
--- a/tests/src/com/android/exchange/ExchangeServiceAccountTests.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2009 Marc Blank
- * Licensed to 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.exchange;
-
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.Mailbox;
-import com.android.emailsync.AbstractSyncService;
-import com.android.emailsync.SyncManager.SyncError;
-import com.android.exchange.provider.EmailContentSetupUtils;
-import com.android.exchange.utility.ExchangeTestCase;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.ExchangeServiceAccountTests exchange
- */
-@MediumTest
-public class ExchangeServiceAccountTests extends ExchangeTestCase {
-
- public ExchangeServiceAccountTests() {
- super();
- }
-
- public void brokentestReleaseSyncHolds() {
- ExchangeService exchangeService = new ExchangeService();
- SyncError securityErrorAccount1 =
- exchangeService.new SyncError(AbstractSyncService.EXIT_SECURITY_FAILURE, false);
- SyncError ioError =
- exchangeService.new SyncError(AbstractSyncService.EXIT_IO_ERROR, false);
- SyncError securityErrorAccount2 =
- exchangeService.new SyncError(AbstractSyncService.EXIT_SECURITY_FAILURE, false);
- // Create account and two mailboxes
- Account acct1 = setupTestAccount("acct1", true);
- Mailbox box1 = EmailContentSetupUtils.setupMailbox("box1", acct1.mId, true,
- mProviderContext);
- Mailbox box2 = EmailContentSetupUtils.setupMailbox("box2", acct1.mId, true,
- mProviderContext);
- Account acct2 = setupTestAccount("acct2", true);
- Mailbox box3 = EmailContentSetupUtils.setupMailbox("box3", acct2.mId, true,
- mProviderContext);
- Mailbox box4 = EmailContentSetupUtils.setupMailbox("box4", acct2.mId, true,
- mProviderContext);
-
- ConcurrentHashMap<Long, SyncError> errorMap = exchangeService.mSyncErrorMap;
- // Add errors into the map
- errorMap.put(box1.mId, securityErrorAccount1);
- errorMap.put(box2.mId, ioError);
- errorMap.put(box3.mId, securityErrorAccount2);
- errorMap.put(box4.mId, securityErrorAccount2);
- // We should have 4
- assertEquals(4, errorMap.keySet().size());
- // Release the holds on acct2 (there are two of them)
- assertTrue(exchangeService.releaseSyncHolds(mProviderContext,
- AbstractSyncService.EXIT_SECURITY_FAILURE, acct2));
- // There should be two left
- assertEquals(2, errorMap.keySet().size());
- // And these are the two...
- assertNotNull(errorMap.get(box2.mId));
- assertNotNull(errorMap.get(box1.mId));
-
- // Put the two back
- errorMap.put(box3.mId, securityErrorAccount2);
- errorMap.put(box4.mId, securityErrorAccount2);
- // We should have 4 again
- assertEquals(4, errorMap.keySet().size());
- // Release all of the security holds
- assertTrue(exchangeService.releaseSyncHolds(mProviderContext,
- AbstractSyncService.EXIT_SECURITY_FAILURE, null));
- // There should be one left
- assertEquals(1, errorMap.keySet().size());
- // And this is the one
- assertNotNull(errorMap.get(box2.mId));
-
- // Release the i/o holds on account 2 (there aren't any)
- assertFalse(exchangeService.releaseSyncHolds(mProviderContext,
- AbstractSyncService.EXIT_IO_ERROR, acct2));
- // There should still be one left
- assertEquals(1, errorMap.keySet().size());
-
- // Release the i/o holds on account 1 (there's one)
- assertTrue(exchangeService.releaseSyncHolds(mProviderContext,
- AbstractSyncService.EXIT_IO_ERROR, acct1));
- // There should still be one left
- assertEquals(0, errorMap.keySet().size());
- }
-
- public void brokentestIsSyncable() {
- Account acct1 = setupTestAccount("acct1", true);
- Mailbox box1 = EmailContentSetupUtils.setupMailbox("box1", acct1.mId, true,
- mProviderContext, Mailbox.TYPE_DRAFTS);
- Mailbox box2 = EmailContentSetupUtils.setupMailbox("box2", acct1.mId, true,
- mProviderContext, Mailbox.TYPE_OUTBOX);
- Mailbox box3 = EmailContentSetupUtils.setupMailbox("box2", acct1.mId, true,
- mProviderContext, Mailbox.TYPE_ATTACHMENT);
- Mailbox box4 = EmailContentSetupUtils.setupMailbox("box2", acct1.mId, true,
- mProviderContext, Mailbox.TYPE_NOT_SYNCABLE + 64);
- Mailbox box5 = EmailContentSetupUtils.setupMailbox("box2", acct1.mId, true,
- mProviderContext, Mailbox.TYPE_MAIL);
- assertFalse(ExchangeService.isSyncable(box1));
- assertFalse(ExchangeService.isSyncable(box2));
- assertFalse(ExchangeService.isSyncable(box3));
- assertFalse(ExchangeService.isSyncable(box4));
- assertTrue(ExchangeService.isSyncable(box5));
- }
-}
diff --git a/tests/src/com/android/exchange/ExchangeServiceTest.java b/tests/src/com/android/exchange/ExchangeServiceTest.java
deleted file mode 100644
index b4be23f9..00000000
--- a/tests/src/com/android/exchange/ExchangeServiceTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2010 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.exchange;
-
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import java.io.File;
-@SmallTest
-public class ExchangeServiceTest extends AndroidTestCase {
- private static class MyContext extends ContextWrapper {
- public boolean isGetFileStreamPathCalled;
-
- public MyContext(Context base) {
- super(base);
- }
-
- @Override
- public File getFileStreamPath(String name) {
- isGetFileStreamPathCalled = true;
- return super.getFileStreamPath(name);
- }
- }
-
- public void testGetDeviceId() throws Exception {
- final MyContext context = new MyContext(getContext());
-
- final String id = ExchangeService.getDeviceId(context);
-
- // Consists of alpha-numeric
- assertTrue(id.matches("^[a-zA-Z0-9]+$"));
-
- // getDeviceId may have been called in other tests, so we don't check
- // isGetFileStreamPathCalled here.
-
- context.isGetFileStreamPathCalled = false;
- final String cachedId = ExchangeService.getDeviceId(context);
-
- // Should be the same.
- assertEquals(id, cachedId);
- // Should be cached. (If cached, this method won't be called.)
- assertFalse(context.isGetFileStreamPathCalled);
- }
-}
diff --git a/tests/src/com/android/exchange/RequestTests.java b/tests/src/com/android/exchange/RequestTests.java
deleted file mode 100644
index db7cc804..00000000
--- a/tests/src/com/android/exchange/RequestTests.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2011 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.exchange;
-
-import com.android.emailcommon.provider.EmailContent.Attachment;
-import com.android.emailsync.PartRequest;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.RequestTests exchange
- */
-@SmallTest
-public class RequestTests extends AndroidTestCase {
-
- public void testPartRequestEquals() {
- Attachment att1 = new Attachment();
- att1.mId = 1;
- Attachment att2 = new Attachment();
- att2.mId = 2;
- // For part requests, the attachment id's must be ==
- PartRequest req1 = new PartRequest(att1, "dest1", "content1");
- PartRequest req2 = new PartRequest(att2, "dest2", "content2");
- assertFalse(req1.equals(req2));
- Attachment att3 = new Attachment();
- att3.mId = 1;
- PartRequest req3 = new PartRequest(att3, "dest3", "content3");
- assertTrue(req1.equals(req3));
- MessageMoveRequest req4 = new MessageMoveRequest(10L, 12L);
- assertFalse(req1.equals(req4));
- }
-
- public void testRequestEquals() {
- // Only the messageId needs to be ==
- MessageMoveRequest req1 = new MessageMoveRequest(1L, 10L);
- MessageMoveRequest req2 = new MessageMoveRequest(1L, 11L);
- assertTrue(req1.equals(req2));
- MessageMoveRequest req3 = new MessageMoveRequest(2L, 11L);
- assertFalse(req3.equals(req2));
- MeetingResponseRequest req4 = new MeetingResponseRequest(1L, 3);
- assertFalse(req4.equals(req1));
- MeetingResponseRequest req5 = new MeetingResponseRequest(1L, 4);
- assertTrue(req5.equals(req4));
- }
-} \ No newline at end of file
diff --git a/tests/src/com/android/exchange/adapter/AttachmentLoaderTests.java b/tests/src/com/android/exchange/adapter/AttachmentLoaderTests.java
deleted file mode 100644
index 2e16ac82..00000000
--- a/tests/src/com/android/exchange/adapter/AttachmentLoaderTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright (C) 2011 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.
- */
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.adapter.AttachmentLoaderTests exchange
- */
-package com.android.exchange.adapter;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-@SmallTest
-public class AttachmentLoaderTests extends AndroidTestCase {
- private static final String TEST_LOCATION =
- "Inbox/FW:%204G%20Netbook%20|%20Now%20Available%20for%20Order.EML/image012.jpg";
-
- public void testEncodeForExchange2003() {
- assertEquals("abc", AttachmentLoader.encodeForExchange2003("abc"));
- // We don't encode the four characters after abc
- assertEquals("abc_:/.", AttachmentLoader.encodeForExchange2003("abc_:/."));
- // We don't re-encode escaped characters
- assertEquals("%20%33", AttachmentLoader.encodeForExchange2003("%20%33"));
- // Test with the location that failed in use
- assertEquals(TEST_LOCATION.replace("|", "%7C"),
- AttachmentLoader.encodeForExchange2003(TEST_LOCATION));
- }
-}
diff --git a/tests/src/com/android/exchange/adapter/EmailSyncAdapterTests.java b/tests/src/com/android/exchange/adapter/EmailSyncAdapterTests.java
deleted file mode 100644
index 4f89e029..00000000
--- a/tests/src/com/android/exchange/adapter/EmailSyncAdapterTests.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (C) 2010 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.exchange.adapter;
-
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.EmailContent;
-import com.android.emailcommon.provider.EmailContent.Body;
-import com.android.emailcommon.provider.EmailContent.Message;
-import com.android.emailcommon.provider.EmailContent.MessageColumns;
-import com.android.emailcommon.provider.EmailContent.SyncColumns;
-import com.android.emailcommon.provider.Mailbox;
-import com.android.exchange.EasSyncService;
-import com.android.exchange.adapter.EmailSyncAdapter.EasEmailSyncParser;
-import com.android.exchange.adapter.EmailSyncAdapter.EasEmailSyncParser.ServerChange;
-import com.android.exchange.provider.EmailContentSetupUtils;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-@SmallTest
-public class EmailSyncAdapterTests extends SyncAdapterTestCase<EmailSyncAdapter> {
-
- private static final String WHERE_ACCOUNT_KEY = MessageColumns.ACCOUNT_KEY + "=?";
- private static final String[] ACCOUNT_ARGUMENT = new String[1];
-
- // A server id that is guaranteed to be test-related
- private static final String TEST_SERVER_ID = "__1:22";
-
- public EmailSyncAdapterTests() {
- super();
- }
-
- /**
- * Check functionality for getting mime type from a file name (using its extension)
- * The default for all unknown files is application/octet-stream
- */
- public void testGetMimeTypeFromFileName() throws IOException {
- EasSyncService service = getTestService();
- EmailSyncAdapter adapter = new EmailSyncAdapter(service);
- EasEmailSyncParser p = new EasEmailSyncParser(getTestInputStream(), adapter);
- // Test a few known types
- String mimeType = p.getMimeTypeFromFileName("foo.jpg");
- assertEquals("image/jpeg", mimeType);
- // Make sure this is case insensitive
- mimeType = p.getMimeTypeFromFileName("foo.JPG");
- assertEquals("image/jpeg", mimeType);
- mimeType = p.getMimeTypeFromFileName("this_is_a_weird_filename.gif");
- assertEquals("image/gif", mimeType);
- // Test an illegal file name ending with the extension prefix
- mimeType = p.getMimeTypeFromFileName("foo.");
- assertEquals("application/octet-stream", mimeType);
- // Test a really awful name
- mimeType = p.getMimeTypeFromFileName(".....");
- assertEquals("application/octet-stream", mimeType);
- // Test a bare file name (no extension)
- mimeType = p.getMimeTypeFromFileName("foo");
- assertEquals("application/octet-stream", mimeType);
- // And no name at all (null isn't a valid input)
- mimeType = p.getMimeTypeFromFileName("");
- assertEquals("application/octet-stream", mimeType);
- }
-
- public void testFormatDateTime() throws IOException {
- EmailSyncAdapter adapter = getTestSyncAdapter(EmailSyncAdapter.class);
- GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
- // Calendar is odd, months are zero based, so the first 11 below is December...
- calendar.set(2008, 11, 11, 18, 19, 20);
- String date = adapter.formatDateTime(calendar);
- assertEquals("2008-12-11T18:19:20.000Z", date);
- calendar.clear();
- calendar.set(2012, 0, 2, 23, 0, 1);
- date = adapter.formatDateTime(calendar);
- assertEquals("2012-01-02T23:00:01.000Z", date);
- }
-
- public void brokentestSendDeletedItems() throws IOException {
- setupAccountMailboxAndMessages(0);
- // Setup our adapter and parser
- setupSyncParserAndAdapter(mAccount, mMailbox);
-
- Serializer s = new Serializer();
- ArrayList<Long> ids = new ArrayList<Long>();
- ArrayList<Long> deletedIds = new ArrayList<Long>();
-
- // Create account and two mailboxes
- mSyncAdapter.mAccount = mAccount;
- Mailbox box1 = EmailContentSetupUtils.setupMailbox("box1", mAccount.mId, true,
- mProviderContext);
- mSyncAdapter.mMailbox = box1;
-
- // Create 3 messages
- Message msg1 = EmailContentSetupUtils.setupMessage("message1", mAccount.mId, box1.mId,
- true, true, mProviderContext);
- ids.add(msg1.mId);
- Message msg2 = EmailContentSetupUtils.setupMessage("message2", mAccount.mId, box1.mId,
- true, true, mProviderContext);
- ids.add(msg2.mId);
- Message msg3 = EmailContentSetupUtils.setupMessage("message3", mAccount.mId, box1.mId,
- true, true, mProviderContext);
- ids.add(msg3.mId);
- assertEquals(3, EmailContent.count(mProviderContext, Message.CONTENT_URI, WHERE_ACCOUNT_KEY,
- getAccountArgument(mAccount.mId)));
-
- // Delete them
- for (long id: ids) {
- mResolver.delete(ContentUris.withAppendedId(Message.SYNCED_CONTENT_URI, id),
- null, null);
- }
-
- // Confirm that the messages are in the proper table
- assertEquals(0, EmailContent.count(mProviderContext, Message.CONTENT_URI, WHERE_ACCOUNT_KEY,
- getAccountArgument(mAccount.mId)));
- assertEquals(3, EmailContent.count(mProviderContext, Message.DELETED_CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
-
- // Call code to send deletions; the id's of the ones actually deleted will be in the
- // deletedIds list
- mSyncAdapter.sendDeletedItems(s, deletedIds, true);
- assertEquals(3, deletedIds.size());
-
- // Clear this out for the next test
- deletedIds.clear();
-
- // Create a new message
- Message msg4 = EmailContentSetupUtils.setupMessage("message4", mAccount.mId, box1.mId,
- true, true, mProviderContext);
- assertEquals(1, EmailContent.count(mProviderContext, Message.CONTENT_URI, WHERE_ACCOUNT_KEY,
- getAccountArgument(mAccount.mId)));
- // Find the body for this message
- Body body = Body.restoreBodyWithMessageId(mProviderContext, msg4.mId);
- // Set its source message to msg2's id
- ContentValues values = new ContentValues();
- values.put(EmailContent.BodyColumns.SOURCE_MESSAGE_KEY, msg2.mId);
- body.update(mProviderContext, values);
-
- // Now send deletions again; this time only two should get deleted; msg2 should NOT be
- // deleted as it's referenced by msg4
- mSyncAdapter.sendDeletedItems(s, deletedIds, true);
- assertEquals(2, deletedIds.size());
- assertFalse(deletedIds.contains(msg2.mId));
- }
-
- private String[] getAccountArgument(long id) {
- ACCOUNT_ARGUMENT[0] = Long.toString(id);
- return ACCOUNT_ARGUMENT;
- }
-
- void setupSyncParserAndAdapter(Account account, Mailbox mailbox) throws IOException {
- EasSyncService service = getTestService(account, mailbox);
- mSyncAdapter = new EmailSyncAdapter(service);
- mSyncParser = new EasEmailSyncParser(getTestInputStream(), mSyncAdapter);
- }
-
- ArrayList<Long> setupAccountMailboxAndMessages(int numMessages) {
- ArrayList<Long> ids = new ArrayList<Long>();
-
- // Create account and two mailboxes
- mAccount = EmailContentSetupUtils.setupAccount("account", true, mProviderContext);
- mMailbox = EmailContentSetupUtils.setupMailbox("box1", mAccount.mId, true,
- mProviderContext);
-
- for (int i = 0; i < numMessages; i++) {
- Message msg = EmailContentSetupUtils.setupMessage("message" + i, mAccount.mId,
- mMailbox.mId, true, true, mProviderContext);
- ids.add(msg.mId);
- }
-
- assertEquals(numMessages, EmailContent.count(mProviderContext, Message.CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
- return ids;
- }
-
- public void brokentestDeleteParser() throws IOException {
- // Setup some messages
- ArrayList<Long> messageIds = setupAccountMailboxAndMessages(3);
- ContentValues cv = new ContentValues();
- cv.put(SyncColumns.SERVER_ID, TEST_SERVER_ID);
- long deleteMessageId = messageIds.get(1);
- mResolver.update(ContentUris.withAppendedId(Message.CONTENT_URI, deleteMessageId), cv,
- null, null);
-
- // Setup our adapter and parser
- setupSyncParserAndAdapter(mAccount, mMailbox);
-
- // Set up an input stream with a delete command
- Serializer s = new Serializer(false);
- s.start(Tags.SYNC_DELETE).data(Tags.SYNC_SERVER_ID, TEST_SERVER_ID).end().done();
- byte[] bytes = s.toByteArray();
- mSyncParser.resetInput(new ByteArrayInputStream(bytes));
- mSyncParser.nextTag(0);
-
- // Run the delete parser
- ArrayList<Long> deleteList = new ArrayList<Long>();
- mSyncParser.deleteParser(deleteList, Tags.SYNC_DELETE);
- // It should have found the message
- assertEquals(1, deleteList.size());
- long id = deleteList.get(0);
- // And the id's should match
- assertEquals(deleteMessageId, id);
- }
-
- public void brokentestChangeParser() throws IOException {
- // Setup some messages
- ArrayList<Long> messageIds = setupAccountMailboxAndMessages(3);
- ContentValues cv = new ContentValues();
- int randomFlags = Message.FLAG_INCOMING_MEETING_CANCEL | Message.FLAG_TYPE_FORWARD;
- cv.put(SyncColumns.SERVER_ID, TEST_SERVER_ID);
- cv.put(MessageColumns.FLAGS, randomFlags);
- long changeMessageId = messageIds.get(1);
- mResolver.update(ContentUris.withAppendedId(Message.CONTENT_URI, changeMessageId), cv,
- null, null);
-
- // Setup our adapter and parser
- setupSyncParserAndAdapter(mAccount, mMailbox);
-
- // Set up an input stream with a change command (marking TEST_SERVER_ID unread)
- // Note that the test message creation code sets read to "true"
- Serializer s = new Serializer(false);
- s.start(Tags.SYNC_CHANGE).data(Tags.SYNC_SERVER_ID, TEST_SERVER_ID);
- s.start(Tags.SYNC_APPLICATION_DATA);
- s.data(Tags.EMAIL_READ, "0");
- s.data(Tags.EMAIL2_LAST_VERB_EXECUTED,
- Integer.toString(EmailSyncAdapter.LAST_VERB_FORWARD));
- s.end().end().done();
- byte[] bytes = s.toByteArray();
- mSyncParser.resetInput(new ByteArrayInputStream(bytes));
- mSyncParser.nextTag(0);
-
- // Run the delete parser
- ArrayList<ServerChange> changeList = new ArrayList<ServerChange>();
- mSyncParser.changeParser(changeList);
- // It should have found the message
- assertEquals(1, changeList.size());
- // And the id's should match
- ServerChange change = changeList.get(0);
- assertEquals(changeMessageId, change.id);
- assertNotNull(change.read);
- assertFalse(change.read);
- // Make sure we see the forwarded flag AND that the original flags are preserved
- assertEquals((Integer)(randomFlags | Message.FLAG_FORWARDED), change.flags);
- }
-
- public void brokentestCleanup() throws IOException {
- // Setup some messages
- ArrayList<Long> messageIds = setupAccountMailboxAndMessages(3);
- // Setup our adapter and parser
- setupSyncParserAndAdapter(mAccount, mMailbox);
-
- // Delete two of the messages, change one
- long id = messageIds.get(0);
- mResolver.delete(ContentUris.withAppendedId(Message.SYNCED_CONTENT_URI, id),
- null, null);
- mSyncAdapter.mDeletedIdList.add(id);
- id = messageIds.get(1);
- mResolver.delete(ContentUris.withAppendedId(Message.SYNCED_CONTENT_URI,
- id), null, null);
- mSyncAdapter.mDeletedIdList.add(id);
- id = messageIds.get(2);
- ContentValues cv = new ContentValues();
- cv.put(MessageColumns.FLAG_READ, 0);
- mResolver.update(ContentUris.withAppendedId(Message.SYNCED_CONTENT_URI,
- id), cv, null, null);
- mSyncAdapter.mUpdatedIdList.add(id);
-
- // The changed message should still exist
- assertEquals(1, EmailContent.count(mProviderContext, Message.CONTENT_URI, WHERE_ACCOUNT_KEY,
- getAccountArgument(mAccount.mId)));
-
- // As well, the two deletions and one update
- assertEquals(2, EmailContent.count(mProviderContext, Message.DELETED_CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
- assertEquals(1, EmailContent.count(mProviderContext, Message.UPDATED_CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
-
- // Cleanup (i.e. after sync); should remove items from delete/update tables
- mSyncAdapter.cleanup();
-
- // The three should be gone
- assertEquals(0, EmailContent.count(mProviderContext, Message.DELETED_CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
- assertEquals(0, EmailContent.count(mProviderContext, Message.UPDATED_CONTENT_URI,
- WHERE_ACCOUNT_KEY, getAccountArgument(mAccount.mId)));
- }
-}
diff --git a/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java b/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java
deleted file mode 100644
index 3eb59e7d..00000000
--- a/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Copyright (C) 2010 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.exchange.adapter;
-
-import android.content.ContentResolver;
-import android.content.res.AssetManager;
-import android.database.Cursor;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.EmailContent;
-import com.android.emailcommon.provider.Mailbox;
-import com.android.emailcommon.provider.EmailContent.MailboxColumns;
-import com.android.emailcommon.service.SyncWindow;
-import com.android.exchange.CommandStatusException;
-import com.android.exchange.EasSyncService;
-import com.android.exchange.provider.EmailContentSetupUtils;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-
-/**
- * You can run this entire test case with:
- * runtest -c com.android.exchange.adapter.FolderSyncParserTests exchange
- */
-@MediumTest
-public class FolderSyncParserTests extends SyncAdapterTestCase<EmailSyncAdapter> {
-
- // We increment this to generate unique server id's
- private int mServerIdCount = 0;
- private final long mCreationTime = System.currentTimeMillis();
- private final String[] mMailboxQueryArgs = new String[2];
-
- public FolderSyncParserTests() {
- super();
- }
-
- private Mailbox setupBoxSync(int interval, int lookback, String serverId) {
- // Don't save the box; just create it, and give it a server id
- Mailbox box = EmailContentSetupUtils.setupMailbox("box1", mAccount.mId, false,
- mProviderContext, Mailbox.TYPE_MAIL);
- box.mSyncInterval = interval;
- box.mSyncLookback = lookback;
- if (serverId != null) {
- box.mServerId = serverId;
- } else {
- box.mServerId = "serverId-" + mCreationTime + '-' + mServerIdCount++;
- }
- box.save(mProviderContext);
- return box;
- }
-
- private boolean syncOptionsSame(Mailbox a, Mailbox b) {
- if (a.mSyncInterval != b.mSyncInterval) return false;
- if (a.mSyncLookback != b.mSyncLookback) return false;
- return true;
- }
-
- public void brokentestSaveAndRestoreMailboxSyncOptions() throws IOException {
- EasSyncService service = getTestService();
- EmailSyncAdapter adapter = new EmailSyncAdapter(service);
- FolderSyncParser parser = new FolderSyncParser(getTestInputStream(), adapter);
- mAccount.save(mProviderContext);
-
- parser.mAccount = mAccount;
- parser.mAccountId = mAccount.mId;
- parser.mAccountIdAsString = Long.toString(mAccount.mId);
- parser.mContext = mProviderContext;
- parser.mContentResolver = mProviderContext.getContentResolver();
-
- // Don't save the box; just create it, and give it a server id
- Mailbox box1 = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- null);
- Mailbox box2 = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- null);
- Mailbox boxa = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_1_MONTH,
- null);
- Mailbox boxb = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_2_WEEKS,
- null);
- Mailbox boxc = setupBoxSync(Account.CHECK_INTERVAL_PUSH, SyncWindow.SYNC_WINDOW_ACCOUNT,
- null);
- Mailbox boxd = setupBoxSync(Account.CHECK_INTERVAL_PUSH, SyncWindow.SYNC_WINDOW_ACCOUNT,
- null);
- Mailbox boxe = setupBoxSync(Account.CHECK_INTERVAL_PUSH, SyncWindow.SYNC_WINDOW_1_DAY,
- null);
-
- // Save the options (for a, b, c, d, e);
- parser.saveMailboxSyncOptions();
- // There should be 5 entries in the map, and they should be the correct ones
- assertNotNull(parser.mSyncOptionsMap.get(boxa.mServerId));
- assertNotNull(parser.mSyncOptionsMap.get(boxb.mServerId));
- assertNotNull(parser.mSyncOptionsMap.get(boxc.mServerId));
- assertNotNull(parser.mSyncOptionsMap.get(boxd.mServerId));
- assertNotNull(parser.mSyncOptionsMap.get(boxe.mServerId));
-
- // Delete all the mailboxes in the account
- ContentResolver cr = mProviderContext.getContentResolver();
- cr.delete(Mailbox.CONTENT_URI, Mailbox.ACCOUNT_KEY + "=?",
- new String[] {parser.mAccountIdAsString});
-
- // Create new boxes, all with default values for interval & window
- Mailbox box1x = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- box1.mServerId);
- Mailbox box2x = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- box2.mServerId);
- Mailbox boxax = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- boxa.mServerId);
- Mailbox boxbx = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- boxb.mServerId);
- Mailbox boxcx = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- boxc.mServerId);
- Mailbox boxdx = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- boxd.mServerId);
- Mailbox boxex = setupBoxSync(Account.CHECK_INTERVAL_NEVER, SyncWindow.SYNC_WINDOW_ACCOUNT,
- boxe.mServerId);
-
- // Restore the sync options
- parser.restoreMailboxSyncOptions();
- box1x = Mailbox.restoreMailboxWithId(mProviderContext, box1x.mId);
- box2x = Mailbox.restoreMailboxWithId(mProviderContext, box2x.mId);
- boxax = Mailbox.restoreMailboxWithId(mProviderContext, boxax.mId);
- boxbx = Mailbox.restoreMailboxWithId(mProviderContext, boxbx.mId);
- boxcx = Mailbox.restoreMailboxWithId(mProviderContext, boxcx.mId);
- boxdx = Mailbox.restoreMailboxWithId(mProviderContext, boxdx.mId);
- boxex = Mailbox.restoreMailboxWithId(mProviderContext, boxex.mId);
-
- assertTrue(syncOptionsSame(box1, box1x));
- assertTrue(syncOptionsSame(box2, box2x));
- assertTrue(syncOptionsSame(boxa, boxax));
- assertTrue(syncOptionsSame(boxb, boxbx));
- assertTrue(syncOptionsSame(boxc, boxcx));
- assertTrue(syncOptionsSame(boxd, boxdx));
- assertTrue(syncOptionsSame(boxe, boxex));
- }
-
- private static class MockFolderSyncParser extends FolderSyncParser {
- private BufferedReader mReader;
- private int mDepth = 0;
- private String[] mStack = new String[32];
- private HashMap<String, Integer> mTagMap;
-
-
- public MockFolderSyncParser(String fileName, AbstractSyncAdapter adapter)
- throws IOException {
- super(null, adapter);
- AssetManager am = mContext.getAssets();
- InputStream is = am.open(fileName);
- if (is != null) {
- mReader = new BufferedReader(new InputStreamReader(is));
- }
- }
-
- private void initTagMap() {
- mTagMap = new HashMap<String, Integer>();
- int pageNum = 0;
- for (String[] page: Tags.mPages) {
- int tagNum = 5;
- for (String tag: page) {
- if (mTagMap.containsKey(tag)) {
- System.err.println("Duplicate tag: " + tag);
- }
- int val = (pageNum << Tags.PAGE_SHIFT) + tagNum;
- mTagMap.put(tag, val);
- tagNum++;
- }
- pageNum++;
- }
- }
-
- private int lookupTag(String tagName) {
- if (mTagMap == null) {
- initTagMap();
- }
- int res = mTagMap.get(tagName);
- return res;
- }
-
- private String getLine() throws IOException {
- while (true) {
- String line = mReader.readLine();
- if (line == null) {
- return null;
- }
- int start = line.indexOf("| ");
- if (start > 2) {
- return line.substring(start + 2);
- }
- // Keep looking for a suitable line
- }
- }
-
- @Override
- public int getValueInt() throws IOException {
- return Integer.parseInt(getValue());
- }
-
- @Override
- public String getValue() throws IOException {
- String line = getLine();
- if (line == null) throw new IOException();
- int start = line.indexOf(": ");
- if (start < 0) throw new IOException("Line has no value: " + line);
- try {
- return line.substring(start + 2).trim();
- } finally {
- if (nextTag(0) != END) {
- throw new IOException("Value not followed by end tag");
- }
- }
- }
-
- @Override
- public void skipTag() throws IOException {
- if (nextTag(0) == -1) {
- nextTag(0);
- }
- }
-
- @Override
- public int nextTag(int endingTag) throws IOException {
- String line = getLine();
- if (line == null) {
- return END_DOCUMENT;
- }
- if (line.startsWith("</")) {
- int end = line.indexOf('>');
- String tagName = line.substring(2, end).trim();
- if (!tagName.equals(mStack[--mDepth])) {
- throw new IOException("Tag end doesn't match tag");
- }
- mStack[mDepth] = null;
- return END;
- } else if (line.startsWith("<")) {
- int end = line.indexOf('>');
- String tagName = line.substring(1, end).trim();
- mStack[mDepth++] = tagName;
- tag = lookupTag(tagName);
- return tag;
- } else {
- return -1;
- }
- }
- }
-
- private Mailbox getMailboxWithName(String folderName) {
- mMailboxQueryArgs[1] = folderName;
- Cursor c = mResolver.query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
- Mailbox.ACCOUNT_KEY + "=? AND " + Mailbox.DISPLAY_NAME + "=?", mMailboxQueryArgs,
- null);
- try {
- assertTrue(c.getCount() == 1);
- c.moveToFirst();
- Mailbox m = new Mailbox();
- m.restore(c);
- return m;
- } finally {
- c.close();
- }
- }
-
- private boolean isTopLevel(String folderName) {
- Mailbox m = getMailboxWithName(folderName);
- assertNotNull(m);
- return m.mParentKey == Mailbox.NO_MAILBOX;
- }
-
- private boolean isSubfolder(String parentName, String childName) {
- Mailbox parent = getMailboxWithName(parentName);
- Mailbox child = getMailboxWithName(childName);
- assertNotNull(parent);
- assertNotNull(child);
- assertTrue((parent.mFlags & Mailbox.FLAG_HAS_CHILDREN) != 0);
- return child.mParentKey == parent.mId;
- }
-
- /**
- * Parse a set of EAS FolderSync commands and create the Mailbox tree accordingly
- *
- * @param fileName the name of the file containing emaillog data for folder sync
- * @throws IOException
- * @throws CommandStatusException
- */
- private void testComplexFolderListParse(String fileName) throws IOException,
- CommandStatusException {
- EasSyncService service = getTestService();
- EmailSyncAdapter adapter = new EmailSyncAdapter(service);
- FolderSyncParser parser = new MockFolderSyncParser(fileName, adapter);
- mAccount.save(mProviderContext);
- mMailboxQueryArgs[0] = Long.toString(mAccount.mId);
- parser.mAccount = mAccount;
- parser.mAccountId = mAccount.mId;
- parser.mAccountIdAsString = Long.toString(mAccount.mId);
- parser.mContext = mProviderContext;
- parser.mContentResolver = mResolver;
-
- parser.parse();
-
- assertTrue(isTopLevel("Inbox"));
- assertTrue(isSubfolder("Inbox", "Gecko"));
- assertTrue(isSubfolder("Inbox", "Wombat"));
- assertTrue(isSubfolder("Inbox", "Laslo"));
- assertTrue(isSubfolder("Inbox", "Tomorrow"));
- assertTrue(isSubfolder("Inbox", "Vader"));
- assertTrue(isSubfolder("Inbox", "Personal"));
- assertTrue(isSubfolder("Laslo", "Lego"));
- assertTrue(isSubfolder("Tomorrow", "HomeRun"));
- assertTrue(isSubfolder("Tomorrow", "Services"));
- assertTrue(isSubfolder("HomeRun", "Review"));
- assertTrue(isSubfolder("Vader", "Max"));
- assertTrue(isSubfolder("Vader", "Parser"));
- assertTrue(isSubfolder("Vader", "Scott"));
- assertTrue(isSubfolder("Vader", "Surfing"));
- assertTrue(isSubfolder("Max", "Thomas"));
- assertTrue(isSubfolder("Personal", "Famine"));
- assertTrue(isSubfolder("Personal", "Bar"));
- assertTrue(isSubfolder("Personal", "Bill"));
- assertTrue(isSubfolder("Personal", "Boss"));
- assertTrue(isSubfolder("Personal", "Houston"));
- assertTrue(isSubfolder("Personal", "Mistake"));
- assertTrue(isSubfolder("Personal", "Online"));
- assertTrue(isSubfolder("Personal", "Sports"));
- assertTrue(isSubfolder("Famine", "Buffalo"));
- assertTrue(isSubfolder("Famine", "CornedBeef"));
- assertTrue(isSubfolder("Houston", "Rebar"));
- assertTrue(isSubfolder("Mistake", "Intro"));
- }
-
- // FolderSyncParserTest.txt is based on customer data (all names changed) that failed to
- // properly create the Mailbox list
- public void brokentestComplexFolderListParse1() throws CommandStatusException, IOException {
- testComplexFolderListParse("FolderSyncParserTest.txt");
- }
-
- // As above, with the order changed (putting children before parents; a more difficult case
- public void brokentestComplexFolderListParse2() throws CommandStatusException, IOException {
- testComplexFolderListParse("FolderSyncParserTest2.txt");
- }
-
- // Much larger test (from user with issues related to Type 1 folders)
- public void brokentestComplexFolderListParse3() throws CommandStatusException, IOException {
- EasSyncService service = getTestService();
- EmailSyncAdapter adapter = new EmailSyncAdapter(service);
- FolderSyncParser parser = new MockFolderSyncParser("FolderSyncParserTest3.txt", adapter);
- mAccount.save(mProviderContext);
- mMailboxQueryArgs[0] = Long.toString(mAccount.mId);
- parser.mAccount = mAccount;
- parser.mAccountId = mAccount.mId;
- parser.mAccountIdAsString = Long.toString(mAccount.mId);
- parser.mContext = mProviderContext;
- parser.mContentResolver = mResolver;
- parser.parse();
-
- int cnt = EmailContent.count(mProviderContext, Mailbox.CONTENT_URI,
- MailboxColumns.ACCOUNT_KEY + "=" + mAccount.mId, null);
- // 270 in the file less 4 "conflicts" folders
- assertEquals(266, cnt);
- }
-}
diff --git a/tests/src/com/android/exchange/adapter/ProvisionParserTests.java b/tests/src/com/android/exchange/adapter/ProvisionParserTests.java
index 77ff05b0..9f6388d5 100644
--- a/tests/src/com/android/exchange/adapter/ProvisionParserTests.java
+++ b/tests/src/com/android/exchange/adapter/ProvisionParserTests.java
@@ -20,6 +20,7 @@ import com.android.emailcommon.provider.Policy;
import com.android.exchange.adapter.ProvisionParser;
import android.content.Context;
+import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import java.io.ByteArrayInputStream;
@@ -30,7 +31,7 @@ import java.io.IOException;
* runtest -c com.android.exchange.adapter.ProvisionParserTests exchange
*/
@SmallTest
-public class ProvisionParserTests extends SyncAdapterTestCase {
+public class ProvisionParserTests extends AndroidTestCase {
// <Sync><Status>1</Status></Sync>
private final byte[] wbxmlBytes = new byte[] {
0x03, 0x01, 0x6A, 0x00, 0x45, 0x4E, 0x03, 0x31, 0x00, 0x01, 0x01};
diff --git a/tests/src/com/android/exchange/adapter/SyncAdapterTestCase.java b/tests/src/com/android/exchange/adapter/SyncAdapterTestCase.java
deleted file mode 100644
index aff4c542..00000000
--- a/tests/src/com/android/exchange/adapter/SyncAdapterTestCase.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2010 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.exchange.adapter;
-
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.Mailbox;
-import com.android.exchange.EasSyncService;
-import com.android.exchange.adapter.AbstractSyncAdapter;
-import com.android.exchange.adapter.EmailSyncAdapter;
-import com.android.exchange.adapter.EmailSyncAdapter.EasEmailSyncParser;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-@MediumTest
-public class SyncAdapterTestCase<T extends AbstractSyncAdapter> extends AndroidTestCase {
- public Context mContext;
- public Context mProviderContext;
- public ContentResolver mResolver;
- public Mailbox mMailbox;
- public Account mAccount;
- public EmailSyncAdapter mSyncAdapter;
- public EasEmailSyncParser mSyncParser;
-
- public SyncAdapterTestCase() {
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mContext = getContext();
- // This could be used with a MockContext if we switch over
- mProviderContext = mContext;
- mResolver = mContext.getContentResolver();
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- // If we've created and saved an account, delete it
- if (mAccount != null && mAccount.mId > 0) {
- mResolver.delete(ContentUris.withAppendedId(Account.CONTENT_URI, mAccount.mId), null,
- null);
- }
- }
-
- /**
- * Create and return a short, simple InputStream that has at least four bytes, which is all
- * that's required to initialize an EasParser (the parent class of EasEmailSyncParser)
- * @return the InputStream
- */
- public InputStream getTestInputStream() {
- // <Sync><Status>1</Status></Sync>
- final byte[] wbxmlBytes = new byte[] {
- 0x03, 0x01, 0x6A, 0x00, 0x45, 0x4E, 0x03, 0x31, 0x00, 0x01, 0x01};
- return new ByteArrayInputStream(wbxmlBytes);
- }
-
- EasSyncService getTestService() {
- mAccount = new Account();
- mAccount.mEmailAddress = "__test__@android.com";
- mAccount.mId = -1;
- Mailbox mailbox = new Mailbox();
- mailbox.mId = -1;
- return getTestService(mAccount, mailbox);
- }
-
- EasSyncService getTestService(Account account, Mailbox mailbox) {
- EasSyncService service = new EasSyncService();
- service.mContext = mContext;
- service.mMailbox = mailbox;
- service.mAccount = account;
- service.mContentResolver = mContext.getContentResolver();
- return service;
- }
-
- protected T getTestSyncAdapter(Class<T> klass) {
- EasSyncService service = getTestService();
- Constructor<T> c;
- try {
- c = klass.getDeclaredConstructor(new Class[] {EasSyncService.class});
- return c.newInstance(service);
- } catch (SecurityException e) {
- } catch (NoSuchMethodException e) {
- } catch (IllegalArgumentException e) {
- } catch (InstantiationException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- }
- return null;
- }
-
-}
diff --git a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
index bf80f1b7..13d24882 100644
--- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
+++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
@@ -30,15 +30,9 @@ import com.android.emailcommon.provider.EmailContent.Attachment;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.utility.Utility;
import com.android.exchange.R;
-import com.android.exchange.adapter.CalendarSyncParser;
-import com.android.exchange.adapter.Parser;
-import com.android.exchange.adapter.Serializer;
-import com.android.exchange.adapter.SyncAdapterTestCase;
-import com.android.exchange.adapter.Tags;
import com.android.mail.utils.LogUtils;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.text.DateFormat;