add ConnectionsDevice/PresenceDevice to offline frames builders.

PiperOrigin-RevId: 549380626
This commit is contained in:
Anay Wadhera
2023-07-19 11:46:30 -07:00
committed by Copybara-Service
parent c6566b00c7
commit 8450f2b607
8 changed files with 377 additions and 73 deletions
+29 -4
View File
@@ -35,7 +35,6 @@
#include "connections/medium_selector.h"
#include "connections/status.h"
#include "connections/v3/connection_listening_options.h"
#include "connections/v3/connections_device.h"
#include "connections/v3/listeners.h"
#include "internal/flags/nearby_flags.h"
#include "internal/interop/device.h"
@@ -59,8 +58,10 @@ constexpr int kEndpointCancelAlarmTimeout = 10;
using ::location::nearby::connections::ConnectionRequestFrame;
using ::location::nearby::connections::ConnectionResponseFrame;
using ::location::nearby::connections::ConnectionsDevice;
using ::location::nearby::connections::MediumMetadata;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::PresenceDevice;
using ::location::nearby::connections::V1Frame;
using ::securegcm::UKey2Handshake;
@@ -696,8 +697,10 @@ Status BasePcpHandler::RequestConnection(
ConnectionInfo connection_info =
FillConnectionInfo(client, info, connection_options);
Exception write_exception =
WriteConnectionRequestFrame(connection_info, channel.get());
const NearbyDevice* local_device = client->GetLocalDevice();
Exception write_exception = WriteConnectionRequestFrame(
local_device->GetType(), local_device->ToProtoBytes(),
connection_info, channel.get());
if (!write_exception.Ok()) {
NEARBY_LOGS(INFO) << "Failed to send connection request: endpoint_id="
@@ -958,8 +961,30 @@ bool BasePcpHandler::CanReceiveIncomingConnection(ClientProxy* client) const {
}
Exception BasePcpHandler::WriteConnectionRequestFrame(
NearbyDevice::Type device_type, absl::string_view device_proto_bytes,
const ConnectionInfo& conection_info, EndpointChannel* endpoint_channel) {
return endpoint_channel->Write(parser::ForConnectionRequest(conection_info));
ConnectionsDevice connections_device_frame;
PresenceDevice presence_device_frame;
switch (device_type) {
case NearbyDevice::kConnectionsDevice:
if (connections_device_frame.ParseFromString(
std::string(device_proto_bytes))) { // NOLINT
return endpoint_channel->Write(parser::ForConnectionRequestConnections(
connections_device_frame, conection_info));
}
return {Exception::kInvalidProtocolBuffer};
case NearbyDevice::kPresenceDevice:
if (presence_device_frame.ParseFromString(
std::string(device_proto_bytes))) { // NOLINT
return endpoint_channel->Write(parser::ForConnectionRequestPresence(
presence_device_frame, conection_info));
}
return {Exception::kInvalidProtocolBuffer};
default:
// Legacy.
return endpoint_channel->Write(
parser::ForConnectionRequestConnections({}, conection_info));
}
}
void BasePcpHandler::ProcessPreConnectionInitiationFailure(
@@ -462,6 +462,7 @@ class BasePcpHandler : public PcpHandler,
EndpointChannel* endpoint_channel);
static Exception WriteConnectionRequestFrame(
NearbyDevice::Type device_type, absl::string_view device_proto_bytes,
const ConnectionInfo& conection_info, EndpointChannel* endpoint_channel);
static constexpr absl::Duration kConnectionRequestReadTimeout =
absl::Seconds(2);
@@ -37,6 +37,8 @@
#include "connections/status.h"
#include "connections/strategy.h"
#include "connections/v3/connection_listening_options.h"
#include "internal/interop/device.h"
#include "internal/interop/device_provider.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/medium_environment.h"
@@ -89,6 +91,21 @@ constexpr BooleanMediumSelector kTestCases[] = {
},
};
class FakePresenceDevice : public NearbyDevice {
public:
std::string GetEndpointId() const override { return "TEST"; }
MOCK_METHOD(std::vector<ConnectionInfoVariant>, GetConnectionInfos, (),
(const override));
MOCK_METHOD(NearbyDevice::Type, GetType, (), (const override));
MOCK_METHOD(std::string, ToProtoBytes, (), (const override));
};
class FakePresenceDeviceProvider : public NearbyDeviceProvider {
public:
const NearbyDevice* GetLocalDevice() override { return &local_device_; }
FakePresenceDevice local_device_;
};
class MockEndpointChannel : public BaseEndpointChannel {
public:
explicit MockEndpointChannel(Pipe* reader, Pipe* writer)
@@ -823,7 +840,6 @@ TEST_F(BasePcpHandlerTest, WifiMediumFailFallBackToBT) {
TEST_P(BasePcpHandlerTest, RequestConnectionChangesState) {
env_.Start();
std::string endpoint_id{"1234"};
ClientProxy client;
Mediums m;
EndpointChannelManager ecm;
@@ -839,7 +855,83 @@ TEST_P(BasePcpHandlerTest, RequestConnectionChangesState) {
EXPECT_CALL(*channel_a, CloseImpl).Times(1);
EXPECT_CALL(*channel_b, CloseImpl).Times(1);
EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0));
RequestConnection(endpoint_id, std::move(channel_a), channel_b.get(), &client,
RequestConnection("1234", std::move(channel_a), channel_b.get(), &client,
&pcp_handler, connect_medium);
NEARBY_LOG(INFO, "RequestConnection complete");
channel_b->Close();
bwu.Shutdown();
pcp_handler.DisconnectFromEndpointManager();
env_.Stop();
}
TEST_P(BasePcpHandlerTest, CanRequestConnectionPresence) {
env_.Start();
ClientProxy client;
FakePresenceDeviceProvider provider;
EXPECT_CALL(provider.local_device_, GetType)
.WillRepeatedly(Return(NearbyDevice::Type::kPresenceDevice));
EXPECT_CALL(provider.local_device_, ToProtoBytes).WillRepeatedly([]() {
location::nearby::connections::PresenceDevice presence_device;
presence_device.set_endpoint_id("TEST");
presence_device.set_device_id(2468);
presence_device.add_identity_type(1);
presence_device.add_actions(1);
presence_device.add_actions(2);
presence_device.add_actions(3);
presence_device.add_actions(4);
presence_device.add_discovery_medium(
location::nearby::connections::ConnectionRequestFrame::BLUETOOTH);
std::string serialized = presence_device.SerializeAsString();
EXPECT_FALSE(serialized.empty());
return serialized;
});
client.RegisterDeviceProvider(&provider);
Mediums m;
EndpointChannelManager ecm;
EndpointManager em(&ecm);
BwuManager bwu(m, em, ecm, {}, {});
MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu);
StartDiscovery(&client, &pcp_handler);
auto mediums = pcp_handler.GetDiscoveryMediums(&client);
auto connect_medium = mediums[mediums.size() - 1];
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, connect_medium);
auto& channel_a = channel_pair.first;
auto& channel_b = channel_pair.second;
EXPECT_CALL(*channel_a, CloseImpl).Times(1);
EXPECT_CALL(*channel_b, CloseImpl).Times(1);
EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0));
RequestConnection("1234", std::move(channel_a), channel_b.get(), &client,
&pcp_handler, connect_medium);
NEARBY_LOG(INFO, "RequestConnection complete");
channel_b->Close();
bwu.Shutdown();
pcp_handler.DisconnectFromEndpointManager();
env_.Stop();
}
TEST_P(BasePcpHandlerTest, CanRequestConnectionLegacy) {
env_.Start();
ClientProxy client;
FakePresenceDeviceProvider provider;
EXPECT_CALL(provider.local_device_, GetType)
.WillRepeatedly(Return(NearbyDevice::Type::kUnknownDevice));
EXPECT_CALL(provider.local_device_, ToProtoBytes);
client.RegisterDeviceProvider(&provider);
Mediums m;
EndpointChannelManager ecm;
EndpointManager em(&ecm);
BwuManager bwu(m, em, ecm, {}, {});
MockPcpHandler pcp_handler(&m, &em, &ecm, &bwu);
StartDiscovery(&client, &pcp_handler);
auto mediums = pcp_handler.GetDiscoveryMediums(&client);
auto connect_medium = mediums[mediums.size() - 1];
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, connect_medium);
auto& channel_a = channel_pair.first;
auto& channel_b = channel_pair.second;
EXPECT_CALL(*channel_a, CloseImpl).Times(1);
EXPECT_CALL(*channel_b, CloseImpl).Times(1);
EXPECT_CALL(mock_connection_listener_.rejected_cb, Call).Times(AtLeast(0));
RequestConnection("1234", std::move(channel_a), channel_b.get(), &client,
&pcp_handler, connect_medium);
NEARBY_LOG(INFO, "RequestConnection complete");
channel_b->Close();
@@ -1473,10 +1565,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithUnknown) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()->mutable_connection_request()->clear_connections_device();
@@ -1521,10 +1614,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithUnknown) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()->mutable_connection_request()->clear_connections_device();
@@ -1570,10 +1664,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithConnections) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()
@@ -1620,10 +1715,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForPresenceWithPresence) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()
@@ -1669,10 +1765,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithConnections) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()
@@ -1718,10 +1815,11 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) {
ASSERT_TRUE(client.IsListeningForIncomingConnections());
ASSERT_TRUE(pcp_handler.CanReceiveIncomingConnection(&client));
auto channel_pair = SetupConnection(pipe_a_, pipe_b_, Medium::BLUETOOTH);
ByteArray serialized_frame = parser::ForConnectionRequest({
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
ByteArray serialized_frame = parser::ForConnectionRequestConnections(
{}, {
.local_endpoint_id = "ABCD",
.local_endpoint_info = ByteArray("local endpoint"),
});
location::nearby::connections::OfflineFrame frame;
frame.ParseFromString(serialized_frame.AsStringView());
frame.mutable_v1()
@@ -227,7 +227,7 @@ TEST_F(EndpointManagerTest, RegisterFrameProcessorWorks) {
0 /*keep_alive_interval_millis*/,
0 /*keep_alive_timeout_millis*/};
auto read_data = parser::ForConnectionRequest(connection_info);
auto read_data = parser::ForConnectionRequestConnections({}, connection_info);
EXPECT_CALL(*connect_request, OnIncomingFrame);
EXPECT_CALL(*connect_request, OnEndpointDisconnect);
EXPECT_CALL(*endpoint_channel, Read(_))
@@ -393,7 +393,8 @@ TEST_F(EndpointManagerTest, TryDecrypt) {
std::vector<Medium>{Medium::BLE} /*supported_mediums*/,
0 /*keep_alive_interval_millis*/,
0 /*keep_alive_timeout_millis*/};
ByteArray decrypted_data = parser::ForConnectionRequest(connection_info);
ByteArray decrypted_data =
parser::ForConnectionRequestConnections({}, connection_info);
EXPECT_CALL(*connect_request, OnIncomingFrame);
EXPECT_CALL(*connect_request, OnEndpointDisconnect);
EXPECT_CALL(*endpoint_channel, Read(_))
+58 -5
View File
@@ -20,9 +20,9 @@
#include <vector>
#include "connections/implementation/offline_frames_validator.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "connections/status.h"
#include "internal/platform/byte_array.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
namespace nearby {
namespace connections {
@@ -72,20 +72,28 @@ V1Frame::FrameType GetFrameType(const OfflineFrame& frame) {
return V1Frame::UNKNOWN_FRAME_TYPE;
}
ByteArray ForConnectionRequest(const ConnectionInfo& conection_info) {
ByteArray ForConnectionRequestConnections(
const location::nearby::connections::ConnectionsDevice&
proto_connections_device,
const ConnectionInfo& conection_info) {
OfflineFrame frame;
frame.set_version(OfflineFrame::V1);
auto* v1_frame = frame.mutable_v1();
v1_frame->set_type(V1Frame::CONNECTION_REQUEST);
auto* connection_request = v1_frame->mutable_connection_request();
if (!conection_info.local_endpoint_id.empty())
if (proto_connections_device.has_endpoint_id()) {
connection_request->mutable_connections_device()->MergeFrom(
proto_connections_device);
}
if (!conection_info.local_endpoint_id.empty()) {
connection_request->set_endpoint_id(conection_info.local_endpoint_id);
}
if (!conection_info.local_endpoint_info.Empty()) {
connection_request->set_endpoint_name(
std::string(conection_info.local_endpoint_info));
conection_info.local_endpoint_info.string_data());
connection_request->set_endpoint_info(
std::string(conection_info.local_endpoint_info));
conection_info.local_endpoint_info.string_data());
}
connection_request->set_nonce(conection_info.nonce);
auto* medium_metadata = connection_request->mutable_medium_metadata();
@@ -112,6 +120,51 @@ ByteArray ForConnectionRequest(const ConnectionInfo& conection_info) {
return ToBytes(std::move(frame));
}
ByteArray ForConnectionRequestPresence(
const location::nearby::connections::PresenceDevice& proto_presence_device,
const ConnectionInfo& connection_info) {
OfflineFrame frame;
frame.set_version(OfflineFrame::V1);
auto* v1_frame = frame.mutable_v1();
v1_frame->set_type(V1Frame::CONNECTION_REQUEST);
auto* connection_request = v1_frame->mutable_connection_request();
if (!connection_info.local_endpoint_id.empty()) {
connection_request->set_endpoint_id(proto_presence_device.endpoint_id());
}
if (!connection_info.local_endpoint_info.Empty()) {
connection_request->set_endpoint_name(
connection_info.local_endpoint_info.string_data());
connection_request->set_endpoint_info(
connection_info.local_endpoint_info.string_data());
}
connection_request->mutable_presence_device()->MergeFrom(
proto_presence_device);
connection_request->set_nonce(connection_info.nonce);
auto* medium_metadata = connection_request->mutable_medium_metadata();
medium_metadata->set_supports_5_ghz(connection_info.supports_5_ghz);
if (!connection_info.bssid.empty())
medium_metadata->set_bssid(connection_info.bssid);
medium_metadata->set_ap_frequency(connection_info.ap_frequency);
if (!connection_info.ip_address.empty())
medium_metadata->set_ip_address(connection_info.ip_address);
if (!connection_info.supported_mediums.empty()) {
for (const auto& medium : connection_info.supported_mediums) {
connection_request->add_mediums(MediumToConnectionRequestMedium(medium));
}
}
if (connection_info.keep_alive_interval_millis > 0) {
connection_request->set_keep_alive_interval_millis(
connection_info.keep_alive_interval_millis);
}
if (connection_info.keep_alive_timeout_millis > 0) {
connection_request->set_keep_alive_timeout_millis(
connection_info.keep_alive_timeout_millis);
}
return ToBytes(std::move(frame));
}
ByteArray ForConnectionResponse(std::int32_t status, const OsInfo& os_info) {
OfflineFrame frame;
+7 -1
View File
@@ -45,7 +45,13 @@ location::nearby::connections::V1Frame::FrameType GetFrameType(
const location::nearby::connections::OfflineFrame& offline_frame);
// Builds Connection Request / Response messages.
ByteArray ForConnectionRequest(const ConnectionInfo& conection_info);
ByteArray ForConnectionRequestConnections(
const location::nearby::connections::ConnectionsDevice&
proto_connections_device,
const ConnectionInfo& conection_info);
ByteArray ForConnectionRequestPresence(
const location::nearby::connections::PresenceDevice& proto_presence_device,
const ConnectionInfo& connection_info);
ByteArray ForConnectionResponse(
std::int32_t status, const location::nearby::connections::OsInfo& os_info);
+149 -29
View File
@@ -90,8 +90,8 @@ TEST(OfflineFramesTest, CanParseMessageFromBytes) {
std::vector(kMediums.begin(), kMediums.end()));
}
TEST(OfflineFramesTest, CanGenerateConnectionRequest) {
constexpr char kExpected[] =
TEST(OfflineFramesTest, CanGenerateLegacyConnectionRequest) {
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -132,15 +132,135 @@ TEST(OfflineFramesTest, CanGenerateConnectionRequest) {
kMediums.begin(), kMediums.end()),
kKeepAliveIntervalMillis,
kKeepAliveTimeoutMillis};
ByteArray bytes = ForConnectionRequest(connection_info);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateConnectionsConnectionRequest) {
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
type: CONNECTION_REQUEST
connection_request: <
endpoint_id: "ABC"
endpoint_name: "XYZ"
endpoint_info: "XYZ"
nonce: 1234
medium_metadata: <
supports_5_ghz: true
bssid: "FF:FF:FF:FF:FF:FF"
ip_address: "8xqT"
ap_frequency: 2412
>
mediums: MDNS
mediums: BLUETOOTH
mediums: WIFI_HOTSPOT
mediums: BLE
mediums: WIFI_LAN
mediums: WIFI_AWARE
mediums: NFC
mediums: WIFI_DIRECT
mediums: WEB_RTC
keep_alive_interval_millis: 1000
keep_alive_timeout_millis: 5000
connections_device {
endpoint_id: "ABC"
endpoint_type: CONNECTIONS_ENDPOINT
endpoint_info: "XYZ"
}
>
>)pb";
location::nearby::connections::ConnectionsDevice connections_device;
connections_device.set_endpoint_id("ABC");
connections_device.set_endpoint_type(
location::nearby::connections::CONNECTIONS_ENDPOINT);
connections_device.set_endpoint_info("XYZ");
ConnectionInfo connection_info{std::string(kEndpointId),
ByteArray{std::string(kEndpointName)},
kNonce,
kSupports5ghz,
std::string(kBssid),
kApFrequency,
std::string(kIp4Bytes),
std::vector<Medium, std::allocator<Medium>>(
kMediums.begin(), kMediums.end()),
kKeepAliveIntervalMillis,
kKeepAliveTimeoutMillis};
ByteArray bytes =
ForConnectionRequestConnections(connections_device, connection_info);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGeneratePresenceConnectionRequest) {
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
type: CONNECTION_REQUEST
connection_request: <
endpoint_id: "ABC"
endpoint_name: "XYZ"
endpoint_info: "XYZ"
nonce: 1234
medium_metadata: <
supports_5_ghz: true
bssid: "FF:FF:FF:FF:FF:FF"
ip_address: "8xqT"
ap_frequency: 2412
>
mediums: MDNS
mediums: BLUETOOTH
mediums: WIFI_HOTSPOT
mediums: BLE
mediums: WIFI_LAN
mediums: WIFI_AWARE
mediums: NFC
mediums: WIFI_DIRECT
mediums: WEB_RTC
keep_alive_interval_millis: 1000
keep_alive_timeout_millis: 5000
presence_device {
endpoint_id: "ABC"
endpoint_type: PRESENCE_ENDPOINT
device_name: "TEST DEVICE"
}
>
>)pb";
ConnectionInfo connection_info{std::string(kEndpointId),
ByteArray{std::string(kEndpointName)},
kNonce,
kSupports5ghz,
std::string(kBssid),
kApFrequency,
std::string(kIp4Bytes),
std::vector<Medium, std::allocator<Medium>>(
kMediums.begin(), kMediums.end()),
kKeepAliveIntervalMillis,
kKeepAliveTimeoutMillis};
location::nearby::connections::PresenceDevice presence_device;
presence_device.set_endpoint_id("ABC");
presence_device.set_endpoint_type(
location::nearby::connections::PRESENCE_ENDPOINT);
presence_device.set_device_name("TEST DEVICE");
ByteArray bytes =
ForConnectionRequestPresence(presence_device, connection_info);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -157,7 +277,7 @@ TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
ByteArray bytes = ForConnectionResponse(1, os_info);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
@@ -170,7 +290,7 @@ TEST(OfflineFramesTest, CanGenerateControlPayloadTransfer) {
control.set_event(PayloadTransferFrame::ControlMessage::PAYLOAD_CANCELED);
control.set_offset(150);
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -184,7 +304,7 @@ TEST(OfflineFramesTest, CanGenerateControlPayloadTransfer) {
ByteArray bytes = ForControlPayloadTransfer(header, control);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
@@ -198,7 +318,7 @@ TEST(OfflineFramesTest, CanGenerateDataPayloadTransfer) {
chunk.set_offset(150);
chunk.set_flags(1);
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -212,12 +332,12 @@ TEST(OfflineFramesTest, CanGenerateDataPayloadTransfer) {
ByteArray bytes = ForDataPayloadTransfer(header, chunk);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuWifiHotspotPathAvailable) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -241,12 +361,12 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiHotspotPathAvailable) {
"0.0.0.0", false);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -263,12 +383,12 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) {
ByteArray bytes = ForBwuWifiLanPathAvailable("\x01\x02\x03\x04", 1234);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuWifiAwarePathAvailable) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -291,12 +411,12 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiAwarePathAvailable) {
"password", false);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuWifiDirectPathAvailable) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -321,12 +441,12 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiDirectPathAvailable) {
"DIRECT-A0-0123456789AB", "password", 1000, 2412, false, "192.168.1.1");
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuBluetoothPathAvailable) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -347,12 +467,12 @@ TEST(OfflineFramesTest, CanGenerateBwuBluetoothPathAvailable) {
ForBwuBluetoothPathAvailable("service", "\x11\x22\x33\x44\x55\x66");
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuLastWrite) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -362,12 +482,12 @@ TEST(OfflineFramesTest, CanGenerateBwuLastWrite) {
ByteArray bytes = ForBwuLastWrite();
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuSafeToClose) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -377,19 +497,19 @@ TEST(OfflineFramesTest, CanGenerateBwuSafeToClose) {
ByteArray bytes = ForBwuSafeToClose();
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateBwuIntroduction) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
type: BANDWIDTH_UPGRADE_NEGOTIATION
bandwidth_upgrade_negotiation: <
event_type: CLIENT_INTRODUCTION
client_introduction: <
client_introduction: <
endpoint_id: "ABC"
supports_disabling_encryption: false
>
@@ -399,12 +519,12 @@ TEST(OfflineFramesTest, CanGenerateBwuIntroduction) {
std::string(kEndpointId), false /* supports_disabling_encryption */);
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
TEST(OfflineFramesTest, CanGenerateKeepAlive) {
constexpr char kExpected[] =
constexpr absl::string_view kExpected =
R"pb(
version: V1
v1: <
@@ -414,7 +534,7 @@ TEST(OfflineFramesTest, CanGenerateKeepAlive) {
ByteArray bytes = ForKeepAlive();
auto response = FromBytes(bytes);
ASSERT_TRUE(response.ok());
OfflineFrame message = FromBytes(bytes).result();
OfflineFrame message = response.result();
EXPECT_THAT(message, EqualsProto(kExpected));
}
@@ -76,7 +76,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
ValidatesAsOkWithValidConnectionRequestFrame) {
OfflineFrame offline_frame;
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);
@@ -88,7 +88,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
ValidatesAsFailWithNullConnectionRequestFrame) {
OfflineFrame offline_frame;
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto* v1_frame = offline_frame.mutable_v1();
@@ -104,7 +104,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
OfflineFrame offline_frame;
connection_info_.local_endpoint_id = "";
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);
@@ -117,7 +117,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
OfflineFrame offline_frame;
connection_info_.local_endpoint_info = ByteArray{""};
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);
@@ -130,7 +130,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
OfflineFrame offline_frame;
connection_info_.bssid = "";
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);
@@ -143,7 +143,7 @@ TEST_F(OfflineFramesConnectionRequestTest,
OfflineFrame offline_frame;
connection_info_.supported_mediums = {};
ByteArray bytes = ForConnectionRequest(connection_info_);
ByteArray bytes = ForConnectionRequestConnections({}, connection_info_);
offline_frame.ParseFromString(std::string(bytes));
auto ret_value = EnsureValidOfflineFrame(offline_frame);