1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/signaling/server_log_entry_unittest.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
14 using buzz::XmlElement
;
18 const char kJabberClientNamespace
[] = "jabber:client";
19 const char kChromotingNamespace
[] = "google:remoting";
21 XmlElement
* GetLogElementFromStanza(XmlElement
* stanza
) {
22 if (stanza
->Name() != QName(kJabberClientNamespace
, "iq")) {
23 ADD_FAILURE() << "Expected element 'iq'";
26 XmlElement
* log_element
= stanza
->FirstChild()->AsElement();
27 if (log_element
->Name() != QName(kChromotingNamespace
, "log")) {
28 ADD_FAILURE() << "Expected element 'log'";
31 if (log_element
->NextChild()) {
32 ADD_FAILURE() << "Expected only 1 child of 'iq'";
38 XmlElement
* GetSingleLogEntryFromStanza(XmlElement
* stanza
) {
39 XmlElement
* log_element
= GetLogElementFromStanza(stanza
);
41 // Test failure already recorded, so just return NULL here.
44 XmlElement
* entry
= log_element
->FirstChild()->AsElement();
45 if (entry
->Name() != QName(kChromotingNamespace
, "entry")) {
46 ADD_FAILURE() << "Expected element 'entry'";
49 if (entry
->NextChild()) {
50 ADD_FAILURE() << "Expected only 1 child of 'log'";
57 const std::map
<std::string
, std::string
>& key_value_pairs
,
58 const std::set
<std::string
> keys
,
59 const XmlElement
* elem
,
62 for (const XmlAttr
* attr
= elem
->FirstAttr(); attr
!= NULL
;
63 attr
= attr
->NextAttr(), attrCount
++) {
64 if (attr
->Name().Namespace().length() != 0) {
65 *error
= "attribute has non-empty namespace " +
66 attr
->Name().Namespace();
69 const std::string
& key
= attr
->Name().LocalPart();
70 const std::string
& value
= attr
->Value();
71 std::map
<std::string
, std::string
>::const_iterator iter
=
72 key_value_pairs
.find(key
);
73 if (iter
== key_value_pairs
.end()) {
74 if (keys
.find(key
) == keys
.end()) {
75 *error
= "unexpected attribute " + key
;
79 if (iter
->second
!= value
) {
80 *error
= "attribute " + key
+ " has value " + iter
->second
+
81 ": expected " + value
;
86 int attr_count_expected
= key_value_pairs
.size() + keys
.size();
87 if (attrCount
!= attr_count_expected
) {
89 s
<< "stanza has " << attrCount
<< " keys: expected "
90 << attr_count_expected
;
97 } // namespace remoting