1 // Copyright 2018 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/cpp/base/big_buffer_mojom_traits.h"
6 #include "mojo/public/cpp/base/ref_counted_memory_mojom_traits.h"
7 #include "mojo/public/cpp/test_support/test_utils.h"
8 #include "mojo/public/mojom/base/ref_counted_memory.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mojo_base {
12
TEST(RefCountedMemoryTest,Data)13 TEST(RefCountedMemoryTest, Data) {
14 uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};
15
16 scoped_refptr<base::RefCountedMemory> in =
17 new base::RefCountedStaticMemory(&data, arraysize(data));
18
19 scoped_refptr<base::RefCountedMemory> out;
20 ASSERT_TRUE(
21 mojo::test::SerializeAndDeserialize<mojom::RefCountedMemory>(&in, &out));
22 ASSERT_EQ(out->size(), in->size());
23 for (size_t i = 0; i < out->size(); ++i)
24 EXPECT_EQ(in->front()[i], out->front()[i]);
25 }
26
TEST(RefCountedMemoryTest,Null)27 TEST(RefCountedMemoryTest, Null) {
28 // Stuff real data in out to ensure it gets overwritten with a null.
29 uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};
30 scoped_refptr<base::RefCountedMemory> out =
31 new base::RefCountedStaticMemory(&data, arraysize(data));
32
33 scoped_refptr<base::RefCountedMemory> in;
34 ASSERT_TRUE(
35 mojo::test::SerializeAndDeserialize<mojom::RefCountedMemory>(&in, &out));
36
37 ASSERT_FALSE(out.get());
38 }
39
40 } // namespace mojo_base
41