blob: 107464840801caf128514cd70b5d8715dcafec6a [file] [log] [blame]
Jelena Marusic46bd31b2015-04-30 10:57:10 +02001/*
2 * Copyright (c) 2015 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/voice_engine/include/voe_network.h"
12
13#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/voice_engine/include/voe_errors.h"
15#include "webrtc/voice_engine/voice_engine_fixture.h"
16
17namespace webrtc {
18
19enum {
20 kSizeTooSmallForRtcp = 2, // Minimum size of a valid RTCP packet is 4.
21 kSizeTooSmallForRtp = 10, // Minimum size of a valid RTP packet is 12.
22 kSizeGood = 12, // Acceptable size for both RTP and RTCP packets.
23 kSizeTooLarge = 1300 // Maximum size of a valid RTP packet is 1292.
24};
25
26// A packet with a valid header for both RTP and RTCP.
27// Methods that are tested here are checking only packet header.
28static const uint8_t kPacket[kSizeGood] = {0x80};
29static const uint8_t kPacketJunk[kSizeGood] = {};
30
31static const int kNonExistingChannel = 1234;
32
33class VoENetworkFixture : public VoiceEngineFixture {
34 protected:
35 int CreateChannelAndRegisterExternalTransport() {
36 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
37 int channelID = base_->CreateChannel();
38 EXPECT_NE(channelID, -1);
39 EXPECT_EQ(0, network_->RegisterExternalTransport(channelID, transport_));
40 return channelID;
41 }
42};
43
44TEST_F(VoENetworkFixture, RegisterExternalTransport) {
45 int channelID = CreateChannelAndRegisterExternalTransport();
46 EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
47}
48
49TEST_F(VoENetworkFixture, RegisterExternalTransportBeforeInitShouldFail) {
50 EXPECT_NE(
51 0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
52}
53
54TEST_F(VoENetworkFixture, DeRegisterExternalTransportBeforeInitShouldFail) {
55 EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
56}
57
58TEST_F(VoENetworkFixture,
59 RegisterExternalTransportOnNonExistingChannelShouldFail) {
60 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
61 EXPECT_NE(
62 0, network_->RegisterExternalTransport(kNonExistingChannel, transport_));
63}
64
65TEST_F(VoENetworkFixture,
66 DeRegisterExternalTransportOnNonExistingChannelShouldFail) {
67 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
68 EXPECT_NE(0, network_->DeRegisterExternalTransport(kNonExistingChannel));
69}
70
71TEST_F(VoENetworkFixture, DeRegisterExternalTransportBeforeRegister) {
72 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
73 int channelID = base_->CreateChannel();
74 EXPECT_NE(channelID, -1);
75 EXPECT_EQ(0, network_->DeRegisterExternalTransport(channelID));
76}
77
78TEST_F(VoENetworkFixture, ReceivedRTPPacketWithJunkDataShouldFail) {
79 int channelID = CreateChannelAndRegisterExternalTransport();
80 EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, kPacketJunk,
81 sizeof(kPacketJunk)));
82}
83
84TEST_F(VoENetworkFixture, ReceivedRTPPacketBeforeInitShouldFail) {
85 EXPECT_EQ(-1, network_->ReceivedRTPPacket(0, kPacket, sizeof(kPacket)));
86}
87
88TEST_F(VoENetworkFixture, ReceivedRTPPacketOnNonExistingChannelShouldFail) {
89 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
90 EXPECT_EQ(-1, network_->ReceivedRTPPacket(kNonExistingChannel, kPacket,
91 sizeof(kPacket)));
92}
93
94TEST_F(VoENetworkFixture,
95 ReceivedRTPPacketOnChannelWithoutTransportShouldFail) {
96 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
97 int channelID = base_->CreateChannel();
98 EXPECT_NE(channelID, -1);
99 EXPECT_EQ(-1,
100 network_->ReceivedRTPPacket(channelID, kPacket, sizeof(kPacket)));
101}
102
103TEST_F(VoENetworkFixture, ReceivedTooSmallRTPPacketShouldFail) {
104 int channelID = CreateChannelAndRegisterExternalTransport();
105 EXPECT_EQ(
106 -1, network_->ReceivedRTPPacket(channelID, kPacket, kSizeTooSmallForRtp));
107}
108
109TEST_F(VoENetworkFixture, ReceivedTooLargeRTPPacketShouldFail) {
110 int channelID = CreateChannelAndRegisterExternalTransport();
111 EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, kPacket, kSizeTooLarge));
112}
113
114TEST_F(VoENetworkFixture, ReceivedRTPPacketWithNullDataShouldFail) {
115 int channelID = CreateChannelAndRegisterExternalTransport();
116 EXPECT_EQ(-1, network_->ReceivedRTPPacket(channelID, nullptr, 0));
117}
118
119TEST_F(VoENetworkFixture, ReceivedRTCPPacketWithJunkDataShouldFail) {
120 int channelID = CreateChannelAndRegisterExternalTransport();
121 EXPECT_EQ(0, network_->ReceivedRTCPPacket(channelID, kPacketJunk,
122 sizeof(kPacketJunk)));
123 EXPECT_EQ(VE_SOCKET_TRANSPORT_MODULE_ERROR, base_->LastError());
124}
125
126TEST_F(VoENetworkFixture, ReceivedRTCPPacketBeforeInitShouldFail) {
127 EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
128 sizeof(kPacket)));
129}
130
131TEST_F(VoENetworkFixture, ReceivedRTCPPacketOnNonExistingChannelShouldFail) {
132 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
133 EXPECT_EQ(-1, network_->ReceivedRTCPPacket(kNonExistingChannel, kPacket,
134 sizeof(kPacket)));
135}
136
137TEST_F(VoENetworkFixture,
138 ReceivedRTCPPacketOnChannelWithoutTransportShouldFail) {
139 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
140 int channelID = base_->CreateChannel();
141 EXPECT_NE(channelID, -1);
142 EXPECT_EQ(-1,
143 network_->ReceivedRTCPPacket(channelID, kPacket, sizeof(kPacket)));
144}
145
146TEST_F(VoENetworkFixture, ReceivedTooSmallRTCPPacket4ShouldFail) {
147 int channelID = CreateChannelAndRegisterExternalTransport();
148 EXPECT_EQ(-1, network_->ReceivedRTCPPacket(channelID, kPacket,
149 kSizeTooSmallForRtcp));
150}
151
152TEST_F(VoENetworkFixture, ReceivedRTCPPacketWithNullDataShouldFail) {
153 int channelID = CreateChannelAndRegisterExternalTransport();
154 EXPECT_EQ(-1, network_->ReceivedRTCPPacket(channelID, nullptr, 0));
155}
156
157} // namespace webrtc