summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2014-05-10 23:27:20 -0700
committerJay Shrauner <shrauner@google.com>2014-05-16 10:22:41 -0700
commit3d52ff729b82a20802bb6d5a8952040f4d961cef (patch)
tree8357c464bf40133e8a5a4fb4d90e75cd9c876c4c /tests
parent0347367531674a83ff36a4fbc222319d5e1693d9 (diff)
downloadandroid_packages_apps_Exchange-3d52ff729b82a20802bb6d5a8952040f4d961cef.tar.gz
android_packages_apps_Exchange-3d52ff729b82a20802bb6d5a8952040f4d961cef.tar.bz2
android_packages_apps_Exchange-3d52ff729b82a20802bb6d5a8952040f4d961cef.zip
Fix handling of encoded ints
Fix encoding of ints to handle ints with high bit set. Modify Parser to detect when it is decoding a run-on badly encoded int (ie, >5 bytes). Bug:14817987 Change-Id: I4a21b126d03e2e244b0fd4c4fb4821d165897ad6
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/exchange/TagsTests.java40
-rw-r--r--tests/src/com/android/exchange/adapter/FolderSyncParserTests.java2
-rw-r--r--tests/src/com/android/exchange/adapter/ParserTest.java22
-rw-r--r--tests/src/com/android/exchange/adapter/SerializerTests.java11
4 files changed, 23 insertions, 52 deletions
diff --git a/tests/src/com/android/exchange/TagsTests.java b/tests/src/com/android/exchange/TagsTests.java
deleted file mode 100644
index 55b27c0d..00000000
--- a/tests/src/com/android/exchange/TagsTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.exchange;
-
-import com.android.exchange.adapter.Tags;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import java.util.HashMap;
-@SmallTest
-public class TagsTests extends AndroidTestCase {
-
- // Make sure there are no duplicates in the tags table
- // This test is no longer required - tags can be duplicated
- public void disable_testNoDuplicates() {
- String[][] allTags = Tags.pages;
- HashMap<String, Boolean> map = new HashMap<String, Boolean>();
- for (String[] page: allTags) {
- for (String tag: page) {
- assertTrue(tag, !map.containsKey(tag));
- map.put(tag, true);
- }
- }
- }
-}
diff --git a/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java b/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java
index 53fdc526..3eb59e7d 100644
--- a/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java
+++ b/tests/src/com/android/exchange/adapter/FolderSyncParserTests.java
@@ -170,7 +170,7 @@ public class FolderSyncParserTests extends SyncAdapterTestCase<EmailSyncAdapter>
private void initTagMap() {
mTagMap = new HashMap<String, Integer>();
int pageNum = 0;
- for (String[] page: Tags.pages) {
+ for (String[] page: Tags.mPages) {
int tagNum = 5;
for (String tag: page) {
if (mTagMap.containsKey(tag)) {
diff --git a/tests/src/com/android/exchange/adapter/ParserTest.java b/tests/src/com/android/exchange/adapter/ParserTest.java
index b6436233..8b36433d 100644
--- a/tests/src/com/android/exchange/adapter/ParserTest.java
+++ b/tests/src/com/android/exchange/adapter/ParserTest.java
@@ -109,17 +109,6 @@ public class ParserTest extends AndroidTestCase {
}
@SmallTest
- public void testParser() throws Exception {
- // Test parser with sample valid data
- final String wbxmlDataStr =
- "03 01 6A 00 45 5C 4F 50 03 43 6F 6E 74 61 63 74 73 00 01 4B 03 32 00 01 52 03 32 00 01 4E 03 " +
- "31 00 01 56 47 4D 03 32 3A 31 00 01 5D 00 11 4A 46 03 31 00 01 4C 03 30 00 01 4D 03 31 00 01 " +
- "01 00 01 5E 03 46 75 6E 6B 2C 20 44 6F 6E 00 01 5F 03 44 6F 6E 00 01 69 03 46 75 6E 6B 00 01 " +
- "00 11 56 03 31 00 01 01 01 01 01 01 01";
- testParserHelper(wbxmlDataStr);
- }
-
- @SmallTest
public void testUnsupportedWbxmlTag() throws Exception {
// Test parser with unsupported Wbxml tag (EXT_2 = 0xC2)
final String unsupportedWbxmlTag = "03 01 6A 00 45 5F C2 05 11 22 33 44 00 01 01";
@@ -229,6 +218,17 @@ public class ParserTest extends AndroidTestCase {
}
@SmallTest
+ public void testRunOnInteger() throws Exception {
+ final String runOnIntegerEncoding = "03 01 6A 00 45 4D C3 81 82 83 84 85 06 11 22 33 01 01";
+ try {
+ testParserHelper(runOnIntegerEncoding);
+ fail("Expected EasParserException for improperly encoded integer");
+ } catch (Parser.EasParserException e) {
+ // expected
+ }
+ }
+
+ @SmallTest
public void testAttributeTag() throws Exception {
// Test parser with known tag with attributes
final String tagWithAttributes = "03 01 6A 00 45 DF 06 01 03 31 00 01 01";
diff --git a/tests/src/com/android/exchange/adapter/SerializerTests.java b/tests/src/com/android/exchange/adapter/SerializerTests.java
index 921c2261..75132dc9 100644
--- a/tests/src/com/android/exchange/adapter/SerializerTests.java
+++ b/tests/src/com/android/exchange/adapter/SerializerTests.java
@@ -22,7 +22,10 @@ import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
/** You can run this entire test case with:
* runtest -c com.android.exchange.adapter.SerializerTests exchange
@@ -93,4 +96,12 @@ public class SerializerTests extends AndroidTestCase {
// Make sure we get what's expected
MoreAsserts.assertEquals("Serializer mismatch", bytes, expectedBytes);
}
+
+ @SmallTest
+ public void testWriteInteger() throws IOException {
+ OutputStream output = new ByteArrayOutputStream();
+ Serializer.writeInteger(output, 384);
+ Serializer.writeInteger(output, 0);
+ Serializer.writeInteger(output, -1);
+ }
}