mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Create ConnectionsDeviceProvider
PiperOrigin-RevId: 529781099
This commit is contained in:
committed by
Copybara-Service
parent
0200a92978
commit
630b2dd3db
@@ -496,6 +496,7 @@ let package = Package(
|
||||
"connections/implementation/ble_advertisement_test.cc",
|
||||
"connections/implementation/base_endpoint_channel_test.cc",
|
||||
"connections/v3/connections_device_test.cc",
|
||||
"connections/v3/connections_device_provider_test.cc",
|
||||
"connections/core_test.cc",
|
||||
"connections/status_test.cc",
|
||||
"connections/payload_test.cc",
|
||||
|
||||
@@ -5,6 +5,7 @@ cc_library(
|
||||
"connection_listening_options.h",
|
||||
"connection_resolution.h",
|
||||
"connections_device.h",
|
||||
"connections_device_provider.h",
|
||||
"listeners.h",
|
||||
],
|
||||
visibility = [
|
||||
@@ -23,6 +24,7 @@ cc_library(
|
||||
cc_test(
|
||||
name = "v3_types_test",
|
||||
srcs = [
|
||||
"connections_device_provider_test.cc",
|
||||
"connections_device_test.cc",
|
||||
],
|
||||
deps = [
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "connections/v3/connections_device.h"
|
||||
#include "internal/interop/device_provider.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
|
||||
class ConnectionsDeviceProvider
|
||||
: public NearbyDeviceProvider<ConnectionsDevice> {
|
||||
public:
|
||||
ConnectionsDeviceProvider(
|
||||
absl::string_view endpoint_info,
|
||||
const std::vector<ConnectionInfoVariant> connection_infos)
|
||||
: device_{endpoint_info, connection_infos} {}
|
||||
ConnectionsDeviceProvider(
|
||||
absl::string_view endpoint_id, absl::string_view endpoint_info,
|
||||
const std::vector<ConnectionInfoVariant> connection_infos)
|
||||
: device_{endpoint_id, endpoint_info, connection_infos} {}
|
||||
|
||||
const ConnectionsDevice& GetLocalDevice() override { return device_; }
|
||||
|
||||
private:
|
||||
ConnectionsDevice device_;
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "connections/v3/connections_device_provider.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
namespace {
|
||||
|
||||
constexpr absl::string_view kEndpointId = "ABCD";
|
||||
constexpr absl::string_view kEndpointInfo = "NC endpoint";
|
||||
|
||||
TEST(ConnectionsDeviceProviderTest, TestProviderWorksTwoArgs) {
|
||||
ConnectionsDeviceProvider provider(kEndpointInfo, {});
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetEndpointInfo(), kEndpointInfo);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetType(),
|
||||
NearbyDevice::Type::kConnectionsDevice);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetConnectionInfos().size(), 0);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetEndpointId().size(),
|
||||
kEndpointIdLength);
|
||||
}
|
||||
|
||||
TEST(ConnectionsDeviceProviderTest, TestProviderWorksThreeArgs) {
|
||||
ConnectionsDeviceProvider provider(kEndpointId, kEndpointInfo, {});
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetEndpointInfo(), kEndpointInfo);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetType(),
|
||||
NearbyDevice::Type::kConnectionsDevice);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetConnectionInfos().size(), 0);
|
||||
EXPECT_EQ(provider.GetLocalDevice().GetEndpointId(), kEndpointId);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
@@ -54,6 +54,16 @@ TEST(ConnectionsDeviceTest, TestThreeArgumentConstructor) {
|
||||
EXPECT_EQ(device.GetEndpointInfo(), "connections endpoint");
|
||||
}
|
||||
|
||||
TEST(ConnectionsDeviceTest, TestLongEndpointId) {
|
||||
auto connection_infos = CreateDefaultConnectionInfos();
|
||||
ConnectionsDevice device("ABCDEF", "connections endpoint", connection_infos);
|
||||
EXPECT_EQ(device.GetConnectionInfos(), connection_infos);
|
||||
EXPECT_EQ(device.GetType(), NearbyDevice::Type::kConnectionsDevice);
|
||||
EXPECT_EQ(device.GetEndpointId().length(), 4);
|
||||
EXPECT_NE(device.GetEndpointId(), "ABCDEF");
|
||||
EXPECT_EQ(device.GetEndpointInfo(), "connections endpoint");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
|
||||
Reference in New Issue
Block a user