diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-19 09:19:57 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-19 13:33:07 +0000 |
commit | 0d86ecb08e1b2c204333b1f1f6b0b014e5b2971c (patch) | |
tree | f816429f8581c16a60773eb23385dc8e55729bac /xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp | |
parent | 3b71d26f092ebc86ca9177fbbe89d83caa67ae1b (diff) | |
download | pdfium-0d86ecb08e1b2c204333b1f1f6b0b014e5b2971c.tar.xz |
Move fde XML parser to core
This CL moves the XML parser from FDE into FXCRT and renames to CFX_
from CFDE_.
Change-Id: I21a9590bf74daf5517df630d7e7a5de89da99ea4
Reviewed-on: https://pdfium-review.googlesource.com/4312
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp')
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp | 527 |
1 files changed, 0 insertions, 527 deletions
diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp deleted file mode 100644 index 45ad3bb2f0..0000000000 --- a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp +++ /dev/null @@ -1,527 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xfa/fde/xml/cfde_xmlsyntaxparser.h" - -#include <memory> - -#include "core/fxcrt/cfx_seekablestreamproxy.h" -#include "core/fxcrt/fx_codepage.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/test_support.h" - -class CFDE_XMLSyntaxParserTest : public pdfium::FPDF_Test {}; - -TEST_F(CFDE_XMLSyntaxParserTest, CData) { - 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" - L" if (a[1] < 3)\n" - L" app.alert(\"Tclams\");\n" - L" "; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse()); - ASSERT_EQ(cdata, parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, CDataWithInnerScript) { - 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" - L" if (a[1] < 3)\n" - L" app.alert(\"Tclams\");\n" - L" </script>\n" - L" "; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse()); - ASSERT_EQ(cdata, parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangArrow) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!>\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, ArrowBangBracketArrow) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <![>\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - 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. - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, IncompleteCData) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <![CDATA>\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - 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. - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, UnClosedCData) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <![CDATA[\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - 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. - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, EmptyCData) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <![CDATA[]]>\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::CData, parser.DoSyntaxParse()); - ASSERT_EQ(L"", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, Comment) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!-- A Comment -->\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, IncorrectCommentStart) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!- A Comment -->\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, CommentEmpty) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!---->\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, CommentThreeDash) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!--->\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, CommentTwoDash) { - const char* input = - "<script contentType=\"application/x-javascript\">\n" - " <!-->\n" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"\n ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, Entities) { - const char* input = - "<script contentType=\"application/x-javascript\">" - "B" - "T" - "H" - "ꭈ" - "�" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L"BTH\xab48", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowHex) { - const char* input = - "<script contentType=\"application/x-javascript\">" - "�" - "�" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L" ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} - -TEST_F(CFDE_XMLSyntaxParserTest, EntityOverflowDecimal) { - const char* input = - "<script contentType=\"application/x-javascript\">" - "�" - "�" - "</script>"; - - CFX_RetainPtr<CFX_SeekableStreamProxy> stream = - pdfium::MakeRetain<CFX_SeekableStreamProxy>( - reinterpret_cast<uint8_t*>(const_cast<char*>(input)), strlen(input)); - stream->SetCodePage(FX_CODEPAGE_UTF8); - - CFDE_XMLSyntaxParser parser(stream); - ASSERT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - 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()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); - ASSERT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); - ASSERT_EQ(L" ", parser.GetTextData()); - - ASSERT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); - ASSERT_EQ(L"script", parser.GetTagName()); - - ASSERT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); -} |