Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 1 | // Copyright 2020 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "testing/embedder_test_environment.h" |
| 6 | |
Tom Sepez | 3799960 | 2022-05-20 16:44:20 +0000 | [diff] [blame] | 7 | #include <ostream> |
| 8 | |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 9 | #include "core/fxcrt/fx_system.h" |
| 10 | #include "public/fpdfview.h" |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 11 | #include "third_party/base/check.h" |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 12 | |
| 13 | #ifdef PDF_ENABLE_V8 |
| 14 | #include "testing/v8_test_environment.h" |
| 15 | #endif // PDF_ENABLE_V8 |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | EmbedderTestEnvironment* g_environment = nullptr; |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | EmbedderTestEnvironment::EmbedderTestEnvironment() { |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 24 | DCHECK(!g_environment); |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 25 | g_environment = this; |
| 26 | } |
| 27 | |
| 28 | EmbedderTestEnvironment::~EmbedderTestEnvironment() { |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 29 | DCHECK(g_environment); |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 30 | g_environment = nullptr; |
| 31 | } |
| 32 | |
| 33 | // static |
| 34 | EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() { |
| 35 | return g_environment; |
| 36 | } |
| 37 | |
| 38 | void EmbedderTestEnvironment::SetUp() { |
| 39 | FPDF_LIBRARY_CONFIG config; |
| 40 | config.version = 3; |
| 41 | config.m_pUserFontPaths = nullptr; |
| 42 | config.m_v8EmbedderSlot = 0; |
| 43 | config.m_pPlatform = nullptr; |
Tom Anderson | d4fe5f7 | 2021-12-03 20:52:52 +0000 | [diff] [blame] | 44 | |
| 45 | config.m_pUserFontPaths = test_fonts_.font_paths(); |
| 46 | |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 47 | #ifdef PDF_ENABLE_V8 |
| 48 | config.m_pIsolate = V8TestEnvironment::GetInstance()->isolate(); |
| 49 | config.m_pPlatform = V8TestEnvironment::GetInstance()->platform(); |
| 50 | #else // PDF_ENABLE_V8 |
| 51 | config.m_pIsolate = nullptr; |
| 52 | config.m_pPlatform = nullptr; |
| 53 | #endif // PDF_ENABLE_V8 |
| 54 | |
| 55 | FPDF_InitLibraryWithConfig(&config); |
Tom Anderson | d4fe5f7 | 2021-12-03 20:52:52 +0000 | [diff] [blame] | 56 | |
| 57 | test_fonts_.InstallFontMapper(); |
Tom Sepez | 72f520c | 2020-08-24 23:43:46 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void EmbedderTestEnvironment::TearDown() { |
| 61 | FPDF_DestroyLibrary(); |
| 62 | } |
Tom Sepez | 3799960 | 2022-05-20 16:44:20 +0000 | [diff] [blame] | 63 | |
| 64 | void EmbedderTestEnvironment::AddFlags(int argc, char** argv) { |
| 65 | for (int i = 1; i < argc; ++i) |
| 66 | AddFlag(argv[i]); |
| 67 | } |
| 68 | |
| 69 | void EmbedderTestEnvironment::AddFlag(const std::string& flag) { |
| 70 | if (flag == "--write-pngs") |
| 71 | write_pngs_ = true; |
| 72 | else |
| 73 | std::cerr << "Unknown flag: " << flag << "\n"; |
| 74 | } |