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

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, 1 month 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 (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(
Sergey Ulanov 2011/11/22 02:01:43 nit:VerifyStanza
simonmorris 2011/11/22 23:27:35 Done.
22 const std::map<std::string, std::string>& keyValuePairs,
Sergey Ulanov 2011/11/22 02:01:43 nit:key_value_pair
simonmorris 2011/11/22 23:27:35 Done.
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();
Sergey Ulanov 2011/11/22 02:01:43 nit: + must be on the previous line. We have diffe
simonmorris 2011/11/22 23:27:35 Done.
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 keyValuePairs.find(key);
38 if (iter == keyValuePairs.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;
Sergey Ulanov 2011/11/22 02:01:43 nit: + must be on the previous line.
simonmorris 2011/11/22 23:27:35 Done.
47 return false;
48 }
49 }
50 }
51 int attrCountExpected = keyValuePairs.size() + keys.size();
Sergey Ulanov 2011/11/22 02:01:43 attr_count_expected
simonmorris 2011/11/22 23:27:35 Done.
52 if (attrCount != attrCountExpected) {
53 std::stringstream s;
54 s << "stanza has " << attrCount << " keys: expected "
55 << attrCountExpected;
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> keyValuePairs;
Sergey Ulanov 2011/11/22 02:01:43 not: key_value_pairs
simonmorris 2011/11/22 23:27:35 Done.
69 keyValuePairs["role"] = "host";
70 keyValuePairs["event-name"] = "session-state";
71 keyValuePairs["session-state"] = "connected";
72 std::set<std::string> keys;
73 ASSERT_TRUE(verifyStanza(keyValuePairs, keys, stanza.get(), &error)) << error;
74 }
75
76 TEST_F(ServerLogEntryTest, AddHostFields) {
77 scoped_ptr<ServerLogEntry> entry(
78 ServerLogEntry::MakeSessionStateChange(true));
79 entry->AddHostFields();
80 scoped_ptr<XmlElement> stanza(entry->ToStanza());
81 std::string error;
82 std::map<std::string, std::string> keyValuePairs;
Sergey Ulanov 2011/11/22 02:01:43 same here
simonmorris 2011/11/22 23:27:35 Done.
83 keyValuePairs["role"] = "host";
84 keyValuePairs["event-name"] = "session-state";
85 keyValuePairs["session-state"] = "connected";
86 std::set<std::string> keys;
87 keys.insert("cpu");
88 #if defined(OS_WIN)
89 keyValuePairs["os-name"] = "Windows";
90 keys.insert("os-version");
91 #elif defined(OS_MACOSX)
92 keyValuePairs["os-name"] = "Mac";
93 keys.insert("os-version");
94 #elif defined(OS_CHROMEOS)
95 keyValuePairs["os-name"] = "ChromeOS";
96 keys.insert("os-version");
97 #elif defined(OS_LINUX)
98 keyValuePairs["os-name"] = "Linux";
99 #endif
100 ASSERT_TRUE(verifyStanza(keyValuePairs, keys, stanza.get(), &error)) << error;
101 }
102
103 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698