/WaveReader/WaveReaderTest/WaveReaderTest.cs

http://dot-net-wave-reader.googlecode.com/ · C# · 151 lines · 104 code · 9 blank · 38 comment · 1 complexity · b03428eb47ec82235dd542c0d7b644ce MD5 · raw file

  1. using WaveReader;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using System.IO;
  4. using System;
  5. using System.Linq;
  6. namespace WaveReaderTest
  7. {
  8. /// <summary>
  9. ///This is a test class for WaveReaderTest and is intended
  10. ///to contain all WaveReaderTest Unit Tests
  11. ///</summary>
  12. [TestClass()]
  13. public class WaveReaderTest
  14. {
  15. private TestContext testContextInstance;
  16. /// <summary>
  17. ///Gets or sets the test context which provides
  18. ///information about and functionality for the current test run.
  19. ///</summary>
  20. public TestContext TestContext
  21. {
  22. get
  23. {
  24. return testContextInstance;
  25. }
  26. set
  27. {
  28. testContextInstance = value;
  29. }
  30. }
  31. #region Additional test attributes
  32. //
  33. //You can use the following additional attributes as you write your tests:
  34. //
  35. //Use ClassInitialize to run code before running the first test in the class
  36. //[ClassInitialize()]
  37. //public static void MyClassInitialize(TestContext testContext)
  38. //{
  39. //}
  40. //
  41. //Use ClassCleanup to run code after all tests in a class have run
  42. //[ClassCleanup()]
  43. //public static void MyClassCleanup()
  44. //{
  45. //}
  46. //
  47. //Use TestInitialize to run code before running each test
  48. //[TestInitialize()]
  49. //public void MyTestInitialize()
  50. //{
  51. //}
  52. //
  53. //Use TestCleanup to run code after each test has run
  54. //[TestCleanup()]
  55. //public void MyTestCleanup()
  56. //{
  57. //}
  58. //
  59. #endregion
  60. /// <summary>
  61. ///A test for SplitChannels
  62. ///</summary>
  63. [TestMethod()]
  64. public void SplitChannelsTest()
  65. {
  66. var splitChannelsTests = new SplitChannelsTest[]
  67. {
  68. new SplitChannelsTest()
  69. {
  70. BitsPerSample = 8,
  71. NumberOfChannels = 2,
  72. Input = new byte[]
  73. {
  74. 0x15,
  75. 0x51
  76. },
  77. Output = new short[][]
  78. {
  79. new short[]
  80. {
  81. 0x15
  82. },
  83. new short[]
  84. {
  85. 0x51
  86. }
  87. }
  88. },
  89. new SplitChannelsTest()
  90. {
  91. BitsPerSample = 4,
  92. NumberOfChannels = 1,
  93. Input = new byte[]
  94. {
  95. 0x15,
  96. 0x51
  97. },
  98. Output = new short[][]
  99. {
  100. new short[]
  101. {
  102. 0x01,
  103. 0x05,
  104. 0x05,
  105. 0x01
  106. }
  107. }
  108. },
  109. new SplitChannelsTest()
  110. {
  111. BitsPerSample = 16,
  112. NumberOfChannels = 1,
  113. Input = new byte[]
  114. {
  115. 0x15,
  116. 0x51
  117. },
  118. Output = new short[][]
  119. {
  120. new short[]
  121. {
  122. 0x5115
  123. }
  124. }
  125. }
  126. };
  127. foreach (var splitChannelsTest in splitChannelsTests)
  128. {
  129. using (var stream = new MemoryStream(splitChannelsTest.Input))
  130. using (var binaryReader = new BinaryReader(stream))
  131. {
  132. var actual = WaveData.SplitChannels(binaryReader, splitChannelsTest.NumberOfChannels, splitChannelsTest.BitsPerSample, splitChannelsTest.GetNumberOfFrames());
  133. Assert.AreEqual(splitChannelsTest.Output.Length, actual.Length);
  134. for (var channel = 0; channel < splitChannelsTest.NumberOfChannels; channel++)
  135. {
  136. Assert.IsTrue(splitChannelsTest.Output[channel].SequenceEqual(actual[channel]));
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }