diff options
author | George Mount <mount@google.com> | 2015-09-17 07:42:41 -0700 |
---|---|---|
committer | George Mount <mount@google.com> | 2016-02-23 15:05:20 -0800 |
commit | b7eeedbfadec03792551014e9dfa2bd384fc21a3 (patch) | |
tree | 27a2c93238a1b1f9e83a1b36e47889075aa43cf4 /compilationTests | |
parent | b522c7650bf7d9ec566845bc9eb37e761eea853d (diff) | |
download | data-binding-b7eeedbfadec03792551014e9dfa2bd384fc21a3.tar.gz |
Two-way binding tests
Bug 1474349
Bug 22460238
Tests for two-way data binding can't be checked in until the
SDK becomes public. Also updates the sample application because
it has the same restrictions.
Change-Id: I7e2b2f84943844401d2b8edbac4e60ea9f5704a6
Diffstat (limited to 'compilationTests')
2 files changed, 62 insertions, 8 deletions
diff --git a/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java b/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java index f38dcc4f..3525b3a8 100644 --- a/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java +++ b/compilationTests/src/test/java/android/databinding/compilationTest/SimpleCompilationTest.java @@ -16,13 +16,6 @@ package android.databinding.compilationTest; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.PrefixFileFilter; -import org.apache.commons.io.filefilter.SuffixFileFilter; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; - import android.databinding.tool.processing.ErrorMessages; import android.databinding.tool.processing.ScopedErrorReport; import android.databinding.tool.processing.ScopedException; @@ -30,6 +23,12 @@ import android.databinding.tool.store.Location; import com.google.common.base.Joiner; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.PrefixFileFilter; +import org.apache.commons.io.filefilter.SuffixFileFilter; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -37,7 +36,6 @@ import java.util.Collection; import java.util.List; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -327,4 +325,25 @@ public class SimpleCompilationTest extends BaseCompilationTest { assertEquals("Merge shouldn't support includes as root. Error message was '" + result.error, ErrorMessages.INCLUDE_INSIDE_MERGE, ex.getBareMessage()); } + + @Test + public void testAssignTwoWayEvent() throws Throwable { + prepareProject(); + copyResourceTo("/layout/layout_with_two_way_event_attribute.xml", + "/app/src/main/res/layout/layout_with_two_way_event_attribute.xml"); + CompilationResult result = runGradle("assembleDebug"); + assertNotEquals(0, result.resultCode); + List<ScopedException> errors = ScopedException.extractErrors(result.error); + assertEquals(result.error, 1, errors.size()); + final ScopedException ex = errors.get(0); + final ScopedErrorReport report = ex.getScopedErrorReport(); + final File errorFile = new File(report.getFilePath()); + assertTrue(errorFile.exists()); + assertEquals(new File(testFolder, + "/app/src/main/res/layout/layout_with_two_way_event_attribute.xml") + .getCanonicalFile(), + errorFile.getCanonicalFile()); + assertEquals("The attribute android:textAttrChanged is a two-way binding event attribute " + + "and cannot be assigned.", ex.getBareMessage()); + } } diff --git a/compilationTests/src/test/resources/layout/layout_with_two_way_event_attribute.xml b/compilationTests/src/test/resources/layout/layout_with_two_way_event_attribute.xml new file mode 100644 index 00000000..16536e34 --- /dev/null +++ b/compilationTests/src/test/resources/layout/layout_with_two_way_event_attribute.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<layout xmlns:android="http://schemas.android.com/apk/res/android" +> + <data> + <variable name="myVariable" type="String"/> + <variable name="myEventListener" type="android.databinding.InverseBindingListener"/> + </data> + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <!-- undefined variable --> + <TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/textView" + android:text="@{myVariable}" + android:textAttrChanged="@{myEventListener}"/> + </LinearLayout> +</layout>
\ No newline at end of file |