Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fbfc627 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

CoreTests: Tidy up legacy tests.

(not to be confused with core/tests/FrameworksCoreTests.)

- JniLibTest: Completely broken, ther's no Jni lib to load.
- MiscRegressionTest: Doesn't test anything.
- Sha1Test: We have more systematic and complete benchmarks in libcore.

The Apache HTTP tests remain, and only because they are the only
remaining tests of the Apache HTTP lib. They will be moved to the apache
repository in a separate commit.

Also remove bogus dependencies on conscrypt and bouncycastle.

Bug: 73635411
Test: adb shell am instrument -w android.core/android.test.InstrumentationTestRunner

Change-Id: Ia3648da023ceabcb6023941961810516857c4f48
parent 89c32b38
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -7,14 +7,14 @@ LOCAL_SRC_FILES := \
	$(call all-subdir-java-files)

LOCAL_JAVA_LIBRARIES := \
    android.test.runner \
    bouncycastle \
    conscrypt \
    android.test.runner.stubs \
    org.apache.http.legacy \
    android.test.base \
    android.test.base.stubs \

LOCAL_SDK_VERSION := current

LOCAL_STATIC_JAVA_LIBRARIES := junit

LOCAL_PACKAGE_NAME := CoreTests
LOCAL_PACKAGE_NAME := LegacyCoreTests

include $(BUILD_PACKAGE)
+0 −59
Original line number Diff line number Diff line
/*
 * 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.core;

import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
import junit.framework.TestCase;


@Suppress
public class JniLibTest extends TestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        /*
         * This causes the native shared library to be loaded when the
         * class is first used.  The library is only loaded once, even if
         * multiple classes include this line.
         *
         * The library must be in java.library.path, which is derived from
         * LD_LIBRARY_PATH.  The actual library name searched for will be
         * "libjni_lib_test.so" under Linux, but may be different on other
         * platforms.
         */
        try {
            System.loadLibrary("jni_lib_test");
        } catch (UnsatisfiedLinkError ule) {
            Log.e("JniLibTest", "WARNING: Could not load jni_lib_test natives");
        }
    }

    private static native int nativeStaticThing(float f);
    private native void nativeThing(int val);

    public void testNativeCall() {
        Log.i("JniLibTest", "JNI search path is "
                + System.getProperty("java.library.path"));
        Log.i("JniLibTest", "'jni_lib_test' becomes '"
                + System.mapLibraryName("jni_lib_test") + "'");

        int result = nativeStaticThing(1234.5f);
        nativeThing(result);
    }
}
+0 −37
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.core;

import android.test.suitebuilder.annotation.MediumTest;
import java.util.logging.Logger;
import junit.framework.TestCase;

public class MiscRegressionTest extends TestCase {

    // Regression test for #951285: Suitable LogHandler should be chosen
    // depending on the environment.
    @MediumTest
    public void testAndroidLogHandler() throws Exception {
        Logger.global.severe("This has logging Level.SEVERE, should become ERROR");
        Logger.global.warning("This has logging Level.WARNING, should become WARN");
        Logger.global.info("This has logging Level.INFO, should become INFO");
        Logger.global.config("This has logging Level.CONFIG, should become DEBUG");
        Logger.global.fine("This has logging Level.FINE, should become VERBOSE");
        Logger.global.finer("This has logging Level.FINER, should become VERBOSE");
        Logger.global.finest("This has logging Level.FINEST, should become VERBOSE");
    }
}
+6 −7
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
import android.webkit.CookieSyncManager;
import com.google.android.collect.Maps;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -87,7 +86,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * header is attempted to be set
         */
        Log.d(LOGTAG, "testRequestAddNullHeader start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put(null, null);
        verifyFailure(headers);
        Log.d(LOGTAG, "testRequestAddNullHeader - returning");
@@ -99,7 +98,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * value is attempted to be set
         */
        Log.d(LOGTAG, "testRequestAddNullValue start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put("TestHeader", null);
        verifyFailure(headers);
        Log.d(LOGTAG, "testRequestAddNullValue - returning");
@@ -111,7 +110,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * header is attempted to be set
         */
        Log.d(LOGTAG, "testRequestAddEmptyValue start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put("TestHeader", "");
        verifyFailure(headers);
        Log.d(LOGTAG, "testRequestAddEmptyValue - returning");
@@ -131,7 +130,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * generating and exception
         */
        Log.d(LOGTAG, "testRequestAddHeader start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put("TestHeader", "RequestAddHeader");
        verifySuccess(headers);
        Log.d(LOGTAG, "testRequestAddHeader - returning");
@@ -143,7 +142,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * can be set without generating and exception
         */
        Log.d(LOGTAG, "testRequestAddMultiHeader start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put("TestHeader", "RequestAddMultiHeader");
        headers.put("TestHeader2", "RequestAddMultiHeader");
        headers.put("TestHeader3", "RequestAddMultiHeader");
@@ -157,7 +156,7 @@ public class RequestAPITest extends AndroidTestCase implements HttpConstants {
         * and values can be set without generating and exception
         */
        Log.d(LOGTAG, "testRequestAddSameHeader start ");
        Map<String, String> headers = Maps.newHashMap();
        Map<String, String> headers = new HashMap<>();
        headers.put("TestHeader", "RequestAddSameHeader");
        headers.put("TestHeader", "RequestAddSameHeader");
        headers.put("TestHeader", "RequestAddSameHeader");
+0 −69
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.core;

import android.test.suitebuilder.annotation.SmallTest;
import java.security.MessageDigest;
import junit.framework.TestCase;

/**
 * Tests SHA1 message digest algorithm.
 */
public class Sha1Test extends TestCase {
    class TestData {
        private String input;
        private String result;

        public TestData(String i, String r) {
            input = i;
            result = r;
        }
    }

    TestData[] mTestData = new TestData[]{
            new TestData("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"),
            new TestData("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
                    "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
    };

    @SmallTest
    public void testSha1() throws Exception {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");

        int numTests = mTestData.length;
        for (int i = 0; i < numTests; i++) {
            digest.update(mTestData[i].input.getBytes());
            byte[] hash = digest.digest();
            String encodedHash = encodeHex(hash);
            assertEquals(encodedHash, mTestData[i].result);
        }
    }

    private static String encodeHex(byte[] bytes) {
        StringBuffer hex = new StringBuffer(bytes.length * 2);

        for (int i = 0; i < bytes.length; i++) {
            if (((int) bytes[i] & 0xff) < 0x10) {
                hex.append("0");
            }
            hex.append(Integer.toString((int) bytes[i] & 0xff, 16));
        }

        return hex.toString();
    }
}