~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/app/webrtc/jsepsessiondescription_unittest.cc

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libjingle
3
 
 * Copyright 2012, Google Inc.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
8
 
 *  1. Redistributions of source code must retain the above copyright notice,
9
 
 *     this list of conditions and the following disclaimer.
10
 
 *  2. Redistributions in binary form must reproduce the above copyright notice,
11
 
 *     this list of conditions and the following disclaimer in the documentation
12
 
 *     and/or other materials provided with the distribution.
13
 
 *  3. The name of the author may not be used to endorse or promote products
14
 
 *     derived from this software without specific prior written permission.
15
 
 *
16
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
 
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 
 */
27
 
 
28
 
#include <string>
29
 
 
30
 
#include "talk/app/webrtc/jsepicecandidate.h"
31
 
#include "talk/app/webrtc/jsepsessiondescription.h"
32
 
#include "talk/base/gunit.h"
33
 
#include "talk/base/scoped_ptr.h"
34
 
#include "talk/p2p/base/candidate.h"
35
 
#include "talk/p2p/base/constants.h"
36
 
#include "talk/p2p/base/sessiondescription.h"
37
 
#include "talk/session/phone/mediasession.h"
38
 
 
39
 
using webrtc::IceCandidateColletion;
40
 
using webrtc::IceCandidateInterface;
41
 
using webrtc::JsepIceCandidate;
42
 
using webrtc::JsepSessionDescription;
43
 
using webrtc::SessionDescriptionInterface;
44
 
using talk_base::scoped_ptr;
45
 
 
46
 
// This creates a session description with both audio and video media contents.
47
 
// In SDP this is described by two m lines, one audio and one video.
48
 
static cricket::SessionDescription* CreateCricketSessionDescription() {
49
 
  cricket::SessionDescription* desc(new cricket::SessionDescription());
50
 
  // AudioContentDescription
51
 
  scoped_ptr<cricket::AudioContentDescription> audio(
52
 
      new cricket::AudioContentDescription());
53
 
 
54
 
  // VideoContentDescription
55
 
  scoped_ptr<cricket::VideoContentDescription> video(
56
 
      new cricket::VideoContentDescription());
57
 
 
58
 
  audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0, 0));
59
 
  desc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
60
 
                   audio.release());
61
 
 
62
 
  video->AddCodec(cricket::VideoCodec(120, "VP8", 640, 480, 30, 0));
63
 
  desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
64
 
                   video.release());
65
 
  return desc;
66
 
}
67
 
 
68
 
class JsepSessionDescriptionTest : public testing::Test {
69
 
 protected:
70
 
  virtual void SetUp() {
71
 
    int port = 1234;
72
 
    talk_base::SocketAddress address("127.0.0.1", port++);
73
 
    cricket::Candidate candidate("rtp", "udp", address, 1, "user_rtp",
74
 
                                 "password_rtp", "local", "eth0", 0);
75
 
    candidate_ = candidate;
76
 
 
77
 
    jsep_desc_.reset(new JsepSessionDescription());
78
 
    jsep_desc_->SetDescription(CreateCricketSessionDescription());
79
 
  }
80
 
 
81
 
  std::string Serialize(const SessionDescriptionInterface* desc) {
82
 
    std::string sdp;
83
 
    EXPECT_TRUE(desc->ToString(&sdp));
84
 
    EXPECT_FALSE(sdp.empty());
85
 
    return sdp;
86
 
  }
87
 
 
88
 
  SessionDescriptionInterface* DeSerialize(const std::string& sdp) {
89
 
    JsepSessionDescription* desc(new JsepSessionDescription());
90
 
    EXPECT_TRUE(desc->Initialize(sdp));
91
 
    return desc;
92
 
  }
93
 
 
94
 
  cricket::Candidate candidate_;
95
 
  talk_base::scoped_ptr<JsepSessionDescription> jsep_desc_;
96
 
};
97
 
 
98
 
// Test that number_of_mediasections() returns the number of media contents in
99
 
// a session description.
100
 
TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) {
101
 
  EXPECT_EQ(2u, jsep_desc_->number_of_mediasections());
102
 
}
103
 
 
104
 
// Test that we can add a candidate to a session description.
105
 
TEST_F(JsepSessionDescriptionTest, AddCandidate) {
106
 
  JsepIceCandidate jsep_candidate("0", candidate_);
107
 
  EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
108
 
  const IceCandidateColletion* ice_candidates = jsep_desc_->candidates(0);
109
 
  ASSERT_TRUE(ice_candidates != NULL);
110
 
  EXPECT_EQ(1u, ice_candidates->count());
111
 
  const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
112
 
  ASSERT_TRUE(ice_candidate != NULL);
113
 
  EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
114
 
 
115
 
  EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
116
 
}
117
 
 
118
 
// Test that we can not add a candidate if there is no corresponding media
119
 
// content in the session description.
120
 
TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
121
 
  JsepIceCandidate bad_candidate1("55", candidate_);
122
 
  EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1));
123
 
 
124
 
  JsepIceCandidate bad_candidate2("some weird label", candidate_);
125
 
  EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
126
 
}
127
 
 
128
 
// Test that we can serialize a JsepSessionDescription and deserialize it again.
129
 
TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
130
 
  std::string sdp = Serialize(jsep_desc_.get());
131
 
 
132
 
  scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(DeSerialize(sdp));
133
 
  EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
134
 
 
135
 
  std::string parsed_sdp = Serialize(parsed_jsep_desc.get());
136
 
  EXPECT_EQ(sdp, parsed_sdp);
137
 
}
138
 
 
139
 
// Tests that we can serialize and deserialize a JsepSesssionDescription
140
 
// with candidates.
141
 
TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) {
142
 
  std::string sdp = Serialize(jsep_desc_.get());
143
 
 
144
 
  // Add a candidate and check that the serialized result is different.
145
 
  JsepIceCandidate jsep_candidate("0", candidate_);
146
 
  EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
147
 
  std::string sdp_with_candidate = Serialize(jsep_desc_.get());
148
 
  EXPECT_NE(sdp, sdp_with_candidate);
149
 
 
150
 
  scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(
151
 
      DeSerialize(sdp_with_candidate));
152
 
  std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get());
153
 
 
154
 
  EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate);
155
 
}
156