summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml/cfx_xmltext_unittest.cpp
blob: ab977e9546ff03dd81627fb45821505dc41597a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2018 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 "core/fxcrt/xml/cfx_xmltext.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/string_write_stream.h"
#include "testing/test_support.h"

TEST(CFX_XMLTextTest, GetType) {
  CFX_XMLText text(L"My Text");
  EXPECT_EQ(FX_XMLNODE_Text, text.GetType());
}

TEST(CFX_XMLTextTest, GetText) {
  CFX_XMLText data(L"My Data");
  EXPECT_EQ(L"My Data", data.GetText());
}

TEST(CFX_XMLTextTest, Clone) {
  CFX_XMLText data(L"My Data");
  auto clone = data.Clone();
  EXPECT_TRUE(clone != nullptr);
  ASSERT_EQ(FX_XMLNODE_Text, clone->GetType());
  EXPECT_EQ(L"My Data", static_cast<CFX_XMLText*>(clone.get())->GetText());
}

TEST(CFX_XMLTextTest, Save) {
  auto stream = pdfium::MakeRetain<StringWriteStream>();
  CFX_XMLText data(L"My Data & this is < and > and ' and \" stuff.");
  data.Save(stream);
  EXPECT_EQ("My Data &amp; this is &lt; and &gt; and &apos; and &quot; stuff.",
            stream->ToString());
}

TEST(CFX_XMLTextTest, SetText) {
  CFX_XMLText data(L"My Data");
  EXPECT_EQ(L"My Data", data.GetText());
  data.SetText(L"New Text");
  EXPECT_EQ(L"New Text", data.GetText());
}