From fcc9eb3a7c60fab1205ab5b6fb4fcccb1efb3892 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Fri, 16 Feb 2018 17:13:57 +0000 Subject: Implement operator<< for CFX_Rect and CFX_RectF. This is for debugging, so gated by #ifndef NDEBUG. Also make label the printed values to make them clear and differentiate top>bottom and bottom>top rect systems. Change-Id: I2d816b6b8b1be5fb5464630e771d200f2534917e Reviewed-on: https://pdfium-review.googlesource.com/26911 Reviewed-by: Ryan Harrison Commit-Queue: Henrique Nakashima --- core/fxcrt/fx_coordinates.cpp | 6 +++--- core/fxcrt/fx_coordinates.h | 10 +++++++++ core/fxcrt/fx_coordinates_unittest.cpp | 37 ++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp index 69fedb5522..d25a754d7a 100644 --- a/core/fxcrt/fx_coordinates.cpp +++ b/core/fxcrt/fx_coordinates.cpp @@ -201,11 +201,11 @@ FX_RECT CFX_FloatRect::ToRoundedFxRect() const { #ifndef NDEBUG std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect) { - os << "rect[" << rect.Width() << "x" << rect.Height() << " (" << rect.left - << ", " << rect.bottom << ")]"; + os << "rect[w " << rect.Width() << " x h " << rect.Height() << " (left " + << rect.left << ", bot " << rect.bottom << ")]"; return os; } -#endif +#endif // NDEBUG CFX_Matrix CFX_Matrix::GetInverse() const { CFX_Matrix inverse; diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index 3d09652b13..2e8c1abca3 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -581,6 +581,16 @@ class CFX_RTemplate { using CFX_Rect = CFX_RTemplate; using CFX_RectF = CFX_RTemplate; +#ifndef NDEBUG +template +std::ostream& operator<<(std::ostream& os, + const CFX_RTemplate& rect) { + os << "rect[w " << rect.Width() << " x h " << rect.Height() << " (left " + << rect.left << ", top " << rect.top << ")]"; + return os; +} +#endif // NDEBUG + // The matrix is of the form: // | a b 0 | // | c d 0 | diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp index 15ee661509..7c25d0da28 100644 --- a/core/fxcrt/fx_coordinates_unittest.cpp +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -197,19 +197,48 @@ TEST(CFX_FloatRect, Print) { std::ostringstream os; CFX_FloatRect rect; os << rect; - EXPECT_STREQ("rect[0x0 (0, 0)]", os.str().c_str()); + EXPECT_STREQ("rect[w 0 x h 0 (left 0, bot 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()); + EXPECT_STREQ("rect[w 4 x h 3 (left 10, bot 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()); + EXPECT_STREQ("rect[w 4.25 x h 3.25 (left 10.5, bot 20.5)]", os.str().c_str()); } -#endif + +TEST(CFX_Rect, Print) { + std::ostringstream os; + CFX_Rect rect; + os << rect; + EXPECT_STREQ("rect[w 0 x h 0 (left 0, top 0)]", os.str().c_str()); + + os.str(""); + rect = CFX_Rect(10, 20, 4, 3); + os << rect; + EXPECT_STREQ("rect[w 4 x h 3 (left 10, top 20)]", os.str().c_str()); +} + +TEST(CFX_RectF, Print) { + std::ostringstream os; + CFX_RectF rect; + os << rect; + EXPECT_STREQ("rect[w 0 x h 0 (left 0, top 0)]", os.str().c_str()); + + os.str(""); + rect = CFX_RectF(10, 20, 4, 3); + os << rect; + EXPECT_STREQ("rect[w 4 x h 3 (left 10, top 20)]", os.str().c_str()); + + os.str(""); + rect = CFX_RectF(10.5, 20.5, 4.25, 3.25); + os << rect; + EXPECT_STREQ("rect[w 4.25 x h 3.25 (left 10.5, top 20.5)]", os.str().c_str()); +} +#endif // NDEBUG TEST(CFX_Matrix, ReverseIdentity) { CFX_Matrix m; -- cgit v1.2.3