diff options
Diffstat (limited to 'xfa/fde/xml')
-rw-r--r-- | xfa/fde/xml/fde_xml_imp.cpp | 10 | ||||
-rw-r--r-- | xfa/fde/xml/fde_xml_imp.h | 13 | ||||
-rw-r--r-- | xfa/fde/xml/fde_xml_imp_unittest.cpp | 165 |
3 files changed, 88 insertions, 100 deletions
diff --git a/xfa/fde/xml/fde_xml_imp.cpp b/xfa/fde/xml/fde_xml_imp.cpp index 1fbb1cdda7..f333b4fcda 100644 --- a/xfa/fde/xml/fde_xml_imp.cpp +++ b/xfa/fde/xml/fde_xml_imp.cpp @@ -394,7 +394,7 @@ CFDE_XMLNode* CFDE_XMLNode::Clone(bool bRecursive) { return nullptr; } -void CFDE_XMLNode::SaveXMLNode(IFGAS_Stream* pXMLStream) { +void CFDE_XMLNode::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream) { CFDE_XMLNode* pNode = (CFDE_XMLNode*)this; switch (pNode->GetType()) { case FDE_XMLNODE_Instruction: { @@ -986,7 +986,8 @@ void CFDE_XMLDoc::CloseXML() { ReleaseParser(); } -void CFDE_XMLDoc::SaveXMLNode(IFGAS_Stream* pXMLStream, CFDE_XMLNode* pINode) { +void CFDE_XMLDoc::SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream, + CFDE_XMLNode* pINode) { CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; switch (pNode->GetType()) { case FDE_XMLNODE_Instruction: { @@ -1096,7 +1097,8 @@ void CFDE_XMLDoc::SaveXMLNode(IFGAS_Stream* pXMLStream, CFDE_XMLNode* pINode) { } } -void CFDE_XMLDoc::SaveXML(IFGAS_Stream* pXMLStream, bool bSaveBOM) { +void CFDE_XMLDoc::SaveXML(CFX_RetainPtr<IFGAS_Stream>& pXMLStream, + bool bSaveBOM) { if (!pXMLStream || pXMLStream == m_pStream) { m_pStream->Seek(FX_STREAMSEEK_Begin, 0); pXMLStream = m_pStream; @@ -1288,7 +1290,7 @@ CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() m_CurNode.eNodeType = FDE_XMLNODE_Unknown; } -void CFDE_XMLSyntaxParser::Init(IFGAS_Stream* pStream, +void CFDE_XMLSyntaxParser::Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, int32_t iXMLPlaneSize, int32_t iTextDataSize) { ASSERT(!m_pStream && !m_pBuffer); diff --git a/xfa/fde/xml/fde_xml_imp.h b/xfa/fde/xml/fde_xml_imp.h index 924f958b86..283184aadc 100644 --- a/xfa/fde/xml/fde_xml_imp.h +++ b/xfa/fde/xml/fde_xml_imp.h @@ -63,7 +63,7 @@ class CFDE_XMLNode : public CFX_Target { bool InsertNodeItem(CFDE_XMLNode::NodeItem eItem, CFDE_XMLNode* pNode); CFDE_XMLNode* RemoveNodeItem(CFDE_XMLNode::NodeItem eItem); - void SaveXMLNode(IFGAS_Stream* pXMLStream); + void SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream); CFDE_XMLNode* m_pParent; CFDE_XMLNode* m_pChild; @@ -197,14 +197,15 @@ class CFDE_XMLDoc : public CFX_Target { int32_t DoLoad(IFX_Pause* pPause = nullptr); void CloseXML(); CFDE_XMLNode* GetRoot() const { return m_pRoot; } - void SaveXML(IFGAS_Stream* pXMLStream = nullptr, bool bSaveBOM = true); - void SaveXMLNode(IFGAS_Stream* pXMLStream, CFDE_XMLNode* pNode); + void SaveXML(CFX_RetainPtr<IFGAS_Stream>& pXMLStream, bool bSaveBOM = true); + void SaveXMLNode(const CFX_RetainPtr<IFGAS_Stream>& pXMLStream, + CFDE_XMLNode* pNode); protected: void Reset(bool bInitRoot); void ReleaseParser(); - IFGAS_Stream* m_pStream; + CFX_RetainPtr<IFGAS_Stream> m_pStream; int32_t m_iStatus; CFDE_XMLNode* m_pRoot; CFDE_XMLSyntaxParser* m_pSyntaxParser; @@ -261,7 +262,7 @@ class CFDE_XMLSyntaxParser : public CFX_Target { ~CFDE_XMLSyntaxParser() override; void Release() { delete this; } - void Init(IFGAS_Stream* pStream, + void Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, int32_t iXMLPlaneSize, int32_t iTextDataSize = 256); @@ -320,7 +321,7 @@ class CFDE_XMLSyntaxParser : public CFX_Target { void ParseTextChar(FX_WCHAR ch); - IFGAS_Stream* m_pStream; + CFX_RetainPtr<IFGAS_Stream> m_pStream; int32_t m_iXMLPlaneSize; int32_t m_iCurrentPos; int32_t m_iCurrentNodeNum; diff --git a/xfa/fde/xml/fde_xml_imp_unittest.cpp b/xfa/fde/xml/fde_xml_imp_unittest.cpp index 553afffd86..6db1b1905a 100644 --- a/xfa/fde/xml/fde_xml_imp_unittest.cpp +++ b/xfa/fde/xml/fde_xml_imp_unittest.cpp @@ -26,15 +26,14 @@ TEST(CFDE_XMLSyntaxParser, CData) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -84,15 +83,14 @@ TEST(CFDE_XMLSyntaxParser, CDataWithInnerScript) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -131,15 +129,14 @@ TEST(CFDE_XMLSyntaxParser, ArrowBangArrow) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -174,15 +171,14 @@ TEST(CFDE_XMLSyntaxParser, ArrowBangBracketArrow) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -211,15 +207,14 @@ TEST(CFDE_XMLSyntaxParser, IncompleteCData) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -248,15 +243,14 @@ TEST(CFDE_XMLSyntaxParser, UnClosedCData) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -285,15 +279,14 @@ TEST(CFDE_XMLSyntaxParser, EmptyCData) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -332,15 +325,14 @@ TEST(CFDE_XMLSyntaxParser, Comment) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -375,15 +367,14 @@ TEST(CFDE_XMLSyntaxParser, IncorrectCommentStart) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -418,15 +409,14 @@ TEST(CFDE_XMLSyntaxParser, CommentEmpty) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -461,15 +451,14 @@ TEST(CFDE_XMLSyntaxParser, CommentThreeDash) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -496,15 +485,14 @@ TEST(CFDE_XMLSyntaxParser, CommentTwoDash) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -535,15 +523,14 @@ TEST(CFDE_XMLSyntaxParser, Entities) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -575,15 +562,14 @@ TEST(CFDE_XMLSyntaxParser, EntityOverflowHex) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); @@ -615,15 +601,14 @@ TEST(CFDE_XMLSyntaxParser, EntityOverflowDecimal) { // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); - std::unique_ptr<IFGAS_Stream> stream(IFGAS_Stream::CreateStream( - reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); + CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( + reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0); CFDE_XMLSyntaxParser parser; - parser.Init(stream.get(), 256); - - CFX_WideString data; - + parser.Init(stream, 256); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); + + CFX_WideString data; parser.GetTagName(data); EXPECT_EQ(L"script", data); |