• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "talk/base/gunit.h"
30 #include "talk/xmllite/qname.h"
31 
32 using buzz::StaticQName;
33 using buzz::QName;
34 
TEST(QNameTest,TestTrivial)35 TEST(QNameTest, TestTrivial) {
36   QName name("test");
37   EXPECT_EQ(name.LocalPart(), "test");
38   EXPECT_EQ(name.Namespace(), "");
39 }
40 
TEST(QNameTest,TestSplit)41 TEST(QNameTest, TestSplit) {
42   QName name("a:test");
43   EXPECT_EQ(name.LocalPart(), "test");
44   EXPECT_EQ(name.Namespace(), "a");
45   QName name2("a-very:long:namespace:test-this");
46   EXPECT_EQ(name2.LocalPart(), "test-this");
47   EXPECT_EQ(name2.Namespace(), "a-very:long:namespace");
48 }
49 
TEST(QNameTest,TestMerge)50 TEST(QNameTest, TestMerge) {
51   QName name("a", "test");
52   EXPECT_EQ(name.LocalPart(), "test");
53   EXPECT_EQ(name.Namespace(), "a");
54   EXPECT_EQ(name.Merged(), "a:test");
55   QName name2("a-very:long:namespace", "test-this");
56   EXPECT_EQ(name2.LocalPart(), "test-this");
57   EXPECT_EQ(name2.Namespace(), "a-very:long:namespace");
58   EXPECT_EQ(name2.Merged(), "a-very:long:namespace:test-this");
59 }
60 
TEST(QNameTest,TestAssignment)61 TEST(QNameTest, TestAssignment) {
62   QName name("a", "test");
63   // copy constructor
64   QName namecopy(name);
65   EXPECT_EQ(namecopy.LocalPart(), "test");
66   EXPECT_EQ(namecopy.Namespace(), "a");
67   QName nameassigned("");
68   nameassigned = name;
69   EXPECT_EQ(nameassigned.LocalPart(), "test");
70   EXPECT_EQ(nameassigned.Namespace(), "a");
71 }
72 
TEST(QNameTest,TestConstAssignment)73 TEST(QNameTest, TestConstAssignment) {
74   StaticQName name = { "a", "test" };
75   QName namecopy(name);
76   EXPECT_EQ(namecopy.LocalPart(), "test");
77   EXPECT_EQ(namecopy.Namespace(), "a");
78   QName nameassigned("");
79   nameassigned = name;
80   EXPECT_EQ(nameassigned.LocalPart(), "test");
81   EXPECT_EQ(nameassigned.Namespace(), "a");
82 }
83 
TEST(QNameTest,TestEquality)84 TEST(QNameTest, TestEquality) {
85   QName name("a-very:long:namespace:test-this");
86   QName name2("a-very:long:namespace", "test-this");
87   QName name3("a-very:long:namespaxe", "test-this");
88   EXPECT_TRUE(name == name2);
89   EXPECT_FALSE(name == name3);
90 }
91 
TEST(QNameTest,TestCompare)92 TEST(QNameTest, TestCompare) {
93   QName name("a");
94   QName name2("nsa", "a");
95   QName name3("nsa", "b");
96   QName name4("nsb", "b");
97 
98   EXPECT_TRUE(name < name2);
99   EXPECT_FALSE(name2 < name);
100 
101   EXPECT_FALSE(name2 < name2);
102 
103   EXPECT_TRUE(name2 < name3);
104   EXPECT_FALSE(name3 < name2);
105 
106   EXPECT_TRUE(name3 < name4);
107   EXPECT_FALSE(name4 < name3);
108 }
109 
TEST(QNameTest,TestStaticQName)110 TEST(QNameTest, TestStaticQName) {
111   const StaticQName const_name1 = { "namespace", "local-name1" };
112   const StaticQName const_name2 = { "namespace", "local-name2" };
113   const QName name("namespace", "local-name1");
114   const QName name1 = const_name1;
115   const QName name2 = const_name2;
116 
117   EXPECT_TRUE(name == const_name1);
118   EXPECT_TRUE(const_name1 == name);
119   EXPECT_FALSE(name != const_name1);
120   EXPECT_FALSE(const_name1 != name);
121 
122   EXPECT_TRUE(name == name1);
123   EXPECT_TRUE(name1 == name);
124   EXPECT_FALSE(name != name1);
125   EXPECT_FALSE(name1 != name);
126 
127   EXPECT_FALSE(name == name2);
128   EXPECT_FALSE(name2 == name);
129   EXPECT_TRUE(name != name2);
130   EXPECT_TRUE(name2 != name);
131 }
132