| OLD | NEW |
| (Empty) |
| 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 <iostream> | |
| 12 #include <sstream> | |
| 13 #include <string> | |
| 14 #include "webrtc/libjingle/xmllite/xmlbuilder.h" | |
| 15 #include "webrtc/libjingle/xmllite/xmlelement.h" | |
| 16 #include "webrtc/libjingle/xmllite/xmlparser.h" | |
| 17 #include "webrtc/base/common.h" | |
| 18 #include "webrtc/base/gunit.h" | |
| 19 | |
| 20 using buzz::XmlBuilder; | |
| 21 using buzz::XmlElement; | |
| 22 using buzz::XmlParser; | |
| 23 | |
| 24 TEST(XmlBuilderTest, TestTrivial) { | |
| 25 XmlBuilder builder; | |
| 26 XmlParser::ParseXml(&builder, "<testing/>"); | |
| 27 EXPECT_EQ("<testing/>", builder.BuiltElement()->Str()); | |
| 28 } | |
| 29 | |
| 30 TEST(XmlBuilderTest, TestAttributes1) { | |
| 31 XmlBuilder builder; | |
| 32 XmlParser::ParseXml(&builder, "<testing a='b'/>"); | |
| 33 EXPECT_EQ("<testing a=\"b\"/>", builder.BuiltElement()->Str()); | |
| 34 } | |
| 35 | |
| 36 TEST(XmlBuilderTest, TestAttributes2) { | |
| 37 XmlBuilder builder; | |
| 38 XmlParser::ParseXml(&builder, "<testing e='' long='some text'/>"); | |
| 39 EXPECT_EQ("<testing e=\"\" long=\"some text\"/>", | |
| 40 builder.BuiltElement()->Str()); | |
| 41 } | |
| 42 | |
| 43 TEST(XmlBuilderTest, TestNesting1) { | |
| 44 XmlBuilder builder; | |
| 45 XmlParser::ParseXml(&builder, | |
| 46 "<top><first/><second><third></third></second></top>"); | |
| 47 EXPECT_EQ("<top><first/><second><third/></second></top>", | |
| 48 builder.BuiltElement()->Str()); | |
| 49 } | |
| 50 | |
| 51 TEST(XmlBuilderTest, TestNesting2) { | |
| 52 XmlBuilder builder; | |
| 53 XmlParser::ParseXml(&builder, | |
| 54 "<top><fifth><deeper><and><deeper/></and><sibling><leaf/>" | |
| 55 "</sibling></deeper></fifth><first/><second><third></third>" | |
| 56 "</second></top>"); | |
| 57 EXPECT_EQ("<top><fifth><deeper><and><deeper/></and><sibling><leaf/>" | |
| 58 "</sibling></deeper></fifth><first/><second><third/>" | |
| 59 "</second></top>", builder.BuiltElement()->Str()); | |
| 60 } | |
| 61 | |
| 62 TEST(XmlBuilderTest, TestQuoting1) { | |
| 63 XmlBuilder builder; | |
| 64 XmlParser::ParseXml(&builder, "<testing a='>'/>"); | |
| 65 EXPECT_EQ("<testing a=\">\"/>", builder.BuiltElement()->Str()); | |
| 66 } | |
| 67 | |
| 68 TEST(XmlBuilderTest, TestQuoting2) { | |
| 69 XmlBuilder builder; | |
| 70 XmlParser::ParseXml(&builder, "<testing a='<>&"'/>"); | |
| 71 EXPECT_EQ("<testing a=\"<>&"\"/>", | |
| 72 builder.BuiltElement()->Str()); | |
| 73 } | |
| 74 | |
| 75 TEST(XmlBuilderTest, TestQuoting3) { | |
| 76 XmlBuilder builder; | |
| 77 XmlParser::ParseXml(&builder, "<testing a='so "important"'/>"); | |
| 78 EXPECT_EQ("<testing a=\"so "important"\"/>", | |
| 79 builder.BuiltElement()->Str()); | |
| 80 } | |
| 81 | |
| 82 TEST(XmlBuilderTest, TestQuoting4) { | |
| 83 XmlBuilder builder; | |
| 84 XmlParser::ParseXml(&builder, "<testing a='"important", yes'/>"); | |
| 85 EXPECT_EQ("<testing a=\""important", yes\"/>", | |
| 86 builder.BuiltElement()->Str()); | |
| 87 } | |
| 88 | |
| 89 TEST(XmlBuilderTest, TestQuoting5) { | |
| 90 XmlBuilder builder; | |
| 91 XmlParser::ParseXml(&builder, | |
| 92 "<testing a='<what is "important">'/>"); | |
| 93 EXPECT_EQ("<testing a=\"<what is "important">\"/>", | |
| 94 builder.BuiltElement()->Str()); | |
| 95 } | |
| 96 | |
| 97 TEST(XmlBuilderTest, TestText1) { | |
| 98 XmlBuilder builder; | |
| 99 XmlParser::ParseXml(&builder, "<testing>></testing>"); | |
| 100 EXPECT_EQ("<testing>></testing>", builder.BuiltElement()->Str()); | |
| 101 } | |
| 102 | |
| 103 TEST(XmlBuilderTest, TestText2) { | |
| 104 XmlBuilder builder; | |
| 105 XmlParser::ParseXml(&builder, "<testing><>&"</testing>"); | |
| 106 EXPECT_EQ("<testing><>&\"</testing>", | |
| 107 builder.BuiltElement()->Str()); | |
| 108 } | |
| 109 | |
| 110 TEST(XmlBuilderTest, TestText3) { | |
| 111 XmlBuilder builder; | |
| 112 XmlParser::ParseXml(&builder, "<testing>so <important></testing>"); | |
| 113 EXPECT_EQ("<testing>so <important></testing>", | |
| 114 builder.BuiltElement()->Str()); | |
| 115 } | |
| 116 | |
| 117 TEST(XmlBuilderTest, TestText4) { | |
| 118 XmlBuilder builder; | |
| 119 XmlParser::ParseXml(&builder, "<testing><important>, yes</testing>"); | |
| 120 EXPECT_EQ("<testing><important>, yes</testing>", | |
| 121 builder.BuiltElement()->Str()); | |
| 122 } | |
| 123 | |
| 124 TEST(XmlBuilderTest, TestText5) { | |
| 125 XmlBuilder builder; | |
| 126 XmlParser::ParseXml(&builder, | |
| 127 "<testing>importance &<important>&</testing>"); | |
| 128 EXPECT_EQ("<testing>importance &<important>&</testing>", | |
| 129 builder.BuiltElement()->Str()); | |
| 130 } | |
| 131 | |
| 132 TEST(XmlBuilderTest, TestNamespace1) { | |
| 133 XmlBuilder builder; | |
| 134 XmlParser::ParseXml(&builder, "<testing xmlns='foo'/>"); | |
| 135 EXPECT_EQ("<testing xmlns=\"foo\"/>", builder.BuiltElement()->Str()); | |
| 136 } | |
| 137 | |
| 138 TEST(XmlBuilderTest, TestNamespace2) { | |
| 139 XmlBuilder builder; | |
| 140 XmlParser::ParseXml(&builder, "<testing xmlns:a='foo' a:b='c'/>"); | |
| 141 EXPECT_EQ("<testing xmlns:a=\"foo\" a:b=\"c\"/>", | |
| 142 builder.BuiltElement()->Str()); | |
| 143 } | |
| 144 | |
| 145 TEST(XmlBuilderTest, TestNamespace3) { | |
| 146 XmlBuilder builder; | |
| 147 XmlParser::ParseXml(&builder, "<testing xmlns:a=''/>"); | |
| 148 EXPECT_TRUE(NULL == builder.BuiltElement()); | |
| 149 } | |
| 150 | |
| 151 TEST(XmlBuilderTest, TestNamespace4) { | |
| 152 XmlBuilder builder; | |
| 153 XmlParser::ParseXml(&builder, "<testing a:b='c'/>"); | |
| 154 EXPECT_TRUE(NULL == builder.BuiltElement()); | |
| 155 } | |
| 156 | |
| 157 TEST(XmlBuilderTest, TestAttrCollision1) { | |
| 158 XmlBuilder builder; | |
| 159 XmlParser::ParseXml(&builder, "<testing a='first' a='second'/>"); | |
| 160 EXPECT_TRUE(NULL == builder.BuiltElement()); | |
| 161 } | |
| 162 | |
| 163 TEST(XmlBuilderTest, TestAttrCollision2) { | |
| 164 XmlBuilder builder; | |
| 165 XmlParser::ParseXml(&builder, | |
| 166 "<testing xmlns:a='foo' xmlns:b='foo' a:x='c' b:x='d'/>"); | |
| 167 EXPECT_TRUE(NULL == builder.BuiltElement()); | |
| 168 } | |
| 169 | |
| 170 TEST(XmlBuilderTest, TestAttrCollision3) { | |
| 171 XmlBuilder builder; | |
| 172 XmlParser::ParseXml(&builder, | |
| 173 "<testing xmlns:a='foo'><nested xmlns:b='foo' a:x='c' b:x='d'/>" | |
| 174 "</testing>"); | |
| 175 EXPECT_TRUE(NULL == builder.BuiltElement()); | |
| 176 } | |
| 177 | |
| OLD | NEW |