From 98c96670b43d408525e250d390eb437bcde30a51 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Wed, 28 Feb 2024 12:32:07 -0800 Subject: [PATCH] Make Skia object ostream operators work with unit tests (flutter/engine#51041) Unit tests currently output basic hex dumps of skia objects even though we have ostream operators for many of the common ones. It looks like the operators were created in the wrong namespace (flutter/testing rather than the std namespace). Changing the namespace for the associated `assertions_skia` source files makes them compatible with unit tests that deal with these objects provided that the test files include that header and gn dependency, as verified with the `display_list_unittests` here. --- engine/src/flutter/display_list/BUILD.gn | 1 + engine/src/flutter/display_list/display_list_unittests.cc | 1 + engine/src/flutter/testing/assertions_skia.cc | 6 ++---- engine/src/flutter/testing/assertions_skia.h | 6 ++---- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/display_list/BUILD.gn b/engine/src/flutter/display_list/BUILD.gn index 9e34768f81..eb547dd7d7 100644 --- a/engine/src/flutter/display_list/BUILD.gn +++ b/engine/src/flutter/display_list/BUILD.gn @@ -128,6 +128,7 @@ if (enable_unittests) { ":display_list_fixtures", "//flutter/display_list/testing:display_list_testing", "//flutter/testing", + "//flutter/testing:skia", ] if (!defined(defines)) { diff --git a/engine/src/flutter/display_list/display_list_unittests.cc b/engine/src/flutter/display_list/display_list_unittests.cc index 8845ce3ac6..242b34359a 100644 --- a/engine/src/flutter/display_list/display_list_unittests.cc +++ b/engine/src/flutter/display_list/display_list_unittests.cc @@ -18,6 +18,7 @@ #include "flutter/display_list/utils/dl_receiver_utils.h" #include "flutter/fml/logging.h" #include "flutter/fml/math.h" +#include "flutter/testing/assertions_skia.h" #include "flutter/testing/display_list_testing.h" #include "flutter/testing/testing.h" diff --git a/engine/src/flutter/testing/assertions_skia.cc b/engine/src/flutter/testing/assertions_skia.cc index 856ddf1972..a8e036d973 100644 --- a/engine/src/flutter/testing/assertions_skia.cc +++ b/engine/src/flutter/testing/assertions_skia.cc @@ -4,8 +4,7 @@ #include "flutter/testing/assertions_skia.h" -namespace flutter { -namespace testing { +namespace std { std::ostream& operator<<(std::ostream& os, const SkClipOp& o) { switch (o) { @@ -100,5 +99,4 @@ std::ostream& operator<<(std::ostream& os, const SkSamplingOptions& s) { } } -} // namespace testing -} // namespace flutter +} // namespace std diff --git a/engine/src/flutter/testing/assertions_skia.h b/engine/src/flutter/testing/assertions_skia.h index 663ab57f3b..c1e3764ca3 100644 --- a/engine/src/flutter/testing/assertions_skia.h +++ b/engine/src/flutter/testing/assertions_skia.h @@ -16,8 +16,7 @@ #include "third_party/skia/include/core/SkRRect.h" #include "third_party/skia/include/core/SkSamplingOptions.h" -namespace flutter { -namespace testing { +namespace std { extern std::ostream& operator<<(std::ostream& os, const SkClipOp& o); extern std::ostream& operator<<(std::ostream& os, const SkMatrix& m); @@ -33,7 +32,6 @@ extern std::ostream& operator<<(std::ostream& os, const SkColor4f& r); extern std::ostream& operator<<(std::ostream& os, const SkPaint& r); extern std::ostream& operator<<(std::ostream& os, const SkSamplingOptions& s); -} // namespace testing -} // namespace flutter +} // namespace std #endif // FLUTTER_TESTING_ASSERTIONS_SKIA_H_