ImageTests.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using Avalonia.Controls;
  6. using Avalonia.Media;
  7. using Avalonia.Media.Imaging;
  8. using Xunit;
  9. #if AVALONIA_CAIRO
  10. namespace Avalonia.Cairo.RenderTests.Controls
  11. #elif AVALONIA_SKIA
  12. namespace Avalonia.Skia.RenderTests
  13. #else
  14. namespace Avalonia.Direct2D1.RenderTests.Controls
  15. #endif
  16. {
  17. public class ImageTests : TestBase
  18. {
  19. private readonly Bitmap _bitmap;
  20. public ImageTests()
  21. : base(@"Controls\Image")
  22. {
  23. _bitmap = new Bitmap(Path.Combine(OutputPath, "test.png"));
  24. }
  25. [Fact]
  26. public async Task Image_Stretch_None()
  27. {
  28. Decorator target = new Decorator
  29. {
  30. Padding = new Thickness(20, 8),
  31. Width = 200,
  32. Height = 200,
  33. Child = new Border
  34. {
  35. Background = Brushes.Red,
  36. Child = new Image
  37. {
  38. Source = _bitmap,
  39. Stretch = Stretch.None,
  40. }
  41. }
  42. };
  43. await RenderToFile(target);
  44. CompareImages();
  45. }
  46. [Fact]
  47. public async Task Image_Stretch_Fill()
  48. {
  49. Decorator target = new Decorator
  50. {
  51. Padding = new Thickness(20, 8),
  52. Width = 200,
  53. Height = 200,
  54. Child = new Border
  55. {
  56. Background = Brushes.Red,
  57. Child = new Image
  58. {
  59. Source = _bitmap,
  60. Stretch = Stretch.Fill,
  61. }
  62. }
  63. };
  64. await RenderToFile(target);
  65. CompareImages();
  66. }
  67. [Fact]
  68. public async Task Image_Stretch_Uniform()
  69. {
  70. Decorator target = new Decorator
  71. {
  72. Padding = new Thickness(20, 8),
  73. Width = 200,
  74. Height = 200,
  75. Child = new Border
  76. {
  77. Background = Brushes.Red,
  78. Child = new Image
  79. {
  80. Source = _bitmap,
  81. Stretch = Stretch.Uniform,
  82. }
  83. }
  84. };
  85. await RenderToFile(target);
  86. CompareImages();
  87. }
  88. [Fact]
  89. public async Task Image_Stretch_UniformToFill()
  90. {
  91. Decorator target = new Decorator
  92. {
  93. Padding = new Thickness(20, 8),
  94. Width = 200,
  95. Height = 200,
  96. Child = new Border
  97. {
  98. Background = Brushes.Red,
  99. Child = new Image
  100. {
  101. Source = _bitmap,
  102. Stretch = Stretch.UniformToFill,
  103. }
  104. }
  105. };
  106. await RenderToFile(target);
  107. CompareImages();
  108. }
  109. }
  110. }