summaryrefslogtreecommitdiff
path: root/testing
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 /testing
parentd33c8e3145539631d03242a16c3683c3538c7557 (diff)
downloadpdfium-bcd3e538f170a5ab2c3295f1a3b0062781d384a5.tar.xz
Check dimensions and content of bitmaps in EmbedderTests.chromium/2927
Review-Url: https://codereview.chromium.org/2514173002
Diffstat (limited to 'testing')
-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
4 files changed, 43 insertions, 10 deletions
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',
+]