The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.widget.cts; |
| 18 | |
Gilles Debunne | 30e770d | 2010-03-23 17:35:00 -0700 | [diff] [blame] | 19 | import com.android.cts.stub.R; |
| 20 | |
| 21 | import dalvik.annotation.TestLevel; |
| 22 | import dalvik.annotation.TestTargetClass; |
| 23 | import dalvik.annotation.TestTargetNew; |
| 24 | import dalvik.annotation.TestTargets; |
| 25 | import dalvik.annotation.ToBeFixed; |
| 26 | |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 27 | import org.xmlpull.v1.XmlPullParser; |
| 28 | |
| 29 | import android.content.Context; |
| 30 | import android.database.DataSetObserver; |
| 31 | import android.graphics.Canvas; |
| 32 | import android.graphics.drawable.BitmapDrawable; |
| 33 | import android.graphics.drawable.Drawable; |
| 34 | import android.os.Parcelable; |
| 35 | import android.test.AndroidTestCase; |
| 36 | import android.util.AttributeSet; |
| 37 | import android.util.Xml; |
| 38 | import android.view.View; |
| 39 | import android.view.ViewGroup; |
| 40 | import android.widget.AdapterView; |
| 41 | import android.widget.ExpandableListAdapter; |
| 42 | import android.widget.ExpandableListView; |
| 43 | import android.widget.ListAdapter; |
| 44 | import android.widget.AdapterView.OnItemClickListener; |
| 45 | import android.widget.ExpandableListView.OnChildClickListener; |
| 46 | import android.widget.ExpandableListView.OnGroupClickListener; |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 47 | |
| 48 | @TestTargetClass(ExpandableListView.class) |
| 49 | public class ExpandableListViewTest extends AndroidTestCase { |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 50 | @TestTargets({ |
| 51 | @TestTargetNew( |
| 52 | level = TestLevel.COMPLETE, |
| 53 | notes = "Test constructor(s) of {@link ExpandableListView}", |
| 54 | method = "ExpandableListView", |
| 55 | args = {android.content.Context.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 56 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 57 | @TestTargetNew( |
| 58 | level = TestLevel.COMPLETE, |
| 59 | notes = "Test constructor(s) of {@link ExpandableListView}", |
| 60 | method = "ExpandableListView", |
| 61 | args = {android.content.Context.class, android.util.AttributeSet.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 62 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 63 | @TestTargetNew( |
| 64 | level = TestLevel.COMPLETE, |
| 65 | notes = "Test constructor(s) of {@link ExpandableListView}", |
| 66 | method = "ExpandableListView", |
| 67 | args = {android.content.Context.class, android.util.AttributeSet.class, int.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 68 | ) |
| 69 | }) |
| 70 | @ToBeFixed(bug = "1417734", explanation = "ExpandableListView#ExpandableListView(Context), " + |
| 71 | "ExpandableListView#ExpandableListView(Context, AttributeSet) and " + |
| 72 | "ExpandableListView#ExpandableListView(Context, AttributeSet, int)" + |
| 73 | " should check whether the input Context is null") |
| 74 | public void testConstructor() { |
| 75 | new ExpandableListView(mContext); |
| 76 | |
| 77 | new ExpandableListView(mContext, null); |
| 78 | |
| 79 | new ExpandableListView(mContext, null, 0); |
| 80 | |
| 81 | XmlPullParser parser = |
| 82 | getContext().getResources().getXml(R.layout.expandablelistview_layout); |
| 83 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 84 | new ExpandableListView(mContext, attrs); |
| 85 | new ExpandableListView(mContext, attrs, 0); |
| 86 | |
| 87 | try { |
| 88 | new ExpandableListView(null); |
| 89 | fail("should throw NullPointerException."); |
| 90 | } catch (NullPointerException e) { |
| 91 | } |
| 92 | |
| 93 | try { |
| 94 | new ExpandableListView(null, null); |
| 95 | fail("should throw NullPointerException."); |
| 96 | } catch (NullPointerException e) { |
| 97 | } |
| 98 | |
| 99 | try { |
| 100 | new ExpandableListView(null, null, 0); |
| 101 | fail("should throw NullPointerException."); |
| 102 | } catch (NullPointerException e) { |
| 103 | } |
| 104 | } |
| 105 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 106 | @TestTargetNew( |
| 107 | level = TestLevel.COMPLETE, |
| 108 | notes = "Test {@link ExpandableListView#setChildDivider(Drawable)}", |
| 109 | method = "setChildDivider", |
| 110 | args = {android.graphics.drawable.Drawable.class} |
| 111 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 112 | @ToBeFixed(bug = "1386429", explanation = "No getter and can't check indirectly") |
| 113 | public void testSetChildDivider() { |
| 114 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 115 | Drawable drawable = mContext.getResources().getDrawable(R.drawable.scenery); |
| 116 | expandableListView.setChildDivider(drawable); |
| 117 | } |
| 118 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 119 | @TestTargetNew( |
| 120 | level = TestLevel.COMPLETE, |
| 121 | method = "setAdapter", |
| 122 | args = {android.widget.ListAdapter.class} |
| 123 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 124 | public void testSetAdapter() { |
| 125 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 126 | try { |
| 127 | expandableListView.setAdapter((ListAdapter) null); |
| 128 | fail("setAdapter(ListAdapter) should throw RuntimeException here."); |
| 129 | } catch (RuntimeException e) { |
| 130 | } |
| 131 | } |
| 132 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 133 | @TestTargetNew( |
| 134 | level = TestLevel.COMPLETE, |
| 135 | notes = "Test {@link ExpandableListView#getAdapter()}", |
| 136 | method = "getAdapter", |
| 137 | args = {} |
| 138 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 139 | public void testGetAdapter() { |
| 140 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 141 | assertNull(expandableListView.getAdapter()); |
| 142 | |
| 143 | ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); |
| 144 | expandableListView.setAdapter(expandableAdapter); |
| 145 | assertNotNull(expandableListView.getAdapter()); |
| 146 | } |
| 147 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 148 | @TestTargets({ |
| 149 | @TestTargetNew( |
| 150 | level = TestLevel.COMPLETE, |
| 151 | method = "setAdapter", |
| 152 | args = {android.widget.ExpandableListAdapter.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 153 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 154 | @TestTargetNew( |
| 155 | level = TestLevel.COMPLETE, |
| 156 | method = "getExpandableListAdapter", |
| 157 | args = {} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 158 | ) |
| 159 | }) |
| 160 | public void testAccessExpandableListAdapter() { |
| 161 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 162 | ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); |
| 163 | |
| 164 | assertNull(expandableListView.getExpandableListAdapter()); |
| 165 | expandableListView.setAdapter(expandableAdapter); |
| 166 | assertSame(expandableAdapter, expandableListView.getExpandableListAdapter()); |
| 167 | } |
| 168 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 169 | @TestTargetNew( |
| 170 | level = TestLevel.COMPLETE, |
| 171 | notes = "Test {@link ExpandableListView#performItemClick(View, int, long)}", |
| 172 | method = "performItemClick", |
| 173 | args = {android.view.View.class, int.class, long.class} |
| 174 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 175 | public void testPerformItemClick() { |
| 176 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 177 | |
| 178 | assertFalse(expandableListView.performItemClick(null, 100, 99)); |
| 179 | |
| 180 | MockOnItemClickListener onClickListener = new MockOnItemClickListener(); |
| 181 | expandableListView.setOnItemClickListener(onClickListener); |
| 182 | assertTrue(expandableListView.performItemClick(null, 100, 99)); |
| 183 | } |
| 184 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 185 | @TestTargetNew( |
| 186 | level = TestLevel.COMPLETE, |
| 187 | notes = "Test {@link ExpandableListView#setOnItemClickListener(OnItemClickListener)}", |
| 188 | method = "setOnItemClickListener", |
| 189 | args = {android.widget.AdapterView.OnItemClickListener.class} |
| 190 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 191 | @ToBeFixed(bug = "1486189", explanation = "It is a redundant override method") |
| 192 | public void testSetOnItemClickListener() { |
| 193 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 194 | MockOnItemClickListener listener = new MockOnItemClickListener(); |
| 195 | |
| 196 | assertNull(expandableListView.getOnItemClickListener()); |
| 197 | expandableListView.setOnItemClickListener(listener); |
| 198 | assertSame(listener, expandableListView.getOnItemClickListener()); |
| 199 | } |
| 200 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 201 | @TestTargets({ |
| 202 | @TestTargetNew( |
| 203 | level = TestLevel.COMPLETE, |
| 204 | method = "expandGroup", |
| 205 | args = {int.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 206 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 207 | @TestTargetNew( |
| 208 | level = TestLevel.COMPLETE, |
| 209 | method = "setOnGroupExpandListener", |
| 210 | args = {android.widget.ExpandableListView.OnGroupExpandListener.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 211 | ) |
| 212 | }) |
| 213 | @ToBeFixed(bug = "1371108", explanation = "unexpected NullPointerException") |
| 214 | public void testExpandGroup() { |
| 215 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 216 | ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); |
| 217 | expandableListView.setAdapter(expandableAdapter); |
| 218 | |
| 219 | MockOnGroupExpandListener mockOnGroupExpandListener = new MockOnGroupExpandListener(); |
| 220 | expandableListView.setOnGroupExpandListener(mockOnGroupExpandListener); |
| 221 | |
| 222 | assertFalse(mockOnGroupExpandListener.hasCalledOnGroupExpand()); |
| 223 | assertTrue(expandableListView.expandGroup(0)); |
| 224 | assertTrue(mockOnGroupExpandListener.hasCalledOnGroupExpand()); |
| 225 | mockOnGroupExpandListener.reset(); |
| 226 | assertFalse(expandableListView.expandGroup(0)); |
| 227 | assertTrue(mockOnGroupExpandListener.hasCalledOnGroupExpand()); |
| 228 | mockOnGroupExpandListener.reset(); |
| 229 | assertTrue(expandableListView.expandGroup(1)); |
| 230 | assertTrue(mockOnGroupExpandListener.hasCalledOnGroupExpand()); |
| 231 | mockOnGroupExpandListener.reset(); |
| 232 | assertFalse(expandableListView.expandGroup(1)); |
| 233 | assertTrue(mockOnGroupExpandListener.hasCalledOnGroupExpand()); |
| 234 | mockOnGroupExpandListener.reset(); |
| 235 | |
| 236 | expandableListView.setAdapter((ExpandableListAdapter) null); |
| 237 | try { |
| 238 | expandableListView.expandGroup(0); |
| 239 | fail("should throw NullPointerException"); |
| 240 | } catch (NullPointerException e) { |
| 241 | } |
| 242 | } |
| 243 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 244 | @TestTargets({ |
| 245 | @TestTargetNew( |
| 246 | level = TestLevel.COMPLETE, |
| 247 | method = "collapseGroup", |
| 248 | args = {int.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 249 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 250 | @TestTargetNew( |
| 251 | level = TestLevel.COMPLETE, |
| 252 | method = "setOnGroupCollapseListener", |
| 253 | args = {android.widget.ExpandableListView.OnGroupCollapseListener.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 254 | ) |
| 255 | }) |
| 256 | @ToBeFixed(bug = "1371108", explanation = "unexpected NullPointerException") |
| 257 | public void testCollapseGroup() { |
| 258 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 259 | ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); |
| 260 | expandableListView.setAdapter(expandableAdapter); |
| 261 | |
| 262 | MockOnGroupCollapseListener mockOnGroupCollapseListener = |
| 263 | new MockOnGroupCollapseListener(); |
| 264 | expandableListView.setOnGroupCollapseListener(mockOnGroupCollapseListener); |
| 265 | |
| 266 | assertFalse(mockOnGroupCollapseListener.hasCalledOnGroupCollapse()); |
| 267 | assertFalse(expandableListView.collapseGroup(0)); |
| 268 | assertTrue(mockOnGroupCollapseListener.hasCalledOnGroupCollapse()); |
| 269 | mockOnGroupCollapseListener.reset(); |
| 270 | |
| 271 | expandableListView.expandGroup(0); |
| 272 | assertTrue(expandableListView.collapseGroup(0)); |
| 273 | assertTrue(mockOnGroupCollapseListener.hasCalledOnGroupCollapse()); |
| 274 | mockOnGroupCollapseListener.reset(); |
| 275 | assertFalse(expandableListView.collapseGroup(1)); |
| 276 | assertTrue(mockOnGroupCollapseListener.hasCalledOnGroupCollapse()); |
| 277 | mockOnGroupCollapseListener.reset(); |
| 278 | |
| 279 | expandableListView.setAdapter((ExpandableListAdapter) null); |
| 280 | try { |
| 281 | expandableListView.collapseGroup(0); |
| 282 | fail("should throw NullPointerException"); |
| 283 | } catch (NullPointerException e) { |
| 284 | } |
| 285 | } |
| 286 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 287 | @TestTargetNew( |
| 288 | level = TestLevel.COMPLETE, |
| 289 | notes = "Test {@link ExpandableListView#setOnGroupClickListener(OnGroupClickListener)}", |
| 290 | method = "setOnGroupClickListener", |
| 291 | args = {android.widget.ExpandableListView.OnGroupClickListener.class} |
| 292 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 293 | public void testSetOnGroupClickListener() { |
| 294 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 295 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 296 | MockOnGroupClickListener listener = new MockOnGroupClickListener(); |
| 297 | |
| 298 | expandableListView.setOnGroupClickListener(listener); |
| 299 | assertFalse(listener.hasCalledOnGroupClick()); |
| 300 | expandableListView.performItemClick(null, 0, 0); |
| 301 | assertTrue(listener.hasCalledOnGroupClick()); |
| 302 | } |
| 303 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 304 | @TestTargetNew( |
| 305 | level = TestLevel.COMPLETE, |
| 306 | notes = "Test {@link ExpandableListView#setOnChildClickListener(OnChildClickListener)}", |
| 307 | method = "setOnChildClickListener", |
| 308 | args = {android.widget.ExpandableListView.OnChildClickListener.class} |
| 309 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 310 | public void testSetOnChildClickListener() { |
| 311 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 312 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 313 | MockOnChildClickListener listener = new MockOnChildClickListener(); |
| 314 | |
| 315 | expandableListView.setOnChildClickListener(listener); |
| 316 | assertFalse(listener.hasCalledOnChildClick()); |
| 317 | // first let the list expand |
| 318 | expandableListView.expandGroup(0); |
| 319 | // click on the child list of the first group |
| 320 | expandableListView.performItemClick(null, 1, 0); |
| 321 | assertTrue(listener.hasCalledOnChildClick()); |
| 322 | } |
| 323 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 324 | @TestTargetNew( |
| 325 | level = TestLevel.COMPLETE, |
| 326 | notes = "Test {@link ExpandableListView#getExpandableListPosition(int)}", |
| 327 | method = "getExpandableListPosition", |
| 328 | args = {int.class} |
| 329 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 330 | public void testGetExpandableListPosition() { |
| 331 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 332 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 333 | |
| 334 | assertEquals(0, expandableListView.getExpandableListPosition(0)); |
Gilles Debunne | 30e770d | 2010-03-23 17:35:00 -0700 | [diff] [blame] | 335 | |
| 336 | // Group 0 is not expanded, position 1 is invalid |
| 337 | assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, |
| 338 | expandableListView.getExpandableListPosition(1)); |
| 339 | |
| 340 | // Position 1 becomes valid when group 0 is expanded |
| 341 | expandableListView.expandGroup(0); |
| 342 | assertEquals(ExpandableListView.getPackedPositionForChild(0, 0), |
| 343 | expandableListView.getExpandableListPosition(1)); |
| 344 | |
| 345 | // Position 2 is still invalid (only one child). |
| 346 | assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, |
| 347 | expandableListView.getExpandableListPosition(2)); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 350 | @TestTargetNew( |
| 351 | level = TestLevel.COMPLETE, |
| 352 | notes = "Test {@link ExpandableListView#getFlatListPosition(long)}", |
| 353 | method = "getFlatListPosition", |
| 354 | args = {long.class} |
| 355 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 356 | @ToBeFixed(bug = "1417734", explanation = "NullPointerException is not expected.") |
| 357 | public void testGetFlatListPosition() { |
| 358 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 359 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 360 | |
| 361 | try { |
| 362 | expandableListView.getFlatListPosition(ExpandableListView.PACKED_POSITION_VALUE_NULL); |
| 363 | } catch (NullPointerException e) { |
| 364 | } |
| 365 | assertEquals(0, expandableListView.getFlatListPosition( |
| 366 | ExpandableListView.PACKED_POSITION_TYPE_CHILD<<32)); |
| 367 | // 0x8000000100000000L means this is a child and group position is 1. |
| 368 | assertEquals(1, expandableListView.getFlatListPosition(0x8000000100000000L)); |
| 369 | } |
| 370 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 371 | @TestTargetNew( |
| 372 | level = TestLevel.COMPLETE, |
| 373 | notes = "Test {@link ExpandableListView#getSelectedPosition()}", |
| 374 | method = "getSelectedPosition", |
| 375 | args = {} |
| 376 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 377 | public void testGetSelectedPosition() { |
| 378 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 379 | |
| 380 | assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, |
| 381 | expandableListView.getSelectedPosition()); |
| 382 | |
| 383 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 384 | |
| 385 | expandableListView.setSelectedGroup(0); |
| 386 | assertEquals(0, expandableListView.getSelectedPosition()); |
| 387 | |
| 388 | expandableListView.setSelectedGroup(1); |
| 389 | assertEquals(0, expandableListView.getSelectedPosition()); |
| 390 | } |
| 391 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 392 | @TestTargetNew( |
| 393 | level = TestLevel.COMPLETE, |
| 394 | notes = "Test {@link ExpandableListView#getSelectedId()}", |
| 395 | method = "getSelectedId", |
| 396 | args = {} |
| 397 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 398 | public void testGetSelectedId() { |
| 399 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 400 | |
| 401 | assertEquals(-1, expandableListView.getSelectedId()); |
| 402 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 403 | |
| 404 | expandableListView.setSelectedGroup(0); |
| 405 | assertEquals(0, expandableListView.getSelectedId()); |
| 406 | |
| 407 | expandableListView.setSelectedGroup(1); |
| 408 | assertEquals(0, expandableListView.getSelectedId()); |
| 409 | } |
| 410 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 411 | @TestTargetNew( |
| 412 | level = TestLevel.COMPLETE, |
| 413 | notes = "Test {@link ExpandableListView#setSelectedGroup(int)}", |
| 414 | method = "setSelectedGroup", |
| 415 | args = {int.class} |
| 416 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 417 | public void testSetSelectedGroup() { |
| 418 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 419 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 420 | |
| 421 | expandableListView.setSelectedGroup(0); |
| 422 | assertEquals(0, expandableListView.getSelectedPosition()); |
| 423 | |
| 424 | expandableListView.setSelectedGroup(1); |
| 425 | assertEquals(0, expandableListView.getSelectedPosition()); |
| 426 | } |
| 427 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 428 | @TestTargetNew( |
| 429 | level = TestLevel.COMPLETE, |
| 430 | notes = "Test {@link ExpandableListView#setSelectedChild(int, int, boolean)}", |
| 431 | method = "setSelectedChild", |
| 432 | args = {int.class, int.class, boolean.class} |
| 433 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 434 | public void testSetSelectedChild() { |
| 435 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 436 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 437 | |
| 438 | assertTrue(expandableListView.setSelectedChild(0, 0, false)); |
| 439 | assertTrue(expandableListView.setSelectedChild(0, 1, true)); |
| 440 | } |
| 441 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 442 | @TestTargetNew( |
| 443 | level = TestLevel.COMPLETE, |
| 444 | notes = "Test {@link ExpandableListView#isGroupExpanded(int)}", |
| 445 | method = "isGroupExpanded", |
| 446 | args = {int.class} |
| 447 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 448 | public void testIsGroupExpanded() { |
| 449 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 450 | expandableListView.setAdapter(new MockExpandableListAdapter()); |
| 451 | |
| 452 | expandableListView.expandGroup(1); |
| 453 | assertFalse(expandableListView.isGroupExpanded(0)); |
| 454 | assertTrue(expandableListView.isGroupExpanded(1)); |
| 455 | } |
| 456 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 457 | @TestTargetNew( |
| 458 | level = TestLevel.COMPLETE, |
| 459 | notes = "Test {@link ExpandableListView#getPackedPositionType(long)}", |
| 460 | method = "getPackedPositionType", |
| 461 | args = {long.class} |
| 462 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 463 | public void testGetPackedPositionType() { |
| 464 | assertEquals(ExpandableListView.PACKED_POSITION_TYPE_NULL, |
| 465 | ExpandableListView.getPackedPositionType( |
| 466 | ExpandableListView.PACKED_POSITION_VALUE_NULL)); |
| 467 | |
| 468 | assertEquals(ExpandableListView.PACKED_POSITION_TYPE_GROUP, |
| 469 | ExpandableListView.getPackedPositionType(0)); |
| 470 | |
| 471 | // 0x8000000000000000L is PACKED_POSITION_MASK_TYPE, but it is private, |
| 472 | // so we just use its value. |
| 473 | assertEquals(ExpandableListView.PACKED_POSITION_TYPE_CHILD, |
| 474 | ExpandableListView.getPackedPositionType(0x8000000000000000L)); |
| 475 | } |
| 476 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 477 | @TestTargetNew( |
| 478 | level = TestLevel.COMPLETE, |
| 479 | notes = "Test {@link ExpandableListView#getPackedPositionGroup(long)}", |
| 480 | method = "getPackedPositionGroup", |
| 481 | args = {long.class} |
| 482 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 483 | public void testGetPackedPositionGroup() { |
| 484 | assertEquals(-1, ExpandableListView.getPackedPositionGroup( |
| 485 | ExpandableListView.PACKED_POSITION_VALUE_NULL)); |
| 486 | |
| 487 | assertEquals(0, ExpandableListView.getPackedPositionGroup(0)); |
| 488 | |
| 489 | // 0x123400000000L means its group position is 0x1234 |
| 490 | assertEquals(0x1234, ExpandableListView.getPackedPositionGroup(0x123400000000L)); |
| 491 | |
| 492 | // 0x7FFFFFFF00000000L means its group position is 0x7FFFFFFF |
| 493 | assertEquals(0x7FFFFFFF, ExpandableListView.getPackedPositionGroup(0x7FFFFFFF00000000L)); |
| 494 | } |
| 495 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 496 | @TestTargetNew( |
| 497 | level = TestLevel.COMPLETE, |
| 498 | notes = "Test {@link ExpandableListView#getPackedPositionChild(long)}", |
| 499 | method = "getPackedPositionChild", |
| 500 | args = {long.class} |
| 501 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 502 | public void testGetPackedPositionChild() { |
| 503 | assertEquals(-1, ExpandableListView.getPackedPositionChild( |
| 504 | ExpandableListView.PACKED_POSITION_VALUE_NULL)); |
| 505 | |
| 506 | assertEquals(-1, ExpandableListView.getPackedPositionChild(1)); |
| 507 | |
| 508 | // 0x8000000000000000L means its child position is 0 |
| 509 | assertEquals(0, ExpandableListView.getPackedPositionChild(0x8000000000000000L)); |
| 510 | |
| 511 | // 0x80000000ffffffffL means its child position is 0xffffffff |
| 512 | assertEquals(0xffffffff, ExpandableListView.getPackedPositionChild(0x80000000ffffffffL)); |
| 513 | } |
| 514 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 515 | @TestTargetNew( |
| 516 | level = TestLevel.COMPLETE, |
| 517 | notes = "Test {@link ExpandableListView#getPackedPositionForChild(int, int)}", |
| 518 | method = "getPackedPositionForChild", |
| 519 | args = {int.class, int.class} |
| 520 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 521 | public void testGetPackedPositionForChild() { |
Gilles Debunne | 30840f2 | 2010-04-06 17:05:21 -0700 | [diff] [blame^] | 522 | assertEquals(0x8000000000000000L, |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 523 | ExpandableListView.getPackedPositionForChild(0, 0)); |
| 524 | |
Gilles Debunne | 30840f2 | 2010-04-06 17:05:21 -0700 | [diff] [blame^] | 525 | assertEquals(0xffffffffffffffffL, |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 526 | ExpandableListView.getPackedPositionForChild(Integer.MAX_VALUE, 0xffffffff)); |
| 527 | } |
| 528 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 529 | @TestTargetNew( |
| 530 | level = TestLevel.COMPLETE, |
| 531 | notes = "Test {@link ExpandableListView#getPackedPositionForGroup(int)}", |
| 532 | method = "getPackedPositionForGroup", |
| 533 | args = {int.class} |
| 534 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 535 | public void testGetPackedPositionForGroup() { |
| 536 | assertEquals(0, ExpandableListView.getPackedPositionForGroup(0)); |
| 537 | |
| 538 | assertEquals(0x7fffffff00000000L, |
| 539 | ExpandableListView.getPackedPositionForGroup(Integer.MAX_VALUE)); |
| 540 | } |
| 541 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 542 | @TestTargetNew( |
| 543 | level = TestLevel.COMPLETE, |
| 544 | notes = "Test {@link ExpandableListView#setChildIndicator(Drawable)}", |
| 545 | method = "setChildIndicator", |
| 546 | args = {android.graphics.drawable.Drawable.class} |
| 547 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 548 | @ToBeFixed(bug = "1386429", explanation = "No getter and can't check indirectly") |
| 549 | public void testSetChildIndicator() { |
| 550 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 551 | expandableListView.setChildIndicator(null); |
| 552 | } |
| 553 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 554 | @TestTargetNew( |
| 555 | level = TestLevel.COMPLETE, |
| 556 | notes = "Test {@link ExpandableListView#setChildIndicatorBounds(int, int)}", |
| 557 | method = "setChildIndicatorBounds", |
| 558 | args = {int.class, int.class} |
| 559 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 560 | @ToBeFixed(bug = "1386429", explanation = "No getter and can't check indirectly") |
| 561 | public void testSetChildIndicatorBounds() { |
| 562 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 563 | expandableListView.setChildIndicatorBounds(10, 10); |
| 564 | } |
| 565 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 566 | @TestTargetNew( |
| 567 | level = TestLevel.COMPLETE, |
| 568 | notes = "Test {@link ExpandableListView#setGroupIndicator(Drawable)}", |
| 569 | method = "setGroupIndicator", |
| 570 | args = {android.graphics.drawable.Drawable.class} |
| 571 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 572 | @ToBeFixed(bug = "1386429", explanation = "No getter and can't check indirectly") |
| 573 | public void testSetGroupIndicator() { |
| 574 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 575 | Drawable drawable = new BitmapDrawable(); |
| 576 | expandableListView.setGroupIndicator(drawable); |
| 577 | } |
| 578 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 579 | @TestTargetNew( |
| 580 | level = TestLevel.COMPLETE, |
| 581 | notes = "Test {@link ExpandableListView#setIndicatorBounds(int, int)}", |
| 582 | method = "setIndicatorBounds", |
| 583 | args = {int.class, int.class} |
| 584 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 585 | @ToBeFixed(bug = "1386429", explanation = "No getter and can't check indirectly") |
| 586 | public void testSetIndicatorBounds() { |
| 587 | ExpandableListView expandableListView = new ExpandableListView(mContext); |
| 588 | expandableListView.setIndicatorBounds(10,10); |
| 589 | } |
| 590 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 591 | @TestTargets({ |
| 592 | @TestTargetNew( |
| 593 | level = TestLevel.COMPLETE, |
| 594 | method = "onSaveInstanceState", |
| 595 | args = {} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 596 | ), |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 597 | @TestTargetNew( |
| 598 | level = TestLevel.COMPLETE, |
| 599 | method = "onRestoreInstanceState", |
| 600 | args = {android.os.Parcelable.class} |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 601 | ) |
| 602 | }) |
| 603 | @ToBeFixed(bug = "", explanation = "can't use SaveState which is package protected") |
| 604 | public void testOnSaveInstanceState() { |
| 605 | ExpandableListView src = new ExpandableListView(mContext); |
| 606 | Parcelable p1 = src.onSaveInstanceState(); |
| 607 | |
| 608 | ExpandableListView dest = new ExpandableListView(mContext); |
| 609 | dest.onRestoreInstanceState(p1); |
| 610 | Parcelable p2 = dest.onSaveInstanceState(); |
| 611 | |
| 612 | assertNotNull(p1); |
| 613 | assertNotNull(p2); |
| 614 | } |
| 615 | |
Scott Su | 54e7e71 | 2009-03-27 18:17:33 -0700 | [diff] [blame] | 616 | @TestTargetNew( |
| 617 | level = TestLevel.COMPLETE, |
| 618 | notes = "Test {@link ExpandableListView#dispatchDraw(Canvas)}", |
| 619 | method = "dispatchDraw", |
| 620 | args = {android.graphics.Canvas.class} |
| 621 | ) |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 622 | public void testDispatchDraw() { |
| 623 | MockExpandableListView expandableListView = new MockExpandableListView(mContext); |
| 624 | expandableListView.dispatchDraw(null); |
| 625 | } |
| 626 | |
| 627 | private class MockExpandableListAdapter implements ExpandableListAdapter { |
| 628 | public void registerDataSetObserver(DataSetObserver observer) { |
| 629 | } |
| 630 | |
| 631 | public void unregisterDataSetObserver(DataSetObserver observer) { |
| 632 | } |
| 633 | |
| 634 | public int getGroupCount() { |
| 635 | return 1; |
| 636 | } |
| 637 | |
| 638 | public int getChildrenCount(int groupPosition) { |
| 639 | switch (groupPosition) { |
| 640 | case 0: |
| 641 | return 1; |
| 642 | default: |
| 643 | return 0; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | public Object getGroup(int groupPosition) { |
| 648 | switch (groupPosition) { |
| 649 | case 0: |
| 650 | return "Data"; |
| 651 | default: |
| 652 | return null; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | public Object getChild(int groupPosition, int childPosition) { |
| 657 | if (groupPosition == 0 && childPosition == 0) |
| 658 | return "child data"; |
| 659 | else |
| 660 | return null; |
| 661 | } |
| 662 | |
| 663 | public long getGroupId(int groupPosition) { |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | public long getChildId(int groupPosition, int childPosition) { |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | public boolean hasStableIds() { |
| 672 | return true; |
| 673 | } |
| 674 | |
| 675 | public View getGroupView(int groupPosition, boolean isExpanded, |
| 676 | View convertView, ViewGroup parent) { |
| 677 | return null; |
| 678 | } |
| 679 | |
| 680 | public View getChildView(int groupPosition, int childPosition, |
| 681 | boolean isLastChild, View convertView, ViewGroup parent) { |
| 682 | return null; |
| 683 | } |
| 684 | |
| 685 | public boolean isChildSelectable(int groupPosition, int childPosition) { |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | public boolean areAllItemsEnabled() { |
| 690 | return true; |
| 691 | } |
| 692 | |
| 693 | public boolean isEmpty() { |
| 694 | return true; |
| 695 | } |
| 696 | |
| 697 | public void onGroupExpanded(int groupPosition) { |
| 698 | } |
| 699 | |
| 700 | public void onGroupCollapsed(int groupPosition) { |
| 701 | } |
| 702 | |
| 703 | public long getCombinedChildId(long groupId, long childId) { |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | public long getCombinedGroupId(long groupId) { |
| 708 | return 0; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | private class MockOnGroupExpandListener implements ExpandableListView.OnGroupExpandListener { |
| 713 | private boolean mCalledOnGroupExpand = false; |
| 714 | |
| 715 | public void onGroupExpand(int groupPosition) { |
| 716 | mCalledOnGroupExpand = true; |
| 717 | } |
| 718 | |
| 719 | public boolean hasCalledOnGroupExpand() { |
| 720 | return mCalledOnGroupExpand; |
| 721 | } |
| 722 | |
| 723 | public void reset() { |
| 724 | mCalledOnGroupExpand = false; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | private class MockOnGroupCollapseListener implements |
| 729 | ExpandableListView.OnGroupCollapseListener { |
| 730 | private boolean mCalledOnGroupCollapse = false; |
| 731 | |
| 732 | public void onGroupCollapse(int groupPosition) { |
| 733 | mCalledOnGroupCollapse = true; |
| 734 | } |
| 735 | |
| 736 | public boolean hasCalledOnGroupCollapse() { |
| 737 | return mCalledOnGroupCollapse; |
| 738 | } |
| 739 | |
| 740 | public void reset() { |
| 741 | mCalledOnGroupCollapse = false; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | private class MockOnItemClickListener implements OnItemClickListener { |
| 746 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | private class MockOnGroupClickListener implements OnGroupClickListener { |
| 751 | private boolean mCalledOnGroupClick = false; |
| 752 | |
| 753 | public boolean onGroupClick(ExpandableListView parent, View v, |
| 754 | int groupPosition, long id) { |
| 755 | mCalledOnGroupClick = true; |
| 756 | return true; |
| 757 | } |
| 758 | |
| 759 | public boolean hasCalledOnGroupClick() { |
| 760 | return mCalledOnGroupClick; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | private class MockOnChildClickListener implements OnChildClickListener { |
| 765 | private boolean mCalledOnChildClick = false; |
| 766 | |
| 767 | public boolean onChildClick(ExpandableListView parent, View v, |
| 768 | int groupPosition, int childPosition, long id) { |
| 769 | mCalledOnChildClick = true; |
| 770 | return true; |
| 771 | } |
| 772 | |
| 773 | public boolean hasCalledOnChildClick() { |
| 774 | return mCalledOnChildClick; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | private class MockExpandableListView extends ExpandableListView { |
| 779 | public MockExpandableListView(Context context) { |
| 780 | super(context); |
| 781 | } |
| 782 | |
| 783 | public MockExpandableListView(Context context, AttributeSet attrs) { |
| 784 | super(context, attrs); |
| 785 | } |
| 786 | |
| 787 | public MockExpandableListView(Context context, AttributeSet attrs, int defStyle) { |
| 788 | super(context, attrs, defStyle); |
| 789 | } |
| 790 | |
Gilles Debunne | 30e770d | 2010-03-23 17:35:00 -0700 | [diff] [blame] | 791 | @Override |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 792 | protected void dispatchDraw(Canvas canvas) { |
| 793 | super.dispatchDraw(canvas); |
| 794 | } |
| 795 | } |
| 796 | } |