Remove out-parameter from PathService::GetTestFilePath()
Just return the path directly, and use empty paths as the indicator for
failure.
Change-Id: Iffb892260e3dcc907148ff91698a1a44c67694a8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/113450
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp b/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
index 34e436f..50986f1 100644
--- a/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
@@ -27,8 +27,8 @@
CPDF_PageModule::Create();
{
- std::string file_path;
- ASSERT_TRUE(PathService::GetTestFilePath("jpx_lzw.pdf", &file_path));
+ std::string file_path = PathService::GetTestFilePath("jpx_lzw.pdf");
+ ASSERT_FALSE(file_path.empty());
auto document =
std::make_unique<CPDF_Document>(std::make_unique<CPDF_DocRenderData>(),
std::make_unique<CPDF_DocPageData>());
diff --git a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
index c61afa1..64f7e26 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
@@ -28,9 +28,8 @@
RetainPtr<CPDF_ReadValidator> MakeValidatorFromFile(
const std::string& file_name) {
- std::string file_path;
- PathService::GetTestFilePath(file_name, &file_path);
- DCHECK(!file_path.empty());
+ std::string file_path = PathService::GetTestFilePath(file_name);
+ CHECK(!file_path.empty());
return pdfium::MakeRetain<CPDF_ReadValidator>(
IFX_SeekableReadStream::CreateFromFilename(file_path.c_str()), nullptr);
}
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index acaf9cb..addff1f 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -141,9 +141,9 @@
TEST(ParserTest, RebuildCrossRefCorrectly) {
CPDF_TestParser parser;
- std::string test_file;
- ASSERT_TRUE(PathService::GetTestFilePath("parser_rebuildxref_correct.pdf",
- &test_file));
+ std::string test_file =
+ PathService::GetTestFilePath("parser_rebuildxref_correct.pdf");
+ ASSERT_FALSE(test_file.empty());
ASSERT_TRUE(parser.InitTestFromFile(test_file.c_str())) << test_file;
ASSERT_TRUE(parser.RebuildCrossRef());
@@ -161,9 +161,9 @@
TEST(ParserTest, RebuildCrossRefFailed) {
CPDF_TestParser parser;
- std::string test_file;
- ASSERT_TRUE(PathService::GetTestFilePath(
- "parser_rebuildxref_error_notrailer.pdf", &test_file));
+ std::string test_file =
+ PathService::GetTestFilePath("parser_rebuildxref_error_notrailer.pdf");
+ ASSERT_FALSE(test_file.empty());
ASSERT_TRUE(parser.InitTestFromFile(test_file.c_str())) << test_file;
ASSERT_FALSE(parser.RebuildCrossRef());
@@ -340,9 +340,9 @@
TEST(ParserTest, ParseStartXRef) {
CPDF_TestParser parser;
- std::string test_file;
- ASSERT_TRUE(
- PathService::GetTestFilePath("annotation_stamp_with_ap.pdf", &test_file));
+ std::string test_file =
+ PathService::GetTestFilePath("annotation_stamp_with_ap.pdf");
+ ASSERT_FALSE(test_file.empty());
ASSERT_TRUE(parser.InitTestFromFile(test_file.c_str())) << test_file;
EXPECT_EQ(100940, parser.ParseStartXRef());
@@ -354,9 +354,9 @@
TEST(ParserTest, ParseStartXRefWithHeaderOffset) {
static constexpr FX_FILESIZE kTestHeaderOffset = 765;
- std::string test_file;
- ASSERT_TRUE(
- PathService::GetTestFilePath("annotation_stamp_with_ap.pdf", &test_file));
+ std::string test_file =
+ PathService::GetTestFilePath("annotation_stamp_with_ap.pdf");
+ ASSERT_FALSE(test_file.empty());
RetainPtr<IFX_SeekableReadStream> pFileAccess =
IFX_SeekableReadStream::CreateFromFilename(test_file.c_str());
ASSERT_TRUE(pFileAccess);
@@ -376,8 +376,8 @@
TEST(ParserTest, ParseLinearizedWithHeaderOffset) {
static constexpr FX_FILESIZE kTestHeaderOffset = 765;
- std::string test_file;
- ASSERT_TRUE(PathService::GetTestFilePath("linearized.pdf", &test_file));
+ std::string test_file = PathService::GetTestFilePath("linearized.pdf");
+ ASSERT_FALSE(test_file.empty());
RetainPtr<IFX_SeekableReadStream> pFileAccess =
IFX_SeekableReadStream::CreateFromFilename(test_file.c_str());
ASSERT_TRUE(pFileAccess);
diff --git a/fpdfsdk/fpdf_dataavail_embeddertest.cpp b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
index 55e7705..011ef2c 100644
--- a/fpdfsdk/fpdf_dataavail_embeddertest.cpp
+++ b/fpdfsdk/fpdf_dataavail_embeddertest.cpp
@@ -36,9 +36,10 @@
class TestAsyncLoader final : public FX_DOWNLOADHINTS, FX_FILEAVAIL {
public:
explicit TestAsyncLoader(const std::string& file_name) {
- std::string file_path;
- if (!PathService::GetTestFilePath(file_name, &file_path))
+ std::string file_path = PathService::GetTestFilePath(file_name);
+ if (file_path.empty()) {
return;
+ }
file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
if (!file_contents_)
return;
diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp
index 7ad2308..bc3d442 100644
--- a/fpdfsdk/fpdf_ppo_embeddertest.cpp
+++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp
@@ -633,8 +633,8 @@
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
EXPECT_EQ(1, FPDF_GetPageCount(document()));
- std::string file_path;
- ASSERT_TRUE(PathService::GetTestFilePath("rectangles.pdf", &file_path));
+ std::string file_path = PathService::GetTestFilePath("rectangles.pdf");
+ ASSERT_FALSE(file_path.empty());
size_t file_length = 0;
std::unique_ptr<char, pdfium::FreeDeleter> file_contents =
GetFileContents(file_path.c_str(), &file_length);
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index 617b9cf..4f1c9e3 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -507,8 +507,8 @@
}
TEST_F(FPDFViewEmbedderTest, LoadDocument64) {
- std::string file_path;
- ASSERT_TRUE(PathService::GetTestFilePath("about_blank.pdf", &file_path));
+ std::string file_path = PathService::GetTestFilePath("about_blank.pdf");
+ ASSERT_FALSE(file_path.empty());
size_t file_length = 0;
std::unique_ptr<char, pdfium::FreeDeleter> file_contents =
@@ -610,9 +610,9 @@
ScopedFPDFDocument doc;
{
// Read a PDF, and copy it into |file_contents_string|.
- std::string pdf_path;
size_t pdf_length;
- ASSERT_TRUE(PathService::GetTestFilePath("rectangles.pdf", &pdf_path));
+ std::string pdf_path = PathService::GetTestFilePath("rectangles.pdf");
+ ASSERT_FALSE(pdf_path.empty());
auto file_contents = GetFileContents(pdf_path.c_str(), &pdf_length);
ASSERT_TRUE(file_contents);
for (size_t i = 0; i < pdf_length; ++i)
@@ -1401,9 +1401,9 @@
}
TEST_F(FPDFViewEmbedderTest, UnSupportedOperations_LoadDocument) {
- std::string file_path;
- ASSERT_TRUE(
- PathService::GetTestFilePath("unsupported_feature.pdf", &file_path));
+ std::string file_path =
+ PathService::GetTestFilePath("unsupported_feature.pdf");
+ ASSERT_FALSE(file_path.empty());
RecordUnsupportedErrorDelegate delegate;
SetDelegate(&delegate);
@@ -1432,8 +1432,8 @@
ASSERT_TRUE(OpenDocument("empty_xref.pdf"));
EXPECT_TRUE(FPDF_DocumentHasValidCrossReferenceTable(document()));
- std::string file_path;
- ASSERT_TRUE(PathService::GetTestFilePath("empty_xref.pdf", &file_path));
+ std::string file_path = PathService::GetTestFilePath("empty_xref.pdf");
+ ASSERT_FALSE(file_path.empty());
{
ScopedFPDFDocument doc(FPDF_LoadDocument(file_path.c_str(), ""));
ASSERT_TRUE(doc);
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index 80b1578..5c040df 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -328,9 +328,10 @@
const char* password,
LinearizeOption linearize_option,
JavaScriptOption javascript_option) {
- std::string file_path;
- if (!PathService::GetTestFilePath(filename, &file_path))
+ std::string file_path = PathService::GetTestFilePath(filename);
+ if (file_path.empty()) {
return false;
+ }
file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
if (!file_contents_)
diff --git a/testing/utils/file_util.cpp b/testing/utils/file_util.cpp
index 6998f0e..77da127 100644
--- a/testing/utils/file_util.cpp
+++ b/testing/utils/file_util.cpp
@@ -39,9 +39,10 @@
}
FileAccessForTesting::FileAccessForTesting(const std::string& file_name) {
- std::string file_path;
- if (!PathService::GetTestFilePath(file_name, &file_path))
+ std::string file_path = PathService::GetTestFilePath(file_name);
+ if (file_path.empty()) {
return;
+ }
file_contents_ = GetFileContents(file_path.c_str(), &file_length_);
if (!file_contents_)
diff --git a/testing/utils/path_service.cpp b/testing/utils/path_service.cpp
index 01a1bfe..b57f70c 100644
--- a/testing/utils/path_service.cpp
+++ b/testing/utils/path_service.cpp
@@ -157,15 +157,17 @@
}
// static
-bool PathService::GetTestFilePath(const std::string& file_name,
- std::string* path) {
- if (!GetTestDataDir(path))
- return false;
+std::string PathService::GetTestFilePath(const std::string& file_name) {
+ std::string path;
+ if (!GetTestDataDir(&path)) {
+ return std::string();
+ }
- if (!EndsWithSeparator(*path))
- path->push_back(PATH_SEPARATOR);
- path->append(file_name);
- return true;
+ if (!EndsWithSeparator(path)) {
+ path.push_back(PATH_SEPARATOR);
+ }
+ path.append(file_name);
+ return path;
}
// static
diff --git a/testing/utils/path_service.h b/testing/utils/path_service.h
index a6582c3..91f96ec 100644
--- a/testing/utils/path_service.h
+++ b/testing/utils/path_service.h
@@ -36,7 +36,8 @@
static bool GetTestDataDir(std::string* path);
// Get the full path for a test file under the test data directory.
- static bool GetTestFilePath(const std::string& file_name, std::string* path);
+ // Returns an empty string on failure.
+ static std::string GetTestFilePath(const std::string& file_name);
// Get the full path for a file under the third-party directory.
static bool GetThirdPartyFilePath(const std::string& file_name,