PkmnLibSharp/PkmnLibSharpTests/TestClass.cs

53 lines
1.7 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using NUnit.Framework;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Utilities;
using PkmnLibSharpTests.Battling;
namespace PkmnLibSharpTests
{
[SetUpFixture]
public sealed class TestClass
{
[OneTimeSetUp]
public void Init()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
NativeLibrary.SetDllImportResolver(assembly, ImportResolver);
}
LoadLibrary("libArbutils");
LoadLibrary("libCreatureLib");
LoadLibrary("libangelscript");
LoadLibrary("libpkmnLib");
LoadLibrary("libpkmnlib_ai");
LogHandler.RegisterListener((level, s) =>
{
Console.WriteLine($"[{level.ToString().ToUpperInvariant()}] {s}");
});
SignalHandler.SetSignalListener(s => throw new Exception("Encountered a catastrophic signal. \n" + s));
}
private IntPtr ImportResolver(string libraryname, Assembly assembly, DllImportSearchPath? searchpath)
{
return LoadLibrary(libraryname);
}
private IntPtr LoadLibrary(string libraryName)
{
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyFile = Environment.OSVersion.Platform == PlatformID.Unix
? Path.Join(directory, libraryName + ".so")
: Path.Join(directory, libraryName + ".dll");
return NativeLibrary.Load(assemblyFile);
}
}
}