OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "xfa/fde/xml/fde_xml_imp.h" | 5 #include "xfa/fde/xml/fde_xml_imp.h" |
6 | 6 |
7 #include "xfa/fgas/crt/fgas_stream.h" | 7 #include "xfa/fgas/crt/fgas_stream.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 TEST(CFDE_XMLSyntaxParser, CData) { | 10 TEST(CFDE_XMLSyntaxParser, CData) { |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 parser.GetAttributeValue(data); | 513 parser.GetAttributeValue(data); |
514 EXPECT_EQ(L"application/x-javascript", data); | 514 EXPECT_EQ(L"application/x-javascript", data); |
515 | 515 |
516 EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); | 516 EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); |
517 EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); | 517 EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); |
518 parser.GetTextData(data); | 518 parser.GetTextData(data); |
519 EXPECT_EQ(L"\n ", data); | 519 EXPECT_EQ(L"\n ", data); |
520 | 520 |
521 EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); | 521 EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); |
522 } | 522 } |
| 523 |
| 524 TEST(CFDE_XMLSyntaxParser, Entities) { |
| 525 const FX_WCHAR* input = |
| 526 L"<script contentType=\"application/x-javascript\">" |
| 527 L"B" |
| 528 L"T" |
| 529 L"H" |
| 530 L"ꭈ" |
| 531 L"�" |
| 532 L"</script>"; |
| 533 |
| 534 // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. |
| 535 size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); |
| 536 std::unique_ptr<IFX_Stream> stream(IFX_Stream::CreateStream( |
| 537 reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); |
| 538 CFDE_XMLSyntaxParser parser; |
| 539 parser.Init(stream.get(), 256); |
| 540 |
| 541 CFX_WideString data; |
| 542 |
| 543 EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); |
| 544 EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); |
| 545 parser.GetTagName(data); |
| 546 EXPECT_EQ(L"script", data); |
| 547 |
| 548 EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse()); |
| 549 parser.GetAttributeName(data); |
| 550 EXPECT_EQ(L"contentType", data); |
| 551 EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse()); |
| 552 parser.GetAttributeValue(data); |
| 553 EXPECT_EQ(L"application/x-javascript", data); |
| 554 |
| 555 EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); |
| 556 EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); |
| 557 parser.GetTextData(data); |
| 558 EXPECT_EQ(L"BTH\xab48", data); |
| 559 |
| 560 EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); |
| 561 parser.GetTagName(data); |
| 562 EXPECT_EQ(L"script", data); |
| 563 |
| 564 EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); |
| 565 } |
| 566 |
| 567 TEST(CFDE_XMLSyntaxParser, EntityOverflowHex) { |
| 568 const FX_WCHAR* input = |
| 569 L"<script contentType=\"application/x-javascript\">" |
| 570 L"�" |
| 571 L"�" |
| 572 L"</script>"; |
| 573 |
| 574 // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. |
| 575 size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); |
| 576 std::unique_ptr<IFX_Stream> stream(IFX_Stream::CreateStream( |
| 577 reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); |
| 578 CFDE_XMLSyntaxParser parser; |
| 579 parser.Init(stream.get(), 256); |
| 580 |
| 581 CFX_WideString data; |
| 582 |
| 583 EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); |
| 584 EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); |
| 585 parser.GetTagName(data); |
| 586 EXPECT_EQ(L"script", data); |
| 587 |
| 588 EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse()); |
| 589 parser.GetAttributeName(data); |
| 590 EXPECT_EQ(L"contentType", data); |
| 591 EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse()); |
| 592 parser.GetAttributeValue(data); |
| 593 EXPECT_EQ(L"application/x-javascript", data); |
| 594 |
| 595 EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); |
| 596 EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); |
| 597 parser.GetTextData(data); |
| 598 EXPECT_EQ(L" ", data); |
| 599 |
| 600 EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); |
| 601 parser.GetTagName(data); |
| 602 EXPECT_EQ(L"script", data); |
| 603 |
| 604 EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); |
| 605 } |
| 606 |
| 607 TEST(CFDE_XMLSyntaxParser, EntityOverflowDecimal) { |
| 608 const FX_WCHAR* input = |
| 609 L"<script contentType=\"application/x-javascript\">" |
| 610 L"�" |
| 611 L"�" |
| 612 L"</script>"; |
| 613 |
| 614 // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR. |
| 615 size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR); |
| 616 std::unique_ptr<IFX_Stream> stream(IFX_Stream::CreateStream( |
| 617 reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0)); |
| 618 CFDE_XMLSyntaxParser parser; |
| 619 parser.Init(stream.get(), 256); |
| 620 |
| 621 CFX_WideString data; |
| 622 |
| 623 EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); |
| 624 EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); |
| 625 parser.GetTagName(data); |
| 626 EXPECT_EQ(L"script", data); |
| 627 |
| 628 EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse()); |
| 629 parser.GetAttributeName(data); |
| 630 EXPECT_EQ(L"contentType", data); |
| 631 EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse()); |
| 632 parser.GetAttributeValue(data); |
| 633 EXPECT_EQ(L"application/x-javascript", data); |
| 634 |
| 635 EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse()); |
| 636 EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse()); |
| 637 parser.GetTextData(data); |
| 638 EXPECT_EQ(L" ", data); |
| 639 |
| 640 EXPECT_EQ(FDE_XmlSyntaxResult::ElementClose, parser.DoSyntaxParse()); |
| 641 parser.GetTagName(data); |
| 642 EXPECT_EQ(L"script", data); |
| 643 |
| 644 EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse()); |
| 645 } |
OLD | NEW |