| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/base/shared_buffer.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 | |
| 8 const uint32 kBufferSize = 4096; | |
| 9 const int kPattern = 0x12345678; | |
| 10 | |
| 11 const int kIdZero = 0; | |
| 12 const int kIdOne = 1; | |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 TEST(SharedBufferTest, Basic) { | |
| 17 scoped_refptr<SharedBuffer> source(new SharedBuffer(kBufferSize)); | |
| 18 | |
| 19 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 20 // its ID is reset. | |
| 21 EXPECT_TRUE(source->ptr() != NULL); | |
| 22 EXPECT_EQ(source->id(), kIdZero); | |
| 23 EXPECT_EQ(source->size(), kBufferSize); | |
| 24 | |
| 25 // See if setting of the ID works. | |
| 26 source->set_id(kIdOne); | |
| 27 EXPECT_EQ(source->id(), kIdOne); | |
| 28 | |
| 29 scoped_refptr<SharedBuffer> dest( | |
| 30 new SharedBuffer(kIdZero, source->handle(), kBufferSize)); | |
| 31 | |
| 32 // Make sure that the buffer is allocated, the size is recorded correctly and | |
| 33 // its ID is reset. | |
| 34 EXPECT_TRUE(dest->ptr() != NULL); | |
| 35 EXPECT_EQ(dest->id(), kIdZero); | |
| 36 EXPECT_EQ(dest->size(), kBufferSize); | |
| 37 | |
| 38 // Verify that the memory contents are the same for the two buffers. | |
| 39 int* source_ptr = reinterpret_cast<int*>(source->ptr()); | |
| 40 *source_ptr = kPattern; | |
| 41 int* dest_ptr = reinterpret_cast<int*>(dest->ptr()); | |
| 42 EXPECT_EQ(*source_ptr, *dest_ptr); | |
| 43 | |
| 44 // Check that the destination buffer is still mapped even when the source | |
| 45 // buffer is destroyed. | |
| 46 source = NULL; | |
| 47 EXPECT_EQ(0x12345678, *dest_ptr); | |
| 48 } | |
| 49 | |
| 50 } // namespace remoting | |
| OLD | NEW |