AI 147618: CTS: add test cases for android.app.ExpandableListActivity
Automated import of CL 147618
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 0fcd046..b0cc510 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -493,6 +493,14 @@
android:process=":remoteActivity">
</activity>
+ <activity android:name="android.app.cts.ExpandableListTestActivity"
+ android:label="ExpandableListTestActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
</application>
</manifest>
diff --git a/tests/src/android/app/cts/ExpandableListTestActivity.java b/tests/src/android/app/cts/ExpandableListTestActivity.java
new file mode 100644
index 0000000..8c8b65b
--- /dev/null
+++ b/tests/src/android/app/cts/ExpandableListTestActivity.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2008 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.app.cts;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import android.app.ExpandableListActivity;
+import android.os.Bundle;
+import android.os.Looper;
+import android.os.MessageQueue;
+import android.view.ContextMenu;
+import android.view.View;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.widget.ExpandableListAdapter;
+import android.widget.ExpandableListView;
+import android.widget.SimpleExpandableListAdapter;
+
+import com.android.internal.R;
+import com.android.internal.view.menu.ContextMenuBuilder;
+import com.google.android.collect.Lists;
+
+public class ExpandableListTestActivity extends ExpandableListActivity {
+ private static final String NAME = "NAME";
+ private static final String IS_EVEN = "IS_EVEN";
+ private boolean mOnContentChangedCalled = false;
+ private boolean mOnCreateContextMenuCalled = false;
+ private boolean mOnGroupCollapseCalled = false;
+ private boolean mOnGroupExpandCalled = false;
+ private ExpandableListAdapter mAdapter;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final List<Map<String, String>> groupData = Lists.newArrayList();
+ final List<List<Map<String, String>>> childData = Lists.newArrayList();
+ for (int i = 0; i < 20; i++) {
+ final Map<String, String> curGroupMap = new HashMap<String, String>();
+ groupData.add(curGroupMap);
+ curGroupMap.put(NAME, "Group " + i);
+ curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
+
+ final List<Map<String, String>> children = Lists.newArrayList();
+ for (int j = 0; j < 15; j++) {
+ Map<String, String> curChildMap = new HashMap<String, String>();
+ children.add(curChildMap);
+ curChildMap.put(NAME, "Child " + j);
+ curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
+ }
+ childData.add(children);
+ }
+
+ // Set up our adapter
+ mAdapter = new SimpleExpandableListAdapter(this, groupData,
+ R.layout.simple_expandable_list_item_1,
+ new String[] { NAME, IS_EVEN }, new int[] { R.id.text1, R.id.text2 }, childData,
+ R.layout.simple_expandable_list_item_2,
+ new String[] { NAME, IS_EVEN }, new int[] { R.id.text1, R.id.text2 });
+ setListAdapter(mAdapter);
+
+ }
+
+ private int testCallback() {
+ final ExpandableListView v = getExpandableListView();
+ final ExpandableListAdapter a = getExpandableListAdapter();
+ final View convertView = new View(this);
+ final View gv = a.getGroupView(0, true, convertView, v);
+ v.setOnCreateContextMenuListener(this);
+ v.createContextMenu(new ContextMenuBuilder(this));
+ for (int i = 0; i < 20; i++) {
+ v.expandGroup(i);
+ v.performClick();
+ v.performLongClick();
+ for (int k = 0; k < 15; k++) {
+ v.performItemClick(gv, i, k);
+ }
+ v.collapseGroup(i);
+ }
+ if (mOnContentChangedCalled && mOnCreateContextMenuCalled
+ && mOnGroupCollapseCalled && mOnGroupExpandCalled)
+ return RESULT_OK;
+
+ return RESULT_CANCELED;
+ }
+
+ private int testView() {
+ final ExpandableListView currentView = getExpandableListView();
+ for (int i = 0; i < 20; i++) {
+ if (!currentView.expandGroup(i))
+ return RESULT_CANCELED;
+ if (!currentView.collapseGroup(i))
+ return RESULT_CANCELED;
+ }
+ final View otherView = findViewById(android.R.id.list);
+ setContentView(otherView);
+ if (!otherView.equals(getExpandableListView()))
+ return RESULT_CANCELED;
+ setContentView(currentView);
+ return RESULT_OK;
+ }
+
+ private int testSelecte() {
+ final ExpandableListView v = getExpandableListView();
+ for (int i = 0; i < 20; i++) {
+ v.expandGroup(i);
+ setSelectedGroup(i);
+ for (int k = 0; k < 15; k++) {
+ setSelectedChild(i, k, false);
+ if (ExpandableListView.getPackedPositionForChild(i, k) != getSelectedPosition())
+ return RESULT_CANCELED;
+ }
+
+ for (int k = 0; k < 15; k++) {
+ setSelectedChild(i, k, true);
+ if (ExpandableListView.getPackedPositionForChild(i, k) != getSelectedPosition())
+ return RESULT_CANCELED;
+ }
+ v.collapseGroup(i);
+ }
+ return RESULT_OK;
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ final String action = getIntent().getAction();
+ if (LaunchpadActivity.EXPANDLIST_SELECT.equals(action)) {
+ setResult(testSelecte());
+ } else if (LaunchpadActivity.EXPANDLIST_VIEW.equals(action)) {
+ setResult(testView());
+ } else if (LaunchpadActivity.EXPANDLIST_CALLBACK.equals(action)) {
+ setResult(testCallback());
+ }
+ Looper.myQueue().addIdleHandler(new Idler());
+ }
+
+ protected void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ }
+
+ @Override
+ public void onContentChanged() {
+ mOnContentChangedCalled = true;
+ super.onContentChanged();
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenuInfo menuInfo) {
+ mOnCreateContextMenuCalled = true;
+ super.onCreateContextMenu(menu, v, menuInfo);
+ }
+
+ @Override
+ public void onGroupCollapse(int groupPosition) {
+ mOnGroupCollapseCalled = true;
+ super.onGroupCollapse(groupPosition);
+ }
+
+ @Override
+ public void onGroupExpand(int groupPosition) {
+ mOnGroupExpandCalled = true;
+ super.onGroupExpand(groupPosition);
+ }
+
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ }
+
+ protected void onStop() {
+ super.onStop();
+ }
+
+ private class Idler implements MessageQueue.IdleHandler {
+ public final boolean queueIdle() {
+ finish();
+ return false;
+ }
+ }
+
+}
diff --git a/tests/tests/app/src/android/app/cts/ExpandableListActivityTest.java b/tests/tests/app/src/android/app/cts/ExpandableListActivityTest.java
new file mode 100644
index 0000000..0d91df0
--- /dev/null
+++ b/tests/tests/app/src/android/app/cts/ExpandableListActivityTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2008 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.app.cts;
+
+import android.app.ExpandableListActivity;
+import android.content.ComponentName;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+@TestTargetClass(ExpandableListActivity.class)
+public class ExpandableListActivityTest extends ActivityTestsBase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mIntent.putExtra("component", new ComponentName(getContext(),
+ ExpandableListTestActivity.class));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getExpandableListView",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setListAdapter",
+ args = {android.widget.ExpandableListAdapter.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getSelectedPosition",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupExpand",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupCollapse",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setSelectedChild",
+ args = {int.class, int.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setSelectedGroup",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getSelectedId",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "ExpandableListActivity",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getExpandableListAdapter",
+ args = {}
+ )
+ })
+ public void testSelect() {
+ runLaunchpad(LaunchpadActivity.EXPANDLIST_SELECT);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setListAdapter",
+ args = {android.widget.ExpandableListAdapter.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupExpand",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupCollapse",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "ExpandableListActivity",
+ args = {}
+ )
+ })
+ public void testView() {
+ runLaunchpad(LaunchpadActivity.EXPANDLIST_VIEW);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setListAdapter",
+ args = {android.widget.ExpandableListAdapter.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupExpand",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onGroupCollapse",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onCreateContextMenu",
+ args = {android.view.ContextMenu.class, android.view.View.class,
+ android.view.ContextMenu.ContextMenuInfo.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getExpandableListView",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "ExpandableListActivity",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onChildClick",
+ args = {android.widget.ExpandableListView.class, android.view.View.class,
+ int.class, int.class, long.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onContentChanged",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "onRestoreInstanceState",
+ args = {android.os.Bundle.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getExpandableListAdapter",
+ args = {}
+ )
+ })
+ public void testCallback() {
+ runLaunchpad(LaunchpadActivity.EXPANDLIST_CALLBACK);
+ }
+}
\ No newline at end of file