1 /*
2  * Copyright 2020 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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include "storage/adapter_config.h"
21 #include "storage/mutation.h"
22 
23 namespace testing {
24 
25 using bluetooth::common::ByteArray;
26 using bluetooth::hci::Address;
27 using bluetooth::hci::DeviceType;
28 using bluetooth::storage::AdapterConfig;
29 using bluetooth::storage::ConfigCache;
30 using bluetooth::storage::Device;
31 using bluetooth::storage::Mutation;
32 
TEST(AdapterConfigTest,create_new_adapter_config)33 TEST(AdapterConfigTest, create_new_adapter_config) {
34   ConfigCache config(10, Device::kLinkKeyProperties);
35   ConfigCache memory_only_config(10, {});
36   AdapterConfig adapter_config(&config, &memory_only_config, "Adapter");
37   ASSERT_FALSE(adapter_config.GetAddress());
38 }
39 
TEST(AdapterConfigTest,set_property)40 TEST(AdapterConfigTest, set_property) {
41   ConfigCache config(10, Device::kLinkKeyProperties);
42   ConfigCache memory_only_config(10, {});
43   Address address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
44   AdapterConfig adapter_config(&config, &memory_only_config, "Adapter");
45   ASSERT_FALSE(adapter_config.GetAddress());
46   Mutation mutation(&config, &memory_only_config);
47   mutation.Add(adapter_config.SetAddress(address));
48   mutation.Commit();
49   ASSERT_THAT(adapter_config.GetAddress(), Optional(Eq(address)));
50 }
51 
TEST(AdapterConfigTest,equality_test)52 TEST(AdapterConfigTest, equality_test) {
53   ConfigCache config(10, Device::kLinkKeyProperties);
54   ConfigCache memory_only_config(10, {});
55   bluetooth::hci::Address address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
56   AdapterConfig adapter_config_1(&config, &memory_only_config, "Adapter");
57   AdapterConfig adapter_config_2(&config, &memory_only_config, "Adapter");
58   ASSERT_EQ(adapter_config_1, adapter_config_2);
59   ConfigCache memory_only_config_2(10, {});
60   AdapterConfig adapter_config_3(&config, &memory_only_config_2, "Adapter");
61   ASSERT_NE(adapter_config_1, adapter_config_3);
62 }
63 
64 }  // namespace testing