| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
* Unless required by applicable law or agreed to in writing, software |
| 8 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 |
* See the License for the specific language governing permissions and |
| 11 |
* limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package android.databinding.testapp; |
| 15 |
|
| 16 |
import android.databinding.testapp.databinding.BracketTestBinding; |
| 17 |
|
| 18 |
import android.test.UiThreadTest; |
| 19 |
import android.util.LongSparseArray; |
| 20 |
import android.util.SparseArray; |
| 21 |
import android.util.SparseBooleanArray; |
| 22 |
import android.util.SparseIntArray; |
| 23 |
import android.util.SparseLongArray; |
| 24 |
|
| 25 |
public class BracketTest extends BaseDataBinderTest<BracketTestBinding> { |
| 26 |
private String[] mArray = { |
| 27 |
"Hello World" |
| 28 |
}; |
| 29 |
|
| 30 |
private SparseArray<String> mSparseArray = new SparseArray<>(); |
| 31 |
private SparseIntArray mSparseIntArray = new SparseIntArray(); |
| 32 |
private SparseBooleanArray mSparseBooleanArray = new SparseBooleanArray(); |
| 33 |
private SparseLongArray mSparseLongArray = new SparseLongArray(); |
| 34 |
private LongSparseArray<String> mLongSparseArray = new LongSparseArray<>(); |
| 35 |
|
| 36 |
public BracketTest() { |
| 37 |
super(BracketTestBinding.class); |
| 38 |
mSparseArray.put(0, "Hello"); |
| 39 |
mLongSparseArray.put(0, "World"); |
| 40 |
mSparseIntArray.put(0, 100); |
| 41 |
mSparseBooleanArray.put(0, true); |
| 42 |
mSparseLongArray.put(0, 5); |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
protected void setUp() throws Exception { |
| 47 |
super.setUp(); |
| 48 |
initBinder(new Runnable() { |
| 49 |
@Override |
| 50 |
public void run() { |
| 51 |
mBinder.setArray(mArray); |
| 52 |
mBinder.setSparseArray(mSparseArray); |
| 53 |
mBinder.setSparseIntArray(mSparseIntArray); |
| 54 |
mBinder.setSparseBooleanArray(mSparseBooleanArray); |
| 55 |
mBinder.setSparseLongArray(mSparseLongArray); |
| 56 |
mBinder.setLongSparseArray(mLongSparseArray); |
| 57 |
mBinder.setIndexObj((Integer) 0); |
| 58 |
|
| 59 |
mBinder.executePendingBindings(); |
| 60 |
} |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
@UiThreadTest |
| 65 |
public void testBrackets() { |
| 66 |
assertEquals("Hello World", mBinder.arrayText.getText().toString()); |
| 67 |
assertEquals("Hello", mBinder.sparseArrayText.getText().toString()); |
| 68 |
assertEquals("World", mBinder.longSparseArrayText.getText().toString()); |
| 69 |
assertEquals("100", mBinder.sparseIntArrayText.getText().toString()); |
| 70 |
assertEquals("true", mBinder.sparseBooleanArrayText.getText().toString()); |
| 71 |
assertEquals("5", mBinder.sparseLongArrayText.getText().toString()); |
| 72 |
} |
| 73 |
|
| 74 |
@UiThreadTest |
| 75 |
public void testBracketOutOfBounds() { |
| 76 |
mBinder.setIndex(1); |
| 77 |
mBinder.executePendingBindings(); |
| 78 |
assertEquals("", mBinder.arrayText.getText().toString()); |
| 79 |
assertEquals("", mBinder.sparseArrayText.getText().toString()); |
| 80 |
assertEquals("", mBinder.longSparseArrayText.getText().toString()); |
| 81 |
assertEquals("0", mBinder.sparseIntArrayText.getText().toString()); |
| 82 |
assertEquals("false", mBinder.sparseBooleanArrayText.getText().toString()); |
| 83 |
assertEquals("0", mBinder.sparseLongArrayText.getText().toString()); |
| 84 |
mBinder.setIndex(-1); |
| 85 |
mBinder.executePendingBindings(); |
| 86 |
assertEquals("", mBinder.arrayText.getText().toString()); |
| 87 |
assertEquals("", mBinder.sparseArrayText.getText().toString()); |
| 88 |
assertEquals("", mBinder.longSparseArrayText.getText().toString()); |
| 89 |
assertEquals("0", mBinder.sparseIntArrayText.getText().toString()); |
| 90 |
assertEquals("false", mBinder.sparseBooleanArrayText.getText().toString()); |
| 91 |
assertEquals("0", mBinder.sparseLongArrayText.getText().toString()); |
| 92 |
} |
| 93 |
|
| 94 |
@UiThreadTest |
| 95 |
public void testBracketObj() { |
| 96 |
mBinder.executePendingBindings(); |
| 97 |
assertEquals("Hello World", mBinder.indexObjView.getText().toString()); |
| 98 |
assertEquals("Hello", mBinder.sparseArrayTextObj.getText().toString()); |
| 99 |
} |
| 100 |
|
| 101 |
@UiThreadTest |
| 102 |
public void testBracketMap() throws Throwable { |
| 103 |
assertEquals("", mBinder.bracketMap.getText().toString()); |
| 104 |
} |
| 105 |
} |