1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// Copyright 2014 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 "ui/gfx/test/gfx_util.h"
#include <iomanip>
#include <sstream>
#include <string>
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/scroll_offset.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform.h"
namespace gfx {
namespace {
std::string ColorAsString(SkColor color) {
std::ostringstream stream;
stream << std::hex << std::uppercase << "#" << std::setfill('0')
<< std::setw(2) << SkColorGetA(color)
<< std::setw(2) << SkColorGetR(color)
<< std::setw(2) << SkColorGetG(color)
<< std::setw(2) << SkColorGetB(color);
return stream.str();
}
bool FloatAlmostEqual(float a, float b) {
// FloatLE is the gtest predicate for less than or almost equal to.
return ::testing::FloatLE("a", "b", a, b) &&
::testing::FloatLE("b", "a", b, a);
}
} // namespace
::testing::AssertionResult AssertBoxFloatEqual(const char* lhs_expr,
const char* rhs_expr,
const BoxF& lhs,
const BoxF& rhs) {
if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
FloatAlmostEqual(lhs.y(), rhs.y()) &&
FloatAlmostEqual(lhs.z(), rhs.z()) &&
FloatAlmostEqual(lhs.width(), rhs.width()) &&
FloatAlmostEqual(lhs.height(), rhs.height()) &&
FloatAlmostEqual(lhs.depth(), rhs.depth())) {
return ::testing::AssertionSuccess();
}
return ::testing::AssertionFailure() << "Value of: " << rhs_expr
<< "\n Actual: " << rhs.ToString()
<< "\nExpected: " << lhs_expr
<< "\nWhich is: " << lhs.ToString();
}
::testing::AssertionResult AssertRectFloatEqual(const char* lhs_expr,
const char* rhs_expr,
const RectF& lhs,
const RectF& rhs) {
if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
FloatAlmostEqual(lhs.y(), rhs.y()) &&
FloatAlmostEqual(lhs.width(), rhs.width()) &&
FloatAlmostEqual(lhs.height(), rhs.height())) {
return ::testing::AssertionSuccess();
}
return ::testing::AssertionFailure()
<< "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
<< "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
}
::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr,
const char* rhs_expr,
SkColor lhs,
SkColor rhs) {
if (lhs == rhs) {
return ::testing::AssertionSuccess();
}
return ::testing::AssertionFailure() << "Value of: " << rhs_expr
<< "\n Actual: " << ColorAsString(rhs)
<< "\nExpected: " << lhs_expr
<< "\nWhich is: " << ColorAsString(lhs);
}
void PrintTo(const BoxF& box, ::std::ostream* os) {
*os << box.ToString();
}
void PrintTo(const Point& point, ::std::ostream* os) {
*os << point.ToString();
}
void PrintTo(const Point3F& point, ::std::ostream* os) {
*os << point.ToString();
}
void PrintTo(const PointF& point, ::std::ostream* os) {
*os << point.ToString();
}
void PrintTo(const QuadF& quad, ::std::ostream* os) {
*os << quad.ToString();
}
void PrintTo(const Rect& rect, ::std::ostream* os) {
*os << rect.ToString();
}
void PrintTo(const RectF& rect, ::std::ostream* os) {
*os << rect.ToString();
}
void PrintTo(const ScrollOffset& offset, ::std::ostream* os) {
*os << offset.ToString();
}
void PrintTo(const Size& size, ::std::ostream* os) {
*os << size.ToString();
}
void PrintTo(const SizeF& size, ::std::ostream* os) {
*os << size.ToString();
}
void PrintTo(const Transform& transform, ::std::ostream* os) {
*os << transform.ToString();
}
void PrintTo(const Vector2d& vector, ::std::ostream* os) {
*os << vector.ToString();
}
void PrintTo(const Vector2dF& vector, ::std::ostream* os) {
*os << vector.ToString();
}
void PrintTo(const Vector3dF& vector, ::std::ostream* os) {
*os << vector.ToString();
}
} // namespace gfx
|