summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-05-22 00:48:46 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-22 00:48:46 +0000
commit8d0e7eb9ea500349f4ddcbfecf02964e29fe9391 (patch)
treecd304cd1e12f45cd6357eee4de2ac48656d183ee /tests
parent4f78475d134afaa40011ab99a6ea8b67b4bfe30c (diff)
parent33370ca96ee94dd38c8102c8f128a972a4919657 (diff)
Merge "passpoint-r2: added the OMA-DM MO and XML lib for the serialization"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java95
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java63
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/MoSerializerTest.java144
3 files changed, 302 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java
new file mode 100644
index 000000000..6fb12d0f2
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/SystemInfoTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2018 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.server.wifi.hotspot2;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import android.content.Context;
+import android.support.test.filters.SmallTest;
+import android.telephony.TelephonyManager;
+
+import com.android.server.wifi.WifiNative;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Unit tests for {@link SystemInfo}.
+ */
+@SmallTest
+public class SystemInfoTest {
+ @Mock Context mContext;
+ @Mock TelephonyManager mTelephonyManager;
+ @Mock WifiNative mWifiNative;
+
+ SystemInfo mSystemInfo;
+ private static final String TEST_MAC = "11:22:33:44:55:66";
+ private static final String TEST_IFACE = "wlan0";
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
+ mSystemInfo = new SystemInfo(mContext, mWifiNative);
+ }
+
+ /**
+ * Verify that IMEI is returned as device ID when it is provided by {@link TelephonyManager}.
+ */
+ @Test
+ public void getDeviceIdWithImei() {
+ String imei = "123456";
+ when(mTelephonyManager.getImei()).thenReturn(imei);
+ assertEquals(imei, mSystemInfo.getDeviceId());
+ }
+
+ /**
+ * Verify that MEID is returned as device ID when it is provided by {@link TelephonyManager}.
+ */
+ @Test
+ public void getDeviceIdWithMeid() {
+ String meid = "098763";
+ when(mTelephonyManager.getImei()).thenReturn(null);
+ when(mTelephonyManager.getMeid()).thenReturn(meid);
+ assertEquals(meid, mSystemInfo.getDeviceId());
+ }
+
+ /**
+ * Verify that {@link SystemInfo#UNKNOWN_INFO} is returned as device ID when both IMEI and
+ * MEID are not provided by {@link TelephonyManager}.
+ */
+ @Test
+ public void getDeviceIdWithoutSim() {
+ when(mTelephonyManager.getImei()).thenReturn(null);
+ when(mTelephonyManager.getMeid()).thenReturn(null);
+ assertEquals(SystemInfo.UNKNOWN_INFO, mSystemInfo.getDeviceId());
+ }
+
+ /**
+ * Verify that mac address is returned successfully.
+ */
+ @Test
+ public void getWifiMacAddress() {
+ when(mWifiNative.getMacAddress(any(String.class))).thenReturn(TEST_MAC);
+ assertEquals(TEST_MAC, mSystemInfo.getMacAddress(TEST_IFACE));
+ }
+}
+
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java
new file mode 100644
index 000000000..d0b93b941
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/DevInfoMoTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2018 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.server.wifi.hotspot2.omadm;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.os.Build;
+import android.support.test.filters.SmallTest;
+
+import com.android.server.wifi.hotspot2.SystemInfo;
+
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link DevInfoMo}.
+ */
+@SmallTest
+public class DevInfoMoTest {
+ private static final String TEST_DEV_ID = "12312341";
+ private static final String TEST_MANUFACTURER = Build.MANUFACTURER;
+ private static final String TEST_MODEL = Build.MODEL;
+ private static final String TEST_LANGUAGE = "en";
+
+ @Test
+ public void serializeDevInfo() {
+ SystemInfo systemInfo = mock(SystemInfo.class);
+ when(systemInfo.getDeviceId()).thenReturn(TEST_DEV_ID);
+ when(systemInfo.getDeviceManufacturer()).thenReturn(TEST_MANUFACTURER);
+ when(systemInfo.getDeviceModel()).thenReturn(TEST_MODEL);
+ when(systemInfo.getLanguage()).thenReturn(TEST_LANGUAGE);
+ String expected = String.format(
+ "<MgmtTree>"
+ + "<VerDTD>%s</VerDTD>"
+ + "<Node><NodeName>DevInfo</NodeName>"
+ + "<RTProperties><Type><DDFName>%s</DDFName></Type></RTProperties></Node>"
+ + "<Node><NodeName>DevID</NodeName><Value>%s</Value></Node>"
+ + "<Node><NodeName>Man</NodeName><Value>%s</Value></Node>"
+ + "<Node><NodeName>Mod</NodeName><Value>%s</Value></Node>"
+ + "<Node><NodeName>DmV</NodeName><Value>%s</Value></Node>"
+ + "<Node><NodeName>Lang</NodeName><Value>%s</Value></Node>"
+ + "</MgmtTree>",
+ MoSerializer.DM_VERSION, DevInfoMo.URN, TEST_DEV_ID, TEST_MANUFACTURER,
+ TEST_MODEL, MoSerializer.DM_VERSION, TEST_LANGUAGE);
+ DevInfoMo mo = new DevInfoMo(systemInfo);
+ assertEquals(expected, mo.serializeToXml());
+ }
+} \ No newline at end of file
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/MoSerializerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/MoSerializerTest.java
new file mode 100644
index 000000000..983976331
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/omadm/MoSerializerTest.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2018 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.server.wifi.hotspot2.omadm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import android.support.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Unit tests for {@link MoSerializer}.
+ */
+@SmallTest
+public class MoSerializerTest {
+ MoSerializer mMoSerializer;
+ Document mDocument;
+ static final String TEST_NODE = "test_node";
+ static final String TEST_VALUE = "test_value";
+ static final String TEST_URN = "urn:oma:mo:oma-dm-devinfo:1.0";
+
+ @Before
+ public void setUp() throws Exception {
+ mMoSerializer = new MoSerializer();
+ mDocument = mMoSerializer.createNewDocument();
+ }
+
+ /**
+ * Verify that the returned element should be valid element.
+ *
+ * Expected output: <MgmtTree></MgmtTree>
+ */
+ @Test
+ public void testShouldReturnValidElementForCreateMgmtTree() {
+ Element element = mMoSerializer.createMgmtTree(mDocument);
+
+ assertEquals(element.getTagName(), MoSerializer.TAG_MGMT_TREE);
+ assertTrue(mDocument.hasChildNodes());
+ }
+
+ /**
+ * Verify that the returned element should be valid element.
+ *
+ * Expected output: <VerDTD>[value]</VerDTD>
+ */
+ @Test
+ public void testShouldReturnValidElementForWriteVersion() {
+ Element element = mMoSerializer.writeVersion(mDocument);
+
+ assertEquals(element.getTagName(), MoSerializer.TAG_VERSION);
+ Node childNode = element.getFirstChild();
+ assertNotNull(childNode);
+ assertEquals(childNode.getNodeValue(), MoSerializer.DM_VERSION);
+ }
+
+ /**
+ * Verify that the returned element should be valid element.
+ *
+ * Expected output: <RTProperties><Type><DDFName>[urn]</DDFName></Type></RTProperites>
+ */
+ @Test
+ public void testShouldReturnValidElementForCreateNodeForUrn() {
+ Element element = mMoSerializer.createNodeForUrn(mDocument, TEST_URN);
+
+ assertEquals(element.getTagName(), MoSerializer.TAG_RTPROPERTIES);
+ assertEquals(element.getChildNodes().getLength(), 1);
+ Node childNode = element.getFirstChild();
+ assertTrue(childNode instanceof Element);
+ assertEquals(((Element)childNode).getTagName(), MoSerializer.TAG_TYPE);
+
+ Node childNode2 = childNode.getFirstChild();
+ assertTrue(childNode2 instanceof Element);
+ assertEquals(((Element)childNode2).getTagName(), MoSerializer.TAG_DDF_NAME);
+ Node textNode = childNode2.getFirstChild();
+ assertNotNull(textNode);
+ assertEquals(textNode.getNodeValue(), TEST_URN);
+ }
+
+ /**
+ * Verify that the returned element should be valid element.
+ *
+ * Expected output: <Node><NodeName>[nodeName]</NodeName></Node>
+ */
+ @Test
+ public void testShouldReturnValidElementForCreateNode() {
+ Element element = mMoSerializer.createNode(mDocument, TEST_NODE);
+
+ assertEquals(element.getTagName(), MoSerializer.TAG_NODE);
+ assertEquals(element.getChildNodes().getLength(), 1);
+ Node childNode = element.getFirstChild();
+ assertTrue(childNode instanceof Element);
+ Node textNode = childNode.getFirstChild();
+ assertNotNull(textNode);
+ assertEquals(textNode.getNodeValue(), TEST_NODE);
+ }
+
+ /**
+ * Verify that the returned element should be valid element.
+ *
+ * Expected output:
+ * <Node><NodeName>[name]</NodeName><Value>[value]</Value></Node>
+ */
+ @Test
+ public void testShouldReturnValidElementForCreateNodeForValue() {
+ Element element = mMoSerializer.createNodeForValue(mDocument, TEST_NODE, TEST_VALUE);
+
+ assertEquals(element.getTagName(), MoSerializer.TAG_NODE);
+ assertEquals(element.getChildNodes().getLength(), 2);
+ List<String> values = Arrays.asList(TEST_NODE, TEST_VALUE);
+ Node childNode;
+ Node textNode;
+ for (String value : values) {
+ childNode = element.getFirstChild();
+ assertTrue(childNode instanceof Element);
+ textNode = childNode.getFirstChild();
+ assertNotNull(textNode);
+ assertEquals(textNode.getNodeValue(), value);
+ element.removeChild(childNode);
+ }
+ }
+}