From 7c0a92e1761dddaf6ed84e3bea723dc7a40c8685 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Thu, 11 Jan 2018 21:56:48 +0000 Subject: Add operator<< to CFX_FloatRect. This helps debugging. Change-Id: I4d14dd5975d8d8f4566009ed4a4127f9c56d36dd Reviewed-on: https://pdfium-review.googlesource.com/22790 Commit-Queue: Henrique Nakashima Commit-Queue: dsinclair Reviewed-by: dsinclair Reviewed-by: Ryan Harrison --- core/fxcrt/fx_coordinates.cpp | 8 ++++++++ core/fxcrt/fx_coordinates.h | 4 ++++ core/fxcrt/fx_coordinates_unittest.cpp | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp index db4bea945f..ac13a32329 100644 --- a/core/fxcrt/fx_coordinates.cpp +++ b/core/fxcrt/fx_coordinates.cpp @@ -199,6 +199,14 @@ FX_RECT CFX_FloatRect::ToRoundedFxRect() const { FXSYS_round(bottom)); } +#ifndef NDEBUG +std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect) { + os << "rect[" << rect.Width() << "x" << rect.Height() << " (" << rect.left + << ", " << rect.bottom << ")]"; + return os; +} +#endif + CFX_Matrix CFX_Matrix::GetInverse() const { CFX_Matrix inverse; float i = a * d - b * c; diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index c53d157610..69d16d1c55 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -357,6 +357,10 @@ class CFX_FloatRect { float top; }; +#ifndef NDEBUG +std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect); +#endif + // LTWH rectangles (y-axis runs downwards). template class CFX_RTemplate { diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp index 5be3aa83f9..3368a40e18 100644 --- a/core/fxcrt/fx_coordinates_unittest.cpp +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -192,6 +192,25 @@ TEST(CFX_FloatRect, ScaleFromCenterPointEmpty) { EXPECT_FLOAT_EQ(0.0f, rect.top); } +#ifndef NDEBUG +TEST(CFX_FloatRect, Print) { + std::ostringstream os; + CFX_FloatRect rect; + os << rect; + EXPECT_STREQ("rect[0x0 (0, 0)]", os.str().c_str()); + + os.str(""); + rect = CFX_FloatRect(10, 20, 14, 23); + os << rect; + EXPECT_STREQ("rect[4x3 (10, 20)]", os.str().c_str()); + + os.str(""); + rect = CFX_FloatRect(10.5, 20.5, 14.75, 23.75); + os << rect; + EXPECT_STREQ("rect[4.25x3.25 (10.5, 20.5)]", os.str().c_str()); +} +#endif + TEST(CFX_Matrix, ReverseIdentity) { CFX_Matrix m; m.SetIdentity(); -- cgit v1.2.3