Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: testing/embedder_test.cpp

Issue 2514173002: Check dimensions and content of bitmaps in EmbedderTests. (Closed)
Patch Set: Use built-in md5sum, rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/embedder_test.h ('k') | testing/libfuzzer/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/embedder_test.cpp
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index c23b5c8018d78c4bdf1a88b0d0726c4b0ca62b3c..bc4c027c6641cae5a52fb8a6efab54e8a3998bb6 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) {
« no previous file with comments | « testing/embedder_test.h ('k') | testing/libfuzzer/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698