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

Commit e1e13c2f authored by Grzegorz Kolodziejczyk's avatar Grzegorz Kolodziejczyk Committed by Gerrit Code Review
Browse files

Merge "bass: Fix broken test cases" into main

parents f8c2cb45 fe24eb0d
Loading
Loading
Loading
Loading
+43 −24
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.LinkedHashSet;
import java.util.Set;

@RunWith(JUnit4.class)
public class BaseDataTest {
@@ -36,9 +34,17 @@ public class BaseDataTest {
        assertThat(info.presentationDelay.length).isEqualTo(3);
        assertThat(info.codecId.length).isEqualTo(5);

        assertThat(info.isCodecIdUnknown()).isFalse();
        assertThat(info.codecId)
                .isEqualTo(
                        new byte[] {
                            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
                        });
        info.codecId[4] = (byte) 0xFE;
        assertThat(info.isCodecIdUnknown()).isTrue();
        assertThat(info.codecId)
                .isNotEqualTo(
                        new byte[] {
                            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
                        });

        // info.print() with different combination shouldn't crash.
        info.print();
@@ -48,9 +54,10 @@ public class BaseDataTest {
        info.print();

        info.level = 2;
        info.metaDataLength = 1;
        info.keyMetadataDiff.add("metadata-diff");
        info.keyCodecCfgDiff.add("cfg-diff");
        info.codecConfigLength = 3;
        info.codecConfigInfo = new byte[] {(byte) 0x01, (byte) 0x05};
        info.metaDataLength = 4;
        info.metaData = new byte[] {(byte) 0x04, (byte) 0x80, (byte) 0x79, (byte) 0x76};
        info.print();

        info.level = 3;
@@ -61,21 +68,33 @@ public class BaseDataTest {
    public void parseBaseData() {
        assertThrows(IllegalArgumentException.class, () -> BaseData.parseBaseData(null));

        byte[] serviceData = new byte[] {
        byte[] serviceData =
                new byte[] {
                    // LEVEL 1
                (byte) 0x01, (byte) 0x02, (byte) 0x03, // presentationDelay
                    (byte) 0x01,
                    (byte) 0x02,
                    (byte) 0x03, // presentationDelay
                    (byte) 0x01, // numSubGroups
                    // LEVEL 2
                    (byte) 0x01, // numSubGroups
                (byte) 0xFE,  // UNKNOWN_CODEC
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00, // UNKNOWN_CODEC
                    (byte) 0x02, // codecConfigLength
                (byte) 0x01, (byte) 'A', // codecConfigInfo
                    (byte) 0x01,
                    (byte) 'A', // codecConfigInfo
                    (byte) 0x03, // metaDataLength
                (byte) 0x06, (byte) 0x07, (byte) 0x08,  // metaData
                    (byte) 0x06,
                    (byte) 0x07,
                    (byte) 0x08, // metaData
                    // LEVEL 3
                    (byte) 0x04, // index
                    (byte) 0x03, // codecConfigLength
                (byte) 0x02, (byte) 'B', (byte) 'C' // codecConfigInfo
                    (byte) 0x02,
                    (byte) 'B',
                    (byte) 'C' // codecConfigInfo
                };

        BaseData data = BaseData.parseBaseData(serviceData);
@@ -87,7 +106,7 @@ public class BaseDataTest {
        level = data.getLevelTwo().get(0);

        assertThat(level.numSubGroups).isEqualTo(1);
        assertThat(level.isCodecIdUnknown()).isTrue();
        assertThat(level.codecId).isEqualTo(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00});
        assertThat(level.codecConfigLength).isEqualTo(2);
        assertThat(level.metaDataLength).isEqualTo(3);

+56 −22
Original line number Diff line number Diff line
@@ -456,28 +456,64 @@ public class BassClientStateMachineTest {

    @Test
    public void parseScanRecord_withBaseData_callsUpdateBase() {
        byte[] scanRecordWithBaseData = new byte[] {
                0x02, 0x01, 0x1a, // advertising flags
                0x05, 0x02, 0x51, 0x18, 0x0a, 0x11, // 16 bit service uuids
                0x04, 0x09, 0x50, 0x65, 0x64, // name
                0x02, 0x0A, (byte) 0xec, // tx power level
                0x15, 0x16, 0x51, 0x18, // service data (base data with 18 bytes)
        byte[] scanRecordWithBaseData =
                new byte[] {
                    (byte) 0x02,
                    (byte) 0x01,
                    (byte) 0x1a, // advertising flags
                    (byte) 0x05,
                    (byte) 0x02,
                    (byte) 0x51,
                    (byte) 0x18,
                    (byte) 0x0a,
                    (byte) 0x11, // 16 bit service uuids
                    (byte) 0x04,
                    (byte) 0x09,
                    (byte) 0x50,
                    (byte) 0x65,
                    (byte) 0x64, // name
                    (byte) 0x02,
                    (byte) 0x0A,
                    (byte) 0xec, // tx power level
                    (byte) 0x19,
                    (byte) 0x16,
                    (byte) 0x51,
                    (byte) 0x18, // service data (base data with 18 bytes)
                    // LEVEL 1
                    (byte) 0x01, (byte) 0x02, (byte) 0x03, // presentationDelay
                    (byte) 0x01,
                    (byte) 0x02,
                    (byte) 0x03, // presentationDelay
                    (byte) 0x01, // numSubGroups
                    // LEVEL 2
                    (byte) 0x01, // numSubGroups
                    (byte) 0xFE,  // UNKNOWN_CODEC
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00,
                    (byte) 0x00, // UNKNOWN_CODEC
                    (byte) 0x02, // codecConfigLength
                    (byte) 0x01, (byte) 'A', // codecConfigInfo
                    (byte) 0x01,
                    (byte) 'A', // codecConfigInfo
                    (byte) 0x03, // metaDataLength
                    (byte) 0x06, (byte) 0x07, (byte) 0x08,  // metaData
                    (byte) 0x06,
                    (byte) 0x07,
                    (byte) 0x08, // metaData
                    // LEVEL 3
                    (byte) 0x04, // index
                    (byte) 0x03, // codecConfigLength
                    (byte) 0x02, (byte) 'B', (byte) 'C', // codecConfigInfo
                0x05, (byte) 0xff, (byte) 0xe0, 0x00, 0x02, 0x15, // manufacturer specific data
                0x03, 0x50, 0x01, 0x02, // an unknown data type won't cause trouble
                    (byte) 0x02,
                    (byte) 'B',
                    (byte) 'C', // codecConfigInfo
                    (byte) 0x05,
                    (byte) 0xff,
                    (byte) 0xe0,
                    (byte) 0x00,
                    (byte) 0x02,
                    (byte) 0x15, // manufacturer specific data
                    (byte) 0x03,
                    (byte) 0x50,
                    (byte) 0x01,
                    (byte) 0x02, // an unknown data type won't cause trouble
                };
        ScanRecord data = ScanRecord.parseFromBytes(scanRecordWithBaseData);
        assertThat(data.getServiceUuids()).contains(BassConstants.BASIC_AUDIO_UUID);
@@ -1141,7 +1177,6 @@ public class BassClientStateMachineTest {

        mBassClientStateMachine.sendMessage(UPDATE_BCAST_SOURCE, sourceId, paSync, metadata);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        verify(callbacks).notifySourceRemoveFailed(any(), anyInt(), anyInt());

        PeriodicAdvertisementResult paResult = Mockito.mock(PeriodicAdvertisementResult.class);
        when(mBassClientService.getPeriodicAdvertisementResult(any())).thenReturn(paResult);
@@ -1150,7 +1185,6 @@ public class BassClientStateMachineTest {

        mBassClientStateMachine.sendMessage(UPDATE_BCAST_SOURCE, sourceId, paSync, metadata);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        verify(callbacks).notifySourceRemoveFailed(any(), anyInt(), anyInt());

        BaseData data = Mockito.mock(BaseData.class);
        when(mBassClientService.getBase(anyInt())).thenReturn(data);