am 92ec8f77: am c4b48e7e: am 4e7386bd: am 89b22492: Merge "Fix CTS build" into lollipop-cts-dev automerge: ab0f0fe
* commit '92ec8f7720cb5232e1e07f21d9e53e17b298dfa2':
Fix CTS build
diff --git a/tests/cts/hostside/app/Android.mk b/tests/cts/hostside/app/Android.mk
index 29b620d..055287a 100644
--- a/tests/cts/hostside/app/Android.mk
+++ b/tests/cts/hostside/app/Android.mk
@@ -29,4 +29,4 @@
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
-include $(BUILD_PACKAGE)
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/cts/net/Android.mk b/tests/cts/net/Android.mk
index 46d4d81..6524871 100644
--- a/tests/cts/net/Android.mk
+++ b/tests/cts/net/Android.mk
@@ -24,17 +24,18 @@
# Include both the 32 and 64 bit versions
LOCAL_MULTILIB := both
-LOCAL_JAVA_LIBRARIES := voip-common conscrypt
+LOCAL_JAVA_LIBRARIES := voip-common conscrypt org.apache.http.legacy
-LOCAL_JNI_SHARED_LIBRARIES := libnativedns_jni
+LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libnativedns_jni \
+ libnativemultinetwork_jni
# include CtsTestServer as a temporary hack to free net.cts from cts.stub.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := CtsNetTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestserver ctsdeviceutil ctstestrunner \
- core-tests-support
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support ctsdeviceutil \
+ ctstestrunner ctstestserver mockwebserver
# uncomment when b/13249961 is fixed
#LOCAL_SDK_VERSION := current
diff --git a/tests/cts/net/AndroidManifest.xml b/tests/cts/net/AndroidManifest.xml
index 652262d..bca2d2c 100644
--- a/tests/cts/net/AndroidManifest.xml
+++ b/tests/cts/net/AndroidManifest.xml
@@ -30,6 +30,7 @@
<application>
<uses-library android:name="android.test.runner" />
+ <uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/cts/net/jni/Android.mk b/tests/cts/net/jni/Android.mk
index 75982de..ca82b30 100644
--- a/tests/cts/net/jni/Android.mk
+++ b/tests/cts/net/jni/Android.mk
@@ -28,3 +28,12 @@
LOCAL_SHARED_LIBRARIES := libnativehelper liblog
include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libnativemultinetwork_jni
+# Don't include this package in any configuration by default.
+LOCAL_MODULE_TAGS := optional
+LOCAL_SRC_FILES := NativeMultinetworkJni.c
+LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
+LOCAL_SHARED_LIBRARIES := libandroid libnativehelper liblog
+include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/cts/net/jni/NativeDnsJni.c b/tests/cts/net/jni/NativeDnsJni.c
index b975594..4eb3c7a 100644
--- a/tests/cts/net/jni/NativeDnsJni.c
+++ b/tests/cts/net/jni/NativeDnsJni.c
@@ -18,6 +18,7 @@
#include <jni.h>
#include <netdb.h>
#include <stdio.h>
+#include <string.h>
#include <utils/Log.h>
const char *GoogleDNSIpV4Address="8.8.8.8";
diff --git a/tests/cts/net/jni/NativeMultinetworkJni.c b/tests/cts/net/jni/NativeMultinetworkJni.c
new file mode 100644
index 0000000..9a5ab9c
--- /dev/null
+++ b/tests/cts/net/jni/NativeMultinetworkJni.c
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+
+#define LOG_TAG "MultinetworkApiTest"
+#include <utils/Log.h>
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <jni.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <android/multinetwork.h>
+
+#define UNUSED(X) ((void) X)
+
+static const char kHostname[] = "connectivitycheck.android.com";
+
+
+JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runGetaddrinfoCheck(
+ JNIEnv* env, jclass class, jlong nethandle) {
+ UNUSED(env);
+ UNUSED(class);
+ net_handle_t handle = (net_handle_t) nethandle;
+ struct addrinfo *res = NULL;
+
+ errno = 0;
+ int rval = android_getaddrinfofornetwork(handle, kHostname, NULL, NULL, &res);
+ const int saved_errno = errno;
+ freeaddrinfo(res);
+
+ ALOGD("android_getaddrinfofornetwork(%llu, %s) returned rval=%d errno=%d",
+ handle, kHostname, rval, saved_errno);
+ return rval == 0 ? 0 : -saved_errno;
+}
+
+JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runSetprocnetwork(
+ JNIEnv* env, jclass class, jlong nethandle) {
+ UNUSED(env);
+ UNUSED(class);
+ net_handle_t handle = (net_handle_t) nethandle;
+
+ errno = 0;
+ int rval = android_setprocnetwork(handle);
+ const int saved_errno = errno;
+ ALOGD("android_setprocnetwork(%llu) returned rval=%d errno=%d",
+ handle, rval, saved_errno);
+ return rval == 0 ? 0 : -saved_errno;
+}
+
+JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runSetsocknetwork(
+ JNIEnv* env, jclass class, jlong nethandle) {
+ UNUSED(env);
+ UNUSED(class);
+ net_handle_t handle = (net_handle_t) nethandle;
+
+ errno = 0;
+ int fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
+ ALOGD("socket() failed, errno=%d", errno);
+ return -errno;
+ }
+
+ errno = 0;
+ int rval = android_setsocknetwork(handle, fd);
+ const int saved_errno = errno;
+ ALOGD("android_setprocnetwork(%llu, %d) returned rval=%d errno=%d",
+ handle, fd, rval, saved_errno);
+ close(fd);
+ return rval == 0 ? 0 : -saved_errno;
+}
+
+static const int kSockaddrStrLen = INET6_ADDRSTRLEN + strlen("[]:65535");
+
+void sockaddr_ntop(const struct sockaddr *sa, socklen_t salen, char *dst, const size_t size) {
+ char addrstr[INET6_ADDRSTRLEN];
+ char portstr[sizeof("65535")];
+ char buf[sizeof(addrstr) + sizeof(portstr) + sizeof("[]:")];
+ int ret = getnameinfo(sa, salen,
+ addrstr, sizeof(addrstr),
+ portstr, sizeof(portstr),
+ NI_NUMERICHOST | NI_NUMERICSERV);
+ if (ret == 0) {
+ snprintf(buf, sizeof(buf),
+ (sa->sa_family == AF_INET6) ? "[%s]:%s" : "%s:%s",
+ addrstr, portstr);
+ } else {
+ sprintf(buf, "???");
+ }
+
+ strlcpy(dst, buf, (strlen(buf) < size - 1) ? strlen(buf) : size - 1);
+}
+
+JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
+ JNIEnv* env, jclass class, jlong nethandle) {
+ UNUSED(env);
+ UNUSED(class);
+ const struct addrinfo kHints = {
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_DGRAM,
+ .ai_protocol = IPPROTO_UDP,
+ };
+ struct addrinfo *res = NULL;
+ net_handle_t handle = (net_handle_t) nethandle;
+
+ // Quoth Ian Swett:
+ // "QUIC always uses 80 and 443, but only 443 is used for secure(HTTPS) traffic."
+ int rval = android_getaddrinfofornetwork(handle, kHostname, "80", &kHints, &res);
+ if (rval != 0) {
+ ALOGD("android_getaddrinfofornetwork(%llu, %s) returned rval=%d errno=%d",
+ handle, kHostname, rval, errno);
+ freeaddrinfo(res);
+ return -errno;
+ }
+
+ // Rely upon getaddrinfo sorting the best destination to the front.
+ int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (fd < 0) {
+ ALOGD("socket(%d, %d, %d) failed, errno=%d",
+ res->ai_family, res->ai_socktype, res->ai_protocol, errno);
+ freeaddrinfo(res);
+ return -errno;
+ }
+
+ rval = android_setsocknetwork(handle, fd);
+ ALOGD("android_setprocnetwork(%llu, %d) returned rval=%d errno=%d",
+ handle, fd, rval, errno);
+ if (rval != 0) {
+ close(fd);
+ freeaddrinfo(res);
+ return -errno;
+ }
+
+ char addrstr[kSockaddrStrLen];
+ sockaddr_ntop(res->ai_addr, res->ai_addrlen, addrstr, sizeof(addrstr));
+ ALOGD("Attempting connect() to %s...", addrstr);
+
+ rval = connect(fd, res->ai_addr, res->ai_addrlen);
+ if (rval != 0) {
+ close(fd);
+ freeaddrinfo(res);
+ return -errno;
+ }
+ freeaddrinfo(res);
+
+ struct sockaddr_storage src_addr;
+ socklen_t src_addrlen = sizeof(src_addr);
+ if (getsockname(fd, (struct sockaddr *)&src_addr, &src_addrlen) != 0) {
+ close(fd);
+ return -errno;
+ }
+ sockaddr_ntop((const struct sockaddr *)&src_addr, sizeof(src_addr), addrstr, sizeof(addrstr));
+ ALOGD("... from %s", addrstr);
+
+ // Don't let reads or writes block indefinitely.
+ const struct timeval timeo = { 5, 0 }; // 5 seconds
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
+
+ uint8_t quic_packet[] = {
+ 0x0c, // public flags: 64bit conn ID, 8bit sequence number
+ 0, 0, 0, 0, 0, 0, 0, 0, // 64bit connection ID
+ 0x01, // sequence number
+ 0x00, // private flags
+ 0x07, // type: regular frame type "PING"
+ };
+
+ arc4random_buf(quic_packet + 1, 8); // random connection ID
+
+ ssize_t sent = send(fd, quic_packet, sizeof(quic_packet), 0);
+ if (sent < (ssize_t)sizeof(quic_packet)) {
+ ALOGD("send(QUIC packet) returned sent=%zd, errno=%d", sent, errno);
+ close(fd);
+ return -errno;
+ }
+
+ uint8_t response[1500];
+ ssize_t rcvd = recv(fd, response, sizeof(response), 0);
+ if (rcvd < sent) {
+ ALOGD("recv() returned rcvd=%zd, errno=%d", rcvd, errno);
+ close(fd);
+ return -errno;
+ }
+
+ int conn_id_cmp = memcmp(quic_packet + 1, response + 1, 8);
+ if (conn_id_cmp != 0) {
+ ALOGD("sent and received connection IDs do not match");
+ close(fd);
+ return -EPROTO;
+ }
+
+ // TODO: log, and compare to the IP address encoded in the
+ // response, since this should be a public reset packet.
+
+ close(fd);
+ return 0;
+}
diff --git a/tests/cts/net/src/android/net/cts/LocalSocketTest.java b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
index 70d69c8..865ec21 100644
--- a/tests/cts/net/src/android/net/cts/LocalSocketTest.java
+++ b/tests/cts/net/src/android/net/cts/LocalSocketTest.java
@@ -112,7 +112,6 @@
}
public void testAccessors() throws IOException{
- final int INITIAL_SEND_BUFFER_SIZE = 1998;
LocalSocket socket = new LocalSocket();
LocalSocketAddress addr = new LocalSocketAddress("secondary");
@@ -127,14 +126,8 @@
socket.setReceiveBufferSize(1999);
assertEquals(1999 << 1, socket.getReceiveBufferSize());
- socket.setSendBufferSize(INITIAL_SEND_BUFFER_SIZE);
- int sendBufferSize = socket.getSendBufferSize();
- if ((INITIAL_SEND_BUFFER_SIZE << 1) < sendBufferSize) {
- socket.setSendBufferSize(sendBufferSize / 2);
- assertEquals(sendBufferSize, socket.getSendBufferSize());
- } else {
- assertEquals(INITIAL_SEND_BUFFER_SIZE << 1, sendBufferSize);
- }
+ socket.setSendBufferSize(3998);
+ assertEquals(3998 << 1, socket.getSendBufferSize());
// Timeout is not support at present, so set is ignored
socket.setSoTimeout(1996);
diff --git a/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java b/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java
new file mode 100644
index 0000000..51ee50e
--- /dev/null
+++ b/tests/cts/net/src/android/net/cts/MultinetworkApiTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.cts;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkUtils;
+import android.system.ErrnoException;
+import android.system.OsConstants;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+
+
+public class MultinetworkApiTest extends AndroidTestCase {
+
+ static {
+ System.loadLibrary("nativemultinetwork_jni");
+ }
+
+ private static final String TAG = "MultinetworkNativeApiTest";
+
+ /**
+ * @return 0 on success
+ */
+ private static native int runGetaddrinfoCheck(long networkHandle);
+ private static native int runSetprocnetwork(long networkHandle);
+ private static native int runSetsocknetwork(long networkHandle);
+ private static native int runDatagramCheck(long networkHandle);
+
+ private ConnectivityManager mCM;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mCM = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+ }
+
+ private Network[] getTestableNetworks() {
+ final ArrayList<Network> testableNetworks = new ArrayList<Network>();
+ for (Network network : mCM.getAllNetworks()) {
+ final NetworkCapabilities nc = mCM.getNetworkCapabilities(network);
+ if (nc != null
+ && nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
+ && nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
+ testableNetworks.add(network);
+ }
+ }
+
+ assertTrue(
+ "This test requires that at least one network be connected. " +
+ "Please ensure that the device is connected to a network.",
+ testableNetworks.size() >= 1);
+ return testableNetworks.toArray(new Network[0]);
+ }
+
+ public void testGetaddrinfo() throws ErrnoException {
+ for (Network network : getTestableNetworks()) {
+ int errno = runGetaddrinfoCheck(network.getNetworkHandle());
+ if (errno != 0) {
+ throw new ErrnoException(
+ "getaddrinfo on " + mCM.getNetworkInfo(network), -errno);
+ }
+ }
+ }
+
+ public void testSetprocnetwork() throws ErrnoException {
+ // Hopefully no prior test in this process space has set a default network.
+ assertNull(mCM.getProcessDefaultNetwork());
+ assertEquals(0, NetworkUtils.getBoundNetworkForProcess());
+
+ for (Network network : getTestableNetworks()) {
+ mCM.setProcessDefaultNetwork(null);
+ assertNull(mCM.getProcessDefaultNetwork());
+
+ int errno = runSetprocnetwork(network.getNetworkHandle());
+ if (errno != 0) {
+ throw new ErrnoException(
+ "setprocnetwork on " + mCM.getNetworkInfo(network), -errno);
+ }
+ Network processDefault = mCM.getProcessDefaultNetwork();
+ assertNotNull(processDefault);
+ assertEquals(network, processDefault);
+ // TODO: open DatagramSockets, connect them to 192.0.2.1 and 2001:db8::,
+ // and ensure that the source address is in fact on this network as
+ // determined by mCM.getLinkProperties(network).
+
+ mCM.setProcessDefaultNetwork(null);
+ }
+
+ for (Network network : getTestableNetworks()) {
+ NetworkUtils.bindProcessToNetwork(0);
+ assertNull(mCM.getBoundNetworkForProcess());
+
+ int errno = runSetprocnetwork(network.getNetworkHandle());
+ if (errno != 0) {
+ throw new ErrnoException(
+ "setprocnetwork on " + mCM.getNetworkInfo(network), -errno);
+ }
+ assertEquals(network, new Network(mCM.getBoundNetworkForProcess()));
+ // TODO: open DatagramSockets, connect them to 192.0.2.1 and 2001:db8::,
+ // and ensure that the source address is in fact on this network as
+ // determined by mCM.getLinkProperties(network).
+
+ NetworkUtils.bindProcessToNetwork(0);
+ }
+ }
+
+ public void testSetsocknetwork() throws ErrnoException {
+ for (Network network : getTestableNetworks()) {
+ int errno = runSetsocknetwork(network.getNetworkHandle());
+ if (errno != 0) {
+ throw new ErrnoException(
+ "setsocknetwork on " + mCM.getNetworkInfo(network), -errno);
+ }
+ }
+ }
+
+ public void testNativeDatagramTransmission() throws ErrnoException {
+ for (Network network : getTestableNetworks()) {
+ int errno = runDatagramCheck(network.getNetworkHandle());
+ if (errno != 0) {
+ throw new ErrnoException(
+ "DatagramCheck on " + mCM.getNetworkInfo(network), -errno);
+ }
+ }
+ }
+
+ public void testNoSuchNetwork() {
+ final Network eNoNet = new Network(54321);
+ assertNull(mCM.getNetworkInfo(eNoNet));
+
+ final long eNoNetHandle = eNoNet.getNetworkHandle();
+ assertEquals(-OsConstants.ENONET, runSetsocknetwork(eNoNetHandle));
+ assertEquals(-OsConstants.ENONET, runSetprocnetwork(eNoNetHandle));
+ // TODO: correct test permissions so this call is not silently re-mapped
+ // to query on the default network.
+ // assertEquals(-OsConstants.ENONET, runGetaddrinfoCheck(eNoNetHandle));
+ }
+}
diff --git a/tests/cts/net/src/android/net/cts/MultinetworkTest.java b/tests/cts/net/src/android/net/cts/MultinetworkSysctlTest.java
similarity index 96%
rename from tests/cts/net/src/android/net/cts/MultinetworkTest.java
rename to tests/cts/net/src/android/net/cts/MultinetworkSysctlTest.java
index 256c030..c091a13 100644
--- a/tests/cts/net/src/android/net/cts/MultinetworkTest.java
+++ b/tests/cts/net/src/android/net/cts/MultinetworkSysctlTest.java
@@ -27,9 +27,9 @@
import java.io.IOException;
/**
- * Tests for multinetwork functionality.
+ * Tests for multinetwork sysctl functionality.
*/
-public class MultinetworkTest extends AndroidTestCase {
+public class MultinetworkSysctlTest extends AndroidTestCase {
// Global sysctls. Must be present and set to 1.
private static final String[] GLOBAL_SYSCTLS = {
diff --git a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
index 6175923..60ac226 100644
--- a/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
+++ b/tests/cts/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -26,7 +26,7 @@
import android.net.SSLCertificateSocketFactory;
import android.test.AndroidTestCase;
-import libcore.javax.net.ssl.SSLDefaultConfigurationAsserts;
+import libcore.javax.net.ssl.SSLConfigurationAsserts;
public class SSLCertificateSocketFactoryTest extends AndroidTestCase {
private SSLCertificateSocketFactory mFactory;
@@ -40,7 +40,7 @@
}
public void testDefaultConfiguration() throws Exception {
- SSLDefaultConfigurationAsserts.assertSSLSocketFactory(mFactory);
+ SSLConfigurationAsserts.assertSSLSocketFactoryDefaultConfiguration(mFactory);
}
public void testAccessProperties() throws Exception {
diff --git a/tests/cts/net/src/android/net/http/cts/ApacheHttpClientTest.java b/tests/cts/net/src/android/net/http/cts/ApacheHttpClientTest.java
index 7d9189f..2e5306d 100644
--- a/tests/cts/net/src/android/net/http/cts/ApacheHttpClientTest.java
+++ b/tests/cts/net/src/android/net/http/cts/ApacheHttpClientTest.java
@@ -21,56 +21,27 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.NetworkInfo.State;
import android.net.Uri;
-import android.net.wifi.WifiManager;
import android.test.AndroidTestCase;
-import android.util.Log;
import android.webkit.cts.CtsTestServer;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
public class ApacheHttpClientTest extends AndroidTestCase {
- private static final String TAG = ApacheHttpClientTest.class.getSimpleName();
-
private static final int NUM_DOWNLOADS = 20;
private static final int SMALL_DOWNLOAD_SIZE = 100 * 1024;
private CtsTestServer mWebServer;
- private WifiManager mWifiManager;
-
- private ConnectivityManager mConnectivityManager;
-
- private boolean mHasTelephony;
-
- private boolean mHasWifi;
-
@Override
protected void setUp() throws Exception {
super.setUp();
mWebServer = new CtsTestServer(mContext);
- mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
- mConnectivityManager = (ConnectivityManager)
- mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
-
- PackageManager packageManager = mContext.getPackageManager();
- mHasTelephony = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
- mHasWifi = packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);
}
@Override
@@ -79,25 +50,8 @@
mWebServer.shutdown();
}
- public void testExecute_withMobile() throws Exception {
- if (mHasTelephony) {
- disconnectWifiToConnectToMobile();
- }
-
+ public void testExecute() throws Exception {
downloadMultipleFiles();
-
- if (mHasWifi) {
- connectToWifi();
- }
- }
-
- public void testExecute_withWifi() throws Exception {
- if (mHasWifi) {
- if (!mWifiManager.isWifiEnabled()) {
- connectToWifi();
- }
- downloadMultipleFiles();
- }
}
private void downloadMultipleFiles() throws ClientProtocolException, IOException {
@@ -134,77 +88,6 @@
numBytes += bytesRead;
}
}
- assertEquals(message, SMALL_DOWNLOAD_SIZE, numBytes);
- }
-
- private void connectToWifi() throws InterruptedException {
- if (!mWifiManager.isWifiEnabled()) {
- ConnectivityActionReceiver receiver =
- new ConnectivityActionReceiver(ConnectivityManager.TYPE_WIFI, State.CONNECTED);
- IntentFilter filter = new IntentFilter();
- filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
- mContext.registerReceiver(receiver, filter);
-
- assertTrue(mWifiManager.setWifiEnabled(true));
- assertTrue("Wifi must be configured to connect to an access point for this test.",
- receiver.waitForStateChange());
-
- mContext.unregisterReceiver(receiver);
- }
- }
-
- private void disconnectWifiToConnectToMobile() throws InterruptedException {
- if (mHasWifi && mWifiManager.isWifiEnabled()) {
- ConnectivityActionReceiver connectMobileReceiver =
- new ConnectivityActionReceiver(ConnectivityManager.TYPE_MOBILE,
- State.CONNECTED);
- ConnectivityActionReceiver disconnectWifiReceiver =
- new ConnectivityActionReceiver(ConnectivityManager.TYPE_WIFI,
- State.DISCONNECTED);
- IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
- mContext.registerReceiver(connectMobileReceiver, filter);
- mContext.registerReceiver(disconnectWifiReceiver, filter);
-
- assertTrue(mWifiManager.setWifiEnabled(false));
- assertTrue(disconnectWifiReceiver.waitForStateChange());
- assertTrue(connectMobileReceiver.waitForStateChange());
-
- mContext.unregisterReceiver(connectMobileReceiver);
- mContext.unregisterReceiver(disconnectWifiReceiver);
- }
- }
-
- /** Receiver that captures the last connectivity change's network type and state. */
- private class ConnectivityActionReceiver extends BroadcastReceiver {
-
- private final CountDownLatch mReceiveLatch = new CountDownLatch(1);
-
- private final int mNetworkType;
-
- private final State mExpectedState;
-
- ConnectivityActionReceiver(int networkType, State expectedState) {
- mNetworkType = networkType;
- mExpectedState = expectedState;
- }
-
- public void onReceive(Context context, Intent intent) {
- NetworkInfo networkInfo = intent.getExtras()
- .getParcelable(ConnectivityManager.EXTRA_NETWORK_INFO);
- int networkType = networkInfo.getType();
- State networkState = networkInfo.getState();
- Log.i(TAG, "Network type: " + networkType + " State: " + networkInfo.getState());
- if (networkType == mNetworkType && networkInfo.getState() == mExpectedState) {
- mReceiveLatch.countDown();
- }
- }
-
- public boolean waitForStateChange() throws InterruptedException {
- return mReceiveLatch.await(30, TimeUnit.SECONDS) || hasExpectedState();
- }
-
- private boolean hasExpectedState() {
- return mExpectedState == mConnectivityManager.getNetworkInfo(mNetworkType).getState();
- }
+ assertEquals(message, expectedNumBytes, numBytes);
}
}
diff --git a/tests/cts/net/src/android/net/http/cts/HttpResponseCacheTest.java b/tests/cts/net/src/android/net/http/cts/HttpResponseCacheTest.java
new file mode 100644
index 0000000..545541d
--- /dev/null
+++ b/tests/cts/net/src/android/net/http/cts/HttpResponseCacheTest.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2011 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 com.google.mockwebserver.MockResponse;
+import com.google.mockwebserver.MockWebServer;
+
+import junit.framework.TestCase;
+
+import android.cts.util.FileUtils;
+import android.net.http.HttpResponseCache;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.CacheRequest;
+import java.net.CacheResponse;
+import java.net.ResponseCache;
+import java.net.URI;
+import java.net.URLConnection;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+public final class HttpResponseCacheTest extends TestCase {
+
+ private File cacheDir;
+ private MockWebServer server = new MockWebServer();
+
+ @Override public void setUp() throws Exception {
+ super.setUp();
+ String tmp = System.getProperty("java.io.tmpdir");
+ cacheDir = new File(tmp, "HttpCache-" + UUID.randomUUID());
+ cacheDir.mkdirs();
+ // Make the cache directory read / writable.
+ FileUtils.setPermissions(cacheDir.getPath(), 0777);
+ }
+
+ @Override protected void tearDown() throws Exception {
+ ResponseCache.setDefault(null);
+ server.shutdown();
+ super.tearDown();
+ }
+
+ public void testInstall() throws Exception {
+ HttpResponseCache installed = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ assertNotNull(installed);
+ assertSame(installed, ResponseCache.getDefault());
+ assertSame(installed, HttpResponseCache.getDefault());
+ }
+
+ public void testSecondEquivalentInstallDoesNothing() throws Exception {
+ HttpResponseCache first = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ HttpResponseCache another = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ assertSame(first, another);
+ }
+
+ public void testInstallClosesPreviouslyInstalled() throws Exception {
+ HttpResponseCache first = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ initializeCache(first);
+
+ HttpResponseCache another = HttpResponseCache.install(cacheDir, 8 * 1024 * 1024);
+ initializeCache(first);
+
+ assertNotSame(first, another);
+ try {
+ first.flush();
+ fail();
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ public void testGetInstalledWithWrongTypeInstalled() {
+ ResponseCache.setDefault(new ResponseCache() {
+ @Override public CacheResponse get(URI uri, String requestMethod,
+ Map<String, List<String>> requestHeaders) {
+ return null;
+ }
+ @Override public CacheRequest put(URI uri, URLConnection connection) {
+ return null;
+ }
+ });
+ assertNull(HttpResponseCache.getInstalled());
+ }
+
+ public void testCloseCloses() throws Exception {
+ HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ initializeCache(cache);
+
+ cache.close();
+ try {
+ cache.flush();
+ fail();
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ public void testCloseUninstalls() throws Exception {
+ HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ cache.close();
+ assertNull(ResponseCache.getDefault());
+ }
+
+ public void testDeleteUninstalls() throws Exception {
+ HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+ cache.delete();
+ assertNull(ResponseCache.getDefault());
+ }
+
+ /**
+ * Make sure that statistics tracking are wired all the way through the
+ * wrapper class. http://code.google.com/p/android/issues/detail?id=25418
+ */
+ public void testStatisticsTracking() throws Exception {
+ HttpResponseCache cache = HttpResponseCache.install(cacheDir, 10 * 1024 * 1024);
+
+ server.enqueue(new MockResponse()
+ .addHeader("Cache-Control: max-age=60")
+ .setBody("A"));
+ server.play();
+
+ URLConnection c1 = server.getUrl("/").openConnection();
+ InputStream inputStream1 = c1.getInputStream();
+ assertEquals('A', inputStream1.read());
+ inputStream1.close();
+
+ assertEquals(1, cache.getRequestCount());
+ assertEquals(1, cache.getNetworkCount());
+ assertEquals(0, cache.getHitCount());
+
+ URLConnection c2 = server.getUrl("/").openConnection();
+ assertEquals('A', c2.getInputStream().read());
+
+ URLConnection c3 = server.getUrl("/").openConnection();
+ assertEquals('A', c3.getInputStream().read());
+ assertEquals(3, cache.getRequestCount());
+ assertEquals(1, cache.getNetworkCount());
+ assertEquals(2, cache.getHitCount());
+ }
+
+ private void initializeCache(HttpResponseCache cache) {
+ // Ensure the cache is initialized, otherwise various methods are no-ops.
+ cache.size();
+ }
+}
diff --git a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
index eddb416..c23ad30 100644
--- a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
+++ b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java
@@ -155,7 +155,7 @@
public void testLoopbackPing() throws ErrnoException, IOException {
// Generate a random ping packet and send it to localhost.
InetAddress ipv6Loopback = InetAddress.getByName(null);
- assertEquals("localhost/::1", ipv6Loopback.toString());
+ assertEquals("::1", ipv6Loopback.getHostAddress());
for (int i = 0; i < NUM_PACKETS; i++) {
byte[] packet = pingPacket((int) (Math.random() * (MAX_SIZE - ICMP_HEADER_SIZE)));
diff --git a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
index d434728..e132cce 100644
--- a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java
@@ -372,8 +372,6 @@
assertTrue(lastEvent != null);
assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName));
- assertTrue(eventCacheSize() == 2);
-
// Register service again to see if we discover it
checkForAdditionalEvents();
clearEventCache();
@@ -405,7 +403,6 @@
lastEvent.mInfo.getServiceName());
assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName));
- assertTrue(checkCacheSize(2));
checkForAdditionalEvents();
clearEventCache();
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
index 6e395aa..2cc5951 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java
@@ -32,6 +32,10 @@
private static final String IDENTITY = "identity";
private static final String PASSWORD = "password";
private static final String SUBJECT_MATCH = "subjectmatch";
+ private static final String ALT_SUBJECT_MATCH = "altsubjectmatch";
+ private static final String DOM_SUBJECT_MATCH = "domsubjectmatch";
+ private static final String PLMN = "plmn";
+ private static final String REALM = "realm";
private static final String ANON_IDENTITY = "anonidentity";
private static final int ENABLE_DELAY = 10000;
@@ -87,6 +91,15 @@
config.setClientKeyEntry(null, null);
config.setSubjectMatch(SUBJECT_MATCH);
assertTrue(config.getSubjectMatch().equals(SUBJECT_MATCH));
+ // Hotspot 2.0 related attributes
+ config.setPlmn(PLMN);
+ assertTrue(config.getPlmn().equals(PLMN));
+ config.setRealm(REALM);
+ assertTrue(config.getRealm().equals(REALM));
+ config.setAltSubjectMatch(ALT_SUBJECT_MATCH);
+ assertTrue(config.getAltSubjectMatch().equals(ALT_SUBJECT_MATCH));
+ config.setDomainSuffixMatch(DOM_SUBJECT_MATCH);
+ assertTrue(config.getDomainSuffixMatch().equals(DOM_SUBJECT_MATCH));
}
public void testAddEapNetwork() {