/MediaParsersTests/MpegLayer3WaveFormatTests.cs

https://github.com/slau/ManagedMediaHelpers · C# · 242 lines · 128 code · 22 blank · 92 comment · 0 complexity · 97d6ac27b2db2448e294a7ab8b34c1c3 MD5 · raw file

  1. //-----------------------------------------------------------------------
  2. // <copyright file="MpegLayer3WaveFormatTests.cs" company="Larry Olson">
  3. // (c) Copyright Larry Olson.
  4. // This source is subject to the Microsoft Public License (Ms-PL)
  5. // See http://code.msdn.microsoft.com/ManagedMediaHelpers/Project/License.aspx
  6. // All other rights reserved.
  7. // </copyright>
  8. //-----------------------------------------------------------------------
  9. namespace MediaParsersTests
  10. {
  11. using System;
  12. using System.Diagnostics.CodeAnalysis;
  13. using System.Net;
  14. using MediaParsers;
  15. using Microsoft.VisualStudio.TestTools.UnitTesting;
  16. [TestClass]
  17. public class MpegLayer3WaveFormatTests
  18. {
  19. private WaveFormatExtensible wfx;
  20. [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "mp3 is not hungarian notation and is common parlance")]
  21. private MpegLayer3WaveFormat mp3wfx;
  22. [TestInitialize]
  23. public void SetupTests()
  24. {
  25. this.wfx = new WaveFormatExtensible();
  26. this.wfx.FormatTag = 85;
  27. this.wfx.Channels = 2;
  28. this.wfx.SamplesPerSec = 8000;
  29. this.wfx.AverageBytesPerSecond = 500;
  30. this.wfx.BlockAlign = 1;
  31. this.wfx.BitsPerSample = 16;
  32. this.wfx.Size = 12;
  33. this.mp3wfx = new MpegLayer3WaveFormat();
  34. }
  35. [TestMethod]
  36. public void WaveFormatExtensibleTest()
  37. {
  38. this.mp3wfx.WaveFormatExtensible = this.wfx;
  39. Assert.AreEqual(this.wfx, this.mp3wfx.WaveFormatExtensible);
  40. }
  41. [TestMethod]
  42. public void WaveFormatExtensibleNullTest()
  43. {
  44. this.mp3wfx.WaveFormatExtensible = null;
  45. Assert.AreEqual(null, this.mp3wfx.WaveFormatExtensible);
  46. }
  47. [TestMethod]
  48. public void WaveFormatExtensibleCoherencyTest()
  49. {
  50. /*
  51. * There are certain combinations of fields that are valid
  52. * and invalid in a MpegLayer3WaveFormat structure.
  53. * IE:
  54. * mp3wfx.WaveFormatExtensible.Size must be 12;
  55. * mp3wfx.Id must be 1
  56. *
  57. * Code currently does not check for this but could be added for extra
  58. * robustness
  59. *
  60. * See the documentation for MPEGLAYER3WAVEFORMAT on msdn
  61. * http://msdn.microsoft.com/en-us/library/cc307970(VS.85).aspx
  62. */
  63. ////Assert.Inconclusive();
  64. }
  65. [TestMethod]
  66. public void IdTest()
  67. {
  68. this.mp3wfx.Id = 1;
  69. Assert.AreEqual(1, this.mp3wfx.Id);
  70. }
  71. [TestMethod]
  72. public void IdMinimumValueTest()
  73. {
  74. /*
  75. * 1 is the smallest possible Id
  76. *
  77. * Code currently does not check for this but could be added for extra
  78. * robustness
  79. *
  80. * Clamp or throw
  81. */
  82. ////mp3wfx.Id = 1;
  83. ////Assert.Inconclusive();
  84. }
  85. [TestMethod]
  86. public void IdMaximumValueTest()
  87. {
  88. /*
  89. * 1 is the largest possible Id
  90. *
  91. * Code currently does not check for this but could be added for extra
  92. * robustness
  93. *
  94. * Clamp or throw
  95. */
  96. ////mp3wfx.Id = 1;
  97. ////Assert.Inconclusive();
  98. }
  99. [TestMethod]
  100. public void BitratePaddingModeTest()
  101. {
  102. this.mp3wfx.BitratePaddingMode = 2;
  103. Assert.AreEqual(2, this.mp3wfx.BitratePaddingMode);
  104. }
  105. [TestMethod]
  106. public void BitratePaddingModeMinimumValueTest()
  107. {
  108. /*
  109. * 0 is the smallest possible BitratePaddingMode
  110. *
  111. * Code currently does not check for this but could be added for extra
  112. * robustness
  113. *
  114. * Clamp or throw
  115. */
  116. ////mp3wfx.BitratePaddingMode = -1;
  117. ////Assert.Inconclusive();
  118. }
  119. [TestMethod]
  120. public void BitratePaddingModeMaximumValueTest()
  121. {
  122. /*
  123. * 2 is the largest possible BitratePaddingMode
  124. *
  125. * Code currently does not check for this but could be added for extra
  126. * robustness
  127. *
  128. * Clamp or throw
  129. */
  130. ////mp3wfx.BitratePaddingMode = 3;
  131. ////Assert.Inconclusive();
  132. }
  133. [TestMethod]
  134. public void BlockSizeTest()
  135. {
  136. this.mp3wfx.BlockSize = 500;
  137. Assert.AreEqual(500, this.mp3wfx.BlockSize);
  138. }
  139. [TestMethod]
  140. public void BlockSizeMinimumValueTest()
  141. {
  142. /*
  143. * 1 is the smallest possible BlockSize
  144. *
  145. * Code currently does not check for this but could be added for extra
  146. * robustness
  147. *
  148. * Clamp or throw
  149. */
  150. ////mp3wfx.BlockSize = 0;
  151. ////Assert.Inconclusive();
  152. }
  153. [TestMethod]
  154. public void FramePerBlockTest()
  155. {
  156. this.mp3wfx.FramesPerBlock = 1;
  157. Assert.AreEqual(1, this.mp3wfx.FramesPerBlock);
  158. }
  159. [TestMethod]
  160. public void FramePerBlockMinimumValueTest()
  161. {
  162. /*
  163. * 1 is the smallest possible number of FramesPerBlock
  164. *
  165. * Code currently does not check for this but could be added for extra
  166. * robustness
  167. *
  168. * Clamp or throw
  169. */
  170. ////mp3wfx.FramesPerBlock = 0;
  171. ////Assert.Inconclusive();
  172. }
  173. [TestMethod]
  174. public void CodecDelayTest()
  175. {
  176. this.mp3wfx.CodecDelay = 10;
  177. Assert.AreEqual(10, this.mp3wfx.CodecDelay);
  178. }
  179. [TestMethod]
  180. public void CodecDelayMinimumValueTest()
  181. {
  182. /*
  183. * 0 is the smallest possible number of CodecDelay
  184. *
  185. * Code currently does not check for this but could be added for extra
  186. * robustness
  187. *
  188. * Clamp or throw
  189. */
  190. ////mp3wfx.CodecDelay = -1;
  191. ////Assert.Inconclusive();
  192. }
  193. [TestMethod]
  194. public void ToHexStringTest()
  195. {
  196. this.mp3wfx.WaveFormatExtensible = this.wfx;
  197. this.mp3wfx.Id = 1;
  198. this.mp3wfx.BitratePaddingMode = 2;
  199. this.mp3wfx.BlockSize = 1000;
  200. this.mp3wfx.FramesPerBlock = 1;
  201. this.mp3wfx.CodecDelay = 0;
  202. string s = this.mp3wfx.ToHexString();
  203. string expectedResult = "55000200401F0000F4010000010010000C00010002000000E80301000000";
  204. Assert.AreEqual(expectedResult, s);
  205. }
  206. [TestMethod]
  207. public void ToStringTest()
  208. {
  209. this.mp3wfx.WaveFormatExtensible = this.wfx;
  210. this.mp3wfx.Id = 1;
  211. this.mp3wfx.BitratePaddingMode = 2;
  212. this.mp3wfx.BlockSize = 1000;
  213. this.mp3wfx.FramesPerBlock = 1;
  214. this.mp3wfx.CodecDelay = 0;
  215. string s = this.mp3wfx.ToString();
  216. string expectedResult = "MPEGLAYER3 WAVEFORMATEX FormatTag: 85, Channels: 2, SamplesPerSec: 8000, AvgBytesPerSec: 500, BlockAlign: 1, BitsPerSample: 16, Size: 12 ID: 1, Flags: 2, BlockSize: 1000, FramesPerBlock 1, CodecDelay 0";
  217. Assert.AreEqual(expectedResult, s);
  218. }
  219. }
  220. }