OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" | 7 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" |
8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 void* b = buf.Allocate(10); | 34 void* b = buf.Allocate(10); |
35 ASSERT_TRUE(b); | 35 ASSERT_TRUE(b); |
36 EXPECT_TRUE(IsZero(b, 10)); | 36 EXPECT_TRUE(IsZero(b, 10)); |
37 EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(b) % 8); | 37 EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(b) % 8); |
38 | 38 |
39 // Any more allocations would result in an assert, but we can't test that. | 39 // Any more allocations would result in an assert, but we can't test that. |
40 } | 40 } |
41 | 41 |
42 // Tests that FixedBuffer::Leak passes ownership to the caller. | 42 // Tests that FixedBuffer::Leak passes ownership to the caller. |
43 TEST(FixedBufferTest, Leak) { | 43 TEST(FixedBufferTest, Leak) { |
44 void* ptr = NULL; | 44 void* ptr = nullptr; |
45 void* buf_ptr = NULL; | 45 void* buf_ptr = nullptr; |
46 { | 46 { |
47 internal::FixedBuffer buf(8); | 47 internal::FixedBuffer buf(8); |
48 ASSERT_EQ(8u, buf.size()); | 48 ASSERT_EQ(8u, buf.size()); |
49 | 49 |
50 ptr = buf.Allocate(8); | 50 ptr = buf.Allocate(8); |
51 ASSERT_TRUE(ptr); | 51 ASSERT_TRUE(ptr); |
52 buf_ptr = buf.Leak(); | 52 buf_ptr = buf.Leak(); |
53 | 53 |
54 // The buffer should point to the first element allocated. | 54 // The buffer should point to the first element allocated. |
55 // TODO(mpcomplete): Is this a reasonable expectation? | 55 // TODO(mpcomplete): Is this a reasonable expectation? |
(...skipping 26 matching lines...) Expand all Loading... |
82 | 82 |
83 // A lot too large, leading to possible integer overflow. | 83 // A lot too large, leading to possible integer overflow. |
84 EXPECT_EQ(reinterpret_cast<void*>(0), | 84 EXPECT_EQ(reinterpret_cast<void*>(0), |
85 buf.Allocate(std::numeric_limits<size_t>::max() - 8u)); | 85 buf.Allocate(std::numeric_limits<size_t>::max() - 8u)); |
86 } | 86 } |
87 #endif | 87 #endif |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 } // namespace test | 90 } // namespace test |
91 } // namespace mojo | 91 } // namespace mojo |
OLD | NEW |