Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 1 | // 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 Sinclair | c7cd809 | 2016-02-18 15:02:55 -0500 | [diff] [blame] | 5 | #ifndef TESTING_TEST_SUPPORT_H_ |
| 6 | #define TESTING_TEST_SUPPORT_H_ |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 7 | |
| 8 | #include <stdlib.h> |
Lei Zhang | 9a25ede | 2017-06-22 00:05:12 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 10 | #include <memory> |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 11 | #include <string> |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 12 | #include <vector> |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 13 | |
Dan Sinclair | 61046b9 | 2016-02-18 14:48:48 -0500 | [diff] [blame] | 14 | #include "public/fpdfview.h" |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 15 | |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 16 | #if PDF_ENABLE_XFA |
| 17 | #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 18 | #endif // PDF_ENABLE_XFA |
| 19 | |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 20 | namespace pdfium { |
| 21 | |
Wei Li | 970c11e | 2016-02-16 14:26:22 -0800 | [diff] [blame] | 22 | #define STR_IN_TEST_CASE(input_literal, ...) \ |
| 23 | { \ |
| 24 | (const unsigned char*) input_literal, sizeof(input_literal) - 1, \ |
| 25 | __VA_ARGS__ \ |
| 26 | } |
| 27 | |
Wei Li | 4f7f4ee | 2016-02-16 12:52:14 -0800 | [diff] [blame] | 28 | #define STR_IN_OUT_CASE(input_literal, expected_literal, ...) \ |
Wei Li | 0db9009 | 2016-02-09 11:38:47 -0800 | [diff] [blame] | 29 | { \ |
| 30 | (const unsigned char*) input_literal, sizeof(input_literal) - 1, \ |
| 31 | (const unsigned char*)expected_literal, sizeof(expected_literal) - 1, \ |
Wei Li | 4f7f4ee | 2016-02-16 12:52:14 -0800 | [diff] [blame] | 32 | __VA_ARGS__ \ |
Wei Li | 0db9009 | 2016-02-09 11:38:47 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | struct StrFuncTestData { |
| 36 | const unsigned char* input; |
| 37 | unsigned int input_size; |
| 38 | const unsigned char* expected; |
| 39 | unsigned int expected_size; |
| 40 | }; |
| 41 | |
| 42 | struct DecodeTestData { |
| 43 | const unsigned char* input; |
| 44 | unsigned int input_size; |
| 45 | const unsigned char* expected; |
| 46 | unsigned int expected_size; |
| 47 | // The size of input string being processed. |
| 48 | unsigned int processed_size; |
| 49 | }; |
| 50 | |
Wei Li | 65b3655 | 2016-02-18 14:04:57 -0800 | [diff] [blame] | 51 | struct NullTermWstrFuncTestData { |
| 52 | const wchar_t* input; |
| 53 | const wchar_t* expected; |
| 54 | }; |
| 55 | |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 56 | // Used with std::unique_ptr to free() objects that can't be deleted. |
| 57 | struct FreeDeleter { |
| 58 | inline void operator()(void* ptr) const { free(ptr); } |
| 59 | }; |
| 60 | |
| 61 | } // namespace pdfium |
| 62 | |
| 63 | // Reads the entire contents of a file into a newly alloc'd buffer. |
| 64 | std::unique_ptr<char, pdfium::FreeDeleter> GetFileContents(const char* filename, |
| 65 | size_t* retlen); |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 66 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 67 | std::vector<std::string> StringSplit(const std::string& str, char delimiter); |
| 68 | |
Jane Liu | 4442d45 | 2017-07-19 10:19:42 -0400 | [diff] [blame] | 69 | // Converts a FPDF_WIDESTRING to a std::string. |
| 70 | // Deals with differences between UTF16LE and UTF8. |
| 71 | std::string GetPlatformString(FPDF_WIDESTRING wstr); |
| 72 | |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 73 | // Converts a FPDF_WIDESTRING to a std::wstring. |
| 74 | // Deals with differences between UTF16LE and wchar_t. |
Lei Zhang | 54d91ec | 2017-06-16 19:08:02 -0700 | [diff] [blame] | 75 | std::wstring GetPlatformWString(FPDF_WIDESTRING wstr); |
Tom Sepez | 8ab45ea | 2016-01-05 10:17:30 -0800 | [diff] [blame] | 76 | |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 77 | // Returns a newly allocated FPDF_WIDESTRING. |
Tom Sepez | 8ab45ea | 2016-01-05 10:17:30 -0800 | [diff] [blame] | 78 | // Deals with differences between UTF16LE and wchar_t. |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 79 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString( |
| 80 | const std::wstring& wstr); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 81 | |
Lei Zhang | d9e0e6e | 2017-04-28 16:54:10 -0700 | [diff] [blame] | 82 | std::string CryptToBase16(const uint8_t* digest); |
| 83 | std::string GenerateMD5Base16(const uint8_t* data, uint32_t size); |
| 84 | |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 85 | #ifdef PDF_ENABLE_V8 |
Lei Zhang | 9a25ede | 2017-06-22 00:05:12 -0700 | [diff] [blame] | 86 | namespace v8 { |
| 87 | class Platform; |
| 88 | } |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 89 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
Lei Zhang | 9a25ede | 2017-06-22 00:05:12 -0700 | [diff] [blame] | 90 | namespace v8 { |
| 91 | class StartupData; |
| 92 | } |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 93 | bool InitializeV8ForPDFium(const std::string& exe_path, |
| 94 | const std::string& bin_dir, |
| 95 | v8::StartupData* natives_blob, |
| 96 | v8::StartupData* snapshot_blob, |
| 97 | v8::Platform** platform); |
| 98 | #else // V8_USE_EXTERNAL_STARTUP_DATA |
jochen | 9e077d2 | 2016-06-09 02:51:13 -0700 | [diff] [blame] | 99 | bool InitializeV8ForPDFium(const std::string& exe_path, |
| 100 | v8::Platform** platform); |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 101 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 102 | #endif // PDF_ENABLE_V8 |
| 103 | |
| 104 | class TestLoader { |
| 105 | public: |
| 106 | TestLoader(const char* pBuf, size_t len); |
| 107 | static int GetBlock(void* param, |
| 108 | unsigned long pos, |
| 109 | unsigned char* pBuf, |
| 110 | unsigned long size); |
| 111 | |
| 112 | private: |
| 113 | const char* const m_pBuf; |
| 114 | const size_t m_Len; |
| 115 | }; |
| 116 | |
Dan Sinclair | 574d440 | 2017-08-28 10:11:24 -0400 | [diff] [blame] | 117 | #if PDF_ENABLE_XFA |
| 118 | CFGAS_FontMgr* GetGlobalFontManager(); |
| 119 | #endif // PDF_ENABLE_XFA |
| 120 | |
Dan Sinclair | c7cd809 | 2016-02-18 15:02:55 -0500 | [diff] [blame] | 121 | #endif // TESTING_TEST_SUPPORT_H_ |