blob: 33ee331e7b48d315fe6826a4c2fd61e6f5b7e61f [file] [log] [blame]
Lei Zhangd50bdff2019-02-05 19:42:33 +00001// Copyright 2019 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/test_loader.h"
6
7#include <string.h>
8
9#include "third_party/base/logging.h"
10
Lei Zhangb3be4a12019-02-05 22:11:07 +000011TestLoader::TestLoader(pdfium::span<const char> span) : m_Span(span) {}
Lei Zhangd50bdff2019-02-05 19:42:33 +000012
13// static
14int TestLoader::GetBlock(void* param,
15 unsigned long pos,
16 unsigned char* pBuf,
17 unsigned long size) {
18 TestLoader* pLoader = static_cast<TestLoader*>(param);
Lei Zhangb3be4a12019-02-05 22:11:07 +000019 if (pos + size < pos || pos + size > pLoader->m_Span.size()) {
Lei Zhangd50bdff2019-02-05 19:42:33 +000020 NOTREACHED();
21 return 0;
22 }
23
Lei Zhangb3be4a12019-02-05 22:11:07 +000024 memcpy(pBuf, &pLoader->m_Span[pos], size);
Lei Zhangd50bdff2019-02-05 19:42:33 +000025 return 1;
26}