BorderTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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.Threading.Tasks;
  4. using Avalonia.Controls;
  5. using Avalonia.Layout;
  6. using Avalonia.Media;
  7. using Xunit;
  8. #if AVALONIA_CAIRO
  9. namespace Avalonia.Cairo.RenderTests.Controls
  10. #elif AVALONIA_SKIA
  11. namespace Avalonia.Skia.RenderTests
  12. #else
  13. namespace Avalonia.Direct2D1.RenderTests.Controls
  14. #endif
  15. {
  16. public class BorderTests : TestBase
  17. {
  18. public BorderTests()
  19. : base(@"Controls\Border")
  20. {
  21. }
  22. [Fact]
  23. public async Task Border_1px_Border()
  24. {
  25. Decorator target = new Decorator
  26. {
  27. Padding = new Thickness(8),
  28. Width = 200,
  29. Height = 200,
  30. Child = new Border
  31. {
  32. BorderBrush = Brushes.Black,
  33. BorderThickness = 1,
  34. }
  35. };
  36. await RenderToFile(target);
  37. CompareImages();
  38. }
  39. [Fact]
  40. public async Task Border_2px_Border()
  41. {
  42. Decorator target = new Decorator
  43. {
  44. Padding = new Thickness(8),
  45. Width = 200,
  46. Height = 200,
  47. Child = new Border
  48. {
  49. BorderBrush = Brushes.Black,
  50. BorderThickness = 2,
  51. }
  52. };
  53. await RenderToFile(target);
  54. CompareImages();
  55. }
  56. [Fact]
  57. public async Task Border_Fill()
  58. {
  59. Decorator target = new Decorator
  60. {
  61. Padding = new Thickness(8),
  62. Width = 200,
  63. Height = 200,
  64. Child = new Border
  65. {
  66. Background = Brushes.Red,
  67. }
  68. };
  69. await RenderToFile(target);
  70. CompareImages();
  71. }
  72. [Fact]
  73. public async Task Border_Brush_Offsets_Content()
  74. {
  75. Decorator target = new Decorator
  76. {
  77. Padding = new Thickness(8),
  78. Width = 200,
  79. Height = 200,
  80. Child = new Border
  81. {
  82. BorderBrush = Brushes.Black,
  83. BorderThickness = 2,
  84. Child = new Border
  85. {
  86. Background = Brushes.Red,
  87. }
  88. }
  89. };
  90. await RenderToFile(target);
  91. CompareImages();
  92. }
  93. [Fact]
  94. public async Task Border_Padding_Offsets_Content()
  95. {
  96. Decorator target = new Decorator
  97. {
  98. Padding = new Thickness(8),
  99. Width = 200,
  100. Height = 200,
  101. Child = new Border
  102. {
  103. BorderBrush = Brushes.Black,
  104. BorderThickness = 2,
  105. Padding = new Thickness(2),
  106. Child = new Border
  107. {
  108. Background = Brushes.Red,
  109. }
  110. }
  111. };
  112. await RenderToFile(target);
  113. CompareImages();
  114. }
  115. [Fact]
  116. public async Task Border_Margin_Offsets_Content()
  117. {
  118. Decorator target = new Decorator
  119. {
  120. Padding = new Thickness(8),
  121. Width = 200,
  122. Height = 200,
  123. Child = new Border
  124. {
  125. BorderBrush = Brushes.Black,
  126. BorderThickness = 2,
  127. Child = new Border
  128. {
  129. Background = Brushes.Red,
  130. Margin = new Thickness(2),
  131. }
  132. }
  133. };
  134. await RenderToFile(target);
  135. CompareImages();
  136. }
  137. #if AVALONIA_CAIRO
  138. [Fact(Skip = "Font scaling currently broken on cairo")]
  139. #else
  140. [Fact]
  141. #endif
  142. public async Task Border_Centers_Content_Horizontally()
  143. {
  144. Decorator target = new Decorator
  145. {
  146. Padding = new Thickness(8),
  147. Width = 200,
  148. Height = 200,
  149. Child = new Border
  150. {
  151. BorderBrush = Brushes.Black,
  152. BorderThickness = 2,
  153. Child = new TextBlock
  154. {
  155. Text = "Foo",
  156. Background = Brushes.Red,
  157. FontFamily = "Segoe UI",
  158. FontSize = 12,
  159. HorizontalAlignment = HorizontalAlignment.Center,
  160. }
  161. }
  162. };
  163. await RenderToFile(target);
  164. CompareImages();
  165. }
  166. #if AVALONIA_CAIRO
  167. [Fact(Skip = "Font scaling currently broken on cairo")]
  168. #elif AVALONIA_SKIA_SKIP_FAIL
  169. [Fact(Skip = "Waiting for new FormattedText")]
  170. #else
  171. [Fact]
  172. #endif
  173. public async Task Border_Centers_Content_Vertically()
  174. {
  175. Decorator target = new Decorator
  176. {
  177. Padding = new Thickness(8),
  178. Width = 200,
  179. Height = 200,
  180. Child = new Border
  181. {
  182. BorderBrush = Brushes.Black,
  183. BorderThickness = 2,
  184. Child = new TextBlock
  185. {
  186. Text = "Foo",
  187. Background = Brushes.Red,
  188. FontFamily = "Segoe UI",
  189. FontSize = 12,
  190. VerticalAlignment = VerticalAlignment.Center,
  191. }
  192. }
  193. };
  194. await RenderToFile(target);
  195. CompareImages();
  196. }
  197. #if AVALONIA_CAIRO
  198. [Fact(Skip = "Font scaling currently broken on cairo")]
  199. #else
  200. [Fact]
  201. #endif
  202. public async Task Border_Stretches_Content_Horizontally()
  203. {
  204. Decorator target = new Decorator
  205. {
  206. Padding = new Thickness(8),
  207. Width = 200,
  208. Height = 200,
  209. Child = new Border
  210. {
  211. BorderBrush = Brushes.Black,
  212. BorderThickness = 2,
  213. Child = new TextBlock
  214. {
  215. Text = "Foo",
  216. Background = Brushes.Red,
  217. FontFamily = "Segoe UI",
  218. FontSize = 12,
  219. HorizontalAlignment = HorizontalAlignment.Stretch,
  220. }
  221. }
  222. };
  223. await RenderToFile(target);
  224. CompareImages();
  225. }
  226. #if AVALONIA_CAIRO
  227. [Fact(Skip = "Font scaling currently broken on cairo")]
  228. #else
  229. [Fact]
  230. #endif
  231. public async Task Border_Stretches_Content_Vertically()
  232. {
  233. Decorator target = new Decorator
  234. {
  235. Padding = new Thickness(8),
  236. Width = 200,
  237. Height = 200,
  238. Child = new Border
  239. {
  240. BorderBrush = Brushes.Black,
  241. BorderThickness = 2,
  242. Child = new TextBlock
  243. {
  244. Text = "Foo",
  245. Background = Brushes.Red,
  246. FontFamily = "Segoe UI",
  247. FontSize = 12,
  248. VerticalAlignment = VerticalAlignment.Stretch,
  249. }
  250. }
  251. };
  252. await RenderToFile(target);
  253. CompareImages();
  254. }
  255. #if AVALONIA_CAIRO
  256. [Fact(Skip = "Font scaling currently broken on cairo")]
  257. #else
  258. [Fact]
  259. #endif
  260. public async Task Border_Left_Aligns_Content()
  261. {
  262. Decorator target = new Decorator
  263. {
  264. Padding = new Thickness(8),
  265. Width = 200,
  266. Height = 200,
  267. Child = new Border
  268. {
  269. BorderBrush = Brushes.Black,
  270. BorderThickness = 2,
  271. Child = new TextBlock
  272. {
  273. Text = "Foo",
  274. Background = Brushes.Red,
  275. FontFamily = "Segoe UI",
  276. FontSize = 12,
  277. HorizontalAlignment = HorizontalAlignment.Left,
  278. }
  279. }
  280. };
  281. await RenderToFile(target);
  282. CompareImages();
  283. }
  284. #if AVALONIA_CAIRO
  285. [Fact(Skip = "Font scaling currently broken on cairo")]
  286. #else
  287. [Fact]
  288. #endif
  289. public async Task Border_Right_Aligns_Content()
  290. {
  291. Decorator target = new Decorator
  292. {
  293. Padding = new Thickness(8),
  294. Width = 200,
  295. Height = 200,
  296. Child = new Border
  297. {
  298. BorderBrush = Brushes.Black,
  299. BorderThickness = 2,
  300. Child = new TextBlock
  301. {
  302. Text = "Foo",
  303. Background = Brushes.Red,
  304. FontFamily = "Segoe UI",
  305. FontSize = 12,
  306. HorizontalAlignment = HorizontalAlignment.Right,
  307. }
  308. }
  309. };
  310. await RenderToFile(target);
  311. CompareImages();
  312. }
  313. #if AVALONIA_CAIRO
  314. [Fact(Skip = "Font scaling currently broken on cairo")]
  315. #elif AVALONIA_SKIA_SKIP_FAIL
  316. [Fact(Skip = "Waiting for new FormattedText")]
  317. #else
  318. [Fact]
  319. #endif
  320. public async Task Border_Top_Aligns_Content()
  321. {
  322. Decorator target = new Decorator
  323. {
  324. Padding = new Thickness(8),
  325. Width = 200,
  326. Height = 200,
  327. Child = new Border
  328. {
  329. BorderBrush = Brushes.Black,
  330. BorderThickness = 2,
  331. Child = new TextBlock
  332. {
  333. Text = "Foo",
  334. Background = Brushes.Red,
  335. FontFamily = "Segoe UI",
  336. FontSize = 12,
  337. VerticalAlignment = VerticalAlignment.Top,
  338. }
  339. }
  340. };
  341. await RenderToFile(target);
  342. CompareImages();
  343. }
  344. #if AVALONIA_CAIRO
  345. [Fact(Skip = "Font scaling currently broken on cairo")]
  346. #elif AVALONIA_SKIA_SKIP_FAIL
  347. [Fact(Skip = "Waiting for new FormattedText")]
  348. #else
  349. [Fact]
  350. #endif
  351. public async Task Border_Bottom_Aligns_Content()
  352. {
  353. Decorator target = new Decorator
  354. {
  355. Padding = new Thickness(8),
  356. Width = 200,
  357. Height = 200,
  358. Child = new Border
  359. {
  360. BorderBrush = Brushes.Black,
  361. BorderThickness = 2,
  362. Child = new TextBlock
  363. {
  364. Text = "Foo",
  365. Background = Brushes.Red,
  366. FontFamily = "Segoe UI",
  367. FontSize = 12,
  368. VerticalAlignment = VerticalAlignment.Bottom,
  369. }
  370. }
  371. };
  372. await RenderToFile(target);
  373. CompareImages();
  374. }
  375. [Fact]
  376. public async Task Border_Nested_Rotate()
  377. {
  378. Decorator target = new Decorator
  379. {
  380. Padding = new Thickness(8),
  381. Width = 200,
  382. Height = 200,
  383. Child = new Border
  384. {
  385. Background = Brushes.Coral,
  386. Width = 100,
  387. Height = 100,
  388. HorizontalAlignment = HorizontalAlignment.Center,
  389. VerticalAlignment = VerticalAlignment.Center,
  390. Child = new Border
  391. {
  392. Margin = new Thickness(25),
  393. Background = Brushes.Chocolate,
  394. },
  395. RenderTransform = new RotateTransform(45),
  396. }
  397. };
  398. await RenderToFile(target);
  399. CompareImages();
  400. }
  401. }
  402. }