OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2015 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 "testing/gtest/include/gtest/gtest.h" | |
29 | |
30 #include "talk/media/webrtc/webrtcmediaengine.h" | |
31 | |
32 namespace cricket { | |
33 namespace { | |
34 | |
35 std::vector<RtpHeaderExtension> MakeUniqueExtensions() { | |
36 std::vector<RtpHeaderExtension> result; | |
37 char name[] = "a"; | |
38 for (int i = 0; i < 7; ++i) { | |
39 result.push_back(RtpHeaderExtension(name, 1 + i)); | |
40 name[0]++; | |
41 result.push_back(RtpHeaderExtension(name, 14 - i)); | |
42 name[0]++; | |
43 } | |
44 return result; | |
45 } | |
46 | |
47 std::vector<RtpHeaderExtension> MakeRedundantExtensions() { | |
48 std::vector<RtpHeaderExtension> result; | |
49 char name[] = "a"; | |
50 for (int i = 0; i < 7; ++i) { | |
51 result.push_back(RtpHeaderExtension(name, 1 + i)); | |
52 result.push_back(RtpHeaderExtension(name, 14 - i)); | |
53 name[0]++; | |
54 } | |
55 return result; | |
56 } | |
57 | |
58 bool SupportedExtensions1(const std::string& name) { | |
59 return name == "c" || name == "i"; | |
60 } | |
61 | |
62 bool SupportedExtensions2(const std::string& name) { | |
63 return name != "a" && name != "n"; | |
64 } | |
65 | |
66 bool IsSorted(const std::vector<webrtc::RtpExtension>& extensions) { | |
67 const std::string* last = nullptr; | |
68 for (const auto& extension : extensions) { | |
69 if (last && *last > extension.name) { | |
70 return false; | |
71 } | |
72 last = &extension.name; | |
73 } | |
74 return true; | |
75 } | |
76 } // namespace | |
77 | |
78 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_EmptyList) { | |
79 std::vector<RtpHeaderExtension> extensions; | |
80 EXPECT_TRUE(ValidateRtpExtensions(extensions)); | |
81 } | |
82 | |
83 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_AllGood) { | |
84 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
85 EXPECT_TRUE(ValidateRtpExtensions(extensions)); | |
86 } | |
87 | |
88 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_Low) { | |
89 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
90 extensions.push_back(RtpHeaderExtension("foo", 0)); | |
91 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
92 } | |
93 | |
94 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_High) { | |
95 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
96 extensions.push_back(RtpHeaderExtension("foo", 15)); | |
97 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
98 } | |
99 | |
100 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_StartOfSet) { | |
101 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
102 extensions.push_back(RtpHeaderExtension("foo", 1)); | |
103 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
104 } | |
105 | |
106 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_EndOfSet) { | |
107 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
108 extensions.push_back(RtpHeaderExtension("foo", 14)); | |
109 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
110 } | |
111 | |
112 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_EmptyList) { | |
113 std::vector<RtpHeaderExtension> extensions; | |
114 std::vector<webrtc::RtpExtension> filtered = | |
115 FilterRtpExtensions(extensions, SupportedExtensions1, true); | |
116 EXPECT_EQ(0, filtered.size()); | |
117 } | |
118 | |
119 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_IncludeOnlySupported) { | |
120 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
121 std::vector<webrtc::RtpExtension> filtered = | |
122 FilterRtpExtensions(extensions, SupportedExtensions1, false); | |
123 EXPECT_EQ(2, filtered.size()); | |
124 EXPECT_EQ("c", filtered[0].name); | |
125 EXPECT_EQ("i", filtered[1].name); | |
126 } | |
127 | |
128 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_1) { | |
129 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
130 std::vector<webrtc::RtpExtension> filtered = | |
131 FilterRtpExtensions(extensions, SupportedExtensions2, false); | |
132 EXPECT_EQ(12, filtered.size()); | |
133 EXPECT_TRUE(IsSorted(filtered)); | |
134 } | |
135 | |
136 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_2) { | |
137 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
138 std::vector<webrtc::RtpExtension> filtered = | |
139 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
140 EXPECT_EQ(12, filtered.size()); | |
141 EXPECT_TRUE(IsSorted(filtered)); | |
142 } | |
143 | |
144 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_DontRemoveRedundant) { | |
145 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); | |
146 std::vector<webrtc::RtpExtension> filtered = | |
147 FilterRtpExtensions(extensions, SupportedExtensions2, false); | |
148 EXPECT_EQ(12, filtered.size()); | |
149 EXPECT_TRUE(IsSorted(filtered)); | |
150 EXPECT_EQ(filtered[0].name, filtered[1].name); | |
151 } | |
152 | |
153 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundant) { | |
154 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); | |
155 std::vector<webrtc::RtpExtension> filtered = | |
156 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
157 EXPECT_EQ(6, filtered.size()); | |
158 EXPECT_TRUE(IsSorted(filtered)); | |
159 EXPECT_NE(filtered[0].name, filtered[1].name); | |
160 } | |
161 | |
162 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_1) { | |
163 std::vector<RtpHeaderExtension> extensions; | |
164 extensions.push_back( | |
165 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 3)); | |
166 extensions.push_back( | |
167 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 9)); | |
168 extensions.push_back( | |
169 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 6)); | |
170 extensions.push_back( | |
171 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 1)); | |
172 extensions.push_back( | |
173 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14)); | |
174 std::vector<webrtc::RtpExtension> filtered = | |
175 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
176 EXPECT_EQ(1, filtered.size()); | |
177 EXPECT_EQ(kRtpTransportSequenceNumberHeaderExtension, filtered[0].name); | |
178 } | |
179 | |
180 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_2) { | |
181 std::vector<RtpHeaderExtension> extensions; | |
182 extensions.push_back( | |
183 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 1)); | |
184 extensions.push_back( | |
185 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 14)); | |
186 extensions.push_back( | |
187 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 7)); | |
188 std::vector<webrtc::RtpExtension> filtered = | |
189 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
190 EXPECT_EQ(1, filtered.size()); | |
191 EXPECT_EQ(kRtpAbsoluteSenderTimeHeaderExtension, filtered[0].name); | |
192 } | |
193 | |
194 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_3) { | |
195 std::vector<RtpHeaderExtension> extensions; | |
196 extensions.push_back( | |
197 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 2)); | |
198 extensions.push_back( | |
199 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14)); | |
200 std::vector<webrtc::RtpExtension> filtered = | |
201 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
202 EXPECT_EQ(1, filtered.size()); | |
203 EXPECT_EQ(kRtpTimestampOffsetHeaderExtension, filtered[0].name); | |
204 } | |
205 } // namespace cricket | |
OLD | NEW |