summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-01-16 19:02:15 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-16 19:02:15 +0000
commitdb269577f5f033c083d10b6327cbd1e1e32feb05 (patch)
tree1c2df50fda364dccba7f6b2e001e3447371535d3
parent2615590b040a2d49413be41cad298e242d1072e8 (diff)
downloadpdfium-db269577f5f033c083d10b6327cbd1e1e32feb05.tar.xz
Add WriteBitmapToPng to EmbedderTest.
This is a util method to output the png to a file for visually validating the result of an embedder test. Once validated, the md5 can be considered correct. Bug: pdfium:981 Change-Id: I544dfbf2e85295e6ca2cdf48d1bc3f0bd5f415e9 Reviewed-on: https://pdfium-review.googlesource.com/22990 Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
-rw-r--r--BUILD.gn1
-rw-r--r--testing/embedder_test.cpp28
-rw-r--r--testing/embedder_test.h6
3 files changed, 35 insertions, 0 deletions
diff --git a/BUILD.gn b/BUILD.gn
index f4e5fe9e44..60c2e42f7a 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2926,6 +2926,7 @@ test("pdfium_embeddertests") {
"testing/range_set.h",
]
deps = [
+ ":image_diff",
":pdfium",
":test_support",
"//testing/gmock",
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index de7251383b..09a8533902 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -6,6 +6,7 @@
#include <limits.h>
+#include <fstream>
#include <list>
#include <string>
#include <utility>
@@ -17,6 +18,7 @@
#include "public/fpdf_text.h"
#include "public/fpdfview.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/image_diff/image_diff_png.h"
#include "testing/test_support.h"
#include "testing/utils/path_service.h"
#include "third_party/base/ptr_util.h"
@@ -426,6 +428,32 @@ std::string EmbedderTest::HashBitmap(FPDF_BITMAP bitmap) {
return CryptToBase16(digest);
}
+#ifndef NDEBUG
+// static
+void EmbedderTest::WriteBitmapToPng(FPDF_BITMAP bitmap,
+ const std::string& filename) {
+ const int stride = FPDFBitmap_GetStride(bitmap);
+ const int width = FPDFBitmap_GetWidth(bitmap);
+ const int height = FPDFBitmap_GetHeight(bitmap);
+ const auto* buffer =
+ static_cast<const unsigned char*>(FPDFBitmap_GetBuffer(bitmap));
+
+ std::vector<unsigned char> png_encoding;
+ bool encoded = image_diff_png::EncodeBGRAPNG(buffer, width, height, stride,
+ false, &png_encoding);
+
+ ASSERT_TRUE(encoded);
+ ASSERT_LT(filename.size(), 256u);
+
+ std::ofstream png_file;
+ png_file.open(filename);
+ png_file.write(reinterpret_cast<char*>(&png_encoding.front()),
+ png_encoding.size());
+ ASSERT_TRUE(png_file.good());
+ png_file.close();
+}
+#endif
+
// static
void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap,
int expected_width,
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index 8da1643824..98432e3e54 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -134,6 +134,12 @@ class EmbedderTest : public ::testing::Test,
// Return the hash of |bitmap|.
static std::string HashBitmap(FPDF_BITMAP bitmap);
+#ifndef NDEBUG
+ // For debugging purposes.
+ // Write |bitmap| to a png file.
+ static void WriteBitmapToPng(FPDF_BITMAP bitmap, const std::string& filename);
+#endif
+
// Check |bitmap| to make sure it has the right dimensions and content.
static void CompareBitmap(FPDF_BITMAP bitmap,
int expected_width,