OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/embedder_test.h" | 5 #include "testing/embedder_test.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "core/fdrm/crypto/fx_crypt.h" |
14 #include "public/fpdf_dataavail.h" | 15 #include "public/fpdf_dataavail.h" |
15 #include "public/fpdf_edit.h" | 16 #include "public/fpdf_edit.h" |
16 #include "public/fpdf_text.h" | 17 #include "public/fpdf_text.h" |
17 #include "public/fpdfview.h" | 18 #include "public/fpdfview.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/test_support.h" | 20 #include "testing/test_support.h" |
20 #include "testing/utils/path_service.h" | 21 #include "testing/utils/path_service.h" |
21 | 22 |
22 #ifdef PDF_ENABLE_V8 | 23 #ifdef PDF_ENABLE_V8 |
23 #include "v8/include/v8-platform.h" | 24 #include "v8/include/v8-platform.h" |
24 #include "v8/include/v8.h" | 25 #include "v8/include/v8.h" |
25 #endif // PDF_ENABLE_V8 | 26 #endif // PDF_ENABLE_V8 |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const char* g_exe_path = nullptr; | 30 const char* g_exe_path = nullptr; |
30 | 31 |
31 #ifdef PDF_ENABLE_V8 | 32 #ifdef PDF_ENABLE_V8 |
32 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 33 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
33 v8::StartupData* g_v8_natives = nullptr; | 34 v8::StartupData* g_v8_natives = nullptr; |
34 v8::StartupData* g_v8_snapshot = nullptr; | 35 v8::StartupData* g_v8_snapshot = nullptr; |
35 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 36 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
36 #endif // PDF_ENABLE_V8 | 37 #endif // PDF_ENABLE_V8 |
37 | 38 |
38 } // namespace | |
39 | |
40 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 39 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
41 return true; | 40 return true; |
42 } | 41 } |
43 | 42 |
44 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} | 43 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} |
45 | 44 |
| 45 std::string CRYPT_ToBase16(const uint8_t* digest) { |
| 46 static char const zEncode[] = "0123456789abcdef"; |
| 47 std::string ret; |
| 48 ret.resize(32); |
| 49 for (int i = 0, j = 0; i < 16; i++, j += 2) { |
| 50 uint8_t a = digest[i]; |
| 51 ret[j] = zEncode[(a >> 4) & 0xf]; |
| 52 ret[j + 1] = zEncode[a & 0xf]; |
| 53 } |
| 54 return ret; |
| 55 } |
| 56 |
| 57 } // namespace |
| 58 |
46 EmbedderTest::EmbedderTest() | 59 EmbedderTest::EmbedderTest() |
47 : default_delegate_(new EmbedderTest::Delegate()), | 60 : default_delegate_(new EmbedderTest::Delegate()), |
48 document_(nullptr), | 61 document_(nullptr), |
49 form_handle_(nullptr), | 62 form_handle_(nullptr), |
50 avail_(nullptr), | 63 avail_(nullptr), |
51 external_isolate_(nullptr), | 64 external_isolate_(nullptr), |
52 loader_(nullptr), | 65 loader_(nullptr), |
53 file_length_(0), | 66 file_length_(0), |
54 file_contents_(nullptr) { | 67 file_contents_(nullptr) { |
55 memset(&hints_, 0, sizeof(hints_)); | 68 memset(&hints_, 0, sizeof(hints_)); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 329 } |
317 | 330 |
318 // static | 331 // static |
319 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, | 332 FPDF_PAGE EmbedderTest::GetPageTrampoline(FPDF_FORMFILLINFO* info, |
320 FPDF_DOCUMENT document, | 333 FPDF_DOCUMENT document, |
321 int page_index) { | 334 int page_index) { |
322 return static_cast<EmbedderTest*>(info)->delegate_->GetPage(info, document, | 335 return static_cast<EmbedderTest*>(info)->delegate_->GetPage(info, document, |
323 page_index); | 336 page_index); |
324 } | 337 } |
325 | 338 |
| 339 // static |
| 340 void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap, |
| 341 int expected_width, |
| 342 int expected_height, |
| 343 const char* expected_md5sum) { |
| 344 ASSERT_EQ(expected_width, FPDFBitmap_GetWidth(bitmap)); |
| 345 ASSERT_EQ(expected_height, FPDFBitmap_GetHeight(bitmap)); |
| 346 const int expected_stride = expected_width * 4; |
| 347 ASSERT_EQ(expected_stride, FPDFBitmap_GetStride(bitmap)); |
| 348 |
| 349 if (!expected_md5sum) |
| 350 return; |
| 351 |
| 352 uint8_t digest[16]; |
| 353 CRYPT_MD5Generate(static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)), |
| 354 expected_stride * expected_height, digest); |
| 355 EXPECT_EQ(expected_md5sum, CRYPT_ToBase16(digest)); |
| 356 } |
| 357 |
326 // Can't use gtest-provided main since we need to stash the path to the | 358 // Can't use gtest-provided main since we need to stash the path to the |
327 // executable in order to find the external V8 binary data files. | 359 // executable in order to find the external V8 binary data files. |
328 int main(int argc, char** argv) { | 360 int main(int argc, char** argv) { |
329 g_exe_path = argv[0]; | 361 g_exe_path = argv[0]; |
330 testing::InitGoogleTest(&argc, argv); | 362 testing::InitGoogleTest(&argc, argv); |
331 testing::InitGoogleMock(&argc, argv); | 363 testing::InitGoogleMock(&argc, argv); |
332 int ret_val = RUN_ALL_TESTS(); | 364 int ret_val = RUN_ALL_TESTS(); |
333 | 365 |
334 #ifdef PDF_ENABLE_V8 | 366 #ifdef PDF_ENABLE_V8 |
335 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 367 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
336 if (g_v8_natives) | 368 if (g_v8_natives) |
337 free(const_cast<char*>(g_v8_natives->data)); | 369 free(const_cast<char*>(g_v8_natives->data)); |
338 if (g_v8_snapshot) | 370 if (g_v8_snapshot) |
339 free(const_cast<char*>(g_v8_snapshot->data)); | 371 free(const_cast<char*>(g_v8_snapshot->data)); |
340 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 372 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
341 #endif // PDF_ENABLE_V8 | 373 #endif // PDF_ENABLE_V8 |
342 | 374 |
343 return ret_val; | 375 return ret_val; |
344 } | 376 } |
OLD | NEW |