Create testing command line helpers
Promote ParseSwitchKeyValue() out of pdfium_test sample into a helper
file so that it can be shared with other testing executables.
Similarly move BuildDefaultRendererType() out of pdfium_test sample.
Rename this to avoid possible confusion with a builder pattern, as
this routine is a query which does not build anything.
Bug: pdfium:1878
Change-Id: I24e4830a5130a1f46f89be68ab9c814aa0b85e9f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98311
Commit-Queue: Alan Screen <awscreen@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index e35db65..3d9b027 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -37,6 +37,7 @@
#include "samples/pdfium_test_dump_helper.h"
#include "samples/pdfium_test_event_helper.h"
#include "samples/pdfium_test_write_helper.h"
+#include "testing/command_line_helpers.h"
#include "testing/font_renamer.h"
#include "testing/fx_string_testhelpers.h"
#include "testing/test_loader.h"
@@ -183,14 +184,6 @@
return flags;
}
-FPDF_RENDERER_TYPE BuildDefaultRendererType() {
-#if defined(_SKIA_SUPPORT_)
- return FPDF_RENDERERTYPE_SKIA;
-#else
- return FPDF_RENDERERTYPE_AGG;
-#endif
-}
-
absl::optional<std::string> ExpandDirectoryPath(const std::string& path) {
#if defined(WORDEXP_AVAILABLE)
wordexp_t expansion;
@@ -414,17 +407,6 @@
printf("Unsupported feature: %s.\n", feature.c_str());
}
-// |arg| is expected to be "--key=value", and |key| is "--key=".
-bool ParseSwitchKeyValue(const std::string& arg,
- const std::string& key,
- std::string* value) {
- if (arg.size() <= key.size() || arg.compare(0, key.size(), key) != 0)
- return false;
-
- *value = arg.substr(key.size());
- return true;
-}
-
bool ParseCommandLine(const std::vector<std::string>& args,
Options* options,
std::vector<std::string>* files) {
@@ -1233,7 +1215,7 @@
config.m_v8EmbedderSlot = 0;
config.m_pPlatform = nullptr;
config.m_RendererType =
- options.use_renderer_type.value_or(BuildDefaultRendererType());
+ options.use_renderer_type.value_or(GetDefaultRendererType());
std::function<void()> idler = []() {};
#ifdef PDF_ENABLE_V8
diff --git a/testing/BUILD.gn b/testing/BUILD.gn
index 9a01845..97ea865 100644
--- a/testing/BUILD.gn
+++ b/testing/BUILD.gn
@@ -7,6 +7,8 @@
source_set("test_support") {
testonly = true
sources = [
+ "command_line_helpers.cpp",
+ "command_line_helpers.h",
"font_renamer.cpp",
"font_renamer.h",
"fx_string_testhelpers.cpp",
diff --git a/testing/command_line_helpers.cpp b/testing/command_line_helpers.cpp
new file mode 100644
index 0000000..758f278
--- /dev/null
+++ b/testing/command_line_helpers.cpp
@@ -0,0 +1,23 @@
+// Copyright 2022 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/command_line_helpers.h"
+
+bool ParseSwitchKeyValue(const std::string& arg,
+ const std::string& key,
+ std::string* value) {
+ if (arg.size() <= key.size() || arg.compare(0, key.size(), key) != 0)
+ return false;
+
+ *value = arg.substr(key.size());
+ return true;
+}
+
+FPDF_RENDERER_TYPE GetDefaultRendererType() {
+#if defined(_SKIA_SUPPORT_)
+ return FPDF_RENDERERTYPE_SKIA;
+#else
+ return FPDF_RENDERERTYPE_AGG;
+#endif
+}
diff --git a/testing/command_line_helpers.h b/testing/command_line_helpers.h
new file mode 100644
index 0000000..cc134cb
--- /dev/null
+++ b/testing/command_line_helpers.h
@@ -0,0 +1,23 @@
+// Copyright 2022 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_COMMAND_LINE_HELPERS_H_
+#define TESTING_COMMAND_LINE_HELPERS_H_
+
+#include <string>
+
+#include "public/fpdfview.h"
+
+// Extract the value from a keyed command line argument.
+// `arg` is expected to be "--key=value", and `key` is "--key=".
+bool ParseSwitchKeyValue(const std::string& arg,
+ const std::string& key,
+ std::string* value);
+
+// Identifies the compile-time default 2D graphics library to use for rendering
+// to FPDF_BITMAPs. Used as part of support to override the renderer at runtime
+// based upon command line options.
+FPDF_RENDERER_TYPE GetDefaultRendererType();
+
+#endif // TESTING_COMMAND_LINE_HELPERS_H_