1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <gmock/gmock.h>
18
19 #include "bluetooth_gatt_client.h"
20 #include "bluetooth_gatt_manager.h"
21 #include "uuid.h"
22 #include "vector"
23
24 using namespace testing;
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace Bluetooth {
28 class GattClientCallbackTest : public GattClientCallback {
29 public:
GattClientCallbackTest()30 GattClientCallbackTest()
31 {}
~GattClientCallbackTest()32 ~GattClientCallbackTest()
33 {}
34
OnConnectionStateChanged(int connectionState,int ret)35 void OnConnectionStateChanged(int connectionState, int ret)
36 {
37 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnConnectionStateChanged called";
38 }
39
OnCharacteristicChanged(const GattCharacteristic & characteristic)40 void OnCharacteristicChanged(const GattCharacteristic &characteristic)
41 {
42 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnCharacteristicChanged called";
43 }
44
OnCharacteristicReadResult(const GattCharacteristic & characteristic,int ret)45 void OnCharacteristicReadResult(const GattCharacteristic &characteristic, int ret)
46 {
47 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnCharacteristicReadResult called";
48 }
49
OnCharacteristicWriteResult(const GattCharacteristic & characteristic,int ret)50 void OnCharacteristicWriteResult(const GattCharacteristic &characteristic, int ret)
51 {
52 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnCharacteristicWriteResult called";
53 }
54
OnDescriptorReadResult(const GattDescriptor & descriptor,int ret)55 void OnDescriptorReadResult(const GattDescriptor &descriptor, int ret)
56 {
57 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnDescriptorReadResult called";
58 }
59
OnDescriptorWriteResult(const GattDescriptor & descriptor,int ret)60 void OnDescriptorWriteResult(const GattDescriptor &descriptor, int ret)
61 {
62 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnDescriptorWriteResult called";
63 }
64
OnMtuUpdate(int mtu,int ret)65 void OnMtuUpdate(int mtu, int ret)
66 {
67 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnMtuUpdate called";
68 }
69
OnServicesDiscovered(int status)70 void OnServicesDiscovered(int status)
71 {
72 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnServicesDiscovered called";
73 }
74
OnConnectionParameterChanged(int interval,int latency,int timeout,int status)75 void OnConnectionParameterChanged(int interval, int latency, int timeout, int status)
76 {
77 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnConnectionParameterChanged called";
78 }
79
OnSetNotifyCharacteristic(int status)80 void OnSetNotifyCharacteristic(int status)
81 {
82 GTEST_LOG_(INFO) << "GattClientCallbackTest::OnSetNotifyCharacteristic called";
83 }
84 };
85
86 class GattManagerTest : public testing::Test {
87 public:
GattManagerTest()88 GattManagerTest()
89 {}
~GattManagerTest()90 ~GattManagerTest()
91 {}
92
93 static void SetUpTestCase(void);
94 static void TearDownTestCase(void);
95 void SetUp();
96 void TearDown();
97 };
98
SetUpTestCase(void)99 void GattManagerTest::SetUpTestCase(void)
100 {}
TearDownTestCase(void)101 void GattManagerTest::TearDownTestCase(void)
102 {}
SetUp()103 void GattManagerTest::SetUp()
104 {}
105
TearDown()106 void GattManagerTest::TearDown()
107 {}
108
109 /*
110 * @tc.number: GattManager001
111 * @tc.name: GetDevicesByStates
112 */
113 HWTEST_F(GattManagerTest, GattManager_UnitTest_GetDevicesByStates, TestSize.Level1)
114 {
115 GTEST_LOG_(INFO) << "GattManager::GattManager ends";
116 BluetoothRemoteDevice device;
117 GattClient client(device);
118 GattClientCallbackTest callback_;
119 bool isAutoConnect = true;
120 int transport = 12;
121 client.Connect(callback_, isAutoConnect, transport);
122
123 std::array<int, GattManager::GATT_CONNECTION_STATE_NUM> states = {1, 2, 3};
124
125 GattManager test;
126
127 EXPECT_EQ((int)test.GetDevicesByStates(states).size(), 0);
128
129 GTEST_LOG_(INFO) << "GattManager::GetDevicesByState ends";
130 }
131
132 /*
133 * @tc.number: GattManager002
134 * @tc.name: GetConnectedDevices
135 */
136 HWTEST_F(GattManagerTest, GattManager_UnitTest_GetConnectedDevices, TestSize.Level1)
137 {
138 GTEST_LOG_(INFO) << "GattManager::GattManager ends";
139 BluetoothRemoteDevice device;
140 GattClient client(device);
141 GattClientCallbackTest callback_;
142 bool isAutoConnect = true;
143 int transport = 12;
144 client.Connect(callback_, isAutoConnect, transport);
145
146 GattManager test;
147
148 EXPECT_EQ((int)test.GetConnectedDevices().size(), 0);
149
150 GTEST_LOG_(INFO) << "GattManager::GetConnectedDevices ends";
151 }
152
153 } // namespace Bluetooth
154 } // namespace OHOS
155