DocumentTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using PixiEditor.Models.Controllers;
  2. using PixiEditor.Models.DataHolders;
  3. using PixiEditor.Models.Enums;
  4. using PixiEditor.Models.Layers;
  5. using PixiEditor.Models.Position;
  6. using PixiEditor.ViewModels;
  7. using PixiEditorTests.HelpersTests;
  8. using SkiaSharp;
  9. using System;
  10. using Xunit;
  11. namespace PixiEditorTests.ModelsTests.DataHoldersTests
  12. {
  13. [Collection("Application collection")]
  14. public class DocumentTests
  15. {
  16. //[Theory]
  17. //[InlineData(10, 10, 20, 20)]
  18. //[InlineData(1, 2, 5, 8)]
  19. //[InlineData(20, 20, 10, 10)] // TODO Anchor
  20. //public void TestResizeCanvasResizesProperly(int oldWidth, int oldHeight, int newWidth, int newHeight)
  21. //{
  22. // Document document = new Document(oldWidth, oldHeight);
  23. // document.ResizeCanvas(newWidth, newHeight, AnchorPoint.Top | AnchorPoint.Left);
  24. // Assert.Equal(newHeight, document.Height);
  25. // Assert.Equal(newWidth, document.Width);
  26. //}
  27. //[Theory]
  28. //[InlineData(10, 10, 20, 20)]
  29. //[InlineData(5, 8, 10, 16)]
  30. //public void TestResizeWorks(int oldWidth, int oldHeight, int newWidth, int newHeight)
  31. //{
  32. // Document document = new Document(oldWidth, oldHeight);
  33. // document.Resize(newWidth, newHeight);
  34. // Assert.Equal(newHeight, document.Height);
  35. // Assert.Equal(newWidth, document.Width);
  36. //}
  37. //[Theory]
  38. //[InlineData(10, 10, 0, 0)]
  39. //[InlineData(50, 50, 10, 49)]
  40. //public void TestThatClipCanvasWorksForSingleLayer(int initialWidth, int initialHeight, int additionalPixelX, int additionalPixelY)
  41. //{
  42. // Document document = new Document(initialWidth, initialHeight);
  43. // BitmapManager manager = new BitmapManager
  44. // {
  45. // ActiveDocument = document
  46. // };
  47. // manager.ActiveDocument.AddNewLayer("test");
  48. // manager.ActiveLayer.SetPixel(
  49. // new Coordinates(
  50. // (int)Math.Ceiling(initialWidth / 2f),
  51. // (int)Math.Ceiling(initialHeight / 2f)), SKColors.Black);
  52. // manager.ActiveLayer.SetPixel(new Coordinates(additionalPixelX, additionalPixelY), SKColors.Black);
  53. // document.ClipCanvas();
  54. // Assert.Equal(manager.ActiveLayer.Width, document.Width);
  55. // Assert.Equal(manager.ActiveLayer.Height, document.Height);
  56. //}
  57. //[Theory]
  58. //[InlineData(10, 10, 0, 0)]
  59. //[InlineData(50, 50, 15, 23)]
  60. //[InlineData(3, 3, 1, 1)]
  61. //[InlineData(1, 1, 0, 0)]
  62. //public void TestThatClipCanvasWorksForMultipleLayers(int initialWidth, int initialHeight, int secondLayerPixelX, int secondLayerPixelY)
  63. //{
  64. // Document document = new Document(initialWidth, initialHeight);
  65. // BitmapManager manager = new BitmapManager
  66. // {
  67. // ActiveDocument = document
  68. // };
  69. // manager.ActiveDocument.AddNewLayer("test");
  70. // manager.ActiveLayer.SetPixel(
  71. // new Coordinates(
  72. // (int)Math.Ceiling(initialWidth / 2f),
  73. // (int)Math.Ceiling(initialHeight / 2f)), SKColors.Black); // Set pixel in center
  74. // manager.ActiveDocument.AddNewLayer("test2");
  75. // manager.ActiveLayer.SetPixel(new Coordinates(secondLayerPixelX, secondLayerPixelY), SKColors.Black);
  76. // document.ClipCanvas();
  77. // int totalWidth = Math.Abs(manager.ActiveDocument.Layers[1].OffsetX +
  78. // manager.ActiveDocument.Layers[1].Width - (manager.ActiveDocument.Layers[0].OffsetX +
  79. // manager.ActiveDocument.Layers[0].Width)) + 1;
  80. // int totalHeight = Math.Abs(manager.ActiveDocument.Layers[1].OffsetY +
  81. // manager.ActiveDocument.Layers[1].Height - (manager.ActiveDocument.Layers[0].OffsetY +
  82. // manager.ActiveDocument.Layers[0].Height)) + 1;
  83. // Assert.Equal(totalWidth, document.Width);
  84. // Assert.Equal(totalHeight, document.Height);
  85. //}
  86. //[Theory]
  87. //[InlineData(10, 10)]
  88. //[InlineData(11, 11)]
  89. //[InlineData(25, 17)]
  90. //public void TestThatCenterContentCentersContentForSingleLayer(int docWidth, int docHeight)
  91. //{
  92. // Document doc = new Document(docWidth, docHeight);
  93. // BitmapManager manager = new BitmapManager
  94. // {
  95. // ActiveDocument = doc
  96. // };
  97. // manager.ActiveDocument.AddNewLayer("test");
  98. // manager.ActiveLayer.SetPixel(new Coordinates(0, 0), SKColors.Lime);
  99. // doc.CenterContent();
  100. // Assert.Equal(Math.Floor(docWidth / 2f), manager.ActiveLayer.OffsetX);
  101. // Assert.Equal(Math.Floor(docHeight / 2f), manager.ActiveLayer.OffsetY);
  102. //}
  103. //[Theory]
  104. //[InlineData(10, 10)]
  105. //[InlineData(11, 11)]
  106. //[InlineData(25, 17)]
  107. //public void TestThatCenterContentCentersContentForMultipleLayers(int docWidth, int docHeight)
  108. //{
  109. // Document doc = new Document(docWidth, docHeight);
  110. // BitmapManager manager = new BitmapManager
  111. // {
  112. // ActiveDocument = doc
  113. // };
  114. // manager.ActiveDocument.AddNewLayer("test");
  115. // manager.ActiveLayer.SetPixel(new Coordinates(0, 0), SKColors.Lime);
  116. // manager.ActiveDocument.AddNewLayer("test2");
  117. // manager.ActiveLayer.SetPixel(new Coordinates(1, 1), SKColors.Lime);
  118. // foreach (var layer in manager.ActiveDocument.Layers)
  119. // {
  120. // layer.IsActive = true;
  121. // }
  122. // doc.CenterContent();
  123. // int midWidth = (int)Math.Floor(docWidth / 2f);
  124. // int midHeight = (int)Math.Floor(docHeight / 2f);
  125. // Assert.Equal(midWidth - 1, manager.ActiveDocument.Layers[0].OffsetX);
  126. // Assert.Equal(midHeight - 1, manager.ActiveDocument.Layers[0].OffsetY);
  127. // Assert.Equal(midWidth, manager.ActiveDocument.Layers[1].OffsetX);
  128. // Assert.Equal(midHeight, manager.ActiveDocument.Layers[1].OffsetY);
  129. //}
  130. //[Fact]
  131. //public void TestThatSetNextActiveLayerSetsLayerBelow()
  132. //{
  133. // Document doc = new Document(10, 10);
  134. // doc.Layers.Add(new PixiEditor.Models.Layers.Layer("Test"));
  135. // doc.Layers.Add(new PixiEditor.Models.Layers.Layer("Test 2"));
  136. // doc.SetMainActiveLayer(1);
  137. // doc.SetNextLayerAsActive(1);
  138. // Assert.False(doc.Layers[1].IsActive);
  139. // Assert.True(doc.Layers[0].IsActive);
  140. //}
  141. //[Fact]
  142. //public void TestThatAddNewLayerAddsUndoChange()
  143. //{
  144. // Document document = new Document(10, 10);
  145. // document.AddNewLayer("Test");
  146. // document.AddNewLayer("Test2");
  147. // Assert.Single(document.UndoManager.UndoStack);
  148. //}
  149. //[Fact]
  150. //public void TestThatAddNewLayerUndoProcessWorks()
  151. //{
  152. // Document document = new Document(10, 10);
  153. // document.AddNewLayer("Test");
  154. // document.AddNewLayer("Test2");
  155. // document.UndoManager.Undo();
  156. // Assert.Single(document.Layers);
  157. //}
  158. //[Fact]
  159. //public void TestThatAddNewLayerRedoProcessWorks()
  160. //{
  161. // Document document = new Document(10, 10);
  162. // document.AddNewLayer("Test");
  163. // document.AddNewLayer("Test2");
  164. // document.UndoManager.Undo();
  165. // document.UndoManager.Redo();
  166. // Assert.Equal(2, document.Layers.Count);
  167. //}
  168. //[Fact]
  169. //public void TestThatRemoveLayerUndoProcessWorks()
  170. //{
  171. // Document document = new Document(10, 10);
  172. // document.AddNewLayer("Test");
  173. // document.AddNewLayer("Test2");
  174. // document.RemoveLayer(1);
  175. // document.UndoManager.Undo();
  176. // Assert.Equal(2, document.Layers.Count);
  177. //}
  178. //[Fact]
  179. //public void TestThatRemoveLayerRedoProcessWorks()
  180. //{
  181. // Document document = new Document(10, 10);
  182. // document.AddNewLayer("Test");
  183. // document.AddNewLayer("Test2");
  184. // document.RemoveLayer(1);
  185. // document.UndoManager.Undo();
  186. // document.UndoManager.Redo();
  187. // Assert.Single(document.Layers);
  188. //}
  189. //[Theory]
  190. //[InlineData(2, 0, 1)]
  191. //[InlineData(2, 1, -1)]
  192. //[InlineData(3, 1, 1)]
  193. //[InlineData(3, 2, -2)]
  194. //[InlineData(10, 9, -5)]
  195. //public void TestThatMoveLayerInStructureWorks(int layersAmount, int index, int amount)
  196. //{
  197. // Document document = new Document(10, 10);
  198. // for (int i = 0; i < layersAmount; i++)
  199. // {
  200. // document.AddNewLayer("Layer " + i);
  201. // }
  202. // Guid oldGuid = document.Layers[index].LayerGuid;
  203. // Guid referenceGuid = document.Layers[index + amount].LayerGuid;
  204. // document.MoveLayerInStructure(oldGuid, referenceGuid, amount > 0);
  205. // Assert.Equal(oldGuid, document.Layers[index + amount].LayerGuid);
  206. //}
  207. //[Fact]
  208. //public void TestThatMoveLayerInStructureUndoProcessWorks()
  209. //{
  210. // Document document = new Document(10, 10);
  211. // document.AddNewLayer("Test");
  212. // document.AddNewLayer("Test2");
  213. // Guid oldGuid = document.Layers[0].LayerGuid;
  214. // Guid referenceGuid = document.Layers[1].LayerGuid;
  215. // document.MoveLayerInStructure(oldGuid, referenceGuid);
  216. // document.UndoManager.Undo();
  217. // Assert.Equal("Test2", document.Layers[1].Name);
  218. // Assert.Equal("Test", document.Layers[0].Name);
  219. //}
  220. //[Fact]
  221. //public void TestThatMoveLayerInStructureRedoProcessWorks()
  222. //{
  223. // Document document = new Document(10, 10);
  224. // document.AddNewLayer("Test");
  225. // document.AddNewLayer("Test2");
  226. // Guid oldGuid = document.Layers[0].LayerGuid;
  227. // Guid referenceGuid = document.Layers[1].LayerGuid;
  228. // document.MoveLayerInStructure(oldGuid, referenceGuid, true);
  229. // document.UndoManager.Undo();
  230. // document.UndoManager.Redo();
  231. // Assert.Equal("Test", document.Layers[1].Name);
  232. // Assert.Equal("Test2", document.Layers[0].Name);
  233. //}
  234. //[StaFact]
  235. //public void TestThatDocumentGetsAddedToRecentlyOpenedList()
  236. //{
  237. // ViewModelMain viewModel = ViewModelHelper.MockedViewModelMain();
  238. // Document document = new Document(1, 1)
  239. // {
  240. // XamlAccesibleViewModel = viewModel
  241. // };
  242. // string testFilePath = @"C:\idk\somewhere\homework";
  243. // document.DocumentFilePath = testFilePath;
  244. // Assert.Contains(viewModel.FileSubViewModel.RecentlyOpened, x => x.FilePath == testFilePath);
  245. //}
  246. //[Fact]
  247. //public void TestThatDupliacteLayerWorks()
  248. //{
  249. // const string layerName = "New Layer";
  250. // Document document = new(10, 10);
  251. // document.AddNewLayer(layerName);
  252. // Layer duplicate = document.DuplicateLayer(0);
  253. // Assert.Equal(document.Layers[1], duplicate);
  254. // Assert.Equal(layerName + " (1)", duplicate.Name);
  255. // Assert.True(duplicate.IsActive);
  256. //}
  257. //[Fact]
  258. //public void TestThatCorrectLayerSuffixIsSet()
  259. //{
  260. // const string layerName = "New Layer";
  261. // Document document = new(10, 10);
  262. // document.AddNewLayer(layerName);
  263. // document.AddNewLayer(layerName);
  264. // document.AddNewLayer(layerName);
  265. // Assert.Equal(layerName, document.Layers[0].Name);
  266. // Assert.Equal(layerName + " (1)", document.Layers[1].Name);
  267. // Assert.Equal(layerName + " (2)", document.Layers[2].Name);
  268. // document.Layers.Add(new Layer(layerName + " (15)"));
  269. // document.AddNewLayer(layerName);
  270. // Assert.Equal(layerName + " (16)", document.Layers[4].Name);
  271. //}
  272. }
  273. }