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

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

Add tests for classes in package avrcpcontroller

This CL adds tests for:
- RequestGetImage
- RequestGetImageProperties
- StackEvent

Bug: 237467631
Test: Ran each test with atest
Change-Id: I4d121e488167f1af97fa0bc73cdb6cb2b50d4899
(cherry picked from commit 0f6974b5)
parent 8c312386
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.bluetooth.avrcpcontroller;

import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.ClientSession;
import com.android.obex.HeaderSet;

@@ -29,7 +30,8 @@ import java.io.InputStream;
public class RequestGetImage extends BipRequest {
    // Expected inputs
    private final String mImageHandle;
    private final BipImageDescriptor mImageDescriptor;
    @VisibleForTesting
    final BipImageDescriptor mImageDescriptor;

    // Expected return type
    private static final String TYPE = "x-bt/img-img";
+65 −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.avrcpcontroller;

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 StackEventTest {

    @Test
    public void connectionStateChanged() {
        boolean remoteControlConnected = true;
        boolean browsingConnected = true;

        StackEvent stackEvent = StackEvent.connectionStateChanged(remoteControlConnected,
                browsingConnected);

        assertThat(stackEvent.mType).isEqualTo(StackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
        assertThat(stackEvent.mRemoteControlConnected).isTrue();
        assertThat(stackEvent.mBrowsingConnected).isTrue();
        assertThat(stackEvent.toString()).isEqualTo(
                "EVENT_TYPE_CONNECTION_STATE_CHANGED " + remoteControlConnected);
    }

    @Test
    public void rcFeatures() {
        int features = 3;

        StackEvent stackEvent = StackEvent.rcFeatures(features);

        assertThat(stackEvent.mType).isEqualTo(StackEvent.EVENT_TYPE_RC_FEATURES);
        assertThat(stackEvent.mFeatures).isEqualTo(features);
        assertThat(stackEvent.toString()).isEqualTo("EVENT_TYPE_RC_FEATURES");
    }

    @Test
    public void toString_whenEventTypeNone() {
        StackEvent stackEvent = StackEvent.rcFeatures(1);

        stackEvent.mType = StackEvent.EVENT_TYPE_NONE;

        assertThat(stackEvent.toString()).isEqualTo("Unknown");
    }
}
 No newline at end of file
+48 −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.avrcpcontroller;

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 RequestGetImagePropertiesTest {
    private static final String TEST_IMAGE_HANDLE = "test_image_handle";

    @Test
    public void constructor() {
        RequestGetImageProperties requestGetImageProperties = new RequestGetImageProperties(
                TEST_IMAGE_HANDLE);

        assertThat(requestGetImageProperties.getImageHandle()).isEqualTo(TEST_IMAGE_HANDLE);
    }

    @Test
    public void getType() {
        RequestGetImageProperties requestGetImageProperties = new RequestGetImageProperties(
                TEST_IMAGE_HANDLE);

        assertThat(requestGetImageProperties.getType()).isEqualTo(
                BipRequest.TYPE_GET_IMAGE_PROPERTIES);
    }
}
 No newline at end of file
+63 −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.avrcpcontroller;

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 RequestGetImageTest {
    private static final String TEST_IMAGE_HANDLE = "test_image_handle";
    private static final String sXmlDocDecl =
            "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\r\n";

    @Test
    public void constructor_withDescriptorNotNull() {
        BipImageDescriptor.Builder builder = new BipImageDescriptor.Builder();
        builder.setEncoding(BipEncoding.JPEG);
        builder.setFixedDimensions(1280, 960);
        BipImageDescriptor descriptor = builder.build();

        RequestGetImage requestGetImage = new RequestGetImage(TEST_IMAGE_HANDLE, descriptor);

        String expected = sXmlDocDecl + "<image-descriptor version=\"1.0\">\r\n"
                + "  <image encoding=\"JPEG\" pixel=\"1280*960\" />\r\n"
                + "</image-descriptor>";
        assertThat(requestGetImage.getImageHandle()).isEqualTo(TEST_IMAGE_HANDLE);
        assertThat(requestGetImage.mImageDescriptor.toString()).isEqualTo(expected);
    }

    @Test
    public void constructor_withDescriptorNull() {
        RequestGetImage requestGetImage = new RequestGetImage(TEST_IMAGE_HANDLE, null);

        assertThat(requestGetImage.getImageHandle()).isEqualTo(TEST_IMAGE_HANDLE);
    }

    @Test
    public void getType() {
        RequestGetImage requestGetImage = new RequestGetImage(TEST_IMAGE_HANDLE, null);

        assertThat(requestGetImage.getType()).isEqualTo(BipRequest.TYPE_GET_IMAGE);
    }
}
 No newline at end of file