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.
5 #include "ui/gfx/test/gfx_util.h"
15 std::string
ColorAsString(SkColor color
) {
16 std::ostringstream stream
;
17 stream
<< std::hex
<< std::uppercase
<< "#" << std::setfill('0')
18 << std::setw(2) << SkColorGetA(color
)
19 << std::setw(2) << SkColorGetR(color
)
20 << std::setw(2) << SkColorGetG(color
)
21 << std::setw(2) << SkColorGetB(color
);
25 bool 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
);
33 ::testing::AssertionResult
AssertBoxFloatEqual(const char* lhs_expr
,
37 if (FloatAlmostEqual(lhs
.x(), rhs
.x()) &&
38 FloatAlmostEqual(lhs
.y(), rhs
.y()) &&
39 FloatAlmostEqual(lhs
.z(), rhs
.z()) &&
40 FloatAlmostEqual(lhs
.width(), rhs
.width()) &&
41 FloatAlmostEqual(lhs
.height(), rhs
.height()) &&
42 FloatAlmostEqual(lhs
.depth(), rhs
.depth())) {
43 return ::testing::AssertionSuccess();
45 return ::testing::AssertionFailure() << "Value of: " << rhs_expr
46 << "\n Actual: " << rhs
.ToString()
47 << "\nExpected: " << lhs_expr
48 << "\nWhich is: " << lhs
.ToString();
51 ::testing::AssertionResult
AssertSkColorsEqual(const char* lhs_expr
,
56 return ::testing::AssertionSuccess();
58 return ::testing::AssertionFailure() << "Value of: " << rhs_expr
59 << "\n Actual: " << ColorAsString(rhs
)
60 << "\nExpected: " << lhs_expr
61 << "\nWhich is: " << ColorAsString(lhs
);