Loading framework/tests/unit/src/android/bluetooth/BluetoothCodecConfigTest.java +181 −35 Original line number Original line Diff line number Diff line Loading @@ -16,11 +16,22 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import static com.google.common.truth.Truth.assertThat; import junit.framework.TestCase; import androidx.test.runner.AndroidJUnit4; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** Unit test cases for {@link BluetoothCodecConfig}. */ /** Unit test cases for {@link BluetoothCodecConfig}. */ public class BluetoothCodecConfigTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothCodecConfigTest { @Rule public Expect expect = Expect.create(); private static final int[] sCodecTypeArray = private static final int[] sCodecTypeArray = new int[] { new int[] { BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, Loading Loading @@ -199,9 +210,8 @@ public class BluetoothCodecConfigTest extends TestCase { return sCodecSpecific4Array[index]; return sCodecSpecific4Array[index]; } } @SmallTest @Test public void testBluetoothCodecConfig_valid_get_methods() { public void testBluetoothCodecConfig_valid_get_methods() { for (int config_id = 0; config_id < sTotalConfigs; config_id++) { for (int config_id = 0; config_id < sTotalConfigs; config_id++) { int codec_type = selectCodecType(config_id); int codec_type = selectCodecType(config_id); int codec_priority = selectCodecPriority(config_id); int codec_priority = selectCodecPriority(config_id); Loading @@ -226,47 +236,48 @@ public class BluetoothCodecConfigTest extends TestCase { codec_specific4); codec_specific4); if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { assertTrue(bcc.isMandatoryCodec()); expect.that(bcc.isMandatoryCodec()).isTrue(); } else { } else { assertFalse(bcc.isMandatoryCodec()); expect.that(bcc.isMandatoryCodec()).isFalse(); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { assertEquals("SBC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("SBC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) { assertEquals("AAC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("AAC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX) { assertEquals("aptX", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("aptX"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD) { assertEquals("aptX HD", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("aptX HD"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) { assertEquals("LDAC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("LDAC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS) { assertEquals("Opus", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("Opus"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) { assertEquals("INVALID CODEC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)) .isEqualTo("INVALID CODEC"); } } assertEquals(codec_type, bcc.getCodecType()); expect.that(bcc.getCodecType()).isEqualTo(codec_type); assertEquals(codec_priority, bcc.getCodecPriority()); expect.that(bcc.getCodecPriority()).isEqualTo(codec_priority); assertEquals(sample_rate, bcc.getSampleRate()); expect.that(bcc.getSampleRate()).isEqualTo(sample_rate); assertEquals(bits_per_sample, bcc.getBitsPerSample()); expect.that(bcc.getBitsPerSample()).isEqualTo(bits_per_sample); assertEquals(channel_mode, bcc.getChannelMode()); expect.that(bcc.getChannelMode()).isEqualTo(channel_mode); assertEquals(codec_specific1, bcc.getCodecSpecific1()); expect.that(bcc.getCodecSpecific1()).isEqualTo(codec_specific1); assertEquals(codec_specific2, bcc.getCodecSpecific2()); expect.that(bcc.getCodecSpecific2()).isEqualTo(codec_specific2); assertEquals(codec_specific3, bcc.getCodecSpecific3()); expect.that(bcc.getCodecSpecific3()).isEqualTo(codec_specific3); assertEquals(codec_specific4, bcc.getCodecSpecific4()); expect.that(bcc.getCodecSpecific4()).isEqualTo(codec_specific4); } } } } @SmallTest @Test public void testBluetoothCodecConfig_equals() { public void testBluetoothCodecConfig_same() { BluetoothCodecConfig bcc1 = BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, Loading @@ -290,7 +301,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertTrue(bcc1.equals(bcc2_same)); assertThat(bcc2_same).isEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_codec_type() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc3_codec_type = BluetoothCodecConfig bcc3_codec_type = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -303,7 +329,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc3_codec_type)); assertThat(bcc3_codec_type).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_codec_priority() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc4_codec_priority = BluetoothCodecConfig bcc4_codec_priority = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -316,7 +357,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc4_codec_priority)); assertThat(bcc4_codec_priority).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_sample_rate() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc5_sample_rate = BluetoothCodecConfig bcc5_sample_rate = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -329,7 +385,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc5_sample_rate)); assertThat(bcc5_sample_rate).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_bits_per_sample() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc6_bits_per_sample = BluetoothCodecConfig bcc6_bits_per_sample = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -342,7 +413,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc6_bits_per_sample)); assertThat(bcc6_bits_per_sample).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_channel_mode() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc7_channel_mode = BluetoothCodecConfig bcc7_channel_mode = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -355,7 +441,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc7_channel_mode)); assertThat(bcc7_channel_mode).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_1() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc8_codec_specific1 = BluetoothCodecConfig bcc8_codec_specific1 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -368,7 +469,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc8_codec_specific1)); assertThat(bcc8_codec_specific1).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_2() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc9_codec_specific2 = BluetoothCodecConfig bcc9_codec_specific2 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -381,7 +497,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2002, 2002, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc9_codec_specific2)); assertThat(bcc9_codec_specific2).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_3() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc10_codec_specific3 = BluetoothCodecConfig bcc10_codec_specific3 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -394,7 +525,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3003, 3003, 4000); 4000); assertFalse(bcc1.equals(bcc10_codec_specific3)); assertThat(bcc10_codec_specific3).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_4() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc11_codec_specific4 = BluetoothCodecConfig bcc11_codec_specific4 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -407,7 +553,7 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4004); 4004); assertFalse(bcc1.equals(bcc11_codec_specific4)); assertThat(bcc11_codec_specific4).isNotEqualTo(bcc1); } } private BluetoothCodecConfig buildBluetoothCodecConfig( private BluetoothCodecConfig buildBluetoothCodecConfig( Loading framework/tests/unit/src/android/bluetooth/BluetoothCodecStatusTest.java +29 −22 Original line number Original line Diff line number Diff line Loading @@ -16,13 +16,21 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; import java.util.List; import java.util.Objects; import junit.framework.TestCase; /** Unit test cases for {@link BluetoothCodecStatus}. */ /** Unit test cases for {@link BluetoothCodecStatus}. */ public class BluetoothCodecStatusTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothCodecStatusTest { @Rule public Expect expect = Expect.create(); // Codec configs: A and B are same; C is different // Codec configs: A and B are same; C is different private static final BluetoothCodecConfig CONFIG_A = private static final BluetoothCodecConfig CONFIG_A = Loading Loading @@ -547,30 +555,29 @@ public class BluetoothCodecStatusTest extends TestCase { private static final BluetoothCodecStatus BCS_C = private static final BluetoothCodecStatus BCS_C = new BluetoothCodecStatus(CONFIG_C, LOCAL_CAPABILITY_C, SELECTABLE_CAPABILITY_C); new BluetoothCodecStatus(CONFIG_C, LOCAL_CAPABILITY_C, SELECTABLE_CAPABILITY_C); @SmallTest @Test public void testBluetoothCodecStatus_get_methods() { public void testBluetoothCodecStatus_get_methods() { expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_A); expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_B); expect.that(BCS_A.getCodecConfig()).isNotEqualTo(CONFIG_C); assertTrue(Objects.equals(BCS_A.getCodecConfig(), CONFIG_A)); expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_A); assertTrue(Objects.equals(BCS_A.getCodecConfig(), CONFIG_B)); expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_B); assertFalse(Objects.equals(BCS_A.getCodecConfig(), CONFIG_C)); expect.that(BCS_A.getCodecsLocalCapabilities()).isNotEqualTo(LOCAL_CAPABILITY_C); assertTrue(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_A)); assertTrue(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_B)); assertFalse(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_C)); assertTrue(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_A)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_A); assertTrue(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_B)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_B); assertFalse(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_C)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isNotEqualTo(SELECTABLE_CAPABILITY_C); } } @SmallTest @Test public void testBluetoothCodecStatus_equals() { public void testBluetoothCodecStatus_equals() { assertTrue(BCS_A.equals(BCS_B)); expect.that(BCS_A).isEqualTo(BCS_B); assertTrue(BCS_B.equals(BCS_A)); expect.that(BCS_B).isEqualTo(BCS_A); assertTrue(BCS_A.equals(BCS_B_REORDERED)); expect.that(BCS_A).isEqualTo(BCS_B_REORDERED); assertTrue(BCS_B_REORDERED.equals(BCS_A)); expect.that(BCS_B_REORDERED).isEqualTo(BCS_A); assertFalse(BCS_A.equals(BCS_C)); expect.that(BCS_A).isNotEqualTo(BCS_C); assertFalse(BCS_C.equals(BCS_A)); expect.that(BCS_C).isNotEqualTo(BCS_A); } } private static BluetoothCodecConfig buildBluetoothCodecConfig( private static BluetoothCodecConfig buildBluetoothCodecConfig( Loading framework/tests/unit/src/android/bluetooth/BluetoothLeAudioCodecConfigTest.java +16 −8 Original line number Original line Diff line number Diff line Loading @@ -16,20 +16,28 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import junit.framework.TestCase; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** Unit test cases for {@link BluetoothLeAudioCodecConfig}. */ /** Unit test cases for {@link BluetoothLeAudioCodecConfig}. */ public class BluetoothLeAudioCodecConfigTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothLeAudioCodecConfigTest { @Rule public Expect expect = Expect.create(); private int[] mCodecTypeArray = private int[] mCodecTypeArray = new int[] { new int[] { BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID, }; }; @SmallTest @Test public void testBluetoothLeAudioCodecConfig_valid_get_methods() { public void testBluetoothLeAudioCodecConfig_valid_get_methods() { for (int codecIdx = 0; codecIdx < mCodecTypeArray.length; codecIdx++) { for (int codecIdx = 0; codecIdx < mCodecTypeArray.length; codecIdx++) { int codecType = mCodecTypeArray[codecIdx]; int codecType = mCodecTypeArray[codecIdx]; Loading @@ -37,13 +45,13 @@ public class BluetoothLeAudioCodecConfigTest extends TestCase { buildBluetoothLeAudioCodecConfig(codecType); buildBluetoothLeAudioCodecConfig(codecType); if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3) { if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3) { assertEquals("LC3", leAudioCodecConfig.getCodecName()); expect.that(leAudioCodecConfig.getCodecName()).isEqualTo("LC3"); } } if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID) { if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID) { assertEquals("INVALID CODEC", leAudioCodecConfig.getCodecName()); expect.that(leAudioCodecConfig.getCodecName()).isEqualTo("INVALID CODEC"); } } assertEquals(codecType, leAudioCodecConfig.getCodecType()); expect.that(leAudioCodecConfig.getCodecType()).isEqualTo(codecType); } } } } Loading framework/tests/unit/src/android/bluetooth/BluetoothUuidTest.java +48 −31 Original line number Original line Diff line number Diff line Loading @@ -16,25 +16,39 @@ package android.bluetooth; package android.bluetooth; import static com.google.common.truth.Truth.assertThat; import android.os.ParcelUuid; import android.os.ParcelUuid; import androidx.test.filters.SmallTest; import junit.framework.TestCase; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Unit test cases for {@link BluetoothUuid}. */ /** Unit test cases for {@link BluetoothUuid}. */ public class BluetoothUuidTest extends TestCase { @RunWith(JUnit4.class) public class BluetoothUuidTest { @Rule public Expect expect = Expect.create(); @SmallTest @Test public void testUuidParser() { public void testUuid16Parser() { byte[] uuid16 = new byte[] {0x0B, 0x11}; byte[] uuid16 = new byte[] {0x0B, 0x11}; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid16)) ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"), .isEqualTo(ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")); BluetoothUuid.parseUuidFrom(uuid16)); } @Test public void testUuid32Parser() { byte[] uuid32 = new byte[] {0x0B, 0x11, 0x33, (byte) 0xFE}; byte[] uuid32 = new byte[] {0x0B, 0x11, 0x33, (byte) 0xFE}; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid32)) ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"), .isEqualTo(ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")); BluetoothUuid.parseUuidFrom(uuid32)); } @Test public void testUuid128Parser() { byte[] uuid128 = byte[] uuid128 = new byte[] { new byte[] { 0x01, 0x01, Loading @@ -54,28 +68,31 @@ public class BluetoothUuidTest extends TestCase { 0x0F, 0x0F, (byte) 0xFF (byte) 0xFF }; }; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid128)) ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-060504030201"), .isEqualTo(ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-060504030201")); BluetoothUuid.parseUuidFrom(uuid128)); } } @SmallTest @Test public void testUuidType() { public void testUuidType() { assertTrue( expect.that( BluetoothUuid.is16BitUuid( BluetoothUuid.is16BitUuid( ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))) assertFalse( .isTrue(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))) .isFalse(); assertFalse( expect.that( BluetoothUuid.is16BitUuid( BluetoothUuid.is16BitUuid( ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))) assertTrue( .isFalse(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))) assertFalse( .isTrue(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB"))) .isFalse(); } } } } framework/tests/unit/src/android/bluetooth/le/ScanFilterTest.java +12 −5 Original line number Original line Diff line number Diff line Loading @@ -16,13 +16,20 @@ package android.bluetooth.le; package android.bluetooth.le; import static com.google.common.truth.Truth.assertThat; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.os.Parcel; import android.os.Parcel; import androidx.test.filters.SmallTest; import junit.framework.TestCase; public class ScanFilterTest extends TestCase { import org.junit.Test; @SmallTest import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Test for Bluetooth LE {@link ScanFilter}. */ @RunWith(JUnit4.class) public class ScanFilterTest { @Test public void testIrkFilterParcelable() { public void testIrkFilterParcelable() { // arrange: an IRK filter // arrange: an IRK filter Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain(); Loading @@ -40,6 +47,6 @@ public class ScanFilterTest extends TestCase { ScanFilter filterFromParcel = ScanFilter.CREATOR.createFromParcel(parcel); ScanFilter filterFromParcel = ScanFilter.CREATOR.createFromParcel(parcel); // assert: no change // assert: no change assertEquals(filter, filterFromParcel); assertThat(filterFromParcel).isEqualTo(filter); } } } } Loading
framework/tests/unit/src/android/bluetooth/BluetoothCodecConfigTest.java +181 −35 Original line number Original line Diff line number Diff line Loading @@ -16,11 +16,22 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import static com.google.common.truth.Truth.assertThat; import junit.framework.TestCase; import androidx.test.runner.AndroidJUnit4; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** Unit test cases for {@link BluetoothCodecConfig}. */ /** Unit test cases for {@link BluetoothCodecConfig}. */ public class BluetoothCodecConfigTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothCodecConfigTest { @Rule public Expect expect = Expect.create(); private static final int[] sCodecTypeArray = private static final int[] sCodecTypeArray = new int[] { new int[] { BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, Loading Loading @@ -199,9 +210,8 @@ public class BluetoothCodecConfigTest extends TestCase { return sCodecSpecific4Array[index]; return sCodecSpecific4Array[index]; } } @SmallTest @Test public void testBluetoothCodecConfig_valid_get_methods() { public void testBluetoothCodecConfig_valid_get_methods() { for (int config_id = 0; config_id < sTotalConfigs; config_id++) { for (int config_id = 0; config_id < sTotalConfigs; config_id++) { int codec_type = selectCodecType(config_id); int codec_type = selectCodecType(config_id); int codec_priority = selectCodecPriority(config_id); int codec_priority = selectCodecPriority(config_id); Loading @@ -226,47 +236,48 @@ public class BluetoothCodecConfigTest extends TestCase { codec_specific4); codec_specific4); if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { assertTrue(bcc.isMandatoryCodec()); expect.that(bcc.isMandatoryCodec()).isTrue(); } else { } else { assertFalse(bcc.isMandatoryCodec()); expect.that(bcc.isMandatoryCodec()).isFalse(); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) { assertEquals("SBC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("SBC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) { assertEquals("AAC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("AAC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX) { assertEquals("aptX", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("aptX"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD) { assertEquals("aptX HD", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("aptX HD"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) { assertEquals("LDAC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("LDAC"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_OPUS) { assertEquals("Opus", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)).isEqualTo("Opus"); } } if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) { if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) { assertEquals("INVALID CODEC", BluetoothCodecConfig.getCodecName(codec_type)); expect.that(BluetoothCodecConfig.getCodecName(codec_type)) .isEqualTo("INVALID CODEC"); } } assertEquals(codec_type, bcc.getCodecType()); expect.that(bcc.getCodecType()).isEqualTo(codec_type); assertEquals(codec_priority, bcc.getCodecPriority()); expect.that(bcc.getCodecPriority()).isEqualTo(codec_priority); assertEquals(sample_rate, bcc.getSampleRate()); expect.that(bcc.getSampleRate()).isEqualTo(sample_rate); assertEquals(bits_per_sample, bcc.getBitsPerSample()); expect.that(bcc.getBitsPerSample()).isEqualTo(bits_per_sample); assertEquals(channel_mode, bcc.getChannelMode()); expect.that(bcc.getChannelMode()).isEqualTo(channel_mode); assertEquals(codec_specific1, bcc.getCodecSpecific1()); expect.that(bcc.getCodecSpecific1()).isEqualTo(codec_specific1); assertEquals(codec_specific2, bcc.getCodecSpecific2()); expect.that(bcc.getCodecSpecific2()).isEqualTo(codec_specific2); assertEquals(codec_specific3, bcc.getCodecSpecific3()); expect.that(bcc.getCodecSpecific3()).isEqualTo(codec_specific3); assertEquals(codec_specific4, bcc.getCodecSpecific4()); expect.that(bcc.getCodecSpecific4()).isEqualTo(codec_specific4); } } } } @SmallTest @Test public void testBluetoothCodecConfig_equals() { public void testBluetoothCodecConfig_same() { BluetoothCodecConfig bcc1 = BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, Loading @@ -290,7 +301,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertTrue(bcc1.equals(bcc2_same)); assertThat(bcc2_same).isEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_codec_type() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc3_codec_type = BluetoothCodecConfig bcc3_codec_type = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -303,7 +329,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc3_codec_type)); assertThat(bcc3_codec_type).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_codec_priority() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc4_codec_priority = BluetoothCodecConfig bcc4_codec_priority = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -316,7 +357,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc4_codec_priority)); assertThat(bcc4_codec_priority).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_sample_rate() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc5_sample_rate = BluetoothCodecConfig bcc5_sample_rate = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -329,7 +385,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc5_sample_rate)); assertThat(bcc5_sample_rate).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_bits_per_sample() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc6_bits_per_sample = BluetoothCodecConfig bcc6_bits_per_sample = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -342,7 +413,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc6_bits_per_sample)); assertThat(bcc6_bits_per_sample).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_channel_mode() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc7_channel_mode = BluetoothCodecConfig bcc7_channel_mode = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -355,7 +441,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc7_channel_mode)); assertThat(bcc7_channel_mode).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_1() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc8_codec_specific1 = BluetoothCodecConfig bcc8_codec_specific1 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -368,7 +469,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc8_codec_specific1)); assertThat(bcc8_codec_specific1).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_2() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc9_codec_specific2 = BluetoothCodecConfig bcc9_codec_specific2 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -381,7 +497,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2002, 2002, 3000, 3000, 4000); 4000); assertFalse(bcc1.equals(bcc9_codec_specific2)); assertThat(bcc9_codec_specific2).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_3() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc10_codec_specific3 = BluetoothCodecConfig bcc10_codec_specific3 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -394,7 +525,22 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3003, 3003, 4000); 4000); assertFalse(bcc1.equals(bcc10_codec_specific3)); assertThat(bcc10_codec_specific3).isNotEqualTo(bcc1); } @Test public void testBluetoothCodecConfig_different_code_specific_4() { BluetoothCodecConfig bcc1 = buildBluetoothCodecConfig( BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, BluetoothCodecConfig.SAMPLE_RATE_44100, BluetoothCodecConfig.BITS_PER_SAMPLE_16, BluetoothCodecConfig.CHANNEL_MODE_STEREO, 1000, 2000, 3000, 4000); BluetoothCodecConfig bcc11_codec_specific4 = BluetoothCodecConfig bcc11_codec_specific4 = buildBluetoothCodecConfig( buildBluetoothCodecConfig( Loading @@ -407,7 +553,7 @@ public class BluetoothCodecConfigTest extends TestCase { 2000, 2000, 3000, 3000, 4004); 4004); assertFalse(bcc1.equals(bcc11_codec_specific4)); assertThat(bcc11_codec_specific4).isNotEqualTo(bcc1); } } private BluetoothCodecConfig buildBluetoothCodecConfig( private BluetoothCodecConfig buildBluetoothCodecConfig( Loading
framework/tests/unit/src/android/bluetooth/BluetoothCodecStatusTest.java +29 −22 Original line number Original line Diff line number Diff line Loading @@ -16,13 +16,21 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; import java.util.List; import java.util.Objects; import junit.framework.TestCase; /** Unit test cases for {@link BluetoothCodecStatus}. */ /** Unit test cases for {@link BluetoothCodecStatus}. */ public class BluetoothCodecStatusTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothCodecStatusTest { @Rule public Expect expect = Expect.create(); // Codec configs: A and B are same; C is different // Codec configs: A and B are same; C is different private static final BluetoothCodecConfig CONFIG_A = private static final BluetoothCodecConfig CONFIG_A = Loading Loading @@ -547,30 +555,29 @@ public class BluetoothCodecStatusTest extends TestCase { private static final BluetoothCodecStatus BCS_C = private static final BluetoothCodecStatus BCS_C = new BluetoothCodecStatus(CONFIG_C, LOCAL_CAPABILITY_C, SELECTABLE_CAPABILITY_C); new BluetoothCodecStatus(CONFIG_C, LOCAL_CAPABILITY_C, SELECTABLE_CAPABILITY_C); @SmallTest @Test public void testBluetoothCodecStatus_get_methods() { public void testBluetoothCodecStatus_get_methods() { expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_A); expect.that(BCS_A.getCodecConfig()).isEqualTo(CONFIG_B); expect.that(BCS_A.getCodecConfig()).isNotEqualTo(CONFIG_C); assertTrue(Objects.equals(BCS_A.getCodecConfig(), CONFIG_A)); expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_A); assertTrue(Objects.equals(BCS_A.getCodecConfig(), CONFIG_B)); expect.that(BCS_A.getCodecsLocalCapabilities()).isEqualTo(LOCAL_CAPABILITY_B); assertFalse(Objects.equals(BCS_A.getCodecConfig(), CONFIG_C)); expect.that(BCS_A.getCodecsLocalCapabilities()).isNotEqualTo(LOCAL_CAPABILITY_C); assertTrue(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_A)); assertTrue(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_B)); assertFalse(BCS_A.getCodecsLocalCapabilities().equals(LOCAL_CAPABILITY_C)); assertTrue(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_A)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_A); assertTrue(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_B)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isEqualTo(SELECTABLE_CAPABILITY_B); assertFalse(BCS_A.getCodecsSelectableCapabilities().equals(SELECTABLE_CAPABILITY_C)); expect.that(BCS_A.getCodecsSelectableCapabilities()).isNotEqualTo(SELECTABLE_CAPABILITY_C); } } @SmallTest @Test public void testBluetoothCodecStatus_equals() { public void testBluetoothCodecStatus_equals() { assertTrue(BCS_A.equals(BCS_B)); expect.that(BCS_A).isEqualTo(BCS_B); assertTrue(BCS_B.equals(BCS_A)); expect.that(BCS_B).isEqualTo(BCS_A); assertTrue(BCS_A.equals(BCS_B_REORDERED)); expect.that(BCS_A).isEqualTo(BCS_B_REORDERED); assertTrue(BCS_B_REORDERED.equals(BCS_A)); expect.that(BCS_B_REORDERED).isEqualTo(BCS_A); assertFalse(BCS_A.equals(BCS_C)); expect.that(BCS_A).isNotEqualTo(BCS_C); assertFalse(BCS_C.equals(BCS_A)); expect.that(BCS_C).isNotEqualTo(BCS_A); } } private static BluetoothCodecConfig buildBluetoothCodecConfig( private static BluetoothCodecConfig buildBluetoothCodecConfig( Loading
framework/tests/unit/src/android/bluetooth/BluetoothLeAudioCodecConfigTest.java +16 −8 Original line number Original line Diff line number Diff line Loading @@ -16,20 +16,28 @@ package android.bluetooth; package android.bluetooth; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import junit.framework.TestCase; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** Unit test cases for {@link BluetoothLeAudioCodecConfig}. */ /** Unit test cases for {@link BluetoothLeAudioCodecConfig}. */ public class BluetoothLeAudioCodecConfigTest extends TestCase { @RunWith(AndroidJUnit4.class) public class BluetoothLeAudioCodecConfigTest { @Rule public Expect expect = Expect.create(); private int[] mCodecTypeArray = private int[] mCodecTypeArray = new int[] { new int[] { BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID, BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID, }; }; @SmallTest @Test public void testBluetoothLeAudioCodecConfig_valid_get_methods() { public void testBluetoothLeAudioCodecConfig_valid_get_methods() { for (int codecIdx = 0; codecIdx < mCodecTypeArray.length; codecIdx++) { for (int codecIdx = 0; codecIdx < mCodecTypeArray.length; codecIdx++) { int codecType = mCodecTypeArray[codecIdx]; int codecType = mCodecTypeArray[codecIdx]; Loading @@ -37,13 +45,13 @@ public class BluetoothLeAudioCodecConfigTest extends TestCase { buildBluetoothLeAudioCodecConfig(codecType); buildBluetoothLeAudioCodecConfig(codecType); if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3) { if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_LC3) { assertEquals("LC3", leAudioCodecConfig.getCodecName()); expect.that(leAudioCodecConfig.getCodecName()).isEqualTo("LC3"); } } if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID) { if (codecType == BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID) { assertEquals("INVALID CODEC", leAudioCodecConfig.getCodecName()); expect.that(leAudioCodecConfig.getCodecName()).isEqualTo("INVALID CODEC"); } } assertEquals(codecType, leAudioCodecConfig.getCodecType()); expect.that(leAudioCodecConfig.getCodecType()).isEqualTo(codecType); } } } } Loading
framework/tests/unit/src/android/bluetooth/BluetoothUuidTest.java +48 −31 Original line number Original line Diff line number Diff line Loading @@ -16,25 +16,39 @@ package android.bluetooth; package android.bluetooth; import static com.google.common.truth.Truth.assertThat; import android.os.ParcelUuid; import android.os.ParcelUuid; import androidx.test.filters.SmallTest; import junit.framework.TestCase; import com.google.common.truth.Expect; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Unit test cases for {@link BluetoothUuid}. */ /** Unit test cases for {@link BluetoothUuid}. */ public class BluetoothUuidTest extends TestCase { @RunWith(JUnit4.class) public class BluetoothUuidTest { @Rule public Expect expect = Expect.create(); @SmallTest @Test public void testUuidParser() { public void testUuid16Parser() { byte[] uuid16 = new byte[] {0x0B, 0x11}; byte[] uuid16 = new byte[] {0x0B, 0x11}; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid16)) ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"), .isEqualTo(ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB")); BluetoothUuid.parseUuidFrom(uuid16)); } @Test public void testUuid32Parser() { byte[] uuid32 = new byte[] {0x0B, 0x11, 0x33, (byte) 0xFE}; byte[] uuid32 = new byte[] {0x0B, 0x11, 0x33, (byte) 0xFE}; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid32)) ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"), .isEqualTo(ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB")); BluetoothUuid.parseUuidFrom(uuid32)); } @Test public void testUuid128Parser() { byte[] uuid128 = byte[] uuid128 = new byte[] { new byte[] { 0x01, 0x01, Loading @@ -54,28 +68,31 @@ public class BluetoothUuidTest extends TestCase { 0x0F, 0x0F, (byte) 0xFF (byte) 0xFF }; }; assertEquals( assertThat(BluetoothUuid.parseUuidFrom(uuid128)) ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-060504030201"), .isEqualTo(ParcelUuid.fromString("FF0F0E0D-0C0B-0A09-0807-060504030201")); BluetoothUuid.parseUuidFrom(uuid128)); } } @SmallTest @Test public void testUuidType() { public void testUuidType() { assertTrue( expect.that( BluetoothUuid.is16BitUuid( BluetoothUuid.is16BitUuid( ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))) assertFalse( .isTrue(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"))) .isFalse(); assertFalse( expect.that( BluetoothUuid.is16BitUuid( BluetoothUuid.is16BitUuid( ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))) assertTrue( .isFalse(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-0000-1000-8000-00805F9B34FB"))) assertFalse( .isTrue(); expect.that( BluetoothUuid.is32BitUuid( BluetoothUuid.is32BitUuid( ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB"))); ParcelUuid.fromString("FE33110B-1000-1000-8000-00805F9B34FB"))) .isFalse(); } } } }
framework/tests/unit/src/android/bluetooth/le/ScanFilterTest.java +12 −5 Original line number Original line Diff line number Diff line Loading @@ -16,13 +16,20 @@ package android.bluetooth.le; package android.bluetooth.le; import static com.google.common.truth.Truth.assertThat; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.os.Parcel; import android.os.Parcel; import androidx.test.filters.SmallTest; import junit.framework.TestCase; public class ScanFilterTest extends TestCase { import org.junit.Test; @SmallTest import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Test for Bluetooth LE {@link ScanFilter}. */ @RunWith(JUnit4.class) public class ScanFilterTest { @Test public void testIrkFilterParcelable() { public void testIrkFilterParcelable() { // arrange: an IRK filter // arrange: an IRK filter Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain(); Loading @@ -40,6 +47,6 @@ public class ScanFilterTest extends TestCase { ScanFilter filterFromParcel = ScanFilter.CREATOR.createFromParcel(parcel); ScanFilter filterFromParcel = ScanFilter.CREATOR.createFromParcel(parcel); // assert: no change // assert: no change assertEquals(filter, filterFromParcel); assertThat(filterFromParcel).isEqualTo(filter); } } } }