using System; using Annulus; using Azimuth; using Blacklight.Core; using Glass; using Glass.Blacklight; using Konis.Blacklight; using Prism.Glass; using UnitTestSharp; namespace Konis.Testbed.UnitTests { public class TuningPanelTests : TestFixture { public static SpritePreviews PreviewsOn(WindowHandle window) { return new SpritePreviews(window, new BlacklightRenderer(), new SpriteResolver(window)); } public static TuningPanel BuiltPanel(Func copy) { new BlacklightRenderer().RegisterAllFonts(new NullWindowHandle()); var window = new NullWindowHandle(); TestbedSkin skin = TestbedSkinTests.NewSkin(); return new TuningPanel( skin, respawnTooltip: null, respawn: () => { }, copy, window, new GradientWindow(skin, window), new FunctionWindow(skin, window), new SlabWindow(skin), PreviewsOn(window)); } public static TuningPanel BuiltPanel() { return BuiltPanel(text => true); } /// /// A panel with the window it opens, which the panel's own helper doesn't give back. /// public static TuningPanel BuiltPanel(out FunctionWindow functions) { new BlacklightRenderer().RegisterAllFonts(new NullWindowHandle()); var window = new NullWindowHandle(); TestbedSkin skin = TestbedSkinTests.NewSkin(); functions = new FunctionWindow(skin, window); return new TuningPanel( skin, respawnTooltip: null, respawn: () => { }, copy: text => true, window, new GradientWindow(skin, window), functions, new SlabWindow(skin), PreviewsOn(window)); } /// /// A panel with the gradient window it opens, which the panel's own helper doesn't give back. /// public static TuningPanel BuiltPanel(out GradientWindow gradients) { new BlacklightRenderer().RegisterAllFonts(new NullWindowHandle()); var window = new NullWindowHandle(); TestbedSkin skin = TestbedSkinTests.NewSkin(); gradients = new GradientWindow(skin, window); return new TuningPanel( skin, respawnTooltip: null, respawn: () => { }, copy: text => true, window, gradients, new FunctionWindow(skin, window), new SlabWindow(skin), PreviewsOn(window)); } /// /// A panel with the slab window it opens, which the panel's own helper doesn't give back. /// public static TuningPanel BuiltPanel(out SlabWindow slabs) { new BlacklightRenderer().RegisterAllFonts(new NullWindowHandle()); var window = new NullWindowHandle(); TestbedSkin skin = TestbedSkinTests.NewSkin(); slabs = new SlabWindow(skin); return new TuningPanel( skin, respawnTooltip: null, respawn: () => { }, copy: text => true, window, new GradientWindow(skin, window), new FunctionWindow(skin, window), slabs, PreviewsOn(window)); } public static Control Find(Control parent, string debugName) { foreach (Control child in parent.CanvasChildren.BackToFront()) { Control found = child.DebugName == debugName ? child : Find(child, debugName); if (found != null) { return found; } } return null; } public class CopyMessageTests : TestFixture { public void NoText_SaysNothingChanged() { CheckEqual("Nothing has changed", TuningPanel.CopyMessage("", copied: false)); } public void TextTheClipboardRefused_SaysItIsBusy() { CheckEqual("The clipboard is busy", TuningPanel.CopyMessage("Size = 2,\r\n", copied: false)); } public void OneLine_SaysOneLine() { string text = " Size = 2," + Environment.NewLine; CheckEqual("Copied 1 line", TuningPanel.CopyMessage(text, copied: true)); } public void SeveralLines_SaysHowMany() { string text = "A = 1," + Environment.NewLine + "B = 2," + Environment.NewLine + "C = 3," + Environment.NewLine; CheckEqual("Copied 3 lines", TuningPanel.CopyMessage(text, copied: true)); } } public class CtorTests : TestFixture { public TuningPanel Panel; public override void FixtureSetup() { Panel = BuiltPanel(); } public void ClipSoftness_HasOneField() { CheckNotNull(Find(Panel.Frame, "clip softness field")); CheckNull(Find(Panel.Frame, "clip softness maximum field")); } public void TintOverLife_HasASwatchRow() { CheckNotNull(Find(Panel.Frame, "tint over life preview")); } public void TintOverLife_HasAnEditButton() { CheckNotNull(Find(Panel.Frame, "Edit button")); } public void SizeAndAlphaOverLife_EachHaveAPlotRow() { CheckNotNull(Find(Panel.Frame, "size over life plot")); CheckNotNull(Find(Panel.Frame, "alpha over life plot")); } public void Sprite_HasADropdownRow() { CheckNotNull(Find(Panel.Frame, "sprite dropdown") as Dropdown); } public void ClipSlabs_HasASummaryRow() { CheckNotNull(Find(Panel.Frame, "clip slabs summary") as Label); } public void EveryButton_IsAsWideAsItsTextNeeds() { TestbedSkin skin = TestbedSkinTests.BuiltSkin(); string[,] buttons = { { "Respawn selected button", "Respawn selected" }, { "Copy changes button", "Copy changes" }, { "Copy all button", "Copy all" }, { "Edit button", "Edit" }, { "size over life edit button", "Edit" }, { "clip slabs edit button", "Edit" }, }; for (int i = 0; i < buttons.GetLength(0); i++) { Control button = Find(Panel.Frame, buttons[i, 0]); CheckNotNull(button); CheckTrue(button.Bounds.Width >= skin.ButtonSizeFor(buttons[i, 1]).X); } } public void TheTwoCopyButtonsFitSideBySideInsideThePanel() { Control changes = Find(Panel.Frame, "Copy changes button"); Control all = Find(Panel.Frame, "Copy all button"); CheckTrue(changes.Bounds.Right <= all.Bounds.Left); } } public class SlabSummaryTests : TestFixture { public void NoSlabs_SaysNone() { CheckEqual("none", TuningPanel.SlabSummary(null)); CheckEqual("none", TuningPanel.SlabSummary(new Slab[0])); } public void OneSlab_SaysOneSlab() { CheckEqual("1 slab", TuningPanel.SlabSummary(new[] { Slab.Above(Axis.Z, 0) })); } public void SeveralSlabs_SaysHowMany() { Slab one = Slab.Above(Axis.Z, 0); CheckEqual("3 slabs", TuningPanel.SlabSummary(new[] { one, one, one })); } } public class SlabRowTests : TestFixture { private static StandardEmitterDef DefWith(Slab[] slabs) { return new StandardEmitterDef { Capacity = 10, ClipSlabs = slabs, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; } private static string SummaryOf(TuningPanel panel) { return ((Label)Find(panel.Frame, "clip slabs summary")).Text.ToString(); } public void ADefWithNoSlabs_ShowsNone() { TuningPanel panel = BuiltPanel(); panel.Bind(DefWith(null), "test"); CheckEqual("none", SummaryOf(panel)); } public void ADefWithSlabs_ShowsHowMany() { TuningPanel panel = BuiltPanel(); panel.Bind(DefWith(new[] { Slab.Above(Axis.Z, 0), Slab.Below(Axis.X, 4) }), "test"); CheckEqual("2 slabs", SummaryOf(panel)); } public void BindingTheNextDef_ShowsItsSlabs() { TuningPanel panel = BuiltPanel(); panel.Bind(DefWith(new[] { Slab.Above(Axis.Z, 0) }), "first"); panel.Bind(DefWith(null), "second"); CheckEqual("none", SummaryOf(panel)); } public void TheRowHasAnEditButton() { CheckNotNull(Find(BuiltPanel().Frame, "clip slabs edit button") as Button); } public void Edit_OpensTheWindowOnTheDefsSlabsUnderTheEffectsName() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); panel.Bind(DefWith(new[] { Slab.Above(Axis.Z, 0), Slab.Below(Axis.X, 4) }), "test"); ((Button)Find(panel.Frame, "clip slabs edit button")).Activate(default, new KeyboardManager()); CheckTrue(slabs.IsOpen); CheckEqual(2, slabs.SlabCount); CheckEqual("clip slabs: test", slabs.Frame.Title); } public void Edit_BeforeAnyDefIsBound_DoesNothing() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); ((Button)Find(panel.Frame, "clip slabs edit button")).Activate(default, new KeyboardManager()); CheckFalse(slabs.IsOpen); } public void AnEditInTheWindow_GivesTheDefTheSlabsAndUpdatesTheSummary() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); StandardEmitterDef def = DefWith(new[] { Slab.Above(Axis.Z, 0) }); panel.Bind(def, "test"); ((Button)Find(panel.Frame, "clip slabs edit button")).Activate(default, new KeyboardManager()); SlabWindowTests.Press(slabs, "add slab button"); CheckEqual(2, def.ClipSlabs.Length); CheckEqual("2 slabs", SummaryOf(panel)); } public void AnEditThatLeavesNoSlabs_GivesTheDefNone() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); StandardEmitterDef def = DefWith(new[] { Slab.Above(Axis.Z, 0) }); panel.Bind(def, "test"); ((Button)Find(panel.Frame, "clip slabs edit button")).Activate(default, new KeyboardManager()); SlabWindowTests.Press(slabs, "slab 1 remove button"); CheckEqual(0, def.ClipSlabs.Length); CheckEqual("none", SummaryOf(panel)); } public void BindingTheNextDef_MovesAnOpenWindowToIt() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); panel.Bind(DefWith(new[] { Slab.Above(Axis.Z, 0) }), "first"); ((Button)Find(panel.Frame, "clip slabs edit button")).Activate(default, new KeyboardManager()); StandardEmitterDef next = DefWith(new[] { Slab.Above(Axis.Y, 1), Slab.Below(Axis.X, 4) }); panel.Bind(next, "second"); SlabWindowTests.Press(slabs, "slab 1 remove button"); CheckEqual(1, slabs.SlabCount); CheckEqual("clip slabs: second", slabs.Frame.Title); CheckEqual(1, next.ClipSlabs.Length); } public void BindingTheNextDef_LeavesAClosedWindowClosed() { TuningPanel panel = BuiltPanel(out SlabWindow slabs); panel.Bind(DefWith(null), "first"); panel.Bind(DefWith(null), "second"); CheckFalse(slabs.IsOpen); } public void CopyAll_WritesTheSlabs() { string copied = null; TuningPanel panel = BuiltPanel(text => { copied = text; return true; }); panel.Bind(DefWith(new[] { Slab.Above(Axis.Z, 0) }), "test"); panel.CopyAll(); CheckTrue(copied.Contains("ClipSlabs = new[] { Slab.Above(Axis.Z, 0) },")); } } public class SpriteRowTests : TestFixture { private static StandardEmitterDef DefWith(SpriteDef sprite) { return new StandardEmitterDef { Capacity = 10, Sprite = sprite, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; } private static int? IndexOf(SpriteDef sprite) { for (int i = 0; i < SpriteChoices.All.Count; i++) { if (ReferenceEquals(SpriteChoices.All[i].Def, sprite)) { return i; } } throw new InvalidOperationException("The sprite isn't one of the choices."); } private static Control ItemOf(Control row) { foreach (Control item in row.CanvasChildren.BackToFront()) { return item; } throw new InvalidOperationException("The row holds no item."); } public void TheListLaysItsSpritesOutInThreeColumns() { var dropdown = (Dropdown)Find(BuiltPanel().Frame, "sprite dropdown"); CheckEqual(3, dropdown.Columns); } public void TheListOffersEachSpriteAsAPictureCaptionedWithItsLabel() { var dropdown = (Dropdown)Find(BuiltPanel().Frame, "sprite dropdown"); CheckEqual(SpriteChoices.All.Count, dropdown.Popup.RowCount); for (int i = 0; i < SpriteChoices.All.Count; i++) { var cell = (SpriteCell)ItemOf(dropdown.Popup.RowAt(i)); CheckEqual(SpriteChoices.All[i].Label, cell.Caption.Text.ToString()); } } public void AnotherChoiceList_StaysInOneColumn() { var dropdown = (Dropdown)Find(BuiltPanel().Frame, "clock dropdown"); CheckEqual(1, dropdown.Columns); } public void ADefWithAStaticSprite_ShowsItPicked() { TuningPanel panel = BuiltPanel(); panel.Bind(DefWith(TestbedSprites.Ring), "test"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); CheckEqual(IndexOf(TestbedSprites.Ring), dropdown.SelectedIndex); } public void ADefWithAnEffectsOwnFlipbook_ShowsItPicked() { TuningPanel panel = BuiltPanel(); SpriteDef flipbook = Effects.Flicker.Def.Sprite; panel.Bind(DefWith(flipbook), "test"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); CheckEqual(IndexOf(flipbook), dropdown.SelectedIndex); } public void ADefWithNoSprite_ShowsNothingPicked() { TuningPanel panel = BuiltPanel(); panel.Bind(DefWith(null), "test"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); CheckNull(dropdown.SelectedIndex); } public void PickingASprite_PutsItOnTheBoundDef() { TuningPanel panel = BuiltPanel(); StandardEmitterDef def = DefWith(SoftDisc.Sprite); panel.Bind(def, "test"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); dropdown.Select(IndexOf(TestbedSprites.Cross)); CheckTrue(ReferenceEquals(TestbedSprites.Cross, def.Sprite)); } public void BindingAnotherDef_ShowsItsSpriteWithoutChangingEitherDef() { TuningPanel panel = BuiltPanel(); StandardEmitterDef first = DefWith(TestbedSprites.Star); StandardEmitterDef second = DefWith(TestbedSprites.Diamond); panel.Bind(first, "first"); panel.Bind(second, "second"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); CheckEqual(IndexOf(TestbedSprites.Diamond), dropdown.SelectedIndex); CheckTrue(ReferenceEquals(TestbedSprites.Star, first.Sprite)); CheckTrue(ReferenceEquals(TestbedSprites.Diamond, second.Sprite)); } public void CopyChanges_AfterPickingAStaticSprite_WritesItsLine() { string copied = null; TuningPanel panel = BuiltPanel(text => { copied = text; return true; }); panel.Bind(DefWith(SoftDisc.Sprite), "test"); var dropdown = (Dropdown)Find(panel.Frame, "sprite dropdown"); dropdown.Select(IndexOf(TestbedSprites.Cross)); panel.CopyChanges(); CheckEqual(DefText.Indent + "Sprite = TestbedSprites.Cross," + Environment.NewLine, copied); } } public class MessageTests : TestFixture { private static TuningPanel BoundPanel() { TuningPanel panel = BuiltPanel(); panel.Bind( new StandardEmitterDef { Capacity = 10, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }, "test"); return panel; } public void NothingToSay_ShowsNeitherMessage() { TuningPanel panel = BoundPanel(); CheckFalse(Find(panel.Frame, "status").Visible); CheckFalse(Find(panel.Frame, "problem").Visible); } public void AStatus_SitsUnderTheCopyButtons() { TuningPanel panel = BoundPanel(); panel.CopyAll(); CheckTrue(Find(panel.Frame, "status").Visible); CheckEqual( Find(panel.Frame, "Copy all button").Bounds.Bottom + 2, Find(panel.Frame, "status").Bounds.Top); } public void AStatus_GrowsTheWindowByItsHeightAndTheGapAbove() { TuningPanel panel = BoundPanel(); Scalar before = panel.Frame.Bounds.Height; panel.CopyAll(); CheckEqual(before + Find(panel.Frame, "status").Bounds.Height + 2, panel.Frame.Bounds.Height); } public void AProblem_SitsUnderTheStatus() { TuningPanel panel = BoundPanel(); panel.CopyAll(); panel.ShowProblem("A value can't work."); CheckEqual(Find(panel.Frame, "status").Bounds.Bottom + 2, Find(panel.Frame, "problem").Bounds.Top); } public void AProblemWithNoStatus_SitsUnderTheCopyButtons() { TuningPanel panel = BoundPanel(); panel.ShowProblem("A value can't work."); CheckEqual( Find(panel.Frame, "Copy all button").Bounds.Bottom + 2, Find(panel.Frame, "problem").Bounds.Top); } public void AProblemLongerThanALine_IsTallerThanOneThatFits() { TuningPanel panel = BoundPanel(); panel.ShowProblem("Short."); Scalar oneLine = Find(panel.Frame, "problem").Bounds.Height; panel.ShowProblem(string.Concat(System.Linq.Enumerable.Repeat("A value can't work. ", 6))); CheckTrue(Find(panel.Frame, "problem").Bounds.Height > oneLine); } public void AProblemLongerThanALine_StaysAsWideAsTheWindowsContent() { TuningPanel panel = BoundPanel(); panel.ShowProblem(string.Concat(System.Linq.Enumerable.Repeat("A value can't work. ", 6))); Control respawn = Find(panel.Frame, "Respawn selected button"); CheckEqual(respawn.Bounds.Width, Find(panel.Frame, "problem").Bounds.Width); } public void ClearingTheProblem_ShrinksTheWindowBack() { TuningPanel panel = BoundPanel(); Scalar before = panel.Frame.Bounds.Height; panel.ShowProblem("A value can't work."); panel.ShowProblem(""); CheckEqual(before, panel.Frame.Bounds.Height); CheckFalse(Find(panel.Frame, "problem").Visible); } public void Binding_ClearsBothMessages() { TuningPanel panel = BoundPanel(); Scalar before = panel.Frame.Bounds.Height; panel.CopyAll(); panel.ShowProblem("A value can't work."); panel.Bind(new StandardEmitterDef { Capacity = 10, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }, "again"); CheckEqual(before, panel.Frame.Bounds.Height); CheckFalse(Find(panel.Frame, "status").Visible); CheckFalse(Find(panel.Frame, "problem").Visible); } public void AMessage_KeepsTheWindowWhereItIs() { TuningPanel panel = BoundPanel(); var place = new Vector(40, 60); panel.Frame.Bounds = Rect.FromPositionAndSize(place, panel.Frame.Bounds.Size); panel.ShowProblem("A value can't work."); CheckEqual(place, panel.Frame.Bounds.TopLeft); } public void TheWindowHoldsNoUnusedRoomBelowTheButtons() { TuningPanel panel = BoundPanel(); TestbedSkin skin = TestbedSkinTests.BuiltSkin(); var content = new Vector(0, Find(panel.Frame, "Copy all button").Bounds.Bottom); CheckEqual(skin.Window.BoundsSizeFor(content, panel.Frame.TitleBarHeight).Y, panel.Frame.Bounds.Height); } } public class BindTests : TestFixture { public void ADefWhoseFunctionsArePointsCodeOrAbsent_IsShown() { TuningPanel panel = BuiltPanel(); var def = new StandardEmitterDef { Capacity = 10, SizeOverLife = new CallbackFunction(x => 1 - x), AlphaOverLife = new MonotoneSpline((0, 0), (0.5, 1), (1, 0)), TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; panel.Bind(def, "test"); CheckEqual("Tuning test", panel.Frame.Title); } public void ADefWithNoFunctions_IsShown() { TuningPanel panel = BuiltPanel(); var def = new StandardEmitterDef { Capacity = 10, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; panel.Bind(def, "plain"); CheckEqual("Tuning plain", panel.Frame.Title); } } public class FunctionEditTests : TestFixture { [IgnoreTest] private static StandardEmitterDef PointDef(IScalarFunction size = null) { return new StandardEmitterDef { Capacity = 10, SizeOverLife = size ?? new PiecewiseLinear((0, 1), (1, 0.5)), AlphaOverLife = new MonotoneSpline((0, 0), (0.5, 1), (1, 0)), TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; } [IgnoreTest] private static void Click(TuningPanel panel, string debugName) { ((Button)Find(panel.Frame, debugName)).Activate(default, new KeyboardManager()); } public void EachFunctionRow_HasAnEditButton() { TuningPanel panel = BuiltPanel(); CheckNotNull(Find(panel.Frame, "size over life edit button")); CheckNotNull(Find(panel.Frame, "alpha over life edit button")); } public void TheEditButton_OpensTheWindowOnThatFunction() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(PointDef(), "test"); Click(panel, "alpha over life edit button"); CheckTrue(functions.IsOpen); CheckEqual("alpha over life: test", functions.Frame.Title); CheckEqual(FunctionMode.Smooth, FunctionWindowTests.EditorOf(functions).Model.Mode); } public void AnEditInTheWindow_ReachesTheDef() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); StandardEmitterDef def = PointDef(); panel.Bind(def, "test"); Click(panel, "size over life edit button"); FunctionWindowTests.AddAPointInTheMiddle(functions); CheckEqual(3, ((PointFunction)def.SizeOverLife).PointCount); } /// /// A def that won't let its size dip below 0.7 halfway through life. /// public class PickyDef : StandardEmitterDef { public override void Validate() { base.Validate(); if (SizeOverLife.Evaluate(0.5) < 0.7) { throw new InvalidOperationException("The size can't dip that low."); } } } [IgnoreTest] private static PickyDef Picky() { return new PickyDef { Capacity = 10, SizeOverLife = new PiecewiseLinear((0, 1), (1, 0.5)), TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; } public void AnEditTheDefRefuses_LeavesTheDefAndTheWindowOnTheOldFunctionAndSaysWhy() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); PickyDef def = Picky(); var before = (PointFunction)def.SizeOverLife; panel.Bind(def, "picky"); Click(panel, "size over life edit button"); FunctionWindowTests.AddAPointInTheMiddle(functions); CheckTrue(ReferenceEquals(before, def.SizeOverLife)); CheckEqual(2, FunctionWindowTests.EditorOf(functions).Model.PointCount); CheckEqual("The size can't dip that low.", functions.Problem); } public void ADefsRefusal_IsNotShownInThePanelsOwnProblemRow() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(Picky(), "picky"); Click(panel, "size over life edit button"); FunctionWindowTests.AddAPointInTheMiddle(functions); CheckFalse(Find(panel.Frame, "problem").Visible); } public void ADefWithNoFunction_OpensOnOneEverywhereAndTakesTheFirstEdit() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); var def = new StandardEmitterDef { Capacity = 10, TintOverLife = new GradientDef { Gradient = Prism.Gradient.Constant(Prism.Colors.White) }, }; panel.Bind(def, "plain"); Click(panel, "size over life edit button"); FunctionWindowTests.AddAPointInTheMiddle(functions); CheckEqual(2, ((PointFunction)def.SizeOverLife).PointCount); } public void ANewDef_MovesAnOpenWindowToItsFunction() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(PointDef(), "first"); Click(panel, "size over life edit button"); StandardEmitterDef next = PointDef(); panel.Bind(next, "second"); FunctionWindowTests.AddAPointInTheMiddle(functions); CheckEqual("size over life: second", functions.Frame.Title); CheckEqual(3, ((PointFunction)next.SizeOverLife).PointCount); } public void ANewDef_LeavesAClosedWindowClosed() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(PointDef(), "first"); panel.Bind(PointDef(), "second"); CheckFalse(functions.IsOpen); } public void ANewDef_LeavesAWindowTheUserClosedClosed() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(PointDef(), "first"); Click(panel, "size over life edit button"); functions.Close(); panel.Bind(PointDef(), "second"); CheckFalse(functions.IsOpen); } public void AFunctionOfCode_HasAnEditButtonThatIsDisabled() { TuningPanel panel = BuiltPanel(); panel.Bind(PointDef(new CallbackFunction(x => 1 - x)), "code"); CheckFalse(((Button)Find(panel.Frame, "size over life edit button")).Enabled); CheckTrue(((Button)Find(panel.Frame, "alpha over life edit button")).Enabled); } public void ANewDefWhoseFunctionIsCode_ClosesTheWindow() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); panel.Bind(PointDef(), "first"); Click(panel, "size over life edit button"); panel.Bind(PointDef(new CallbackFunction(x => 1 - x)), "code"); CheckFalse(functions.IsOpen); } public void WithNoDefBound_TheEditButtonDoesNothing() { TuningPanel panel = BuiltPanel(out FunctionWindow functions); Click(panel, "size over life edit button"); CheckFalse(functions.IsOpen); } } public class GradientEditTests : TestFixture { /// /// A def that won't take a tint of more than two stops. /// public class TwoStopDef : StandardEmitterDef { public override void Validate() { base.Validate(); if (TintOverLife.Gradient.StopCount > 2) { throw new InvalidOperationException("The tint can't have that many stops."); } } } [IgnoreTest] private static TwoStopDef TwoStops() { return new TwoStopDef { Capacity = 10, SizeOverLife = new PiecewiseLinear((0, 1), (1, 0.5)), TintOverLife = new GradientDef { Gradient = GradientWindowTests.WhiteToWhite() }, }; } [IgnoreTest] private static void ClickEdit(TuningPanel panel) { ((Button)Find(panel.Frame, "Edit button")).Activate(default, new KeyboardManager()); } public void TheEditButton_OpensTheWindowOnTheDefsGradient() { TuningPanel panel = BuiltPanel(out GradientWindow gradients); panel.Bind(TwoStops(), "test"); ClickEdit(panel); CheckTrue(gradients.IsOpen); CheckEqual("tint over life: test", gradients.Frame.Title); } public void AnEditTheDefTakes_ReachesTheDef() { TuningPanel panel = BuiltPanel(out GradientWindow gradients); StandardEmitterDef def = new StandardEmitterDef { Capacity = 10, SizeOverLife = new PiecewiseLinear((0, 1), (1, 0.5)), TintOverLife = new GradientDef { Gradient = GradientWindowTests.WhiteToWhite() }, }; panel.Bind(def, "test"); ClickEdit(panel); GradientWindowTests.AddAStopInTheMiddle(gradients); CheckEqual(3, def.TintOverLife.Gradient.StopCount); } public void AnEditTheDefRefuses_LeavesTheDefAndTheWindowOnTheOldGradientAndSaysWhy() { TuningPanel panel = BuiltPanel(out GradientWindow gradients); TwoStopDef def = TwoStops(); Prism.Gradient before = def.TintOverLife.Gradient; panel.Bind(def, "test"); ClickEdit(panel); GradientWindowTests.AddAStopInTheMiddle(gradients); CheckTrue(ReferenceEquals(before, def.TintOverLife.Gradient)); CheckEqual(2, GradientWindowTests.EditorOf(gradients).Model.StopCount); CheckEqual("The tint can't have that many stops.", gradients.Problem); } public void ADefsRefusal_IsNotShownInThePanelsOwnProblemRow() { TuningPanel panel = BuiltPanel(out GradientWindow gradients); panel.Bind(TwoStops(), "test"); ClickEdit(panel); GradientWindowTests.AddAStopInTheMiddle(gradients); CheckFalse(Find(panel.Frame, "problem").Visible); } } public class FriendlyNameTests : TestFixture { public void AOneWordName_IsLowerCased() { CheckEqual("capacity", TuningPanel.FriendlyName("Capacity")); } public void ACamelCaseName_BecomesSeparateWords() { CheckEqual("sort by", TuningPanel.FriendlyName("SortBy")); CheckEqual("sort descending", TuningPanel.FriendlyName("SortDescending")); } public void AngularVelocity_IsCalledSpin() { CheckEqual("spin", TuningPanel.FriendlyName("AngularVelocity")); } } } }