OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "remoting/jingle_glue/server_log_entry_unittest.h" |
| 6 |
| 7 #include <sstream> |
| 8 |
| 9 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 10 |
| 11 using buzz::XmlAttr; |
| 12 using buzz::XmlElement; |
| 13 |
| 14 namespace remoting { |
| 15 |
| 16 bool VerifyStanza( |
| 17 const std::map<std::string, std::string>& key_value_pairs, |
| 18 const std::set<std::string> keys, |
| 19 const XmlElement* elem, |
| 20 std::string* error) { |
| 21 int attrCount = 0; |
| 22 for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL; |
| 23 attr = attr->NextAttr(), attrCount++) { |
| 24 if (attr->Name().Namespace().length() != 0) { |
| 25 *error = "attribute has non-empty namespace " + |
| 26 attr->Name().Namespace(); |
| 27 return false; |
| 28 } |
| 29 const std::string& key = attr->Name().LocalPart(); |
| 30 const std::string& value = attr->Value(); |
| 31 std::map<std::string, std::string>::const_iterator iter = |
| 32 key_value_pairs.find(key); |
| 33 if (iter == key_value_pairs.end()) { |
| 34 if (keys.find(key) == keys.end()) { |
| 35 *error = "unexpected attribute " + key; |
| 36 return false; |
| 37 } |
| 38 } else { |
| 39 if (iter->second != value) { |
| 40 *error = "attribute " + key + " has value " + iter->second + |
| 41 ": expected " + value; |
| 42 return false; |
| 43 } |
| 44 } |
| 45 } |
| 46 int attr_count_expected = key_value_pairs.size() + keys.size(); |
| 47 if (attrCount != attr_count_expected) { |
| 48 std::stringstream s; |
| 49 s << "stanza has " << attrCount << " keys: expected " |
| 50 << attr_count_expected; |
| 51 *error = s.str(); |
| 52 return false; |
| 53 } |
| 54 return true; |
| 55 } |
| 56 |
| 57 } // namespace remoting |
OLD | NEW |