15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/* 25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle 35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2012, Google Inc. 45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without 65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met: 75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer. 105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer in the documentation 125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * and/or other materials provided with the distribution. 135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 3. The name of the author may not be used to endorse or promote products 145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * derived from this software without specific prior written permission. 155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */ 275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <string> 295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/app/webrtc/jsepicecandidate.h" 315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/app/webrtc/jsepsessiondescription.h" 325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/gunit.h" 335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/helpers.h" 345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/scoped_ptr.h" 355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/stringencode.h" 365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/candidate.h" 375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/constants.h" 385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/sessiondescription.h" 395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/mediasession.h" 405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing webrtc::IceCandidateCollection; 425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing webrtc::IceCandidateInterface; 435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing webrtc::JsepIceCandidate; 445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing webrtc::JsepSessionDescription; 455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing webrtc::SessionDescriptionInterface; 465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing talk_base::scoped_ptr; 475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidateUfrag[] = "ufrag"; 495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidatePwd[] = "pwd"; 505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidateUfragVoice[] = "ufrag_voice"; 515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidatePwdVoice[] = "pwd_voice"; 525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidateUfragVideo[] = "ufrag_video"; 535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const char kCandidatePwdVideo[] = "pwd_video"; 545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// This creates a session description with both audio and video media contents. 565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// In SDP this is described by two m lines, one audio and one video. 575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic cricket::SessionDescription* CreateCricketSessionDescription() { 585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::SessionDescription* desc(new cricket::SessionDescription()); 595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // AudioContentDescription 605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<cricket::AudioContentDescription> audio( 615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new cricket::AudioContentDescription()); 625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // VideoContentDescription 645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<cricket::VideoContentDescription> video( 655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new cricket::VideoContentDescription()); 665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0, 0)); 685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org desc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, 695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio.release()); 705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video->AddCodec(cricket::VideoCodec(120, "VP8", 640, 480, 30, 0)); 725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, 735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video.release()); 745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(desc->AddTransportInfo( 765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::TransportInfo( 775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::CN_AUDIO, 785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::TransportDescription( 795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::NS_GINGLE_P2P, 805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>(), 815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org kCandidateUfragVoice, kCandidatePwdVoice, 825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::ICEMODE_FULL, NULL, 835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::Candidates())))); 845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(desc->AddTransportInfo( 855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::TransportInfo(cricket::CN_VIDEO, 865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::TransportDescription( 875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::NS_GINGLE_P2P, 885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>(), 895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org kCandidateUfragVideo, kCandidatePwdVideo, 905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::ICEMODE_FULL, NULL, 915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::Candidates())))); 925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return desc; 935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass JsepSessionDescriptionTest : public testing::Test { 965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org protected: 975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org virtual void SetUp() { 985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int port = 1234; 995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::SocketAddress address("127.0.0.1", port++); 1005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::Candidate candidate("rtp", cricket::ICE_CANDIDATE_COMPONENT_RTP, 1015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org "udp", address, 1, "", 1025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org "", "local", "eth0", 0, "1"); 1035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_ = candidate; 1045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string session_id = 1055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::ToString(talk_base::CreateRandomId64()); 1065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string session_version = 1075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::ToString(talk_base::CreateRandomId()); 1085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org jsep_desc_.reset(new JsepSessionDescription("dummy")); 1095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(), 1105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org session_id, session_version)); 1115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string Serialize(const SessionDescriptionInterface* desc) { 1145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string sdp; 1155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(desc->ToString(&sdp)); 1165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_FALSE(sdp.empty()); 1175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return sdp; 1185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SessionDescriptionInterface* DeSerialize(const std::string& sdp) { 1215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepSessionDescription* desc(new JsepSessionDescription("dummy")); 1225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(desc->Initialize(sdp, NULL)); 1235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return desc; 1245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::Candidate candidate_; 1275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::scoped_ptr<JsepSessionDescription> jsep_desc_; 1285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}; 1295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Test that number_of_mediasections() returns the number of media contents in 1315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// a session description. 1325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, CheckSessionDescription) { 1335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(2u, jsep_desc_->number_of_mediasections()); 1345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Test that we can add a candidate to a session description. 1375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) { 1385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate jsep_candidate("", 0, candidate_); 1395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); 1405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); 1415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidates != NULL); 1425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(1u, ice_candidates->count()); 1435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateInterface* ice_candidate = ice_candidates->at(0); 1445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidate != NULL); 1455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_username(kCandidateUfragVoice); 1465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_password(kCandidatePwdVoice); 1475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); 1485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(0, ice_candidate->sdp_mline_index()); 1495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); 1505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, AddCandidateWithMid) { 1535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // mid and m-line index don't match, in this case mid is preferred. 1545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate jsep_candidate("video", 0, candidate_); 1555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); 1565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(0u, jsep_desc_->candidates(0)->count()); 1575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1); 1585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidates != NULL); 1595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(1u, ice_candidates->count()); 1605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateInterface* ice_candidate = ice_candidates->at(0); 1615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidate != NULL); 1625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_username(kCandidateUfragVideo); 1635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_password(kCandidatePwdVideo); 1645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); 1655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The mline index should have been updated according to mid. 1665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(1, ice_candidate->sdp_mline_index()); 1675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) { 1705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_username(kCandidateUfrag); 1715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_password(kCandidatePwd); 1725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate jsep_candidate("audio", 0, candidate_); 1735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); 1745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0); 1755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidates != NULL); 1765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(1u, ice_candidates->count()); 1775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const IceCandidateInterface* ice_candidate = ice_candidates->at(0); 1785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT_TRUE(ice_candidate != NULL); 1795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_username(kCandidateUfrag); 1805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate_.set_password(kCandidatePwd); 1815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_)); 1825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(0u, jsep_desc_->candidates(1)->count()); 1845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Test that we can not add a candidate if there is no corresponding media 1875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// content in the session description. 1885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, AddBadCandidate) { 1895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate bad_candidate1("", 55, candidate_); 1905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1)); 1915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate bad_candidate2("some weird mid", 0, candidate_); 1935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2)); 1945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Test that we can serialize a JsepSessionDescription and deserialize it again. 1975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, SerializeDeserialize) { 1985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string sdp = Serialize(jsep_desc_.get()); 1995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(DeSerialize(sdp)); 2015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections()); 2025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string parsed_sdp = Serialize(parsed_jsep_desc.get()); 2045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(sdp, parsed_sdp); 2055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Tests that we can serialize and deserialize a JsepSesssionDescription 2085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// with candidates. 2095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) { 2105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string sdp = Serialize(jsep_desc_.get()); 2115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add a candidate and check that the serialized result is different. 2135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org JsepIceCandidate jsep_candidate("audio", 0, candidate_); 2145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); 2155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string sdp_with_candidate = Serialize(jsep_desc_.get()); 2165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_NE(sdp, sdp_with_candidate); 2175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc( 2195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org DeSerialize(sdp_with_candidate)); 2205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); 2215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); 2235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 224