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

Commit 1db39ed6 authored by Ajay Panicker's avatar Ajay Panicker Committed by android-build-merger
Browse files

Merge "Remove all old Bluetooth tests" am: 6cf3e270

am: 8a400b2f

Change-Id: I450aacdde9737670863adf37beef40686b66c709
parents 6706cb31 8a400b2f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

# We only want this apk build for tests.
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform

LOCAL_JAVA_LIBRARIES := javax.obex android.test.runner telephony-common libprotobuf-java-micro
+0 −22
Original line number Diff line number Diff line

package com.android.bluetooth.gatt;

import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.bluetooth.gatt.GattService;

/**
 * Test cases for {@link GattService}.
 */
public class GattServiceTest extends AndroidTestCase {

    @SmallTest
    public void testParseBatchTimestamp() {
        GattService service = new GattService();
        long timestampNanos = service.parseTimestampNanos(new byte[] {
                -54, 7 });
        assertEquals(99700000000L, timestampNanos);
    }

}
+0 −876

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −166
Original line number Diff line number Diff line
package com.android.bluetooth.tests;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.test.AndroidTestCase;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.android.bluetooth.mapapi.BluetoothMapContract;

public class BluetoothMapIMContentTest extends AndroidTestCase {
    private static final String TAG = "BluetoothMapIMContentTest";

    private static final boolean D = true;
    private static final boolean V = true;

    private Context mContext;
    private ContentResolver mResolver;

    private String getDateTimeString(long timestamp) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
        Date date = new Date(timestamp);
        return format.format(date); // Format to YYYYMMDDTHHMMSS local time
    }

    private void printCursor(Cursor c) {
        StringBuilder sb = new StringBuilder();
        sb.append("\nprintCursor:\n");
        for(int i = 0; i < c.getColumnCount(); i++) {
            if(c.getColumnName(i).equals(BluetoothMapContract.MessageColumns.DATE) ||
               c.getColumnName(i).equals(BluetoothMapContract.ConversationColumns.LAST_THREAD_ACTIVITY) ||
               c.getColumnName(i).equals(BluetoothMapContract.ChatStatusColumns.LAST_ACTIVE) ||
               c.getColumnName(i).equals(BluetoothMapContract.PresenceColumns.LAST_ONLINE) ){
                sb.append("  ").append(c.getColumnName(i)).append(" : ").append(getDateTimeString(c.getLong(i))).append("\n");
            } else {
                sb.append("  ").append(c.getColumnName(i)).append(" : ").append(c.getString(i)).append("\n");
            }
        }
        Log.d(TAG, sb.toString());
    }

    private void dumpImMessageTable() {
        Log.d(TAG, "**** Dump of im message table ****");

        Cursor c = mResolver.query(
                BluetoothMapContract.buildMessageUri("info.guardianproject.otr.app.im.provider.bluetoothprovider"),
                BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, null, null, "_id DESC");
        if (c != null) {
            Log.d(TAG, "c.getCount() = " + c.getCount());
            c.moveToPosition(-1);
            while (c.moveToNext()) {
                printCursor(c);
            }
        } else {
            Log.d(TAG, "query failed");
            c.close();
        }

    }

    private void insertImMessage( ) {
        Log.d(TAG, "**** Insert message in im message table ****");
        ContentValues cv = new ContentValues();
        cv.put(BluetoothMapContract.MessageColumns.BODY, "This is a test to insert a message");
        cv.put(BluetoothMapContract.MessageColumns.DATE, System.currentTimeMillis());
        cv.put(BluetoothMapContract.MessageColumns.THREAD_ID, 2);
        Uri uri = BluetoothMapContract.buildMessageUri("info.guardianproject.otr.app.im.provider.bluetoothprovider");
        Uri uriWithId = mResolver.insert(uri, cv);
        if (uriWithId != null) {
            Log.d(TAG, "uriWithId = " + uriWithId.toString());
        } else {
            Log.d(TAG, "query failed");
        }

    }

    private void dumpImConversationTable() {
        Log.d(TAG, "**** Dump of conversation message table ****");

        Uri uri = BluetoothMapContract.buildConversationUri(
                "info.guardianproject.otr.app.im.provider.bluetoothprovider", "1");
        uri = uri.buildUpon().appendQueryParameter(BluetoothMapContract.FILTER_ORIGINATOR_SUBSTRING,
                "asp").build();

        Cursor convo = mResolver.query(
                uri,
                BluetoothMapContract.BT_CONVERSATION_PROJECTION, null, null,
                null);

        if (convo != null) {
            Log.d(TAG, "c.getCount() = " + convo.getCount());

            while(convo.moveToNext()) {
                printCursor(convo);
            }
            convo.close();
        } else {
            Log.d(TAG, "query failed");
        }
    }


    private void dumpImContactsTable() {
        Log.d(TAG, "**** Dump of contacts message table ****");
        Cursor cContact = mResolver.query(
                BluetoothMapContract.buildConvoContactsUri("info.guardianproject.otr.app.im.provider.bluetoothprovider","1"),
                BluetoothMapContract.BT_CONTACT_CHATSTATE_PRESENCE_PROJECTION, null, null, "_id DESC");

        if (cContact != null && cContact.moveToFirst()) {
            Log.d(TAG, "c.getCount() = " +  cContact.getCount());
            do {
                printCursor(cContact);
            } while(cContact.moveToNext());

        } else {
            Log.d(TAG, "query failed");
            cContact.close();
        }
    }

    private void dumpImAccountsTable() {
        Log.d(TAG, "**** Dump of accounts table ****");
        Cursor cContact = mResolver.query(
                BluetoothMapContract.buildAccountUri("info.guardianproject.otr.app.im.provider.bluetoothprovider"),
                BluetoothMapContract.BT_ACCOUNT_PROJECTION, null, null, "_id DESC");

        if (cContact != null && cContact.moveToFirst()) {
            Log.d(TAG, "c.getCount() = " +  cContact.getCount());
            do {
                printCursor(cContact);
            } while(cContact.moveToNext());

        } else {
            Log.d(TAG, "query failed");
            cContact.close();
        }
    }


    public BluetoothMapIMContentTest() {
        super();
    }

    public void testDumpMessages() {
        mContext = this.getContext();
        mResolver = mContext.getContentResolver();
        dumpImMessageTable();
        dumpImConversationTable();
        dumpImContactsTable();
        dumpImAccountsTable();

        insertImMessage();

    }

    public void testDumpConversations() {
        mContext = this.getContext();
        mResolver = mContext.getContentResolver();
        dumpImConversationTable();
    }
}
+0 −113
Original line number Diff line number Diff line

package com.android.bluetooth.tests;

import android.test.AndroidTestCase;
import android.util.Log;

import java.io.UnsupportedEncodingException;

import com.android.bluetooth.SignedLongLong;
import com.android.bluetooth.map.BluetoothMapUtils;

public class BluetoothMapUtilsTest extends AndroidTestCase {
    private static final String TAG = "BluetoothMapUtilsTest";

    private static final boolean D = true;
    private static final boolean V = true;
    private static final String encText1 = "=?UTF-8?b?w6bDuMOlw4bDmMOF?="; //æøåÆØÅ base64
    private static final String encText2 = "=?UTF-8?B?w6bDuMOlw4bDmMOF?="; //æøåÆØÅ base64
    private static final String encText3 = "=?UTF-8?q?=C3=A6=C3=B8=C3=A5=C3=86=C3=98=C3=85?="; //æøåÆØÅ QP
    private static final String encText4 = "=?UTF-8?Q?=C3=A6=C3=B8=C3=A5=C3=86=C3=98=C3=85?="; //æøåÆØÅ QP
    private static final String encText5 = "=?UTF-8?B?=C3=A6=C3=B8=C3=A5=C3=86=C3=98=C3=85?="; //QP in base64 string - should not compute
    private static final String encText6 = "=?UTF-8?Q?w6bDuMOlw4bDmMOF?="; //æøåÆØÅ base64 in QP stirng - should not compute
    private static final String encText7 = "this is a split =?UTF-8?Q?=C3=A6=C3=B8=C3=A5 ###123?= with more =?UTF-8?Q?=C3=A6=C3=B8=C3=A5 ###123?= inside"; // mix of QP and normal
    private static final String encText8 = "this is a split =?UTF-8?B?w6bDuMOlICMjIzEyMw==?= with more =?UTF-8?Q?=C3=A6=C3=B8=C3=A5 ###123?= inside"; // mix of normal, QP and Base64
    private static final String encText9 = "=?UTF-8?Q??=";
    private static final String encText10 = "=?UTF-8?Q??=";
    private static final String encText11 = "=?UTF-8?Q??=";

    private static final String decText1 = "æøåÆØÅ";
    private static final String decText2 = "æøåÆØÅ";
    private static final String decText3 = "æøåÆØÅ";
    private static final String decText4 = "æøåÆØÅ";
    private static final String decText5 = encText5;
    private static final String decText6 = "w6bDuMOlw4bDmMOF";
    private static final String decText7 = "this is a split æøå ###123 with more æøå ###123 inside";
    private static final String decText8 = "this is a split æøå ###123 with more æøå ###123 inside";

    public BluetoothMapUtilsTest() {
        super();

    }


    public void testEncoder(){
        assertTrue(BluetoothMapUtils.stripEncoding(encText1).equals(decText1));
        assertTrue(BluetoothMapUtils.stripEncoding(encText2).equals(decText2));
        assertTrue(BluetoothMapUtils.stripEncoding(encText3).equals(decText3));
        assertTrue(BluetoothMapUtils.stripEncoding(encText4).equals(decText4));
        assertTrue(BluetoothMapUtils.stripEncoding(encText5).equals(decText5));
        assertTrue(BluetoothMapUtils.stripEncoding(encText6).equals(decText6));
        Log.i(TAG,"##############################enc7:" +
                BluetoothMapUtils.stripEncoding(encText7));
        assertTrue(BluetoothMapUtils.stripEncoding(encText7).equals(decText7));
        assertTrue(BluetoothMapUtils.stripEncoding(encText8).equals(decText8));
    }

    public void testXBtUid() throws UnsupportedEncodingException {
        {
            SignedLongLong expected = new SignedLongLong(0x12345678L, 0x90abcdefL);
            /* this will cause an exception, since the value is too big... */
            SignedLongLong value;
            value = SignedLongLong.fromString("90abcdef0000000012345678");
            assertTrue("expected: " + expected + " value = " + value,
                    0 == value.compareTo(expected));
            assertEquals("expected: " + expected + " value = " + value,
                    expected.toHexString(), value.toHexString());
            Log.i(TAG,"Succesfully compared : " + value);
        }
        {
            SignedLongLong expected = new SignedLongLong(0x12345678L, 0xfedcba9890abcdefL);
            /* this will cause an exception, since the value is too big... */
            SignedLongLong value;
            value = SignedLongLong.fromString("fedcba9890abcdef0000000012345678");
            assertTrue("expected: " + expected + " value = " + value,
                    0 == value.compareTo(expected));
            assertEquals("expected: " + expected + " value = " + value,
                    expected.toHexString(), value.toHexString());
            Log.i(TAG,"Succesfully compared : " + value);
        }
        {
            SignedLongLong expected = new SignedLongLong(0x12345678L, 0);
            SignedLongLong value = SignedLongLong.fromString("000012345678");
            assertTrue("expected: " + expected + " value = " + value,
                    0 == value.compareTo(expected));
            assertEquals("expected: " + expected + " value = " + value,
                    expected.toHexString(), value.toHexString());
            Log.i(TAG,"Succesfully compared : " + value);
        }
        {
            SignedLongLong expected = new SignedLongLong(0x12345678L, 0);
            SignedLongLong value = SignedLongLong.fromString("12345678");
            assertTrue("expected: " + expected + " value = " + value,
                    0 == value.compareTo(expected));
            assertEquals("expected: " + expected + " value = " + value,
                    expected.toHexString(), value.toHexString());
            Log.i(TAG,"Succesfully compared : " + value);
        }
        {
            SignedLongLong expected = new SignedLongLong(0x123456789abcdef1L, 0x9L);
            SignedLongLong value = SignedLongLong.fromString("0009123456789abcdef1");
            assertTrue("expected: " + expected + " value = " + value,
                    0 == value.compareTo(expected));
            assertEquals("expected: " + expected + " value = " + value,
                    expected.toHexString(), value.toHexString());
            Log.i(TAG,"Succesfully compared : " + value);
        }
        {
            long expected = 0x123456789abcdefL;
            long value = BluetoothMapUtils.getLongFromString(" 1234 5678 9abc-def");
            assertTrue("expected: " + expected + " value = " + value, value == expected);
        }
    }
}
Loading