Skip to content

Commit

Permalink
add message stack tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laves committed Nov 21, 2023
1 parent 0ab4bd4 commit cd9a7cb
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions binding/dotnet/LeopardTest/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ specific language governing permissions and limitations under the License.
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

using Fastenshtein;

Expand Down Expand Up @@ -224,6 +226,67 @@ public void TestSampleRate()
}
}

[TestMethod]
public void TestMessageStack()
{
Leopard l;
string[] messageList = new string[] { };

try
{
l = Leopard.Create("invalid");
Assert.IsNull(l);
l.Dispose();
}
catch (LeopardException e)
{
messageList = e.MessageStack;
}

Assert.IsTrue(0 < messageList.Length);
Assert.IsTrue(messageList.Length < 8);

try
{
l = Leopard.Create("invalid");
Assert.IsNull(l);
l.Dispose();
}
catch (LeopardException e)
{
for (int i = 0; i < messageList.Length; i++)
{
Assert.AreEqual(messageList[i], e.MessageStack[i]);
}
}
}

[TestMethod]
public void TestProcessMessageStack()
{
Leopard l = Leopard.Create(_accessKey);
short[] testPcm = new short[1024];

var obj = typeof(Leopard).GetField("_libraryPointer", BindingFlags.NonPublic | BindingFlags.Instance);
IntPtr address = (IntPtr)obj.GetValue(l);
obj.SetValue(l, IntPtr.Zero);

try
{
LeopardTranscript res = l.Process(testPcm);
Assert.IsTrue(res == null);
}
catch (LeopardException e)
{
Assert.IsTrue(0 < e.MessageStack.Length);
Assert.IsTrue(e.MessageStack.Length < 8);
}

obj.SetValue(l, address);
l.Dispose();
}


[TestMethod]
[DynamicData(nameof(ProcessTestParameters))]
public void TestProcess(
Expand Down

0 comments on commit cd9a7cb

Please sign in to comment.