~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/xmllite/xmlbuilder_unittest.cc

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2004, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
8
 *  1. Redistributions of source code must retain the above copyright notice,
 
9
 *     this list of conditions and the following disclaimer.
 
10
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 
11
 *     this list of conditions and the following disclaimer in the documentation
 
12
 *     and/or other materials provided with the distribution.
 
13
 *  3. The name of the author may not be used to endorse or promote products
 
14
 *     derived from this software without specific prior written permission.
 
15
 *
 
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
17
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
18
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
19
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
20
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
22
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
23
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
24
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
25
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
26
 */
 
27
 
 
28
#include <string>
 
29
#include <sstream>
 
30
#include <iostream>
 
31
#include "talk/base/common.h"
 
32
#include "talk/base/gunit.h"
 
33
#include "talk/xmllite/xmlbuilder.h"
 
34
#include "talk/xmllite/xmlelement.h"
 
35
#include "talk/xmllite/xmlparser.h"
 
36
 
 
37
using buzz::XmlBuilder;
 
38
using buzz::XmlElement;
 
39
using buzz::XmlParser;
 
40
 
 
41
TEST(XmlBuilderTest, TestTrivial) {
 
42
  XmlBuilder builder;
 
43
  XmlParser::ParseXml(&builder, "<testing/>");
 
44
  EXPECT_EQ("<testing/>", builder.BuiltElement()->Str());
 
45
}
 
46
 
 
47
TEST(XmlBuilderTest, TestAttributes1) {
 
48
  XmlBuilder builder;
 
49
  XmlParser::ParseXml(&builder, "<testing a='b'/>");
 
50
  EXPECT_EQ("<testing a=\"b\"/>", builder.BuiltElement()->Str());
 
51
}
 
52
 
 
53
TEST(XmlBuilderTest, TestAttributes2) {
 
54
  XmlBuilder builder;
 
55
  XmlParser::ParseXml(&builder, "<testing e='' long='some text'/>");
 
56
  EXPECT_EQ("<testing e=\"\" long=\"some text\"/>",
 
57
      builder.BuiltElement()->Str());
 
58
}
 
59
 
 
60
TEST(XmlBuilderTest, TestNesting1) {
 
61
  XmlBuilder builder;
 
62
  XmlParser::ParseXml(&builder,
 
63
      "<top><first/><second><third></third></second></top>");
 
64
  EXPECT_EQ("<top><first/><second><third/></second></top>",
 
65
      builder.BuiltElement()->Str());
 
66
}
 
67
 
 
68
TEST(XmlBuilderTest, TestNesting2) {
 
69
  XmlBuilder builder;
 
70
  XmlParser::ParseXml(&builder,
 
71
    "<top><fifth><deeper><and><deeper/></and><sibling><leaf/>"
 
72
    "</sibling></deeper></fifth><first/><second><third></third>"
 
73
    "</second></top>");
 
74
  EXPECT_EQ("<top><fifth><deeper><and><deeper/></and><sibling><leaf/>"
 
75
    "</sibling></deeper></fifth><first/><second><third/>"
 
76
    "</second></top>", builder.BuiltElement()->Str());
 
77
}
 
78
 
 
79
TEST(XmlBuilderTest, TestQuoting1) {
 
80
  XmlBuilder builder;
 
81
  XmlParser::ParseXml(&builder, "<testing a='>'/>");
 
82
  EXPECT_EQ("<testing a=\"&gt;\"/>", builder.BuiltElement()->Str());
 
83
}
 
84
 
 
85
TEST(XmlBuilderTest, TestQuoting2) {
 
86
  XmlBuilder builder;
 
87
  XmlParser::ParseXml(&builder, "<testing a='&lt;>&amp;&quot;'/>");
 
88
  EXPECT_EQ("<testing a=\"&lt;&gt;&amp;&quot;\"/>",
 
89
      builder.BuiltElement()->Str());
 
90
}
 
91
 
 
92
TEST(XmlBuilderTest, TestQuoting3) {
 
93
  XmlBuilder builder;
 
94
  XmlParser::ParseXml(&builder, "<testing a='so &quot;important&quot;'/>");
 
95
  EXPECT_EQ("<testing a=\"so &quot;important&quot;\"/>",
 
96
      builder.BuiltElement()->Str());
 
97
}
 
98
 
 
99
TEST(XmlBuilderTest, TestQuoting4) {
 
100
  XmlBuilder builder;
 
101
  XmlParser::ParseXml(&builder, "<testing a='&quot;important&quot;, yes'/>");
 
102
  EXPECT_EQ("<testing a=\"&quot;important&quot;, yes\"/>",
 
103
      builder.BuiltElement()->Str());
 
104
}
 
105
 
 
106
TEST(XmlBuilderTest, TestQuoting5) {
 
107
  XmlBuilder builder;
 
108
  XmlParser::ParseXml(&builder,
 
109
      "<testing a='&lt;what is &quot;important&quot;&gt;'/>");
 
110
  EXPECT_EQ("<testing a=\"&lt;what is &quot;important&quot;&gt;\"/>",
 
111
      builder.BuiltElement()->Str());
 
112
}
 
113
 
 
114
TEST(XmlBuilderTest, TestText1) {
 
115
  XmlBuilder builder;
 
116
  XmlParser::ParseXml(&builder, "<testing>></testing>");
 
117
  EXPECT_EQ("<testing>&gt;</testing>", builder.BuiltElement()->Str());
 
118
}
 
119
 
 
120
TEST(XmlBuilderTest, TestText2) {
 
121
  XmlBuilder builder;
 
122
  XmlParser::ParseXml(&builder, "<testing>&lt;>&amp;&quot;</testing>");
 
123
  EXPECT_EQ("<testing>&lt;&gt;&amp;\"</testing>",
 
124
      builder.BuiltElement()->Str());
 
125
}
 
126
 
 
127
TEST(XmlBuilderTest, TestText3) {
 
128
  XmlBuilder builder;
 
129
  XmlParser::ParseXml(&builder, "<testing>so &lt;important&gt;</testing>");
 
130
  EXPECT_EQ("<testing>so &lt;important&gt;</testing>",
 
131
      builder.BuiltElement()->Str());
 
132
}
 
133
 
 
134
TEST(XmlBuilderTest, TestText4) {
 
135
  XmlBuilder builder;
 
136
  XmlParser::ParseXml(&builder, "<testing>&lt;important&gt;, yes</testing>");
 
137
  EXPECT_EQ("<testing>&lt;important&gt;, yes</testing>",
 
138
      builder.BuiltElement()->Str());
 
139
}
 
140
 
 
141
TEST(XmlBuilderTest, TestText5) {
 
142
  XmlBuilder builder;
 
143
  XmlParser::ParseXml(&builder,
 
144
      "<testing>importance &amp;&lt;important&gt;&amp;</testing>");
 
145
  EXPECT_EQ("<testing>importance &amp;&lt;important&gt;&amp;</testing>",
 
146
      builder.BuiltElement()->Str());
 
147
}
 
148
 
 
149
TEST(XmlBuilderTest, TestNamespace1) {
 
150
  XmlBuilder builder;
 
151
  XmlParser::ParseXml(&builder, "<testing xmlns='foo'/>");
 
152
  EXPECT_EQ("<testing xmlns=\"foo\"/>", builder.BuiltElement()->Str());
 
153
}
 
154
 
 
155
TEST(XmlBuilderTest, TestNamespace2) {
 
156
  XmlBuilder builder;
 
157
  XmlParser::ParseXml(&builder, "<testing xmlns:a='foo' a:b='c'/>");
 
158
  EXPECT_EQ("<testing xmlns:a=\"foo\" a:b=\"c\"/>",
 
159
      builder.BuiltElement()->Str());
 
160
}
 
161
 
 
162
TEST(XmlBuilderTest, TestNamespace3) {
 
163
  XmlBuilder builder;
 
164
  XmlParser::ParseXml(&builder, "<testing xmlns:a=''/>");
 
165
  EXPECT_TRUE(NULL == builder.BuiltElement());
 
166
}
 
167
 
 
168
TEST(XmlBuilderTest, TestNamespace4) {
 
169
  XmlBuilder builder;
 
170
  XmlParser::ParseXml(&builder, "<testing a:b='c'/>");
 
171
  EXPECT_TRUE(NULL == builder.BuiltElement());
 
172
}
 
173
 
 
174
TEST(XmlBuilderTest, TestAttrCollision1) {
 
175
  XmlBuilder builder;
 
176
  XmlParser::ParseXml(&builder, "<testing a='first' a='second'/>");
 
177
  EXPECT_TRUE(NULL == builder.BuiltElement());
 
178
}
 
179
 
 
180
TEST(XmlBuilderTest, TestAttrCollision2) {
 
181
  XmlBuilder builder;
 
182
  XmlParser::ParseXml(&builder,
 
183
      "<testing xmlns:a='foo' xmlns:b='foo' a:x='c' b:x='d'/>");
 
184
  EXPECT_TRUE(NULL == builder.BuiltElement());
 
185
}
 
186
 
 
187
TEST(XmlBuilderTest, TestAttrCollision3) {
 
188
  XmlBuilder builder;
 
189
  XmlParser::ParseXml(&builder,
 
190
      "<testing xmlns:a='foo'><nested xmlns:b='foo' a:x='c' b:x='d'/>"
 
191
      "</testing>");
 
192
  EXPECT_TRUE(NULL == builder.BuiltElement());
 
193
}
 
194