1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "third_party/libjingle_xmpp/xmllite/xmlprinter.h"
12
13 #include <sstream>
14 #include <string>
15
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/libjingle_xmpp/xmllite/qname.h"
18 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
19 #include "third_party/libjingle_xmpp/xmllite/xmlnsstack.h"
20
21 using jingle_xmpp::QName;
22 using jingle_xmpp::XmlElement;
23 using jingle_xmpp::XmlnsStack;
24 using jingle_xmpp::XmlPrinter;
25
TEST(XmlPrinterTest,TestBasicPrinting)26 TEST(XmlPrinterTest, TestBasicPrinting) {
27 XmlElement elt(QName("google:test", "first"));
28 std::stringstream ss;
29 XmlPrinter::PrintXml(&ss, &elt);
30 EXPECT_EQ("<test:first xmlns:test=\"google:test\"/>", ss.str());
31 }
32
TEST(XmlPrinterTest,TestNamespacedPrinting)33 TEST(XmlPrinterTest, TestNamespacedPrinting) {
34 XmlElement elt(QName("google:test", "first"));
35 elt.AddElement(new XmlElement(QName("nested:test", "second")));
36 std::stringstream ss;
37
38 XmlnsStack ns_stack;
39 ns_stack.AddXmlns("gg", "google:test");
40 ns_stack.AddXmlns("", "nested:test");
41
42 XmlPrinter::PrintXml(&ss, &elt, &ns_stack);
43 EXPECT_EQ("<gg:first><second/></gg:first>", ss.str());
44 }
45