forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WavImporterTests.cs
79 lines (66 loc) · 3.67 KB
/
WavImporterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// MonoGame - Copyright (C) MonoGame Foundation, Inc
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline;
using NUnit.Framework;
namespace MonoGame.Tests.ContentPipeline
{
class WavImporterTests
{
[Test]
public void Arguments()
{
var context = new TestImporterContext("TestObj", "TestBin");
Assert.Throws<ArgumentNullException>(() => new WavImporter().Import(null, context));
Assert.Throws<ArgumentNullException>(() => new WavImporter().Import("", context));
Assert.Throws<ArgumentNullException>(() => new WavImporter().Import(@"Assets/Audio/bark_mono_44hz_8bit.wav", null));
Assert.Throws<FileNotFoundException>(() => new WavImporter().Import(@"this\does\not\exist.wav", context));
}
[TestCase(@"Assets/Audio/rock_loop_stereo.mp3")]
[TestCase(@"Assets/Audio/rock_loop_stereo.wma")]
public void InvalidFormat(string sourceFile)
{
Assert.Throws<InvalidContentException>(() => new WavImporter().Import(sourceFile, new TestImporterContext("TestObj", "TestBin")));
}
[TestCase(@"Assets/Audio/bark_mono_44hz_32bit.wav")]
public void InvalidBitDepth(string sourceFile)
{
Assert.Throws<InvalidContentException>(() => new WavImporter().Import(sourceFile, new TestImporterContext("TestObj", "TestBin")));
}
// TODO: Need to add tests for channel counts and sample rate most likely!
[TestCase(@"Assets/Audio/bark_mono_88hz_16bit.wav")]
public void InvalidSampleRate(string sourceFile)
{
Assert.Throws<InvalidContentException>(() => new WavImporter().Import(sourceFile, new TestImporterContext("TestObj", "TestBin")));
}
// 8bit Mono
[TestCase(@"Assets/Audio/bark_mono_44hz_8bit.wav", 1, 44100, 44100, 8, 1)]
[TestCase(@"Assets/Audio/bark_mono_22hz_8bit.wav", 1, 22050, 22050, 8, 1)]
[TestCase(@"Assets/Audio/bark_mono_11hz_8bit.wav", 1, 11025, 11025, 8, 1)]
// 8bit Stereo
[TestCase(@"Assets/Audio/rock_loop_stereo_44hz_8bit.wav", 2, 88200, 44100, 8, 2)]
[TestCase(@"Assets/Audio/rock_loop_stereo_22hz_8bit.wav", 2, 44100, 22050, 8, 2)]
[TestCase(@"Assets/Audio/rock_loop_stereo_11hz_8bit.wav", 2, 22050, 11025, 8, 2)]
// 16bit Mono
[TestCase(@"Assets/Audio/blast_mono.wav", 1, 88200, 44100, 16, 2)]
[TestCase(@"Assets/Audio/blast_mono_22hz.wav", 1, 44100, 22050, 16, 2)]
[TestCase(@"Assets/Audio/blast_mono_11hz.wav", 1, 22050, 11025, 16, 2)]
// 16bit Stereo
[TestCase(@"Assets/Audio/rock_loop_stereo.wav", 2, 176400, 44100, 16, 4)]
[TestCase(@"Assets/Audio/rock_loop_stereo_22hz.wav", 2, 88200, 22050, 16, 4)]
[TestCase(@"Assets/Audio/rock_loop_stereo_11hz.wav", 2, 44100, 11025, 16, 4)]
public void Import(string sourceFile, int channels, int averageBytesPerSecond, int sampleRate, int bitsPerSample, int blockAlign)
{
var content = new WavImporter().Import(sourceFile, new TestImporterContext("TestObj", "TestBin"));
Assert.AreEqual(1, content.Format.Format);
Assert.AreEqual(channels, content.Format.ChannelCount);
Assert.AreEqual(averageBytesPerSecond, content.Format.AverageBytesPerSecond);
Assert.AreEqual(sampleRate, content.Format.SampleRate);
Assert.AreEqual(bitsPerSample, content.Format.BitsPerSample);
Assert.AreEqual(blockAlign, content.Format.BlockAlign);
content.Dispose();
}
}
}