1 /*
2 * Copyright (C) 2024 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 #include "bta/le_audio/gmap_client.h"
18
19 #include <bluetooth/log.h>
20 #include <com_android_bluetooth_flags.h>
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
23 #include <hardware/bluetooth.h>
24
25 #include "bta/le_audio/le_audio_types.h"
26 #include "fake_osi.h"
27 #include "osi/include/properties.h"
28 #include "test/mock/mock_osi_properties.h"
29
30 using bluetooth::le_audio::GmapClient;
31 using ::testing::_;
32
33 static constexpr char kGmapEnabledSysProp[] = "bluetooth.profile.gmap.enabled";
34
35 class GmapClientTest : public ::testing::Test {
36 public:
37 RawAddress addr = RawAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
38 GmapClient gmapClient = GmapClient(addr);
39 };
40
TEST_F(GmapClientTest,test_parse_role)41 TEST_F(GmapClientTest, test_parse_role) {
42 const uint8_t role = 0b0001;
43 gmapClient.parseAndSaveGmapRole(1, &role);
44
45 ASSERT_EQ(gmapClient.getRole(), role);
46 }
47
TEST_F(GmapClientTest,test_parse_invalid_role)48 TEST_F(GmapClientTest, test_parse_invalid_role) {
49 const uint8_t role = 0b0001;
50 ASSERT_FALSE(gmapClient.parseAndSaveGmapRole(2, &role));
51 }
52
TEST_F(GmapClientTest,test_parse_ugt_feature)53 TEST_F(GmapClientTest, test_parse_ugt_feature) {
54 const uint8_t value = 0b0001;
55 gmapClient.parseAndSaveUGTFeature(1, &value);
56
57 ASSERT_EQ(gmapClient.getUGTFeature(), value);
58 }
59
TEST_F(GmapClientTest,test_parse_invalid_ugt_feature)60 TEST_F(GmapClientTest, test_parse_invalid_ugt_feature) {
61 const uint8_t value = 0b0001;
62 ASSERT_FALSE(gmapClient.parseAndSaveUGTFeature(2, &value));
63 }
64
TEST_F(GmapClientTest,test_add_from_storage)65 TEST_F(GmapClientTest, test_add_from_storage) {
66 const uint8_t role = 0b0001;
67 const uint16_t role_handle = 2;
68 const uint8_t UGT_feature = 0b0011;
69 const uint16_t UGT_feature_handle = 4;
70 gmapClient.AddFromStorage(role, role_handle, UGT_feature, UGT_feature_handle);
71 ASSERT_EQ(gmapClient.getRole(), role);
72 ASSERT_EQ(gmapClient.getRoleHandle(), role_handle);
73 ASSERT_EQ(gmapClient.getUGTFeature(), UGT_feature);
74 ASSERT_EQ(gmapClient.getUGTFeatureHandle(), UGT_feature_handle);
75 }
76
TEST_F(GmapClientTest,test_role_handle)77 TEST_F(GmapClientTest, test_role_handle) {
78 const uint16_t handle = 5;
79 gmapClient.setRoleHandle(handle);
80 ASSERT_EQ(gmapClient.getRoleHandle(), handle);
81 }
82
TEST_F(GmapClientTest,test_ugt_feature_handle)83 TEST_F(GmapClientTest, test_ugt_feature_handle) {
84 const uint16_t handle = 6;
85 gmapClient.setUGTFeatureHandle(handle);
86 ASSERT_EQ(gmapClient.getUGTFeatureHandle(), handle);
87 }
88
TEST_F(GmapClientTest,test_is_gmap_client_enabled)89 TEST_F(GmapClientTest, test_is_gmap_client_enabled) {
90 GmapClient::UpdateGmapOffloaderSupport(false);
91 ASSERT_EQ(GmapClient::IsGmapClientEnabled(), false);
92
93 com::android::bluetooth::flags::provider_->leaudio_gmap_client(true);
94 osi_property_set_bool(kGmapEnabledSysProp, true);
95
96 GmapClient::UpdateGmapOffloaderSupport(true);
97
98 ASSERT_EQ(GmapClient::IsGmapClientEnabled(), true);
99 osi_property_set_bool(kGmapEnabledSysProp, false);
100 }
101