OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/public/bindings/lib/bindings_serialization.h" | 5 #include "mojo/public/bindings/lib/bindings_serialization.h" |
6 #include "mojo/public/bindings/lib/buffer.h" | 6 #include "mojo/public/bindings/lib/buffer.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace test { | 10 namespace test { |
(...skipping 14 matching lines...) Expand all Loading... |
25 void* small = buf.Allocate(10); | 25 void* small = buf.Allocate(10); |
26 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); | 26 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); |
27 EXPECT_TRUE(IsZero(small, 10)); | 27 EXPECT_TRUE(IsZero(small, 10)); |
28 | 28 |
29 // Large allocations won't be on the stack. | 29 // Large allocations won't be on the stack. |
30 void* large = buf.Allocate(100*1024); | 30 void* large = buf.Allocate(100*1024); |
31 EXPECT_TRUE(IsZero(large, 100*1024)); | 31 EXPECT_TRUE(IsZero(large, 100*1024)); |
32 EXPECT_FALSE(large >= &buf && large < (&buf + sizeof(buf))); | 32 EXPECT_FALSE(large >= &buf && large < (&buf + sizeof(buf))); |
33 | 33 |
34 // But another small allocation should be back on the stack. | 34 // But another small allocation should be back on the stack. |
35 // TODO(mpcomplete): but it isn't. We can fix that easily enough. | |
36 small = buf.Allocate(10); | 35 small = buf.Allocate(10); |
37 EXPECT_TRUE(IsZero(small, 10)); | 36 EXPECT_TRUE(IsZero(small, 10)); |
38 //EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); | 37 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); |
39 } | 38 } |
40 | 39 |
41 // Tests that FixedBuffer allocates memory aligned to 8 byte boundaries. | 40 // Tests that FixedBuffer allocates memory aligned to 8 byte boundaries. |
42 TEST(FixedBufferTest, Alignment) { | 41 TEST(FixedBufferTest, Alignment) { |
43 FixedBuffer buf(internal::Align(10) * 2); | 42 FixedBuffer buf(internal::Align(10) * 2); |
44 ASSERT_EQ(buf.size(), 16u * 2); | 43 ASSERT_EQ(buf.size(), 16u * 2); |
45 | 44 |
46 void* a = buf.Allocate(10); | 45 void* a = buf.Allocate(10); |
47 ASSERT_TRUE(a); | 46 ASSERT_TRUE(a); |
48 EXPECT_TRUE(IsZero(a, 10)); | 47 EXPECT_TRUE(IsZero(a, 10)); |
(...skipping 29 matching lines...) Expand all Loading... |
78 } | 77 } |
79 | 78 |
80 // Since we called Leak, ptr is still writable after FixedBuffer went out of | 79 // Since we called Leak, ptr is still writable after FixedBuffer went out of |
81 // scope. | 80 // scope. |
82 memset(ptr, 1, 8); | 81 memset(ptr, 1, 8); |
83 free(buf_ptr); | 82 free(buf_ptr); |
84 } | 83 } |
85 | 84 |
86 } // namespace test | 85 } // namespace test |
87 } // namespace mojo | 86 } // namespace mojo |
OLD | NEW |