Skip to content

Commit

Permalink
Create a copy of talk/xmllite under webrtc/xmllite.
Browse files Browse the repository at this point in the history
BUG=3379
R=andrew@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/22249004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7027 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
henrike@webrtc.org committed Sep 2, 2014
1 parent 6f729e8 commit d72a759
Show file tree
Hide file tree
Showing 26 changed files with 3,153 additions and 0 deletions.
4 changes: 4 additions & 0 deletions webrtc/build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'gen_core_neon_offsets_gyp%': '<(gen_core_neon_offsets_gyp)',
'webrtc_vp8_dir%': '<(webrtc_vp8_dir)',
'include_opus%': '<(include_opus)',
'rtc_relative_path%': 1,
'rbe_components_path%': '<(rbe_components_path)',
'external_libraries%': '0',
'json_root%': '<(DEPTH)/third_party/jsoncpp/source/include/',
Expand Down Expand Up @@ -178,6 +179,9 @@
'<!@(pkg-config --cflags dbus-glib-1)',
],
}],
['rtc_relative_path==1', {
'defines': ['EXPAT_RELATIVE_PATH',],
}],
['enable_video==1', {
'defines': ['WEBRTC_MODULE_UTILITY_VIDEO',],
}],
Expand Down
1 change: 1 addition & 0 deletions webrtc/build/merge_libs.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'merge_libs_dependencies': [
'../webrtc.gyp:webrtc',
'../sound/sound.gyp:rtc_sound',
'../libjingle/xmllite/xmllite.gyp:rtc_xmllite',
],
},
'targets': [
Expand Down
22 changes: 22 additions & 0 deletions webrtc/libjingle/xmllite/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
henrika@webrtc.org
henrike@webrtc.org
henrikg@webrtc.org
hta@webrtc.org
jiayl@webrtc.org
juberti@webrtc.org
mflodman@webrtc.org
perkj@webrtc.org
pthatcher@webrtc.org
sergeyu@chromium.org
tommi@webrtc.org

per-file BUILD.gn=kjellander@webrtc.org
78 changes: 78 additions & 0 deletions webrtc/libjingle/xmllite/qname.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#include "webrtc/libjingle/xmllite/qname.h"

namespace buzz {

QName::QName() {
}

QName::QName(const QName& qname)
: namespace_(qname.namespace_),
local_part_(qname.local_part_) {
}

QName::QName(const StaticQName& const_value)
: namespace_(const_value.ns),
local_part_(const_value.local) {
}

QName::QName(const std::string& ns, const std::string& local)
: namespace_(ns),
local_part_(local) {
}

QName::QName(const std::string& merged_or_local) {
size_t i = merged_or_local.rfind(':');
if (i == std::string::npos) {
local_part_ = merged_or_local;
} else {
namespace_ = merged_or_local.substr(0, i);
local_part_ = merged_or_local.substr(i + 1);
}
}

QName::~QName() {
}

std::string QName::Merged() const {
if (namespace_[0] == '\0')
return local_part_;

std::string result;
result.reserve(namespace_.length() + 1 + local_part_.length());
result += namespace_;
result += ':';
result += local_part_;
return result;
}

bool QName::IsEmpty() const {
return namespace_.empty() && local_part_.empty();
}

int QName::Compare(const StaticQName& other) const {
int result = local_part_.compare(other.local);
if (result != 0)
return result;

return namespace_.compare(other.ns);
}

int QName::Compare(const QName& other) const {
int result = local_part_.compare(other.local_part_);
if (result != 0)
return result;

return namespace_.compare(other.namespace_);
}

} // namespace buzz
83 changes: 83 additions & 0 deletions webrtc/libjingle/xmllite/qname.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#ifndef WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
#define WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_

#include <string>

namespace buzz {

class QName;

// StaticQName is used to represend constant quailified names. They
// can be initialized statically and don't need intializers code, e.g.
// const StaticQName QN_FOO = { "foo_namespace", "foo" };
//
// Beside this use case, QName should be used everywhere
// else. StaticQName instances are implicitly converted to QName
// objects.
struct StaticQName {
const char* const ns;
const char* const local;

bool operator==(const QName& other) const;
bool operator!=(const QName& other) const;
};

class QName {
public:
QName();
QName(const QName& qname);
QName(const StaticQName& const_value);
QName(const std::string& ns, const std::string& local);
explicit QName(const std::string& merged_or_local);
~QName();

const std::string& Namespace() const { return namespace_; }
const std::string& LocalPart() const { return local_part_; }
std::string Merged() const;
bool IsEmpty() const;

int Compare(const StaticQName& other) const;
int Compare(const QName& other) const;

bool operator==(const StaticQName& other) const {
return Compare(other) == 0;
}
bool operator==(const QName& other) const {
return Compare(other) == 0;
}
bool operator!=(const StaticQName& other) const {
return Compare(other) != 0;
}
bool operator!=(const QName& other) const {
return Compare(other) != 0;
}
bool operator<(const QName& other) const {
return Compare(other) < 0;
}

private:
std::string namespace_;
std::string local_part_;
};

inline bool StaticQName::operator==(const QName& other) const {
return other.Compare(*this) == 0;
}

inline bool StaticQName::operator!=(const QName& other) const {
return other.Compare(*this) != 0;
}

} // namespace buzz

#endif // WEBRTC_LIBJINGLE_XMLLITE_QNAME_H_
114 changes: 114 additions & 0 deletions webrtc/libjingle/xmllite/qname_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#include <string>
#include "webrtc/libjingle/xmllite/qname.h"
#include "webrtc/base/gunit.h"

using buzz::StaticQName;
using buzz::QName;

TEST(QNameTest, TestTrivial) {
QName name("test");
EXPECT_EQ(name.LocalPart(), "test");
EXPECT_EQ(name.Namespace(), "");
}

TEST(QNameTest, TestSplit) {
QName name("a:test");
EXPECT_EQ(name.LocalPart(), "test");
EXPECT_EQ(name.Namespace(), "a");
QName name2("a-very:long:namespace:test-this");
EXPECT_EQ(name2.LocalPart(), "test-this");
EXPECT_EQ(name2.Namespace(), "a-very:long:namespace");
}

TEST(QNameTest, TestMerge) {
QName name("a", "test");
EXPECT_EQ(name.LocalPart(), "test");
EXPECT_EQ(name.Namespace(), "a");
EXPECT_EQ(name.Merged(), "a:test");
QName name2("a-very:long:namespace", "test-this");
EXPECT_EQ(name2.LocalPart(), "test-this");
EXPECT_EQ(name2.Namespace(), "a-very:long:namespace");
EXPECT_EQ(name2.Merged(), "a-very:long:namespace:test-this");
}

TEST(QNameTest, TestAssignment) {
QName name("a", "test");
// copy constructor
QName namecopy(name);
EXPECT_EQ(namecopy.LocalPart(), "test");
EXPECT_EQ(namecopy.Namespace(), "a");
QName nameassigned("");
nameassigned = name;
EXPECT_EQ(nameassigned.LocalPart(), "test");
EXPECT_EQ(nameassigned.Namespace(), "a");
}

TEST(QNameTest, TestConstAssignment) {
StaticQName name = { "a", "test" };
QName namecopy(name);
EXPECT_EQ(namecopy.LocalPart(), "test");
EXPECT_EQ(namecopy.Namespace(), "a");
QName nameassigned("");
nameassigned = name;
EXPECT_EQ(nameassigned.LocalPart(), "test");
EXPECT_EQ(nameassigned.Namespace(), "a");
}

TEST(QNameTest, TestEquality) {
QName name("a-very:long:namespace:test-this");
QName name2("a-very:long:namespace", "test-this");
QName name3("a-very:long:namespaxe", "test-this");
EXPECT_TRUE(name == name2);
EXPECT_FALSE(name == name3);
}

TEST(QNameTest, TestCompare) {
QName name("a");
QName name2("nsa", "a");
QName name3("nsa", "b");
QName name4("nsb", "b");

EXPECT_TRUE(name < name2);
EXPECT_FALSE(name2 < name);

EXPECT_FALSE(name2 < name2);

EXPECT_TRUE(name2 < name3);
EXPECT_FALSE(name3 < name2);

EXPECT_TRUE(name3 < name4);
EXPECT_FALSE(name4 < name3);
}

TEST(QNameTest, TestStaticQName) {
const StaticQName const_name1 = { "namespace", "local-name1" };
const StaticQName const_name2 = { "namespace", "local-name2" };
const QName name("namespace", "local-name1");
const QName name1 = const_name1;
const QName name2 = const_name2;

EXPECT_TRUE(name == const_name1);
EXPECT_TRUE(const_name1 == name);
EXPECT_FALSE(name != const_name1);
EXPECT_FALSE(const_name1 != name);

EXPECT_TRUE(name == name1);
EXPECT_TRUE(name1 == name);
EXPECT_FALSE(name != name1);
EXPECT_FALSE(name1 != name);

EXPECT_FALSE(name == name2);
EXPECT_FALSE(name2 == name);
EXPECT_TRUE(name != name2);
EXPECT_TRUE(name2 != name);
}
Loading

0 comments on commit d72a759

Please sign in to comment.