2020-08-14 14:15:19 +00:00
|
|
|
using System;
|
2022-03-26 15:46:07 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
2020-07-31 12:19:21 +00:00
|
|
|
using System.Reflection;
|
|
|
|
using System.Runtime.InteropServices;
|
2022-03-26 15:46:07 +00:00
|
|
|
using System.Runtime.Loader;
|
2020-07-31 12:19:21 +00:00
|
|
|
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;
|
2020-12-23 11:27:58 +00:00
|
|
|
using PkmnLibSharpTests.Battling;
|
2020-07-31 12:19:21 +00:00
|
|
|
|
|
|
|
namespace PkmnLibSharpTests
|
|
|
|
{
|
|
|
|
[SetUpFixture]
|
|
|
|
public sealed class TestClass
|
|
|
|
{
|
|
|
|
[OneTimeSetUp]
|
|
|
|
public void Init()
|
|
|
|
{
|
2022-03-26 15:46:07 +00:00
|
|
|
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-12-23 11:27:58 +00:00
|
|
|
|
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));
|
2020-07-31 12:19:21 +00:00
|
|
|
}
|
2022-03-26 15:46:07 +00:00
|
|
|
|
|
|
|
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)
|
2022-03-26 15:46:07 +00:00
|
|
|
{
|
|
|
|
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");
|
2022-03-26 15:46:07 +00:00
|
|
|
return NativeLibrary.Load(assemblyFile);
|
|
|
|
}
|
2020-07-31 12:19:21 +00:00
|
|
|
}
|
|
|
|
}
|