Refactor HpackDecoder's public API to ease integration into SpdyFramer.
[chromium-blink-merge.git] / ui / gfx / test / gfx_util.cc
blob29afec288ca6864d14eb1e7dbb1ae4e3062bcc65
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"
7 #include <iomanip>
8 #include <sstream>
9 #include <string>
11 namespace gfx {
13 namespace {
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);
22 return stream.str();
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);
31 } // namespace
33 ::testing::AssertionResult AssertBoxFloatEqual(const char* lhs_expr,
34 const char* rhs_expr,
35 const BoxF& lhs,
36 const BoxF& rhs) {
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,
52 const char* rhs_expr,
53 SkColor lhs,
54 SkColor rhs) {
55 if (lhs == rhs) {
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);
64 } // namespace gfx