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

Commit 50be8ef4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add tests for VolumeControlOffsetDescriptor" am: d08bdb59 am:...

Merge "Add tests for VolumeControlOffsetDescriptor" am: d08bdb59 am: 51bbe12f am: 241a2075 am: be88d3d2

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2226218



Change-Id: I10929d273614420eb7e4979249f4cb5811c402df
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a24c00a6 be88d3d2
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -79,7 +79,10 @@ public class VolumeControlService extends ProfileService {
    @VisibleForTesting
    RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks;

    private class VolumeControlOffsetDescriptor {
    @VisibleForTesting
    static class VolumeControlOffsetDescriptor {
        Map<Integer, Descriptor> mVolumeOffsets;

        private class Descriptor {
            Descriptor() {
                mValue = 0;
@@ -94,15 +97,18 @@ public class VolumeControlService extends ProfileService {
        VolumeControlOffsetDescriptor() {
            mVolumeOffsets = new HashMap<>();
        }

        int size() {
            return mVolumeOffsets.size();
        }

        void add(int id) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
                mVolumeOffsets.put(id, new Descriptor());
            }
        }

        boolean setValue(int id, int value) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -111,6 +117,7 @@ public class VolumeControlService extends ProfileService {
            d.mValue = value;
            return true;
        }

        int getValue(int id) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -118,6 +125,7 @@ public class VolumeControlService extends ProfileService {
            }
            return d.mValue;
        }

        boolean setDescription(int id, String desc) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -126,6 +134,7 @@ public class VolumeControlService extends ProfileService {
            d.mDescription = desc;
            return true;
        }

        String getDescription(int id) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -133,6 +142,7 @@ public class VolumeControlService extends ProfileService {
            }
            return d.mDescription;
        }

        boolean setLocation(int id, int location) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -141,6 +151,7 @@ public class VolumeControlService extends ProfileService {
            d.mLocation = location;
            return true;
        }

        int getLocation(int id) {
            Descriptor d = mVolumeOffsets.get(id);
            if (d == null) {
@@ -148,12 +159,15 @@ public class VolumeControlService extends ProfileService {
            }
            return d.mLocation;
        }

        void remove(int id) {
            mVolumeOffsets.remove(id);
        }

        void clear() {
            mVolumeOffsets.clear();
        }

        void dump(StringBuilder sb) {
            for (Map.Entry<Integer, Descriptor> entry : mVolumeOffsets.entrySet()) {
                Descriptor descriptor = entry.getValue();
@@ -164,8 +178,6 @@ public class VolumeControlService extends ProfileService {
                ProfileService.println(sb, "        description: " + descriptor.mDescription);
            }
        }

        Map<Integer, Descriptor> mVolumeOffsets;
    }

    @VisibleForTesting
+41 −0
Original line number Diff line number Diff line
@@ -718,6 +718,47 @@ public class VolumeControlServiceTest {
        verify(mNativeInterface).unmuteGroup(groupId);
    }

    @Test
    public void testVolumeControlOffsetDescriptor() {
        VolumeControlService.VolumeControlOffsetDescriptor descriptor =
                new VolumeControlService.VolumeControlOffsetDescriptor();
        int invalidId = -1;
        int validId = 10;
        int testValue = 100;
        String testDesc = "testDescription";
        int testLocation = 10000;

        Assert.assertEquals(0, descriptor.size());
        descriptor.add(validId);
        Assert.assertEquals(1, descriptor.size());

        Assert.assertFalse(descriptor.setValue(invalidId, testValue));
        Assert.assertTrue(descriptor.setValue(validId, testValue));
        Assert.assertEquals(0, descriptor.getValue(invalidId));
        Assert.assertEquals(testValue, descriptor.getValue(validId));

        Assert.assertFalse(descriptor.setDescription(invalidId, testDesc));
        Assert.assertTrue(descriptor.setDescription(validId, testDesc));
        Assert.assertEquals(null, descriptor.getDescription(invalidId));
        Assert.assertEquals(testDesc, descriptor.getDescription(validId));

        Assert.assertFalse(descriptor.setLocation(invalidId, testLocation));
        Assert.assertTrue(descriptor.setLocation(validId, testLocation));
        Assert.assertEquals(0, descriptor.getLocation(invalidId));
        Assert.assertEquals(testLocation, descriptor.getLocation(validId));

        StringBuilder sb = new StringBuilder();
        descriptor.dump(sb);
        Assert.assertTrue(sb.toString().contains(testDesc));

        descriptor.add(validId + 1);
        Assert.assertEquals(2, descriptor.size());
        descriptor.remove(validId);
        Assert.assertEquals(1, descriptor.size());
        descriptor.clear();
        Assert.assertEquals(0, descriptor.size());
    }

    private void connectDevice(BluetoothDevice device) throws Exception {
        VolumeControlStackEvent connCompletedEvent;