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

Commit d5c2df10 authored by Kihong Seong's avatar Kihong Seong Committed by Gerrit Code Review
Browse files

Merge "Add additional tests for classes in package hfp"

parents 722ae701 8d0ac9e0
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.bluetooth.hfp;

import static com.google.common.truth.Truth.assertThat;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class HeadsetAgIndicatorEnableStateTest {

    @Test
    public void hashCode_returnsCorrectResult() {
        HeadsetAgIndicatorEnableState state = new HeadsetAgIndicatorEnableState(true, true, true,
                true);

        assertThat(state.hashCode()).isEqualTo(15);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -992,6 +992,13 @@ public class HeadsetServiceTest {
        Assert.assertEquals(null, mHeadsetService.getActiveDevice());
    }

    @Test
    public void testDump_doesNotCrash() {
        StringBuilder sb = new StringBuilder();

        mHeadsetService.dump(sb);
    }

    /*
     *  Helper function to test okToAcceptConnection() method
     *
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.bluetooth.hfp;

import static com.google.common.truth.Truth.assertThat;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class HeadsetStackEventTest {

    @Test
    public void getTypeString() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = adapter.getRemoteDevice("00:01:02:03:04:05");

        HeadsetStackEvent event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_NONE, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_NONE");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED,
                device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_CONNECTION_STATE_CHANGED");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_AUDIO_STATE_CHANGED");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_VR_STATE_CHANGED, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_VR_STATE_CHANGED");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_ANSWER_CALL, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_ANSWER_CALL");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_HANGUP_CALL, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_HANGUP_CALL");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_VOLUME_CHANGED, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_VOLUME_CHANGED");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_DIAL_CALL, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_DIAL_CALL");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_SEND_DTMF, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_SEND_DTMF");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_NOISE_REDUCTION, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_NOISE_REDUCTION");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AT_CHLD, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_AT_CHLD");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST,
                device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_SUBSCRIBER_NUMBER_REQUEST");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AT_CIND, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_AT_CIND");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AT_COPS, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_AT_COPS");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AT_CLCC, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_AT_CLCC");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_UNKNOWN_AT, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_UNKNOWN_AT");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_KEY_PRESSED, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_KEY_PRESSED");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_WBS, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_WBS");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIND, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_BIND");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIEV, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_BIEV");

        event = new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIA, device);
        assertThat(event.getTypeString()).isEqualTo("EVENT_TYPE_BIA");

        int unknownType = 21;
        event = new HeadsetStackEvent(unknownType, device);
        assertThat(event.getTypeString()).isEqualTo("UNKNOWN");
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -1427,6 +1427,13 @@ public class HeadsetStateMachineTest {
        verify(mockAudioManager).setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO, 2, 0);
    }

    @Test
    public void testDump_doesNotCrash() {
        StringBuilder sb = new StringBuilder();

        mHeadsetStateMachine.dump(sb);
    }

    /**
     * Setup Connecting State
     * @return number of times mHeadsetService.sendBroadcastAsUser() has been invoked