Update CTS tests for AnalogClock to add seconds hand
Bug: 177997338
Test: atest
Change-Id: Ib48b03c4dcdb57437fdfdf6906eae9c936ba6d43
Merged-In: Ib48b03c4dcdb57437fdfdf6906eae9c936ba6d43
diff --git a/tests/tests/widget/res/layout/analogclock.xml b/tests/tests/widget/res/layout/analogclock.xml
deleted file mode 100644
index 7d862c3..0000000
--- a/tests/tests/widget/res/layout/analogclock.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<AnalogClock android:id="@+id/clock"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="96dip"
- android:layout_gravity="center_horizontal"
- android:layout_height="wrap_content"/>
diff --git a/tests/tests/widget/res/layout/analogclock_layout.xml b/tests/tests/widget/res/layout/analogclock_layout.xml
new file mode 100644
index 0000000..821c114
--- /dev/null
+++ b/tests/tests/widget/res/layout/analogclock_layout.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2021 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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <AnalogClock
+ android:id="@+id/clock"
+ android:layout_width="60dp"
+ android:layout_height="60dp"/>
+ <AnalogClock
+ android:id="@+id/clock_with_attrs"
+ android:layout_width="60dp"
+ android:layout_height="60dp"
+ android:dial="@drawable/blue_fill"
+ android:hand_hour="@drawable/green_fill"
+ android:hand_minute="@drawable/magenta_fill"
+ android:hand_second="@drawable/yellow_fill"/>
+</LinearLayout>
+
diff --git a/tests/tests/widget/src/android/widget/cts/AnalogClockTest.java b/tests/tests/widget/src/android/widget/cts/AnalogClockTest.java
index a5a4a50..468a632 100644
--- a/tests/tests/widget/src/android/widget/cts/AnalogClockTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AnalogClockTest.java
@@ -17,8 +17,10 @@
package android.widget.cts;
import android.app.Activity;
+import android.graphics.drawable.Icon;
import android.util.AttributeSet;
import android.util.Xml;
+import android.view.View;
import android.widget.AnalogClock;
import androidx.test.filters.SmallTest;
@@ -36,6 +38,8 @@
public class AnalogClockTest {
private AttributeSet mAttrSet;
private Activity mActivity;
+ private AnalogClock mClock;
+ private AnalogClock mClockWithAttrs;
@Rule
public ActivityTestRule<FrameLayoutCtsActivity> mActivityRule =
@@ -44,8 +48,12 @@
@Before
public void setup() throws Exception {
mActivity = mActivityRule.getActivity();
- XmlPullParser parser = mActivity.getResources().getXml(R.layout.analogclock);
+ XmlPullParser parser = mActivity.getResources().getXml(R.layout.analogclock_layout);
mAttrSet = Xml.asAttributeSet(parser);
+
+ View layout = mActivity.getLayoutInflater().inflate(R.layout.analogclock_layout, null);
+ mClock = layout.findViewById(R.id.clock);
+ mClockWithAttrs = layout.findViewById(R.id.clock_with_attrs);
}
@Test
@@ -55,18 +63,67 @@
new AnalogClock(mActivity, mAttrSet, 0);
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void testConstructorWithNullContext1() {
new AnalogClock(null);
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void testConstructorWithNullContext2() {
new AnalogClock(null, null);
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void testConstructorWithNullContext3() {
new AnalogClock(null, null, -1);
}
+
+ @Test
+ public void testSetDial() {
+ Icon icon = Icon.createWithResource(mActivity, R.drawable.magenta_fill);
+ mClock.setDial(icon);
+ mClockWithAttrs.setDial(icon);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSetDialWithNull() {
+ mClock.setDial(null);
+ }
+
+ @Test
+ public void testSetHourHand() {
+ Icon icon = Icon.createWithResource(mActivity, R.drawable.magenta_fill);
+ mClock.setHourHand(icon);
+ mClockWithAttrs.setHourHand(icon);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSetHourHandWithNull() {
+ mClock.setHourHand(null);
+ }
+
+ @Test
+ public void testSetMinuteHand() {
+ Icon icon = Icon.createWithResource(mActivity, R.drawable.magenta_fill);
+ mClock.setMinuteHand(icon);
+ mClockWithAttrs.setMinuteHand(icon);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSetMinuteHandWithNull() {
+ mClock.setMinuteHand(null);
+ }
+
+ @Test
+ public void testSetSecondHand() {
+ Icon icon = Icon.createWithResource(mActivity, R.drawable.magenta_fill);
+ mClock.setSecondHand(icon);
+ mClockWithAttrs.setSecondHand(icon);
+ }
+
+ @Test
+ public void testSetSecondHandWithNull() {
+ mClock.setSecondHand(null);
+ mClockWithAttrs.setSecondHand(null);
+ }
}