Move pdfium_test.cc from samples/ to testing/

Allow future use of non-public APIs in the test programs. Also,
this has become far too complex to serve as a useful sample.

Fixed: pdfium:1895
Change-Id: I8ff3113a4aebbaf24d1cbcc46746c37436f46dbb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/118911
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 5ac06bf..5f4da3b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -586,7 +586,7 @@
     ":pdfium_diff",
     ":pdfium_embeddertests",
     ":pdfium_unittests",
-    "samples",
+    "testing:pdfium_test",
     "testing/fuzzers",
   ]
 
diff --git a/README.md b/README.md
index d674025..1aeb563 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@
 is_component_build = false # Disable component build (Though it should work)
 ```
 
-For sample applications like `pdfium_test` to build, one must set
+For test applications like `pdfium_test` to build, one must set
 `pdf_is_standalone = true`.
 
 By default, the entire project builds with C++20.
@@ -110,11 +110,12 @@
 
 ## Building the code
 
-You can build the sample program by running: `ninja -C <directory> pdfium_test`
+You can build the standalone test program by running:
+`ninja -C <directory> pdfium_test`
 You can build the entire product (which includes a few unit tests) by running:
-`ninja -C <directory> pdfium_all`.
+`ninja -C <directory> pdfium_all`
 
-## Running the sample program
+## Running the standalone test program
 
 The pdfium\_test program supports reading, parsing, and rasterizing the pages of
 a .pdf file to .ppm or .png output image files (Windows supports two other
diff --git a/samples/BUILD.gn b/samples/BUILD.gn
deleted file mode 100644
index 666b043..0000000
--- a/samples/BUILD.gn
+++ /dev/null
@@ -1,86 +0,0 @@
-# Copyright 2014 The PDFium Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/config/sanitizers/sanitizers.gni")
-import("../pdfium.gni")
-
-group("samples") {
-  testonly = true
-  deps = [ ":pdfium_test" ]
-}
-
-config("pdfium_samples_config") {
-  cflags = []
-  ldflags = []
-  defines = []
-  include_dirs = [ ".." ]
-  if (pdf_use_skia) {
-    defines += [ "PDF_ENABLE_SKIA" ]
-  }
-  if (is_asan) {
-    defines += [ "PDF_ENABLE_ASAN" ]
-  }
-  if (pdf_use_partition_alloc) {
-    defines += [ "PDF_USE_PARTITION_ALLOC" ]
-  }
-  if (enable_callgrind) {
-    defines += [ "ENABLE_CALLGRIND" ]
-  }
-  if (build_with_chromium) {
-    defines += [ "BUILD_WITH_CHROMIUM" ]
-  }
-}
-
-executable("pdfium_test") {
-  testonly = true
-  sources = [
-    "helpers/dump.cc",
-    "helpers/dump.h",
-    "helpers/event.cc",
-    "helpers/event.h",
-    "helpers/page_renderer.cc",
-    "helpers/page_renderer.h",
-    "helpers/write.cc",
-    "helpers/write.h",
-    "pdfium_test.cc",
-  ]
-
-  # Note: One should write programs that depend on ../:pdfium. Whereas this
-  # sample program does not set a good example, and depends on PDFium internals,
-  # as well as test support code, for convenience.
-  deps = [
-    "../:pdfium_public_headers",
-    "../fpdfsdk",
-    "../testing:test_support",
-    "../testing/image_diff",
-    "//build/win:default_exe_manifest",
-  ]
-  configs += [ ":pdfium_samples_config" ]
-
-  if (is_win) {
-    sources += [
-      "helpers/win32/com_factory.cc",
-      "helpers/win32/com_factory.h",
-    ]
-  }
-
-  if (pdf_enable_v8) {
-    deps += [
-      "//v8:v8_headers",
-      "//v8:v8_libplatform",
-    ]
-    include_dirs = [ "//v8" ]
-    configs += [ "//v8:external_startup_data" ]
-  }
-  if (pdf_use_skia) {
-    deps += [ "//skia" ]
-    if (build_with_chromium) {
-      sources += [
-        "chromium_support/discardable_memory_allocator.cc",
-        "chromium_support/discardable_memory_allocator.h",
-      ]
-      deps += [ "//base/test:test_support" ]
-    }
-  }
-}
diff --git a/samples/DEPS b/samples/DEPS
index c77b78b..407fa4a 100644
--- a/samples/DEPS
+++ b/samples/DEPS
@@ -1,6 +1,4 @@
 include_rules = [
-  '+core/fxcrt',
   '+public',
-  '+third_party/skia/include',
   '+v8',
 ]
diff --git a/samples/chromium_support/discardable_memory_allocator.h b/samples/chromium_support/discardable_memory_allocator.h
deleted file mode 100644
index 1f91f70..0000000
--- a/samples/chromium_support/discardable_memory_allocator.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2023 The PDFium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SAMPLES_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
-#define SAMPLES_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
-
-namespace chromium_support {
-
-void InitializeDiscardableMemoryAllocator();
-
-}  // namespace chromium_support
-
-#endif  // SAMPLES_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
diff --git a/testing/BUILD.gn b/testing/BUILD.gn
index 168f9a42..eea1387 100644
--- a/testing/BUILD.gn
+++ b/testing/BUILD.gn
@@ -229,6 +229,81 @@
   }
 }
 
+config("pdfium_test_config") {
+  cflags = []
+  ldflags = []
+  defines = []
+  include_dirs = [ ".." ]
+  if (pdf_use_skia) {
+    defines += [ "PDF_ENABLE_SKIA" ]
+  }
+  if (is_asan) {
+    defines += [ "PDF_ENABLE_ASAN" ]
+  }
+  if (pdf_use_partition_alloc) {
+    defines += [ "PDF_USE_PARTITION_ALLOC" ]
+  }
+  if (enable_callgrind) {
+    defines += [ "ENABLE_CALLGRIND" ]
+  }
+  if (build_with_chromium) {
+    defines += [ "BUILD_WITH_CHROMIUM" ]
+  }
+}
+
+executable("pdfium_test") {
+  testonly = true
+  sources = [
+    "helpers/dump.cc",
+    "helpers/dump.h",
+    "helpers/event.cc",
+    "helpers/event.h",
+    "helpers/page_renderer.cc",
+    "helpers/page_renderer.h",
+    "helpers/write.cc",
+    "helpers/write.h",
+    "pdfium_test.cc",
+  ]
+
+  # Note: One should write programs that depend on ../:pdfium. Whereas this
+  # test program does not set a good example, and depends on PDFium internals,
+  # as well as test support code, for convenience.
+  deps = [
+    "../:pdfium_public_headers",
+    "../fpdfsdk",
+    "../testing:test_support",
+    "../testing/image_diff",
+    "//build/win:default_exe_manifest",
+  ]
+  configs += [ ":pdfium_test_config" ]
+
+  if (is_win) {
+    sources += [
+      "helpers/win32/com_factory.cc",
+      "helpers/win32/com_factory.h",
+    ]
+  }
+
+  if (pdf_enable_v8) {
+    deps += [
+      "//v8:v8_headers",
+      "//v8:v8_libplatform",
+    ]
+    include_dirs = [ "//v8" ]
+    configs += [ "//v8:external_startup_data" ]
+  }
+  if (pdf_use_skia) {
+    deps += [ "//skia" ]
+    if (build_with_chromium) {
+      sources += [
+        "chromium_support/discardable_memory_allocator.cc",
+        "chromium_support/discardable_memory_allocator.h",
+      ]
+      deps += [ "//base/test:test_support" ]
+    }
+  }
+}
+
 # Dummy group to keep satisfy references from //build.
 group("test_scripts_shared") {
 }
diff --git a/testing/DEPS b/testing/DEPS
index bb5891e..efd29d3 100644
--- a/testing/DEPS
+++ b/testing/DEPS
@@ -4,6 +4,7 @@
   '+fxjs',
   '+partition_alloc',
   '+public',
+  '+third_party/skia/include',
   '+v8',
   '+xfa'
 ]
diff --git a/samples/chromium_support/DEPS b/testing/chromium_support/DEPS
similarity index 100%
rename from samples/chromium_support/DEPS
rename to testing/chromium_support/DEPS
diff --git a/samples/chromium_support/discardable_memory_allocator.cc b/testing/chromium_support/discardable_memory_allocator.cc
similarity index 87%
rename from samples/chromium_support/discardable_memory_allocator.cc
rename to testing/chromium_support/discardable_memory_allocator.cc
index f89bb1c..b2ba7fd 100644
--- a/samples/chromium_support/discardable_memory_allocator.cc
+++ b/testing/chromium_support/discardable_memory_allocator.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/chromium_support/discardable_memory_allocator.h"
+#include "testing/chromium_support/discardable_memory_allocator.h"
 
 #include "base/test/test_discardable_memory_allocator.h"
 
diff --git a/testing/chromium_support/discardable_memory_allocator.h b/testing/chromium_support/discardable_memory_allocator.h
new file mode 100644
index 0000000..1dda9c2
--- /dev/null
+++ b/testing/chromium_support/discardable_memory_allocator.h
@@ -0,0 +1,14 @@
+// Copyright 2023 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_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
+#define TESTING_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
+
+namespace chromium_support {
+
+void InitializeDiscardableMemoryAllocator();
+
+}  // namespace chromium_support
+
+#endif  // TESTING_CHROMIUM_SUPPORT_DISCARDABLE_MEMORY_ALLOCATOR_H_
diff --git a/samples/helpers/dump.cc b/testing/helpers/dump.cc
similarity index 99%
rename from samples/helpers/dump.cc
rename to testing/helpers/dump.cc
index e2a8469..f682732 100644
--- a/samples/helpers/dump.cc
+++ b/testing/helpers/dump.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/helpers/dump.h"
+#include "testing/helpers/dump.h"
 
 #include <limits.h>
 #include <string.h>
diff --git a/samples/helpers/dump.h b/testing/helpers/dump.h
similarity index 79%
rename from samples/helpers/dump.h
rename to testing/helpers/dump.h
index 6682b29..2e804e3 100644
--- a/samples/helpers/dump.h
+++ b/testing/helpers/dump.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SAMPLES_HELPERS_DUMP_H_
-#define SAMPLES_HELPERS_DUMP_H_
+#ifndef TESTING_HELPERS_DUMP_H_
+#define TESTING_HELPERS_DUMP_H_
 
 #include "public/fpdfview.h"
 
@@ -12,4 +12,4 @@
 void DumpPageStructure(FPDF_PAGE page, int page_idx);
 void DumpMetaData(FPDF_DOCUMENT doc);
 
-#endif  // SAMPLES_HELPERS_DUMP_H_
+#endif  // TESTING_HELPERS_DUMP_H_
diff --git a/samples/helpers/event.cc b/testing/helpers/event.cc
similarity index 99%
rename from samples/helpers/event.cc
rename to testing/helpers/event.cc
index 48491e8..9ed69a4 100644
--- a/samples/helpers/event.cc
+++ b/testing/helpers/event.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/helpers/event.h"
+#include "testing/helpers/event.h"
 
 #include <stdio.h>
 
diff --git a/samples/helpers/event.h b/testing/helpers/event.h
similarity index 80%
rename from samples/helpers/event.h
rename to testing/helpers/event.h
index 021c075..f7af3a8 100644
--- a/samples/helpers/event.h
+++ b/testing/helpers/event.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SAMPLES_HELPERS_EVENT_H_
-#define SAMPLES_HELPERS_EVENT_H_
+#ifndef TESTING_HELPERS_EVENT_H_
+#define TESTING_HELPERS_EVENT_H_
 
 #include <functional>
 #include <string>
@@ -16,4 +16,4 @@
                     const std::string& events,
                     const std::function<void()>& idler);
 
-#endif  // SAMPLES_HELPERS_EVENT_H_
+#endif  // TESTING_HELPERS_EVENT_H_
diff --git a/samples/helpers/page_renderer.cc b/testing/helpers/page_renderer.cc
similarity index 90%
rename from samples/helpers/page_renderer.cc
rename to testing/helpers/page_renderer.cc
index e7771ef..c673be8 100644
--- a/samples/helpers/page_renderer.cc
+++ b/testing/helpers/page_renderer.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/helpers/page_renderer.h"
+#include "testing/helpers/page_renderer.h"
 
 #include "public/fpdfview.h"
 
diff --git a/samples/helpers/page_renderer.h b/testing/helpers/page_renderer.h
similarity index 89%
rename from samples/helpers/page_renderer.h
rename to testing/helpers/page_renderer.h
index 277bd0f..8710b3d 100644
--- a/samples/helpers/page_renderer.h
+++ b/testing/helpers/page_renderer.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SAMPLES_HELPERS_PAGE_RENDERER_H_
-#define SAMPLES_HELPERS_PAGE_RENDERER_H_
+#ifndef TESTING_HELPERS_PAGE_RENDERER_H_
+#define TESTING_HELPERS_PAGE_RENDERER_H_
 
 #include <string>
 
@@ -44,4 +44,4 @@
   int flags_;
 };
 
-#endif  // SAMPLES_HELPERS_PAGE_RENDERER_H_
+#endif  // TESTING_HELPERS_PAGE_RENDERER_H_
diff --git a/samples/helpers/win32/com_factory.cc b/testing/helpers/win32/com_factory.cc
similarity index 96%
rename from samples/helpers/win32/com_factory.cc
rename to testing/helpers/win32/com_factory.cc
index ffe9cf6..6c37dc3 100644
--- a/samples/helpers/win32/com_factory.cc
+++ b/testing/helpers/win32/com_factory.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/helpers/win32/com_factory.h"
+#include "testing/helpers/win32/com_factory.h"
 
 #include <combaseapi.h>
 #include <objbase.h>
diff --git a/samples/helpers/win32/com_factory.h b/testing/helpers/win32/com_factory.h
similarity index 76%
rename from samples/helpers/win32/com_factory.h
rename to testing/helpers/win32/com_factory.h
index eabaffe..d634cef 100644
--- a/samples/helpers/win32/com_factory.h
+++ b/testing/helpers/win32/com_factory.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SAMPLES_HELPERS_WIN32_COM_FACTORY_H_
-#define SAMPLES_HELPERS_WIN32_COM_FACTORY_H_
+#ifndef TESTING_HELPERS_WIN32_COM_FACTORY_H_
+#define TESTING_HELPERS_WIN32_COM_FACTORY_H_
 
 struct IXpsOMObjectFactory;
 
@@ -22,4 +22,4 @@
   IXpsOMObjectFactory* xps_om_object_factory_ = nullptr;
 };
 
-#endif  // SAMPLES_HELPERS_WIN32_COM_FACTORY_H_
+#endif  // TESTING_HELPERS_WIN32_COM_FACTORY_H_
diff --git a/samples/helpers/write.cc b/testing/helpers/write.cc
similarity index 99%
rename from samples/helpers/write.cc
rename to testing/helpers/write.cc
index a3478f2..951a170 100644
--- a/samples/helpers/write.cc
+++ b/testing/helpers/write.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "samples/helpers/write.h"
+#include "testing/helpers/write.h"
 
 #include <limits.h>
 
diff --git a/samples/helpers/write.h b/testing/helpers/write.h
similarity index 95%
rename from samples/helpers/write.h
rename to testing/helpers/write.h
index b23760e..8717364 100644
--- a/samples/helpers/write.h
+++ b/testing/helpers/write.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SAMPLES_HELPERS_WRITE_H_
-#define SAMPLES_HELPERS_WRITE_H_
+#ifndef TESTING_HELPERS_WRITE_H_
+#define TESTING_HELPERS_WRITE_H_
 
 #include <memory>
 #include <string>
@@ -66,4 +66,4 @@
                              int page_num);
 void WriteThumbnail(FPDF_PAGE page, const char* pdf_name, int page_num);
 
-#endif  // SAMPLES_HELPERS_WRITE_H_
+#endif  // TESTING_HELPERS_WRITE_H_
diff --git a/samples/pdfium_test.cc b/testing/pdfium_test.cc
similarity index 99%
rename from samples/pdfium_test.cc
rename to testing/pdfium_test.cc
index a48bde8..6f8dcab 100644
--- a/samples/pdfium_test.cc
+++ b/testing/pdfium_test.cc
@@ -37,13 +37,13 @@
 #include "public/fpdf_structtree.h"
 #include "public/fpdf_text.h"
 #include "public/fpdfview.h"
-#include "samples/helpers/dump.h"
-#include "samples/helpers/event.h"
-#include "samples/helpers/page_renderer.h"
-#include "samples/helpers/write.h"
 #include "testing/command_line_helpers.h"
 #include "testing/font_renamer.h"
 #include "testing/fx_string_testhelpers.h"
+#include "testing/helpers/dump.h"
+#include "testing/helpers/event.h"
+#include "testing/helpers/page_renderer.h"
+#include "testing/helpers/write.h"
 #include "testing/test_loader.h"
 #include "testing/utils/file_util.h"
 #include "testing/utils/hash.h"
@@ -55,7 +55,7 @@
 #include <io.h>
 #include <wingdi.h>
 
-#include "samples/helpers/win32/com_factory.h"
+#include "testing/helpers/win32/com_factory.h"
 #else
 #include <unistd.h>
 #endif  // _WIN32
@@ -84,7 +84,7 @@
 #endif
 
 #ifdef BUILD_WITH_CHROMIUM
-#include "samples/chromium_support/discardable_memory_allocator.h"  // nogncheck
+#include "testing/chromium_support/discardable_memory_allocator.h"  // nogncheck
 #endif
 #endif  // PDF_ENABLE_SKIA
 
diff --git a/testing/tools/BUILD.gn b/testing/tools/BUILD.gn
index 8815b53..15d841b 100644
--- a/testing/tools/BUILD.gn
+++ b/testing/tools/BUILD.gn
@@ -37,8 +37,8 @@
 
     # Built runtime dependencies.
     data_deps = [
+      "../:pdfium_test",
       "../../:pdfium_diff",
-      "../../samples:pdfium_test",
     ]
 
     # Force `data_deps` to be built before this target, rather than in parallel.