Chromium Code Reviews| 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 AscendingNameOrder(const std::vector<webrtc::RtpExtension>& extensions) { | |
| 
 
stefan-webrtc
2015/12/01 15:36:57
HasAscendingNameOrder or Verify..., maybe?
 
the sun
2015/12/01 16:34:45
Done.
 
 | |
| 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_AllGood) { | |
| 79 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 80 EXPECT_TRUE(ValidateRtpExtensions(extensions)); | |
| 81 } | |
| 82 | |
| 83 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_Low) { | |
| 84 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 85 extensions.push_back(extensions.front()); | |
| 86 extensions.back().id = 0; | |
| 87 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
| 88 } | |
| 89 | |
| 90 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_High) { | |
| 91 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 92 extensions.push_back(extensions.back()); | |
| 93 extensions.back().id = 15; | |
| 94 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
| 95 } | |
| 96 | |
| 97 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_1) { | |
| 
 
stefan-webrtc
2015/12/01 15:36:57
SameNameOverlappingIds?
 
the sun
2015/12/01 16:34:45
True, better use different names.
 
 | |
| 98 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 99 extensions.push_back(extensions.front()); | |
| 100 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
| 101 } | |
| 102 | |
| 103 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_2) { | |
| 
 
stefan-webrtc
2015/12/01 15:36:57
Does this test anything different from the previou
 
the sun
2015/12/01 16:34:45
I was thinking start/end of set would be good to t
 
stefan-webrtc
2015/12/02 09:26:25
Acknowledged.
 
 | |
| 104 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 105 extensions.push_back(extensions.back()); | |
| 106 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
| 107 } | |
| 108 | |
| 109 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_3) { | |
| 110 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 111 extensions.push_back(extensions.back()); | |
| 112 extensions.back().id /= 2; | |
| 
 
stefan-webrtc
2015/12/01 15:36:57
Just want to verify: this is supposed to test that
 
the sun
2015/12/01 16:34:45
I've removed this specific test. Doesn't "Overlapp
 
stefan-webrtc
2015/12/02 09:26:25
Acknowledged.
 
 | |
| 113 EXPECT_FALSE(ValidateRtpExtensions(extensions)); | |
| 114 } | |
| 115 | |
| 116 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_IncludeOnlySupported) { | |
| 117 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 118 std::vector<webrtc::RtpExtension> filtered = | |
| 119 FilterRtpExtensions(extensions, SupportedExtensions1, false); | |
| 120 EXPECT_EQ(2, filtered.size()); | |
| 121 EXPECT_EQ("c", filtered[0].name); | |
| 122 EXPECT_EQ("i", filtered[1].name); | |
| 123 } | |
| 124 | |
| 125 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_1) { | |
| 126 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 127 std::vector<webrtc::RtpExtension> filtered = | |
| 128 FilterRtpExtensions(extensions, SupportedExtensions2, false); | |
| 129 EXPECT_EQ(12, filtered.size()); | |
| 130 EXPECT_TRUE(AscendingNameOrder(filtered)); | |
| 131 } | |
| 132 | |
| 133 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_2) { | |
| 134 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); | |
| 135 std::vector<webrtc::RtpExtension> filtered = | |
| 136 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
| 137 EXPECT_EQ(12, filtered.size()); | |
| 138 EXPECT_TRUE(AscendingNameOrder(filtered)); | |
| 139 } | |
| 140 | |
| 141 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_DontRemoveRedundant) { | |
| 142 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); | |
| 143 std::vector<webrtc::RtpExtension> filtered = | |
| 144 FilterRtpExtensions(extensions, SupportedExtensions2, false); | |
| 145 EXPECT_EQ(12, filtered.size()); | |
| 146 EXPECT_TRUE(AscendingNameOrder(filtered)); | |
| 147 EXPECT_EQ(filtered[0].name, filtered[1].name); | |
| 148 } | |
| 149 | |
| 150 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundant) { | |
| 151 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); | |
| 152 std::vector<webrtc::RtpExtension> filtered = | |
| 153 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
| 154 EXPECT_EQ(6, filtered.size()); | |
| 155 EXPECT_TRUE(AscendingNameOrder(filtered)); | |
| 156 EXPECT_NE(filtered[0].name, filtered[1].name); | |
| 157 } | |
| 158 | |
| 159 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_1) { | |
| 160 std::vector<RtpHeaderExtension> extensions; | |
| 161 extensions.push_back( | |
| 162 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 3)); | |
| 163 extensions.push_back( | |
| 164 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 9)); | |
| 165 extensions.push_back( | |
| 166 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 6)); | |
| 167 extensions.push_back( | |
| 168 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 1)); | |
| 169 extensions.push_back( | |
| 170 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14)); | |
| 171 std::vector<webrtc::RtpExtension> filtered = | |
| 172 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
| 173 EXPECT_EQ(1, filtered.size()); | |
| 174 EXPECT_EQ(kRtpTransportSequenceNumberHeaderExtension, filtered[0].name); | |
| 175 } | |
| 176 | |
| 177 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_2) { | |
| 178 std::vector<RtpHeaderExtension> extensions; | |
| 179 extensions.push_back( | |
| 180 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 1)); | |
| 181 extensions.push_back( | |
| 182 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 14)); | |
| 183 extensions.push_back( | |
| 184 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 7)); | |
| 185 std::vector<webrtc::RtpExtension> filtered = | |
| 186 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
| 187 EXPECT_EQ(1, filtered.size()); | |
| 188 EXPECT_EQ(kRtpAbsoluteSenderTimeHeaderExtension, filtered[0].name); | |
| 189 } | |
| 190 | |
| 191 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_3) { | |
| 192 std::vector<RtpHeaderExtension> extensions; | |
| 193 extensions.push_back( | |
| 194 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 2)); | |
| 195 extensions.push_back( | |
| 196 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14)); | |
| 197 std::vector<webrtc::RtpExtension> filtered = | |
| 198 FilterRtpExtensions(extensions, SupportedExtensions2, true); | |
| 199 EXPECT_EQ(1, filtered.size()); | |
| 200 EXPECT_EQ(kRtpTimestampOffsetHeaderExtension, filtered[0].name); | |
| 201 } | |
| 202 } // namespace cricket | |
| OLD | NEW |