diff options
-rw-r--r-- | library/build.gradle | 6 | ||||
-rw-r--r-- | library/test/AndroidManifest.xml | 21 | ||||
-rw-r--r-- | library/test/res/layout/test_layout.xml | 27 | ||||
-rw-r--r-- | library/test/res/layout/test_template.xml | 31 | ||||
-rw-r--r-- | library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java | 104 |
5 files changed, 189 insertions, 0 deletions
diff --git a/library/build.gradle b/library/build.gradle index 02173e3..d1a9649 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -30,5 +30,11 @@ android { icsCompat { res.srcDirs = ['res-ics'] } + + androidTest { + manifest.srcFile 'test/AndroidManifest.xml' + java.srcDirs = ['test/src'] + res.srcDirs = ['test/res'] + } } } diff --git a/library/test/AndroidManifest.xml b/library/test/AndroidManifest.xml new file mode 100644 index 0000000..b560357 --- /dev/null +++ b/library/test/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.setupwizardlib.test"> + +</manifest> diff --git a/library/test/res/layout/test_layout.xml b/library/test/res/layout/test_layout.xml new file mode 100644 index 0000000..d2635e7 --- /dev/null +++ b/library/test/res/layout/test_layout.xml @@ -0,0 +1,27 @@ +<!-- + 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. +--> + +<com.android.setupwizardlib.SetupWizardLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:id="@+id/test_content" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + +</com.android.setupwizardlib.SetupWizardLayout>
\ No newline at end of file diff --git a/library/test/res/layout/test_template.xml b/library/test/res/layout/test_template.xml new file mode 100644 index 0000000..968179c --- /dev/null +++ b/library/test/res/layout/test_template.xml @@ -0,0 +1,31 @@ +<!-- + 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. +--> + +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <View + android:id="@+id/test_template_view" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <FrameLayout + android:id="@+id/suw_layout_content" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + +</FrameLayout> diff --git a/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java new file mode 100644 index 0000000..ced07b2 --- /dev/null +++ b/library/test/src/com/android/setupwizardlib/test/SetupWizardLayoutTests.java @@ -0,0 +1,104 @@ +/* + * 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. + */ + +package com.android.setupwizardlib.test; + +import android.annotation.TargetApi; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Build.VERSION_CODES; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import com.android.setupwizardlib.SetupWizardLayout; +import com.android.setupwizardlib.view.NavigationBar; + +public class SetupWizardLayoutTests extends InstrumentationTestCase { + + @SmallTest + public void testDefaultTemplate() { + SetupWizardLayout layout = new SetupWizardLayout(getInstrumentation().getContext()); + assertDefaultTemplateInflated(layout); + } + + @SmallTest + public void testSetHeaderText() { + SetupWizardLayout layout = new SetupWizardLayout(getInstrumentation().getContext()); + TextView title = (TextView) layout.findViewById(R.id.suw_layout_title); + layout.setHeaderText("Abracadabra"); + assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText()); + } + + @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) + @SmallTest + public void testAddView() { + SetupWizardLayout layout = new SetupWizardLayout(getInstrumentation().getContext()); + TextView tv = new TextView(getInstrumentation().getContext()); + int id = View.generateViewId(); + tv.setId(id); + layout.addView(tv); + assertDefaultTemplateInflated(layout); + View view = layout.findViewById(id); + assertSame("The view added should be the same text view", tv, view); + } + + @SmallTest + public void testInflateFromXml() { + LayoutInflater inflater = LayoutInflater.from(getInstrumentation().getContext()); + SetupWizardLayout layout = (SetupWizardLayout) inflater.inflate(R.layout.test_layout, null); + assertDefaultTemplateInflated(layout); + View content = layout.findViewById(R.id.test_content); + assertTrue("@id/test_content should be a TextView", content instanceof TextView); + } + + @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) + @SmallTest + public void testCustomTemplate() { + SetupWizardLayout layout = new SetupWizardLayout(getInstrumentation().getContext(), + R.layout.test_template); + View templateView = layout.findViewById(R.id.test_template_view); + assertNotNull("@id/test_template_view should exist in template", templateView); + + TextView tv = new TextView(getInstrumentation().getContext()); + int id = View.generateViewId(); + tv.setId(id); + layout.addView(tv); + + templateView = layout.findViewById(R.id.test_template_view); + assertNotNull("@id/test_template_view should exist in template", templateView); + View contentView = layout.findViewById(id); + assertSame("The view added should be the same text view", tv, contentView); + + // The following methods should be no-ops because the custom template doesn't contain the + // corresponding optional views. Just check that they don't throw exceptions. + layout.setHeaderText("Abracadabra"); + layout.setIllustration(new ColorDrawable(Color.MAGENTA)); + layout.setLayoutBackground(new ColorDrawable(Color.RED)); + } + + private void assertDefaultTemplateInflated(SetupWizardLayout layout) { + View decorView = layout.findViewById(R.id.suw_layout_decor); + View navbar = layout.findViewById(R.id.suw_layout_navigation_bar); + View title = layout.findViewById(R.id.suw_layout_title); + assertNotNull("@id/suw_layout_decor_view should not be null", decorView); + assertTrue("@id/suw_layout_navigation_bar should be an instance of NavigationBar", + navbar instanceof NavigationBar); + assertNotNull("@id/suw_layout_title should not be null", title); + } +} |