summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp718
-rw-r--r--xfa/fgas/crt/ifgas_stream.cpp124
-rw-r--r--xfa/fgas/crt/ifgas_stream.h2
3 files changed, 367 insertions, 477 deletions
diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
index aa7c17901a..a45bb1276a 100644
--- a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
+++ b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp
@@ -8,18 +8,19 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
+#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fgas/crt/ifgas_stream.h"
class CFDE_XMLSyntaxParserTest : public pdfium::FPDF_Test {};
TEST_F(CFDE_XMLSyntaxParserTest, CData) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![CDATA[\n"
- L" if (a[1] < 3)\n"
- L" app.alert(\"Tclams\");\n"
- L" ]]>\n"
- L"</script>";
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![CDATA[\n"
+ " if (a[1] < 3)\n"
+ " app.alert(\"Tclams\");\n"
+ " ]]>\n"
+ "</script>";
const wchar_t* cdata =
L"\n"
@@ -27,45 +28,46 @@ TEST_F(CFDE_XMLSyntaxParserTest, CData) {
L" app.alert(\"Tclams\");\n"
L" ";
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- EXPECT_EQ(cdata, parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
+ ASSERT_EQ(cdata, parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, CDataWithInnerScript) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![CDATA[\n"
- L" if (a[1] < 3)\n"
- L" app.alert(\"Tclams\");\n"
- L" </script>\n"
- L" ]]>\n"
- L"</script>";
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![CDATA[\n"
+ " if (a[1] < 3)\n"
+ " app.alert(\"Tclams\");\n"
+ " </script>\n"
+ " ]]>\n"
+ "</script>";
const wchar_t* cdata =
L"\n"
@@ -74,438 +76,452 @@ TEST_F(CFDE_XMLSyntaxParserTest, CDataWithInnerScript) {
L" </script>\n"
L" ";
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- EXPECT_EQ(cdata, parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
+ ASSERT_EQ(cdata, parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangArrow) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!>\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!>\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangBracketArrow) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![>\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![>\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
// Parser walks to end of input.
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, IncompleteCData) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![CDATA>\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![CDATA>\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
// Parser walks to end of input.
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, UnClosedCData) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![CDATA[\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![CDATA[\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
// Parser walks to end of input.
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, EmptyCData) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <![CDATA[]]>\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <![CDATA[]]>\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
- EXPECT_EQ(L"", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse());
+ ASSERT_EQ(L"", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, Comment) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!-- A Comment -->\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!-- A Comment -->\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, IncorrectCommentStart) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!- A Comment -->\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!- A Comment -->\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, CommentEmpty) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!---->\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!---->\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, CommentThreeDash) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!--->\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!--->\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, CommentTwoDash) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">\n"
- L" <!-->\n"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">\n"
+ " <!-->\n"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"\n ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"\n ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, Entities) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">"
- L"&#66;"
- L"&#x54;"
- L"&#x00000000000000000048;"
- L"&#x0000000000000000AB48;"
- L"&#x0000000000000000000;"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">"
+ "&#66;"
+ "&#x54;"
+ "&#x00000000000000000048;"
+ "&#x0000000000000000AB48;"
+ "&#x0000000000000000000;"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L"BTH\xab48", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L"BTH\xab48", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowHex) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">"
- L"&#xaDBDFFFFF;"
- L"&#xafffffffffffffffffffffffffffffffff;"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">"
+ "&#xaDBDFFFFF;"
+ "&#xafffffffffffffffffffffffffffffffff;"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L" ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L" ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowDecimal) {
- const wchar_t* input =
- L"<script contentType=\"application/x-javascript\">"
- L"&#2914910205;"
- L"&#29149102052342342134521341234512351234213452315;"
- L"</script>";
-
- // We * sizeof(wchar_t) because we pass in the uint8_t, not the wchar_t.
- size_t len = FXSYS_wcslen(input) * sizeof(wchar_t);
- CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream(
- reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len);
+ const char* input =
+ "<script contentType=\"application/x-javascript\">"
+ "&#2914910205;"
+ "&#29149102052342342134521341234512351234213452315;"
+ "</script>";
+
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateReadStream(IFX_MemoryStream::Create(
+ reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)));
+ stream->SetCodePage(FX_CODEPAGE_UTF8);
+
CFDE_XMLSyntaxParser parser(stream);
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
- EXPECT_EQ(L"contentType", parser.GetAttributeName());
- EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
- EXPECT_EQ(L"application/x-javascript", parser.GetAttributeValue());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
+ ASSERT_EQ(L"contentType", parser.GetAttributeName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
+ ASSERT_EQ(L"application/x-javascript", parser.GetAttributeValue());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
- EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
- EXPECT_EQ(L" ", parser.GetTextData());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
+ ASSERT_EQ(L" ", parser.GetTextData());
- EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
- EXPECT_EQ(L"script", parser.GetTagName());
+ ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse());
+ ASSERT_EQ(L"script", parser.GetTagName());
- EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
+ ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp
index 54fca1a721..874330165b 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/ifgas_stream.cpp
@@ -44,32 +44,6 @@ class IFGAS_StreamImp {
uint32_t m_dwAccess;
};
-class CFGAS_BufferStreamImp : public IFGAS_StreamImp {
- public:
- CFGAS_BufferStreamImp();
- ~CFGAS_BufferStreamImp() override {}
-
- bool LoadBuffer(uint8_t* pData, int32_t iTotalSize);
-
- // IFGAS_StreamImp:
- int32_t GetLength() const override;
- int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
- int32_t GetPosition() override;
- bool IsEOF() const override;
- int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
- int32_t ReadString(wchar_t* pStr, int32_t iMaxLength, bool& bEOS) override;
- int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
- int32_t WriteString(const wchar_t* pStr, int32_t iLength) override;
- void Flush() override {}
- bool SetLength(int32_t iLength) override { return false; }
-
- protected:
- uint8_t* m_pData;
- int32_t m_iTotalSize;
- int32_t m_iPosition;
- int32_t m_iLength;
-};
-
class CFGAS_FileReadStreamImp : public IFGAS_StreamImp {
public:
CFGAS_FileReadStreamImp();
@@ -338,89 +312,6 @@ void CFGAS_FileWriteStreamImp::Flush() {
m_pFileWrite->Flush();
}
}
-CFGAS_BufferStreamImp::CFGAS_BufferStreamImp()
- : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {}
-
-bool CFGAS_BufferStreamImp::LoadBuffer(uint8_t* pData, int32_t iTotalSize) {
- ASSERT(!m_pData && pData && iTotalSize > 0);
-
- m_pData = pData;
- m_iTotalSize = iTotalSize;
- m_iPosition = 0;
- m_iLength = iTotalSize;
- return true;
-}
-int32_t CFGAS_BufferStreamImp::GetLength() const {
- ASSERT(m_pData);
- return m_iLength;
-}
-int32_t CFGAS_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
- ASSERT(m_pData);
- if (eSeek == FX_STREAMSEEK_Begin) {
- m_iPosition = iOffset;
- } else if (eSeek == FX_STREAMSEEK_Current) {
- m_iPosition += iOffset;
- } else if (eSeek == FX_STREAMSEEK_End) {
- m_iPosition = m_iLength + iOffset;
- }
- if (m_iPosition > m_iLength) {
- m_iPosition = m_iLength;
- }
- if (m_iPosition < 0) {
- m_iPosition = 0;
- }
- return m_iPosition;
-}
-int32_t CFGAS_BufferStreamImp::GetPosition() {
- ASSERT(m_pData);
- return m_iPosition;
-}
-bool CFGAS_BufferStreamImp::IsEOF() const {
- ASSERT(m_pData);
- return m_iPosition >= m_iLength;
-}
-int32_t CFGAS_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
- ASSERT(m_pData);
- ASSERT(pBuffer && iBufferSize > 0);
- int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize);
- if (iLen <= 0) {
- return 0;
- }
- memcpy(pBuffer, m_pData + m_iPosition, iLen);
- m_iPosition += iLen;
- return iLen;
-}
-int32_t CFGAS_BufferStreamImp::ReadString(wchar_t* pStr,
- int32_t iMaxLength,
- bool& bEOS) {
- ASSERT(m_pData);
- ASSERT(pStr && iMaxLength > 0);
- int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength);
- if (iLen <= 0) {
- return 0;
- }
- const wchar_t* pSrc = (const wchar_t*)(char*)(m_pData + m_iPosition);
- int32_t iCount = 0;
- while (*pSrc && iCount < iLen) {
- *pStr++ = *pSrc++;
- iCount++;
- }
- m_iPosition += iCount * 2;
- bEOS = (*pSrc == L'\0') || (m_iPosition >= m_iLength);
- return iCount;
-}
-
-int32_t CFGAS_BufferStreamImp::WriteData(const uint8_t* pBuffer,
- int32_t iBufferSize) {
- ASSERT(false);
- return 0;
-}
-
-int32_t CFGAS_BufferStreamImp::WriteString(const wchar_t* pStr,
- int32_t iLength) {
- ASSERT(false);
- return 0;
-}
CFGAS_TextStream::CFGAS_TextStream(const CFX_RetainPtr<IFGAS_Stream>& pStream)
: m_wCodePage(FX_CODEPAGE_DefANSI),
@@ -824,21 +715,6 @@ CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWriteStream(
pdfium::MakeRetain<CFGAS_Stream>(std::move(pImp), FX_STREAMACCESS_Write));
}
-// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateStream(uint8_t* pData,
- int32_t length) {
- if (!pData || length < 1)
- return nullptr;
-
- std::unique_ptr<IFGAS_StreamImp> pImp =
- pdfium::MakeUnique<CFGAS_BufferStreamImp>();
- if (!static_cast<CFGAS_BufferStreamImp*>(pImp.get())
- ->LoadBuffer(pData, length))
- return nullptr;
-
- return pdfium::MakeRetain<CFGAS_Stream>(std::move(pImp), 0);
-}
-
CFX_RetainPtr<IFX_SeekableReadStream> IFGAS_Stream::MakeSeekableReadStream() {
return pdfium::MakeRetain<CFGAS_FileRead>(CFX_RetainPtr<IFGAS_Stream>(this));
}
diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h
index 9d9e24023d..cfb0722b21 100644
--- a/xfa/fgas/crt/ifgas_stream.h
+++ b/xfa/fgas/crt/ifgas_stream.h
@@ -27,8 +27,6 @@ class IFGAS_Stream : public CFX_Retainable {
const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
static CFX_RetainPtr<IFGAS_Stream> CreateWriteStream(
const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite);
- static CFX_RetainPtr<IFGAS_Stream> CreateStream(uint8_t* pData,
- int32_t length);
virtual uint32_t GetAccessModes() const = 0;
virtual int32_t GetLength() const = 0;