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

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

Issue 8468015: The host sends simple log entries to the server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 9 years 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
« no previous file with comments | « remoting/host/server_log_entry.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h"
6 #include "remoting/host/server_log_entry.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
9
10 using buzz::XmlAttr;
11 using buzz::XmlElement;
12
13 namespace remoting {
14
15 class ServerLogEntryTest : public testing::Test {
16 protected:
17 // Verifies a logging stanza.
18 // |keyValuePairs| lists the keys that must have specified values, and |keys|
19 // lists the keys that must be present, but may have arbitrary values.
20 // There must be no other keys.
21 static bool VerifyStanza(
22 const std::map<std::string, std::string>& key_value_pairs,
23 const std::set<std::string> keys,
24 const XmlElement* elem,
25 std::string* error) {
26 int attrCount = 0;
27 for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL;
28 attr = attr->NextAttr(), attrCount++) {
29 if (attr->Name().Namespace().length() != 0) {
30 *error = "attribute has non-empty namespace " +
31 attr->Name().Namespace();
32 return false;
33 }
34 const std::string& key = attr->Name().LocalPart();
35 const std::string& value = attr->Value();
36 std::map<std::string, std::string>::const_iterator iter =
37 key_value_pairs.find(key);
38 if (iter == key_value_pairs.end()) {
39 if (keys.find(key) == keys.end()) {
40 *error = "unexpected attribute " + key;
41 return false;
42 }
43 } else {
44 if (iter->second != value) {
45 *error = "attribute " + key + " has value " + iter->second +
46 ": expected " + value;
47 return false;
48 }
49 }
50 }
51 int attr_count_expected = key_value_pairs.size() + keys.size();
52 if (attrCount != attr_count_expected) {
53 std::stringstream s;
54 s << "stanza has " << attrCount << " keys: expected "
55 << attr_count_expected;
56 *error = s.str();
57 return false;
58 }
59 return true;
60 }
61 };
62
63 TEST_F(ServerLogEntryTest, MakeSessionStateChange) {
64 scoped_ptr<ServerLogEntry> entry(
65 ServerLogEntry::MakeSessionStateChange(true));
66 scoped_ptr<XmlElement> stanza(entry->ToStanza());
67 std::string error;
68 std::map<std::string, std::string> key_value_pairs;
69 key_value_pairs["role"] = "host";
70 key_value_pairs["event-name"] = "session-state";
71 key_value_pairs["session-state"] = "connected";
72 std::set<std::string> keys;
73 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) <<
74 error;
75 }
76
77 TEST_F(ServerLogEntryTest, AddHostFields) {
78 scoped_ptr<ServerLogEntry> entry(
79 ServerLogEntry::MakeSessionStateChange(true));
80 entry->AddHostFields();
81 scoped_ptr<XmlElement> stanza(entry->ToStanza());
82 std::string error;
83 std::map<std::string, std::string> key_value_pairs;
84 key_value_pairs["role"] = "host";
85 key_value_pairs["event-name"] = "session-state";
86 key_value_pairs["session-state"] = "connected";
87 std::set<std::string> keys;
88 keys.insert("cpu");
89 #if defined(OS_WIN)
90 key_value_pairs["os-name"] = "Windows";
91 keys.insert("os-version");
92 #elif defined(OS_MACOSX)
93 key_value_pairs["os-name"] = "Mac";
94 keys.insert("os-version");
95 #elif defined(OS_CHROMEOS)
96 key_value_pairs["os-name"] = "ChromeOS";
97 keys.insert("os-version");
98 #elif defined(OS_LINUX)
99 key_value_pairs["os-name"] = "Linux";
100 #endif
101 ASSERT_TRUE(VerifyStanza(key_value_pairs, keys, stanza.get(), &error)) <<
102 error;
103 }
104
105 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/server_log_entry.cc ('k') | remoting/host/simple_host_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698