Skip to content

Commit

Permalink
Add NWNX VM tests. Fix NWNX function name marshalling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Dec 7, 2024
1 parent 6b3e62d commit af53f38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions NWNX.NET.Tests/src/main/Tests/NWNXVMTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;

namespace NWNX.NET.Tests
{
[TestFixture(Category = "NWNX VM Tests")]
public sealed class NWNXVMTests
{
[Test]
[TestCase("NWNX_Core", 1)]
[TestCase("NWNX_DotNET", 1)]
[TestCase("NWNX_SWIG_DotNET", 1)]
[TestCase("NWNX_MissingPlugin", 0)]
[TestCase("", 0)]
[TestCase(null, 0, Ignore = "NWNX throws a std::logic_error")]
public void PluginExistsTest(string plugin, int expectedResult)
{
NWNXAPI.NWNXSetFunction("NWNX_Core", "PluginExists");
NWNXAPI.NWNXPushString(plugin);
NWNXAPI.NWNXCallFunction();

int result = NWNXAPI.NWNXPopInt();

Assert.That(result, Is.EqualTo(expectedResult));
}
}
}
2 changes: 1 addition & 1 deletion NWNX.NET/src/main/API/NWNXAPI.VM.NWNX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class NWNXAPI
/// <param name="function">The name of the function to call.</param>
[LibraryImport("NWNX_DotNET", EntryPoint = "NWNXSetFunction")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void NWNXSetFunction([MarshalUsing(typeof(Utf16StringMarshaller))] string plugin, [MarshalUsing(typeof(Utf16StringMarshaller))] string function);
public static partial void NWNXSetFunction([MarshalUsing(typeof(Utf8StringMarshaller))] string plugin, [MarshalUsing(typeof(Utf8StringMarshaller))] string function);

/// <summary>
/// NWNX VM Function. Push an integer to the current argument stack.
Expand Down

0 comments on commit af53f38

Please sign in to comment.