summaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/tests/buffer_unittest.cc
blob: 2370454bffcc877099a2c636b57935de60265c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include <limits>

#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace test {
namespace {

// Tests that FixedBuffer allocates memory aligned to 8 byte boundaries.
TEST(FixedBufferTest, Alignment) {
  internal::FixedBufferForTesting buf(internal::Align(10) * 2);
  ASSERT_EQ(buf.size(), 16u * 2);

  size_t a = buf.Allocate(10);
  EXPECT_EQ(0u, a);

  size_t b = buf.Allocate(10);
  ASSERT_EQ(16u, b);

  // Any more allocations would result in an assert, but we can't test that.
}

}  // namespace
}  // namespace test
}  // namespace mojo