22// See the LICENCE file in the repository root for full licence text.
33
44using System . Linq ;
5+ using ManagedBass ;
56using Moq ;
67using NUnit . Framework ;
78using osu . Framework . Audio . Track ;
1011using osu . Game . Rulesets . Edit ;
1112using osu . Game . Rulesets . Edit . Checks ;
1213using osu . Game . Rulesets . Objects ;
14+ using osu . Game . Tests . Resources ;
1315using osu . Game . Tests . Visual ;
16+ using osuTK . Audio ;
1417
1518namespace osu . Game . Tests . Editing . Checks
1619{
@@ -28,9 +31,13 @@ public void Setup()
2831 {
2932 BeatmapInfo = new BeatmapInfo
3033 {
31- Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
34+ Metadata = new BeatmapMetadata ( )
3235 }
3336 } ;
37+
38+ // 0 = No output device. This still allows decoding.
39+ if ( ! Bass . Init ( 0 ) && Bass . LastError != Errors . Already )
40+ throw new AudioException ( "Could not initialize Bass." ) ;
3441 }
3542
3643 [ Test ]
@@ -54,6 +61,14 @@ public void TestAcceptable()
5461 Assert . That ( check . Run ( context ) , Is . Empty ) ;
5562 }
5663
64+ [ Test ]
65+ public void TestAcceptableOgg ( )
66+ {
67+ var context = getContext ( 208 , useOgg : true ) ;
68+
69+ Assert . That ( check . Run ( context ) , Is . Empty ) ;
70+ }
71+
5772 [ Test ]
5873 public void TestNullBitrate ( )
5974 {
@@ -87,6 +102,17 @@ public void TestTooHighBitrate()
87102 Assert . That ( issues . Single ( ) . Template is CheckAudioQuality . IssueTemplateTooHighBitrate ) ;
88103 }
89104
105+ [ Test ]
106+ public void TestTooHighBitrateOgg ( )
107+ {
108+ var context = getContext ( 250 , useOgg : true ) ;
109+
110+ var issues = check . Run ( context ) . ToList ( ) ;
111+
112+ Assert . That ( issues , Has . Count . EqualTo ( 1 ) ) ;
113+ Assert . That ( issues . Single ( ) . Template is CheckAudioQuality . IssueTemplateTooHighBitrate ) ;
114+ }
115+
90116 [ Test ]
91117 public void TestTooLowBitrate ( )
92118 {
@@ -98,24 +124,41 @@ public void TestTooLowBitrate()
98124 Assert . That ( issues . Single ( ) . Template is CheckAudioQuality . IssueTemplateTooLowBitrate ) ;
99125 }
100126
101- private BeatmapVerifierContext getContext ( int ? audioBitrate )
127+ private BeatmapVerifierContext getContext ( int ? audioBitrate , bool useOgg = false )
102128 {
103- return new BeatmapVerifierContext ( beatmap , getMockWorkingBeatmap ( audioBitrate ) . Object ) ;
129+ // Update the audio filename and beatmapset files based on the format being tested
130+ string audioFileName = useOgg ? "abc123.ogg" : "abc123.mp3" ;
131+ string fileExtension = useOgg ? "ogg" : "mp3" ;
132+
133+ beatmap . Metadata . AudioFile = audioFileName ;
134+ beatmap . BeatmapInfo . BeatmapSet = new BeatmapSetInfo
135+ {
136+ Files = { CheckTestHelpers . CreateMockFile ( fileExtension ) }
137+ } ;
138+
139+ return new BeatmapVerifierContext ( beatmap , getMockWorkingBeatmap ( audioBitrate , useOgg ) . Object ) ;
104140 }
105141
106142 /// <summary>
107143 /// Returns the mock of the working beatmap with the given audio properties.
108144 /// </summary>
109145 /// <param name="audioBitrate">The bitrate of the audio file the beatmap uses.</param>
110- private Mock < IWorkingBeatmap > getMockWorkingBeatmap ( int ? audioBitrate )
146+ /// <param name="useOgg">Whether to use an OGG sample instead of MP3.</param>
147+ private Mock < IWorkingBeatmap > getMockWorkingBeatmap ( int ? audioBitrate , bool useOgg = false )
111148 {
112149 var mockTrack = new Mock < OsuTestScene . ClockBackedTestWorkingBeatmap . TrackVirtualManual > ( new FramedClock ( ) , "virtual" ) ;
113150 mockTrack . SetupGet ( t => t . Bitrate ) . Returns ( audioBitrate ) ;
114151
152+ // Use real audio samples for format detection
153+ string samplePath = useOgg ? "Samples/test-sample.ogg" : "Samples/test-sample-cut.mp3" ;
154+
115155 var mockWorkingBeatmap = new Mock < IWorkingBeatmap > ( ) ;
116156 mockWorkingBeatmap . SetupGet ( w => w . Beatmap ) . Returns ( beatmap ) ;
117157 mockWorkingBeatmap . SetupGet ( w => w . Track ) . Returns ( mockTrack . Object ) ;
118158
159+ // Return a fresh stream each time GetStream is called to avoid disposed stream issues
160+ mockWorkingBeatmap . Setup ( w => w . GetStream ( It . IsAny < string > ( ) ) ) . Returns ( ( ) => TestResources . OpenResource ( samplePath ) ) ;
161+
119162 return mockWorkingBeatmap ;
120163 }
121164 }
0 commit comments