pdfium/testing/test_loader.cpp
Lei Zhang 4da226a072 Change GetFileContents() test utility to return a vector
Instead of returning a std::unique_ptr, with a separate out-parameter
for the size, change GetFileContents() to just return a std::vector.
Because it is only used for reading data files in tests,
GetFileContents() should never have to read an empty file. Therefore, it
can use an empty vector to indicate failure, and not have to wrap the
vector in an optional.

Change-Id: I485551e2ed4c47e98f4535cf91bbf6bff1ca99bb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/113452
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
2023-11-10 20:15:43 +00:00

27 lines
786 B
C++

// Copyright 2019 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/test_loader.h"
#include <string.h>
#include "third_party/base/check_op.h"
#include "third_party/base/numerics/checked_math.h"
TestLoader::TestLoader(pdfium::span<const uint8_t> span) : m_Span(span) {}
// static
int TestLoader::GetBlock(void* param,
unsigned long pos,
unsigned char* pBuf,
unsigned long size) {
TestLoader* pLoader = static_cast<TestLoader*>(param);
pdfium::base::CheckedNumeric<size_t> end = pos;
end += size;
CHECK_LE(end.ValueOrDie(), pLoader->m_Span.size());
memcpy(pBuf, &pLoader->m_Span[pos], size);
return 1;
}