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 System;
5using System.Threading;
6using NUnit.Framework;
7using osu.Framework.Audio.Sample;
8
9namespace osu.Framework.Tests.Audio
10{
11 [TestFixture]
12 public class SampleBassTest
13 {
14 private BassTestComponents bass;
15 private Sample sample;
16 private SampleChannel channel;
17
18 [SetUp]
19 public void Setup()
20 {
21 bass = new BassTestComponents();
22 sample = bass.GetSample();
23
24 bass.Update();
25 }
26
27 [TearDown]
28 public void Teardown()
29 {
30 bass?.Dispose();
31 }
32
33 [Test]
34 public void TestGetChannelOnDisposed()
35 {
36 sample.Dispose();
37
38 sample.Update();
39
40 Assert.Throws<ObjectDisposedException>(() => sample.GetChannel());
41 Assert.Throws<ObjectDisposedException>(() => sample.Play());
42 }
43
44 [Test]
45 public void TestStart()
46 {
47 channel = sample.Play();
48 bass.Update();
49
50 Thread.Sleep(50);
51
52 bass.Update();
53
54 Assert.IsTrue(channel.Playing);
55 }
56
57 [Test]
58 public void TestStop()
59 {
60 channel = sample.Play();
61 bass.Update();
62
63 channel.Stop();
64 bass.Update();
65
66 Assert.IsFalse(channel.Playing);
67 }
68
69 [Test]
70 public void TestStopBeforeLoadFinished()
71 {
72 channel = sample.Play();
73 channel.Stop();
74
75 bass.Update();
76
77 Assert.IsFalse(channel.Playing);
78 }
79
80 [Test]
81 public void TestStopsWhenFactoryDisposed()
82 {
83 channel = sample.Play();
84 bass.Update();
85
86 bass.SampleStore.Dispose();
87 bass.Update();
88
89 Assert.IsFalse(channel.Playing);
90 }
91 }
92}