|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Numerics; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace SixLabors.ImageSharp.Drawing.Tests |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// see https://github.com/SixLabors/ImageSharp.Drawing/issues/224 |
| 15 | + /// </summary> |
| 16 | + public class Issue_224 |
| 17 | + { |
| 18 | + [Fact] |
| 19 | + public async Task OutliningWithZeroWidth_MultiplePatterns() |
| 20 | + { |
| 21 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 22 | + |
| 23 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 24 | + { |
| 25 | + _ = shape.GenerateOutline(0, new float[] { 1, 2 }); |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public async Task OutliningWithZeroWidth_SinglePAttern() |
| 31 | + { |
| 32 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 33 | + |
| 34 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 35 | + { |
| 36 | + _ = shape.GenerateOutline(0, new float[] { 1 }); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public async Task OutliningWithZeroWidth_NoPattern() |
| 42 | + { |
| 43 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 44 | + |
| 45 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 46 | + { |
| 47 | + _ = shape.GenerateOutline(0); |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + public async Task OutliningWithLessThanZeroWidth_MultiplePatterns() |
| 53 | + { |
| 54 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 55 | + |
| 56 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 57 | + { |
| 58 | + _ = shape.GenerateOutline(-10, new float[] { 1, 2 }); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public async Task OutliningWithLessThanZeroWidth_SinglePAttern() |
| 64 | + { |
| 65 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 66 | + |
| 67 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 68 | + { |
| 69 | + _ = shape.GenerateOutline(-10, new float[] { 1 }); |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + [Fact] |
| 74 | + public async Task OutliningWithLessThanZeroWidth_NoPattern() |
| 75 | + { |
| 76 | + var shape = new RectangularPolygon(10, 10, 10, 10); |
| 77 | + |
| 78 | + await this.CompletesIn(TimeSpan.FromSeconds(1), () => |
| 79 | + { |
| 80 | + _ = shape.GenerateOutline(-10); |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + private async Task CompletesIn(TimeSpan span, Action action) |
| 85 | + { |
| 86 | + var task = Task.Run(action); |
| 87 | + var timeout = Task.Delay(span); |
| 88 | + |
| 89 | + var completed = await Task.WhenAny(task, timeout); |
| 90 | + |
| 91 | + Assert.True(task == completed, $"Failed to compelete in {span}"); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments