summaryrefslogtreecommitdiff
path: root/library/test
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2014-04-22 11:12:54 +0200
committerYohann Roussel <yroussel@google.com>2014-06-26 13:32:34 +0000
commit7b86f7e21c70ac06129c05ed137e585a308c6fd1 (patch)
tree4682904f9b6f1c92a96dace9e00f339b42a60f4e /library/test
parent5bb7b0d3c370c0fb43ae5ce77d4ec328970db697 (diff)
downloadmultidex-7b86f7e21c70ac06129c05ed137e585a308c6fd1.tar.gz
Deactivate the library if vm version is 2.1 or newer.
It was decided that it would be the revision of multidex native support and that it is the criterion that should be used to discriminate between VMs capable of multidex and others. Bug 14238145. See bug 10447095 for discussions about the deactivation criterion. Change-Id: I50922972d1d5b3019a111d5a1b4f2f18af9713ed
Diffstat (limited to 'library/test')
-rw-r--r--library/test/src/android/support/multidex/MultiDexTest.java47
-rw-r--r--library/test/src/android/util/Log.java225
2 files changed, 272 insertions, 0 deletions
diff --git a/library/test/src/android/support/multidex/MultiDexTest.java b/library/test/src/android/support/multidex/MultiDexTest.java
new file mode 100644
index 0000000..62bdc30
--- /dev/null
+++ b/library/test/src/android/support/multidex/MultiDexTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2014 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.support.multidex;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {@link MultiDex} class.
+ */
+public class MultiDexTest {
+ @Test
+ public void testVersionCheck() {
+ Assert.assertFalse(MultiDex.isVMMultidexCapable(null));
+ Assert.assertFalse(MultiDex.isVMMultidexCapable("-1.32.54"));
+ Assert.assertFalse(MultiDex.isVMMultidexCapable("1.32.54"));
+ Assert.assertFalse(MultiDex.isVMMultidexCapable("1.32"));
+ Assert.assertFalse(MultiDex.isVMMultidexCapable("2.0"));
+ Assert.assertFalse(MultiDex.isVMMultidexCapable("2.000.1254"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("2.1.1254"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("2.1"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("2.2"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("2.1.0000"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("2.2.0000"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("002.0001.0010"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("3.0"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("3.0.0"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("3.0.1"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("3.1.0"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("03.1.132645"));
+ Assert.assertTrue(MultiDex.isVMMultidexCapable("03.2"));
+ }
+}
diff --git a/library/test/src/android/util/Log.java b/library/test/src/android/util/Log.java
new file mode 100644
index 0000000..b94e48b
--- /dev/null
+++ b/library/test/src/android/util/Log.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2006 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.util;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.UnknownHostException;
+
+/**
+ * Mock Log implementation for testing on non android host.
+ */
+public final class Log {
+
+ /**
+ * Priority constant for the println method; use Log.v.
+ */
+ public static final int VERBOSE = 2;
+
+ /**
+ * Priority constant for the println method; use Log.d.
+ */
+ public static final int DEBUG = 3;
+
+ /**
+ * Priority constant for the println method; use Log.i.
+ */
+ public static final int INFO = 4;
+
+ /**
+ * Priority constant for the println method; use Log.w.
+ */
+ public static final int WARN = 5;
+
+ /**
+ * Priority constant for the println method; use Log.e.
+ */
+ public static final int ERROR = 6;
+
+ /**
+ * Priority constant for the println method.
+ */
+ public static final int ASSERT = 7;
+
+ private Log() {
+ }
+
+ /**
+ * Send a {@link #VERBOSE} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int v(String tag, String msg) {
+ return println(LOG_ID_MAIN, VERBOSE, tag, msg);
+ }
+
+ /**
+ * Send a {@link #VERBOSE} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int v(String tag, String msg, Throwable tr) {
+ return println(LOG_ID_MAIN, VERBOSE, tag, msg + '\n' + getStackTraceString(tr));
+ }
+
+ /**
+ * Send a {@link #DEBUG} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int d(String tag, String msg) {
+ return println(LOG_ID_MAIN, DEBUG, tag, msg);
+ }
+
+ /**
+ * Send a {@link #DEBUG} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int d(String tag, String msg, Throwable tr) {
+ return println(LOG_ID_MAIN, DEBUG, tag, msg + '\n' + getStackTraceString(tr));
+ }
+
+ /**
+ * Send an {@link #INFO} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int i(String tag, String msg) {
+ return println(LOG_ID_MAIN, INFO, tag, msg);
+ }
+
+ /**
+ * Send a {@link #INFO} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int i(String tag, String msg, Throwable tr) {
+ return println(LOG_ID_MAIN, INFO, tag, msg + '\n' + getStackTraceString(tr));
+ }
+
+ /**
+ * Send a {@link #WARN} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int w(String tag, String msg) {
+ return println(LOG_ID_MAIN, WARN, tag, msg);
+ }
+
+ /**
+ * Send a {@link #WARN} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int w(String tag, String msg, Throwable tr) {
+ return println(LOG_ID_MAIN, WARN, tag, msg + '\n' + getStackTraceString(tr));
+ }
+
+ /*
+ * Send a {@link #WARN} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param tr An exception to log
+ */
+ public static int w(String tag, Throwable tr) {
+ return println(LOG_ID_MAIN, WARN, tag, getStackTraceString(tr));
+ }
+
+ /**
+ * Send an {@link #ERROR} log message.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ */
+ public static int e(String tag, String msg) {
+ return println(LOG_ID_MAIN, ERROR, tag, msg);
+ }
+
+ /**
+ * Send a {@link #ERROR} log message and log the exception.
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @param tr An exception to log
+ */
+ public static int e(String tag, String msg, Throwable tr) {
+ return println(LOG_ID_MAIN, ERROR, tag, msg + '\n' + getStackTraceString(tr));
+ }
+
+ /**
+ * Handy function to get a loggable stack trace from a Throwable
+ * @param tr An exception to log
+ */
+ public static String getStackTraceString(Throwable tr) {
+ if (tr == null) {
+ return "";
+ }
+
+ // This is to reduce the amount of log spew that apps do in the non-error
+ // condition of the network being unavailable.
+ Throwable t = tr;
+ while (t != null) {
+ if (t instanceof UnknownHostException) {
+ return "";
+ }
+ t = t.getCause();
+ }
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ tr.printStackTrace(pw);
+ pw.flush();
+ return sw.toString();
+ }
+
+ /**
+ * Low-level logging call.
+ * @param priority The priority/type of this log message
+ * @param tag Used to identify the source of a log message. It usually identifies
+ * the class or activity where the log call occurs.
+ * @param msg The message you would like logged.
+ * @return The number of bytes written.
+ */
+ public static int println(int priority, String tag, String msg) {
+ return println(LOG_ID_MAIN, priority, tag, msg);
+ }
+
+ /** @hide */ public static final int LOG_ID_MAIN = 0;
+ /** @hide */ public static final int LOG_ID_RADIO = 1;
+ /** @hide */ public static final int LOG_ID_EVENTS = 2;
+ /** @hide */ public static final int LOG_ID_SYSTEM = 3;
+ /** @hide */ public static final int LOG_ID_CRASH = 4;
+
+ /** @hide */ @SuppressWarnings("unused")
+ public static int println(int bufID,
+ int priority, String tag, String msg) {
+ return 0;
+ }
+}