1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bluetooth.gatt; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.verify; 22 23 import android.content.Intent; 24 25 import androidx.test.filters.SmallTest; 26 import androidx.test.runner.AndroidJUnit4; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.Mock; 32 import org.mockito.MockitoAnnotations; 33 34 /** 35 * Test cases for {@link GattDebugUtils}. 36 */ 37 @SmallTest 38 @RunWith(AndroidJUnit4.class) 39 public class GattDebugUtilsTest { 40 41 @Mock 42 private GattService mService; 43 44 @Before setUp()45 public void setUp() throws Exception { 46 MockitoAnnotations.initMocks(this); 47 } 48 49 @Test handleDebugAction()50 public void handleDebugAction() { 51 Intent intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_USAGE); 52 53 boolean result = GattDebugUtils.handleDebugAction(mService, intent); 54 assertThat(result).isTrue(); 55 56 intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_ENABLE); 57 GattDebugUtils.handleDebugAction(mService, intent); 58 int bEnable = 1; 59 verify(mService).gattTestCommand(0x01, null, null, bEnable, 0, 0, 0, 0); 60 61 intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_CONNECT); 62 GattDebugUtils.handleDebugAction(mService, intent); 63 int type = 2; 64 verify(mService).gattTestCommand(0x02, null, null, type, 0, 0, 0, 0); 65 66 intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_DISCONNECT); 67 GattDebugUtils.handleDebugAction(mService, intent); 68 verify(mService).gattTestCommand(0x03, null, null, 0, 0, 0, 0, 0); 69 70 intent = new Intent(GattDebugUtils.ACTION_GATT_TEST_DISCOVER); 71 GattDebugUtils.handleDebugAction(mService, intent); 72 int typeDiscover = 1; 73 int shdl = 1; 74 int ehdl = 0xFFFF; 75 verify(mService).gattTestCommand(0x04, null, null, typeDiscover, shdl, ehdl, 0, 0); 76 77 intent = new Intent(GattDebugUtils.ACTION_GATT_PAIRING_CONFIG); 78 GattDebugUtils.handleDebugAction(mService, intent); 79 int authReq = 5; 80 int ioCap = 4; 81 int initKey = 7; 82 int respKey = 7; 83 int maxKey = 16; 84 verify(mService).gattTestCommand(0xF0, null, null, authReq, ioCap, initKey, respKey, 85 maxKey); 86 } 87 } 88