video_aspect_ratio_unittest.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2021 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. #include "media/base/video_aspect_ratio.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. #include "ui/gfx/geometry/rect.h"
  7. #include "ui/gfx/geometry/size.h"
  8. namespace media {
  9. namespace {
  10. constexpr gfx::Rect kRect_4_3(0, 0, 4, 3);
  11. constexpr gfx::Rect kRect_16_9(0, 0, 16, 9);
  12. } // namespace
  13. TEST(VideoAspectRatioTest, DefaultConstruction) {
  14. VideoAspectRatio aspect_ratio;
  15. EXPECT_FALSE(aspect_ratio.IsValid());
  16. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 9));
  17. }
  18. TEST(VideoAspectRatioTest, FromNaturalSize) {
  19. VideoAspectRatio aspect_ratio;
  20. aspect_ratio = VideoAspectRatio(kRect_16_9, gfx::Size(16, 9));
  21. EXPECT_TRUE(aspect_ratio.IsValid());
  22. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 9));
  23. aspect_ratio = VideoAspectRatio(kRect_4_3, gfx::Size(16, 9));
  24. EXPECT_TRUE(aspect_ratio.IsValid());
  25. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_4_3), gfx::Size(5, 3));
  26. aspect_ratio = VideoAspectRatio(kRect_16_9, gfx::Size(4, 3));
  27. EXPECT_TRUE(aspect_ratio.IsValid());
  28. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 12));
  29. }
  30. TEST(VideoAspectRatioTest, Pixel) {
  31. VideoAspectRatio aspect_ratio;
  32. aspect_ratio = VideoAspectRatio::PAR(1, 1);
  33. EXPECT_TRUE(aspect_ratio.IsValid());
  34. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 9));
  35. aspect_ratio = VideoAspectRatio::PAR(1, 2);
  36. EXPECT_TRUE(aspect_ratio.IsValid());
  37. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 18));
  38. aspect_ratio = VideoAspectRatio::PAR(2, 1);
  39. EXPECT_TRUE(aspect_ratio.IsValid());
  40. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(32, 9));
  41. }
  42. TEST(VideoAspectRatioTest, Display) {
  43. VideoAspectRatio aspect_ratio;
  44. aspect_ratio = VideoAspectRatio::DAR(1, 1);
  45. EXPECT_TRUE(aspect_ratio.IsValid());
  46. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 16));
  47. aspect_ratio = VideoAspectRatio::DAR(1, 2);
  48. EXPECT_TRUE(aspect_ratio.IsValid());
  49. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(16, 32));
  50. aspect_ratio = VideoAspectRatio::DAR(2, 1);
  51. EXPECT_TRUE(aspect_ratio.IsValid());
  52. EXPECT_EQ(aspect_ratio.GetNaturalSize(kRect_16_9), gfx::Size(18, 9));
  53. }
  54. } // namespace media