summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/ApacheHttpTests.java13
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/CursorWindowTest.java2
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/SSLClientSessionCacheFactoryTest.java54
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/SafeSaxTest.java2
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/SimplePullParserTest.java132
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/TestHttpServer.java207
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/TestHttpService.java608
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/TimeTest.java81
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/UrlRulesTest.java120
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/ExportTestResolver.java35
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardVerifier.java31
-rw-r--r--tests/BrowserTestPlugin/jni/main.cpp5
-rw-r--r--tests/FrameworkTest/tests/src/android/widget/SimpleCursorAdapterTest.java2
-rw-r--r--tests/FrameworkTest/tests/src/com/android/frameworktest/gridview/touch/GridTouchVerticalSpacingStackFromBottomTest.java8
-rw-r--r--tests/appwidgets/AppWidgetHostTest/Android.mk2
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/Android.mk2
-rw-r--r--tests/framework-tests/src/android/util/EventLogFunctionalTest.java36
-rw-r--r--tests/framework-tests/src/android/util/EventLogTest.java4
-rw-r--r--tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java61
19 files changed, 226 insertions, 1179 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/ApacheHttpTests.java b/tests/AndroidTests/src/com/android/unit_tests/ApacheHttpTests.java
deleted file mode 100644
index cf759e0..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/ApacheHttpTests.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.android.unit_tests;
-
-import junit.framework.TestSuite;
-
-public class ApacheHttpTests {
- public static TestSuite suite() {
- TestSuite suite = new TestSuite(ApacheHttpTests.class.getName());
-
- suite.addTestSuite(TestHttpService.class);
-
- return suite;
- }
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/CursorWindowTest.java b/tests/AndroidTests/src/com/android/unit_tests/CursorWindowTest.java
index d9068c8..0247355 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/CursorWindowTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/CursorWindowTest.java
@@ -18,7 +18,7 @@ package com.android.unit_tests;
import android.database.AbstractCursor;
import android.test.suitebuilder.annotation.SmallTest;
-import com.android.internal.database.ArrayListCursor;
+import com.android.common.ArrayListCursor;
import android.database.CursorWindow;
import android.test.PerformanceTestCase;
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SSLClientSessionCacheFactoryTest.java b/tests/AndroidTests/src/com/android/unit_tests/SSLClientSessionCacheFactoryTest.java
deleted file mode 100644
index 5d7349f..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/SSLClientSessionCacheFactoryTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.android.unit_tests;
-
-import com.google.android.net.SSLClientSessionCacheFactory;
-import com.android.internal.net.DbSSLSessionCache;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.Settings;
-import org.apache.harmony.xnet.provider.jsse.SSLClientSessionCache;
-
-/**
- * Unit test for {@link SSLClientSessionCacheFactory}.
- */
-@MediumTest
-public final class SSLClientSessionCacheFactoryTest extends AndroidTestCase {
-
- protected void tearDown() throws Exception {
- setSslSessionCacheValue(getContext(), "");
- super.tearDown();
- }
-
- private static void setSslSessionCacheValue(Context context, String value) {
- ContentResolver resolver = context.getContentResolver();
- Settings.Gservices.putString(resolver, Settings.Gservices.SSL_SESSION_CACHE, value);
- }
-
- private static SSLClientSessionCache getCache(Context context, String type) {
- setSslSessionCacheValue(context, type);
- return SSLClientSessionCacheFactory.getCache(context);
- }
-
- public void testGetDbCache() throws Exception {
- Context context = getContext();
- SSLClientSessionCache cache = getCache(context, "db");
- assertNotNull(cache);
- assertTrue(cache instanceof DbSSLSessionCache);
- }
-
- public void testGetFileCache() throws Exception {
- Context context = getContext();
- SSLClientSessionCache cache = getCache(context, "file");
- assertNotNull(cache);
- // yuck =)
- assertEquals("org.apache.harmony.xnet.provider.jsse.FileClientSessionCache$Impl",
- cache.getClass().getName());
- }
-
- public void testGetNoCache() throws Exception {
- Context context = getContext();
- SSLClientSessionCache cache = getCache(context, "none");
- assertNull(cache);
- }
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SafeSaxTest.java b/tests/AndroidTests/src/com/android/unit_tests/SafeSaxTest.java
index d488a29..8ccd26e 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/SafeSaxTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/SafeSaxTest.java
@@ -29,7 +29,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.text.format.Time;
import android.util.Log;
import android.util.Xml;
-import com.android.internal.util.XmlUtils;
+import com.android.common.XmlUtils;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
diff --git a/tests/AndroidTests/src/com/android/unit_tests/SimplePullParserTest.java b/tests/AndroidTests/src/com/android/unit_tests/SimplePullParserTest.java
deleted file mode 100644
index 9758298..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/SimplePullParserTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.unit_tests;
-
-import com.google.android.util.SimplePullParser;
-import junit.framework.TestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-public class SimplePullParserTest extends TestCase {
- @SmallTest
- public void testTwoLevels() throws Exception {
- String xml = ""
- + "<top a='1' b='hello'>\n"
- + " <next c='2' d='there'/>\n"
- + " <next c='3' d='bye'/>\n"
- + "</top>";
- SimplePullParser parser = new SimplePullParser(xml);
- int depth0 = parser.getDepth();
- assertEquals(0, depth0);
- assertEquals("top", parser.nextTag(depth0));
- assertEquals(1, parser.getIntAttribute(null, "a"));
- assertEquals("hello", parser.getStringAttribute(null, "b"));
-
- int depth1 = parser.getDepth();
- assertEquals(1, depth1);
- assertEquals("next", parser.nextTag(depth1));
- assertEquals(2, parser.getIntAttribute(null, "c"));
- assertEquals("there", parser.getStringAttribute(null, "d"));
- assertEquals("next", parser.nextTag(depth1));
- assertEquals(3, parser.getIntAttribute(null, "c"));
- assertEquals("bye", parser.getStringAttribute(null, "d"));
- assertNull(parser.nextTag(depth1));
-
- assertNull(parser.nextTag(depth0));
- }
-
- @SmallTest
- public void testAttributes() throws Exception {
- String xml = "<top a='1' b='hello'/>";
- SimplePullParser parser = new SimplePullParser(xml);
- int depth = parser.getDepth();
- parser.nextTag(depth);
-
- assertEquals(2, parser.numAttributes());
- assertEquals("a", parser.getAttributeName(0));
- assertEquals("b", parser.getAttributeName(1));
-
- assertEquals(1, parser.getIntAttribute(null, "a"));
- assertEquals(5, parser.getIntAttribute(null, "c", 5));
- assertEquals("hello", parser.getStringAttribute(null, "b"));
- assertEquals("not", parser.getStringAttribute(null, "d", "not"));
- }
-
- @SmallTest
- public void testRecovery() throws Exception {
- String xml = ""
- + "<top a='1' b='hello'>\n"
- + " <middle c='2' d='there'>\n"
- + " <inner/>\n"
- + " <inner2/>\n"
- + " <inner3/>\n"
- + " </middle>\n"
- + " <middle2/>\n"
- + "</top>";
- SimplePullParser parser = new SimplePullParser(xml);
- assertEquals(0, parser.getDepth());
- assertEquals("top", parser.nextTag(0));
- assertEquals(1, parser.getDepth());
- assertEquals("middle", parser.nextTag(1));
- assertEquals(2, parser.getDepth());
- assertEquals("inner", parser.nextTag(2));
- // Now skip some elements.
- assertEquals("middle2", parser.nextTag(1));
- }
-
- @SmallTest
- public void testCdata() throws Exception {
- StringBuilder cdataBuilder;
- String xml = ""
- + "<top>"
- + "<![CDATA[data0]]>"
- + "<next0/>"
- + "<![CDATA[data1]]>"
- + "<next1/>"
- + "<![CDATA[data2]]>"
- + "<next2/>"
- + "<![CDATA[data3]]>"
- + "<next3/>"
- + "<![CDATA[data4]]>"
- + "<next4/>"
- + "<![CDATA[data5]]>"
- + "</top>";
- SimplePullParser parser = new SimplePullParser(xml);
- assertEquals("top", parser.nextTag(0));
-
- // We can ignore cdata by not passing a cdata builder.
- assertEquals("next0", parser.nextTag(1));
-
- // We can get the most recent cdata by passing an empty cdata builder.
- cdataBuilder = new StringBuilder();
- assertSame(SimplePullParser.TEXT_TAG, parser.nextTagOrText(1, cdataBuilder));
- assertEquals("data1", cdataBuilder.toString());
- assertEquals("next1", parser.nextTag(1));
-
- // We can join multiple cdatas by reusing a builder.
- cdataBuilder = new StringBuilder();
- assertSame(SimplePullParser.TEXT_TAG, parser.nextTagOrText(1, cdataBuilder));
- assertEquals("next2", parser.nextTag(1));
- assertSame(SimplePullParser.TEXT_TAG, parser.nextTagOrText(1, cdataBuilder));
- assertEquals("data2data3", cdataBuilder.toString());
- assertEquals("next3", parser.nextTag(1));
-
- // We can read all of the remaining cdata while ignoring any elements.
- cdataBuilder = new StringBuilder();
- parser.readRemainingText(1, cdataBuilder);
- assertEquals("data4data5", cdataBuilder.toString());
- }
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/TestHttpServer.java b/tests/AndroidTests/src/com/android/unit_tests/TestHttpServer.java
deleted file mode 100644
index aae21b3..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/TestHttpServer.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha6/module-main/src/test/java/org/apache/http/mockup/TestHttpServer.java $
- * $Revision: 576077 $
- * $Date: 2007-09-16 04:50:22 -0700 (Sun, 16 Sep 2007) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package com.android.unit_tests;
-
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-import org.apache.http.ConnectionClosedException;
-import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpException;
-import org.apache.http.HttpResponseFactory;
-import org.apache.http.HttpServerConnection;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.protocol.BasicHttpProcessor;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpExpectationVerifier;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.HttpRequestHandlerRegistry;
-import org.apache.http.protocol.HttpService;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
-
-public class TestHttpServer {
-
- private final HttpParams params;
- private final BasicHttpProcessor httpproc;
- private final ConnectionReuseStrategy connStrategy;
- private final HttpResponseFactory responseFactory;
- private final HttpRequestHandlerRegistry reqistry;
- private final ServerSocket serversocket;
-
- private HttpExpectationVerifier expectationVerifier;
-
- private Thread listener;
- private volatile boolean shutdown;
-
- public TestHttpServer() throws IOException {
- super();
- this.params = new BasicHttpParams();
- this.params
- .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000)
- .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
- .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
- .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
- .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1");
- this.httpproc = new BasicHttpProcessor();
- this.httpproc.addInterceptor(new ResponseDate());
- this.httpproc.addInterceptor(new ResponseServer());
- this.httpproc.addInterceptor(new ResponseContent());
- this.httpproc.addInterceptor(new ResponseConnControl());
- this.connStrategy = new DefaultConnectionReuseStrategy();
- this.responseFactory = new DefaultHttpResponseFactory();
- this.reqistry = new HttpRequestHandlerRegistry();
- this.serversocket = new ServerSocket(0);
- }
-
- public void registerHandler(
- final String pattern,
- final HttpRequestHandler handler) {
- this.reqistry.register(pattern, handler);
- }
-
- public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) {
- this.expectationVerifier = expectationVerifier;
- }
-
- private HttpServerConnection acceptConnection() throws IOException {
- Socket socket = this.serversocket.accept();
- DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
- conn.bind(socket, this.params);
- return conn;
- }
-
- public int getPort() {
- return this.serversocket.getLocalPort();
- }
-
- public InetAddress getInetAddress() {
- return this.serversocket.getInetAddress();
- }
-
- public void start() {
- if (this.listener != null) {
- throw new IllegalStateException("Listener already running");
- }
- this.listener = new Thread(new Runnable() {
-
- public void run() {
- while (!shutdown && !Thread.interrupted()) {
- try {
- // Set up HTTP connection
- HttpServerConnection conn = acceptConnection();
- // Set up the HTTP service
- HttpService httpService = new HttpService(
- httpproc,
- connStrategy,
- responseFactory);
- httpService.setParams(params);
- httpService.setExpectationVerifier(expectationVerifier);
- httpService.setHandlerResolver(reqistry);
-
- // Start worker thread
- Thread t = new WorkerThread(httpService, conn);
- t.setDaemon(true);
- t.start();
- } catch (InterruptedIOException ex) {
- break;
- } catch (IOException e) {
- break;
- }
- }
- }
-
- });
- this.listener.start();
- }
-
- public void shutdown() {
- if (this.shutdown) {
- return;
- }
- this.shutdown = true;
- try {
- this.serversocket.close();
- } catch (IOException ignore) {}
- this.listener.interrupt();
- try {
- this.listener.join(1000);
- } catch (InterruptedException ignore) {}
- }
-
- static class WorkerThread extends Thread {
-
- private final HttpService httpservice;
- private final HttpServerConnection conn;
-
- public WorkerThread(
- final HttpService httpservice,
- final HttpServerConnection conn) {
- super();
- this.httpservice = httpservice;
- this.conn = conn;
- }
-
- public void run() {
- HttpContext context = new BasicHttpContext(null);
- try {
- while (!Thread.interrupted() && this.conn.isOpen()) {
- this.httpservice.handleRequest(this.conn, context);
- }
- } catch (ConnectionClosedException ex) {
- } catch (IOException ex) {
- System.err.println("I/O error: " + ex.getMessage());
- } catch (HttpException ex) {
- System.err.println("Unrecoverable HTTP protocol violation: " + ex.getMessage());
- } finally {
- try {
- this.conn.shutdown();
- } catch (IOException ignore) {}
- }
- }
-
- }
-
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/TestHttpService.java b/tests/AndroidTests/src/com/android/unit_tests/TestHttpService.java
deleted file mode 100644
index 6b57d13..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/TestHttpService.java
+++ /dev/null
@@ -1,608 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha6/module-main/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java $
- * $Revision: 576073 $
- * $Date: 2007-09-16 03:53:13 -0700 (Sun, 16 Sep 2007) $
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package com.android.unit_tests;
-
-import org.apache.http.protocol.HttpExpectationVerifier;
-import org.apache.http.protocol.HttpRequestHandler;
-import android.test.PerformanceTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.test.suitebuilder.annotation.MediumTest;
-
-import junit.framework.TestCase;
-
-import org.apache.http.Header;
-import org.apache.http.HttpConnectionMetrics;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.DefaultHttpClientConnection;
-import org.apache.http.message.BasicHttpEntityEnclosingRequest;
-import org.apache.http.message.BasicHttpRequest;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.EncodingUtils;
-import org.apache.http.util.EntityUtils;
-
-
-import java.io.IOException;
-import java.net.Socket;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-public class TestHttpService extends TestCase implements PerformanceTestCase {
-
- public boolean isPerformanceOnly() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public int startPerformance(Intermediates intermediates) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- private TestHttpServer server;
- private TestHttpClient client;
-
- protected void setUp() throws Exception {
- this.server = new TestHttpServer();
- this.client = new TestHttpClient();
- }
-
- protected void tearDown() throws Exception {
- if (server != null) {
- this.server.shutdown();
- }
- }
-
- /**
- * This test case executes a series of simple GET requests
- */
- @LargeTest
- public void testSimpleBasicHttpRequests() throws Exception {
-
- int reqNo = 20;
-
- Random rnd = new Random();
-
- // Prepare some random data
- final List testData = new ArrayList(reqNo);
- for (int i = 0; i < reqNo; i++) {
- int size = rnd.nextInt(5000);
- byte[] data = new byte[size];
- rnd.nextBytes(data);
- testData.add(data);
- }
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- String s = request.getRequestLine().getUri();
- if (s.startsWith("/?")) {
- s = s.substring(2);
- }
- int index = Integer.parseInt(s);
- byte[] data = (byte []) testData.get(index);
- ByteArrayEntity entity = new ByteArrayEntity(data);
- response.setEntity(entity);
- }
-
- });
-
- this.server.start();
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpRequest get = new BasicHttpRequest("GET", "/?" + r);
- HttpResponse response = this.client.execute(get, host, conn);
- byte[] received = EntityUtils.toByteArray(response.getEntity());
- byte[] expected = (byte[]) testData.get(r);
-
- assertEquals(expected.length, received.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], received[i]);
- }
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
-
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
-
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
- /**
- * This test case executes a series of simple POST requests with content length
- * delimited content.
- */
- @LargeTest
- public void testSimpleHttpPostsWithContentLength() throws Exception {
-
- int reqNo = 20;
-
- Random rnd = new Random();
-
- // Prepare some random data
- List testData = new ArrayList(reqNo);
- for (int i = 0; i < reqNo; i++) {
- int size = rnd.nextInt(5000);
- byte[] data = new byte[size];
- rnd.nextBytes(data);
- testData.add(data);
- }
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
- byte[] data = EntityUtils.toByteArray(incoming);
-
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(false);
- response.setEntity(outgoing);
- } else {
- StringEntity outgoing = new StringEntity("No content");
- response.setEntity(outgoing);
- }
- }
-
- });
-
- this.server.start();
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
- byte[] data = (byte[]) testData.get(r);
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- post.setEntity(outgoing);
-
- HttpResponse response = this.client.execute(post, host, conn);
- byte[] received = EntityUtils.toByteArray(response.getEntity());
- byte[] expected = (byte[]) testData.get(r);
-
- assertEquals(expected.length, received.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], received[i]);
- }
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
-
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
- /**
- * This test case executes a series of simple POST requests with chunk
- * coded content content.
- */
- @LargeTest
- public void testSimpleHttpPostsChunked() throws Exception {
-
- int reqNo = 20;
-
- Random rnd = new Random();
-
- // Prepare some random data
- List testData = new ArrayList(reqNo);
- for (int i = 0; i < reqNo; i++) {
- int size = rnd.nextInt(20000);
- byte[] data = new byte[size];
- rnd.nextBytes(data);
- testData.add(data);
- }
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
- byte[] data = EntityUtils.toByteArray(incoming);
-
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(true);
- response.setEntity(outgoing);
- } else {
- StringEntity outgoing = new StringEntity("No content");
- response.setEntity(outgoing);
- }
- }
-
- });
-
- this.server.start();
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
- byte[] data = (byte[]) testData.get(r);
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(true);
- post.setEntity(outgoing);
-
- HttpResponse response = this.client.execute(post, host, conn);
- byte[] received = EntityUtils.toByteArray(response.getEntity());
- byte[] expected = (byte[]) testData.get(r);
-
- assertEquals(expected.length, received.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], received[i]);
- }
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
- /**
- * This test case executes a series of simple HTTP/1.0 POST requests.
- */
- @LargeTest
- public void testSimpleHttpPostsHTTP10() throws Exception {
-
- int reqNo = 20;
-
- Random rnd = new Random();
-
- // Prepare some random data
- List testData = new ArrayList(reqNo);
- for (int i = 0; i < reqNo; i++) {
- int size = rnd.nextInt(5000);
- byte[] data = new byte[size];
- rnd.nextBytes(data);
- testData.add(data);
- }
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
- byte[] data = EntityUtils.toByteArray(incoming);
-
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(false);
- response.setEntity(outgoing);
- } else {
- StringEntity outgoing = new StringEntity("No content");
- response.setEntity(outgoing);
- }
- }
-
- });
-
- this.server.start();
-
- // Set protocol level to HTTP/1.0
- this.client.getParams().setParameter(
- CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
- byte[] data = (byte[]) testData.get(r);
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- post.setEntity(outgoing);
-
- HttpResponse response = this.client.execute(post, host, conn);
- assertEquals(HttpVersion.HTTP_1_0, response.getStatusLine().getProtocolVersion());
- byte[] received = EntityUtils.toByteArray(response.getEntity());
- byte[] expected = (byte[]) testData.get(r);
-
- assertEquals(expected.length, received.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], received[i]);
- }
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
-
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
- /**
- * This test case executes a series of simple POST requests using
- * the 'expect: continue' handshake.
- */
- @LargeTest
- public void testHttpPostsWithExpectContinue() throws Exception {
-
- int reqNo = 20;
-
- Random rnd = new Random();
-
- // Prepare some random data
- List testData = new ArrayList(reqNo);
- for (int i = 0; i < reqNo; i++) {
- int size = rnd.nextInt(5000);
- byte[] data = new byte[size];
- rnd.nextBytes(data);
- testData.add(data);
- }
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
- byte[] data = EntityUtils.toByteArray(incoming);
-
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(true);
- response.setEntity(outgoing);
- } else {
- StringEntity outgoing = new StringEntity("No content");
- response.setEntity(outgoing);
- }
- }
-
- });
-
- this.server.start();
-
- // Activate 'expect: continue' handshake
- this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
- byte[] data = (byte[]) testData.get(r);
- ByteArrayEntity outgoing = new ByteArrayEntity(data);
- outgoing.setChunked(true);
- post.setEntity(outgoing);
-
- HttpResponse response = this.client.execute(post, host, conn);
- byte[] received = EntityUtils.toByteArray(response.getEntity());
- byte[] expected = (byte[]) testData.get(r);
-
- assertEquals(expected.length, received.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], received[i]);
- }
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
-
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
-
- /**
- * This test case executes a series of simple POST requests that do not
- * meet the target server expectations.
- */
- @LargeTest
- public void testHttpPostsWithExpectationVerification() throws Exception {
-
- int reqNo = 3;
-
- // Initialize the server-side request handler
- this.server.registerHandler("*", new HttpRequestHandler() {
-
- public void handle(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- StringEntity outgoing = new StringEntity("No content");
- response.setEntity(outgoing);
- }
-
- });
-
- this.server.setExpectationVerifier(new HttpExpectationVerifier() {
-
- public void verify(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException {
- Header someheader = request.getFirstHeader("Secret");
- if (someheader != null) {
- int secretNumber;
- try {
- secretNumber = Integer.parseInt(someheader.getValue());
- } catch (NumberFormatException ex) {
- response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
- return;
- }
- if (secretNumber < 2) {
- response.setStatusCode(HttpStatus.SC_EXPECTATION_FAILED);
- ByteArrayEntity outgoing = new ByteArrayEntity(
- EncodingUtils.getAsciiBytes("Wrong secret number"));
- response.setEntity(outgoing);
- }
- }
- }
-
- });
-
- this.server.start();
-
- // Activate 'expect: continue' handshake
- this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
-
- DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- HttpHost host = new HttpHost("localhost", this.server.getPort());
-
- try {
- for (int r = 0; r < reqNo; r++) {
- if (!conn.isOpen()) {
- Socket socket = new Socket(host.getHostName(), host.getPort());
- conn.bind(socket, this.client.getParams());
- }
-
- BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
- post.addHeader("Secret", Integer.toString(r));
- ByteArrayEntity outgoing = new ByteArrayEntity(
- EncodingUtils.getAsciiBytes("No content"));
- post.setEntity(outgoing);
-
- HttpResponse response = this.client.execute(post, host, conn);
-
- HttpEntity entity = response.getEntity();
- assertNotNull(entity);
- entity.consumeContent();
-
- if (r < 2) {
- assertEquals(HttpStatus.SC_EXPECTATION_FAILED, response.getStatusLine().getStatusCode());
- } else {
- assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- }
-
- if (!this.client.keepAlive(response)) {
- conn.close();
- }
- }
- //Verify the connection metrics
- HttpConnectionMetrics cm = conn.getMetrics();
- assertEquals(reqNo, cm.getRequestCount());
- assertEquals(reqNo, cm.getResponseCount());
- } finally {
- conn.close();
- this.server.shutdown();
- }
- }
-
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/TimeTest.java b/tests/AndroidTests/src/com/android/unit_tests/TimeTest.java
index 110caa4..3b33a99 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/TimeTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/TimeTest.java
@@ -20,6 +20,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.Suppress;
import android.text.format.Time;
import android.util.Log;
+import android.util.TimeFormatException;
import junit.framework.TestCase;
@@ -354,6 +355,86 @@ public class TimeTest extends TestCase {
}
@SmallTest
+ public void testParse33390() throws Exception {
+ Time t = new Time(Time.TIMEZONE_UTC);
+
+ t.parse3339("1980-05-23");
+ if (!t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23) {
+ fail("Did not parse all-day date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != 0) {
+ fail("Did not parse timezone-offset-less date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50Z");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != 0) {
+ fail("Did not parse UTC date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50.0Z");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != 0) {
+ fail("Did not parse UTC date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50.12Z");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != 0) {
+ fail("Did not parse UTC date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50.123Z");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != 0) {
+ fail("Did not parse UTC date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50-06:00");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != -6*3600) {
+ fail("Did not parse timezone-offset date correctly");
+ }
+
+ t.parse3339("1980-05-23T09:50:50.123-06:00");
+ if (t.allDay || t.year != 1980 || t.month != 05 || t.monthDay != 23 ||
+ t.hour != 9 || t.minute != 50 || t.second != 50 ||
+ t.gmtoff != -6*3600) {
+ fail("Did not parse timezone-offset date correctly");
+ }
+
+ try {
+ t.parse3339("1980");
+ fail("Did not throw error on truncated input length");
+ } catch (TimeFormatException e) {
+ // Successful
+ }
+
+ try {
+ t.parse3339("1980-05-23T09:50:50.123+");
+ fail("Did not throw error on truncated timezone offset");
+ } catch (TimeFormatException e1) {
+ // Successful
+ }
+
+ try {
+ t.parse3339("1980-05-23T09:50:50.123+05:0");
+ fail("Did not throw error on truncated timezone offset");
+ } catch (TimeFormatException e1) {
+ // Successful
+ }
+ }
+
+ @SmallTest
public void testSet0() throws Exception {
Time t = new Time(Time.TIMEZONE_UTC);
t.set(1000L);
diff --git a/tests/AndroidTests/src/com/android/unit_tests/UrlRulesTest.java b/tests/AndroidTests/src/com/android/unit_tests/UrlRulesTest.java
deleted file mode 100644
index a7c19a7..0000000
--- a/tests/AndroidTests/src/com/android/unit_tests/UrlRulesTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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 com.android.unit_tests;
-
-import android.content.ContentResolver;
-import android.provider.Settings;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.google.android.net.UrlRules;
-import static com.google.android.net.UrlRules.Rule;
-
-/** Test loading and matching URL rewrite rules for UrlRules. */
-public class UrlRulesTest extends AndroidTestCase {
- @SmallTest
- public void testEmptyRules() {
- UrlRules rules = new UrlRules(new Rule[] { });
- assertTrue(rules.matchRule("http://foo.bar/") == Rule.DEFAULT);
- }
-
- @SmallTest
- public void testInvalidRule() throws Exception {
- try {
- new Rule("rule", "foo bar");
- } catch (Exception e) {
- // Re-throw any exception except the one we're looking for.
- if (!e.toString().contains("Illegal rule: foo bar")) throw e;
- }
- }
-
- @SmallTest
- public void testRewriteRule() throws UrlRules.RuleFormatException {
- Rule rule = new Rule("test_rule",
- "http://foo.bar/ rewrite http://bar.foo/");
- assertEquals("test_rule", rule.mName);
- assertEquals("http://foo.bar/", rule.mPrefix);
- assertEquals("http://bar.foo/", rule.mRewrite);
- assertFalse(rule.mBlock);
- assertEquals("http://bar.foo/bat", rule.apply("http://foo.bar/bat"));
- }
-
- @SmallTest
- public void testBlockRule() throws UrlRules.RuleFormatException {
- Rule rule = new Rule("test_rule",
- "http://foo.bar/ block");
- assertEquals("test_rule", rule.mName);
- assertEquals("http://foo.bar/", rule.mPrefix);
- assertTrue(rule.mRewrite == null);
- assertTrue(rule.mBlock);
- assertTrue(rule.apply("http://foo.bar/bat") == null);
- }
-
- @SmallTest
- public void testMatchRule() throws UrlRules.RuleFormatException {
- UrlRules rules = new UrlRules(new Rule[] {
- new Rule("12", "http://one.two/ rewrite http://buckle.my.shoe/"),
- new Rule("34", "http://three.four/ rewrite http://close.the.door/"),
- new Rule("56", "http://five.six/ rewrite http://pick.up.sticks/"),
- });
-
- assertTrue(rules.matchRule("https://one.two/") == Rule.DEFAULT);
- assertTrue(rules.matchRule("http://one.two") == Rule.DEFAULT);
- assertEquals("12", rules.matchRule("http://one.two/foo").mName);
-
- String u = "http://five.six/bar";
- assertEquals("http://pick.up.sticks/bar", rules.matchRule(u).apply(u));
- }
-
- @SmallTest
- public void testAmbiguousMatch() throws UrlRules.RuleFormatException {
- // Rule is the longest match wins.
- UrlRules rules = new UrlRules(new Rule[] {
- new Rule("1", "http://xyz/one rewrite http://rewrite/"),
- new Rule("123", "http://xyz/onetwothree rewrite http://rewrite/"),
- new Rule("12", "http://xyz/onetwo rewrite http://rewrite/"),
- });
-
- assertEquals("1", rules.matchRule("http://xyz/one").mName);
- assertEquals("1", rules.matchRule("http://xyz/one...").mName);
- assertEquals("12", rules.matchRule("http://xyz/onetwo...").mName);
- assertEquals("123", rules.matchRule("http://xyz/onetwothree...").mName);
-
- }
-
- @MediumTest
- public void testGservicesRules() {
- // TODO: use a MockContentProvider/MockContentResolver instead.
- ContentResolver r = getContext().getContentResolver();
-
- // Update the digest, so the UrlRules cache is reloaded.
- Settings.Gservices.putString(r, "digest", "testGservicesRules");
- Settings.Gservices.putString(r, "url:blank_test", "");
- Settings.Gservices.putString(r, "url:test",
- "http://foo.bar/ rewrite http://bar.foo/");
-
- UrlRules rules = UrlRules.getRules(r); // Don't crash, please. :)
- assertTrue(rules.matchRule("http://bar.foo/") == Rule.DEFAULT);
-
- Rule rule = rules.matchRule("http://foo.bar/bat");
- assertEquals("test", rule.mName);
- assertEquals("http://foo.bar/", rule.mPrefix);
- assertEquals("http://bar.foo/", rule.mRewrite);
- assertFalse(rule.mBlock);
- }
-}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/ExportTestResolver.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/ExportTestResolver.java
index 38aed6f..a76dfd8 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/ExportTestResolver.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/ExportTestResolver.java
@@ -110,8 +110,41 @@ import java.util.List;
return contactEntry;
}
+ /**
+ * <p>
+ * An old method which had existed but was removed from ContentResolver.
+ * </p>
+ * <p>
+ * We still keep using this method since we don't have a propeer way to know
+ * which value in the ContentValue corresponds to the entry in Contacts database.
+ * </p>
+ * <p>
+ * Detail:
+ * There's an easy way to know which index "family name" corresponds to, via
+ * {@link android.provider.ContactsContract}.
+ * FAMILY_NAME equals DATA3, so the corresponding index
+ * for "family name" should be 2 (note that index is 0-origin).
+ * However, we cannot know what the index 2 corresponds to; it may be "family name",
+ * "label" for now, but may be the other some column in the future. We don't have
+ * convenient way to know the original data structure.
+ * </p>
+ */
+ public EntityIterator queryEntities(Uri uri,
+ String selection, String[] selectionArgs, String sortOrder) {
+ mTestCase.assertTrue(uri != null);
+ mTestCase.assertTrue(ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()));
+ final String authority = uri.getAuthority();
+ mTestCase.assertTrue(RawContacts.CONTENT_URI.getAuthority().equals(authority));
+ mTestCase.assertTrue((Data.CONTACT_ID + "=?").equals(selection));
+ mTestCase.assertEquals(1, selectionArgs.length);
+ final int id = Integer.parseInt(selectionArgs[0]);
+ mTestCase.assertTrue(id >= 0 && id < mContactEntryList.size());
+
+ return new MockEntityIterator(mContactEntryList.get(id).getList());
+ }
+
@Override
- public Cursor query(Uri uri, String[] projection,
+ public Cursor query(Uri uri,String[] projection,
String selection, String[] selectionArgs, String sortOrder) {
mTestCase.assertTrue(VCardComposer.CONTACTS_TEST_CONTENT_URI.equals(uri));
// In this test, following arguments are not supported.
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardVerifier.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardVerifier.java
index e5cdf63..4b97750 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardVerifier.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardVerifier.java
@@ -15,8 +15,11 @@
*/
package com.android.unit_tests.vcard;
+import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.EntityIterator;
+import android.net.Uri;
import android.pim.vcard.VCardComposer;
import android.pim.vcard.VCardConfig;
import android.pim.vcard.VCardEntryConstructor;
@@ -32,6 +35,7 @@ import android.test.mock.MockContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Method;
import java.util.Arrays;
/* package */ class CustomMockContext extends MockContext {
@@ -259,8 +263,24 @@ import java.util.Arrays;
}
}
+ public static EntityIterator mockGetEntityIteratorMethod(
+ final ContentResolver resolver,
+ final Uri uri, final String selection,
+ final String[] selectionArgs, final String sortOrder) {
+ final ContentProvider provider =
+ resolver.acquireContentProviderClient(uri).getLocalContentProvider();
+ return ((ExportTestProvider)provider).queryEntities(
+ uri, selection, selectionArgs, sortOrder);
+ }
+
+ private Method getMockGetEntityIteratorMethod()
+ throws SecurityException, NoSuchMethodException {
+ return this.getClass().getMethod("mockGetEntityIteratorMethod",
+ ContentResolver.class, Uri.class, String.class, String[].class, String.class);
+ }
+
private void verifyForExportTest() {
- VCardComposer composer =
+ final VCardComposer composer =
new VCardComposer(new CustomMockContext(mExportTestResolver), mVCardType);
composer.addHandler(mLineVerifier);
composer.addHandler(mVCardVerifierInternal);
@@ -270,7 +290,14 @@ import java.util.Arrays;
mTestCase.assertFalse(composer.isAfterLast());
try {
while (!composer.isAfterLast()) {
- mTestCase.assertTrue(composer.createOneEntry());
+ try {
+ final Method mockGetEntityIteratorMethod = getMockGetEntityIteratorMethod();
+ mTestCase.assertTrue(
+ composer.createOneEntry(getMockGetEntityIteratorMethod()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ mTestCase.fail();
+ }
}
} finally {
composer.terminate();
diff --git a/tests/BrowserTestPlugin/jni/main.cpp b/tests/BrowserTestPlugin/jni/main.cpp
index c896ad5..586d139 100644
--- a/tests/BrowserTestPlugin/jni/main.cpp
+++ b/tests/BrowserTestPlugin/jni/main.cpp
@@ -168,7 +168,10 @@ NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
NPError NPP_Destroy(NPP instance, NPSavedData** save)
{
PluginObject *obj = (PluginObject*) instance->pdata;
- delete obj->subPlugin;
+ if (obj) {
+ delete obj->subPlugin;
+ browser->releaseobject(&obj->header);
+ }
return NPERR_NO_ERROR;
}
diff --git a/tests/FrameworkTest/tests/src/android/widget/SimpleCursorAdapterTest.java b/tests/FrameworkTest/tests/src/android/widget/SimpleCursorAdapterTest.java
index 58f4ccb..7726f02 100644
--- a/tests/FrameworkTest/tests/src/android/widget/SimpleCursorAdapterTest.java
+++ b/tests/FrameworkTest/tests/src/android/widget/SimpleCursorAdapterTest.java
@@ -16,7 +16,7 @@
package android.widget;
-import com.android.internal.database.ArrayListCursor;
+import com.android.common.ArrayListCursor;
import com.google.android.collect.Lists;
import android.content.Context;
diff --git a/tests/FrameworkTest/tests/src/com/android/frameworktest/gridview/touch/GridTouchVerticalSpacingStackFromBottomTest.java b/tests/FrameworkTest/tests/src/com/android/frameworktest/gridview/touch/GridTouchVerticalSpacingStackFromBottomTest.java
index cc8fa6e..d11a39ba 100644
--- a/tests/FrameworkTest/tests/src/com/android/frameworktest/gridview/touch/GridTouchVerticalSpacingStackFromBottomTest.java
+++ b/tests/FrameworkTest/tests/src/com/android/frameworktest/gridview/touch/GridTouchVerticalSpacingStackFromBottomTest.java
@@ -16,6 +16,7 @@
package com.android.frameworktest.gridview.touch;
+import android.content.Context;
import android.test.ActivityInstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
@@ -30,6 +31,7 @@ import com.android.frameworktest.gridview.GridVerticalSpacingStackFromBottom;
public class GridTouchVerticalSpacingStackFromBottomTest extends ActivityInstrumentationTestCase<GridVerticalSpacingStackFromBottom> {
private GridVerticalSpacingStackFromBottom mActivity;
private GridView mGridView;
+ private ViewConfiguration mViewConfig;
public GridTouchVerticalSpacingStackFromBottomTest() {
super("com.android.frameworktest", GridVerticalSpacingStackFromBottom.class);
@@ -41,6 +43,8 @@ public class GridTouchVerticalSpacingStackFromBottomTest extends ActivityInstrum
mActivity = getActivity();
mGridView = getActivity().getGridView();
+ final Context context = mActivity.getApplicationContext();
+ mViewConfig = ViewConfiguration.get(context);
}
@MediumTest
@@ -83,7 +87,7 @@ public class GridTouchVerticalSpacingStackFromBottomTest extends ActivityInstrum
int lastTop = lastChild.getTop();
TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
- ViewConfiguration.getTouchSlop() + 1 + 10);
+ mViewConfig.getScaledTouchSlop() + 1 + 10);
View newLastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
@@ -107,7 +111,7 @@ public class GridTouchVerticalSpacingStackFromBottomTest extends ActivityInstrum
(int) (mActivity.getWindowManager().getDefaultDisplay().getHeight() * 0.75f));
assertEquals("View scrolled to wrong position", firstTop
- + (distance - ViewConfiguration.getTouchSlop() - 1), firstChild.getTop());
+ + (distance - mViewConfig.getScaledTouchSlop() - 1), firstChild.getTop());
}
@LargeTest
diff --git a/tests/appwidgets/AppWidgetHostTest/Android.mk b/tests/appwidgets/AppWidgetHostTest/Android.mk
index 1bb1e54..4d0c704 100644
--- a/tests/appwidgets/AppWidgetHostTest/Android.mk
+++ b/tests/appwidgets/AppWidgetHostTest/Android.mk
@@ -1,7 +1,7 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE_TAGS := user
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
diff --git a/tests/appwidgets/AppWidgetProviderTest/Android.mk b/tests/appwidgets/AppWidgetProviderTest/Android.mk
index c87a0f2..6084fb9 100644
--- a/tests/appwidgets/AppWidgetProviderTest/Android.mk
+++ b/tests/appwidgets/AppWidgetProviderTest/Android.mk
@@ -1,7 +1,7 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE_TAGS := user
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
diff --git a/tests/framework-tests/src/android/util/EventLogFunctionalTest.java b/tests/framework-tests/src/android/util/EventLogFunctionalTest.java
index 8263083..8afe35f 100644
--- a/tests/framework-tests/src/android/util/EventLogFunctionalTest.java
+++ b/tests/framework-tests/src/android/util/EventLogFunctionalTest.java
@@ -59,31 +59,21 @@ public class EventLogFunctionalTest extends TestCase {
}
public void testLogOfListWithOneInt() throws Exception {
- final EventLog.List list = new EventLog.List(1234);
- final int numBytes = EventLog.writeEvent(TEST_TAG, list);
+ final int numBytes = EventLog.writeEvent(TEST_TAG, new Object[] {1234});
Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1, numBytes);
}
public void testLogOfListWithMultipleInts() throws Exception {
- final EventLog.List list = new EventLog.List(1234, 2345, 3456);
- final int numBytes = EventLog.writeEvent(TEST_TAG, list);
+ final int numBytes = EventLog.writeEvent(TEST_TAG, new Object[] {1234, 2345, 3456});
Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + 1 + 4 + 1 + 4 + 1 + 4 + 1, numBytes);
}
- public void testLogOfListWithEmbeddedList() throws Exception {
- final EventLog.List list = new EventLog.List(
- new EventLog.List(1234, 2345, 3456));
- final int numBytes = EventLog.writeEvent(TEST_TAG, list);
- Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 2 + 1 + 1 + 4 + 1 + 4 + 1 + 4 + 1, numBytes);
- }
-
public void testEventLargerThanInitialBufferCapacity() throws Exception {
final Integer[] array = new Integer[127];
for (int i = 0; i < array.length; i++) {
array[i] = i;
}
- final EventLog.List list = new EventLog.List((Object[]) array);
- final int numBytes = EventLog.writeEvent(TEST_TAG, list);
+ final int numBytes = EventLog.writeEvent(TEST_TAG, (Object[]) array);
Assert.assertEquals(STARTING_POS_OF_PAYLOAD + 1 + (5 * array.length) + 1, numBytes);
}
@@ -117,8 +107,7 @@ public class EventLogFunctionalTest extends TestCase {
// This test is obsolete. See http://b/issue?id=1262082
public void disableTestReadCompoundEntry() throws Exception {
long when = System.currentTimeMillis();
- EventLog.writeEvent(2719,
- new EventLog.List(1l, new EventLog.List("2", "three", "4"), 5));
+ EventLog.writeEvent(2719, 1l, "2", 3);
Log.i(TAG, "Wrote compound event at T=" + when);
ArrayList<EventLog.Event> list = new ArrayList<EventLog.Event>();
@@ -129,18 +118,11 @@ public class EventLogFunctionalTest extends TestCase {
long eventTime = event.getTimeNanos() / 1000000;
Log.i(TAG, " Found event T=" + eventTime);
if (eventTime > when - 100 && eventTime < when + 1000) {
- EventLog.List data = (EventLog.List) event.getData();
- assertEquals(data.getNumItems(), 3);
-
- EventLog.List nested = (EventLog.List) data.getItem(1);
- assertEquals(nested.getNumItems(), 3);
-
- assertEquals(data.getItem(0), 1l);
- assertEquals(nested.getItem(0), "2");
- assertEquals(nested.getItem(1), "three");
- assertEquals(nested.getItem(2), "4");
- assertEquals(data.getItem(2), 5);
-
+ Object[] data = (Object[]) event.getData();
+ assertEquals(data.length, 3);
+ assertEquals(data[0], 1l);
+ assertEquals(data[1], "2");
+ assertEquals(data[2], 3);
assertFalse(found);
found = true;
}
diff --git a/tests/framework-tests/src/android/util/EventLogTest.java b/tests/framework-tests/src/android/util/EventLogTest.java
index 4a5d888..2a9e9cd 100644
--- a/tests/framework-tests/src/android/util/EventLogTest.java
+++ b/tests/framework-tests/src/android/util/EventLogTest.java
@@ -33,13 +33,13 @@ public class EventLogTest extends TestCase {
public void testIllegalListTypesThrowException() throws Exception {
try {
- EventLog.writeEvent(TEST_TAG, new EventLog.List(new Object()));
+ EventLog.writeEvent(TEST_TAG, new Object[]{new Object()});
fail("Can't create List with any old Object");
} catch (IllegalArgumentException e) {
// expected
}
try {
- EventLog.writeEvent(TEST_TAG, new EventLog.List((byte) 1));
+ EventLog.writeEvent(TEST_TAG, new Object[]{(byte) 1});
fail("Can't create List with any old byte");
} catch (IllegalArgumentException e) {
// expected
diff --git a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java b/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java
index 8e3a034..4d016d1 100644
--- a/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java
+++ b/tests/framework-tests/src/com/android/internal/os/LoggingPrintStreamTest.java
@@ -18,12 +18,12 @@ package com.android.internal.os;
import junit.framework.TestCase;
-import java.util.Arrays;
-import java.util.List;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
-import java.io.StringWriter;
-import java.io.PrintWriter;
+import java.util.List;
public class LoggingPrintStreamTest extends TestCase {
@@ -121,6 +121,58 @@ public class LoggingPrintStreamTest extends TestCase {
assertEquals(Arrays.asList("Foo", "4", "a"), out.lines);
}
+ public void testMultiByteCharactersSpanningBuffers() throws Exception {
+ // assume 3*1000 bytes won't fit in LoggingPrintStream's internal buffer
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 1000; i++) {
+ builder.append("\u20AC"); // a Euro character; 3 bytes in UTF-8
+ }
+ String expected = builder.toString();
+
+ out.write(expected.getBytes("UTF-8"));
+ out.flush();
+ assertEquals(Arrays.asList(expected), out.lines);
+ }
+
+ public void testWriteOneByteAtATimeMultibyteCharacters() throws Exception {
+ String expected = " \u20AC \u20AC \u20AC \u20AC ";
+ for (byte b : expected.getBytes()) {
+ out.write(b);
+ }
+ out.flush();
+ assertEquals(Arrays.asList(expected), out.lines);
+ }
+
+ public void testWriteByteArrayAtATimeMultibyteCharacters() throws Exception {
+ String expected = " \u20AC \u20AC \u20AC \u20AC ";
+ out.write(expected.getBytes());
+ out.flush();
+ assertEquals(Arrays.asList(expected), out.lines);
+ }
+
+ public void testWriteWithOffsetsMultibyteCharacters() throws Exception {
+ String expected = " \u20AC \u20AC \u20AC \u20AC ";
+ byte[] bytes = expected.getBytes();
+ int i = 0;
+ while (i < bytes.length - 5) {
+ out.write(bytes, i, 5);
+ i += 5;
+ }
+ out.write(bytes, i, bytes.length - i);
+ out.flush();
+ assertEquals(Arrays.asList(expected), out.lines);
+ }
+
+ public void testWriteFlushesOnNewlines() throws Exception {
+ String a = " \u20AC \u20AC ";
+ String b = " \u20AC \u20AC ";
+ String c = " ";
+ String toWrite = a + "\n" + b + "\n" + c;
+ out.write(toWrite.getBytes());
+ out.flush();
+ assertEquals(Arrays.asList(a, b, c), out.lines);
+ }
+
static class TestPrintStream extends LoggingPrintStream {
final List<String> lines = new ArrayList<String>();
@@ -129,5 +181,4 @@ public class LoggingPrintStreamTest extends TestCase {
lines.add(line);
}
}
-
}