|
| 1 | +/// <summary> |
| 2 | +/// Whether two panes are the same pane, which is what decides whether the window repaints. |
| 3 | +/// ScreenBuilder allocates a fresh Screen every frame, so record equality would report a change |
| 4 | +/// sixty times a second and the comparison is by hand. |
| 5 | +/// </summary> |
| 6 | +public class PaneChangeTests |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// The rows an image side shows are format, dimensions and byte count, and a re-run that |
| 10 | + /// rewrites a received image at the same size changes none of them - for BMP, which is |
| 11 | + /// uncompressed, that is every re-run. So nothing about the screen differed, Apply returned |
| 12 | + /// before repainting, and the pane kept the previous picture while the rows beside it |
| 13 | + /// described the new one. |
| 14 | + /// </summary> |
| 15 | + [Test] |
| 16 | + public async Task A_picture_that_changed_is_not_the_same_pane() |
| 17 | + { |
| 18 | + var before = ImagePane("A1B2"); |
| 19 | + var after = ImagePane("C3D4"); |
| 20 | + |
| 21 | + await Assert.That(ViewerForm.Same(before, after)).IsFalse(); |
| 22 | + } |
| 23 | + |
| 24 | + [Test] |
| 25 | + public async Task A_picture_that_did_not_change_is_the_same_pane() => |
| 26 | + await Assert.That(ViewerForm.Same(ImagePane("A1B2"), ImagePane("A1B2"))).IsTrue(); |
| 27 | + |
| 28 | + [Test] |
| 29 | + public async Task A_picture_replaced_by_one_of_another_size_is_not_the_same_pane() |
| 30 | + { |
| 31 | + var before = ImagePane("A1B2"); |
| 32 | + var after = before with |
| 33 | + { |
| 34 | + Image = new("sample.received.png", 20, 10, "A1B2") |
| 35 | + }; |
| 36 | + |
| 37 | + await Assert.That(ViewerForm.Same(before, after)).IsFalse(); |
| 38 | + } |
| 39 | + |
| 40 | + [Test] |
| 41 | + public async Task Text_panes_are_unaffected() |
| 42 | + { |
| 43 | + var pane = new Pane("received", [new(1, RowKind.Unchanged, "one")], 0, 1); |
| 44 | + |
| 45 | + await Assert.That(ViewerForm.Same(pane, pane with { })).IsTrue(); |
| 46 | + await Assert.That(ViewerForm.Same(pane, pane with { ScrollTop = 1 })).IsFalse(); |
| 47 | + } |
| 48 | + |
| 49 | + static Pane ImagePane(string hash) => |
| 50 | + new( |
| 51 | + "received", |
| 52 | + [], |
| 53 | + 0, |
| 54 | + 0, |
| 55 | + new("sample.received.png", 10, 10, hash)); |
| 56 | +} |
0 commit comments