shadow_value_unittest.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2012 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 "ui/gfx/shadow_value.h"
  5. #include <stddef.h>
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. #include "ui/gfx/geometry/insets.h"
  8. #include "ui/gfx/geometry/vector2d.h"
  9. namespace gfx {
  10. TEST(ShadowValueTest, GetMargin) {
  11. constexpr struct TestCase {
  12. Insets expected_margin;
  13. size_t shadow_count;
  14. ShadowValue shadows[2];
  15. } kTestCases[] = {
  16. {
  17. Insets(),
  18. 0,
  19. {},
  20. },
  21. {
  22. Insets(-2),
  23. 1,
  24. {
  25. {gfx::Vector2d(0, 0), 4, 0},
  26. },
  27. },
  28. {
  29. Insets::TLBR(0, -1, -4, -3),
  30. 1,
  31. {
  32. {gfx::Vector2d(1, 2), 4, 0},
  33. },
  34. },
  35. {
  36. Insets::TLBR(-4, -3, 0, -1),
  37. 1,
  38. {
  39. {gfx::Vector2d(-1, -2), 4, 0},
  40. },
  41. },
  42. {
  43. Insets::TLBR(0, -1, -5, -4),
  44. 2,
  45. {
  46. {gfx::Vector2d(1, 2), 4, 0},
  47. {gfx::Vector2d(2, 3), 4, 0},
  48. },
  49. },
  50. {
  51. Insets::TLBR(-4, -3, -5, -4),
  52. 2,
  53. {
  54. {gfx::Vector2d(-1, -2), 4, 0},
  55. {gfx::Vector2d(2, 3), 4, 0},
  56. },
  57. },
  58. };
  59. for (size_t i = 0; i < std::size(kTestCases); ++i) {
  60. Insets margin = ShadowValue::GetMargin(
  61. ShadowValues(kTestCases[i].shadows,
  62. kTestCases[i].shadows + kTestCases[i].shadow_count));
  63. EXPECT_EQ(kTestCases[i].expected_margin, margin) << " i=" << i;
  64. }
  65. }
  66. } // namespace gfx