OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/jingle_glue/server_log_entry_unittest.h" | 5 #include "remoting/jingle_glue/server_log_entry_unittest.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
10 | 11 |
| 12 using buzz::QName; |
11 using buzz::XmlAttr; | 13 using buzz::XmlAttr; |
12 using buzz::XmlElement; | 14 using buzz::XmlElement; |
13 | 15 |
14 namespace remoting { | 16 namespace remoting { |
15 | 17 |
| 18 const char kJabberClientNamespace[] = "jabber:client"; |
| 19 const char kChromotingNamespace[] = "google:remoting"; |
| 20 |
| 21 XmlElement* GetLogElementFromStanza(XmlElement* stanza) { |
| 22 if (stanza->Name() != QName(kJabberClientNamespace, "iq")) { |
| 23 ADD_FAILURE() << "Expected element 'iq'"; |
| 24 return NULL; |
| 25 } |
| 26 XmlElement* log_element = stanza->FirstChild()->AsElement(); |
| 27 if (log_element->Name() != QName(kChromotingNamespace, "log")) { |
| 28 ADD_FAILURE() << "Expected element 'log'"; |
| 29 return NULL; |
| 30 } |
| 31 if (log_element->NextChild()) { |
| 32 ADD_FAILURE() << "Expected only 1 child of 'iq'"; |
| 33 return NULL; |
| 34 } |
| 35 return log_element; |
| 36 } |
| 37 |
| 38 XmlElement* GetSingleLogEntryFromStanza(XmlElement* stanza) { |
| 39 XmlElement* log_element = GetLogElementFromStanza(stanza); |
| 40 if (!log_element) { |
| 41 // Test failure already recorded, so just return NULL here. |
| 42 return NULL; |
| 43 } |
| 44 XmlElement* entry = log_element->FirstChild()->AsElement(); |
| 45 if (entry->Name() != QName(kChromotingNamespace, "entry")) { |
| 46 ADD_FAILURE() << "Expected element 'entry'"; |
| 47 return NULL; |
| 48 } |
| 49 if (entry->NextChild()) { |
| 50 ADD_FAILURE() << "Expected only 1 child of 'log'"; |
| 51 return NULL; |
| 52 } |
| 53 return entry; |
| 54 } |
| 55 |
16 bool VerifyStanza( | 56 bool VerifyStanza( |
17 const std::map<std::string, std::string>& key_value_pairs, | 57 const std::map<std::string, std::string>& key_value_pairs, |
18 const std::set<std::string> keys, | 58 const std::set<std::string> keys, |
19 const XmlElement* elem, | 59 const XmlElement* elem, |
20 std::string* error) { | 60 std::string* error) { |
21 int attrCount = 0; | 61 int attrCount = 0; |
22 for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL; | 62 for (const XmlAttr* attr = elem->FirstAttr(); attr != NULL; |
23 attr = attr->NextAttr(), attrCount++) { | 63 attr = attr->NextAttr(), attrCount++) { |
24 if (attr->Name().Namespace().length() != 0) { | 64 if (attr->Name().Namespace().length() != 0) { |
25 *error = "attribute has non-empty namespace " + | 65 *error = "attribute has non-empty namespace " + |
(...skipping 22 matching lines...) Expand all Loading... |
48 std::stringstream s; | 88 std::stringstream s; |
49 s << "stanza has " << attrCount << " keys: expected " | 89 s << "stanza has " << attrCount << " keys: expected " |
50 << attr_count_expected; | 90 << attr_count_expected; |
51 *error = s.str(); | 91 *error = s.str(); |
52 return false; | 92 return false; |
53 } | 93 } |
54 return true; | 94 return true; |
55 } | 95 } |
56 | 96 |
57 } // namespace remoting | 97 } // namespace remoting |
OLD | NEW |