Added CTS test for calendarcommon package.
Added a test to ensure partners do not fatally mess with the
calendarcommon package.
Bug: 6739537
Change-Id: I2c16311409d718bc5e3f525e3ce297be5112897c
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 8c2b798..5511ebd 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -59,6 +59,7 @@
CtsAnimationTestCases \
CtsAppTestCases \
CtsBluetoothTestCases \
+ CtsCalendarcommon2TestCases \
CtsContentTestCases \
CtsDatabaseTestCases \
CtsDpiTestCases \
diff --git a/tests/tests/calendarcommon/Android.mk b/tests/tests/calendarcommon/Android.mk
new file mode 100644
index 0000000..c825c32
--- /dev/null
+++ b/tests/tests/calendarcommon/Android.mk
@@ -0,0 +1,37 @@
+# Copyright (C) 2012 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Replace "Example" with your name.
+LOCAL_PACKAGE_NAME := CtsCalendarcommon2TestCases
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+# All tests should include android.test.runner.
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/calendarcommon/AndroidManifest.xml b/tests/tests/calendarcommon/AndroidManifest.xml
new file mode 100644
index 0000000..dc95af5
--- /dev/null
+++ b/tests/tests/calendarcommon/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.calendarcommon2">
+
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!-- This is a self-instrumenting test package. -->
+ <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+ android:targetPackage="com.android.cts.calendarcommon2"
+ android:label="CTS tests of calendarcommon"/>
+
+ <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15"></uses-sdk>
+
+</manifest>
+
diff --git a/tests/tests/calendarcommon/src/android/calendarcommon2/cts/Calendarcommon2Test.java b/tests/tests/calendarcommon/src/android/calendarcommon2/cts/Calendarcommon2Test.java
new file mode 100644
index 0000000..a17e3b8
--- /dev/null
+++ b/tests/tests/calendarcommon/src/android/calendarcommon2/cts/Calendarcommon2Test.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 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 android.calendarcommon2.cts;
+
+import android.test.InstrumentationCtsTestRunner;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.MediumTest;
+import com.android.calendarcommon2.RecurrenceSet;
+import com.android.calendarcommon2.ICalendar;
+
+import java.util.List;
+
+public class Calendarcommon2Test extends InstrumentationTestCase {
+
+ /**
+ * Test to ensure that com.android.calendarcommon2 is not compiled and
+ * included in the BOOTCLASSPATH. If it is, apps that include (via static
+ * linking) a copy of com.android.calendarcommon2 will be using the copy in
+ * BOOTCLASSPATH instead of the copy that is statically linked.
+ */
+ @MediumTest
+ public void testStaticLinking() {
+ RecurrenceSet recurSet = new RecurrenceSet(null, null, null, null);
+ ICalendar.Component component = new ICalendar.Component("CTS", null);
+ List<ICalendar.Property> properties =
+ component.getProperties(RecurrenceSet.CTS_PROPERTY_NAME);
+ assertTrue(properties == null);
+
+ recurSet.addPropertiesForRuleStr(component, null, null);
+ // The above method should be calling the stub RecurrenceSet built with
+ // this test apk which has the hardcoded behavior of adding a property
+ // with the name CTS_PROPERTY_NAME. The lines below test for that
+ // behavior.
+ properties = component.getProperties(RecurrenceSet.CTS_PROPERTY_NAME);
+ assertTrue(properties.size() == 1);
+ }
+}
diff --git a/tests/tests/calendarcommon/src/com/android/calendarcommon2/EventRecurrence.java b/tests/tests/calendarcommon/src/com/android/calendarcommon2/EventRecurrence.java
new file mode 100644
index 0000000..a90b98b
--- /dev/null
+++ b/tests/tests/calendarcommon/src/com/android/calendarcommon2/EventRecurrence.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 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.calendarcommon2;
+
+/**
+ * Stub version of the EventRecurrence class, containing only the exception
+ * required for the method signature of the constructor in RecurrenceSet.
+ */
+public class EventRecurrence {
+ public static class InvalidFormatException extends RuntimeException {
+ InvalidFormatException(String s) {
+ super(s);
+ }
+ }
+}
diff --git a/tests/tests/calendarcommon/src/com/android/calendarcommon2/ICalendar.java b/tests/tests/calendarcommon/src/com/android/calendarcommon2/ICalendar.java
new file mode 100644
index 0000000..7b5002f
--- /dev/null
+++ b/tests/tests/calendarcommon/src/com/android/calendarcommon2/ICalendar.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 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.calendarcommon2;
+
+import android.util.Log;
+
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.ArrayList;
+
+/**
+ * Stub version of the ICalendar class, containing the subclasses for
+ * Component and Property, for use in the test.
+ */
+public class ICalendar {
+
+ private static final String TAG = "Sync";
+
+ /**
+ * A component within an iCalendar (VEVENT, VTODO, VJOURNAL, VFEEBUSY,
+ * VTIMEZONE, VALARM).
+ */
+ public static class Component {
+ private final String mName;
+ private final LinkedHashMap<String, ArrayList<Property>> mPropsMap =
+ new LinkedHashMap<String, ArrayList<Property>>();
+
+ /**
+ * Creates a new component with the provided name.
+ * @param name The name of the component.
+ */
+ public Component(String name, Component parent) {
+ mName = name;
+ }
+
+ /**
+ * Adds a Property to this component.
+ * @param prop
+ */
+ public void addProperty(Property prop) {
+ String name= prop.getName();
+ ArrayList<Property> props = mPropsMap.get(name);
+ if (props == null) {
+ props = new ArrayList<Property>();
+ mPropsMap.put(name, props);
+ }
+ props.add(prop);
+ }
+
+ /**
+ * Returns a list of properties with the specified name. Returns null
+ * if there are no such properties.
+ * @param name The name of the property that should be returned.
+ * @return A list of properties with the requested name.
+ */
+ public List<Property> getProperties(String name) {
+ return mPropsMap.get(name);
+ }
+ }
+
+ /**
+ * A property within an iCalendar component (e.g., DTSTART, DTEND, etc.,
+ * within a VEVENT).
+ */
+ public static class Property {
+ private final String mName;
+
+ /**
+ * Creates a new property with the provided name.
+ * @param name The name of the property.
+ */
+ public Property(String name) {
+ mName = name;
+ }
+
+ /**
+ * Returns the name of the property.
+ * @return The name of the property.
+ */
+ public String getName() {
+ return mName;
+ }
+ }
+
+ private ICalendar() {
+ }
+}
diff --git a/tests/tests/calendarcommon/src/com/android/calendarcommon2/RecurrenceSet.java b/tests/tests/calendarcommon/src/com/android/calendarcommon2/RecurrenceSet.java
new file mode 100644
index 0000000..ceaef53
--- /dev/null
+++ b/tests/tests/calendarcommon/src/com/android/calendarcommon2/RecurrenceSet.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 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.calendarcommon2;
+
+/**
+ * Stub version of the RecurrenceSet class, containing a method used by
+ * the test to ensure the correct library is being used.
+ */
+public class RecurrenceSet {
+ public final static String CTS_PROPERTY_NAME = "CTS_PROPERTY_NAME";
+
+ public RecurrenceSet(String rruleStr, String rdateStr,
+ String exruleStr, String exdateStr)
+ throws EventRecurrence.InvalidFormatException {
+ }
+
+ public static void addPropertiesForRuleStr(ICalendar.Component component,
+ String propertyName,
+ String ruleStr) {
+ component.addProperty(new ICalendar.Property(CTS_PROPERTY_NAME));
+ }
+}
\ No newline at end of file