Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "mojo/public/c/bindings/buffer.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
|
viettrungluu
2016/06/15 15:00:58
nit: blank line above
vardhan
2016/06/15 15:48:00
Done.
| |
| 7 | |
| 8 namespace { | |
| 9 | |
| 10 TEST(MojomBufferTest, Alignment) { | |
| 11 char buffer[100]; | |
| 12 struct MojomBuffer mbuf = { | |
| 13 buffer, sizeof(buffer), | |
| 14 0, // num_bytes_used | |
| 15 }; | |
| 16 | |
| 17 // This should actually allocate 8 bytes: | |
| 18 EXPECT_EQ(buffer, MojomBuffer_Allocate(&mbuf, 6)); | |
| 19 EXPECT_EQ(8ul, mbuf.num_bytes_used); | |
| 20 // The start of the next buffer is buffer + 8 bytes: | |
| 21 EXPECT_EQ(buffer + 8, MojomBuffer_Allocate(&mbuf, 6)); | |
| 22 EXPECT_EQ(16ul, mbuf.num_bytes_used); | |
| 23 } | |
|
viettrungluu
2016/06/15 15:00:58
You should test that allocating things that are al
vardhan
2016/06/15 15:48:00
Done.
| |
| 24 | |
| 25 TEST(MojomBufferTest, Failure) { | |
|
viettrungluu
2016/06/15 15:00:58
You should really test the subtle part, namely the
vardhan
2016/06/15 15:48:00
Done.
| |
| 26 char buffer[100]; | |
| 27 struct MojomBuffer mbuf = { | |
| 28 buffer, sizeof(buffer), | |
| 29 0, // num_bytes_used | |
| 30 }; | |
| 31 | |
| 32 // Allocate too much space. | |
| 33 EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, sizeof(buffer) + 10)); | |
| 34 // Allocating 0 bytes should fail as well. | |
|
viettrungluu
2016/06/15 15:00:58
Why should it necessarily be a failure?
vardhan
2016/06/15 15:48:00
(see other comment)
| |
| 35 EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, 0)); | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| OLD | NEW |