188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar/*
288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * Copyright (C) 2015 The Android Open Source Project
388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar *
488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * you may not use this file except in compliance with the License.
688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * You may obtain a copy of the License at
788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar *
888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar *
1088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * Unless required by applicable law or agreed to in writing, software
1188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
1288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * See the License for the specific language governing permissions and
1488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar * limitations under the License.
1588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar */
1688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
1788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarpackage android.databinding.testapp;
1888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
1988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarimport android.databinding.testapp.databinding.NameMappingTestBinding;
2088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarimport android.databinding.testapp.vo.BasicObject;
2188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarimport android.test.UiThreadTest;
2288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarimport android.databinding.testapp.BR;
2388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
2488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarimport java.util.concurrent.atomic.AtomicBoolean;
2588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
2688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyarpublic class NameMappingTest extends BaseDataBinderTest<NameMappingTestBinding> {
2788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
2888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar    public NameMappingTest() {
2988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        super(NameMappingTestBinding.class);
3088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar    }
3188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
3288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar    @UiThreadTest
3388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar    public void testChanges() {
3488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        initBinder();
3588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        final AtomicBoolean f1 = new AtomicBoolean(false);
3688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        final AtomicBoolean f2 = new AtomicBoolean(false);
3788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        BasicObject object = new BasicObject() {
3888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            @Override
3988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            public boolean isThisNameDoesNotMatchAnythingElse1() {
4088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                return f1.get();
4188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            }
4288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
4388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            @Override
4488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            public boolean getThisNameDoesNotMatchAnythingElse2() {
4588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                return f2.get();
4688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            }
4788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        };
4888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        mBinder.setObj(object);
4988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        mBinder.executePendingBindings();
5088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        for (int i = 0; i < 5; i ++) {
5188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            boolean f1New = (i & 1) != 0;
5288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            boolean f2New = (i & 1 << 1) != 0;
5388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            if (f1New != f1.get()) {
5488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                f1.set(f1New);
5588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                object.notifyPropertyChanged(BR.thisNameDoesNotMatchAnythingElse1);
5688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            }
5788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            if (f2New != f2.get()) {
5888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                f1.set(f2New);
5988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar                object.notifyPropertyChanged(BR.thisNameDoesNotMatchAnythingElse2);
6088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            }
6188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            mBinder.executePendingBindings();
6288ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(f2.get(), mBinder.textView.isEnabled());
6388ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(f2.get(), mBinder.textView2.isEnabled());
6488ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(false, mBinder.textView3.isEnabled());
6588ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar
6688ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(f1.get(), mBinder.textView.isFocusable());
6788ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(f1.get(), mBinder.textView2.isFocusable());
6888ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar            assertEquals(false, mBinder.textView3.isFocusable());
6988ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar        }
7088ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar    }
7188ce44ccc65e74a8553244ca246cc9f4c48483e0Yigit Boyar}
72