auto import from //branches/cupcake_rel/...@138607
diff --git a/tests/cts/net/Android.mk b/tests/cts/net/Android.mk
new file mode 100644
index 0000000..d1a459f
--- /dev/null
+++ b/tests/cts/net/Android.mk
@@ -0,0 +1,30 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := ctstests_net
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsNetTestCases
+
+LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
+
+include $(BUILD_PACKAGE)
+
diff --git a/tests/cts/net/AndroidManifest.xml b/tests/cts/net/AndroidManifest.xml
new file mode 100644
index 0000000..6c2dfbd
--- /dev/null
+++ b/tests/cts/net/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2007 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.cts.net">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.cts.stub"
+ android:label="CTS tests of android.net"/>
+
+</manifest>
+
diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
new file mode 100644
index 0000000..201105f
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import com.android.internal.telephony.Phone;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkInfo.State;
+import android.test.AndroidTestCase;
+
+@TestTargetClass(ConnectivityManager.class)
+public class ConnectivityManagerTest extends AndroidTestCase {
+
+ private static final int HOST_ADDRESS = 0x7f000001;// represent ip 127.0.0.1
+ private ConnectivityManager mCm;
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mCm = (ConnectivityManager) getContext().getSystemService(
+ Context.CONNECTIVITY_SERVICE);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getNetworkInfo(int networkType).",
+ method = "getNetworkInfo",
+ args = {int.class}
+ )
+ public void testGetNetworkInfo() {
+
+ // this test assumes that there are at least two network types.
+ assertTrue(mCm.getAllNetworkInfo().length >= 2);
+ NetworkInfo ni = mCm.getNetworkInfo(1);
+ State state = ni.getState();
+ assertTrue(State.UNKNOWN.ordinal() >= state.ordinal()
+ && state.ordinal() >= State.CONNECTING.ordinal());
+ DetailedState ds = ni.getDetailedState();
+ assertTrue(DetailedState.FAILED.ordinal() >= ds.ordinal()
+ && ds.ordinal() >= DetailedState.IDLE.ordinal());
+
+ ni = mCm.getNetworkInfo(0);
+ state = ni.getState();
+ assertTrue(State.UNKNOWN.ordinal() >= state.ordinal()
+ && state.ordinal() >= State.CONNECTING.ordinal());
+ ds = ni.getDetailedState();
+ assertTrue(DetailedState.FAILED.ordinal() >= ds.ordinal()
+ && ds.ordinal() >= DetailedState.IDLE.ordinal());
+
+ ni = mCm.getNetworkInfo(-1);
+ assertNull(ni);
+
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test isNetworkTypeValid(int networkType).",
+ method = "isNetworkTypeValid",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test isNetworkTypeValid(int networkType).",
+ method = "getAllNetworkInfo",
+ args = {}
+ )
+ })
+ public void testIsNetworkTypeValid() {
+
+ NetworkInfo[] ni = mCm.getAllNetworkInfo();
+
+ for (NetworkInfo n : ni) {
+ assertTrue(ConnectivityManager.isNetworkTypeValid(n.getType()));
+ }
+ assertFalse(ConnectivityManager.isNetworkTypeValid(-1));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "",
+ method = "getNetworkPreference",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "",
+ method = "setNetworkPreference",
+ args = {int.class}
+ )
+ })
+ public void testAccessNetworkPreference() {
+
+ final int EXPECTED = 1;
+ int per = mCm.getNetworkPreference();
+ mCm.setNetworkPreference(EXPECTED);
+ assertEquals(EXPECTED, mCm.getNetworkPreference());
+
+ mCm.setNetworkPreference(0);
+ assertEquals(0, mCm.getNetworkPreference());
+
+ mCm.setNetworkPreference(-1);
+ assertEquals(0, mCm.getNetworkPreference());
+
+ mCm.setNetworkPreference(2);
+ assertEquals(0, mCm.getNetworkPreference());
+
+ mCm.setNetworkPreference(1);
+
+ assertEquals(1, mCm.getNetworkPreference());
+
+ mCm.setNetworkPreference(per);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getAllNetworkInfo().",
+ method = "getAllNetworkInfo",
+ args = {}
+ )
+ public void testGetAllNetworkInfo() {
+
+ NetworkInfo[] ni = mCm.getAllNetworkInfo();
+ assertEquals(2, ni.length);
+
+ assertTrue(ni[0].getType() >=0 && ni[0].getType() <= 1);
+ assertTrue(ni[1].getType() >=0 && ni[1].getType() <= 1);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test start and stop usingNetworkFeature(int networkType, String feature).",
+ method = "startUsingNetworkFeature",
+ args = {int.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test start and stop usingNetworkFeature(int networkType, String feature).",
+ method = "stopUsingNetworkFeature",
+ args = {int.class, java.lang.String.class}
+ )
+ })
+ public void testStartUsingNetworkFeature() {
+
+ final String invalidateFeature = "invalidateFeature";
+ assertEquals(-1, mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+ invalidateFeature));
+
+ assertEquals(-1, mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+ invalidateFeature));
+
+ assertEquals(-1, mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_WIFI,
+ Phone.FEATURE_ENABLE_MMS));
+ assertEquals(-1, mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_WIFI,
+ Phone.FEATURE_ENABLE_MMS));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test requestRouteToHost(int networkType, int hostAddress).",
+ method = "requestRouteToHost",
+ args = {int.class, int.class}
+ )
+ public void testRequestRouteToHost() {
+
+ NetworkInfo[] ni = mCm.getAllNetworkInfo();
+ for (NetworkInfo n : ni) {
+ assertTrue(mCm.requestRouteToHost(n.getType(), HOST_ADDRESS));
+ }
+
+ assertFalse(mCm.requestRouteToHost(-1, HOST_ADDRESS));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getActiveNetworkInfo().",
+ method = "getActiveNetworkInfo",
+ args = {}
+ )
+ public void testGetActiveNetworkInfo() {
+
+ NetworkInfo ni = mCm.getActiveNetworkInfo();
+ if (ni != null) {
+ assertTrue(ni.getType() >= 0);
+ } else {
+ fail("There is no active network connected, should be at least one kind of network");
+ }
+ }
+
+}
diff --git a/tests/cts/net/src/android/net/cts/CredentialsTest.java b/tests/cts/net/src/android/net/cts/CredentialsTest.java
new file mode 100644
index 0000000..0f6e49e
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/CredentialsTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.Credentials;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(android.net.Credentials.class)
+public class CredentialsTest extends AndroidTestCase {
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor of Credentials, and test getGid, getPid, getUid.",
+ method = "Credentials",
+ args = {int.class, int.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor of Credentials, and test getGid, getPid, getUid.",
+ method = "getGid",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor of Credentials, and test getGid, getPid, getUid.",
+ method = "getPid",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor of Credentials, and test getGid, getPid, getUid.",
+ method = "getUid",
+ args = {}
+ )
+ })
+ public void testCredentials() {
+ // new the Credentials instance
+ // Test with zero inputs
+ Credentials cred = new Credentials(0, 0, 0);
+ assertEquals(0, cred.getGid());
+ assertEquals(0, cred.getPid());
+ assertEquals(0, cred.getUid());
+
+ // Test with big integer
+ cred = new Credentials(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
+ assertEquals(Integer.MAX_VALUE, cred.getGid());
+ assertEquals(Integer.MAX_VALUE, cred.getPid());
+ assertEquals(Integer.MAX_VALUE, cred.getUid());
+
+ // Test with big negative integer
+ cred = new Credentials(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
+ assertEquals(Integer.MIN_VALUE, cred.getGid());
+ assertEquals(Integer.MIN_VALUE, cred.getPid());
+ assertEquals(Integer.MIN_VALUE, cred.getUid());
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/DhcpInfoTest.java b/tests/cts/net/src/android/net/cts/DhcpInfoTest.java
new file mode 100644
index 0000000..657d03c
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/DhcpInfoTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.DhcpInfo;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(DhcpInfo.class)
+public class DhcpInfoTest extends AndroidTestCase {
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DhcpInfo's constructor.",
+ method = "DhcpInfo",
+ args = {}
+ )
+ public void testConstructor() {
+ new DhcpInfo();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test toString function.",
+ method = "toString",
+ args = {}
+ )
+ public void testToString() {
+ String expectedDefault = "ipaddr 0.0.0.0 gateway 0.0.0.0 netmask 0.0.0.0 dns1 0.0.0.0 "
+ + "dns2 0.0.0.0 DHCP server 0.0.0.0 lease 0 seconds";
+ String STR_ADDR1 = "255.255.255.255";
+ String STR_ADDR2 = "127.0.0.1";
+ String STR_ADDR3 = "192.168.1.1";
+ String STR_ADDR4 = "192.168.1.0";
+ int leaseTime = 9999;
+ String expected = "ipaddr " + STR_ADDR1 + " gateway " + STR_ADDR2 + " netmask "
+ + STR_ADDR3 + " dns1 " + STR_ADDR4 + " dns2 " + STR_ADDR4 + " DHCP server "
+ + STR_ADDR2 + " lease " + leaseTime + " seconds";
+
+ DhcpInfo dhcpInfo = new DhcpInfo();
+
+ // Test default string.
+ assertEquals(expectedDefault, dhcpInfo.toString());
+
+ dhcpInfo.ipAddress = ipToInteger(STR_ADDR1);
+ dhcpInfo.gateway = ipToInteger(STR_ADDR2);
+ dhcpInfo.netmask = ipToInteger(STR_ADDR3);
+ dhcpInfo.dns1 = ipToInteger(STR_ADDR4);
+ dhcpInfo.dns2 = ipToInteger(STR_ADDR4);
+ dhcpInfo.serverAddress = ipToInteger(STR_ADDR2);
+ dhcpInfo.leaseDuration = leaseTime;
+
+ // Test with new values
+ assertEquals(expected, dhcpInfo.toString());
+ }
+
+ private int ipToInteger(String ipString) {
+ String ipSegs[] = ipString.split("[.]");
+ int tmp = Integer.parseInt(ipSegs[3]) << 24 | Integer.parseInt(ipSegs[2]) << 16 |
+ Integer.parseInt(ipSegs[1]) << 8 | Integer.parseInt(ipSegs[0]);
+ return tmp;
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/LocalServerSocketTest.java b/tests/cts/net/src/android/net/cts/LocalServerSocketTest.java
new file mode 100644
index 0000000..4fb8481
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/LocalServerSocketTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+package android.net.cts;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import android.net.LocalServerSocket;
+import android.net.LocalSocket;
+import android.net.LocalSocketAddress;
+import android.os.ParcelFileDescriptor;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestStatus;
+import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.ToBeFixed;
+
+@TestTargetClass(LocalServerSocket.class)
+public class LocalServerSocketTest extends AndroidTestCase {
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "test LocalServerSocket",
+ targets = {
+ @TestTarget(
+ methodName = "accept",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "close",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getFileDescriptor",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getLocalSocketAddress",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "LocalServerSocket",
+ methodArgs = {FileDescriptor.class}
+ ),
+ @TestTarget(
+ methodName = "LocalServerSocket",
+ methodArgs = {String.class}
+ )
+ })
+ @ToBeFixed(bug = "1520987", explanation = "Cannot find a proper FileDescriptor for " +
+ "android.net.LocalServerSocket constructor")
+ public void testLocalServerSocket() throws IOException {
+ LocalServerSocket localServerSocket = new LocalServerSocket(LocalSocketTest.mSockAddr);
+ assertNotNull(localServerSocket.getLocalSocketAddress());
+ commonFunctions(localServerSocket);
+
+ Socket socket = new Socket("www.google.com", 80);
+ ParcelFileDescriptor parcelFD = ParcelFileDescriptor.fromSocket(socket);
+ FileDescriptor fd = parcelFD.getFileDescriptor();
+
+ // enable the following after bug 1520987 fixed
+// localServerSocket = new LocalServerSocket(fd);
+// assertNull(localServerSocket.getLocalSocketAddress());
+// commonFunctions(localServerSocket);
+ }
+
+ public void commonFunctions(LocalServerSocket localServerSocket) throws IOException {
+ // create client socket
+ LocalSocket clientSocket = new LocalSocket();
+
+ // establish connection between client and server
+ clientSocket.connect(new LocalSocketAddress(LocalSocketTest.mSockAddr));
+ LocalSocket serverSocket = localServerSocket.accept();
+
+ // send data from client to server
+ OutputStream clientOutStream = clientSocket.getOutputStream();
+ clientOutStream.write(12);
+ InputStream serverInStream = serverSocket.getInputStream();
+ assertEquals(12, serverInStream.read());
+
+ // send data from server to client
+ OutputStream serverOutStream = serverSocket.getOutputStream();
+ serverOutStream.write(3);
+ InputStream clientInStream = clientSocket.getInputStream();
+ assertEquals(3, clientInStream.read());
+
+ // close server socket
+ assertNotNull(localServerSocket.getFileDescriptor());
+ localServerSocket.close();
+ assertNull(localServerSocket.getFileDescriptor());
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/LocalSocketAddressTest.java b/tests/cts/net/src/android/net/cts/LocalSocketAddressTest.java
new file mode 100644
index 0000000..cc3a1d3
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/LocalSocketAddressTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.LocalSocketAddress;
+import android.net.LocalSocketAddress.Namespace;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(LocalSocketAddress.class)
+public class LocalSocketAddressTest extends AndroidTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test LocalSocketAddress",
+ method = "LocalSocketAddress",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test LocalSocketAddress",
+ method = "LocalSocketAddress",
+ args = {java.lang.String.class, android.net.LocalSocketAddress.Namespace.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test LocalSocketAddress",
+ method = "getName",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test LocalSocketAddress",
+ method = "getNamespace",
+ args = {}
+ )
+ })
+ public void testNewLocalSocketAddressWithDefaultNamespace() {
+ // default namespace
+ LocalSocketAddress localSocketAddress = new LocalSocketAddress("name");
+ assertEquals("name", localSocketAddress.getName());
+ assertEquals(Namespace.ABSTRACT, localSocketAddress.getNamespace());
+
+ // specify the namespace
+ LocalSocketAddress localSocketAddress2 = new LocalSocketAddress("name2", Namespace.ABSTRACT);
+ assertEquals("name2", localSocketAddress2.getName());
+ assertEquals(Namespace.ABSTRACT, localSocketAddress2.getNamespace());
+
+ LocalSocketAddress localSocketAddress3 = new LocalSocketAddress("name3", Namespace.FILESYSTEM);
+ assertEquals("name3", localSocketAddress3.getName());
+ assertEquals(Namespace.FILESYSTEM, localSocketAddress3.getNamespace());
+
+ LocalSocketAddress localSocketAddress4 = new LocalSocketAddress("name4", Namespace.RESERVED);
+ assertEquals("name4", localSocketAddress4.getName());
+ assertEquals(Namespace.RESERVED, localSocketAddress4.getNamespace());
+ }
+}
+
diff --git a/tests/cts/net/src/android/net/cts/LocalSocketAddress_NamespaceTest.java b/tests/cts/net/src/android/net/cts/LocalSocketAddress_NamespaceTest.java
new file mode 100644
index 0000000..a9acaa3
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/LocalSocketAddress_NamespaceTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.LocalSocketAddress.Namespace;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(Namespace.class)
+public class LocalSocketAddress_NamespaceTest extends AndroidTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test valueOf(String name).",
+ method = "valueOf",
+ args = {java.lang.String.class}
+ )
+ public void testValueOf() {
+ assertEquals(Namespace.ABSTRACT, Namespace.valueOf("ABSTRACT"));
+ assertEquals(Namespace.RESERVED, Namespace.valueOf("RESERVED"));
+ assertEquals(Namespace.FILESYSTEM, Namespace.valueOf("FILESYSTEM"));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test values().",
+ method = "values",
+ args = {}
+ )
+ public void testValues() {
+ Namespace[] expected = Namespace.values();
+ assertEquals(Namespace.ABSTRACT, expected[0]);
+ assertEquals(Namespace.RESERVED, expected[1]);
+ assertEquals(Namespace.FILESYSTEM, expected[2]);
+ }
+}
+
diff --git a/tests/cts/net/src/android/net/cts/LocalSocketTest.java b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
new file mode 100644
index 0000000..ae0b51c
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
@@ -0,0 +1,342 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import android.net.Credentials;
+import android.net.LocalServerSocket;
+import android.net.LocalSocket;
+import android.net.LocalSocketAddress;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(LocalSocket.class)
+public class LocalSocketTest extends AndroidTestCase{
+ public final static String mSockAddr = "com.android.net.LocalSocketTest";
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "LocalSocket",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "close",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "connect",
+ args = {android.net.LocalSocketAddress.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "getAncillaryFileDescriptors",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "getFileDescriptor",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "getInputStream",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "getOutputStream",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "getPeerCredentials",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "isConnected",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "setFileDescriptorsForSend",
+ args = {java.io.FileDescriptor[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "shutdownInput",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test core functions of LocalSocket",
+ method = "shutdownOutput",
+ args = {}
+ )
+ })
+ public void testLocalConnections() throws IOException{
+ // create client and server socket
+ LocalServerSocket localServerSocket = new LocalServerSocket(mSockAddr);
+ LocalSocket clientSocket = new LocalSocket();
+
+ // establish connection between client and server
+ LocalSocketAddress locSockAddr = new LocalSocketAddress(mSockAddr);
+ assertFalse(clientSocket.isConnected());
+ clientSocket.connect(locSockAddr);
+ assertTrue(clientSocket.isConnected());
+ LocalSocket serverSocket = localServerSocket.accept();
+
+ Credentials credent = clientSocket.getPeerCredentials();
+ assertTrue(0 != credent.getPid());
+
+ // send data from client to server
+ OutputStream clientOutStream = clientSocket.getOutputStream();
+ clientOutStream.write(12);
+ InputStream serverInStream = serverSocket.getInputStream();
+ assertEquals(12, serverInStream.read());
+
+ //send data from server to client
+ OutputStream serverOutStream = serverSocket.getOutputStream();
+ serverOutStream.write(3);
+ InputStream clientInStream = clientSocket.getInputStream();
+ assertEquals(3, clientInStream.read());
+
+ // Test sending and receiving file descriptors
+ clientSocket.setFileDescriptorsForSend(new FileDescriptor[]{FileDescriptor.in});
+ clientOutStream.write(32);
+ assertEquals(32, serverInStream.read());
+
+ FileDescriptor[] out = serverSocket.getAncillaryFileDescriptors();
+ assertEquals(1, out.length);
+ FileDescriptor fd = clientSocket.getFileDescriptor();
+ assertTrue(fd.valid());
+
+ //shutdown input stream of client
+ clientSocket.shutdownInput();
+ assertEquals(-1, clientInStream.read());
+
+ //shutdown output stream of client
+ clientSocket.shutdownOutput();
+ try {
+ clientOutStream.write(10);
+ fail("testLocalSocket shouldn't come to here");
+ } catch (IOException e) {
+ // expected
+ }
+
+ //shutdown input stream of server
+ serverSocket.shutdownInput();
+ assertEquals(-1, serverInStream.read());
+
+ //shutdown output stream of server
+ serverSocket.shutdownOutput();
+ try {
+ serverOutStream.write(10);
+ fail("testLocalSocket shouldn't come to here");
+ } catch (IOException e) {
+ // expected
+ }
+
+ //close client socket
+ clientSocket.close();
+ try {
+ clientInStream.read();
+ fail("testLocalSocket shouldn't come to here");
+ } catch (IOException e) {
+ // expected
+ }
+
+ //close server socket
+ serverSocket.close();
+ try {
+ serverInStream.read();
+ fail("testLocalSocket shouldn't come to here");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "bind",
+ args = {android.net.LocalSocketAddress.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "connect",
+ args = {android.net.LocalSocketAddress.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "getLocalSocketAddress",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "getReceiveBufferSize",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "getRemoteSocketAddress",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "getSendBufferSize",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "getSoTimeout",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "isBound",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "isClosed",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "isInputShutdown",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "isOutputShutdown",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "setReceiveBufferSize",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "setSendBufferSize",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "setSoTimeout",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "test secondary functions of LocalSocket",
+ method = "toString",
+ args = {}
+ )
+ })
+ public void testAccessors() throws IOException{
+ LocalSocket socket = new LocalSocket();
+ LocalSocketAddress addr = new LocalSocketAddress("secondary");
+
+ assertFalse(socket.isBound());
+ socket.bind(addr);
+ assertTrue(socket.isBound());
+ assertEquals(addr, socket.getLocalSocketAddress());
+
+ String str = socket.toString();
+ assertTrue(str.contains("impl:android.net.LocalSocketImpl"));
+
+ socket.setReceiveBufferSize(1999);
+ assertEquals(1999 << 1, socket.getReceiveBufferSize());
+
+ socket.setSendBufferSize(1998);
+ assertEquals(1998 << 1, socket.getSendBufferSize());
+
+ // Timeout is not support at present, so set is ignored
+ socket.setSoTimeout(1996);
+ assertEquals(0, socket.getSoTimeout());
+
+ try {
+ socket.getRemoteSocketAddress();
+ fail("testLocalSocketSecondary shouldn't come to here");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ socket.isClosed();
+ fail("testLocalSocketSecondary shouldn't come to here");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ socket.isInputShutdown();
+ fail("testLocalSocketSecondary shouldn't come to here");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ socket.isOutputShutdown();
+ fail("testLocalSocketSecondary shouldn't come to here");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ socket.connect(addr, 2005);
+ fail("testLocalSocketSecondary shouldn't come to here");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/MailToTest.java b/tests/cts/net/src/android/net/cts/MailToTest.java
new file mode 100644
index 0000000..e419272
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/MailToTest.java
@@ -0,0 +1,167 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.MailTo;
+import android.test.AndroidTestCase;
+import android.util.Log;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(MailTo.class)
+public class MailToTest extends AndroidTestCase {
+ private static final String MAILTOURI_1 = "mailto:chris@example.com";
+ private static final String MAILTOURI_2 = "mailto:infobot@example.com?subject=current-issue";
+ private static final String MAILTOURI_3 = "mailto:infobot@example.com?body=send%20current-issue";
+ private static final String MAILTOURI_4 = "mailto:infobot@example.com?body=send%20current-" +
+ "issue%0D%0Asend%20index";
+ private static final String MAILTOURI_5 = "mailto:joe@example.com?" +
+ "cc=bob@example.com&body=hello";
+ private static final String MAILTOURI_6 = "mailto:?to=joe@example.com&" +
+ "cc=bob@example.com&body=hello";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "parse",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "isMailTo",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "getTo",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "getSubject",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "getBody",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "getCc",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "toString",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test parse mailto URI.",
+ method = "getHeaders",
+ args = {}
+ )
+ })
+ public void testParseMailToURI() {
+ assertFalse(MailTo.isMailTo(null));
+ assertFalse(MailTo.isMailTo(""));
+ assertFalse(MailTo.isMailTo("http://www.google.com"));
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_1));
+ MailTo mailTo_1 = MailTo.parse(MAILTOURI_1);
+ Log.d("Trace", mailTo_1.toString());
+ assertEquals("chris@example.com", mailTo_1.getTo());
+ assertEquals(1, mailTo_1.getHeaders().size());
+ assertNull(mailTo_1.getBody());
+ assertNull(mailTo_1.getCc());
+ assertNull(mailTo_1.getSubject());
+ assertEquals("mailto:?to=chris%40example.com&", mailTo_1.toString());
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_2));
+ MailTo mailTo_2 = MailTo.parse(MAILTOURI_2);
+ Log.d("Trace", mailTo_2.toString());
+ assertEquals(2, mailTo_2.getHeaders().size());
+ assertEquals("infobot@example.com", mailTo_2.getTo());
+ assertEquals("current-issue", mailTo_2.getSubject());
+ assertNull(mailTo_2.getBody());
+ assertNull(mailTo_2.getCc());
+ assertEquals("mailto:?to=infobot%40example.com&subject=current-issue&",
+ mailTo_2.toString());
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_3));
+ MailTo mailTo_3 = MailTo.parse(MAILTOURI_3);
+ Log.d("Trace", mailTo_3.toString());
+ assertEquals(2, mailTo_3.getHeaders().size());
+ assertEquals("infobot@example.com", mailTo_3.getTo());
+ assertEquals("send current-issue", mailTo_3.getBody());
+ assertNull(mailTo_3.getCc());
+ assertNull(mailTo_3.getSubject());
+ assertEquals("mailto:?body=send%20current-issue&to=infobot%40example.com&",
+ mailTo_3.toString());
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_4));
+ MailTo mailTo_4 = MailTo.parse(MAILTOURI_4);
+ Log.d("Trace", mailTo_4.toString() + " " + mailTo_4.getBody());
+ assertEquals(2, mailTo_4.getHeaders().size());
+ assertEquals("infobot@example.com", mailTo_4.getTo());
+ assertEquals("send current-issue\r\nsend index", mailTo_4.getBody());
+ assertNull(mailTo_4.getCc());
+ assertNull(mailTo_4.getSubject());
+ assertEquals("mailto:?body=send%20current-issue%0D%0Asend%20index&to=infobot%40example.com&",
+ mailTo_4.toString());
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_5));
+ MailTo mailTo_5 = MailTo.parse(MAILTOURI_5);
+ Log.d("Trace", mailTo_5.toString() + mailTo_5.getHeaders().toString()
+ + mailTo_5.getHeaders().size());
+ assertEquals(3, mailTo_5.getHeaders().size());
+ assertEquals("joe@example.com", mailTo_5.getTo());
+ assertEquals("bob@example.com", mailTo_5.getCc());
+ assertEquals("hello", mailTo_5.getBody());
+ assertNull(mailTo_5.getSubject());
+ assertEquals("mailto:?cc=bob%40example.com&body=hello&to=joe%40example.com&",
+ mailTo_5.toString());
+
+ assertTrue(MailTo.isMailTo(MAILTOURI_6));
+ MailTo mailTo_6 = MailTo.parse(MAILTOURI_6);
+ Log.d("Trace", mailTo_6.toString() + mailTo_6.getHeaders().toString()
+ + mailTo_6.getHeaders().size());
+ assertEquals(3, mailTo_6.getHeaders().size());
+ assertEquals(", joe@example.com", mailTo_6.getTo());
+ assertEquals("bob@example.com", mailTo_6.getCc());
+ assertEquals("hello", mailTo_6.getBody());
+ assertNull(mailTo_6.getSubject());
+ assertEquals("mailto:?cc=bob%40example.com&body=hello&to=%2C%20joe%40example.com&",
+ mailTo_6.toString());
+ }
+}
+
diff --git a/tests/cts/net/src/android/net/cts/NetworkInfoTest.java b/tests/cts/net/src/android/net/cts/NetworkInfoTest.java
new file mode 100644
index 0000000..248ef9a
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/NetworkInfoTest.java
@@ -0,0 +1,171 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkInfo.State;
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestStatus;
+import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(NetworkInfo.class)
+public class NetworkInfoTest extends AndroidTestCase {
+ ConnectivityManager mConnectivityManager;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mConnectivityManager = (ConnectivityManager) mContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test isConnectedOrConnecting().",
+ targets = {
+ @TestTarget(
+ methodName = "isConnectedOrConnecting",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "setFailover",
+ methodArgs = {boolean.class}
+ ),
+ @TestTarget(
+ methodName = "isFailover",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getType",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getTypeName",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "setIsAvailable",
+ methodArgs = {boolean.class}
+ ),
+ @TestTarget(
+ methodName = "isAvailable",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "isConnected",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "describeContents",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getDetailedState",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getState",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getReason",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getExtraInfo",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "toString",
+ methodArgs = {}
+ )
+ })
+ public void testAccessNetworkInfoProperties() {
+ NetworkInfo[] ni = mConnectivityManager.getAllNetworkInfo();
+ assertTrue(ni.length >= 2);
+ assertFalse(ni[ConnectivityManager.TYPE_MOBILE].isFailover());
+ assertFalse(ni[ConnectivityManager.TYPE_WIFI].isFailover());
+
+ // test environment:connect as TYPE_MOBILE, and connect to internet.
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getType(),
+ ConnectivityManager.TYPE_MOBILE);
+ assertEquals(ni[ConnectivityManager.TYPE_WIFI].getType(),
+ ConnectivityManager.TYPE_WIFI);
+ assertEquals("MOBILE",ni[ConnectivityManager.TYPE_MOBILE].getTypeName());
+ assertEquals("WIFI",ni[ConnectivityManager.TYPE_WIFI].getTypeName());
+ assertTrue(ni[ConnectivityManager.TYPE_MOBILE]
+ .isConnectedOrConnecting());
+ assertFalse(ni[ConnectivityManager.TYPE_WIFI].isConnectedOrConnecting());
+ assertTrue(ni[ConnectivityManager.TYPE_MOBILE].isAvailable());
+ assertFalse(ni[ConnectivityManager.TYPE_WIFI].isAvailable());
+ assertTrue(ni[ConnectivityManager.TYPE_MOBILE].isConnected());
+ assertFalse(ni[ConnectivityManager.TYPE_WIFI].isConnected());
+
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].describeContents(), 0);
+ assertEquals(ni[ConnectivityManager.TYPE_WIFI].describeContents(), 0);
+
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getState(),
+ State.CONNECTED);
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getDetailedState(),
+ DetailedState.CONNECTED);
+
+ assertNull(ni[ConnectivityManager.TYPE_MOBILE].getReason());
+ assertNull(ni[ConnectivityManager.TYPE_WIFI].getReason());
+ assertEquals("internet",ni[ConnectivityManager.TYPE_MOBILE].getExtraInfo());
+ assertNull(ni[ConnectivityManager.TYPE_WIFI].getExtraInfo());
+
+ assertNotNull(ni[ConnectivityManager.TYPE_MOBILE].toString());
+ assertNotNull(ni[ConnectivityManager.TYPE_WIFI].toString());
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test writeToParcel(Parcel dest, int flags).",
+ targets = {
+ @TestTarget(
+ methodName = "writeToParcel",
+ methodArgs = {Parcel.class, Integer.class}
+ )
+ })
+ public void testWriteToParcel() {
+ NetworkInfo[] ni = mConnectivityManager.getAllNetworkInfo();
+ Parcel p = Parcel.obtain();
+ ni[ConnectivityManager.TYPE_MOBILE].writeToParcel(p, 1);
+ p.setDataPosition(0);
+ NetworkInfo mNetworkInfo = NetworkInfo.CREATOR.createFromParcel(p);
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getExtraInfo(),
+ mNetworkInfo.getExtraInfo());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getReason(),
+ mNetworkInfo.getReason());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getType(),
+ mNetworkInfo.getType());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getState(),
+ mNetworkInfo.getState());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].getDetailedState(),
+ mNetworkInfo.getDetailedState());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].isAvailable(),
+ mNetworkInfo.isAvailable());
+ assertEquals(ni[ConnectivityManager.TYPE_MOBILE].isFailover(),
+ mNetworkInfo.isFailover());
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/NetworkInfo_DetailedStateTest.java b/tests/cts/net/src/android/net/cts/NetworkInfo_DetailedStateTest.java
new file mode 100644
index 0000000..6459724
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/NetworkInfo_DetailedStateTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.net.NetworkInfo.DetailedState;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestStatus;
+import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(DetailedState.class)
+public class NetworkInfo_DetailedStateTest extends AndroidTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test valueOf(String name).",
+ targets = {
+ @TestTarget(
+ methodName = "valueOf",
+ methodArgs = {String.class}
+ )
+ })
+ public void testValueOf() {
+ assertEquals(DetailedState.AUTHENTICATING, DetailedState
+ .valueOf("AUTHENTICATING"));
+ assertEquals(DetailedState.CONNECTED, DetailedState
+ .valueOf("CONNECTED"));
+ assertEquals(DetailedState.CONNECTING, DetailedState
+ .valueOf("CONNECTING"));
+ assertEquals(DetailedState.DISCONNECTED, DetailedState
+ .valueOf("DISCONNECTED"));
+ assertEquals(DetailedState.DISCONNECTING, DetailedState
+ .valueOf("DISCONNECTING"));
+ assertEquals(DetailedState.FAILED, DetailedState.valueOf("FAILED"));
+ assertEquals(DetailedState.IDLE, DetailedState.valueOf("IDLE"));
+ assertEquals(DetailedState.OBTAINING_IPADDR, DetailedState
+ .valueOf("OBTAINING_IPADDR"));
+ assertEquals(DetailedState.SCANNING, DetailedState.valueOf("SCANNING"));
+ assertEquals(DetailedState.SUSPENDED, DetailedState
+ .valueOf("SUSPENDED"));
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test values().",
+ targets = {
+ @TestTarget(
+ methodName = "values",
+ methodArgs = {}
+ )
+ })
+ public void testValues() {
+ DetailedState[] expected = DetailedState.values();
+ assertEquals(10, expected.length);
+ assertEquals(DetailedState.IDLE, expected[0]);
+ assertEquals(DetailedState.SCANNING, expected[1]);
+ assertEquals(DetailedState.CONNECTING, expected[2]);
+ assertEquals(DetailedState.AUTHENTICATING, expected[3]);
+ assertEquals(DetailedState.OBTAINING_IPADDR, expected[4]);
+ assertEquals(DetailedState.CONNECTED, expected[5]);
+ assertEquals(DetailedState.SUSPENDED, expected[6]);
+ assertEquals(DetailedState.DISCONNECTING, expected[7]);
+ assertEquals(DetailedState.DISCONNECTED, expected[8]);
+ assertEquals(DetailedState.FAILED, expected[9]);
+ }
+
+}
diff --git a/tests/cts/net/src/android/net/cts/NetworkInfo_StateTest.java b/tests/cts/net/src/android/net/cts/NetworkInfo_StateTest.java
new file mode 100644
index 0000000..b03c3f0
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/NetworkInfo_StateTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestStatus;
+import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+import android.net.NetworkInfo.State;
+
+@TestTargetClass(State.class)
+public class NetworkInfo_StateTest extends AndroidTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test valueOf(String name).",
+ targets = {
+ @TestTarget(
+ methodName = "valueOf",
+ methodArgs = {String.class}
+ )
+ })
+ public void testValueOf() {
+ assertEquals(State.CONNECTED, State.valueOf("CONNECTED"));
+ assertEquals(State.CONNECTING, State.valueOf("CONNECTING"));
+ assertEquals(State.DISCONNECTED, State.valueOf("DISCONNECTED"));
+ assertEquals(State.DISCONNECTING, State.valueOf("DISCONNECTING"));
+ assertEquals(State.SUSPENDED, State.valueOf("SUSPENDED"));
+ assertEquals(State.UNKNOWN, State.valueOf("UNKNOWN"));
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test values().",
+ targets = {
+ @TestTarget(
+ methodName = "values",
+ methodArgs = {}
+ )
+ })
+ public void testValues() {
+ State[] expected = State.values();
+ assertEquals(6, expected.length);
+ assertEquals(State.CONNECTING, expected[0]);
+ assertEquals(State.CONNECTED, expected[1]);
+ assertEquals(State.SUSPENDED, expected[2]);
+ assertEquals(State.DISCONNECTING, expected[3]);
+ assertEquals(State.DISCONNECTED, expected[4]);
+ assertEquals(State.UNKNOWN, expected[5]);
+ }
+
+}
diff --git a/tests/cts/net/src/android/net/cts/ProxyTest.java b/tests/cts/net/src/android/net/cts/ProxyTest.java
new file mode 100644
index 0000000..d9f7c1a
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/ProxyTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import android.content.Context;
+import android.net.Proxy;
+import android.provider.Settings;
+import android.test.AndroidTestCase;
+import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestStatus;
+import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+
+@TestTargetClass(Proxy.class)
+public class ProxyTest extends AndroidTestCase {
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test constructor(s) of Proxy.",
+ targets = {
+ @TestTarget(
+ methodName = "Proxy",
+ methodArgs = {}
+ )
+ })
+ public void testConstructor() {
+
+ try {
+ Proxy proxy = new Proxy();
+ } catch (Exception e) {
+ fail("shouldn't throw exception");
+ }
+ }
+
+ @TestInfo(
+ status = TestStatus.TBR,
+ notes = "Test getDefaultPort().",
+ targets = {
+ @TestTarget(
+ methodName = "getDefaultPort",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getDefaultHost",
+ methodArgs = {}
+ ),
+ @TestTarget(
+ methodName = "getHost",
+ methodArgs = {Context.class}
+ ),
+ @TestTarget(
+ methodName = "getHost",
+ methodArgs = {Context.class}
+ ),
+ @TestTarget(
+ methodName = "getPort",
+ methodArgs = {Context.class}
+ )
+ })
+ public void testAccessProperties() {
+ String mHost = "www.google.com";
+ int mPort = 8080;
+ String mHttpProxy = mHost + ":" + mPort;
+
+ Settings.System.putString(mContext.getContentResolver(),
+ Settings.System.HTTP_PROXY, null);
+ assertNull(Proxy.getHost(mContext));
+ assertEquals(-1,Proxy.getPort(mContext));
+
+ Settings.System.putString(mContext.getContentResolver(),
+ Settings.System.HTTP_PROXY, mHttpProxy);
+ assertEquals(mHost,Proxy.getHost(mContext));
+ assertEquals(mPort,Proxy.getPort(mContext));
+ }
+
+}
+
diff --git a/tests/cts/net/src/android/net/cts/UriTest.java b/tests/cts/net/src/android/net/cts/UriTest.java
new file mode 100644
index 0000000..84b58c0
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/UriTest.java
@@ -0,0 +1,727 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import android.content.ContentUris;
+import android.net.Uri;
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+import java.io.File;
+import java.util.Arrays;
+
+@TestTargetClass(Uri.class)
+public class UriTest extends AndroidTestCase {
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test write to and read frome parcel.",
+ method = "writeToParcel",
+ args = {android.os.Parcel.class, android.net.Uri.class}
+ )
+ public void testParcelling() {
+ parcelAndUnparcel(Uri.parse("foo:bob%20lee"));
+ parcelAndUnparcel(Uri.fromParts("foo", "bob lee", "fragment"));
+ parcelAndUnparcel(new Uri.Builder()
+ .scheme("http")
+ .authority("crazybob.org")
+ .path("/rss/")
+ .encodedQuery("a=b")
+ .fragment("foo")
+ .build());
+ }
+
+ private void parcelAndUnparcel(Uri u) {
+ Parcel p = Parcel.obtain();
+ Uri.writeToParcel(p, u);
+ p.setDataPosition(0);
+ assertEquals(u, Uri.CREATOR.createFromParcel(p));
+
+ p.setDataPosition(0);
+ u = u.buildUpon().build();
+ Uri.writeToParcel(p, u);
+ p.setDataPosition(0);
+ assertEquals(u, Uri.CREATOR.createFromParcel(p));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test buildUpon",
+ method = "buildUpon",
+ args = {}
+ )
+ public void testBuildUpon() {
+ Uri u = Uri.parse("bob:lee").buildUpon().scheme("robert").build();
+ assertEquals("robert", u.getScheme());
+ assertEquals("lee", u.getEncodedSchemeSpecificPart());
+ assertEquals("lee", u.getSchemeSpecificPart());
+ assertNull(u.getQuery());
+ assertNull(u.getPath());
+ assertNull(u.getAuthority());
+ assertNull(u.getHost());
+
+ Uri a = Uri.fromParts("foo", "bar", "tee");
+ Uri b = a.buildUpon().fragment("new").build();
+ assertEquals("new", b.getFragment());
+ assertEquals("bar", b.getSchemeSpecificPart());
+ assertEquals("foo", b.getScheme());
+ a = new Uri.Builder()
+ .scheme("foo")
+ .encodedOpaquePart("bar")
+ .fragment("tee")
+ .build();
+ b = a.buildUpon().fragment("new").build();
+ assertEquals("new", b.getFragment());
+ assertEquals("bar", b.getSchemeSpecificPart());
+ assertEquals("foo", b.getScheme());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getSchemeSpecificPart",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getEncodedSchemeSpecificPart",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getEncodedPath",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getPath",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getEncodedQuery",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getQuery",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getEncodedFragment",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getHost",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getPort",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getUserInfo",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "getEncodedUserInfo",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test string uri.",
+ method = "parse",
+ args = {java.lang.String.class}
+ )
+ })
+ public void testStringUri() {
+ assertEquals("bob lee",
+ Uri.parse("foo:bob%20lee").getSchemeSpecificPart());
+ assertEquals("bob%20lee",
+ Uri.parse("foo:bob%20lee").getEncodedSchemeSpecificPart());
+
+ assertEquals("/bob%20lee",
+ Uri.parse("foo:/bob%20lee").getEncodedPath());
+ assertNull(Uri.parse("foo:bob%20lee").getPath());
+
+ assertEquals("bob%20lee",
+ Uri.parse("foo:?bob%20lee").getEncodedQuery());
+ assertNull(Uri.parse("foo:bob%20lee").getEncodedQuery());
+ assertNull(Uri.parse("foo:bar#?bob%20lee").getQuery());
+
+ assertEquals("bob%20lee",
+ Uri.parse("foo:#bob%20lee").getEncodedFragment());
+
+ Uri uri = Uri.parse("http://localhost:42");
+ assertEquals("localhost", uri.getHost());
+ assertEquals(42, uri.getPort());
+
+ uri = Uri.parse("http://bob@localhost:42");
+ assertEquals("bob", uri.getUserInfo());
+ assertEquals("localhost", uri.getHost());
+ assertEquals(42, uri.getPort());
+
+ uri = Uri.parse("http://bob%20lee@localhost:42");
+ assertEquals("bob lee", uri.getUserInfo());
+ assertEquals("bob%20lee", uri.getEncodedUserInfo());
+
+ uri = Uri.parse("http://localhost");
+ assertEquals("localhost", uri.getHost());
+ assertEquals(-1, uri.getPort());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test compareTo",
+ method = "compareTo",
+ args = {android.net.Uri.class}
+ )
+ public void testCompareTo() {
+ Uri a = Uri.parse("foo:a");
+ Uri b = Uri.parse("foo:b");
+ Uri b2 = Uri.parse("foo:b");
+
+ assertTrue(a.compareTo(b) < 0);
+ assertTrue(b.compareTo(a) > 0);
+ assertEquals(0, b.compareTo(b2));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test equals and hashCode.",
+ method = "equals",
+ args = {java.lang.Object.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test equals and hashCode.",
+ method = "hashCode",
+ args = {}
+ )
+ })
+ public void testEqualsAndHashCode() {
+ Uri a = Uri.parse("http://crazybob.org/test/?foo=bar#tee");
+
+ Uri b = new Uri.Builder()
+ .scheme("http")
+ .authority("crazybob.org")
+ .path("/test/")
+ .encodedQuery("foo=bar")
+ .fragment("tee")
+ .build();
+
+ // Try alternate builder methods.
+ Uri c = new Uri.Builder()
+ .scheme("http")
+ .encodedAuthority("crazybob.org")
+ .encodedPath("/test/")
+ .encodedQuery("foo=bar")
+ .encodedFragment("tee")
+ .build();
+
+ assertFalse(Uri.EMPTY.equals(null));
+ assertEquals(a, b);
+ assertEquals(b, c);
+ assertEquals(c, a);
+ assertEquals(a.hashCode(), b.hashCode());
+ assertEquals(b.hashCode(), c.hashCode());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test encode and decode.",
+ method = "encode",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test encode and decode.",
+ method = "encode",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test encode and decode.",
+ method = "decode",
+ args = {java.lang.String.class}
+ )
+ })
+ public void testEncodeAndDecode() {
+ String encoded = Uri.encode("Bob:/", "/");
+ assertEquals(-1, encoded.indexOf(':'));
+ assertTrue(encoded.indexOf('/') > -1);
+ assertDecode(null);
+ assertDecode("");
+ assertDecode("Bob");
+ assertDecode(":Bob");
+ assertDecode("::Bob");
+ assertDecode("Bob::Lee");
+ assertDecode("Bob:Lee");
+ assertDecode("Bob::");
+ assertDecode("Bob:");
+ assertDecode("::Bob::");
+ }
+
+ private void assertDecode(String s) {
+ assertEquals(s, Uri.decode(Uri.encode(s, null)));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test fromFile.",
+ method = "fromFile",
+ args = {java.io.File.class}
+ )
+ public void testFromFile() {
+ File f = new File("/tmp/bob");
+ Uri uri = Uri.fromFile(f);
+ assertEquals("file:///tmp/bob", uri.toString());
+ try {
+ Uri.fromFile(null);
+ fail("testFile fail");
+ } catch (NullPointerException e) {}
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test get query parameters.",
+ method = "getQueryParameter",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test get query parameters.",
+ method = "getQueryParameters",
+ args = {java.lang.String.class}
+ )
+ })
+ public void testQueryParameters() {
+ Uri uri = Uri.parse("content://user");
+ assertEquals(null, uri.getQueryParameter("a"));
+
+ uri = uri.buildUpon().appendQueryParameter("a", "b").build();
+ assertEquals("b", uri.getQueryParameter("a"));
+
+ uri = uri.buildUpon().appendQueryParameter("a", "b2").build();
+ assertEquals(Arrays.asList("b", "b2"), uri.getQueryParameters("a"));
+
+ uri = uri.buildUpon().appendQueryParameter("c", "d").build();
+ assertEquals(Arrays.asList("b", "b2"), uri.getQueryParameters("a"));
+ assertEquals("d", uri.getQueryParameter("c"));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "",
+ method = "getPathSegments",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "",
+ method = "getLastPathSegment",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "",
+ method = "withAppendedPath",
+ args = {android.net.Uri.class, java.lang.String.class}
+ )
+ })
+ public void testPathOperations() {
+ Uri uri = Uri.parse("content://user/a/b");
+
+ assertEquals(2, uri.getPathSegments().size());
+ assertEquals("a", uri.getPathSegments().get(0));
+ assertEquals("b", uri.getPathSegments().get(1));
+ assertEquals("b", uri.getLastPathSegment());
+
+ Uri first = uri;
+ uri = uri.buildUpon().appendPath("c").build();
+ assertEquals(3, uri.getPathSegments().size());
+ assertEquals("c", uri.getPathSegments().get(2));
+ assertEquals("c", uri.getLastPathSegment());
+ assertEquals("content://user/a/b/c", uri.toString());
+
+ uri = ContentUris.withAppendedId(uri, 100);
+ assertEquals(4, uri.getPathSegments().size());
+ assertEquals("100", uri.getPathSegments().get(3));
+ assertEquals("100", uri.getLastPathSegment());
+ assertEquals(100, ContentUris.parseId(uri));
+ assertEquals("content://user/a/b/c/100", uri.toString());
+
+ // Make sure the original URI is still intact.
+ assertEquals(2, first.getPathSegments().size());
+ assertEquals("b", first.getLastPathSegment());
+
+ try {
+ first.getPathSegments().get(2);
+ fail("test path operations");
+ } catch (IndexOutOfBoundsException e) {}
+
+ assertEquals(null, Uri.EMPTY.getLastPathSegment());
+
+ Uri withC = Uri.parse("foo:/a/b/").buildUpon().appendPath("c").build();
+ assertEquals("/a/b/c", withC.getPath());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "isAbsolute",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "isOpaque",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "isRelative",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "getHost",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "getPort",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "getScheme",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "getSchemeSpecificPart",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "fromParts",
+ args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test opaque uri.",
+ method = "toString",
+ args = {}
+ )
+ })
+ public void testOpaqueUri() {
+ Uri uri = Uri.parse("mailto:nobody");
+ testOpaqueUri(uri);
+
+ uri = uri.buildUpon().build();
+ testOpaqueUri(uri);
+
+ uri = Uri.fromParts("mailto", "nobody", null);
+ testOpaqueUri(uri);
+
+ uri = uri.buildUpon().build();
+ testOpaqueUri(uri);
+
+ uri = new Uri.Builder()
+ .scheme("mailto")
+ .opaquePart("nobody")
+ .build();
+ testOpaqueUri(uri);
+
+ uri = uri.buildUpon().build();
+ testOpaqueUri(uri);
+ }
+
+ private void testOpaqueUri(Uri uri) {
+ assertEquals("mailto", uri.getScheme());
+ assertEquals("nobody", uri.getSchemeSpecificPart());
+ assertEquals("nobody", uri.getEncodedSchemeSpecificPart());
+
+ assertNull(uri.getFragment());
+ assertTrue(uri.isAbsolute());
+ assertTrue(uri.isOpaque());
+ assertFalse(uri.isRelative());
+ assertFalse(uri.isHierarchical());
+
+ assertNull(uri.getAuthority());
+ assertNull(uri.getEncodedAuthority());
+ assertNull(uri.getPath());
+ assertNull(uri.getEncodedPath());
+ assertNull(uri.getUserInfo());
+ assertNull(uri.getEncodedUserInfo());
+ assertNull(uri.getQuery());
+ assertNull(uri.getEncodedQuery());
+ assertNull(uri.getHost());
+ assertEquals(-1, uri.getPort());
+
+ assertTrue(uri.getPathSegments().isEmpty());
+ assertNull(uri.getLastPathSegment());
+
+ assertEquals("mailto:nobody", uri.toString());
+
+ Uri withFragment = uri.buildUpon().fragment("top").build();
+ assertEquals("mailto:nobody#top", withFragment.toString());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getAuthority",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getScheme",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getEncodedAuthority",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getPath",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getEncodedPath",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getQuery",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getEncodedQuery",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getFragment",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getEncodedFragment",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "getSchemeSpecificPart",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "isAbsolute",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "isHierarchical",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "isOpaque",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "isRelative",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test hierarchical uris.",
+ method = "toString",
+ args = {}
+ )
+ })
+ public void testHierarchicalUris() {
+ testHierarchical("http", "google.com", "/p1/p2", "query", "fragment");
+ testHierarchical("file", null, "/p1/p2", null, null);
+ testHierarchical("content", "contact", "/p1/p2", null, null);
+ testHierarchical("http", "google.com", "/p1/p2", null, "fragment");
+ testHierarchical("http", "google.com", "", null, "fragment");
+ testHierarchical("http", "google.com", "", "query", "fragment");
+ testHierarchical("http", "google.com", "", "query", null);
+ testHierarchical("http", null, "/", "query", null);
+ }
+
+ private static void testHierarchical(String scheme, String authority,
+ String path, String query, String fragment) {
+ StringBuilder sb = new StringBuilder();
+
+ if (authority != null) {
+ sb.append("//").append(authority);
+ }
+ if (path != null) {
+ sb.append(path);
+ }
+ if (query != null) {
+ sb.append('?').append(query);
+ }
+
+ String ssp = sb.toString();
+
+ if (scheme != null) {
+ sb.insert(0, scheme + ":");
+ }
+ if (fragment != null) {
+ sb.append('#').append(fragment);
+ }
+
+ String uriString = sb.toString();
+
+ Uri uri = Uri.parse(uriString);
+
+ // Run these twice to test caching.
+ compareHierarchical(
+ uriString, ssp, uri, scheme, authority, path, query, fragment);
+ compareHierarchical(
+ uriString, ssp, uri, scheme, authority, path, query, fragment);
+
+ // Test rebuilt version.
+ uri = uri.buildUpon().build();
+
+ // Run these twice to test caching.
+ compareHierarchical(
+ uriString, ssp, uri, scheme, authority, path, query, fragment);
+ compareHierarchical(
+ uriString, ssp, uri, scheme, authority, path, query, fragment);
+
+ // The decoded and encoded versions of the inputs are all the same.
+ // We'll test the actual encoding decoding separately.
+
+ // Test building with encoded versions.
+ Uri built = new Uri.Builder()
+ .scheme(scheme)
+ .encodedAuthority(authority)
+ .encodedPath(path)
+ .encodedQuery(query)
+ .encodedFragment(fragment)
+ .build();
+
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+
+ // Test building with decoded versions.
+ built = new Uri.Builder()
+ .scheme(scheme)
+ .authority(authority)
+ .path(path)
+ .query(query)
+ .fragment(fragment)
+ .build();
+
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+
+ // Rebuild.
+ built = built.buildUpon().build();
+
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+ compareHierarchical(
+ uriString, ssp, built, scheme, authority, path, query, fragment);
+ }
+
+ private static void compareHierarchical(String uriString, String ssp,
+ Uri uri,
+ String scheme, String authority, String path, String query,
+ String fragment) {
+ assertEquals(scheme, uri.getScheme());
+ assertEquals(authority, uri.getAuthority());
+ assertEquals(authority, uri.getEncodedAuthority());
+ assertEquals(path, uri.getPath());
+ assertEquals(path, uri.getEncodedPath());
+ assertEquals(query, uri.getQuery());
+ assertEquals(query, uri.getEncodedQuery());
+ assertEquals(fragment, uri.getFragment());
+ assertEquals(fragment, uri.getEncodedFragment());
+ assertEquals(ssp, uri.getSchemeSpecificPart());
+
+ if (scheme != null) {
+ assertTrue(uri.isAbsolute());
+ assertFalse(uri.isRelative());
+ } else {
+ assertFalse(uri.isAbsolute());
+ assertTrue(uri.isRelative());
+ }
+
+ assertFalse(uri.isOpaque());
+ assertTrue(uri.isHierarchical());
+ assertEquals(uriString, uri.toString());
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/Uri_BuilderTest.java b/tests/cts/net/src/android/net/cts/Uri_BuilderTest.java
new file mode 100644
index 0000000..8a1b423
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/Uri_BuilderTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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.
+ */
+
+package android.net.cts;
+
+import junit.framework.TestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+import android.net.Uri.Builder;
+import android.net.Uri;
+
+@TestTargetClass(Uri.Builder.class)
+public class Uri_BuilderTest extends TestCase {
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "Uri.Builder",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "build",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "scheme",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "authority",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "path",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "query",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "opaquePart",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "fragment",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "appendEncodedPath",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "appendPath",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "appendQueryParameter",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "encodedAuthority",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "encodedFragment",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "encodedPath",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "encodedQuery",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "encodedOpaquePart",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test Builder operations.",
+ method = "toString",
+ args = {}
+ )
+ })
+ public void testBuilderOperations() {
+ Uri uri = Uri.parse("http://google.com/p1?query#fragment");
+ Builder builder = uri.buildUpon();
+ uri = builder.appendPath("p2").build();
+ assertEquals("http", uri.getScheme());
+ assertEquals("google.com", uri.getAuthority());
+ assertEquals("/p1/p2", uri.getPath());
+ assertEquals("query", uri.getQuery());
+ assertEquals("fragment", uri.getFragment());
+ assertEquals(uri.toString(), builder.toString());
+
+ uri = Uri.parse("mailto:nobody");
+ builder = uri.buildUpon();
+ uri = builder.build();
+ assertEquals("mailto", uri.getScheme());
+ assertEquals("nobody", uri.getSchemeSpecificPart());
+ assertEquals(uri.toString(), builder.toString());
+
+ uri = new Uri.Builder()
+ .scheme("http")
+ .encodedAuthority("google.com")
+ .encodedPath("/p1")
+ .appendEncodedPath("p2")
+ .encodedQuery("query")
+ .appendQueryParameter("query2", null)
+ .encodedFragment("fragment")
+ .build();
+ assertEquals("http", uri.getScheme());
+ assertEquals("google.com", uri.getEncodedAuthority());
+ assertEquals("/p1/p2", uri.getEncodedPath());
+ assertEquals("query&query2=null", uri.getEncodedQuery());
+ assertEquals("fragment", uri.getEncodedFragment());
+
+ uri = new Uri.Builder()
+ .scheme("mailto")
+ .encodedOpaquePart("nobody")
+ .build();
+ assertEquals("mailto", uri.getScheme());
+ assertEquals("nobody", uri.getEncodedSchemeSpecificPart());
+ }
+}
+
diff --git a/tests/cts/net/src/android/net/http/cts/SslCertificateTest.java b/tests/cts/net/src/android/net/http/cts/SslCertificateTest.java
new file mode 100644
index 0000000..6e23419
--- /dev/null
+++ b/tests/cts/net/src/android/net/http/cts/SslCertificateTest.java
@@ -0,0 +1,302 @@
+/*
+ * 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.
+ */
+
+package android.net.http.cts;
+
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+import android.net.http.SslCertificate;
+import android.net.http.SslCertificate.DName;
+import android.os.Bundle;
+
+@TestTargetClass(SslCertificate.class)
+public class SslCertificateTest extends TestCase {
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor(s) of SslCertificate.",
+ method = "SslCertificate",
+ args = {java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test constructor(s) of SslCertificate.",
+ method = "SslCertificate",
+ args = {java.security.cert.X509Certificate.class}
+ )
+ })
+ public void testConstructor() {
+ // new the SslCertificate instance
+ String date = DateFormat.getInstance().format(new Date());
+ new SslCertificate("c=129", "e=weji", date, date);
+
+ // new the SslCertificate instance
+ new SslCertificate(new MockX509Certificate());
+
+ }
+
+ class MockX509Certificate extends X509Certificate {
+
+ @Override
+ public void checkValidity() throws CertificateExpiredException,
+ CertificateNotYetValidException {
+ }
+
+ @Override
+ public void checkValidity(Date date) throws CertificateExpiredException,
+ CertificateNotYetValidException {
+ }
+
+ @Override
+ public int getBasicConstraints() {
+ return 0;
+ }
+
+ @Override
+ public Principal getIssuerDN() {
+ return new MockPrincipal();
+ }
+
+ @Override
+ public boolean[] getIssuerUniqueID() {
+ return null;
+ }
+
+ @Override
+ public boolean[] getKeyUsage() {
+ return null;
+ }
+
+ @Override
+ public Date getNotAfter() {
+ return new Date(System.currentTimeMillis());
+ }
+
+ @Override
+ public Date getNotBefore() {
+ return new Date(System.currentTimeMillis() - 1000);
+ }
+
+ @Override
+ public BigInteger getSerialNumber() {
+ return null;
+ }
+
+ @Override
+ public String getSigAlgName() {
+ return null;
+ }
+
+ @Override
+ public String getSigAlgOID() {
+ return null;
+ }
+
+ @Override
+ public byte[] getSigAlgParams() {
+ return null;
+ }
+
+ @Override
+ public byte[] getSignature() {
+ return null;
+ }
+
+ @Override
+ public Principal getSubjectDN() {
+ return new MockPrincipal();
+ }
+
+ class MockPrincipal implements Principal {
+ public String getName() {
+ return null;
+ }
+ }
+ @Override
+ public boolean[] getSubjectUniqueID() {
+ return null;
+ }
+
+ @Override
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+ return null;
+ }
+
+ @Override
+ public int getVersion() {
+ return 0;
+ }
+
+ @Override
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return null;
+ }
+
+ @Override
+ public PublicKey getPublicKey() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return null;
+ }
+
+ @Override
+ public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException, SignatureException {
+ }
+
+ @Override
+ public void verify(PublicKey key, String sigProvider) throws CertificateException,
+ NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException,
+ SignatureException {
+ }
+
+ public Set<String> getCriticalExtensionOIDs() {
+ return null;
+ }
+
+ public byte[] getExtensionValue(String oid) {
+ return null;
+ }
+
+ public Set<String> getNonCriticalExtensionOIDs() {
+ return null;
+ }
+
+ public boolean hasUnsupportedCriticalExtension() {
+ return false;
+ }
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test saveState and restoreState(SslCertificate certificate).",
+ method = "saveState",
+ args = {android.net.http.SslCertificate.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test saveState and restoreState(SslCertificate certificate).",
+ method = "restoreState",
+ args = {android.os.Bundle.class}
+ )
+ })
+ public void testState() {
+ // set the expected value
+
+ Date date1 = new Date(System.currentTimeMillis() - 1000);
+ Date date2 = new Date(System.currentTimeMillis());
+ SslCertificate ssl = new SslCertificate("c=129", "e=weji", DateFormat.getInstance().format(
+ date1), DateFormat.getInstance().format(date2));
+ Bundle saved = SslCertificate.saveState(ssl);
+ assertTrue(saved.size() == 4);
+
+ assertNotNull(saved.getString("issued-to"));
+ assertNotNull(saved.getString("issued-by"));
+ assertNotNull(saved.getString("valid-not-before"));
+ assertNotNull(saved.getString("valid-not-after"));
+ assertNull(SslCertificate.saveState(null));
+
+ SslCertificate restored = SslCertificate.restoreState(saved);
+ assertEquals(ssl.getValidNotAfter(), restored.getValidNotAfter());
+ assertEquals(ssl.getValidNotBefore(), restored.getValidNotBefore());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getIssuedTo().",
+ method = "getIssuedTo",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getIssuedTo().",
+ method = "getIssuedBy",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getIssuedTo().",
+ method = "getValidNotAfter",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getIssuedTo().",
+ method = "getValidNotBefore",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test getIssuedTo().",
+ method = "toString",
+ args = {}
+ )
+ })
+ public void testSslCertificate() {
+
+ final String TO = "c=ccc,o=testOName,ou=testUName,cn=testCName";
+ final String BY = "e=aeei,c=adb,o=testOName,ou=testUName,cn=testCName";
+ // new the SslCertificate instance
+ Date date1 = new Date(System.currentTimeMillis() - 1000);
+ Date date2 = new Date(System.currentTimeMillis());
+ SslCertificate ssl = new SslCertificate(TO, BY, DateFormat.getInstance().format(
+ date1), DateFormat.getInstance().format(date2));
+ DName issuedTo = ssl.getIssuedTo();
+ DName issuedBy = ssl.getIssuedBy();
+
+ assertEquals("testCName", issuedTo.getCName());
+ assertEquals(TO, issuedTo.getDName());
+ assertEquals("testOName", issuedTo.getOName());
+ assertEquals("testUName", issuedTo.getUName());
+
+ assertEquals("testCName", issuedBy.getCName());
+ assertEquals(BY, issuedBy.getDName());
+ assertEquals("testOName", issuedBy.getOName());
+ assertEquals("testUName", issuedBy.getUName());
+
+ assertEquals(DateFormat.getInstance().format(date1), ssl.getValidNotBefore());
+ assertEquals(DateFormat.getInstance().format(date2), ssl.getValidNotAfter());
+ final String EXPECTED = "Issued to: c=ccc,o=testOName,ou=testUName,cn=testCName;\n"
+ + "Issued by: e=aeei,c=adb,o=testOName,ou=testUName,cn=testCName;\n";
+ assertEquals(EXPECTED, ssl.toString());
+ }
+
+}
diff --git a/tests/cts/net/src/android/net/http/cts/SslCertificate_DNameTest.java b/tests/cts/net/src/android/net/http/cts/SslCertificate_DNameTest.java
new file mode 100644
index 0000000..7562e3a
--- /dev/null
+++ b/tests/cts/net/src/android/net/http/cts/SslCertificate_DNameTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+package android.net.http.cts;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import junit.framework.TestCase;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+import android.net.http.SslCertificate;
+import android.net.http.SslCertificate.DName;
+
+@TestTargetClass(DName.class)
+public class SslCertificate_DNameTest extends TestCase {
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DName.",
+ method = "SslCertificate.DName",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DName.",
+ method = "getCName",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DName.",
+ method = "getDName",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DName.",
+ method = "getOName",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.TODO,
+ notes = "Test DName.",
+ method = "getUName",
+ args = {}
+ )
+ })
+ public void testDName() {
+ final String TO = "c=ccc,o=testOName,ou=testUName,cn=testCName";
+ final String BY = "e=aeei,c=adb,o=testOName,ou=testUName,cn=testCName";
+ // new the SslCertificate instance
+ Date date1 = new Date(System.currentTimeMillis() - 1000);
+ Date date2 = new Date(System.currentTimeMillis());
+ SslCertificate ssl = new SslCertificate(TO, BY, DateFormat.getInstance().format(
+ date1), DateFormat.getInstance().format(date2));
+ DName issuedTo = ssl.getIssuedTo();
+
+ assertNotNull(issuedTo);
+
+ assertEquals("testCName", issuedTo.getCName());
+ assertEquals(TO, issuedTo.getDName());
+ assertEquals("testOName", issuedTo.getOName());
+ assertEquals("testUName", issuedTo.getUName());
+ }
+
+}