From 2b797295d6851b3189bcb38c5994074f36453865 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Thu, 6 Apr 2017 14:45:39 -0700 Subject: Fix unit tests to initialize PartitionAlloc. Tests need to be subclasses of FPDF_Test. BUG=pdfium:700 Change-Id: I317ec2c49567e58cb57c6222e387574226f594b3 Reviewed-on: https://pdfium-review.googlesource.com/3890 Reviewed-by: Tom Sepez Commit-Queue: Chris Palmer --- BUILD.gn | 2 +- core/fxcrt/fx_basic_memmgr.cpp | 10 +++ core/fxcrt/fx_memory.h | 1 + fpdfsdk/fpdfview.cpp | 9 +-- testing/test_support.cpp | 4 +- xfa/fde/css/cfde_cssdeclaration_unittest.cpp | 7 +- xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp | 11 +-- xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp | 33 +++++---- xfa/fxfa/cxfa_ffapp_unitest.cpp | 87 ----------------------- xfa/fxfa/cxfa_ffapp_unittest.cpp | 90 ++++++++++++++++++++++++ xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp | 5 +- xfa/fxfa/parser/xfa_utils_unittest.cpp | 7 +- 12 files changed, 144 insertions(+), 122 deletions(-) delete mode 100644 xfa/fxfa/cxfa_ffapp_unitest.cpp create mode 100644 xfa/fxfa/cxfa_ffapp_unittest.cpp diff --git a/BUILD.gn b/BUILD.gn index 5d8ac0ed7c..6260da50f0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1892,7 +1892,7 @@ test("pdfium_unittests") { "xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp", "xfa/fgas/layout/fgas_rtfbreak_unittest.cpp", "xfa/fxfa/app/cxfa_textparser_unittest.cpp", - "xfa/fxfa/cxfa_ffapp_unitest.cpp", + "xfa/fxfa/cxfa_ffapp_unittest.cpp", "xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp", "xfa/fxfa/parser/xfa_utils_unittest.cpp", ] diff --git a/core/fxcrt/fx_basic_memmgr.cpp b/core/fxcrt/fx_basic_memmgr.cpp index 06568c04ad..f3aaa3678d 100644 --- a/core/fxcrt/fx_basic_memmgr.cpp +++ b/core/fxcrt/fx_basic_memmgr.cpp @@ -11,6 +11,16 @@ pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; +void FXMEM_InitalizePartitionAlloc() { + static bool s_gPartitionAllocatorsInitialized = false; + if (!s_gPartitionAllocatorsInitialized) { + pdfium::base::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate); + gArrayBufferPartitionAllocator.init(); + gStringPartitionAllocator.init(); + s_gPartitionAllocatorsInitialized = true; + } +} + void* FXMEM_DefaultAlloc(size_t byte_size, int flags) { return (void*)malloc(byte_size); } diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index c4d619efab..eb369d7d6c 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -31,6 +31,7 @@ void FXMEM_DefaultFree(void* pointer, int flags); extern pdfium::base::PartitionAllocatorGeneric gArrayBufferPartitionAllocator; extern pdfium::base::PartitionAllocatorGeneric gStringPartitionAllocator; +void FXMEM_InitalizePartitionAlloc(); NEVER_INLINE void FX_OutOfMemoryTerminate(); inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index d94bec688b..0b77676cf9 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -368,14 +368,7 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { if (g_pCodecModule) return; - static bool s_gPartitionAllocatorsInitialized = false; - if (!s_gPartitionAllocatorsInitialized) { - pdfium::base::PartitionAllocGlobalInit(FX_OutOfMemoryTerminate); - gArrayBufferPartitionAllocator.init(); - gStringPartitionAllocator.init(); - s_gPartitionAllocatorsInitialized = true; - } - + FXMEM_InitalizePartitionAlloc(); g_pCodecModule = new CCodec_ModuleMgr(); CFX_GEModule* pModule = CFX_GEModule::Get(); diff --git a/testing/test_support.cpp b/testing/test_support.cpp index 6e1bb64bc0..20f1cadf09 100644 --- a/testing/test_support.cpp +++ b/testing/test_support.cpp @@ -9,6 +9,7 @@ #include +#include "core/fxcrt/fx_memory.h" #include "testing/utils/path_service.h" #ifdef PDF_ENABLE_V8 @@ -214,11 +215,10 @@ int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, namespace pdfium { void FPDF_Test::SetUp() { - FPDF_InitLibrary(); + FXMEM_InitalizePartitionAlloc(); } void FPDF_Test::TearDown() { - FPDF_DestroyLibrary(); } } // namespace pdfium diff --git a/xfa/fde/css/cfde_cssdeclaration_unittest.cpp b/xfa/fde/css/cfde_cssdeclaration_unittest.cpp index 48a3c72c39..80cd72c4d3 100644 --- a/xfa/fde/css/cfde_cssdeclaration_unittest.cpp +++ b/xfa/fde/css/cfde_cssdeclaration_unittest.cpp @@ -5,8 +5,11 @@ #include "xfa/fde/css/cfde_cssdeclaration.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" -TEST(CFDE_CSSDecalration, HexEncodingParsing) { +class CFDE_CSSDecalrationTest : public pdfium::FPDF_Test {}; + +TEST_F(CFDE_CSSDecalrationTest, HexEncodingParsing) { FX_ARGB color; // Length value invalid. @@ -42,7 +45,7 @@ TEST(CFDE_CSSDecalration, HexEncodingParsing) { EXPECT_EQ(60, FXARGB_B(color)); } -TEST(CFDE_CSSDecalration, RGBEncodingParsing) { +TEST_F(CFDE_CSSDecalrationTest, RGBEncodingParsing) { FX_ARGB color; // Invalid input for rgb() syntax. diff --git a/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp b/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp index 2864c842ad..077fb54e93 100644 --- a/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp +++ b/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp @@ -7,9 +7,12 @@ #include "xfa/fde/css/cfde_cssvaluelistparser.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "third_party/base/ptr_util.h" -TEST(CFDE_CSSValueListParser, rgb_short) { +class CFDE_CSSValueListParserTest : public pdfium::FPDF_Test {}; + +TEST_F(CFDE_CSSValueListParserTest, rgb_short) { FDE_CSSPrimitiveType type; const wchar_t* start; int32_t len; @@ -40,7 +43,7 @@ TEST(CFDE_CSSValueListParser, rgb_short) { EXPECT_FALSE(parser->NextValue(type, start, len)); } -TEST(CFDE_CSSValueListParser, number_parsing) { +TEST_F(CFDE_CSSValueListParserTest, number_parsing) { FDE_CSSPrimitiveType type; const wchar_t* start; int32_t len; @@ -82,7 +85,7 @@ TEST(CFDE_CSSValueListParser, number_parsing) { EXPECT_EQ(L"43a1.12.34", CFX_WideString(start, len)); } -TEST(CFDE_CSSValueListParser, string_parsing) { +TEST_F(CFDE_CSSValueListParserTest, string_parsing) { FDE_CSSPrimitiveType type; const wchar_t* start; int32_t len; @@ -105,7 +108,7 @@ TEST(CFDE_CSSValueListParser, string_parsing) { EXPECT_EQ(L"standalone", CFX_WideString(start, len)); } -TEST(CFDE_CSSValueListParser, multiparsing) { +TEST_F(CFDE_CSSValueListParserTest, multiparsing) { FDE_CSSPrimitiveType type; const wchar_t* start; int32_t len; diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp index e54b2cecaf..66f4bbf928 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp +++ b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp @@ -7,9 +7,12 @@ #include #include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" #include "xfa/fgas/crt/ifgas_stream.h" -TEST(CFDE_XMLSyntaxParser, CData) { +class CFDE_XMLSyntaxParserTest : public pdfium::FPDF_Test {}; + +TEST_F(CFDE_XMLSyntaxParserTest, CData) { const wchar_t* input = L"