| Index: gpu/ipc/common/struct_traits_unittest.cc
|
| diff --git a/gpu/ipc/common/struct_traits_unittest.cc b/gpu/ipc/common/struct_traits_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8bc611a4b03978d820cb646f9e2b931b59c37dec
|
| --- /dev/null
|
| +++ b/gpu/ipc/common/struct_traits_unittest.cc
|
| @@ -0,0 +1,109 @@
|
| +// Copyright 2016 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 "base/message_loop/message_loop.h"
|
| +#include "base/run_loop.h"
|
| +#include "gpu/ipc/common/traits_test_service.mojom.h"
|
| +#include "mojo/public/cpp/bindings/binding_set.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace gpu {
|
| +
|
| +namespace {
|
| +
|
| +class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
|
| + public:
|
| + StructTraitsTest() {}
|
| +
|
| + protected:
|
| + mojom::TraitsTestServicePtr GetTraitsTestProxy() {
|
| + return traits_test_bindings_.CreateInterfacePtrAndBind(this);
|
| + }
|
| +
|
| + private:
|
| + // TraitsTestService:
|
| + void EchoMailbox(const Mailbox& m,
|
| + const EchoMailboxCallback& callback) override {
|
| + callback.Run(m);
|
| + }
|
| +
|
| + void EchoMailboxHolder(const MailboxHolder& r,
|
| + const EchoMailboxHolderCallback& callback) override {
|
| + callback.Run(r);
|
| + }
|
| +
|
| + void EchoSyncToken(const SyncToken& s,
|
| + const EchoSyncTokenCallback& callback) override {
|
| + callback.Run(s);
|
| + }
|
| +
|
| + base::MessageLoop loop_;
|
| + mojo::BindingSet<TraitsTestService> traits_test_bindings_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(StructTraitsTest, Mailbox) {
|
| + int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = {
|
| + 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
|
| + 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
|
| + 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
|
| + gpu::Mailbox input;
|
| + input.SetName(mailbox_name);
|
| + base::RunLoop loop;
|
| + mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
|
| + proxy->EchoMailbox(input, [&](const Mailbox& pass) {
|
| + EXPECT_EQ(input, pass);
|
| + loop.Quit();
|
| + });
|
| + loop.Run();
|
| +}
|
| +
|
| +TEST_F(StructTraitsTest, MailboxHolder) {
|
| + gpu::MailboxHolder input;
|
| + int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = {
|
| + 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
|
| + 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
|
| + 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
|
| + input.mailbox.SetName(mailbox_name);
|
| + const gpu::CommandBufferNamespace command_buffer_namespace = gpu::IN_PROCESS;
|
| + const int32_t extra_data_field = 0xbeefbeef;
|
| + const gpu::CommandBufferId command_buffer_id(
|
| + gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef));
|
| + const uint64_t release_count = 0xdeadbeefdead;
|
| + input.sync_token = gpu::SyncToken(command_buffer_namespace, extra_data_field,
|
| + command_buffer_id, release_count);
|
| + input.texture_target = 1337;
|
| + base::RunLoop loop;
|
| + mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
|
| + proxy->EchoMailboxHolder(input, [&](const MailboxHolder& pass) {
|
| + EXPECT_EQ(input.mailbox, pass.mailbox);
|
| + EXPECT_EQ(input.sync_token, pass.sync_token);
|
| + EXPECT_EQ(input.texture_target, pass.texture_target);
|
| + loop.Quit();
|
| + });
|
| +}
|
| +
|
| +TEST_F(StructTraitsTest, SyncToken) {
|
| + const gpu::CommandBufferNamespace command_buffer_namespace = gpu::IN_PROCESS;
|
| + const int32_t extra_data_field = 0xbeefbeef;
|
| + const gpu::CommandBufferId command_buffer_id(
|
| + gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef));
|
| + const uint64_t release_count = 0xdeadbeefdead;
|
| + gpu::SyncToken input(command_buffer_namespace, extra_data_field,
|
| + command_buffer_id, release_count);
|
| + base::RunLoop loop;
|
| + mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
|
| + proxy->EchoSyncToken(input, [&](const SyncToken& pass) {
|
| + EXPECT_EQ(input.namespace_id(), pass.namespace_id());
|
| + EXPECT_EQ(input.command_buffer_id(), pass.command_buffer_id());
|
| + EXPECT_EQ(input.release_count(), pass.release_count());
|
| + EXPECT_EQ(input.extra_data_field(), pass.extra_data_field());
|
| + EXPECT_EQ(input.verified_flush(), pass.verified_flush());
|
| + loop.Quit();
|
| + });
|
| + loop.Run();
|
| +}
|
| +
|
| +} // namespace gpu
|
|
|