mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove deprecated OutputStream::Write method.
PiperOrigin-RevId: 854235255
This commit is contained in:
committed by
Copybara-Service
parent
fbf66ad7e3
commit
c2c54a3ca0
@@ -80,7 +80,8 @@ std::function<void()> MakeDataPump(
|
||||
if (monitor) {
|
||||
monitor(read_response.result());
|
||||
}
|
||||
auto write_response = output->Write(read_response.result());
|
||||
auto write_response =
|
||||
output->Write(read_response.result().AsStringView());
|
||||
if (write_response.Raised()) {
|
||||
LOG(INFO) << "Peer writer closed on '" << label << "'";
|
||||
input->Close();
|
||||
|
||||
@@ -53,12 +53,12 @@ class FakeEndpointChannel : public EndpointChannel {
|
||||
}
|
||||
Exception Write(const ByteArray& data) override {
|
||||
write_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return out_ ? out_->Write(data) : Exception{Exception::kIo};
|
||||
return out_ ? out_->Write(data.AsStringView()) : Exception{Exception::kIo};
|
||||
}
|
||||
Exception Write(const ByteArray& data,
|
||||
PacketMetaData& packet_meta_data) override {
|
||||
write_timestamp_ = SystemClock::ElapsedRealtime();
|
||||
return out_ ? out_->Write(data) : Exception{Exception::kIo};
|
||||
return out_ ? out_->Write(data.AsStringView()) : Exception{Exception::kIo};
|
||||
}
|
||||
void Close() override {
|
||||
if (in_) in_->Close();
|
||||
|
||||
@@ -82,7 +82,8 @@ std::function<void()> MakeDataPump(
|
||||
if (monitor) {
|
||||
monitor(read_response.result());
|
||||
}
|
||||
auto write_response = output->Write(read_response.result());
|
||||
auto write_response =
|
||||
output->Write(read_response.result().AsStringView());
|
||||
if (write_response.Raised()) {
|
||||
LOG(INFO) << "Peer writer closed on '" << label << "'";
|
||||
input->Close();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "connections/implementation/mediums/ble/ble_l2cap_packet.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
@@ -203,7 +202,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithInvalidLengthAdvertisement) {
|
||||
TEST(BleL2capPacketTest, CreateFromStreamFailsReadCommand) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
|
||||
output->Write(ByteArray{});
|
||||
output->Write("");
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -216,7 +215,7 @@ TEST(BleL2capPacketTest, CreateFromStreamRequestAdvertisement) {
|
||||
BleL2capPacket::ByteArrayForRequestAdvertisement(std::string(kServiceID));
|
||||
ASSERT_TRUE(byte_array.ok());
|
||||
|
||||
output->Write(*byte_array);
|
||||
output->Write(byte_array->AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -233,7 +232,7 @@ TEST(BleL2capPacketTest, CreateFromStreamZeroDataLength) {
|
||||
1, static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement)),
|
||||
std::string("\x00\x00", 2));
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -248,7 +247,7 @@ TEST(BleL2capPacketTest,
|
||||
1, static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement)),
|
||||
std::string("\x00\x01", 2));
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -262,7 +261,7 @@ TEST(BleL2capPacketTest, CreateFromStreamFailsReadServiceIdHash) {
|
||||
1, static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement)),
|
||||
std::string("\x00\x03", 2));
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -273,7 +272,7 @@ TEST(BleL2capPacketTest, CreateFromStreamRequestAdvertisementFinish) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
auto byte_array = BleL2capPacket::ByteArrayForRequestAdvertisementFinish();
|
||||
|
||||
output->Write(byte_array);
|
||||
output->Write(byte_array.AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -288,7 +287,7 @@ TEST(BleL2capPacketTest, CreateFromStreamResponseAdvertisement) {
|
||||
BleL2capPacket::ByteArrayForResponseAdvertisement(advertisement);
|
||||
ASSERT_TRUE(byte_array.ok());
|
||||
|
||||
output->Write(*byte_array);
|
||||
output->Write(byte_array->AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -306,7 +305,7 @@ TEST(BleL2capPacketTest,
|
||||
BleL2capPacket::Command::kResponseAdvertisement)),
|
||||
"\xFF\xFF");
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -320,7 +319,7 @@ TEST(BleL2capPacketTest, CreateFromStreamFailsReadAdvertisement) {
|
||||
BleL2capPacket::Command::kResponseAdvertisement)),
|
||||
std::string("\x00\x0a", 2));
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -334,7 +333,7 @@ TEST(BleL2capPacketTest, CreateFromStreamResponseLargeAdvertisement) {
|
||||
BleL2capPacket::ByteArrayForResponseAdvertisement(advertisement);
|
||||
ASSERT_TRUE(byte_array.ok());
|
||||
|
||||
output->Write(*byte_array);
|
||||
output->Write(byte_array->AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -348,7 +347,7 @@ TEST(BleL2capPacketTest, CreateFromStreamServiceIdNotFound) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
auto byte_array = BleL2capPacket::ByteArrayForServiceIdNotFound();
|
||||
|
||||
output->Write(byte_array);
|
||||
output->Write(byte_array.AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -360,7 +359,7 @@ TEST(BleL2capPacketTest, CreateFromStreamRequestDataConnection) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
auto byte_array = BleL2capPacket::ByteArrayForRequestDataConnection();
|
||||
|
||||
output->Write(byte_array);
|
||||
output->Write(byte_array.AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -372,7 +371,7 @@ TEST(BleL2capPacketTest, CreateFromStreamDataConnectionReady) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
auto byte_array = BleL2capPacket::ByteArrayForDataConnectionReady();
|
||||
|
||||
output->Write(byte_array);
|
||||
output->Write(byte_array.AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -384,7 +383,7 @@ TEST(BleL2capPacketTest, CreateFromStreamDataConnectionFailure) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
auto byte_array = BleL2capPacket::ByteArrayForDataConnectionFailure();
|
||||
|
||||
output->Write(byte_array);
|
||||
output->Write(byte_array.AsStringView());
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
@@ -396,7 +395,7 @@ TEST(BleL2capPacketTest, CreateFromStreamUnsupportedCommand) {
|
||||
auto [input, output] = nearby::CreatePipe();
|
||||
std::string out = absl::StrCat(std::string(1, static_cast<char>(0XFF)));
|
||||
|
||||
output->Write(ByteArray{std::move(out)});
|
||||
output->Write(out);
|
||||
output->Close();
|
||||
|
||||
auto ble_l2cap_packet = BleL2capPacket::CreateFromStream(*input);
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include "connections/implementation/mediums/webrtc/connection_flow.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/mediums/webrtc/data_channel_listener.h"
|
||||
#include "connections/implementation/mediums/webrtc/local_ice_candidate_listener.h"
|
||||
@@ -130,13 +130,12 @@ TEST_F(ConnectionFlowTest, SuccessfulOfferAnswerFlow) {
|
||||
EXPECT_TRUE(answerer_socket.ok());
|
||||
|
||||
// Send message on data channel
|
||||
const char message[] = "Test";
|
||||
offerer_socket.result().GetImpl().GetOutputStream().Write(
|
||||
ByteArray(message, 4));
|
||||
absl::string_view message = "Test";
|
||||
offerer_socket.result().GetImpl().GetOutputStream().Write(message);
|
||||
ExceptionOr<ByteArray> received_message =
|
||||
answerer_socket.result().GetImpl().GetInputStream().Read(4);
|
||||
EXPECT_TRUE(received_message.ok());
|
||||
EXPECT_EQ(received_message.result(), ByteArray{message});
|
||||
EXPECT_EQ(received_message.result(), ByteArray{message.data()});
|
||||
}
|
||||
|
||||
TEST_F(ConnectionFlowTest, CreateAnswerBeforeOfferReceived) {
|
||||
@@ -338,8 +337,8 @@ TEST_F(ConnectionFlowTest, TerminateAnswerer) {
|
||||
latch.Await();
|
||||
|
||||
// Send message on data channel
|
||||
std::string message = "Test";
|
||||
offerer_socket.result().GetOutputStream().Write(ByteArray{message});
|
||||
absl::string_view message = "Test";
|
||||
offerer_socket.result().GetOutputStream().Write(message);
|
||||
ExceptionOr<ByteArray> received_message =
|
||||
answerer_socket.result().GetInputStream().Read(4);
|
||||
EXPECT_TRUE(received_message.GetResult().Empty());
|
||||
@@ -429,8 +428,8 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
|
||||
latch.Await();
|
||||
|
||||
// Send message on data channel
|
||||
std::string message = "Test";
|
||||
offerer_socket.result().GetOutputStream().Write(ByteArray{message});
|
||||
absl::string_view message = "Test";
|
||||
offerer_socket.result().GetOutputStream().Write(message);
|
||||
ExceptionOr<ByteArray> received_message =
|
||||
answerer_socket.result().GetInputStream().Read(4);
|
||||
EXPECT_TRUE(received_message.GetResult().Empty());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "connections/implementation/mediums/webrtc_peer_id.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
@@ -77,7 +78,7 @@ TEST_P(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message xyz");
|
||||
absl::string_view message("message xyz");
|
||||
|
||||
receiver.StartAcceptingConnections(
|
||||
service_id, self_id, location_hint,
|
||||
@@ -105,7 +106,7 @@ TEST_P(WebRtcTest, ConnectBothDevices_ShutdownSignaling_SendData) {
|
||||
ExceptionOr<ByteArray> received_msg =
|
||||
receiver_socket.GetInputStream().Read(/*size=*/32);
|
||||
ASSERT_TRUE(received_msg.ok());
|
||||
EXPECT_EQ(message, received_msg.result());
|
||||
EXPECT_EQ(message, received_msg.result().AsStringView());
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ TEST_P(WebRtcTest, CanCancelConnect) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message");
|
||||
absl::string_view message("message");
|
||||
|
||||
receiver.StartAcceptingConnections(
|
||||
service_id, self_id, location_hint,
|
||||
@@ -146,7 +147,7 @@ TEST_P(WebRtcTest, CanCancelConnect) {
|
||||
ExceptionOr<ByteArray> received_msg =
|
||||
receiver_socket.GetInputStream().Read(/*size=*/32);
|
||||
ASSERT_TRUE(received_msg.ok());
|
||||
EXPECT_EQ(message, received_msg.result());
|
||||
EXPECT_EQ(message, received_msg.result().AsStringView());
|
||||
|
||||
receiver_socket.Close();
|
||||
} else {
|
||||
@@ -267,7 +268,7 @@ TEST_P(WebRtcTest, ConnectTwice) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message xyz");
|
||||
absl::string_view message("message xyz");
|
||||
|
||||
receiver.StartAcceptingConnections(
|
||||
service_id, self_id, location_hint,
|
||||
@@ -307,7 +308,7 @@ TEST_P(WebRtcTest, ConnectTwice) {
|
||||
ExceptionOr<ByteArray> received_msg =
|
||||
receiver_socket.GetInputStream().Read(/*size=*/32);
|
||||
ASSERT_TRUE(received_msg.ok());
|
||||
EXPECT_EQ(message, received_msg.result());
|
||||
EXPECT_EQ(message, received_msg.result().AsStringView());
|
||||
|
||||
receiver_socket.Close();
|
||||
env_.Stop();
|
||||
@@ -324,7 +325,6 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndAbort) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message xyz");
|
||||
|
||||
receiver.StartAcceptingConnections(
|
||||
service_id, self_id, location_hint,
|
||||
@@ -360,7 +360,7 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndSendData) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message");
|
||||
absl::string_view message("message");
|
||||
|
||||
receiver.StartAcceptingConnections(
|
||||
service_id, self_id, location_hint,
|
||||
@@ -385,7 +385,7 @@ TEST_P(WebRtcTest, ConnectBothDevicesAndSendData) {
|
||||
ExceptionOr<ByteArray> received_msg =
|
||||
receiver_socket.GetInputStream().Read(/*size=*/32);
|
||||
ASSERT_TRUE(received_msg.ok());
|
||||
EXPECT_EQ(message, received_msg.result());
|
||||
EXPECT_EQ(message, received_msg.result().AsStringView());
|
||||
|
||||
receiver_socket.Close();
|
||||
env_.Stop();
|
||||
@@ -461,7 +461,6 @@ TEST_P(WebRtcTest, CancelDuringConnect) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message");
|
||||
|
||||
CancellationFlag receiver_flag;
|
||||
std::unique_ptr<WebRtc> receiver = std::make_unique<TestWebRtc>(
|
||||
@@ -518,7 +517,6 @@ TEST_P(WebRtcTest, CancelBeforeConnect) {
|
||||
const std::string service_id("NearbySharing");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message");
|
||||
|
||||
CancellationFlag receiver_flag;
|
||||
std::unique_ptr<WebRtc> receiver = std::make_unique<TestWebRtc>(
|
||||
@@ -566,7 +564,6 @@ TEST_P(WebRtcTest, CancelDuringConnect_MultipleConnect) {
|
||||
const std::string ph_service_id("PhoneHub");
|
||||
LocationHint location_hint;
|
||||
Future<bool> connected;
|
||||
ByteArray message("message xyz");
|
||||
|
||||
CancellationFlag receiver_flag;
|
||||
std::unique_ptr<WebRtc> receiver = std::make_unique<TestWebRtc>(
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/implementation/system_clock.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
@@ -335,19 +336,18 @@ TEST_P(OfflineServiceControllerTest, CanSendStreamPayload) {
|
||||
OfflineSimulationUser user_b(kDeviceB, GetParam());
|
||||
user_b.ExpectPayload(payload_latch_);
|
||||
ASSERT_TRUE(SetupConnection(user_a, user_b));
|
||||
ByteArray message(std::string{kMessage});
|
||||
auto [input, tx] = CreatePipe();
|
||||
user_a.SendPayload(Payload(std::move(input)));
|
||||
tx->Write(message);
|
||||
tx->Write(kMessage);
|
||||
EXPECT_TRUE(payload_latch_.Await(kLongTimeout));
|
||||
ASSERT_NE(user_b.GetPayload().AsStream(), nullptr);
|
||||
InputStream& rx = *user_b.GetPayload().AsStream();
|
||||
ASSERT_TRUE(user_b.WaitForProgress(
|
||||
[size = message.size()](const PayloadProgressInfo& info) -> bool {
|
||||
[size = kMessage.size()](const PayloadProgressInfo& info) -> bool {
|
||||
return info.bytes_transferred >= size;
|
||||
},
|
||||
kLongTimeout));
|
||||
EXPECT_EQ(rx.Read(kChunkSize).result(), message);
|
||||
EXPECT_EQ(rx.Read(kChunkSize).result().AsStringView(), kMessage);
|
||||
user_a.Stop();
|
||||
user_b.Stop();
|
||||
env_.Stop();
|
||||
@@ -359,23 +359,22 @@ TEST_P(OfflineServiceControllerTest, CanCancelStreamPayload) {
|
||||
OfflineSimulationUser user_b(kDeviceB, GetParam());
|
||||
user_b.ExpectPayload(payload_latch_);
|
||||
ASSERT_TRUE(SetupConnection(user_a, user_b));
|
||||
ByteArray message(std::string{kMessage});
|
||||
auto [input, tx] = CreatePipe();
|
||||
user_a.SendPayload(Payload(std::move(input)));
|
||||
tx->Write(message);
|
||||
tx->Write(kMessage);
|
||||
EXPECT_TRUE(payload_latch_.Await(kLongTimeout));
|
||||
ASSERT_NE(user_b.GetPayload().AsStream(), nullptr);
|
||||
InputStream& rx = *user_b.GetPayload().AsStream();
|
||||
ASSERT_TRUE(user_b.WaitForProgress(
|
||||
[size = message.size()](const PayloadProgressInfo& info) -> bool {
|
||||
[size = kMessage.size()](const PayloadProgressInfo& info) -> bool {
|
||||
return info.bytes_transferred >= size;
|
||||
},
|
||||
kLongTimeout));
|
||||
EXPECT_EQ(rx.Read(kChunkSize).result(), message);
|
||||
EXPECT_EQ(rx.Read(kChunkSize).result().AsStringView(), kMessage);
|
||||
user_b.CancelPayload();
|
||||
absl::Time start_time = SystemClock::ElapsedRealtime();
|
||||
while (true) {
|
||||
if (!tx->Write(message).Ok()) break;
|
||||
if (!tx->Write(kMessage).Ok()) break;
|
||||
absl::Duration run_time = SystemClock::ElapsedRealtime() - start_time;
|
||||
if (run_time >= kLongTimeout) {
|
||||
EXPECT_LT(run_time, kLongTimeout);
|
||||
|
||||
@@ -250,7 +250,7 @@ TEST_F(BluetoothClassicMediumTest, SendData) {
|
||||
bt_b_->ListenForService(service_name, service_uuid);
|
||||
ASSERT_TRUE(server_socket.IsValid());
|
||||
{
|
||||
ByteArray data("data");
|
||||
absl::string_view data("data");
|
||||
CancellationFlag flag;
|
||||
SingleThreadExecutor server_executor;
|
||||
SingleThreadExecutor client_executor;
|
||||
@@ -268,7 +268,7 @@ TEST_F(BluetoothClassicMediumTest, SendData) {
|
||||
socket_b.GetInputStream().Read(data.size());
|
||||
ASSERT_EQ(result.exception(), Exception::kSuccess);
|
||||
ASSERT_TRUE(result.ok());
|
||||
EXPECT_EQ(result.GetResult(), data);
|
||||
EXPECT_EQ(result.GetResult().AsStringView(), data);
|
||||
});
|
||||
}
|
||||
server_socket.Close();
|
||||
@@ -297,7 +297,7 @@ TEST_F(BluetoothClassicMediumTest, IoOnClosedSocketReturnsEmpty) {
|
||||
bt_b_->ListenForService(service_name, service_uuid);
|
||||
ASSERT_TRUE(server_socket.IsValid());
|
||||
{
|
||||
ByteArray data("data");
|
||||
absl::string_view data("data");
|
||||
CancellationFlag flag;
|
||||
SingleThreadExecutor server_executor;
|
||||
SingleThreadExecutor client_executor;
|
||||
|
||||
@@ -153,7 +153,7 @@ static const int kTestPort = 1234;
|
||||
|
||||
// Test output stream.
|
||||
nearby::OutputStream& outputStream = clientSocket->GetOutputStream();
|
||||
nearby::ByteArray writeData("write data");
|
||||
absl::string_view writeData("write data");
|
||||
XCTAssertTrue(outputStream.Write(writeData).Ok());
|
||||
XCTAssertEqualObjects(fakeSocket.writtenData,
|
||||
[@"write data" dataUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
@@ -130,9 +130,9 @@ const char kIPAddress[] = "192.168.1.2";
|
||||
_hotspotMedium->ConnectToService(_service_address, &cancellationFlag);
|
||||
GNCFakeNWFrameworkSocket *fakeSocket = _fakeNWFramework.sockets.firstObject;
|
||||
NSData *data = [@"TestData" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
nearby::ByteArray byteArray(reinterpret_cast<const char *>(data.bytes), data.length);
|
||||
absl::string_view data_str(reinterpret_cast<const char *>(data.bytes), data.length);
|
||||
|
||||
nearby::Exception writeResult = socket->GetOutputStream().Write(byteArray);
|
||||
nearby::Exception writeResult = socket->GetOutputStream().Write(data_str);
|
||||
|
||||
XCTAssertTrue(writeResult.Ok());
|
||||
XCTAssertEqualObjects(fakeSocket.writtenData, data);
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
|
||||
// Test output stream.
|
||||
nearby::OutputStream& outputStream = clientSocket->GetOutputStream();
|
||||
nearby::ByteArray writeData("write data");
|
||||
absl::string_view writeData("write data");
|
||||
XCTAssertTrue(outputStream.Write(writeData).Ok());
|
||||
XCTAssertEqualObjects(fakeSocket.writtenData,
|
||||
[@"write data" dataUsingEncoding:NSUTF8StringEncoding]);
|
||||
|
||||
@@ -389,9 +389,7 @@ void BluetoothAdapter::StoreRadioNames(absl::string_view original_radio_name,
|
||||
VLOG(1) << __func__
|
||||
<< ": saved settings: " << encoded_local_settings.dump();
|
||||
|
||||
ByteArray data(encoded_local_settings.dump());
|
||||
|
||||
settings_file->Write(data);
|
||||
settings_file->Write(encoded_local_settings.dump());
|
||||
settings_file->Close();
|
||||
} catch (const winrt::hresult_error &ex) {
|
||||
LOG(ERROR) << __func__ << ": exception:" << ex.code() << ": "
|
||||
|
||||
@@ -28,7 +28,7 @@ TEST(PlatformTest, CreateOutputFileWithUnixPathSeparator) {
|
||||
std::unique_ptr<OutputFile> output_file =
|
||||
ImplementationPlatform::CreateOutputFile("C:\\tmp\\path1/path2\\x.txt");
|
||||
EXPECT_NE(output_file, nullptr);
|
||||
EXPECT_TRUE(output_file->Write(ByteArray("test")).Ok());
|
||||
EXPECT_TRUE(output_file->Write("test").Ok());
|
||||
}
|
||||
|
||||
TEST(PlatformTest, GetAppDataPath) {
|
||||
|
||||
@@ -15,16 +15,12 @@
|
||||
#ifndef PLATFORM_BASE_OUTPUT_STREAM_H_
|
||||
#define PLATFORM_BASE_OUTPUT_STREAM_H_
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/exception.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
// An OutputStream represents an output stream of bytes.
|
||||
//
|
||||
// https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html
|
||||
class OutputStream {
|
||||
public:
|
||||
virtual ~OutputStream() = default;
|
||||
@@ -32,9 +28,6 @@ class OutputStream {
|
||||
virtual Exception Write(absl::string_view data) = 0; // throws Exception::kIo
|
||||
virtual Exception Flush() = 0; // throws Exception::kIo
|
||||
virtual Exception Close() = 0; // throws Exception::kIo
|
||||
|
||||
ABSL_DEPRECATED("Use the absl::string_view overload instead.")
|
||||
Exception Write(const ByteArray& data) { return Write(data.AsStringView()); }
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -183,15 +183,14 @@ TEST_P(WifiDirectMediumTest, CanStartDirectGOThatOtherCanConnect) {
|
||||
EXPECT_TRUE(socket_b.IsValid());
|
||||
InputStream& in_stream = socket_a.GetInputStream();
|
||||
OutputStream& out_stream = socket_b.GetOutputStream();
|
||||
std::string data(kData);
|
||||
EXPECT_TRUE(out_stream.Write(ByteArray(data)).Ok());
|
||||
EXPECT_TRUE(out_stream.Write(kData).Ok());
|
||||
ExceptionOr<ByteArray> read_data = in_stream.Read(kChunkSize);
|
||||
EXPECT_TRUE(read_data.ok());
|
||||
EXPECT_EQ(std::string(read_data.result()), data);
|
||||
EXPECT_EQ(read_data.result().AsStringView(), kData);
|
||||
|
||||
socket_a.Close();
|
||||
socket_b.Close();
|
||||
EXPECT_FALSE(out_stream.Write(ByteArray(data)).Ok());
|
||||
EXPECT_FALSE(out_stream.Write(kData).Ok());
|
||||
read_data = in_stream.Read(kChunkSize);
|
||||
EXPECT_TRUE(read_data.GetResult().Empty());
|
||||
|
||||
|
||||
@@ -19,17 +19,12 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
@@ -51,7 +46,6 @@ constexpr FeatureFlags kTestCases[] = {
|
||||
|
||||
constexpr absl::string_view kSsid = "Direct-357a2d8c";
|
||||
constexpr absl::string_view kPassword = "b592f7d3";
|
||||
constexpr int kFrequency = 2412;
|
||||
constexpr absl::string_view kData = "ABCD";
|
||||
constexpr const size_t kChunkSize = 10;
|
||||
|
||||
@@ -175,15 +169,14 @@ TEST_P(WifiHotspotMediumTest, CanStartHotspotThatOtherConnect) {
|
||||
EXPECT_TRUE(socket_b.IsValid());
|
||||
InputStream& in_stream = socket_a.GetInputStream();
|
||||
OutputStream& out_stream = socket_b.GetOutputStream();
|
||||
std::string data(kData);
|
||||
EXPECT_TRUE(out_stream.Write(ByteArray(data)).Ok());
|
||||
EXPECT_TRUE(out_stream.Write(kData).Ok());
|
||||
ExceptionOr<ByteArray> read_data = in_stream.Read(kChunkSize);
|
||||
EXPECT_TRUE(read_data.ok());
|
||||
EXPECT_EQ(std::string(read_data.result()), data);
|
||||
EXPECT_EQ(read_data.result().AsStringView(), kData);
|
||||
|
||||
socket_a.Close();
|
||||
socket_b.Close();
|
||||
EXPECT_FALSE(out_stream.Write(ByteArray(data)).Ok());
|
||||
EXPECT_FALSE(out_stream.Write(kData).Ok());
|
||||
read_data = in_stream.Read(kChunkSize);
|
||||
EXPECT_TRUE(read_data.GetResult().Empty());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user