| Index: remoting/protocol/secure_p2p_socket_unittest.cc
|
| diff --git a/remoting/protocol/secure_p2p_socket_unittest.cc b/remoting/protocol/secure_p2p_socket_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..388f7d4cd10e8260f7fc4964e6e5f4bed05efc87
|
| --- /dev/null
|
| +++ b/remoting/protocol/secure_p2p_socket_unittest.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/stringprintf.h"
|
| +#include "crypto/symmetric_key.h"
|
| +#include "net/base/io_buffer.h"
|
| +#include "remoting/protocol/secure_p2p_socket.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace remoting {
|
| +namespace protocol {
|
| +
|
| +namespace {
|
| +class TestSocket : public net::Socket {
|
| + public:
|
| + TestSocket() {}
|
| +
|
| + // Socket implementation.
|
| + virtual int Read(net::IOBuffer* buf, int buf_len,
|
| + net::CompletionCallback* callback) {
|
| + memcpy(buf->data(), buffer_.data(), buffer_.length());
|
| + int size = buffer_.length();
|
| + buffer_.clear();
|
| + return size;
|
| + }
|
| +
|
| + virtual int Write(net::IOBuffer* buf, int buf_len,
|
| + net::CompletionCallback* callback) {
|
| + buffer_ = std::string(buf->data(), buf_len);
|
| + return buf_len;
|
| + }
|
| +
|
| + virtual bool SetReceiveBufferSize(int32 size) {
|
| + return true;
|
| + }
|
| +
|
| + virtual bool SetSendBufferSize(int32 size) {
|
| + return true;
|
| + }
|
| +
|
| + std::string GetBuffer() const {
|
| + return buffer_;
|
| + }
|
| +
|
| + private:
|
| + std::string buffer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestSocket);
|
| +};
|
| +} // namespace
|
| +
|
| +TEST(SecureP2PSocketTest, WriteAndRead) {
|
| + TestSocket test_socket;
|
| + SecureP2PSocket secure_socket(&test_socket, "1234567890123456");
|
| +
|
| + const std::string kWritePattern = "Hello world! This is a nice day.";
|
| + scoped_refptr<net::IOBuffer> write_buf =
|
| + new net::StringIOBuffer(kWritePattern);
|
| + scoped_refptr<net::IOBuffer> read_buf = new net::IOBufferWithSize(2048);
|
| +
|
| + for (int i = 0; i < 5; ++i) {
|
| + size_t written = secure_socket.Write(write_buf,
|
| + kWritePattern.length(), NULL);
|
| + EXPECT_EQ(kWritePattern.length(), written);
|
| + EXPECT_EQ(kWritePattern.length() + 44, test_socket.GetBuffer().length());
|
| +
|
| + std::string hex_packet;
|
| + for (size_t j = 0; j < test_socket.GetBuffer().length(); ++j) {
|
| + base::StringAppendF(&hex_packet, "%02x",
|
| + (uint8)test_socket.GetBuffer()[j]);
|
| + }
|
| + LOG(INFO) << hex_packet;
|
| +
|
| + size_t read = secure_socket.Read(read_buf, 2048, NULL);
|
| + EXPECT_EQ(kWritePattern.length(), read);
|
| + EXPECT_EQ(0, memcmp(kWritePattern.data(), read_buf->data(),
|
| + kWritePattern.length()));
|
| + }
|
| +}
|
| +
|
| +} // namespace protocol
|
| +} // namespace remoting
|
|
|