17551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar/*
27551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * Copyright (C) 2015 The Android Open Source Project
37551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
47551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * you may not use this file except in compliance with the License.
57551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * You may obtain a copy of the License at
67551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
77551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * Unless required by applicable law or agreed to in writing, software
87551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
97551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * See the License for the specific language governing permissions and
117551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar * limitations under the License.
127551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar */
137551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
14fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.testapp;
157551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
162e2043d30f95585de2069e1cbb23e022ab0e71c4George Mountimport android.databinding.testapp.databinding.LayoutWithIncludeBinding;
1796e1c821dd446d1ed78f8ae61131550588f60a24George Mountimport android.databinding.testapp.databinding.MergeContainingMergeBinding;
1896e1c821dd446d1ed78f8ae61131550588f60a24George Mountimport android.databinding.testapp.databinding.MergeLayoutBinding;
19fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.testapp.vo.NotBindableVo;
207551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
217551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyarimport android.test.UiThreadTest;
225d8732072543d6f6fc1aa8f8a64654bcd1784347George Mountimport android.widget.FrameLayout;
237551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyarimport android.widget.TextView;
247551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
254c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mountpublic class IncludeTagTest extends BaseDataBinderTest<LayoutWithIncludeBinding> {
267551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
277551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar    public IncludeTagTest() {
284c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mount        super(LayoutWithIncludeBinding.class);
297551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar    }
307551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
317551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar    @UiThreadTest
327551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar    public void testIncludeTag() {
333f73e3149732132c02f5d19aab7b5da429794058Yigit Boyar        initBinder();
345d8732072543d6f6fc1aa8f8a64654bcd1784347George Mount        assertNotNull(mBinder.includedPlainLayout);
355d8732072543d6f6fc1aa8f8a64654bcd1784347George Mount        assertTrue(mBinder.includedPlainLayout instanceof FrameLayout);
367551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        NotBindableVo vo = new NotBindableVo(3, "a");
377551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        mBinder.setOuterObject(vo);
384c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mount        mBinder.executePendingBindings();
397551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        final TextView outerText = (TextView) mBinder.getRoot().findViewById(R.id.outerTextView);
407551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        assertEquals("a", outerText.getText());
417551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        final TextView innerText = (TextView) mBinder.getRoot().findViewById(R.id.innerTextView);
427551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        assertEquals("modified 3a", innerText.getText().toString());
4396e1c821dd446d1ed78f8ae61131550588f60a24George Mount        TextView textView1 = (TextView) mBinder.getRoot().findViewById(R.id.innerTextView1);
442ac58b34e5200a34b0ba63884c375a68c9a84303George Mount        assertEquals(mBinder.getRoot(), textView1.getParent().getParent());
4596e1c821dd446d1ed78f8ae61131550588f60a24George Mount        TextView textView2 = (TextView) mBinder.getRoot().findViewById(R.id.innerTextView2);
462ac58b34e5200a34b0ba63884c375a68c9a84303George Mount        assertEquals(mBinder.getRoot(), textView2.getParent().getParent());
4796e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a hello 3a", textView1.getText().toString());
4896e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b hello 3a", textView2.getText().toString());
4996e1c821dd446d1ed78f8ae61131550588f60a24George Mount        MergeLayoutBinding mergeLayoutBinding = mBinder.secondMerge;
5096e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertNotSame(textView1, mergeLayoutBinding.innerTextView1);
5196e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertNotSame(textView2, mergeLayoutBinding.innerTextView2);
5296e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a goodbye 3a", mergeLayoutBinding.innerTextView1.getText().toString());
5396e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b goodbye 3a", mergeLayoutBinding.innerTextView2.getText().toString());
5496e1c821dd446d1ed78f8ae61131550588f60a24George Mount        MergeContainingMergeBinding mergeContainingMergeBinding = mBinder.thirdMerge;
5596e1c821dd446d1ed78f8ae61131550588f60a24George Mount        MergeLayoutBinding merge1 = mergeContainingMergeBinding.merge1;
5696e1c821dd446d1ed78f8ae61131550588f60a24George Mount        MergeLayoutBinding merge2 = mergeContainingMergeBinding.merge2;
5796e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a 1 third 3a", merge1.innerTextView1.getText().toString());
5896e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b 1 third 3a", merge1.innerTextView2.getText().toString());
5996e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a 2 third 3a", merge2.innerTextView1.getText().toString());
6096e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b 2 third 3a", merge2.innerTextView2.getText().toString());
617551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar
627551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        vo.setIntValue(5);
637551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        vo.setStringValue("b");
647551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        mBinder.invalidateAll();
654c5cc009bcbcfb19e33fb19db5ec80f83f7b3326George Mount        mBinder.executePendingBindings();
667551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        assertEquals("b", outerText.getText());
677551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar        assertEquals("modified 5b", innerText.getText().toString());
6896e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a hello 5b", textView1.getText().toString());
6996e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b hello 5b", textView2.getText().toString());
7096e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a goodbye 5b", mergeLayoutBinding.innerTextView1.getText().toString());
7196e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b goodbye 5b", mergeLayoutBinding.innerTextView2.getText().toString());
7296e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a 1 third 5b", merge1.innerTextView1.getText().toString());
7396e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b 1 third 5b", merge1.innerTextView2.getText().toString());
7496e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("a 2 third 5b", merge2.innerTextView1.getText().toString());
7596e1c821dd446d1ed78f8ae61131550588f60a24George Mount        assertEquals("b 2 third 5b", merge2.innerTextView2.getText().toString());
767551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar    }
777551861a29997eac7eaf6318e4d9f1cebd8b81d6Yigit Boyar}
78