summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-02 18:08:46 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-02 18:08:46 +0000
commit303f9a3afc4a86147213d4ac57894480485090a2 (patch)
treed19d2167cf305ee52d72f5dd5c74820889c481e4 /core/fxcrt/xml
parent8f893b69012d4f5029cfedf91c5ef653717257a8 (diff)
downloadpdfium-303f9a3afc4a86147213d4ac57894480485090a2.tar.xz
[xml] Simplify the CFX_XMLParser parse methods
This CL moves the switch from CFX_XMLParse::Parse into CFX_XMLParser::DoSyntaxParse. This means all the work to build the tree is now done in one place instead of spread between the two methods. Change-Id: Ie9c6cd67795c3fcbd3e305187a06cd727d386a7c Reviewed-on: https://pdfium-review.googlesource.com/31950 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/xml')
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp250
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.h27
-rw-r--r--core/fxcrt/xml/cfx_xmlparser_unittest.cpp566
3 files changed, 255 insertions, 588 deletions
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index b484660f1f..7a571e38b0 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -74,14 +74,6 @@ CFX_XMLParser::CFX_XMLParser(const RetainPtr<IFX_SeekableReadStream>& pStream) {
std::min(m_iXMLPlaneSize,
pdfium::base::checked_cast<size_t>(m_pStream->GetSize()));
- FX_SAFE_SIZE_T alloc_size_safe = m_iXMLPlaneSize;
- alloc_size_safe += 1; // For NUL.
- if (!alloc_size_safe.IsValid() || alloc_size_safe.ValueOrDie() <= 0) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return;
- }
-
- m_Buffer.resize(pdfium::base::ValueOrDieForType<size_t>(alloc_size_safe));
current_text_.reserve(kCurrentTextReserve);
}
@@ -91,110 +83,28 @@ std::unique_ptr<CFX_XMLDocument> CFX_XMLParser::Parse() {
auto doc = pdfium::MakeUnique<CFX_XMLDocument>();
current_node_ = doc->GetRoot();
- int32_t iCount = 0;
- while (true) {
- FX_XmlSyntaxResult result = DoSyntaxParse();
- if (result == FX_XmlSyntaxResult::Error)
- return nullptr;
- if (result == FX_XmlSyntaxResult::EndOfString)
- break;
-
- switch (result) {
- case FX_XmlSyntaxResult::InstructionClose:
- if (current_node_ && current_node_->GetType() == FX_XMLNODE_Instruction)
- current_node_ = current_node_->GetParent();
- break;
- case FX_XmlSyntaxResult::ElementClose: {
- if (current_node_->GetType() != FX_XMLNODE_Element)
- return nullptr;
-
- WideString element_name = GetTextData();
- if (element_name.GetLength() > 0 &&
- element_name !=
- static_cast<CFX_XMLElement*>(current_node_)->GetName()) {
- return nullptr;
- }
+ FX_SAFE_SIZE_T alloc_size_safe = m_iXMLPlaneSize;
+ alloc_size_safe += 1; // For NUL.
+ if (!alloc_size_safe.IsValid() || alloc_size_safe.ValueOrDie() <= 0)
+ return nullptr;
- current_node_ = current_node_->GetParent();
- iCount++;
- break;
- }
- case FX_XmlSyntaxResult::TargetName: {
- WideString target_name = GetTextData();
- if (target_name == L"originalXFAVersion" || target_name == L"acrobat") {
- auto* node = doc->CreateNode<CFX_XMLInstruction>(target_name);
- current_node_->AppendChild(node);
- current_node_ = node;
- }
- break;
- }
- case FX_XmlSyntaxResult::TagName: {
- auto* child = doc->CreateNode<CFX_XMLElement>(GetTextData());
- current_node_->AppendChild(child);
- current_node_ = child;
- break;
- }
- case FX_XmlSyntaxResult::AttriName: {
- current_attribute_name_ = GetTextData();
- break;
- }
- case FX_XmlSyntaxResult::AttriValue:
- if (current_node_ && current_node_->GetType() == FX_XMLNODE_Element) {
- static_cast<CFX_XMLElement*>(current_node_)
- ->SetAttribute(current_attribute_name_, GetTextData());
- }
- current_attribute_name_.clear();
- break;
- case FX_XmlSyntaxResult::Text: {
- current_node_->AppendChild(doc->CreateNode<CFX_XMLText>(GetTextData()));
- break;
- }
- case FX_XmlSyntaxResult::CData: {
- current_node_->AppendChild(
- doc->CreateNode<CFX_XMLCharData>(GetTextData()));
- break;
- }
- case FX_XmlSyntaxResult::TargetData: {
- WideString target_data = GetTextData();
- if (current_node_ &&
- current_node_->GetType() == FX_XMLNODE_Instruction) {
- if (target_data.IsEmpty())
- break;
- static_cast<CFX_XMLInstruction*>(current_node_)
- ->AppendData(target_data);
- }
- break;
- }
- case FX_XmlSyntaxResult::ElementOpen:
- case FX_XmlSyntaxResult::ElementBreak:
- case FX_XmlSyntaxResult::InstructionOpen:
- default:
- break;
- }
- }
- return doc;
-}
+ m_Buffer.resize(pdfium::base::ValueOrDieForType<size_t>(alloc_size_safe));
-FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
- if (m_syntaxParserResult == FX_XmlSyntaxResult::Error ||
- m_syntaxParserResult == FX_XmlSyntaxResult::EndOfString) {
- return m_syntaxParserResult;
- }
+ return DoSyntaxParse(doc.get()) ? std::move(doc) : nullptr;
+}
- FX_XmlSyntaxResult syntaxParserResult = FX_XmlSyntaxResult::None;
+bool CFX_XMLParser::DoSyntaxParse(CFX_XMLDocument* doc) {
+ int32_t iCount = 0;
while (true) {
if (m_Start >= m_End) {
- if (m_pStream->IsEOF()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString;
- return m_syntaxParserResult;
- }
+ if (m_pStream->IsEOF())
+ return true;
size_t buffer_chars =
m_pStream->ReadBlock(m_Buffer.data(), m_iXMLPlaneSize);
- if (buffer_chars == 0) {
- m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString;
- return m_syntaxParserResult;
- }
+ if (buffer_chars == 0)
+ return true;
+
m_Start = 0;
m_End = buffer_chars;
}
@@ -205,7 +115,8 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
case FDE_XmlSyntaxState::Text:
if (ch == L'<') {
if (!current_text_.empty()) {
- syntaxParserResult = FX_XmlSyntaxResult::Text;
+ current_node_->AppendChild(
+ doc->CreateNode<CFX_XMLText>(GetTextData()));
} else {
m_Start++;
m_syntaxParserState = FDE_XmlSyntaxState::Node;
@@ -225,22 +136,25 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
m_XMLNodeTypeStack.push(FX_XMLNODE_Instruction);
m_Start++;
m_syntaxParserState = FDE_XmlSyntaxState::Target;
- syntaxParserResult = FX_XmlSyntaxResult::InstructionOpen;
} else {
m_XMLNodeTypeStack.push(FX_XMLNODE_Element);
m_syntaxParserState = FDE_XmlSyntaxState::Tag;
- syntaxParserResult = FX_XmlSyntaxResult::ElementOpen;
}
break;
case FDE_XmlSyntaxState::Target:
if (!IsXMLNameChar(ch, current_text_.empty())) {
- if (current_text_.empty()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
- }
+ if (current_text_.empty())
+ return false;
- syntaxParserResult = FX_XmlSyntaxResult::TargetName;
m_syntaxParserState = FDE_XmlSyntaxState::TargetData;
+
+ WideString target_name = GetTextData();
+ if (target_name == L"originalXFAVersion" ||
+ target_name == L"acrobat") {
+ auto* node = doc->CreateNode<CFX_XMLInstruction>(target_name);
+ current_node_->AppendChild(node);
+ current_node_ = node;
+ }
} else {
current_text_.push_back(ch);
m_Start++;
@@ -248,13 +162,14 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
break;
case FDE_XmlSyntaxState::Tag:
if (!IsXMLNameChar(ch, current_text_.empty())) {
- if (current_text_.empty()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
- }
+ if (current_text_.empty())
+ return false;
- syntaxParserResult = FX_XmlSyntaxResult::TagName;
m_syntaxParserState = FDE_XmlSyntaxState::AttriName;
+
+ auto* child = doc->CreateNode<CFX_XMLElement>(GetTextData());
+ current_node_->AppendChild(child);
+ current_node_ = child;
} else {
current_text_.push_back(ch);
m_Start++;
@@ -281,8 +196,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
}
break;
}
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
} else {
if (m_XMLNodeTypeStack.top() == FX_XMLNODE_Instruction) {
if (ch != '=' && !IsXMLWhiteSpace(ch)) {
@@ -291,7 +205,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
}
}
m_syntaxParserState = FDE_XmlSyntaxState::AttriEqualSign;
- syntaxParserResult = FX_XmlSyntaxResult::AttriName;
+ current_attribute_name_ = GetTextData();
}
} else {
current_text_.push_back(ch);
@@ -308,8 +222,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
m_syntaxParserState = FDE_XmlSyntaxState::TargetData;
break;
}
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
} else {
m_syntaxParserState = FDE_XmlSyntaxState::AttriQuotation;
m_Start++;
@@ -321,8 +234,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
break;
}
if (ch != L'\"' && ch != L'\'') {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
}
m_wQuotationMark = ch;
@@ -331,14 +243,19 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
break;
case FDE_XmlSyntaxState::AttriValue:
if (ch == m_wQuotationMark) {
- if (m_iEntityStart > -1) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
- }
+ if (m_iEntityStart > -1)
+ return false;
+
m_wQuotationMark = 0;
m_Start++;
m_syntaxParserState = FDE_XmlSyntaxState::AttriName;
- syntaxParserResult = FX_XmlSyntaxResult::AttriValue;
+
+ if (current_node_ &&
+ current_node_->GetType() == FX_XMLNODE_Element) {
+ static_cast<CFX_XMLElement*>(current_node_)
+ ->SetAttribute(current_attribute_name_, GetTextData());
+ }
+ current_attribute_name_.clear();
} else {
ProcessTextChar(ch);
}
@@ -348,45 +265,53 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
current_text_.push_back(ch);
m_syntaxParserState = FDE_XmlSyntaxState::TargetData;
} else if (!current_text_.empty()) {
- syntaxParserResult = FX_XmlSyntaxResult::TargetData;
+ ProcessTargetData();
} else {
m_Start++;
- if (m_XMLNodeTypeStack.empty()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
- }
- m_XMLNodeTypeStack.pop();
+ if (m_XMLNodeTypeStack.empty())
+ return false;
+ m_XMLNodeTypeStack.pop();
m_syntaxParserState = FDE_XmlSyntaxState::Text;
- syntaxParserResult = FX_XmlSyntaxResult::InstructionClose;
+
+ if (current_node_ &&
+ current_node_->GetType() == FX_XMLNODE_Instruction)
+ current_node_ = current_node_->GetParent();
}
break;
case FDE_XmlSyntaxState::BreakElement:
if (ch == L'>') {
m_syntaxParserState = FDE_XmlSyntaxState::Text;
- syntaxParserResult = FX_XmlSyntaxResult::ElementBreak;
} else if (ch == L'/') {
m_syntaxParserState = FDE_XmlSyntaxState::CloseElement;
} else {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
}
m_Start++;
break;
case FDE_XmlSyntaxState::CloseElement:
if (!IsXMLNameChar(ch, current_text_.empty())) {
if (ch == L'>') {
- if (m_XMLNodeTypeStack.empty()) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
- }
- m_XMLNodeTypeStack.pop();
+ if (m_XMLNodeTypeStack.empty())
+ return false;
+ m_XMLNodeTypeStack.pop();
m_syntaxParserState = FDE_XmlSyntaxState::Text;
- syntaxParserResult = FX_XmlSyntaxResult::ElementClose;
+
+ if (current_node_->GetType() != FX_XMLNODE_Element)
+ return false;
+
+ WideString element_name = GetTextData();
+ if (element_name.GetLength() > 0 &&
+ element_name !=
+ static_cast<CFX_XMLElement*>(current_node_)->GetName()) {
+ return false;
+ }
+
+ current_node_ = current_node_->GetParent();
+ iCount++;
} else if (!IsXMLWhiteSpace(ch)) {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
}
} else {
current_text_.push_back(ch);
@@ -410,8 +335,10 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
case FDE_XmlSyntaxState::SkipCData: {
if (FXSYS_wcsnicmp(m_Buffer.data() + m_Start, L"]]>", 3) == 0) {
m_Start += 3;
- syntaxParserResult = FX_XmlSyntaxResult::CData;
m_syntaxParserState = FDE_XmlSyntaxState::Text;
+
+ current_node_->AppendChild(
+ doc->CreateNode<CFX_XMLCharData>(GetTextData()));
} else {
current_text_.push_back(ch);
m_Start++;
@@ -481,7 +408,7 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
}
if (m_wQuotationMark == 0) {
m_Start++;
- syntaxParserResult = FX_XmlSyntaxResult::TargetData;
+ ProcessTargetData();
break;
}
}
@@ -495,10 +422,9 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
} else if (ch == m_wQuotationMark) {
m_wQuotationMark = 0;
m_Start++;
- syntaxParserResult = FX_XmlSyntaxResult::TargetData;
+ ProcessTargetData();
} else {
- m_syntaxParserResult = FX_XmlSyntaxResult::Error;
- return m_syntaxParserResult;
+ return false;
}
} else {
current_text_.push_back(ch);
@@ -508,15 +434,11 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
default:
break;
}
- if (syntaxParserResult != FX_XmlSyntaxResult::None)
- return syntaxParserResult;
}
}
- return FX_XmlSyntaxResult::Text;
-}
-bool CFX_XMLParser::GetStatus() const {
- return m_pStream && m_syntaxParserResult != FX_XmlSyntaxResult::Error;
+ current_node_->AppendChild(doc->CreateNode<CFX_XMLText>(GetTextData()));
+ return true;
}
void CFX_XMLParser::ProcessTextChar(wchar_t character) {
@@ -576,6 +498,18 @@ void CFX_XMLParser::ProcessTextChar(wchar_t character) {
m_Start++;
}
+void CFX_XMLParser::ProcessTargetData() {
+ WideString target_data = GetTextData();
+ if (target_data.IsEmpty())
+ return;
+ if (!current_node_)
+ return;
+ if (current_node_->GetType() != FX_XMLNODE_Instruction)
+ return;
+
+ static_cast<CFX_XMLInstruction*>(current_node_)->AppendData(target_data);
+}
+
WideString CFX_XMLParser::GetTextData() {
WideString ret(current_text_.data(), current_text_.size());
m_iEntityStart = -1;
diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h
index db8239bd98..aa5ad5761c 100644
--- a/core/fxcrt/xml/cfx_xmlparser.h
+++ b/core/fxcrt/xml/cfx_xmlparser.h
@@ -20,24 +20,6 @@ class CFX_XMLElement;
class CFX_XMLNode;
class IFX_SeekableReadStream;
-enum class FX_XmlSyntaxResult {
- None,
- InstructionOpen,
- InstructionClose,
- ElementOpen,
- ElementBreak,
- ElementClose,
- TargetName,
- TagName,
- AttriName,
- AttriValue,
- Text,
- CData,
- TargetData,
- Error,
- EndOfString
-};
-
class CFX_XMLParser {
public:
static bool IsXMLNameChar(wchar_t ch, bool bFirstChar);
@@ -47,10 +29,6 @@ class CFX_XMLParser {
std::unique_ptr<CFX_XMLDocument> Parse();
- protected:
- FX_XmlSyntaxResult DoSyntaxParse();
- WideString GetTextData();
-
private:
enum class FDE_XmlSyntaxState {
Text,
@@ -71,15 +49,16 @@ class CFX_XMLParser {
TargetData
};
+ bool DoSyntaxParse(CFX_XMLDocument* doc);
+ WideString GetTextData();
void ProcessTextChar(wchar_t ch);
- bool GetStatus() const;
+ void ProcessTargetData();
CFX_XMLNode* current_node_ = nullptr;
WideString current_attribute_name_;
RetainPtr<IFX_SeekableReadStream> m_pStream;
FX_FILESIZE m_Start = 0; // Start position in m_Buffer
FX_FILESIZE m_End = 0; // End position in m_Buffer
- FX_XmlSyntaxResult m_syntaxParserResult = FX_XmlSyntaxResult::None;
FDE_XmlSyntaxState m_syntaxParserState = FDE_XmlSyntaxState::Text;
std::stack<FX_XMLNODETYPE> m_XMLNodeTypeStack;
std::stack<wchar_t> m_SkipStack;
diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
index 7ca242211d..072c18ce3f 100644
--- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
@@ -15,31 +15,43 @@
#include "testing/test_support.h"
#include "third_party/base/ptr_util.h"
-namespace {
-
-class CFX_XMLTestParser : public CFX_XMLParser {
+class CFX_XMLParserTest : public testing::Test {
public:
- explicit CFX_XMLTestParser(const RetainPtr<IFX_SeekableStream>& pStream)
- : CFX_XMLParser(pStream) {}
-
- ~CFX_XMLTestParser() override = default;
-
- FX_XmlSyntaxResult DoSyntaxParse() { return CFX_XMLParser::DoSyntaxParse(); }
- WideString GetTextData() { return CFX_XMLParser::GetTextData(); }
+ std::unique_ptr<CFX_XMLDocument> Parse(const char* input) {
+ auto stream = pdfium::MakeRetain<CFX_MemoryStream>(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input),
+ false);
+
+ CFX_XMLParser parser(stream);
+ return parser.Parse();
+ }
};
-RetainPtr<CFX_MemoryStream> MakeProxy(const char* input) {
- auto stream = pdfium::MakeRetain<CFX_MemoryStream>(
- reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input),
- false);
- return stream;
+TEST_F(CFX_XMLParserTest, AttributesMustBeQuoted) {
+ const char* input =
+ "<script display=1>\n"
+ "</script>";
+ ASSERT_TRUE(Parse(input) == nullptr);
}
-} // namespace
+TEST_F(CFX_XMLParserTest, Attributes) {
+ const char* input =
+ "<script contentType=\"application/x-javascript\" display=\"1\">\n"
+ "</script>";
+
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
-TEST(CFX_XMLParserTest, CData) {
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+
+ EXPECT_EQ(L"application/x-javascript", script->GetAttribute(L"contentType"));
+ EXPECT_EQ(L"1", script->GetAttribute(L"display"));
+}
+
+TEST_F(CFX_XMLParserTest, CData) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![CDATA[\n"
" if (a[1] < 3)\n"
" app.alert(\"Tclams\");\n"
@@ -47,41 +59,22 @@ TEST(CFX_XMLParserTest, CData) {
"</script>";
const wchar_t* cdata =
- L"\n"
+ L"\n \n"
L" if (a[1] < 3)\n"
L" app.alert(\"Tclams\");\n"
- L" ";
-
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- ASSERT_EQ(cdata, parser.GetTextData());
+ L" \n";
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(cdata, script->GetTextData());
}
-TEST(CFX_XMLParserTest, CDataWithInnerScript) {
+TEST_F(CFX_XMLParserTest, CDataWithInnerScript) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![CDATA[\n"
" if (a[1] < 3)\n"
" app.alert(\"Tclams\");\n"
@@ -90,322 +83,162 @@ TEST(CFX_XMLParserTest, CDataWithInnerScript) {
"</script>";
const wchar_t* cdata =
- L"\n"
+ L"\n \n"
L" if (a[1] < 3)\n"
L" app.alert(\"Tclams\");\n"
L" </script>\n"
- L" ";
-
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
+ L" \n";
- ASSERT_EQ(FX_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- ASSERT_EQ(cdata, parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(cdata, script->GetTextData());
}
-TEST(CFX_XMLParserTest, ArrowBangArrow) {
+TEST_F(CFX_XMLParserTest, ArrowBangArrow) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!>\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
-
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n \n", script->GetTextData());
}
-TEST(CFX_XMLParserTest, ArrowBangBracketArrow) {
+TEST_F(CFX_XMLParserTest, ArrowBangBracketArrow) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![>\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- // Parser walks to end of input.
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, IncompleteCData) {
+TEST_F(CFX_XMLParserTest, IncompleteCData) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![CDATA>\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- // Parser walks to end of input.
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, UnClosedCData) {
+TEST_F(CFX_XMLParserTest, UnClosedCData) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![CDATA[\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- // Parser walks to end of input.
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, EmptyCData) {
+TEST_F(CFX_XMLParserTest, EmptyCData) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <![CDATA[]]>\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- ASSERT_EQ(L"", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n \n", script->GetTextData());
}
-TEST(CFX_XMLParserTest, Comment) {
+TEST_F(CFX_XMLParserTest, Comment) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!-- A Comment -->\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n \n", script->GetTextData());
}
-TEST(CFX_XMLParserTest, IncorrectCommentStart) {
+TEST_F(CFX_XMLParserTest, IncorrectCommentStart) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!- A Comment -->\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n \n", script->GetTextData());
}
-TEST(CFX_XMLParserTest, CommentEmpty) {
+TEST_F(CFX_XMLParserTest, CommentEmpty) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!---->\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n \n", script->GetTextData());
}
-TEST(CFX_XMLParserTest, CommentThreeDash) {
+TEST_F(CFX_XMLParserTest, CommentThreeDash) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!--->\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"\n ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, CommentTwoDash) {
+TEST_F(CFX_XMLParserTest, CommentTwoDash) {
const char* input =
- "<script contentType=\"application/x-javascript\">\n"
+ "<script>\n"
" <!-->\n"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"\n ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ EXPECT_EQ(L"\n ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, Entities) {
+TEST_F(CFX_XMLParserTest, Entities) {
const char* input =
- "<script contentType=\"application/x-javascript\">"
+ "<script>"
"&#66;" // B
"&#x54;" // T
"&#x6a;" // j
@@ -420,133 +253,76 @@ TEST(CFX_XMLParserTest, Entities) {
"&something_else;"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"BTjH\xab48&<>'\"", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L"BTjH\xab48&<>'\"", script->GetTextData());
}
-TEST(CFX_XMLParserTest, EntityOverflowHex) {
+TEST_F(CFX_XMLParserTest, EntityOverflowHex) {
const char* input =
- "<script contentType=\"application/x-javascript\">"
+ "<script>"
"&#xaDBDFFFFF;"
"&#xafffffffffffffffffffffffffffffffff;"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L" ", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L" ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, EntityOverflowDecimal) {
+TEST_F(CFX_XMLParserTest, EntityOverflowDecimal) {
const char* input =
- "<script contentType=\"application/x-javascript\">"
+ "<script>"
"&#2914910205;"
"&#29149102052342342134521341234512351234213452315;"
"</script>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- ASSERT_EQ(L"contentType", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- ASSERT_EQ(L"application/x-javascript", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L" ", parser.GetTextData());
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ CFX_XMLElement* script = doc->GetRoot()->GetFirstChildNamed(L"script");
+ ASSERT_TRUE(script != nullptr);
+ EXPECT_EQ(L" ", script->GetTextData());
}
-TEST(CFX_XMLParserTest, IsXMLNameChar) {
- EXPECT_FALSE(CFX_XMLTestParser::IsXMLNameChar(L'-', true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(L'-', false));
-
- EXPECT_FALSE(CFX_XMLTestParser::IsXMLNameChar(0x2069, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0x2070, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0x2073, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0x218F, true));
- EXPECT_FALSE(CFX_XMLTestParser::IsXMLNameChar(0x2190, true));
-
- EXPECT_FALSE(CFX_XMLTestParser::IsXMLNameChar(0xFDEF, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0xFDF0, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0xFDF1, true));
- EXPECT_TRUE(CFX_XMLTestParser::IsXMLNameChar(0xFFFD, true));
- EXPECT_FALSE(CFX_XMLTestParser::IsXMLNameChar(0xFFFE, true));
+TEST_F(CFX_XMLParserTest, IsXMLNameChar) {
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(L'-', true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(L'-', false));
+
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(0x2069, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0x2070, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0x2073, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0x218F, true));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(0x2190, true));
+
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(0xFDEF, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0xFDF0, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0xFDF1, true));
+ EXPECT_TRUE(CFX_XMLParser::IsXMLNameChar(0xFFFD, true));
+ EXPECT_FALSE(CFX_XMLParser::IsXMLNameChar(0xFFFE, true));
}
-TEST(CFX_XMLParserTest, BadElementClose) {
- const char* input = "</endtag>";
-
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::Error, parser.DoSyntaxParse());
+TEST_F(CFX_XMLParserTest, BadElementClose) {
+ ASSERT_TRUE(Parse("</endtag>") == nullptr);
}
-TEST(CFX_XMLParserTest, DoubleElementClose) {
- const char* input = "<p></p></p>";
-
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"p", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(L"", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"p", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::Error, parser.DoSyntaxParse());
+TEST_F(CFX_XMLParserTest, DoubleElementClose) {
+ ASSERT_TRUE(Parse("<p></p></p>") == nullptr);
}
-TEST(CFX_XMLParserTest, ParseInstruction) {
+TEST_F(CFX_XMLParserTest, ParseInstruction) {
const char* input =
"<?originalXFAVersion http://www.xfa.org/schema/xfa-template/3.3/ ?>"
"<form></form>";
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
-
- auto doc = parser.Parse();
- ASSERT_TRUE(doc.get() != nullptr);
+ std::unique_ptr<CFX_XMLDocument> doc = Parse(input);
+ ASSERT_TRUE(doc != nullptr);
CFX_XMLElement* root = doc->GetRoot();
ASSERT_TRUE(root->GetFirstChild() != nullptr);
@@ -557,32 +333,10 @@ TEST(CFX_XMLParserTest, ParseInstruction) {
EXPECT_TRUE(instruction->IsOriginalXFAVersion());
}
-TEST(CFX_XMLParserTest, BadEntity) {
+TEST_F(CFX_XMLParserTest, BadEntity) {
const char* input =
"<script>"
"Test &<p>; thing"
"</script>";
-
- auto stream = MakeProxy(input);
- CFX_XMLTestParser parser(stream);
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"Test &", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- ASSERT_EQ(FX_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- ASSERT_EQ(L"p", parser.GetTextData());
- ASSERT_EQ(FX_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
-
- ASSERT_EQ(FX_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- ASSERT_EQ(L"; thing", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- ASSERT_EQ(L"script", parser.GetTextData());
-
- ASSERT_EQ(FX_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_TRUE(Parse(input) == nullptr);
}