Skip to content

Commit cbc1197

Browse files
Added tests for scalars on AnalyserNode.
1 parent 72925be commit cbc1197

File tree

2 files changed

+102
-9
lines changed

2 files changed

+102
-9
lines changed

src/KristofferStrube.Blazor.WebAudio/AudioNodes/AnalyserNode.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public async Task GetByteTimeDomainDataAsync(Uint8Array array)
112112
/// <returns>Sample frames size.</returns>
113113
public async Task<ulong> GetFftSizeAsync()
114114
{
115-
IJSObjectReference helper = await helperTask.Value;
115+
IJSObjectReference helper = await webAudioHelperTask.Value;
116116
return await helper.InvokeAsync<ulong>("getAttribute", JSReference, "fftSize");
117117
}
118118

@@ -128,7 +128,7 @@ public async Task<ulong> GetFftSizeAsync()
128128
/// <exception cref="IndexSizeErrorException"></exception>
129129
public async Task SetFftSizeAsync(ulong value)
130130
{
131-
IJSObjectReference helper = await helperTask.Value;
131+
IJSObjectReference helper = await webAudioHelperTask.Value;
132132
await helper.InvokeVoidAsync("setAttribute", JSReference, "fftSize", value);
133133
}
134134

@@ -137,7 +137,7 @@ public async Task SetFftSizeAsync(ulong value)
137137
/// </summary>
138138
public async Task<ulong> GetFrequencyBinCountAsync()
139139
{
140-
IJSObjectReference helper = await helperTask.Value;
140+
IJSObjectReference helper = await webAudioHelperTask.Value;
141141
return await helper.InvokeAsync<ulong>("getAttribute", JSReference, "frequencyBinCount");
142142
}
143143

@@ -146,7 +146,7 @@ public async Task<ulong> GetFrequencyBinCountAsync()
146146
/// </summary>
147147
public async Task<double> GetMaxDecibelsAsync()
148148
{
149-
IJSObjectReference helper = await helperTask.Value;
149+
IJSObjectReference helper = await webAudioHelperTask.Value;
150150
return await helper.InvokeAsync<double>("getAttribute", JSReference, "maxDecibels");
151151
}
152152

@@ -160,7 +160,7 @@ public async Task<double> GetMaxDecibelsAsync()
160160
/// <exception cref="IndexSizeErrorException"></exception>
161161
public async Task SetMaxDecibelsAsync(double value)
162162
{
163-
IJSObjectReference helper = await helperTask.Value;
163+
IJSObjectReference helper = await webAudioHelperTask.Value;
164164
await helper.InvokeVoidAsync("setAttribute", JSReference, "maxDecibels", value);
165165
}
166166

@@ -169,7 +169,7 @@ public async Task SetMaxDecibelsAsync(double value)
169169
/// </summary>
170170
public async Task<double> GetMinDecibelsAsync()
171171
{
172-
IJSObjectReference helper = await helperTask.Value;
172+
IJSObjectReference helper = await webAudioHelperTask.Value;
173173
return await helper.InvokeAsync<double>("getAttribute", JSReference, "minDecibels");
174174
}
175175

@@ -183,7 +183,7 @@ public async Task<double> GetMinDecibelsAsync()
183183
/// <exception cref="IndexSizeErrorException"></exception>
184184
public async Task SetMinDecibelsAsync(double value)
185185
{
186-
IJSObjectReference helper = await helperTask.Value;
186+
IJSObjectReference helper = await webAudioHelperTask.Value;
187187
await helper.InvokeVoidAsync("setAttribute", JSReference, "minDecibels", value);
188188
}
189189

@@ -192,7 +192,7 @@ public async Task SetMinDecibelsAsync(double value)
192192
/// </summary>
193193
public async Task<double> GetSmoothingTimeConstantAsync()
194194
{
195-
IJSObjectReference helper = await helperTask.Value;
195+
IJSObjectReference helper = await webAudioHelperTask.Value;
196196
return await helper.InvokeAsync<double>("getAttribute", JSReference, "smoothingTimeConstant");
197197
}
198198

@@ -206,7 +206,7 @@ public async Task<double> GetSmoothingTimeConstantAsync()
206206
/// <exception cref="IndexSizeErrorException"></exception>
207207
public async Task SetSmoothingTimeConstantAsync(double value)
208208
{
209-
IJSObjectReference helper = await helperTask.Value;
209+
IJSObjectReference helper = await webAudioHelperTask.Value;
210210
await helper.InvokeVoidAsync("setAttribute", JSReference, "smoothingTimeConstant", value);
211211
}
212212
}

tests/IntegrationTests/AudioNodeTests/AnalyserNodeTest.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FluentAssertions;
22
using KristofferStrube.Blazor.WebIDL;
3+
using KristofferStrube.Blazor.WebIDL.Exceptions;
34
using Microsoft.JSInterop;
45

56
namespace IntegrationTests.AudioNodeTests;
@@ -134,4 +135,96 @@ public async Task SetFftSizeAsync_ShouldUpdateFftSize(ulong fftSize)
134135
ulong readFftSize = await node.GetFftSizeAsync();
135136
_ = readFftSize.Should().Be(fftSize);
136137
}
138+
139+
[Test]
140+
[TestCase(16ul)]
141+
[TestCase(65536ul)]
142+
public async Task SetFftSizeAsync_ThrowsIndexSizeErrorException_WhenFftSizeIsOutOfBounds(ulong fftSize)
143+
{
144+
// Arrange
145+
await using AudioContext context = await GetAudioContextAsync();
146+
147+
await using AnalyserNode node = await AnalyserNode.CreateAsync(JSRuntime, context);
148+
149+
// Act
150+
Func<Task> action = async () => await node.SetFftSizeAsync(fftSize);
151+
152+
// Assert
153+
_ = await action.Should().ThrowAsync<IndexSizeErrorException>();
154+
}
155+
156+
[Test]
157+
[TestCase(33ul)]
158+
[TestCase(32767ul)]
159+
public async Task SetFftSizeAsync_ThrowsIndexSizeErrorException_WhenFftSizeIsNotAPowerOfTwo(ulong fftSize)
160+
{
161+
// Arrange
162+
await using AudioContext context = await GetAudioContextAsync();
163+
164+
await using AnalyserNode node = await AnalyserNode.CreateAsync(JSRuntime, context);
165+
166+
// Act
167+
Func<Task> action = async () => await node.SetFftSizeAsync(fftSize);
168+
169+
// Assert
170+
_ = await action.Should().ThrowAsync<IndexSizeErrorException>();
171+
}
172+
173+
[Test]
174+
[TestCase(32ul)]
175+
[TestCase(64ul)]
176+
public async Task GetFrequencyBinCountAsync_ShouldRetrieveFrequncyBinCount(ulong fftSize)
177+
{
178+
// Arrange
179+
await using AudioContext context = await GetAudioContextAsync();
180+
181+
await using AnalyserNode node = await AnalyserNode.CreateAsync(JSRuntime, context, new()
182+
{
183+
FftSize = fftSize
184+
});
185+
186+
// Act
187+
ulong readBinCount = await node.GetFrequencyBinCountAsync();
188+
189+
// Assert
190+
_ = readBinCount.Should().Be(fftSize / 2);
191+
}
192+
193+
[Test]
194+
[TestCase(-30)]
195+
[TestCase(0)]
196+
public async Task GetMaxDecibelsAsync_ShouldRetrieveMaxDecibels(double maxDecibels)
197+
{
198+
// Arrange
199+
await using AudioContext context = await GetAudioContextAsync();
200+
201+
await using AnalyserNode node = await AnalyserNode.CreateAsync(JSRuntime, context, new()
202+
{
203+
MaxDecibels = maxDecibels
204+
});
205+
206+
// Act
207+
double readMaxDecibels = await node.GetMaxDecibelsAsync();
208+
209+
// Assert
210+
_ = readMaxDecibels.Should().Be(maxDecibels);
211+
}
212+
213+
[Test]
214+
[TestCase(-30)]
215+
[TestCase(0)]
216+
public async Task SetMaxDecibelsAsync_ShouldUpdateMaxDecibels(double maxDecibels)
217+
{
218+
// Arrange
219+
await using AudioContext context = await GetAudioContextAsync();
220+
221+
await using AnalyserNode node = await AnalyserNode.CreateAsync(JSRuntime, context);
222+
223+
// Act
224+
await node.SetMaxDecibelsAsync(maxDecibels);
225+
226+
// Assert
227+
double readMaxDecibels = await node.GetMaxDecibelsAsync();
228+
_ = readMaxDecibels.Should().Be(maxDecibels);
229+
}
137230
}

0 commit comments

Comments
 (0)