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

Commit b9cfae71 authored by Kihong Seong's avatar Kihong Seong
Browse files

Add tests for classes in package hfp

This CL adds tests for:
- HeadsetClccResponse
- HeadsetVendorSpecificResultCode

Bug: 237467631
Test: Ran each test with atest
Change-Id: I6a6584782f385febe209fc2e7e36c6d720113486
parent 2324ad0d
Loading
Loading
Loading
Loading
+83 −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 HeadsetClccResponseTest {
    private static final int TEST_INDEX = 1;
    private static final int TEST_DIRECTION = 1;
    private static final int TEST_STATUS = 1;
    private static final int TEST_MODE = 1;
    private static final boolean TEST_MPTY = true;
    private static final String TEST_NUMBER = "111-1111-1111";
    private static final int TEST_TYPE = 1;

    @Test
    public void constructor() {
        HeadsetClccResponse response = new HeadsetClccResponse(TEST_INDEX, TEST_DIRECTION,
                TEST_STATUS, TEST_MODE, TEST_MPTY, TEST_NUMBER, TEST_TYPE);

        assertThat(response.mIndex).isEqualTo(TEST_INDEX);
        assertThat(response.mDirection).isEqualTo(TEST_DIRECTION);
        assertThat(response.mStatus).isEqualTo(TEST_STATUS);
        assertThat(response.mMode).isEqualTo(TEST_MODE);
        assertThat(response.mMpty).isEqualTo(TEST_MPTY);
        assertThat(response.mNumber).isEqualTo(TEST_NUMBER);
        assertThat(response.mType).isEqualTo(TEST_TYPE);
    }

    @Test
    public void buildString() {
        HeadsetClccResponse response = new HeadsetClccResponse(TEST_INDEX, TEST_DIRECTION,
                TEST_STATUS, TEST_MODE, TEST_MPTY, TEST_NUMBER, TEST_TYPE);
        StringBuilder builder = new StringBuilder();

        response.buildString(builder);

        String expectedString =
                response.getClass().getSimpleName() + "[index=" + TEST_INDEX + ", direction="
                        + TEST_DIRECTION + ", status=" + TEST_STATUS + ", callMode=" + TEST_MODE
                        + ", isMultiParty=" + TEST_MPTY + ", number=" + "***" + ", type="
                        + TEST_TYPE + "]";
        assertThat(response.toString()).isEqualTo(expectedString);
    }

    @Test
    public void buildString_withNoNumber() {
        HeadsetClccResponse response = new HeadsetClccResponse(TEST_INDEX, TEST_DIRECTION,
                TEST_STATUS, TEST_MODE, TEST_MPTY, null, TEST_TYPE);
        StringBuilder builder = new StringBuilder();

        response.buildString(builder);

        String expectedString =
                response.getClass().getSimpleName() + "[index=" + TEST_INDEX + ", direction="
                        + TEST_DIRECTION + ", status=" + TEST_STATUS + ", callMode=" + TEST_MODE
                        + ", isMultiParty=" + TEST_MPTY + ", number=" + "null" + ", type="
                        + TEST_TYPE + "]";
        assertThat(response.toString()).isEqualTo(expectedString);
    }
}
+69 −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.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class HeadsetVendorSpecificResultCodeTest {
    private static final String TEST_COMMAND = "test_command";
    private static final String TEST_ARG = "test_arg";

    private BluetoothAdapter mAdapter;
    private BluetoothDevice mTestDevice;

    @Before
    public void setUp() {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mTestDevice = mAdapter.getRemoteDevice("00:01:02:03:04:05");
    }

    @Test
    public void constructor() {
        HeadsetVendorSpecificResultCode code = new HeadsetVendorSpecificResultCode(mTestDevice,
                TEST_COMMAND, TEST_ARG);

        assertThat(code.mDevice).isEqualTo(mTestDevice);
        assertThat(code.mCommand).isEqualTo(TEST_COMMAND);
        assertThat(code.mArg).isEqualTo(TEST_ARG);
    }

    @Test
    public void buildString() {
        HeadsetVendorSpecificResultCode code = new HeadsetVendorSpecificResultCode(mTestDevice,
                TEST_COMMAND, TEST_ARG);
        StringBuilder builder = new StringBuilder();

        code.buildString(builder);

        String expectedString =
                code.getClass().getSimpleName() + "[device=" + mTestDevice + ", command="
                        + TEST_COMMAND + ", arg=" + TEST_ARG + "]";
        assertThat(builder.toString()).isEqualTo(expectedString);
    }
}