summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-11-21 13:37:28 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-21 13:37:28 -0800
commitbcd3e538f170a5ab2c3295f1a3b0062781d384a5 (patch)
tree0a16f383cfd22b4b9d26c7acdb085d5b05843631
parentd33c8e3145539631d03242a16c3683c3538c7557 (diff)
downloadpdfium-bcd3e538f170a5ab2c3295f1a3b0062781d384a5.tar.xz
Check dimensions and content of bitmaps in EmbedderTests.chromium/2927
Review-Url: https://codereview.chromium.org/2514173002
-rw-r--r--BUILD.gn1
-rw-r--r--core/fpdfapi/page/fpdf_page_func_embeddertest.cpp1
-rw-r--r--core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp9
-rw-r--r--core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp3
-rw-r--r--core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp1
-rw-r--r--core/fxcodec/codec/fx_codec_embeddertest.cpp1
-rw-r--r--testing/DEPS8
-rw-r--r--testing/embedder_test.cpp36
-rw-r--r--testing/embedder_test.h6
-rw-r--r--testing/libfuzzer/DEPS3
10 files changed, 59 insertions, 10 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 4b37bbc117..13c40d606e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -193,6 +193,7 @@ static_library("test_support") {
"testing/test_support.cpp",
"testing/test_support.h",
"testing/utils/path_service.cpp",
+ "testing/utils/path_service.h",
]
deps = [
":pdfium",
diff --git a/core/fpdfapi/page/fpdf_page_func_embeddertest.cpp b/core/fpdfapi/page/fpdf_page_func_embeddertest.cpp
index 2892036882..6a1b87b570 100644
--- a/core/fpdfapi/page/fpdf_page_func_embeddertest.cpp
+++ b/core/fpdfapi/page/fpdf_page_func_embeddertest.cpp
@@ -15,6 +15,7 @@ TEST_F(FPDFPageFuncEmbeddertest, Bug_551460) {
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
index 639dcbf44c..9dfc26e369 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp
@@ -92,6 +92,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_552046) {
EXPECT_TRUE(OpenDocument("bug_552046.pdf"));
FPDF_PAGE page = LoadPage(0);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
@@ -102,6 +103,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_555784) {
EXPECT_TRUE(OpenDocument("bug_555784.pdf"));
FPDF_PAGE page = LoadPage(0);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
@@ -112,6 +114,13 @@ TEST_F(FPDFParserDecodeEmbeddertest, Bug_455199) {
EXPECT_TRUE(OpenDocument("bug_455199.pdf"));
FPDF_PAGE page = LoadPage(0);
FPDF_BITMAP bitmap = RenderPage(page);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ // Rendering on Mac is inconsistent, so skip this check.
+ const char* const kExpectedMd5sum = nullptr;
+#else
+ const char kExpectedMd5sum[] = "6f9f0fd903da177babb24dd50a806a56";
+#endif
+ CompareBitmap(bitmap, 200, 200, kExpectedMd5sum);
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
diff --git a/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp
index 5c6a8c513f..5b7cbc6f05 100644
--- a/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp
+++ b/core/fpdfapi/render/fpdf_render_loadimage_embeddertest.cpp
@@ -14,6 +14,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_554151) {
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 612, 792, "a14d7ee573c1b2456d7bf6b7762823cf");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
@@ -24,6 +25,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_557223) {
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 24, 24, "dc0ea1b743c2edb22c597cadc8537f7b");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
@@ -34,6 +36,7 @@ TEST_F(FPDFRenderLoadImageEmbeddertest, Bug_603518) {
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 749, 749, "b9e75190cdc5edf0069a408744ca07dc");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
diff --git a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
index 176c923372..ed6da46f2a 100644
--- a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
+++ b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp
@@ -12,6 +12,7 @@ TEST_F(FPDFRenderPatternEmbeddertest, LoadError_547706) {
EXPECT_TRUE(OpenDocument("bug_547706.pdf"));
FPDF_PAGE page = LoadPage(0);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
diff --git a/core/fxcodec/codec/fx_codec_embeddertest.cpp b/core/fxcodec/codec/fx_codec_embeddertest.cpp
index 441494c0e6..fd02f973a1 100644
--- a/core/fxcodec/codec/fx_codec_embeddertest.cpp
+++ b/core/fxcodec/codec/fx_codec_embeddertest.cpp
@@ -14,6 +14,7 @@ TEST_F(FXCodecEmbeddertest, Bug_631912) {
FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_BITMAP bitmap = RenderPage(page);
+ CompareBitmap(bitmap, 691, 432, "24d75af646f8772c5ee7ced260452ae4");
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
diff --git a/testing/DEPS b/testing/DEPS
index 4110b9b4d7..5adeb4141b 100644
--- a/testing/DEPS
+++ b/testing/DEPS
@@ -1,14 +1,6 @@
include_rules = [
- '+core/fpdfapi',
- '+core/fxcodec',
- '+core/fxcrt',
- '+core/fxge',
'+core',
'+fxjs',
'+public',
'+v8',
- '+xfa/fde',
- '+xfa/fgas',
- '+xfa/fxfa/fm2js',
- '+xfa/fxfa/parser',
]
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index c23b5c8018..bc4c027c66 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -11,6 +11,7 @@
#include <utility>
#include <vector>
+#include "core/fdrm/crypto/fx_crypt.h"
#include "public/fpdf_dataavail.h"
#include "public/fpdf_edit.h"
#include "public/fpdf_text.h"
@@ -35,14 +36,26 @@ v8::StartupData* g_v8_snapshot = nullptr;
#endif // V8_USE_EXTERNAL_STARTUP_DATA
#endif // PDF_ENABLE_V8
-} // namespace
-
FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {
return true;
}
void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {}
+std::string CRYPT_ToBase16(const uint8_t* digest) {
+ static char const zEncode[] = "0123456789abcdef";
+ std::string ret;
+ ret.resize(32);
+ for (int i = 0, j = 0; i < 16; i++, j += 2) {
+ uint8_t a = digest[i];
+ ret[j] = zEncode[(a >> 4) & 0xf];
+ ret[j + 1] = zEncode[a & 0xf];
+ }
+ return ret;
+}
+
+} // namespace
+
EmbedderTest::EmbedderTest()
: default_delegate_(new EmbedderTest::Delegate()),
document_(nullptr),
@@ -323,6 +336,25 @@ FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info,
page_index);
}
+// static
+void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap,
+ int expected_width,
+ int expected_height,
+ const char* expected_md5sum) {
+ ASSERT_EQ(expected_width, FPDFBitmap_GetWidth(bitmap));
+ ASSERT_EQ(expected_height, FPDFBitmap_GetHeight(bitmap));
+ const int expected_stride = expected_width * 4;
+ ASSERT_EQ(expected_stride, FPDFBitmap_GetStride(bitmap));
+
+ if (!expected_md5sum)
+ return;
+
+ uint8_t digest[16];
+ CRYPT_MD5Generate(static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)),
+ expected_stride * expected_height, digest);
+ EXPECT_EQ(expected_md5sum, CRYPT_ToBase16(digest));
+}
+
// Can't use gtest-provided main since we need to stash the path to the
// executable in order to find the external V8 binary data files.
int main(int argc, char** argv) {
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index dc4ca0dc08..cc0caec8f6 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -105,6 +105,12 @@ class EmbedderTest : public ::testing::Test,
// is prohibited after this call is made.
virtual void UnloadPage(FPDF_PAGE page);
+ // Check |bitmap| to make sure it has the right dimensions and content.
+ static void CompareBitmap(FPDF_BITMAP bitmap,
+ int expected_width,
+ int expected_height,
+ const char* expected_md5sum);
+
protected:
void SetupFormFillEnvironment();
diff --git a/testing/libfuzzer/DEPS b/testing/libfuzzer/DEPS
new file mode 100644
index 0000000000..b1d034ed8c
--- /dev/null
+++ b/testing/libfuzzer/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ '+xfa',
+]