From 63593d32415a2abe14b67a9b0bbb5051e3f7c408 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 17 Apr 2018 18:24:09 +0000 Subject: Cleanup some seekablestreamproxy code This CL fixes up some cfx_seekablestreamproxy includes and adds a helper to the xmlparser tests. Change-Id: If1b67dee51b49fa39527274f6c68da5ec673704f Reviewed-on: https://pdfium-review.googlesource.com/30854 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/css/cfx_css.h | 1 - core/fxcrt/xml/cfx_xmlparser_unittest.cpp | 101 ++++++++---------------------- testing/libfuzzer/pdf_css_fuzzer.cc | 1 - xfa/fgas/font/cfgas_fontmgr.h | 1 - xfa/fgas/font/cfgas_gefont.h | 1 + 5 files changed, 27 insertions(+), 78 deletions(-) diff --git a/core/fxcrt/css/cfx_css.h b/core/fxcrt/css/cfx_css.h index 32f376f327..e9ff722d08 100644 --- a/core/fxcrt/css/cfx_css.h +++ b/core/fxcrt/css/cfx_css.h @@ -7,7 +7,6 @@ #ifndef CORE_FXCRT_CSS_CFX_CSS_H_ #define CORE_FXCRT_CSS_CFX_CSS_H_ -#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxge/fx_dib.h" enum CFX_CSSVALUETYPE { diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp index 39ddc32987..97a81f7640 100644 --- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp +++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp @@ -13,6 +13,8 @@ #include "testing/test_support.h" #include "third_party/base/ptr_util.h" +namespace { + class CFX_XMLTestParser : public CFX_XMLParser { public: CFX_XMLTestParser(CFX_XMLNode* pParent, @@ -36,6 +38,15 @@ class CFX_XMLTestParser : public CFX_XMLParser { WideString GetTextData() const { return CFX_XMLParser::GetTextData(); } }; +RetainPtr MakeProxy(const char* input) { + auto stream = pdfium::MakeRetain( + reinterpret_cast(const_cast(input)), strlen(input)); + stream->SetCodePage(FX_CODEPAGE_UTF8); + return stream; +} + +} // namespace + TEST(CFX_XMLParserTest, CData) { const char* input = "\n" L" "; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -138,11 +141,7 @@ TEST(CFX_XMLParserTest, ArrowBangArrow) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -174,11 +173,7 @@ TEST(CFX_XMLParserTest, ArrowBangBracketArrow) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -205,11 +200,7 @@ TEST(CFX_XMLParserTest, IncompleteCData) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -236,11 +227,7 @@ TEST(CFX_XMLParserTest, UnClosedCData) { " "; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -267,11 +254,7 @@ TEST(CFX_XMLParserTest, EmptyCData) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -305,11 +288,7 @@ TEST(CFX_XMLParserTest, Comment) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -340,11 +319,7 @@ TEST(CFX_XMLParserTest, IncorrectCommentStart) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -375,11 +350,7 @@ TEST(CFX_XMLParserTest, CommentEmpty) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -410,11 +381,7 @@ TEST(CFX_XMLParserTest, CommentThreeDash) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -439,11 +406,7 @@ TEST(CFX_XMLParserTest, CommentTwoDash) { " \n" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -472,11 +435,7 @@ TEST(CFX_XMLParserTest, Entities) { "�" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -505,11 +464,7 @@ TEST(CFX_XMLParserTest, EntityOverflowHex) { "�" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); @@ -538,11 +493,7 @@ TEST(CFX_XMLParserTest, EntityOverflowDecimal) { "�" ""; - RetainPtr stream = - pdfium::MakeRetain( - reinterpret_cast(const_cast(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - + auto stream = MakeProxy(input); auto root = pdfium::MakeUnique(); CFX_XMLTestParser parser(root.get(), stream); ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); diff --git a/testing/libfuzzer/pdf_css_fuzzer.cc b/testing/libfuzzer/pdf_css_fuzzer.cc index 7cd924e70f..4f2f410aa3 100644 --- a/testing/libfuzzer/pdf_css_fuzzer.cc +++ b/testing/libfuzzer/pdf_css_fuzzer.cc @@ -4,7 +4,6 @@ #include -#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/css/cfx_css.h" #include "core/fxcrt/css/cfx_csssyntaxparser.h" #include "core/fxcrt/fx_string.h" diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index f4a62847d6..f082b02dd3 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -14,7 +14,6 @@ #include #include -#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/observable.h" #include "core/fxcrt/retain_ptr.h" diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index 22169d6d3d..2e70fb662f 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -12,6 +12,7 @@ #include #include +#include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" -- cgit v1.2.3