Lei Zhang | d50bdff | 2019-02-05 19:42:33 +0000 | [diff] [blame] | 1 | // 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 Zhang | b3be4a1 | 2019-02-05 22:11:07 +0000 | [diff] [blame] | 11 | TestLoader::TestLoader(pdfium::span<const char> span) : m_Span(span) {} |
Lei Zhang | d50bdff | 2019-02-05 19:42:33 +0000 | [diff] [blame] | 12 | |
| 13 | // static |
| 14 | int TestLoader::GetBlock(void* param, |
| 15 | unsigned long pos, |
| 16 | unsigned char* pBuf, |
| 17 | unsigned long size) { |
| 18 | TestLoader* pLoader = static_cast<TestLoader*>(param); |
Lei Zhang | b3be4a1 | 2019-02-05 22:11:07 +0000 | [diff] [blame] | 19 | if (pos + size < pos || pos + size > pLoader->m_Span.size()) { |
Lei Zhang | d50bdff | 2019-02-05 19:42:33 +0000 | [diff] [blame] | 20 | NOTREACHED(); |
| 21 | return 0; |
| 22 | } |
| 23 | |
Lei Zhang | b3be4a1 | 2019-02-05 22:11:07 +0000 | [diff] [blame] | 24 | memcpy(pBuf, &pLoader->m_Span[pos], size); |
Lei Zhang | d50bdff | 2019-02-05 19:42:33 +0000 | [diff] [blame] | 25 | return 1; |
| 26 | } |