PkmnLibSharp/PkmnLibSharpTests/TestClass.cs

53 lines
1.7 KiB
C#
Raw Normal View History

2020-08-14 14:15:19 +00:00
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using NUnit.Framework;
2020-08-14 14:15:19 +00:00
using PkmnLibSharp.Battling;
2020-08-18 17:26:39 +00:00
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);
}
2022-03-26 16:35:36 +00:00
LoadLibrary("libArbutils");
LoadLibrary("libCreatureLib");
LoadLibrary("libangelscript");
LoadLibrary("libpkmnLib");
LoadLibrary("libpkmnlib_ai");
2020-08-14 14:15:19 +00:00
LogHandler.RegisterListener((level, s) =>
{
Console.WriteLine($"[{level.ToString().ToUpperInvariant()}] {s}");
});
2020-08-18 17:26:39 +00:00
SignalHandler.SetSignalListener(s => throw new Exception("Encountered a catastrophic signal. \n" + s));
}
private IntPtr ImportResolver(string libraryname, Assembly assembly, DllImportSearchPath? searchpath)
2022-03-26 16:35:36 +00:00
{
return LoadLibrary(libraryname);
}
private IntPtr LoadLibrary(string libraryName)
{
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyFile = Environment.OSVersion.Platform == PlatformID.Unix
2022-03-26 16:35:36 +00:00
? Path.Join(directory, libraryName + ".so")
: Path.Join(directory, libraryName + ".dll");
return NativeLibrary.Load(assemblyFile);
}
}
}