12feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount/* 22feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * Copyright (C) 2015 The Android Open Source Project 32feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * Licensed under the Apache License, Version 2.0 (the "License"); 42feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * you may not use this file except in compliance with the License. 52feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * You may obtain a copy of the License at 62feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * http://www.apache.org/licenses/LICENSE-2.0 72feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * Unless required by applicable law or agreed to in writing, software 82feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * distributed under the License is distributed on an "AS IS" BASIS, 92feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 102feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * See the License for the specific language governing permissions and 112feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount * limitations under the License. 122feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount */ 132feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 14fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.testapp; 152feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 162e2043d30f95585de2069e1cbb23e022ab0e71c4George Mountimport android.databinding.testapp.databinding.BracketTestBinding; 172feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 182feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.test.UiThreadTest; 192feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.util.LongSparseArray; 202feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.util.SparseArray; 212feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.util.SparseBooleanArray; 222feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.util.SparseIntArray; 232feec49448ca1bb31675b22c25d4ae31961cbbd5George Mountimport android.util.SparseLongArray; 242feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 254c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mountpublic class BracketTest extends BaseDataBinderTest<BracketTestBinding> { 262feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private String[] mArray = { 272feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount "Hello World" 282feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount }; 292feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 302feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private SparseArray<String> mSparseArray = new SparseArray<>(); 312feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private SparseIntArray mSparseIntArray = new SparseIntArray(); 322feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private SparseBooleanArray mSparseBooleanArray = new SparseBooleanArray(); 332feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private SparseLongArray mSparseLongArray = new SparseLongArray(); 342feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount private LongSparseArray<String> mLongSparseArray = new LongSparseArray<>(); 352feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 362feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount public BracketTest() { 374c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mount super(BracketTestBinding.class); 382feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount mSparseArray.put(0, "Hello"); 392feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount mLongSparseArray.put(0, "World"); 402feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount mSparseIntArray.put(0, 100); 412feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount mSparseBooleanArray.put(0, true); 422feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount mSparseLongArray.put(0, 5); 432feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount } 442feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 452feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount @Override 462feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount protected void setUp() throws Exception { 472feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount super.setUp(); 483f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar initBinder(new Runnable() { 493f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar @Override 503f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar public void run() { 513f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setArray(mArray); 523f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setSparseArray(mSparseArray); 533f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setSparseIntArray(mSparseIntArray); 543f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setSparseBooleanArray(mSparseBooleanArray); 553f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setSparseLongArray(mSparseLongArray); 563f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.setLongSparseArray(mLongSparseArray); 5776b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.setIndexObj((Integer) 0); 582feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 593f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar mBinder.executePendingBindings(); 603f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar } 613f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar }); 622feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount } 632feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount 642feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount @UiThreadTest 652feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount public void testBrackets() { 6634a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("Hello World", mBinder.arrayText.getText().toString()); 6734a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("Hello", mBinder.sparseArrayText.getText().toString()); 6834a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("World", mBinder.longSparseArrayText.getText().toString()); 6934a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("100", mBinder.sparseIntArrayText.getText().toString()); 7034a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("true", mBinder.sparseBooleanArrayText.getText().toString()); 7134a18e6a231f3b64726bd93e7e097a0d5a75995dGeorge Mount assertEquals("5", mBinder.sparseLongArrayText.getText().toString()); 722feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount } 73e0d5ed7613cb72192430cd2ed8e4159618ca308eGeorge Mount 74e0d5ed7613cb72192430cd2ed8e4159618ca308eGeorge Mount @UiThreadTest 7576b791f78542a2feb191482a2204de95eaf8ee72George Mount public void testBracketOutOfBounds() { 7676b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.setIndex(1); 7776b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.executePendingBindings(); 7876b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.arrayText.getText().toString()); 7976b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.sparseArrayText.getText().toString()); 8076b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.longSparseArrayText.getText().toString()); 8176b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("0", mBinder.sparseIntArrayText.getText().toString()); 8276b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("false", mBinder.sparseBooleanArrayText.getText().toString()); 8376b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("0", mBinder.sparseLongArrayText.getText().toString()); 8476b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.setIndex(-1); 8576b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.executePendingBindings(); 8676b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.arrayText.getText().toString()); 8776b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.sparseArrayText.getText().toString()); 8876b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("", mBinder.longSparseArrayText.getText().toString()); 8976b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("0", mBinder.sparseIntArrayText.getText().toString()); 9076b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("false", mBinder.sparseBooleanArrayText.getText().toString()); 9176b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("0", mBinder.sparseLongArrayText.getText().toString()); 9276b791f78542a2feb191482a2204de95eaf8ee72George Mount } 9376b791f78542a2feb191482a2204de95eaf8ee72George Mount 9476b791f78542a2feb191482a2204de95eaf8ee72George Mount @UiThreadTest 95e0d5ed7613cb72192430cd2ed8e4159618ca308eGeorge Mount public void testBracketObj() { 9676b791f78542a2feb191482a2204de95eaf8ee72George Mount mBinder.executePendingBindings(); 97b7eeedbfadec03792551014e9dfa2bd384fc21a3George Mount assertEquals("Hello World", mBinder.indexObjView.getText().toString()); 9876b791f78542a2feb191482a2204de95eaf8ee72George Mount assertEquals("Hello", mBinder.sparseArrayTextObj.getText().toString()); 9976b791f78542a2feb191482a2204de95eaf8ee72George Mount } 10076b791f78542a2feb191482a2204de95eaf8ee72George Mount 10176b791f78542a2feb191482a2204de95eaf8ee72George Mount @UiThreadTest 10276b791f78542a2feb191482a2204de95eaf8ee72George Mount public void testBracketMap() throws Throwable { 103e0d5ed7613cb72192430cd2ed8e4159618ca308eGeorge Mount assertEquals("", mBinder.bracketMap.getText().toString()); 104e0d5ed7613cb72192430cd2ed8e4159618ca308eGeorge Mount } 1052feec49448ca1bb31675b22c25d4ae31961cbbd5George Mount} 106