Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Unified Diff: remoting/protocol/message_decoder_unittest.cc

Issue 4017002: HostMessageDispatcher to parse control messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged again Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/message_decoder.cc ('k') | remoting/protocol/message_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/message_decoder_unittest.cc
diff --git a/remoting/protocol/messages_decoder_unittest.cc b/remoting/protocol/message_decoder_unittest.cc
similarity index 76%
rename from remoting/protocol/messages_decoder_unittest.cc
rename to remoting/protocol/message_decoder_unittest.cc
index 7c5616d6d779959b5859b00cd22659b87669122a..c2772c8d2a0042013fe5fcb7eb610b432b79bc11 100644
--- a/remoting/protocol/messages_decoder_unittest.cc
+++ b/remoting/protocol/message_decoder_unittest.cc
@@ -7,7 +7,9 @@
#include "base/scoped_ptr.h"
#include "base/stl_util-inl.h"
#include "net/base/io_buffer.h"
-#include "remoting/protocol/messages_decoder.h"
+#include "remoting/base/multiple_array_input_stream.h"
+#include "remoting/proto/internal.pb.h"
+#include "remoting/protocol/message_decoder.h"
#include "remoting/protocol/util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -60,44 +62,42 @@ static void PrepareData(uint8** buffer, int* size) {
memcpy(*buffer, encoded_data.c_str(), *size);
}
-TEST(MessagesDecoderTest, BasicOperations) {
+void SimulateReadSequence(const int read_sequence[], int sequence_size) {
// Prepare encoded data for testing.
int size;
uint8* test_data;
PrepareData(&test_data, &size);
scoped_array<uint8> memory_deleter(test_data);
- // Then simulate using MessagesDecoder to decode variable
+ // Then simulate using MessageDecoder to decode variable
// size of encoded data.
// The first thing to do is to generate a variable size of data. This is done
// by iterating the following array for read sizes.
- const int kReadSizes[] = {1, 2, 3, 1};
-
- MessagesDecoder decoder;
+ MessageDecoder decoder;
// Then feed the protocol decoder using the above generated data and the
// read pattern.
- HostMessageList message_list;
+ std::list<ChromotingHostMessage*> message_list;
for (int i = 0; i < size;) {
// First generate the amount to feed the decoder.
- int read = std::min(size - i, kReadSizes[i % arraysize(kReadSizes)]);
+ int read = std::min(size - i, read_sequence[i % sequence_size]);
- // And then prepare a DataBuffer for feeding it.
+ // And then prepare an IOBuffer for feeding it.
scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(read);
memcpy(buffer->data(), test_data + i, read);
- decoder.ParseHostMessages(buffer, read, &message_list);
+ decoder.ParseMessages(buffer, read, &message_list);
i += read;
}
// Then verify the decoded messages.
EXPECT_EQ(31u, message_list.size());
- ASSERT_TRUE(message_list.size() > 0);
EXPECT_TRUE(message_list.front()->has_init_client());
delete message_list.front();
message_list.pop_front();
int index = 0;
- for (HostMessageList::iterator it = message_list.begin();
+ for (std::list<ChromotingHostMessage*>::iterator it =
+ message_list.begin();
it != message_list.end(); ++it) {
ChromotingHostMessage* message = *it;
int type = index % 3;
@@ -118,4 +118,19 @@ TEST(MessagesDecoderTest, BasicOperations) {
STLDeleteElements(&message_list);
}
+TEST(MessageDecoderTest, SmallReads) {
+ const int kReads[] = {1, 2, 3, 1};
+ SimulateReadSequence(kReads, arraysize(kReads));
+}
+
+TEST(MessageDecoderTest, LargeReads) {
+ const int kReads[] = {50, 50, 5};
+ SimulateReadSequence(kReads, arraysize(kReads));
+}
+
+TEST(MessageDecoderTest, EmptyReads) {
+ const int kReads[] = {4, 0, 50, 0};
+ SimulateReadSequence(kReads, arraysize(kReads));
+}
+
} // namespace remoting
« no previous file with comments | « remoting/protocol/message_decoder.cc ('k') | remoting/protocol/message_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698