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 <utility>
6
7 #include "base/message_loop/message_loop.h"
8 #include "mojo/public/cpp/bindings/binding_set.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/range/mojo/range_traits_test_service.mojom.h"
11
12 namespace gfx {
13
14 namespace {
15
16 class RangeStructTraitsTest : public testing::Test,
17 public mojom::RangeTraitsTestService {
18 public:
RangeStructTraitsTest()19 RangeStructTraitsTest() {}
20
21 protected:
GetTraitsTestProxy()22 mojom::RangeTraitsTestServicePtr GetTraitsTestProxy() {
23 mojom::RangeTraitsTestServicePtr proxy;
24 traits_test_bindings_.AddBinding(this, mojo::MakeRequest(&proxy));
25 return proxy;
26 }
27
28 private:
29 // RangeTraitsTestService:
EchoRange(const Range & p,EchoRangeCallback callback)30 void EchoRange(const Range& p, EchoRangeCallback callback) override {
31 std::move(callback).Run(p);
32 }
33
EchoRangeF(const RangeF & p,EchoRangeFCallback callback)34 void EchoRangeF(const RangeF& p, EchoRangeFCallback callback) override {
35 std::move(callback).Run(p);
36 }
37
38 base::MessageLoop loop_;
39 mojo::BindingSet<RangeTraitsTestService> traits_test_bindings_;
40
41 DISALLOW_COPY_AND_ASSIGN(RangeStructTraitsTest);
42 };
43
44 } // namespace
45
TEST_F(RangeStructTraitsTest,Range)46 TEST_F(RangeStructTraitsTest, Range) {
47 const uint32_t start = 1234;
48 const uint32_t end = 5678;
49 gfx::Range input(start, end);
50 mojom::RangeTraitsTestServicePtr proxy = GetTraitsTestProxy();
51 gfx::Range output;
52 proxy->EchoRange(input, &output);
53 EXPECT_EQ(start, output.start());
54 EXPECT_EQ(end, output.end());
55 }
56
TEST_F(RangeStructTraitsTest,RangeF)57 TEST_F(RangeStructTraitsTest, RangeF) {
58 const float start = 1234.5f;
59 const float end = 6789.6f;
60 gfx::RangeF input(start, end);
61 mojom::RangeTraitsTestServicePtr proxy = GetTraitsTestProxy();
62 gfx::RangeF output;
63 proxy->EchoRangeF(input, &output);
64 EXPECT_EQ(start, output.start());
65 EXPECT_EQ(end, output.end());
66 }
67
68 } // namespace gfx
69