A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using NUnit.Framework;
5using osu.Framework.Bindables;
6using osu.Framework.Graphics.UserInterface;
7using osu.Framework.Testing;
8
9namespace osu.Framework.Tests.Visual.UserInterface
10{
11 [HeadlessTest]
12 public class TestUIComponentsWithCurrent : FrameworkTestScene
13 {
14 [Test]
15 public void TestUnbindDoesntUnbindBound()
16 {
17 Bindable<string> bindable = new Bindable<string>("test");
18 Bindable<string> boundBindable = bindable.GetBoundCopy();
19
20 Assert.That(boundBindable.Value, Is.EqualTo(bindable.Value));
21
22 var dropdown = new BasicDropdown<string> { Current = bindable };
23
24 AddStep("add dropdown", () => Add(dropdown));
25 AddStep("expire", () => dropdown.Expire());
26 AddUntilStep("wait for dispose", () => dropdown.IsDisposed);
27
28 AddStep("update unrelated bindable", () => bindable.Value = "test2");
29
30 AddAssert("ensure current unbound", () => dropdown.Current.Value != bindable.Value);
31 AddAssert("ensure externals still bound", () => boundBindable.Value == bindable.Value);
32 }
33
34 [Test]
35 public void TestChangeCurrent()
36 {
37 Bindable<string> bindable = new Bindable<string>("test");
38 Bindable<string> bindable2 = new Bindable<string>("test2");
39
40 var dropdown = new BasicDropdown<string> { Current = bindable };
41
42 AddStep("add dropdown", () => Add(dropdown));
43 AddAssert("ensure current bound", () => dropdown.Current.Value == bindable.Value);
44
45 AddStep("change target", () => dropdown.Current = bindable2);
46 AddAssert("ensure current switched", () => dropdown.Current.Value == bindable2.Value);
47 AddAssert("ensure original intact", () => dropdown.Current.Value != bindable.Value);
48
49 AddStep("change value", () => bindable2.Value = "test3");
50 AddAssert("ensure current bound", () => dropdown.Current.Value == bindable2.Value);
51 AddAssert("ensure original intact", () => dropdown.Current.Value != bindable.Value);
52 }
53
54 // TODO: add tests for other components
55 }
56}