Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: mojo/public/c/bindings/tests/buffer_unittest.cc

Issue 2062323002: Mojo C bindings library pt1: MojomBuffer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix rounding on large ints. more unittests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/bindings/tests/BUILD.gn ('k') | mojo/public/c/system/buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace {
10
11 TEST(MojomBufferTest, RoundTo8) {
12 char buffer[100];
13 struct MojomBuffer mbuf = {
14 buffer, sizeof(buffer),
15 0, // num_bytes_used
16 };
17
18 // This should actually allocate 8 bytes:
19 EXPECT_EQ(buffer, MojomBuffer_Allocate(&mbuf, 6));
20 EXPECT_EQ(8ul, mbuf.num_bytes_used);
21 // The start of the next buffer is buffer + 8 bytes:
22 EXPECT_EQ(buffer + 8, MojomBuffer_Allocate(&mbuf, 6));
23 EXPECT_EQ(16ul, mbuf.num_bytes_used);
24 // 8-bye allocation results in 8-byte allocation.
25 EXPECT_EQ(buffer + 16, MojomBuffer_Allocate(&mbuf, 8));
26 EXPECT_EQ(24ul, mbuf.num_bytes_used);
27 }
28
29 TEST(MojomBufferTest, Failure) {
30 char buffer[100];
31 struct MojomBuffer mbuf = {
32 buffer, sizeof(buffer),
33 0, // num_bytes_used
34 };
35
36 // Allocate too much space.
37 EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, sizeof(buffer) + 10));
38 // Allocating 0 bytes should fail as well.
39 EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, 0));
40
41 // Setup the buffer data so that it will overflow.
42 mbuf.num_bytes_used = UINT32_MAX - 7; // This divides by 8.
viettrungluu 2016/06/15 15:59:49 nit: You should probably explicitly include <stdin
vardhan 2016/06/15 16:10:21 Done.
43 mbuf.buf_size = UINT32_MAX;
44
45 // Rounds to 8, and allocates more than it has:
46 EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, 1));
47 }
48
49 } // namespace
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/tests/BUILD.gn ('k') | mojo/public/c/system/buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698