summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-25 15:08:04 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-25 19:33:11 +0000
commit233360e3ea0d6d4acea76a7d9e7ce7700ea80b1a (patch)
tree40d66f863b7aac45e885b7ea0b3ec73b93c0b08f /core
parent00ab92f4c6cd045904a0f26d7e2c227217758f02 (diff)
downloadpdfium-233360e3ea0d6d4acea76a7d9e7ce7700ea80b1a.tar.xz
Add unittest for matrix reverse
This Cl adds some unit tests for the CFX_Matrix Reverse method. Bug: chromium:702041 Change-Id: I9598d3eb48d6b86a3e192d313fe1091bd29a4701 Reviewed-on: https://pdfium-review.googlesource.com/4492 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
new file mode 100644
index 0000000000..12ddb97330
--- /dev/null
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -0,0 +1,89 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fxcrt/fx_coordinates.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(CFX_Matrix, ReverseIdentity) {
+ CFX_Matrix m;
+ CFX_Matrix rev;
+
+ m.SetIdentity();
+ rev.SetReverse(m);
+ EXPECT_FLOAT_EQ(1.0, rev.a);
+ EXPECT_FLOAT_EQ(0.0, rev.b);
+ EXPECT_FLOAT_EQ(0.0, rev.c);
+ EXPECT_FLOAT_EQ(1.0, rev.d);
+ EXPECT_FLOAT_EQ(0.0, rev.e);
+ EXPECT_FLOAT_EQ(0.0, rev.f);
+
+ CFX_PointF expected(2, 3);
+ CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3)));
+ EXPECT_FLOAT_EQ(expected.x, result.x);
+ EXPECT_FLOAT_EQ(expected.y, result.y);
+}
+
+TEST(CFX_Matrix, Reverse) {
+ float data[6] = {3, 0, 2, 3, 1, 4};
+ CFX_Matrix m(data);
+ CFX_Matrix rev;
+
+ rev.SetReverse(m);
+ EXPECT_FLOAT_EQ(0.33333334f, rev.a);
+ EXPECT_FLOAT_EQ(0.0f, rev.b);
+ EXPECT_FLOAT_EQ(-0.22222222f, rev.c);
+ EXPECT_FLOAT_EQ(0.33333334f, rev.d);
+ EXPECT_FLOAT_EQ(0.55555556f, rev.e);
+ EXPECT_FLOAT_EQ(-1.3333334f, rev.f);
+
+ CFX_PointF expected(2, 3);
+ CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3)));
+ EXPECT_FLOAT_EQ(expected.x, result.x);
+ EXPECT_FLOAT_EQ(expected.y, result.y);
+}
+
+// Note, I think these are a bug and the matrix should be the identity.
+TEST(CFX_Matrix, ReverseCR702041) {
+ // The determinate is < std::numeric_limits<float>::epsilon()
+ float data[6] = {0.947368443f, -0.108947366f, -0.923076928f,
+ 0.106153846f, 18.0f, 787.929993f};
+ CFX_Matrix m(data);
+ CFX_Matrix rev;
+
+ rev.SetReverse(m);
+ EXPECT_FLOAT_EQ(14247728.0f, rev.a);
+ EXPECT_FLOAT_EQ(14622668.0f, rev.b);
+ EXPECT_FLOAT_EQ(1.2389329e+08f, rev.c);
+ EXPECT_FLOAT_EQ(1.2715364e+08f, rev.d);
+ EXPECT_FLOAT_EQ(-9.7875698e+10f, rev.e);
+ EXPECT_FLOAT_EQ(-1.0045138e+11f, rev.f);
+
+ // Should be 2, 3
+ CFX_PointF expected(0, 0);
+ CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3)));
+ EXPECT_FLOAT_EQ(expected.x, result.x);
+ EXPECT_FLOAT_EQ(expected.y, result.y);
+}
+
+TEST(CFX_Matrix, ReverseCR714187) {
+ // The determinate is < std::numeric_limits<float>::epsilon()
+ float data[6] = {0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f, 136.977646f};
+ CFX_Matrix m(data);
+ CFX_Matrix rev;
+
+ rev.SetReverse(m);
+ EXPECT_FLOAT_EQ(27027.025f, rev.a);
+ EXPECT_FLOAT_EQ(0.0f, rev.b);
+ EXPECT_FLOAT_EQ(0.0f, rev.c);
+ EXPECT_FLOAT_EQ(-27027.025f, rev.d);
+ EXPECT_FLOAT_EQ(-4930083.5f, rev.e);
+ EXPECT_FLOAT_EQ(3702098.2f, rev.f);
+
+ // Should be 3 ....
+ CFX_PointF expected(2, 2.75);
+ CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3)));
+ EXPECT_FLOAT_EQ(expected.x, result.x);
+ EXPECT_FLOAT_EQ(expected.y, result.y);
+}