1 // Copyright 2018 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fxcrt/xml/cfx_xmltext.h"
6 #include "core/fxcrt/xml/cfx_xmldocument.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/string_write_stream.h"
9 
TEST(CFX_XMLTextTest,GetType)10 TEST(CFX_XMLTextTest, GetType) {
11   CFX_XMLText text(L"My Text");
12   EXPECT_EQ(CFX_XMLNode::Type::kText, text.GetType());
13 }
14 
TEST(CFX_XMLTextTest,GetText)15 TEST(CFX_XMLTextTest, GetText) {
16   CFX_XMLText data(L"My Data");
17   EXPECT_EQ(L"My Data", data.GetText());
18 }
19 
TEST(CFX_XMLTextTest,Clone)20 TEST(CFX_XMLTextTest, Clone) {
21   CFX_XMLDocument doc;
22 
23   CFX_XMLText data(L"My Data");
24   CFX_XMLNode* clone = data.Clone(&doc);
25   EXPECT_TRUE(clone != nullptr);
26   ASSERT_EQ(CFX_XMLNode::Type::kText, clone->GetType());
27   EXPECT_EQ(L"My Data", ToXMLText(clone)->GetText());
28 }
29 
TEST(CFX_XMLTextTest,Save)30 TEST(CFX_XMLTextTest, Save) {
31   auto stream = pdfium::MakeRetain<StringWriteStream>();
32   CFX_XMLText data(L"My Data & this is < and > and ' and \" stuff.");
33   data.Save(stream);
34   EXPECT_EQ("My Data &amp; this is &lt; and &gt; and &apos; and &quot; stuff.",
35             stream->ToString());
36 }
37 
TEST(CFX_XMLTextTest,SetText)38 TEST(CFX_XMLTextTest, SetText) {
39   CFX_XMLText data(L"My Data");
40   EXPECT_EQ(L"My Data", data.GetText());
41   data.SetText(L"New Text");
42   EXPECT_EQ(L"New Text", data.GetText());
43 }
44