OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 audio.release()); | 52 audio.release()); |
53 | 53 |
54 video->AddCodec(cricket::VideoCodec(120, "VP8")); | 54 video->AddCodec(cricket::VideoCodec(120, "VP8")); |
55 desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, | 55 desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, |
56 video.release()); | 56 video.release()); |
57 | 57 |
58 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo( | 58 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo( |
59 cricket::CN_AUDIO, | 59 cricket::CN_AUDIO, |
60 cricket::TransportDescription( | 60 cricket::TransportDescription( |
61 std::vector<std::string>(), kCandidateUfragVoice, kCandidatePwdVoice, | 61 std::vector<std::string>(), kCandidateUfragVoice, kCandidatePwdVoice, |
62 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL)))); | 62 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, nullptr)))); |
63 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo( | 63 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo( |
64 cricket::CN_VIDEO, | 64 cricket::CN_VIDEO, |
65 cricket::TransportDescription( | 65 cricket::TransportDescription( |
66 std::vector<std::string>(), kCandidateUfragVideo, kCandidatePwdVideo, | 66 std::vector<std::string>(), kCandidateUfragVideo, kCandidatePwdVideo, |
67 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL)))); | 67 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, nullptr)))); |
68 return desc; | 68 return desc; |
69 } | 69 } |
70 | 70 |
71 class JsepSessionDescriptionTest : public testing::Test { | 71 class JsepSessionDescriptionTest : public testing::Test { |
72 protected: | 72 protected: |
73 virtual void SetUp() { | 73 virtual void SetUp() { |
74 int port = 1234; | 74 int port = 1234; |
75 rtc::SocketAddress address("127.0.0.1", port++); | 75 rtc::SocketAddress address("127.0.0.1", port++); |
76 cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | 76 cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
77 address, 1, "", "", "local", 0, "1"); | 77 address, 1, "", "", "local", 0, "1"); |
78 candidate_ = candidate; | 78 candidate_ = candidate; |
79 const std::string session_id = | 79 const std::string session_id = |
80 rtc::ToString(rtc::CreateRandomId64()); | 80 rtc::ToString(rtc::CreateRandomId64()); |
81 const std::string session_version = | 81 const std::string session_version = |
82 rtc::ToString(rtc::CreateRandomId()); | 82 rtc::ToString(rtc::CreateRandomId()); |
83 jsep_desc_.reset(new JsepSessionDescription("dummy")); | 83 jsep_desc_.reset(new JsepSessionDescription("dummy")); |
84 ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(), | 84 ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(), |
85 session_id, session_version)); | 85 session_id, session_version)); |
86 } | 86 } |
87 | 87 |
88 std::string Serialize(const SessionDescriptionInterface* desc) { | 88 std::string Serialize(const SessionDescriptionInterface* desc) { |
89 std::string sdp; | 89 std::string sdp; |
90 EXPECT_TRUE(desc->ToString(&sdp)); | 90 EXPECT_TRUE(desc->ToString(&sdp)); |
91 EXPECT_FALSE(sdp.empty()); | 91 EXPECT_FALSE(sdp.empty()); |
92 return sdp; | 92 return sdp; |
93 } | 93 } |
94 | 94 |
95 SessionDescriptionInterface* DeSerialize(const std::string& sdp) { | 95 SessionDescriptionInterface* DeSerialize(const std::string& sdp) { |
96 JsepSessionDescription* desc(new JsepSessionDescription("dummy")); | 96 JsepSessionDescription* desc(new JsepSessionDescription("dummy")); |
97 EXPECT_TRUE(desc->Initialize(sdp, NULL)); | 97 EXPECT_TRUE(desc->Initialize(sdp, nullptr)); |
98 return desc; | 98 return desc; |
99 } | 99 } |
100 | 100 |
101 cricket::Candidate candidate_; | 101 cricket::Candidate candidate_; |
102 std::unique_ptr<JsepSessionDescription> jsep_desc_; | 102 std::unique_ptr<JsepSessionDescription> jsep_desc_; |
103 }; | 103 }; |
104 | 104 |
105 // Test that number_of_mediasections() returns the number of media contents in | 105 // Test that number_of_mediasections() returns the number of media contents in |
106 // a session description. | 106 // a session description. |
107 TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) { | 107 TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) { |
108 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections()); | 108 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections()); |
109 } | 109 } |
110 | 110 |
111 // Test that we can add a candidate to a session description without MID. | 111 // Test that we can add a candidate to a session description without MID. |
112 TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) { | 112 TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) { |
113 JsepIceCandidate jsep_candidate("", 0, candidate_); | 113 JsepIceCandidate jsep_candidate("", 0, candidate_); |
114 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 114 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
115 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); | 115 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); |
116 ASSERT_TRUE(ice_candidates != NULL); | 116 ASSERT_TRUE(ice_candidates != nullptr); |
117 EXPECT_EQ(1u, ice_candidates->count()); | 117 EXPECT_EQ(1u, ice_candidates->count()); |
118 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); | 118 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); |
119 ASSERT_TRUE(ice_candidate != NULL); | 119 ASSERT_TRUE(ice_candidate != nullptr); |
120 candidate_.set_username(kCandidateUfragVoice); | 120 candidate_.set_username(kCandidateUfragVoice); |
121 candidate_.set_password(kCandidatePwdVoice); | 121 candidate_.set_password(kCandidatePwdVoice); |
122 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); | 122 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); |
123 EXPECT_EQ(0, ice_candidate->sdp_mline_index()); | 123 EXPECT_EQ(0, ice_candidate->sdp_mline_index()); |
124 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); | 124 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); |
125 } | 125 } |
126 | 126 |
127 // Test that we can add and remove candidates to a session description with | 127 // Test that we can add and remove candidates to a session description with |
128 // MID. Removing candidates requires MID (transport_name). | 128 // MID. Removing candidates requires MID (transport_name). |
129 TEST_F(JsepSessionDescriptionTest, AddAndRemoveCandidatesWithMid) { | 129 TEST_F(JsepSessionDescriptionTest, AddAndRemoveCandidatesWithMid) { |
130 // mid and m-line index don't match, in this case mid is preferred. | 130 // mid and m-line index don't match, in this case mid is preferred. |
131 std::string mid = "video"; | 131 std::string mid = "video"; |
132 JsepIceCandidate jsep_candidate(mid, 0, candidate_); | 132 JsepIceCandidate jsep_candidate(mid, 0, candidate_); |
133 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 133 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
134 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count()); | 134 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count()); |
135 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1); | 135 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1); |
136 ASSERT_TRUE(ice_candidates != NULL); | 136 ASSERT_TRUE(ice_candidates != nullptr); |
137 EXPECT_EQ(1u, ice_candidates->count()); | 137 EXPECT_EQ(1u, ice_candidates->count()); |
138 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); | 138 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); |
139 ASSERT_TRUE(ice_candidate != NULL); | 139 ASSERT_TRUE(ice_candidate != nullptr); |
140 candidate_.set_username(kCandidateUfragVideo); | 140 candidate_.set_username(kCandidateUfragVideo); |
141 candidate_.set_password(kCandidatePwdVideo); | 141 candidate_.set_password(kCandidatePwdVideo); |
142 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); | 142 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); |
143 // The mline index should have been updated according to mid. | 143 // The mline index should have been updated according to mid. |
144 EXPECT_EQ(1, ice_candidate->sdp_mline_index()); | 144 EXPECT_EQ(1, ice_candidate->sdp_mline_index()); |
145 | 145 |
146 std::vector<cricket::Candidate> candidates(1, candidate_); | 146 std::vector<cricket::Candidate> candidates(1, candidate_); |
147 candidates[0].set_transport_name(mid); | 147 candidates[0].set_transport_name(mid); |
148 EXPECT_EQ(1u, jsep_desc_->RemoveCandidates(candidates)); | 148 EXPECT_EQ(1u, jsep_desc_->RemoveCandidates(candidates)); |
149 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count()); | 149 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count()); |
150 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); | 150 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); |
151 } | 151 } |
152 | 152 |
153 TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) { | 153 TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) { |
154 candidate_.set_username(kCandidateUfrag); | 154 candidate_.set_username(kCandidateUfrag); |
155 candidate_.set_password(kCandidatePwd); | 155 candidate_.set_password(kCandidatePwd); |
156 JsepIceCandidate jsep_candidate("audio", 0, candidate_); | 156 JsepIceCandidate jsep_candidate("audio", 0, candidate_); |
157 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 157 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
158 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); | 158 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); |
159 ASSERT_TRUE(ice_candidates != NULL); | 159 ASSERT_TRUE(ice_candidates != nullptr); |
160 EXPECT_EQ(1u, ice_candidates->count()); | 160 EXPECT_EQ(1u, ice_candidates->count()); |
161 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); | 161 const IceCandidateInterface* ice_candidate = ice_candidates->at(0); |
162 ASSERT_TRUE(ice_candidate != NULL); | 162 ASSERT_TRUE(ice_candidate != nullptr); |
163 candidate_.set_username(kCandidateUfrag); | 163 candidate_.set_username(kCandidateUfrag); |
164 candidate_.set_password(kCandidatePwd); | 164 candidate_.set_password(kCandidatePwd); |
165 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); | 165 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); |
166 | 166 |
167 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); | 167 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); |
168 } | 168 } |
169 | 169 |
170 // Test that we can not add a candidate if there is no corresponding media | 170 // Test that we can not add a candidate if there is no corresponding media |
171 // content in the session description. | 171 // content in the session description. |
172 TEST_F(JsepSessionDescriptionTest, AddBadCandidate) { | 172 TEST_F(JsepSessionDescriptionTest, AddBadCandidate) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 221 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
222 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); | 222 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); |
223 EXPECT_NE(sdp, sdp_with_candidate); | 223 EXPECT_NE(sdp, sdp_with_candidate); |
224 | 224 |
225 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( | 225 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( |
226 DeSerialize(sdp_with_candidate)); | 226 DeSerialize(sdp_with_candidate)); |
227 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); | 227 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); |
228 | 228 |
229 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); | 229 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); |
230 } | 230 } |
OLD | NEW |