BorderTests.cs 12 KB

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