blob: 32a75f9808325c0dde88cb5922b2935b61f0cb62 [file] [log] [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/compiler_specific.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "mojo/public/cpp/base/ref_counted_memory_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/mojom/base/ref_counted_memory.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo_base {
TEST(RefCountedMemoryTest, Data) {
const uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};
scoped_refptr<base::RefCountedMemory> in =
new base::RefCountedStaticMemory(data);
scoped_refptr<base::RefCountedMemory> out;
ASSERT_TRUE(
mojo::test::SerializeAndDeserialize<mojom::RefCountedMemory>(in, out));
ASSERT_EQ(out->size(), in->size());
for (size_t i = 0; i < out->size(); ++i)
UNSAFE_TODO(EXPECT_EQ(in->front()[i], out->front()[i]));
}
TEST(RefCountedMemoryTest, Null) {
// Stuff real data in out to ensure it gets overwritten with a null.
const uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};
scoped_refptr<base::RefCountedMemory> out =
new base::RefCountedStaticMemory(data);
scoped_refptr<base::RefCountedMemory> in;
ASSERT_TRUE(
mojo::test::SerializeAndDeserialize<mojom::RefCountedMemory>(in, out));
ASSERT_FALSE(out.get());
}
} // namespace mojo_base