1 /*
2 * Copyright 2023 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 <base/strings/stringprintf.h>
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 #include <sys/socket.h>
21
22 #include <string>
23
24 #include "bta/dm/bta_dm_gatt_client.h"
25 #include "common/circular_buffer.h"
26
27 using namespace bluetooth::common;
28
29 // Test hooks
30 namespace bluetooth {
31 namespace legacy {
32 namespace testing {
33
34 std::vector<TimestampedEntry<std::string>> PullCopyOfGattHistory();
35
36 } // namespace testing
37 } // namespace legacy
38 } // namespace bluetooth
39
40 class BtaDiscTest : public testing::Test {
41 protected:
SetUp()42 void SetUp() override {}
43
TearDown()44 void TearDown() override {}
45 };
46
TEST_F(BtaDiscTest,nop)47 TEST_F(BtaDiscTest, nop) {}
48
TEST_F(BtaDiscTest,gatt_history_callback)49 TEST_F(BtaDiscTest, gatt_history_callback) {
50 std::array<std::string, 3> a = {
51 "ThisIsATest 0",
52 "ThisIsATest 1",
53 "ThisIsATest 2",
54 };
55
56 // C string
57 gatt_history_callback(base::StringPrintf("%s", a[0].c_str()));
58 // Cpp string
59 gatt_history_callback(a[1]);
60 // Third entry for "fun"
61 gatt_history_callback(base::StringPrintf("%s", a[2].c_str()));
62
63 std::vector<bluetooth::common::TimestampedEntry<std::string>> history =
64 bluetooth::legacy::testing::PullCopyOfGattHistory();
65 ASSERT_EQ(3UL, history.size());
66 ASSERT_STREQ(a[0].c_str(), history[0].entry.c_str());
67 ASSERT_STREQ(a[1].c_str(), history[1].entry.c_str());
68 ASSERT_STREQ(a[2].c_str(), history[2].entry.c_str());
69 }
70