Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gfx_util.cc
Go to the documentation of this file.
1// Copyright 2014 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 "gfx/test/gfx_util.h"
6
7#include <iomanip>
8#include <sstream>
9#include <string>
10
11#include "gfx/geometry/point.h"
13#include "gfx/geometry/rect.h"
14#include "gfx/geometry/rect_f.h"
15#include "gfx/geometry/size.h"
16#include "gfx/geometry/size_f.h"
19#include "gfx/transform.h"
20
21namespace gfx {
22
23namespace {
24
25bool FloatAlmostEqual(float a, float b) {
26 // FloatLE is the gtest predicate for less than or almost equal to.
27 return ::testing::FloatLE("a", "b", a, b) &&
28 ::testing::FloatLE("b", "a", b, a);
29}
30
31} // namespace
32
33::testing::AssertionResult AssertPointFloatEqual(const char* lhs_expr,
34 const char* rhs_expr,
35 const PointF& lhs,
36 const PointF& rhs) {
37 if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
38 FloatAlmostEqual(lhs.y(), rhs.y())) {
39 return ::testing::AssertionSuccess();
40 }
41 return ::testing::AssertionFailure()
42 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
43 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
44}
45
46::testing::AssertionResult AssertRectFloatEqual(const char* lhs_expr,
47 const char* rhs_expr,
48 const RectF& lhs,
49 const RectF& rhs) {
50 if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
51 FloatAlmostEqual(lhs.y(), rhs.y()) &&
52 FloatAlmostEqual(lhs.width(), rhs.width()) &&
53 FloatAlmostEqual(lhs.height(), rhs.height())) {
54 return ::testing::AssertionSuccess();
55 }
56 return ::testing::AssertionFailure()
57 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
58 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
59}
60
61::testing::AssertionResult AssertSizeFFloatEqual(const char* lhs_expr,
62 const char* rhs_expr,
63 const SizeF& lhs,
64 const SizeF& rhs) {
65 if (FloatAlmostEqual(lhs.width(), rhs.width()) &&
66 FloatAlmostEqual(lhs.height(), rhs.height())) {
67 return ::testing::AssertionSuccess();
68 }
69 return ::testing::AssertionFailure()
70 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
71 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
72}
73
74void PrintTo(const Point& point, ::std::ostream* os) {
75 *os << point.ToString();
76}
77
78void PrintTo(const PointF& point, ::std::ostream* os) {
79 *os << point.ToString();
80}
81
82void PrintTo(const Rect& rect, ::std::ostream* os) {
83 *os << rect.ToString();
84}
85
86void PrintTo(const RectF& rect, ::std::ostream* os) {
87 *os << rect.ToString();
88}
89
90void PrintTo(const Size& size, ::std::ostream* os) {
91 *os << size.ToString();
92}
93
94void PrintTo(const SizeF& size, ::std::ostream* os) {
95 *os << size.ToString();
96}
97
98void PrintTo(const Transform& transform, ::std::ostream* os) {
99 *os << transform.ToString();
100}
101
102void PrintTo(const Vector2d& vector, ::std::ostream* os) {
103 *os << vector.ToString();
104}
105
106void PrintTo(const Vector2dF& vector, ::std::ostream* os) {
107 *os << vector.ToString();
108}
109
110} // namespace gfx
constexpr float x() const
Definition point_f.h:27
std::string ToString() const
Definition point_f.cc:21
constexpr float y() const
Definition point_f.h:28
std::string ToString() const
Definition point.cc:63
constexpr float y() const
Definition rect_f.h:50
constexpr float width() const
Definition rect_f.h:53
std::string ToString() const
Definition rect_f.cc:231
constexpr float height() const
Definition rect_f.h:56
constexpr float x() const
Definition rect_f.h:47
std::string ToString() const
Definition size_f.cc:29
constexpr float height() const
Definition size_f.h:29
constexpr float width() const
Definition size_f.h:28
std::string ToString() const
Definition vector2d_f.cc:13
std::string ToString() const
Definition vector2d.cc:36
static bool b
struct MyStruct a[10]
Definition insets.cc:10
::testing::AssertionResult AssertRectFloatEqual(const char *lhs_expr, const char *rhs_expr, const RectF &lhs, const RectF &rhs)
Definition gfx_util.cc:46
void PrintTo(const Point &point, ::std::ostream *os)
Definition gfx_util.cc:74
::testing::AssertionResult AssertPointFloatEqual(const char *lhs_expr, const char *rhs_expr, const PointF &lhs, const PointF &rhs)
Definition gfx_util.cc:33
::testing::AssertionResult AssertSizeFFloatEqual(const char *lhs_expr, const char *rhs_expr, const SizeF &lhs, const SizeF &rhs)
Definition gfx_util.cc:61
constexpr size_t size(const T(&array)[N]) noexcept
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47