Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/media_stream_constraints_util_sets.h" | |
| 6 | |
| 7 #include <cmath> | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "content/renderer/media/media_stream_video_source.h" | |
| 12 #include "content/renderer/media/mock_constraint_factory.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 using Point = ResolutionSet::Point; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Defined as macro in order to get more informative line-number information | |
| 22 // when a test fails. | |
| 23 #define EXPECT_POINT_EQ(p1, p2) \ | |
| 24 do { \ | |
| 25 EXPECT_DOUBLE_EQ((p1).height(), (p2).height()); \ | |
| 26 EXPECT_DOUBLE_EQ((p1).width(), (p2).width()); \ | |
| 27 } while (0) | |
| 28 | |
| 29 // Checks if |point| is an element of |vertices| using | |
| 30 // Point::IsApproximatelyEqualTo() to test for equality. | |
| 31 void VerticesContain(const std::vector<Point>& vertices, const Point& point) { | |
| 32 bool result = false; | |
| 33 for (const auto& vertex : vertices) { | |
| 34 if (point.IsApproximatelyEqualTo(vertex)) { | |
| 35 result = true; | |
| 36 break; | |
| 37 } | |
| 38 } | |
| 39 EXPECT_TRUE(result); | |
| 40 } | |
| 41 | |
| 42 // Determines if |vertices| is valid according to the contract for | |
| 43 // ResolutionCandidateSet::ComputeVertices(). | |
| 44 bool AreValidVertices(const std::vector<Point>& vertices) { | |
| 45 // Single-segment, single point or single segment are trivial cases. | |
|
hta - Chromium
2017/03/08 12:42:51
Nit: remove repeated "single-segment"
Guido Urdaneta
2017/03/09 17:55:43
Done.
| |
| 46 if (vertices.size() <= 2) | |
| 47 return true; | |
| 48 else if (vertices.size() > 6) // Polygons of more than 6 sides are not valid. | |
| 49 return false; | |
| 50 | |
| 51 // For the case of 3 to 6 vertices, the vertices must be in counterclockwise | |
| 52 // order. Compute orientation using the determinant of each diagonal in the | |
| 53 // polygon, using the first vertex as reference. | |
|
hbos_chromium
2017/03/09 11:34:22
Because this test uses the first vertex as the ref
Guido Urdaneta
2017/03/09 17:55:43
Your solution to 1 is in principle correct (check
hbos_chromium
2017/03/10 09:17:26
I think the only case 1) doesn't guard against is
| |
| 54 Point prev_diagonal = vertices[1] - vertices[0]; | |
| 55 for (auto vertex = vertices.begin() + 2; vertex != vertices.end(); ++vertex) { | |
| 56 Point current_diagonal = *vertex - vertices[0]; | |
| 57 // The determinant of the two diagonals returns the signed area of the | |
| 58 // parallelogram they generate. The area is positive if the diagonals are in | |
| 59 // counterclockwise order, zero if the diagonals have the same direction and | |
| 60 // negative if the diagonals are in clockwise order. | |
| 61 // See https://en.wikipedia.org/wiki/Determinant#2_.C3.97_2_matrices. | |
| 62 double det = prev_diagonal.height() * current_diagonal.width() - | |
| 63 current_diagonal.height() * prev_diagonal.width(); | |
| 64 if (det <= 0) | |
| 65 return false; | |
|
hbos_chromium
2017/03/09 11:34:22
I think this is prone to rounding errors. Parallel
Guido Urdaneta
2017/03/09 17:55:43
Acknowledged.
hbos_chromium
2017/03/10 09:17:26
How about <= kTolerance? In case of future tests f
| |
| 66 prev_diagonal = current_diagonal; | |
| 67 } | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 // This function provides an alternative method for computing the projection | |
| 72 // of |point| on the line of segment |s1||s2| to be used to compare the results | |
| 73 // provided by Point::ClosestPointInSegment(). Since it relies on library | |
| 74 // functions, it has larger error in practice than | |
| 75 // Point::ClosestPointInSegment(), so results must be compared with | |
| 76 // Point::IsApproximatelyEqualTo(). | |
| 77 // This function only computes projections. The result may be outside the | |
| 78 // segment |s1||s2|. | |
| 79 Point ProjectionOnSegmentLine(const Point& point, | |
| 80 const Point& s1, | |
| 81 const Point& s2) { | |
| 82 double segment_slope = | |
| 83 (s2.width() - s1.width()) / (s2.height() - s1.height()); | |
| 84 double segment_angle = std::atan(segment_slope); | |
| 85 double norm = std::sqrt(Point::Dot(point, point)); | |
| 86 double angle = | |
| 87 (point.height() == 0 && point.width() == 0) | |
| 88 ? 0.0 | |
| 89 : std::atan(point.width() / point.height()) - segment_angle; | |
| 90 double projection_length = norm * std::cos(angle); | |
| 91 double projection_height = projection_length * std::cos(segment_angle); | |
| 92 double projection_width = projection_length * std::sin(segment_angle); | |
| 93 return Point(projection_height, projection_width); | |
| 94 } | |
| 95 | |
| 96 } // namespace | |
| 97 | |
| 98 class MediaStreamConstraintsUtilSetsTest : public testing::Test { | |
| 99 protected: | |
| 100 using P = Point; | |
| 101 MockConstraintFactory factory_; | |
| 102 }; | |
| 103 | |
| 104 // This test tests the test-harness function AreValidVertices. | |
| 105 TEST_F(MediaStreamConstraintsUtilSetsTest, VertexListValidity) { | |
| 106 EXPECT_TRUE(AreValidVertices({P(1, 1)})); | |
| 107 EXPECT_TRUE(AreValidVertices({P(1, 1)})); | |
| 108 EXPECT_TRUE(AreValidVertices({P(1, 0), P(0, 1)})); | |
| 109 EXPECT_TRUE(AreValidVertices({P(1, 1), P(0, 0), P(1, 0)})); | |
| 110 | |
| 111 // Not in counterclockwise order. | |
| 112 EXPECT_FALSE(AreValidVertices({P(1, 0), P(0, 0), P(1, 1)})); | |
| 113 | |
| 114 // Final vertex aligned with the previous two vertices. | |
| 115 EXPECT_FALSE(AreValidVertices({P(1, 0), P(1, 1), P(1, 1.5), P(1, 0.1)})); | |
| 116 | |
| 117 // Not in counterclockwise order. | |
| 118 EXPECT_FALSE( | |
| 119 AreValidVertices({P(1, 0), P(3, 0), P(2, 2), P(3.1, 1), P(0, 1)})); | |
| 120 | |
| 121 EXPECT_TRUE(AreValidVertices( | |
| 122 {P(1, 0), P(3, 0), P(3.1, 1), P(3, 2), P(1, 2), P(0.9, 1)})); | |
| 123 | |
| 124 // Not in counterclockwise order. | |
| 125 EXPECT_FALSE(AreValidVertices( | |
| 126 {P(1, 0), P(3, 0), P(3.1, 1), P(1, 2), P(3, 2), P(0.9, 1)})); | |
| 127 | |
| 128 // Counterclockwise, but more than 6 vertices. | |
| 129 EXPECT_FALSE(AreValidVertices( | |
| 130 {P(1, 0), P(3, 0), P(3.1, 1), P(3, 2), P(2, 2.1), P(1, 2), P(0.9, 1)})); | |
| 131 } | |
| 132 | |
| 133 TEST_F(MediaStreamConstraintsUtilSetsTest, PointOperations) { | |
| 134 const Point kZero(0, 0); | |
| 135 | |
| 136 // Basic equality and inequality | |
| 137 EXPECT_EQ(P(0, 0), kZero); | |
| 138 EXPECT_EQ(P(50, 50), P(50, 50)); | |
| 139 EXPECT_NE(kZero, P(50, 50)); | |
| 140 EXPECT_NE(P(50, 50), P(100, 100)); | |
| 141 EXPECT_NE(P(50, 50), P(100, 50)); | |
| 142 | |
| 143 // Operations with zero. | |
| 144 EXPECT_EQ(kZero, kZero + kZero); | |
| 145 EXPECT_EQ(kZero, kZero - kZero); | |
| 146 EXPECT_EQ(kZero, 0.0 * kZero); | |
| 147 EXPECT_EQ(0.0, P::Dot(kZero, kZero)); | |
| 148 EXPECT_EQ(0.0, P::SquareEuclideanDistance(kZero, kZero)); | |
| 149 EXPECT_EQ(kZero, P::ClosestPointInSegment(kZero, kZero, kZero)); | |
| 150 | |
| 151 // Operations with zero and nonzero values. | |
| 152 EXPECT_EQ(P(50, 50), kZero + P(50, 50)); | |
| 153 EXPECT_EQ(P(50, 50) + kZero, kZero + P(50, 50)); | |
| 154 EXPECT_EQ(P(50, 50), P(50, 50) - kZero); | |
| 155 EXPECT_EQ(kZero, P(50, 50) - P(50, 50)); | |
| 156 EXPECT_EQ(kZero, 0.0 * P(50, 50)); | |
| 157 EXPECT_EQ(0.0, P::Dot(kZero, P(50, 50))); | |
| 158 EXPECT_EQ(0.0, P::Dot(P(50, 50), kZero)); | |
| 159 EXPECT_EQ(5000, P::SquareEuclideanDistance(kZero, P(50, 50))); | |
| 160 EXPECT_EQ(P::SquareEuclideanDistance(P(50, 50), kZero), | |
| 161 P::SquareEuclideanDistance(kZero, P(50, 50))); | |
| 162 EXPECT_EQ(kZero, P::ClosestPointInSegment(kZero, kZero, P(50, 50))); | |
| 163 EXPECT_EQ(kZero, P::ClosestPointInSegment(kZero, P(50, 50), kZero)); | |
| 164 EXPECT_EQ(P(50, 50), | |
| 165 P::ClosestPointInSegment(P(50, 50), P(50, 50), P(50, 50))); | |
| 166 | |
| 167 // Operations with nonzero values. | |
| 168 // Additions. | |
| 169 EXPECT_EQ(P(100, 50), P(50, 50) + P(50, 0)); | |
| 170 EXPECT_EQ(P(100, 50), P(50, 0) + P(50, 50)); | |
| 171 | |
| 172 // Substractions. | |
| 173 EXPECT_EQ(P(50, 50), P(100, 100) - P(50, 50)); | |
| 174 EXPECT_EQ(P(50, 50), P(100, 50) - P(50, 0)); | |
| 175 EXPECT_EQ(P(50, 0), P(100, 50) - P(50, 50)); | |
| 176 | |
| 177 // Scalar-vector products. | |
| 178 EXPECT_EQ(P(50, 50), 1.0 * P(50, 50)); | |
| 179 EXPECT_EQ(P(75, 75), 1.5 * P(50, 50)); | |
| 180 EXPECT_EQ(P(200, 100), 2.0 * P(100, 50)); | |
| 181 EXPECT_EQ(2.0 * (P(100, 100) + P(100, 50)), | |
| 182 2.0 * P(100, 100) + 2.0 * P(100, 50)); | |
| 183 | |
| 184 // Dot products. | |
| 185 EXPECT_EQ(2 * 50 * 100, P::Dot(P(50, 50), P(100, 100))); | |
| 186 EXPECT_EQ(P::Dot(P(100, 100), P(50, 50)), P::Dot(P(50, 50), P(100, 100))); | |
| 187 EXPECT_EQ(0, P::Dot(P(100, 0), P(0, 100))); | |
| 188 | |
| 189 // Distances. | |
| 190 EXPECT_EQ(25, P::SquareEuclideanDistance(P(4, 0), P(0, 3))); | |
| 191 EXPECT_EQ(75 * 75, P::SquareEuclideanDistance(P(100, 0), P(25, 0))); | |
| 192 EXPECT_EQ(75 * 75, P::SquareEuclideanDistance(P(0, 100), P(0, 25))); | |
| 193 EXPECT_EQ(5 * 5 + 9 * 9, P::SquareEuclideanDistance(P(5, 1), P(10, 10))); | |
| 194 | |
| 195 // Closest point to segment from (10,0) to (50,0). | |
| 196 EXPECT_EQ(P(25, 0), P::ClosestPointInSegment(P(25, 25), P(10, 0), P(50, 0))); | |
| 197 EXPECT_EQ(P(50, 0), | |
| 198 P::ClosestPointInSegment(P(100, 100), P(10, 0), P(50, 0))); | |
| 199 EXPECT_EQ(P(10, 0), P::ClosestPointInSegment(P(0, 100), P(10, 0), P(50, 0))); | |
| 200 | |
| 201 // Closest point to segment from (0,10) to (0,50). | |
| 202 EXPECT_EQ(P(0, 25), P::ClosestPointInSegment(P(25, 25), P(0, 10), P(0, 50))); | |
| 203 EXPECT_EQ(P(0, 50), | |
| 204 P::ClosestPointInSegment(P(100, 100), P(0, 10), P(0, 50))); | |
| 205 EXPECT_EQ(P(0, 10), P::ClosestPointInSegment(P(100, 0), P(0, 10), P(0, 50))); | |
| 206 | |
| 207 // Closest point to segment from (0,10) to (10,0). | |
| 208 EXPECT_EQ(P(5, 5), P::ClosestPointInSegment(P(25, 25), P(0, 10), P(10, 0))); | |
| 209 EXPECT_EQ(P(5, 5), P::ClosestPointInSegment(P(100, 100), P(0, 10), P(10, 0))); | |
| 210 EXPECT_EQ(P(10, 0), P::ClosestPointInSegment(P(100, 0), P(0, 10), P(10, 0))); | |
| 211 EXPECT_EQ(P(0, 10), P::ClosestPointInSegment(P(0, 100), P(0, 10), P(10, 0))); | |
| 212 } | |
| 213 | |
| 214 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionUnconstrained) { | |
| 215 ResolutionSet set; | |
| 216 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 217 EXPECT_TRUE(set.ContainsPoint(1, 1)); | |
| 218 EXPECT_TRUE(set.ContainsPoint(2000, 2000)); | |
| 219 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 220 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 221 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 222 } | |
| 223 | |
| 224 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionConstrained) { | |
| 225 ResolutionSet set = ResolutionSet::FromHeight(10, 100); | |
| 226 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 227 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 228 EXPECT_TRUE(set.ContainsPoint(50, 50)); | |
| 229 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 230 EXPECT_FALSE(set.ContainsPoint(500, 500)); | |
| 231 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 232 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 233 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 234 | |
| 235 set = ResolutionSet::FromHeight(0, 100); | |
| 236 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 237 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 238 EXPECT_TRUE(set.ContainsPoint(50, 50)); | |
| 239 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 240 EXPECT_FALSE(set.ContainsPoint(500, 500)); | |
| 241 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 242 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 243 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 244 | |
| 245 set = ResolutionSet::FromHeight(100, ResolutionSet::kMaxDimension); | |
| 246 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 247 EXPECT_FALSE(set.ContainsPoint(10, 10)); | |
| 248 EXPECT_FALSE(set.ContainsPoint(50, 50)); | |
| 249 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 250 EXPECT_TRUE(set.ContainsPoint(500, 500)); | |
| 251 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 252 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 253 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 254 | |
| 255 set = ResolutionSet::FromWidth(10, 100); | |
| 256 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 257 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 258 EXPECT_TRUE(set.ContainsPoint(50, 50)); | |
| 259 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 260 EXPECT_FALSE(set.ContainsPoint(500, 500)); | |
| 261 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 262 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 263 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 264 | |
| 265 set = ResolutionSet::FromWidth(0, 100); | |
| 266 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 267 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 268 EXPECT_TRUE(set.ContainsPoint(50, 50)); | |
| 269 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 270 EXPECT_FALSE(set.ContainsPoint(500, 500)); | |
| 271 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 272 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 273 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 274 | |
| 275 set = ResolutionSet::FromWidth(100, ResolutionSet::kMaxDimension); | |
| 276 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 277 EXPECT_FALSE(set.ContainsPoint(10, 10)); | |
| 278 EXPECT_FALSE(set.ContainsPoint(50, 50)); | |
| 279 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 280 EXPECT_TRUE(set.ContainsPoint(500, 500)); | |
| 281 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 282 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 283 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 284 | |
| 285 set = ResolutionSet::FromAspectRatio(1.0, 2.0); | |
| 286 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 287 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 288 EXPECT_TRUE(set.ContainsPoint(10, 20)); | |
| 289 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 290 EXPECT_TRUE(set.ContainsPoint(2000, 4000)); | |
| 291 EXPECT_FALSE(set.ContainsPoint(1, 50)); | |
| 292 EXPECT_FALSE(set.ContainsPoint(50, 1)); | |
| 293 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 294 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 295 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 296 | |
| 297 set = ResolutionSet::FromAspectRatio(0.0, 2.0); | |
| 298 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 299 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 300 EXPECT_TRUE(set.ContainsPoint(10, 20)); | |
| 301 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 302 EXPECT_TRUE(set.ContainsPoint(2000, 4000)); | |
| 303 EXPECT_FALSE(set.ContainsPoint(1, 50)); | |
| 304 EXPECT_TRUE(set.ContainsPoint(50, 1)); | |
| 305 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 306 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 307 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 308 | |
| 309 set = ResolutionSet::FromAspectRatio(1.0, HUGE_VAL); | |
| 310 EXPECT_TRUE(set.ContainsPoint(0, 0)); | |
| 311 EXPECT_TRUE(set.ContainsPoint(10, 10)); | |
| 312 EXPECT_TRUE(set.ContainsPoint(10, 20)); | |
| 313 EXPECT_TRUE(set.ContainsPoint(100, 100)); | |
| 314 EXPECT_TRUE(set.ContainsPoint(2000, 4000)); | |
| 315 EXPECT_TRUE(set.ContainsPoint(1, 50)); | |
| 316 EXPECT_FALSE(set.ContainsPoint(50, 1)); | |
| 317 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 318 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 319 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 320 } | |
| 321 | |
| 322 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionTrivialEmptiness) { | |
| 323 ResolutionSet set = ResolutionSet::FromHeight(100, 10); | |
| 324 EXPECT_TRUE(set.IsEmpty()); | |
| 325 EXPECT_TRUE(set.IsHeightEmpty()); | |
| 326 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 327 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 328 | |
| 329 set = ResolutionSet::FromWidth(100, 10); | |
| 330 EXPECT_TRUE(set.IsEmpty()); | |
| 331 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 332 EXPECT_TRUE(set.IsWidthEmpty()); | |
| 333 EXPECT_FALSE(set.IsAspectRatioEmpty()); | |
| 334 | |
| 335 set = ResolutionSet::FromAspectRatio(100.0, 10.0); | |
| 336 EXPECT_TRUE(set.IsEmpty()); | |
| 337 EXPECT_FALSE(set.IsHeightEmpty()); | |
| 338 EXPECT_FALSE(set.IsWidthEmpty()); | |
| 339 EXPECT_TRUE(set.IsAspectRatioEmpty()); | |
| 340 } | |
| 341 | |
| 342 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionLineConstraintsEmptiness) { | |
| 343 ResolutionSet set(1, 1, 1, 1, 1, 1); | |
| 344 EXPECT_FALSE(set.IsEmpty()); | |
| 345 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 346 EXPECT_TRUE(set.ContainsPoint(1, 1)); | |
| 347 EXPECT_FALSE(set.ContainsPoint(1, 0)); | |
| 348 EXPECT_FALSE(set.ContainsPoint(0, 1)); | |
| 349 | |
| 350 // Three lines that do not intersect in the same point is empty. | |
| 351 set = ResolutionSet(1, 1, 1, 1, 0.5, 0.5); | |
| 352 EXPECT_TRUE(set.IsEmpty()); | |
| 353 EXPECT_TRUE(set.IsAspectRatioEmpty()); | |
| 354 EXPECT_FALSE(set.ContainsPoint(0, 0)); | |
| 355 EXPECT_FALSE(set.ContainsPoint(1, 1)); | |
| 356 EXPECT_FALSE(set.ContainsPoint(1, 0)); | |
| 357 EXPECT_FALSE(set.ContainsPoint(0, 1)); | |
| 358 } | |
| 359 | |
| 360 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionBoxEmptiness) { | |
| 361 int kMin = 100; | |
| 362 int kMax = 200; | |
| 363 // Max aspect ratio below box. | |
| 364 ResolutionSet set(kMin, kMax, kMin, kMax, 0.4, 0.4); | |
| 365 EXPECT_TRUE(set.IsEmpty()); | |
| 366 EXPECT_TRUE(set.IsAspectRatioEmpty()); | |
| 367 | |
| 368 // Min aspect ratio above box. | |
| 369 set = ResolutionSet(kMin, kMax, kMin, kMax, 3.0, HUGE_VAL); | |
| 370 EXPECT_TRUE(set.IsEmpty()); | |
| 371 EXPECT_TRUE(set.IsAspectRatioEmpty()); | |
| 372 | |
| 373 // Min aspect ratio crosses box. | |
| 374 set = ResolutionSet(kMin, kMax, kMin, kMax, 1.0, HUGE_VAL); | |
| 375 EXPECT_FALSE(set.IsEmpty()); | |
| 376 | |
| 377 // Max aspect ratio crosses box. | |
| 378 set = ResolutionSet(kMin, kMax, kMin, kMax, 0.0, 1.0); | |
| 379 EXPECT_FALSE(set.IsEmpty()); | |
| 380 | |
| 381 // Min and max aspect ratios cross box. | |
| 382 set = ResolutionSet(kMin, kMax, kMin, kMax, 0.9, 1.1); | |
| 383 EXPECT_FALSE(set.IsEmpty()); | |
| 384 | |
| 385 // Min and max aspect ratios cover box. | |
| 386 set = ResolutionSet(kMin, kMax, kMin, kMax, 0.2, 100); | |
| 387 EXPECT_FALSE(set.IsEmpty()); | |
| 388 } | |
| 389 | |
| 390 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionPointIntersection) { | |
| 391 ResolutionSet set1(1, 2, 1, 2, 0.0, HUGE_VAL); | |
| 392 ResolutionSet set2 = ResolutionSet::FromExactAspectRatio(0.5); | |
| 393 | |
| 394 // The intersection should contain only the point (h=2, w=1) | |
| 395 auto intersection = set1.Intersection(set2); | |
| 396 EXPECT_TRUE(intersection.ContainsPoint(2, 1)); | |
|
hbos_chromium
2017/03/09 11:34:21
How about EXPECT-ing the ResolutionSet to be appro
Guido Urdaneta
2017/03/09 17:55:43
Checking set equality is tricky, because the corre
| |
| 397 | |
| 398 // It should not contain any point in the vicinity of the included point. | |
|
hbos_chromium
2017/03/09 11:34:22
nit: It's good if the vicinity is super close and
Guido Urdaneta
2017/03/09 17:55:43
Done.
| |
| 399 EXPECT_FALSE(intersection.ContainsPoint(1, 0)); | |
| 400 EXPECT_FALSE(intersection.ContainsPoint(2, 0)); | |
| 401 EXPECT_FALSE(intersection.ContainsPoint(3, 0)); | |
| 402 EXPECT_FALSE(intersection.ContainsPoint(1, 1)); | |
| 403 EXPECT_FALSE(intersection.ContainsPoint(3, 1)); | |
| 404 EXPECT_FALSE(intersection.ContainsPoint(1, 2)); | |
| 405 EXPECT_FALSE(intersection.ContainsPoint(2, 2)); | |
| 406 EXPECT_FALSE(intersection.ContainsPoint(3, 2)); | |
| 407 } | |
| 408 | |
| 409 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionLineIntersection) { | |
| 410 ResolutionSet set1(1, 2, 1, 2, 0.0, HUGE_VAL); | |
| 411 ResolutionSet set2 = ResolutionSet::FromExactAspectRatio(1.0); | |
| 412 | |
| 413 // The intersection should contain (1,1) and (2,2) | |
| 414 auto intersection = set1.Intersection(set2); | |
| 415 EXPECT_TRUE(intersection.ContainsPoint(1, 1)); | |
| 416 EXPECT_TRUE(intersection.ContainsPoint(2, 2)); | |
| 417 | |
| 418 // It should not contain the other points in the bounding box. | |
| 419 EXPECT_FALSE(intersection.ContainsPoint(1, 2)); | |
| 420 EXPECT_FALSE(intersection.ContainsPoint(2, 1)); | |
| 421 } | |
| 422 | |
| 423 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionBoxIntersection) { | |
| 424 const int kMin1 = 0; | |
| 425 const int kMax1 = 2; | |
| 426 ResolutionSet set1(kMin1, kMax1, kMin1, kMax1, 0.0, HUGE_VAL); | |
| 427 | |
| 428 const int kMin2 = 1; | |
| 429 const int kMax2 = 3; | |
| 430 ResolutionSet set2(kMin2, kMax2, kMin2, kMax2, 0.0, HUGE_VAL); | |
| 431 | |
| 432 auto intersection = set1.Intersection(set2); | |
| 433 for (int i = kMin1; i <= kMax2; ++i) { | |
| 434 for (int j = kMin1; j <= kMax2; ++j) { | |
| 435 if (i >= kMin2 && j >= kMin2 && i <= kMax1 && j <= kMax1) | |
| 436 EXPECT_TRUE(intersection.ContainsPoint(i, j)); | |
| 437 else | |
| 438 EXPECT_FALSE(intersection.ContainsPoint(i, j)); | |
| 439 } | |
| 440 } | |
| 441 } | |
| 442 | |
| 443 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionPointSetClosestPoint) { | |
| 444 const int kHeight = 10; | |
| 445 const int kWidth = 10; | |
| 446 const double kAspectRatio = 1.0; | |
| 447 ResolutionSet set(kHeight, kHeight, kWidth, kWidth, kAspectRatio, | |
| 448 kAspectRatio); | |
| 449 | |
| 450 for (int height = 0; height < 100; height += 10) { | |
| 451 for (int width = 0; width < 100; width += 10) { | |
| 452 EXPECT_EQ(P(kHeight, kWidth), set.ClosestPointTo(P(height, width))); | |
| 453 } | |
| 454 } | |
| 455 } | |
| 456 | |
| 457 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionLineSetClosestPoint) { | |
| 458 { | |
| 459 const int kHeight = 10; | |
| 460 auto set = ResolutionSet::FromExactHeight(kHeight); | |
| 461 for (int height = 0; height < 100; height += 10) { | |
| 462 for (int width = 0; width < 100; width += 10) { | |
| 463 EXPECT_EQ(P(kHeight, width), set.ClosestPointTo(P(height, width))); | |
| 464 } | |
| 465 } | |
| 466 const int kWidth = 10; | |
| 467 set = ResolutionSet::FromExactWidth(kWidth); | |
| 468 for (int height = 0; height < 100; height += 10) { | |
| 469 for (int width = 0; width < 100; width += 10) { | |
| 470 EXPECT_EQ(P(height, kWidth), set.ClosestPointTo(P(height, width))); | |
| 471 } | |
| 472 } | |
| 473 } | |
| 474 | |
| 475 { | |
| 476 const double kAspectRatios[] = {0.0, 0.1, 0.2, 0.5, | |
| 477 1.0, 2.0, 5.0, HUGE_VAL}; | |
| 478 for (double aspect_ratio : kAspectRatios) { | |
| 479 auto set = ResolutionSet::FromExactAspectRatio(aspect_ratio); | |
| 480 for (int height = 0; height < 100; height += 10) { | |
| 481 for (int width = 0; width < 100; width += 10) { | |
| 482 Point point(height, width); | |
| 483 Point expected = | |
| 484 ProjectionOnSegmentLine(point, P(0, 0), P(1, aspect_ratio)); | |
| 485 Point actual = set.ClosestPointTo(point); | |
| 486 // This requires higher tolerance than ExpectPointEx due to the larger | |
| 487 // error of the alternative projection method. | |
| 488 EXPECT_TRUE(expected.IsApproximatelyEqualTo(actual)); | |
| 489 } | |
| 490 } | |
| 491 } | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionGeneralSetClosestPoint) { | |
| 496 // This set contains the following vertices: | |
| 497 // (10, 10), (20, 10), (100, 50), (100, 100), (100/1.5, 100), (10, 15) | |
| 498 ResolutionSet set(10, 100, 10, 100, 0.5, 1.5); | |
| 499 | |
| 500 // Check that vertices are the closest points to themselves. | |
| 501 std::vector<Point> vertices = {P(10, 10), P(20, 10), P(100, 50), | |
| 502 P(100, 100), P(100 / 1.5, 100), P(10, 15)}; | |
|
hbos_chromium
2017/03/09 11:34:21
EXPECT_EQ(vertices, set.ComputeVertices())
Guido Urdaneta
2017/03/09 17:55:43
I prefer to test that ComputeVertices works in Res
hbos_chromium
2017/03/10 09:17:26
Acknowledged.
| |
| 503 for (auto& vertex : vertices) | |
| 504 EXPECT_EQ(vertex, set.ClosestPointTo(vertex)); | |
| 505 | |
| 506 // Point inside the set. | |
| 507 EXPECT_EQ(P(11, 11), set.ClosestPointTo(P(11, 11))); | |
| 508 | |
| 509 // Close to horizontal segment (10, 10) (20, 10). | |
| 510 EXPECT_EQ(P(15, 10), set.ClosestPointTo(P(15, 9))); | |
| 511 | |
| 512 // Close to horizontal segment (100, 100) (100/1.5, 100). | |
| 513 EXPECT_EQ(P(99, 100), set.ClosestPointTo(P(99, 200))); | |
| 514 | |
| 515 // Close to vertical segment (10, 15) (10, 10). | |
| 516 EXPECT_EQ(P(10, 12.5), set.ClosestPointTo(P(2, 12.5))); | |
| 517 | |
| 518 // Close to vertical segment (100, 50) (100, 100). | |
| 519 EXPECT_EQ(P(100, 75), set.ClosestPointTo(P(120, 75))); | |
| 520 | |
| 521 // Close to oblique segment (20, 10) (100, 50) | |
| 522 { | |
| 523 Point point(70, 15); | |
| 524 Point expected = ProjectionOnSegmentLine(point, P(20, 10), P(100, 50)); | |
| 525 Point actual = set.ClosestPointTo(point); | |
| 526 EXPECT_POINT_EQ(expected, actual); | |
| 527 } | |
| 528 | |
| 529 // Close to oblique segment (100/1.5, 100) (10, 15) | |
| 530 { | |
| 531 Point point(12, 70); | |
| 532 Point expected = | |
| 533 ProjectionOnSegmentLine(point, P(100 / 1.5, 100), P(10, 15)); | |
| 534 Point actual = set.ClosestPointTo(point); | |
| 535 EXPECT_POINT_EQ(expected, actual); | |
| 536 } | |
| 537 | |
| 538 // Points close to vertices. | |
| 539 EXPECT_EQ(P(10, 10), set.ClosestPointTo(P(9, 9))); | |
| 540 EXPECT_EQ(P(20, 10), set.ClosestPointTo(P(20, 9))); | |
| 541 EXPECT_EQ(P(100, 50), set.ClosestPointTo(P(101, 50))); | |
| 542 EXPECT_EQ(P(100, 100), set.ClosestPointTo(P(101, 101))); | |
| 543 EXPECT_EQ(P(100 / 1.5, 100), set.ClosestPointTo(P(100 / 1.5, 101))); | |
| 544 EXPECT_EQ(P(10, 15), set.ClosestPointTo(P(9, 15))); | |
| 545 } | |
| 546 | |
| 547 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealIntersects) { | |
| 548 ResolutionSet set(100, 1000, 100, 1000, 0.5, 2.0); | |
|
hbos_chromium
2017/03/09 11:34:21
EXPECT_EQ the vertices returned by ComputeVertices
Guido Urdaneta
2017/03/09 17:55:43
I prefer to test that in ResolutionVertices. If yo
hbos_chromium
2017/03/10 09:17:26
Acknowledged.
| |
| 549 | |
| 550 int kIdealHeight = 500; | |
| 551 int kIdealWidth = 1000; | |
| 552 double kIdealAspectRatio = 1.5; | |
| 553 | |
| 554 // Ideal height. | |
| 555 { | |
| 556 factory_.Reset(); | |
| 557 factory_.basic().height.setIdeal(kIdealHeight); | |
| 558 Point point = set.SelectClosestPointToIdeal( | |
| 559 factory_.CreateWebMediaConstraints().basic()); | |
| 560 EXPECT_POINT_EQ( | |
| 561 Point(kIdealHeight, | |
| 562 kIdealHeight * MediaStreamVideoSource::kDefaultAspectRatio), | |
| 563 point); | |
| 564 } | |
| 565 | |
| 566 // Ideal width. | |
| 567 { | |
| 568 factory_.Reset(); | |
| 569 factory_.basic().width.setIdeal(kIdealWidth); | |
| 570 Point point = set.SelectClosestPointToIdeal( | |
| 571 factory_.CreateWebMediaConstraints().basic()); | |
| 572 EXPECT_POINT_EQ( | |
| 573 Point(kIdealWidth / MediaStreamVideoSource::kDefaultAspectRatio, | |
| 574 kIdealWidth), | |
| 575 point); | |
| 576 } | |
| 577 | |
| 578 // Ideal aspect ratio. | |
| 579 { | |
| 580 factory_.Reset(); | |
| 581 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 582 Point point = set.SelectClosestPointToIdeal( | |
| 583 factory_.CreateWebMediaConstraints().basic()); | |
| 584 EXPECT_DOUBLE_EQ(MediaStreamVideoSource::kDefaultHeight, point.height()); | |
| 585 EXPECT_DOUBLE_EQ(MediaStreamVideoSource::kDefaultHeight * kIdealAspectRatio, | |
| 586 point.width()); | |
| 587 } | |
| 588 | |
| 589 // Ideal height and width. | |
| 590 { | |
| 591 factory_.Reset(); | |
| 592 factory_.basic().height.setIdeal(kIdealHeight); | |
| 593 factory_.basic().width.setIdeal(kIdealWidth); | |
| 594 Point point = set.SelectClosestPointToIdeal( | |
| 595 factory_.CreateWebMediaConstraints().basic()); | |
| 596 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); | |
| 597 } | |
| 598 | |
| 599 // Ideal height and aspect-ratio. | |
| 600 { | |
| 601 factory_.Reset(); | |
| 602 factory_.basic().height.setIdeal(kIdealHeight); | |
| 603 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 604 Point point = set.SelectClosestPointToIdeal( | |
| 605 factory_.CreateWebMediaConstraints().basic()); | |
| 606 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealHeight * kIdealAspectRatio), | |
| 607 point); | |
| 608 } | |
| 609 | |
| 610 // Ideal width and aspect-ratio. | |
| 611 { | |
| 612 factory_.Reset(); | |
| 613 factory_.basic().width.setIdeal(kIdealWidth); | |
| 614 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 615 Point point = set.SelectClosestPointToIdeal( | |
| 616 factory_.CreateWebMediaConstraints().basic()); | |
| 617 EXPECT_POINT_EQ(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth), point); | |
| 618 } | |
| 619 | |
| 620 // Ideal height, width and aspect-ratio. | |
| 621 { | |
| 622 factory_.Reset(); | |
| 623 factory_.basic().height.setIdeal(kIdealHeight); | |
| 624 factory_.basic().width.setIdeal(kIdealWidth); | |
| 625 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 626 Point point = set.SelectClosestPointToIdeal( | |
| 627 factory_.CreateWebMediaConstraints().basic()); | |
| 628 // Ideal aspect ratio should be ignored. | |
| 629 EXPECT_POINT_EQ(Point(kIdealHeight, kIdealWidth), point); | |
| 630 } | |
| 631 } | |
| 632 | |
| 633 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionIdealOutsideSinglePoint) { | |
| 634 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | |
| 635 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); | |
|
hbos_chromium
2017/03/09 11:34:21
EXPECT_EQ the vertices returned by ComputeVertices
Guido Urdaneta
2017/03/09 17:55:43
Ditto.
| |
| 636 | |
| 637 int kIdealHeight = 50; | |
| 638 int kIdealWidth = 1100; | |
| 639 double kIdealAspectRatio = 0.09; | |
| 640 Point kVertex1(100, 100); | |
| 641 Point kVertex2(1000, 100); | |
| 642 Point kVertex3(1000, 1000); | |
| 643 | |
| 644 // Ideal height. | |
| 645 { | |
| 646 factory_.Reset(); | |
| 647 factory_.basic().height.setIdeal(kIdealHeight); | |
| 648 Point point = set.SelectClosestPointToIdeal( | |
| 649 factory_.CreateWebMediaConstraints().basic()); | |
| 650 EXPECT_POINT_EQ(kVertex1, point); | |
| 651 } | |
| 652 | |
| 653 // Ideal width. | |
| 654 { | |
| 655 factory_.Reset(); | |
| 656 factory_.basic().width.setIdeal(kIdealWidth); | |
| 657 Point point = set.SelectClosestPointToIdeal( | |
| 658 factory_.CreateWebMediaConstraints().basic()); | |
| 659 EXPECT_POINT_EQ(kVertex3, point); | |
| 660 } | |
| 661 | |
| 662 // Ideal aspect ratio. | |
| 663 { | |
| 664 factory_.Reset(); | |
| 665 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 666 Point point = set.SelectClosestPointToIdeal( | |
| 667 factory_.CreateWebMediaConstraints().basic()); | |
| 668 EXPECT_POINT_EQ(kVertex2, point); | |
| 669 } | |
| 670 | |
| 671 // Ideal height and width. | |
| 672 { | |
| 673 factory_.Reset(); | |
| 674 factory_.basic().height.setIdeal(kIdealHeight); | |
| 675 factory_.basic().width.setIdeal(kIdealWidth); | |
| 676 Point point = set.SelectClosestPointToIdeal( | |
| 677 factory_.CreateWebMediaConstraints().basic()); | |
| 678 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); | |
| 679 EXPECT_POINT_EQ(expected, point); | |
| 680 } | |
| 681 | |
| 682 // Ideal height and aspect-ratio. | |
| 683 { | |
| 684 factory_.Reset(); | |
| 685 factory_.basic().height.setIdeal(kIdealHeight); | |
| 686 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 687 Point point = set.SelectClosestPointToIdeal( | |
| 688 factory_.CreateWebMediaConstraints().basic()); | |
| 689 Point expected = set.ClosestPointTo( | |
| 690 Point(kIdealHeight, kIdealHeight * kIdealAspectRatio)); | |
| 691 EXPECT_POINT_EQ(expected, point); | |
| 692 } | |
| 693 | |
| 694 // Ideal width and aspect-ratio. | |
| 695 { | |
| 696 factory_.Reset(); | |
| 697 factory_.basic().width.setIdeal(kIdealWidth); | |
| 698 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 699 Point point = set.SelectClosestPointToIdeal( | |
| 700 factory_.CreateWebMediaConstraints().basic()); | |
| 701 Point expected = | |
| 702 set.ClosestPointTo(Point(kIdealWidth / kIdealAspectRatio, kIdealWidth)); | |
| 703 EXPECT_POINT_EQ(expected, point); | |
| 704 } | |
| 705 | |
| 706 // Ideal height, width and aspect-ratio. | |
| 707 { | |
| 708 factory_.Reset(); | |
| 709 factory_.basic().height.setIdeal(kIdealHeight); | |
| 710 factory_.basic().width.setIdeal(kIdealWidth); | |
| 711 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
|
hbos_chromium
2017/03/09 11:34:21
Comment saying the ideal aspect ratio doesn't matt
Guido Urdaneta
2017/03/09 17:55:43
Done.
| |
| 712 Point point = set.SelectClosestPointToIdeal( | |
| 713 factory_.CreateWebMediaConstraints().basic()); | |
| 714 Point expected = set.ClosestPointTo(Point(kIdealHeight, kIdealWidth)); | |
| 715 EXPECT_POINT_EQ(expected, point); | |
| 716 } | |
| 717 } | |
| 718 | |
| 719 TEST_F(MediaStreamConstraintsUtilSetsTest, | |
| 720 ResolutionIdealOutsideMultiplePoints) { | |
| 721 // This set is a triangle with vertices (100,100), (1000,100) and (1000,1000). | |
| 722 ResolutionSet set(100, 1000, 100, 1000, 0.0, 1.0); | |
|
hbos_chromium
2017/03/09 11:34:21
EXPECT_EQ the vertices returned by ComputeVertices
Guido Urdaneta
2017/03/09 17:55:43
Ditto.
| |
| 723 | |
| 724 int kIdealHeight = 1100; | |
| 725 int kIdealWidth = 50; | |
| 726 double kIdealAspectRatio = 11.0; | |
| 727 Point kVertex1(100, 100); | |
| 728 Point kVertex2(1000, 100); | |
| 729 Point kVertex3(1000, 1000); | |
| 730 | |
| 731 // Ideal height. | |
| 732 { | |
| 733 factory_.Reset(); | |
| 734 factory_.basic().height.setIdeal(kIdealHeight); | |
| 735 Point point = set.SelectClosestPointToIdeal( | |
| 736 factory_.CreateWebMediaConstraints().basic()); | |
| 737 // Parallel to the side between kVertex2 and kVertex3. Point closest to | |
| 738 // default aspect ratio is kVertex3. | |
| 739 EXPECT_POINT_EQ(kVertex3, point); | |
| 740 } | |
| 741 | |
| 742 // Ideal width. | |
| 743 { | |
| 744 factory_.Reset(); | |
| 745 factory_.basic().width.setIdeal(kIdealWidth); | |
| 746 Point point = set.SelectClosestPointToIdeal( | |
| 747 factory_.CreateWebMediaConstraints().basic()); | |
| 748 // Parallel to the side between kVertex1 and kVertex2. Point closest to | |
| 749 // default aspect ratio is kVertex1. | |
| 750 EXPECT_POINT_EQ(kVertex1, point); | |
| 751 } | |
| 752 | |
| 753 // Ideal aspect ratio. | |
| 754 { | |
| 755 factory_.Reset(); | |
| 756 factory_.basic().aspectRatio.setIdeal(kIdealAspectRatio); | |
| 757 Point point = set.SelectClosestPointToIdeal( | |
| 758 factory_.CreateWebMediaConstraints().basic()); | |
| 759 // The side between kVertex1 and kVertex3 is closest. The points closest to | |
| 760 // default dimensions are (kDefaultHeight, kDefaultHeight * AR) | |
| 761 // and (kDefaultWidth / AR, kDefaultWidth). Since the aspect ratio of the | |
| 762 // polygon side is less than the default, the algorithm preserves the | |
| 763 // default width. | |
| 764 EXPECT_POINT_EQ( | |
| 765 Point(MediaStreamVideoSource::kDefaultWidth / kVertex1.AspectRatio(), | |
| 766 MediaStreamVideoSource::kDefaultWidth), | |
|
hbos_chromium
2017/03/09 11:34:21
EXPECT_EQ that this point is inside the set.
Guido Urdaneta
2017/03/09 17:55:43
Done.
| |
| 767 point); | |
| 768 } | |
| 769 } | |
| 770 | |
| 771 TEST_F(MediaStreamConstraintsUtilSetsTest, | |
| 772 ResolutionUnconstrainedExtremeIdeal) { | |
| 773 ResolutionSet set; | |
| 774 | |
| 775 // Ideal height. | |
| 776 { | |
| 777 factory_.Reset(); | |
| 778 factory_.basic().height.setIdeal(std::numeric_limits<long>::max()); | |
| 779 Point point = set.SelectClosestPointToIdeal( | |
| 780 factory_.CreateWebMediaConstraints().basic()); | |
| 781 EXPECT_POINT_EQ( | |
| 782 Point(ResolutionSet::kMaxDimension, ResolutionSet::kMaxDimension), | |
| 783 point); | |
| 784 factory_.basic().height.setIdeal(0); | |
| 785 point = set.SelectClosestPointToIdeal( | |
| 786 factory_.CreateWebMediaConstraints().basic()); | |
| 787 EXPECT_POINT_EQ(Point(0, 0), point); | |
| 788 } | |
| 789 | |
| 790 // Ideal width. | |
| 791 { | |
| 792 factory_.Reset(); | |
| 793 factory_.basic().width.setIdeal(std::numeric_limits<long>::max()); | |
| 794 Point point = set.SelectClosestPointToIdeal( | |
| 795 factory_.CreateWebMediaConstraints().basic()); | |
| 796 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension / | |
| 797 MediaStreamVideoSource::kDefaultAspectRatio, | |
| 798 ResolutionSet::kMaxDimension), | |
| 799 point); | |
| 800 factory_.basic().width.setIdeal(0); | |
| 801 point = set.SelectClosestPointToIdeal( | |
| 802 factory_.CreateWebMediaConstraints().basic()); | |
| 803 EXPECT_POINT_EQ(Point(0, 0), point); | |
| 804 } | |
| 805 | |
| 806 // Ideal Aspect Ratio. | |
| 807 { | |
| 808 factory_.Reset(); | |
| 809 factory_.basic().aspectRatio.setIdeal(HUGE_VAL); | |
| 810 Point point = set.SelectClosestPointToIdeal( | |
| 811 factory_.CreateWebMediaConstraints().basic()); | |
| 812 EXPECT_POINT_EQ(Point(0, ResolutionSet::kMaxDimension), point); | |
| 813 factory_.basic().aspectRatio.setIdeal(0.0); | |
| 814 point = set.SelectClosestPointToIdeal( | |
| 815 factory_.CreateWebMediaConstraints().basic()); | |
| 816 EXPECT_POINT_EQ(Point(ResolutionSet::kMaxDimension, 0), point); | |
| 817 } | |
| 818 } | |
| 819 | |
| 820 TEST_F(MediaStreamConstraintsUtilSetsTest, ResolutionVertices) { | |
|
hbos_chromium
2017/03/09 11:34:21
Should VerticesContains be replaced by vertices wh
Guido Urdaneta
2017/03/09 17:55:43
Changed AreValidVertices to check that the vertice
| |
| 821 // Empty set. | |
| 822 { | |
| 823 ResolutionSet set(1000, 100, 1000, 100, 0.5, 1.5); | |
| 824 ASSERT_TRUE(set.IsEmpty()); | |
| 825 auto vertices = set.ComputeVertices(); | |
| 826 EXPECT_EQ(0U, vertices.size()); | |
| 827 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 828 } | |
| 829 | |
| 830 // Three lines that intersect at the same point. | |
| 831 { | |
| 832 ResolutionSet set(1, 1, 1, 1, 1, 1); | |
| 833 EXPECT_FALSE(set.IsEmpty()); | |
| 834 auto vertices = set.ComputeVertices(); | |
| 835 EXPECT_EQ(1U, vertices.size()); | |
| 836 VerticesContain(vertices, Point(1, 1)); | |
| 837 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 838 } | |
| 839 | |
| 840 // A line segment with the lower-left and upper-right corner of the box. | |
| 841 { | |
| 842 ResolutionSet set(0, 100, 0, 100, 1.0, 1.0); | |
| 843 EXPECT_FALSE(set.IsEmpty()); | |
| 844 auto vertices = set.ComputeVertices(); | |
| 845 EXPECT_EQ(2U, vertices.size()); | |
| 846 VerticesContain(vertices, Point(0, 0)); | |
| 847 VerticesContain(vertices, Point(100, 100)); | |
| 848 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 849 | |
| 850 set = ResolutionSet(0, 100, 0, 100, 1.0, HUGE_VAL); | |
| 851 EXPECT_FALSE(set.IsEmpty()); | |
| 852 vertices = set.ComputeVertices(); | |
| 853 EXPECT_EQ(3U, vertices.size()); | |
| 854 VerticesContain(vertices, Point(0, 0)); | |
| 855 VerticesContain(vertices, Point(100, 100)); | |
| 856 VerticesContain(vertices, Point(0, 100)); | |
| 857 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 858 | |
| 859 set = ResolutionSet(0, 100, 0, 100, 0, 1.0); | |
| 860 EXPECT_FALSE(set.IsEmpty()); | |
| 861 vertices = set.ComputeVertices(); | |
| 862 EXPECT_EQ(3U, vertices.size()); | |
| 863 VerticesContain(vertices, Point(0, 0)); | |
| 864 VerticesContain(vertices, Point(100, 100)); | |
| 865 VerticesContain(vertices, Point(100, 0)); | |
| 866 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 867 } | |
| 868 | |
| 869 // A line segment that crosses the bottom and right sides of the box. | |
| 870 { | |
| 871 const double kAspectRatio = 50.0 / 75.0; | |
| 872 ResolutionSet set(50, 100, 50, 100, kAspectRatio, kAspectRatio); | |
| 873 auto vertices = set.ComputeVertices(); | |
| 874 EXPECT_EQ(2U, vertices.size()); | |
| 875 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 876 VerticesContain(vertices, Point(100, 100.0 * kAspectRatio)); | |
| 877 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 878 | |
| 879 set = ResolutionSet(50, 100, 50, 100, kAspectRatio, HUGE_VAL); | |
| 880 vertices = set.ComputeVertices(); | |
| 881 EXPECT_EQ(5U, vertices.size()); | |
| 882 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 883 VerticesContain(vertices, Point(100, 100.0 * kAspectRatio)); | |
| 884 VerticesContain(vertices, Point(50, 50)); | |
| 885 VerticesContain(vertices, Point(50, 100)); | |
| 886 VerticesContain(vertices, Point(100, 100)); | |
| 887 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 888 | |
| 889 set = ResolutionSet(50, 100, 50, 100, 0.0, kAspectRatio); | |
| 890 vertices = set.ComputeVertices(); | |
| 891 EXPECT_EQ(3U, vertices.size()); | |
| 892 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 893 VerticesContain(vertices, Point(100, 100.0 * kAspectRatio)); | |
| 894 VerticesContain(vertices, Point(100, 50)); | |
| 895 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 896 } | |
| 897 | |
| 898 // A line segment that crosses the left and top sides of the box. | |
| 899 { | |
| 900 const double kAspectRatio = 75.0 / 50.0; | |
| 901 ResolutionSet set(50, 100, 50, 100, kAspectRatio, kAspectRatio); | |
| 902 auto vertices = set.ComputeVertices(); | |
| 903 EXPECT_EQ(2U, vertices.size()); | |
| 904 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 905 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 906 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 907 | |
| 908 set = ResolutionSet(50, 100, 50, 100, kAspectRatio, HUGE_VAL); | |
| 909 vertices = set.ComputeVertices(); | |
| 910 EXPECT_EQ(3U, vertices.size()); | |
| 911 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 912 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 913 VerticesContain(vertices, Point(50, 100)); | |
| 914 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 915 | |
| 916 set = ResolutionSet(50, 100, 50, 100, 0.0, kAspectRatio); | |
| 917 vertices = set.ComputeVertices(); | |
| 918 EXPECT_EQ(5U, vertices.size()); | |
| 919 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 920 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 921 VerticesContain(vertices, Point(50, 50)); | |
| 922 VerticesContain(vertices, Point(100, 100)); | |
| 923 VerticesContain(vertices, Point(100, 50)); | |
| 924 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 925 } | |
| 926 | |
| 927 // An aspect ratio constraint crosses the bottom and top sides of the box. | |
| 928 { | |
| 929 const double kAspectRatio = 75.0 / 50.0; | |
| 930 ResolutionSet set(0, 100, 50, 100, kAspectRatio, kAspectRatio); | |
| 931 auto vertices = set.ComputeVertices(); | |
| 932 EXPECT_EQ(2U, vertices.size()); | |
| 933 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 934 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 935 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 936 | |
| 937 set = ResolutionSet(0, 100, 50, 100, kAspectRatio, HUGE_VAL); | |
| 938 vertices = set.ComputeVertices(); | |
| 939 EXPECT_EQ(4U, vertices.size()); | |
| 940 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 941 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 942 VerticesContain(vertices, Point(0, 50)); | |
| 943 VerticesContain(vertices, Point(0, 100)); | |
| 944 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 945 | |
| 946 set = ResolutionSet(0, 100, 50, 100, 0.0, kAspectRatio); | |
| 947 vertices = set.ComputeVertices(); | |
| 948 EXPECT_EQ(4U, vertices.size()); | |
| 949 VerticesContain(vertices, Point(50 / kAspectRatio, 50)); | |
| 950 VerticesContain(vertices, Point(100 / kAspectRatio, 100)); | |
| 951 VerticesContain(vertices, Point(100, 50)); | |
| 952 VerticesContain(vertices, Point(100, 100)); | |
| 953 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 954 } | |
| 955 | |
| 956 // An aspect-ratio constraint crosses the left and right sides of the box. | |
| 957 { | |
| 958 const double kAspectRatio = 75.0 / 50.0; | |
| 959 ResolutionSet set(50, 100, 0, 200, kAspectRatio, kAspectRatio); | |
| 960 auto vertices = set.ComputeVertices(); | |
| 961 // This one fails if floating-point precision is too high. | |
| 962 EXPECT_EQ(2U, vertices.size()); | |
| 963 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 964 VerticesContain(vertices, Point(100, 100 * kAspectRatio)); | |
| 965 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 966 | |
| 967 set = ResolutionSet(50, 100, 0, 200, kAspectRatio, HUGE_VAL); | |
| 968 vertices = set.ComputeVertices(); | |
| 969 // This one fails if floating-point precision is too high. | |
| 970 EXPECT_EQ(4U, vertices.size()); | |
| 971 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 972 VerticesContain(vertices, Point(100, 100 * kAspectRatio)); | |
| 973 VerticesContain(vertices, Point(50, 200)); | |
| 974 VerticesContain(vertices, Point(100, 200)); | |
| 975 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 976 | |
| 977 set = ResolutionSet(50, 100, 0, 200, 0.0, kAspectRatio); | |
| 978 vertices = set.ComputeVertices(); | |
| 979 EXPECT_EQ(4U, vertices.size()); | |
| 980 VerticesContain(vertices, Point(50, 50 * kAspectRatio)); | |
| 981 VerticesContain(vertices, Point(100, 100 * kAspectRatio)); | |
| 982 VerticesContain(vertices, Point(50, 0)); | |
| 983 VerticesContain(vertices, Point(100, 0)); | |
| 984 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 985 } | |
| 986 | |
| 987 // Aspect-ratio lines touch the corners of the box. | |
| 988 { | |
| 989 ResolutionSet set(50, 100, 50, 100, 0.5, 2.0); | |
| 990 auto vertices = set.ComputeVertices(); | |
| 991 EXPECT_EQ(4U, vertices.size()); | |
| 992 VerticesContain(vertices, Point(50, 50)); | |
| 993 VerticesContain(vertices, Point(100, 50)); | |
| 994 VerticesContain(vertices, Point(50, 100)); | |
| 995 VerticesContain(vertices, Point(100, 100)); | |
| 996 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 997 } | |
| 998 | |
| 999 // Hexagons. | |
| 1000 { | |
| 1001 ResolutionSet set(10, 100, 10, 100, 0.5, 1.5); | |
| 1002 auto vertices = set.ComputeVertices(); | |
| 1003 EXPECT_EQ(6U, vertices.size()); | |
| 1004 VerticesContain(vertices, Point(10, 10)); | |
| 1005 VerticesContain(vertices, Point(100, 100)); | |
| 1006 VerticesContain(vertices, Point(10, 10 * 1.5)); | |
| 1007 VerticesContain(vertices, Point(100 / 1.5, 100)); | |
| 1008 VerticesContain(vertices, Point(10 / 0.5, 10)); | |
| 1009 VerticesContain(vertices, Point(100, 100 * 0.5)); | |
| 1010 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1011 | |
| 1012 set = ResolutionSet(50, 100, 50, 100, 50.0 / 75.0, 75.0 / 50.0); | |
| 1013 vertices = set.ComputeVertices(); | |
| 1014 EXPECT_EQ(6U, vertices.size()); | |
| 1015 VerticesContain(vertices, Point(50, 50)); | |
| 1016 VerticesContain(vertices, Point(100, 100)); | |
| 1017 VerticesContain(vertices, Point(75, 50)); | |
| 1018 VerticesContain(vertices, Point(50, 75)); | |
| 1019 VerticesContain(vertices, Point(100, 100.0 * 50.0 / 75.0)); | |
| 1020 VerticesContain(vertices, Point(100 * 50.0 / 75.0, 100.0)); | |
| 1021 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1022 } | |
| 1023 | |
| 1024 // Both aspect-ratio constraints cross the left and top sides of the box. | |
| 1025 { | |
| 1026 ResolutionSet set(10, 100, 10, 100, 1.5, 1.7); | |
| 1027 auto vertices = set.ComputeVertices(); | |
| 1028 EXPECT_EQ(4U, vertices.size()); | |
| 1029 VerticesContain(vertices, Point(10, 10 * 1.5)); | |
| 1030 VerticesContain(vertices, Point(10, 10 * 1.7)); | |
| 1031 VerticesContain(vertices, Point(100 / 1.5, 100)); | |
| 1032 VerticesContain(vertices, Point(100 / 1.7, 100)); | |
| 1033 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1034 } | |
| 1035 | |
| 1036 // Both aspect-ratio constraints cross the left and right sides of the box. | |
| 1037 { | |
| 1038 ResolutionSet set(10, 100, 10, ResolutionSet::kMaxDimension, 1.5, 1.7); | |
| 1039 auto vertices = set.ComputeVertices(); | |
| 1040 EXPECT_EQ(4U, vertices.size()); | |
| 1041 VerticesContain(vertices, Point(10, 10 * 1.5)); | |
| 1042 VerticesContain(vertices, Point(10, 10 * 1.7)); | |
| 1043 VerticesContain(vertices, Point(100, 100 * 1.5)); | |
| 1044 VerticesContain(vertices, Point(100, 100 * 1.7)); | |
| 1045 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1046 } | |
| 1047 | |
| 1048 // Both aspect-ratio constraints cross the bottom and top sides of the box. | |
| 1049 { | |
| 1050 ResolutionSet set(10, 100, 50, 100, 2.0, 4.0); | |
| 1051 auto vertices = set.ComputeVertices(); | |
| 1052 EXPECT_EQ(4U, vertices.size()); | |
| 1053 VerticesContain(vertices, Point(50 / 2.0, 50)); | |
| 1054 VerticesContain(vertices, Point(100 / 2.0, 100)); | |
| 1055 VerticesContain(vertices, Point(50 / 4.0, 50)); | |
| 1056 VerticesContain(vertices, Point(100 / 4.0, 100)); | |
| 1057 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1058 } | |
| 1059 | |
| 1060 // Both aspect-ratio constraints cross the bottom and right sides of the box. | |
| 1061 { | |
| 1062 ResolutionSet set(10, 100, 50, 100, 0.7, 0.9); | |
| 1063 auto vertices = set.ComputeVertices(); | |
| 1064 EXPECT_EQ(4U, vertices.size()); | |
| 1065 VerticesContain(vertices, Point(50 / 0.7, 50)); | |
| 1066 VerticesContain(vertices, Point(50 / 0.9, 50)); | |
| 1067 VerticesContain(vertices, Point(100, 100 * 0.7)); | |
| 1068 VerticesContain(vertices, Point(100, 100 * 0.9)); | |
| 1069 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1070 } | |
| 1071 | |
| 1072 // Pentagons. | |
| 1073 { | |
| 1074 ResolutionSet set(10, 100, 50, 100, 0.7, 4.0); | |
| 1075 auto vertices = set.ComputeVertices(); | |
| 1076 EXPECT_EQ(5U, vertices.size()); | |
| 1077 VerticesContain(vertices, Point(50 / 0.7, 50)); | |
| 1078 VerticesContain(vertices, Point(100, 100 * 0.7)); | |
| 1079 VerticesContain(vertices, Point(50 / 4.0, 50)); | |
| 1080 VerticesContain(vertices, Point(100 / 4.0, 100)); | |
| 1081 VerticesContain(vertices, Point(100, 100)); | |
| 1082 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1083 | |
| 1084 set = ResolutionSet(50, 100, 10, 100, 0.7, 1.5); | |
| 1085 vertices = set.ComputeVertices(); | |
| 1086 EXPECT_EQ(5U, vertices.size()); | |
| 1087 VerticesContain(vertices, Point(50, 50 * 0.7)); | |
| 1088 VerticesContain(vertices, Point(100, 100 * 0.7)); | |
| 1089 VerticesContain(vertices, Point(50, 50 * 1.5)); | |
| 1090 VerticesContain(vertices, Point(100 / 1.5, 100)); | |
| 1091 VerticesContain(vertices, Point(100, 100)); | |
| 1092 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1093 } | |
| 1094 | |
| 1095 // Extreme aspect ratios, for completeness. | |
| 1096 { | |
| 1097 ResolutionSet set(0, 100, 0, ResolutionSet::kMaxDimension, 0.0, 0.0); | |
| 1098 auto vertices = set.ComputeVertices(); | |
| 1099 EXPECT_EQ(2U, vertices.size()); | |
| 1100 VerticesContain(vertices, Point(0, 0)); | |
| 1101 VerticesContain(vertices, Point(100, 0)); | |
| 1102 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1103 | |
| 1104 set = ResolutionSet(0, ResolutionSet::kMaxDimension, 0, 100, HUGE_VAL, | |
| 1105 HUGE_VAL); | |
| 1106 vertices = set.ComputeVertices(); | |
| 1107 EXPECT_EQ(2U, vertices.size()); | |
| 1108 VerticesContain(vertices, Point(0, 0)); | |
| 1109 VerticesContain(vertices, Point(0, 100)); | |
| 1110 EXPECT_TRUE(AreValidVertices(vertices)); | |
| 1111 } | |
| 1112 } | |
| 1113 | |
| 1114 TEST_F(MediaStreamConstraintsUtilSetsTest, NumericRangeSetDouble) { | |
| 1115 using DoubleRangeSet = NumericRangeSet<double>; | |
| 1116 // Unconstrained set. | |
|
hbos_chromium
2017/03/09 11:34:22
Here and elsewhere: "unconstrained" -> "universal"
Guido Urdaneta
2017/03/09 17:55:43
Done.
| |
| 1117 DoubleRangeSet set; | |
| 1118 EXPECT_EQ(0.0, set.Min()); | |
| 1119 EXPECT_EQ(HUGE_VAL, set.Max()); | |
| 1120 EXPECT_FALSE(set.IsEmpty()); | |
| 1121 | |
| 1122 // Constrained set. | |
| 1123 const double kMin = 1.0; | |
| 1124 const double kMax = 10.0; | |
| 1125 set = DoubleRangeSet(kMin, kMax); | |
| 1126 EXPECT_EQ(kMin, set.Min()); | |
| 1127 EXPECT_EQ(kMax, set.Max()); | |
| 1128 EXPECT_FALSE(set.IsEmpty()); | |
| 1129 | |
| 1130 // Empty set. | |
| 1131 set = DoubleRangeSet(kMax, kMin); | |
| 1132 EXPECT_TRUE(set.IsEmpty()); | |
| 1133 | |
| 1134 // Intersection. | |
| 1135 set = DoubleRangeSet(kMin, kMax); | |
| 1136 const double kMin2 = 5.0; | |
| 1137 const double kMax2 = 20.0; | |
| 1138 auto intersection = set.Intersection(DoubleRangeSet(kMin2, kMax2)); | |
| 1139 EXPECT_EQ(kMin2, intersection.Min()); | |
| 1140 EXPECT_EQ(kMax, intersection.Max()); | |
| 1141 EXPECT_FALSE(intersection.IsEmpty()); | |
| 1142 | |
| 1143 // Empty intersection. | |
| 1144 intersection = set.Intersection(DoubleRangeSet(kMax + 1, HUGE_VAL)); | |
| 1145 EXPECT_TRUE(intersection.IsEmpty()); | |
| 1146 } | |
| 1147 | |
| 1148 TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetString) { | |
| 1149 // Unconstrained set. | |
| 1150 using StringSet = DiscreteSet<std::string>; | |
| 1151 StringSet set = StringSet::UniversalSet(); | |
| 1152 EXPECT_TRUE(set.Contains("arbitrary")); | |
| 1153 EXPECT_TRUE(set.Contains("strings")); | |
| 1154 EXPECT_FALSE(set.IsEmpty()); | |
| 1155 EXPECT_TRUE(set.is_universal()); | |
| 1156 EXPECT_FALSE(set.HasExplicitElements()); | |
| 1157 | |
| 1158 // Constrained set. | |
| 1159 set = StringSet(std::vector<std::string>({"a", "b", "c"})); | |
| 1160 EXPECT_TRUE(set.Contains("a")); | |
| 1161 EXPECT_TRUE(set.Contains("b")); | |
| 1162 EXPECT_TRUE(set.Contains("c")); | |
| 1163 EXPECT_FALSE(set.Contains("d")); | |
| 1164 EXPECT_FALSE(set.IsEmpty()); | |
| 1165 EXPECT_FALSE(set.is_universal()); | |
| 1166 EXPECT_TRUE(set.HasExplicitElements()); | |
| 1167 EXPECT_EQ(std::string("a"), set.FirstElement()); | |
| 1168 | |
| 1169 // Empty set. | |
| 1170 set = StringSet::EmptySet(); | |
| 1171 EXPECT_FALSE(set.Contains("a")); | |
| 1172 EXPECT_FALSE(set.Contains("b")); | |
| 1173 EXPECT_TRUE(set.IsEmpty()); | |
| 1174 EXPECT_FALSE(set.is_universal()); | |
| 1175 EXPECT_FALSE(set.HasExplicitElements()); | |
| 1176 | |
| 1177 // Intersection. | |
| 1178 set = StringSet(std::vector<std::string>({"a", "b", "c"})); | |
| 1179 StringSet set2 = StringSet(std::vector<std::string>({"b", "c", "d"})); | |
| 1180 auto intersection = set.Intersection(set2); | |
| 1181 EXPECT_FALSE(intersection.Contains("a")); | |
| 1182 EXPECT_TRUE(intersection.Contains("b")); | |
| 1183 EXPECT_TRUE(intersection.Contains("c")); | |
| 1184 EXPECT_FALSE(intersection.Contains("d")); | |
| 1185 EXPECT_FALSE(intersection.IsEmpty()); | |
| 1186 EXPECT_FALSE(intersection.is_universal()); | |
| 1187 EXPECT_TRUE(intersection.HasExplicitElements()); | |
| 1188 EXPECT_EQ(std::string("b"), intersection.FirstElement()); | |
| 1189 | |
| 1190 // Empty intersection. | |
| 1191 set2 = StringSet(std::vector<std::string>({"d", "e", "f"})); | |
| 1192 intersection = set.Intersection(set2); | |
| 1193 EXPECT_FALSE(intersection.Contains("a")); | |
| 1194 EXPECT_FALSE(intersection.Contains("b")); | |
| 1195 EXPECT_FALSE(intersection.Contains("c")); | |
| 1196 EXPECT_FALSE(intersection.Contains("d")); | |
| 1197 EXPECT_TRUE(intersection.IsEmpty()); | |
| 1198 EXPECT_FALSE(intersection.is_universal()); | |
| 1199 EXPECT_FALSE(intersection.HasExplicitElements()); | |
| 1200 } | |
| 1201 | |
| 1202 TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetBool) { | |
| 1203 using BoolSet = DiscreteSet<bool>; | |
| 1204 // Unconstrained set. | |
| 1205 BoolSet set = BoolSet::UniversalSet(); | |
| 1206 EXPECT_TRUE(set.Contains(true)); | |
| 1207 EXPECT_TRUE(set.Contains(false)); | |
| 1208 EXPECT_FALSE(set.IsEmpty()); | |
| 1209 EXPECT_TRUE(set.is_universal()); | |
| 1210 EXPECT_FALSE(set.HasExplicitElements()); | |
| 1211 | |
| 1212 // Constrained set. | |
| 1213 set = BoolSet({true}); | |
| 1214 EXPECT_TRUE(set.Contains(true)); | |
| 1215 EXPECT_FALSE(set.Contains(false)); | |
| 1216 EXPECT_FALSE(set.IsEmpty()); | |
| 1217 EXPECT_FALSE(set.is_universal()); | |
| 1218 EXPECT_TRUE(set.HasExplicitElements()); | |
| 1219 EXPECT_TRUE(set.FirstElement()); | |
| 1220 | |
| 1221 set = BoolSet({false}); | |
| 1222 EXPECT_FALSE(set.Contains(true)); | |
| 1223 EXPECT_TRUE(set.Contains(false)); | |
| 1224 EXPECT_FALSE(set.IsEmpty()); | |
| 1225 EXPECT_FALSE(set.is_universal()); | |
| 1226 EXPECT_TRUE(set.HasExplicitElements()); | |
| 1227 EXPECT_FALSE(set.FirstElement()); | |
| 1228 | |
| 1229 // Empty set. | |
| 1230 set = BoolSet::EmptySet(); | |
| 1231 EXPECT_FALSE(set.Contains(true)); | |
| 1232 EXPECT_FALSE(set.Contains(false)); | |
| 1233 EXPECT_TRUE(set.IsEmpty()); | |
| 1234 EXPECT_FALSE(set.is_universal()); | |
| 1235 EXPECT_FALSE(set.HasExplicitElements()); | |
| 1236 | |
| 1237 // Intersection. | |
| 1238 set = BoolSet::UniversalSet(); | |
| 1239 auto intersection = set.Intersection(BoolSet({true})); | |
| 1240 EXPECT_TRUE(intersection.Contains(true)); | |
| 1241 EXPECT_FALSE(intersection.Contains(false)); | |
| 1242 intersection = set.Intersection(set); | |
| 1243 EXPECT_TRUE(intersection.Contains(true)); | |
| 1244 EXPECT_TRUE(intersection.Contains(true)); | |
| 1245 | |
| 1246 // Empty intersection. | |
| 1247 set = BoolSet({true}); | |
| 1248 intersection = set.Intersection(BoolSet({false})); | |
| 1249 EXPECT_TRUE(intersection.IsEmpty()); | |
| 1250 } | |
| 1251 | |
| 1252 } // namespace content | |
| OLD | NEW |