2020
2121using namespace llvm ;
2222using namespace lldb ;
23- using namespace lldb_private ;
2423using namespace lldb_dap ;
2524using namespace lldb_dap ::protocol;
25+ using lldb_private::File;
26+ using lldb_private::NativeFile;
27+ using lldb_private::Pipe;
2628
2729class TransportTest : public testing ::Test {
2830protected:
@@ -31,8 +33,8 @@ class TransportTest : public testing::Test {
3133 std::unique_ptr<Transport> transport;
3234
3335 void SetUp () override {
34- ASSERT_THAT_ERROR (input.CreateNew (false ).ToError (), llvm:: Succeeded ());
35- ASSERT_THAT_ERROR (output.CreateNew (false ).ToError (), llvm:: Succeeded ());
36+ ASSERT_THAT_ERROR (input.CreateNew (false ).ToError (), Succeeded ());
37+ ASSERT_THAT_ERROR (output.CreateNew (false ).ToError (), Succeeded ());
3638 transport = std::make_unique<Transport>(
3739 " stdio" , nullptr ,
3840 std::make_shared<NativeFile>(input.GetReadFileDescriptor (),
@@ -64,9 +66,10 @@ TEST_F(TransportTest, MalformedRequests) {
6466
6567TEST_F (TransportTest, Read) {
6668 Write (R"json( {"seq": 1, "type": "request", "command": "abc"})json" );
67- ASSERT_THAT_EXPECTED (transport->Read (std::chrono::milliseconds (1 )),
68- HasValue (testing::VariantWith<Request>(
69- testing::FieldsAre (1 , " abc" , std::nullopt ))));
69+ ASSERT_THAT_EXPECTED (
70+ transport->Read (std::chrono::milliseconds (1 )),
71+ HasValue (testing::VariantWith<Request>(testing::FieldsAre (
72+ /* seq=*/ 1 , /* command=*/ " abc" , /* arguments=*/ std::nullopt ))));
7073}
7174
7275TEST_F (TransportTest, ReadWithTimeout) {
@@ -79,3 +82,17 @@ TEST_F(TransportTest, ReadWithEOF) {
7982 ASSERT_THAT_EXPECTED (transport->Read (std::chrono::milliseconds (1 )),
8083 Failed<EndOfFileError>());
8184}
85+
86+ TEST_F (TransportTest, Write) {
87+ ASSERT_THAT_ERROR (transport->Write (Event{" my-event" , std::nullopt }),
88+ Succeeded ());
89+ output.CloseWriteFileDescriptor ();
90+ char buf[1024 ];
91+ Expected<size_t > bytes_read =
92+ output.Read (buf, sizeof (buf), std::chrono::milliseconds (1 ));
93+ ASSERT_THAT_EXPECTED (bytes_read, Succeeded ());
94+ ASSERT_EQ (
95+ StringRef (buf, *bytes_read),
96+ StringRef (" Content-Length: 43\r\n\r\n "
97+ R"json( {"event":"my-event","seq":0,"type":"event"})json" ));
98+ }
0 commit comments