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: webrtc/libjingle/session/transportparser_unittest.cc

Issue 1175243003: Remove webrtc/libjingle/{examples,session}. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/base/gunit.h"
12 #include "webrtc/libjingle/session/p2ptransportparser.h"
13 #include "webrtc/libjingle/session/parsing.h"
14 #include "webrtc/libjingle/session/sessionmessages.h"
15 #include "webrtc/libjingle/xmllite/xmlelement.h"
16 #include "webrtc/libjingle/xmpp/constants.h"
17 #include "webrtc/p2p/base/constants.h"
18
19 using cricket::Candidate;
20 using cricket::Candidates;
21 using cricket::ParseError;
22 using cricket::WriteError;
23
24 class TransportParserTest : public testing::Test {
25 };
26
27 class FakeCandidateTranslator : public cricket::CandidateTranslator {
28 public:
29 void AddMapping(int component, const std::string& channel_name) {
30 name_to_component[channel_name] = component;
31 component_to_name[component] = channel_name;
32 }
33
34 bool GetChannelNameFromComponent(
35 int component, std::string* channel_name) const {
36 if (component_to_name.find(component) == component_to_name.end()) {
37 return false;
38 }
39 *channel_name = component_to_name.find(component)->second;
40 return true;
41 }
42 bool GetComponentFromChannelName(
43 const std::string& channel_name, int* component) const {
44 if (name_to_component.find(channel_name) == name_to_component.end()) {
45 return false;
46 }
47 *component = name_to_component.find(channel_name)->second;
48 return true;
49 }
50
51 std::map<std::string, int> name_to_component;
52 std::map<int, std::string> component_to_name;
53 };
54
55 // Tests that we can properly serialize/deserialize candidates.
56 TEST_F(TransportParserTest, TestP2PTransportWriteAndParseCandidate) {
57 Candidate test_candidate(
58 "", 1, "udp",
59 rtc::SocketAddress("2001:db8:fefe::1", 9999),
60 738197504, "abcdef", "ghijkl", "foo", 50, "");
61 test_candidate.set_network_name("testnet");
62 Candidate test_candidate2(
63 "", 2, "tcp",
64 rtc::SocketAddress("192.168.7.1", 9999),
65 1107296256, "mnopqr", "stuvwx", "bar", 100, "");
66 test_candidate2.set_network_name("testnet2");
67 rtc::SocketAddress host_address("www.google.com", 24601);
68 host_address.SetResolvedIP(rtc::IPAddress(0x0A000001));
69 Candidate test_candidate3(
70 "", 3, "spdy", host_address, 1476395008, "yzabcd",
71 "efghij", "baz", 150, "");
72 test_candidate3.set_network_name("testnet3");
73 WriteError write_error;
74 ParseError parse_error;
75 rtc::scoped_ptr<buzz::XmlElement> elem;
76 cricket::Candidate parsed_candidate;
77 cricket::P2PTransportParser parser;
78
79 FakeCandidateTranslator translator;
80 translator.AddMapping(1, "test");
81 translator.AddMapping(2, "test2");
82 translator.AddMapping(3, "test3");
83
84 EXPECT_TRUE(parser.WriteGingleCandidate(test_candidate, &translator,
85 elem.accept(), &write_error));
86 EXPECT_EQ("", write_error.text);
87 EXPECT_EQ("test", elem->Attr(buzz::QN_NAME));
88 EXPECT_EQ("udp", elem->Attr(cricket::QN_PROTOCOL));
89 EXPECT_EQ("2001:db8:fefe::1", elem->Attr(cricket::QN_ADDRESS));
90 EXPECT_EQ("9999", elem->Attr(cricket::QN_PORT));
91 EXPECT_EQ("0.34", elem->Attr(cricket::QN_PREFERENCE));
92 EXPECT_EQ("abcdef", elem->Attr(cricket::QN_USERNAME));
93 EXPECT_EQ("ghijkl", elem->Attr(cricket::QN_PASSWORD));
94 EXPECT_EQ("foo", elem->Attr(cricket::QN_TYPE));
95 EXPECT_EQ("testnet", elem->Attr(cricket::QN_NETWORK));
96 EXPECT_EQ("50", elem->Attr(cricket::QN_GENERATION));
97
98 EXPECT_TRUE(parser.ParseGingleCandidate(elem.get(), &translator,
99 &parsed_candidate, &parse_error));
100 EXPECT_TRUE(test_candidate.IsEquivalent(parsed_candidate));
101
102 EXPECT_TRUE(parser.WriteGingleCandidate(test_candidate2, &translator,
103 elem.accept(), &write_error));
104 EXPECT_EQ("test2", elem->Attr(buzz::QN_NAME));
105 EXPECT_EQ("tcp", elem->Attr(cricket::QN_PROTOCOL));
106 EXPECT_EQ("192.168.7.1", elem->Attr(cricket::QN_ADDRESS));
107 EXPECT_EQ("9999", elem->Attr(cricket::QN_PORT));
108 EXPECT_EQ("0.51", elem->Attr(cricket::QN_PREFERENCE));
109 EXPECT_EQ("mnopqr", elem->Attr(cricket::QN_USERNAME));
110 EXPECT_EQ("stuvwx", elem->Attr(cricket::QN_PASSWORD));
111 EXPECT_EQ("bar", elem->Attr(cricket::QN_TYPE));
112 EXPECT_EQ("testnet2", elem->Attr(cricket::QN_NETWORK));
113 EXPECT_EQ("100", elem->Attr(cricket::QN_GENERATION));
114
115 EXPECT_TRUE(parser.ParseGingleCandidate(elem.get(), &translator,
116 &parsed_candidate, &parse_error));
117 EXPECT_TRUE(test_candidate2.IsEquivalent(parsed_candidate));
118
119 // Check that an ip is preferred over hostname.
120 EXPECT_TRUE(parser.WriteGingleCandidate(test_candidate3, &translator,
121 elem.accept(), &write_error));
122 EXPECT_EQ("test3", elem->Attr(cricket::QN_NAME));
123 EXPECT_EQ("spdy", elem->Attr(cricket::QN_PROTOCOL));
124 EXPECT_EQ("10.0.0.1", elem->Attr(cricket::QN_ADDRESS));
125 EXPECT_EQ("24601", elem->Attr(cricket::QN_PORT));
126 EXPECT_EQ("0.69", elem->Attr(cricket::QN_PREFERENCE));
127 EXPECT_EQ("yzabcd", elem->Attr(cricket::QN_USERNAME));
128 EXPECT_EQ("efghij", elem->Attr(cricket::QN_PASSWORD));
129 EXPECT_EQ("baz", elem->Attr(cricket::QN_TYPE));
130 EXPECT_EQ("testnet3", elem->Attr(cricket::QN_NETWORK));
131 EXPECT_EQ("150", elem->Attr(cricket::QN_GENERATION));
132
133 EXPECT_TRUE(parser.ParseGingleCandidate(elem.get(), &translator,
134 &parsed_candidate, &parse_error));
135 EXPECT_TRUE(test_candidate3.IsEquivalent(parsed_candidate));
136 }
OLDNEW
« no previous file with comments | « webrtc/libjingle/session/transportparser.cc ('k') | webrtc/libjingle/session/tunnel/pseudotcpchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698