Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: remoting/protocol/server_log_entry_unittest.cc

Issue 282063005: Pull out common code from client and host versions of ServerLogEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/protocol/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 namespace protocol {
16
17 bool VerifyStanza(
18 const std::map<std::string, std::string>& key_value_pairs,
19 const std::set<std::string> keys,
20 const XmlElement* elem,
21 std::string* error) {
22 int attrCount = 0;
23 for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL;
24 attr = attr->NextAttr(), attrCount++) {
25 if (attr->Name().Namespace().length() != 0) {
26 *error = "attribute has non-empty namespace " +
27 attr->Name().Namespace();
28 return false;
29 }
30 const std::string& key = attr->Name().LocalPart();
31 const std::string& value = attr->Value();
32 std::map<std::string, std::string>::const_iterator iter =
33 key_value_pairs.find(key);
34 if (iter == key_value_pairs.end()) {
35 if (keys.find(key) == keys.end()) {
36 *error = "unexpected attribute " + key;
37 return false;
38 }
39 } else {
40 if (iter->second != value) {
41 *error = "attribute " + key + " has value " + iter->second +
42 ": expected " + value;
43 return false;
44 }
45 }
46 }
47 int attr_count_expected = key_value_pairs.size() + keys.size();
48 if (attrCount != attr_count_expected) {
49 std::stringstream s;
50 s << "stanza has " << attrCount << " keys: expected "
51 << attr_count_expected;
52 *error = s.str();
53 return false;
54 }
55 return true;
56 }
57
58 } // namespace protocol
59 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698