sk_color_eq.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 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. #include "ui/gfx/test/sk_color_eq.h"
  5. #include <iomanip>
  6. #include <string>
  7. namespace gfx {
  8. namespace {
  9. std::string ColorAsString(SkColor color) {
  10. std::ostringstream stream;
  11. stream << std::hex << std::uppercase << "#" << std::setfill('0')
  12. << std::setw(2) << SkColorGetA(color) << std::setw(2)
  13. << SkColorGetR(color) << std::setw(2) << SkColorGetG(color)
  14. << std::setw(2) << SkColorGetB(color);
  15. return stream.str();
  16. }
  17. } // namespace
  18. ::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr,
  19. const char* rhs_expr,
  20. SkColor lhs,
  21. SkColor rhs) {
  22. if (lhs == rhs) {
  23. return ::testing::AssertionSuccess();
  24. }
  25. return ::testing::AssertionFailure()
  26. << "Expected equality of these values:\n"
  27. << lhs_expr << "\n Which is: " << ColorAsString(lhs) << "\n"
  28. << rhs_expr << "\n Which is: " << ColorAsString(rhs);
  29. }
  30. } // namespace gfx