blob: feec4bbe0b99739d712476c8231d12c5faba2249 [file] [log] [blame]
Tom Sepezd831dc72015-10-19 16:04:22 -07001// Copyright 2015 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
Dan Sinclairc7cd8092016-02-18 15:02:55 -05005#ifndef TESTING_TEST_SUPPORT_H_
6#define TESTING_TEST_SUPPORT_H_
Tom Sepezd831dc72015-10-19 16:04:22 -07007
8#include <stdlib.h>
Lei Zhang9a25ede2017-06-22 00:05:12 -07009
Tom Sepez0aa35312016-01-06 10:16:32 -080010#include <memory>
Tom Sepezd831dc72015-10-19 16:04:22 -070011#include <string>
tsepezf09bdfa2016-04-18 16:08:26 -070012#include <vector>
Tom Sepezd831dc72015-10-19 16:04:22 -070013
Dan Sinclair61046b92016-02-18 14:48:48 -050014#include "public/fpdfview.h"
Tom Sepezd831dc72015-10-19 16:04:22 -070015
Tom Sepez0aa35312016-01-06 10:16:32 -080016namespace pdfium {
17
Wei Li970c11e2016-02-16 14:26:22 -080018#define STR_IN_TEST_CASE(input_literal, ...) \
19 { \
20 (const unsigned char*) input_literal, sizeof(input_literal) - 1, \
21 __VA_ARGS__ \
22 }
23
Wei Li4f7f4ee2016-02-16 12:52:14 -080024#define STR_IN_OUT_CASE(input_literal, expected_literal, ...) \
Wei Li0db90092016-02-09 11:38:47 -080025 { \
26 (const unsigned char*) input_literal, sizeof(input_literal) - 1, \
27 (const unsigned char*)expected_literal, sizeof(expected_literal) - 1, \
Wei Li4f7f4ee2016-02-16 12:52:14 -080028 __VA_ARGS__ \
Wei Li0db90092016-02-09 11:38:47 -080029 }
30
31struct StrFuncTestData {
32 const unsigned char* input;
33 unsigned int input_size;
34 const unsigned char* expected;
35 unsigned int expected_size;
36};
37
38struct DecodeTestData {
39 const unsigned char* input;
40 unsigned int input_size;
41 const unsigned char* expected;
42 unsigned int expected_size;
43 // The size of input string being processed.
44 unsigned int processed_size;
45};
46
Wei Li65b36552016-02-18 14:04:57 -080047struct NullTermWstrFuncTestData {
48 const wchar_t* input;
49 const wchar_t* expected;
50};
51
Tom Sepez0aa35312016-01-06 10:16:32 -080052// Used with std::unique_ptr to free() objects that can't be deleted.
53struct FreeDeleter {
54 inline void operator()(void* ptr) const { free(ptr); }
55};
56
57} // namespace pdfium
58
59// Reads the entire contents of a file into a newly alloc'd buffer.
60std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename,
61 size_t* retlen);
Tom Sepezd831dc72015-10-19 16:04:22 -070062
tsepezf09bdfa2016-04-18 16:08:26 -070063std::vector<std::string> StringSplit(const std::string& str, char delimiter);
64
Jane Liu4442d452017-07-19 10:19:42 -040065// Converts a FPDF_WIDESTRING to a std::string.
66// Deals with differences between UTF16LE and UTF8.
67std::string GetPlatformString(FPDF_WIDESTRING wstr);
68
Lei Zhang79e893a2015-11-04 16:02:47 -080069// Converts a FPDF_WIDESTRING to a std::wstring.
70// Deals with differences between UTF16LE and wchar_t.
Lei Zhang54d91ec2017-06-16 19:08:02 -070071std::wstring GetPlatformWString(FPDF_WIDESTRING wstr);
Tom Sepez8ab45ea2016-01-05 10:17:30 -080072
Tom Sepez0aa35312016-01-06 10:16:32 -080073// Returns a newly allocated FPDF_WIDESTRING.
Tom Sepez8ab45ea2016-01-05 10:17:30 -080074// Deals with differences between UTF16LE and wchar_t.
Tom Sepez0aa35312016-01-06 10:16:32 -080075std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString(
76 const std::wstring& wstr);
Lei Zhang79e893a2015-11-04 16:02:47 -080077
Lei Zhangd9e0e6e2017-04-28 16:54:10 -070078std::string CryptToBase16(const uint8_t* digest);
79std::string GenerateMD5Base16(const uint8_t* data, uint32_t size);
80
Tom Sepezd831dc72015-10-19 16:04:22 -070081#ifdef PDF_ENABLE_V8
Lei Zhang9a25ede2017-06-22 00:05:12 -070082namespace v8 {
83class Platform;
84}
Tom Sepezd831dc72015-10-19 16:04:22 -070085#ifdef V8_USE_EXTERNAL_STARTUP_DATA
Lei Zhang9a25ede2017-06-22 00:05:12 -070086namespace v8 {
87class StartupData;
88}
Tom Sepezd831dc72015-10-19 16:04:22 -070089bool InitializeV8ForPDFium(const std::string& exe_path,
90 const std::string& bin_dir,
91 v8::StartupData* natives_blob,
92 v8::StartupData* snapshot_blob,
93 v8::Platform** platform);
94#else // V8_USE_EXTERNAL_STARTUP_DATA
jochen9e077d22016-06-09 02:51:13 -070095bool InitializeV8ForPDFium(const std::string& exe_path,
96 v8::Platform** platform);
Tom Sepezd831dc72015-10-19 16:04:22 -070097#endif // V8_USE_EXTERNAL_STARTUP_DATA
98#endif // PDF_ENABLE_V8
99
100class TestLoader {
101 public:
102 TestLoader(const char* pBuf, size_t len);
103 static int GetBlock(void* param,
104 unsigned long pos,
105 unsigned char* pBuf,
106 unsigned long size);
107
108 private:
109 const char* const m_pBuf;
110 const size_t m_Len;
111};
112
Dan Sinclairc7cd8092016-02-18 15:02:55 -0500113#endif // TESTING_TEST_SUPPORT_H_