/
TestSetup.cs
64 lines (53 loc) · 2.14 KB
/
TestSetup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PEBakery.Core;
using PEBakery.Tests.Core;
namespace PEBakery.Tests
{
[TestClass]
public class TestSetup
{
#region AssemblyInitalize, AssemblyCleanup
[AssemblyInitialize]
public static void PrepareTests(TestContext ctx)
{
EngineTests.BaseDir = Path.GetFullPath(Path.Combine("..", "..", "Samples"));
ProjectCollection projects = new ProjectCollection(EngineTests.BaseDir, null);
projects.PrepareLoad(out _);
projects.Load(null);
// Should be only one project named TestSuite
EngineTests.Project = projects.ProjectList[0];
// Init NativeAssembly
NativeGlobalInit();
// Use InMemory Database for Tests
Logger.DebugLevel = DebugLevel.PrintExceptionStackTrace;
EngineTests.Logger = new Logger(":memory:");
EngineTests.Logger.SystemWrite(new LogInfo(LogState.Info, "PEBakery.Tests launched"));
App.Logger = EngineTests.Logger;
App.BaseDir = EngineTests.BaseDir;
CodeParser.OptimizeCode = true;
}
private static void NativeGlobalInit()
{
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
string arch = IntPtr.Size == 8 ? "x64" : "x86";
string zLibDllPath = Path.Combine(baseDir, arch, "zlibwapi.dll");
string wimLibDllPath = Path.Combine(baseDir, arch, "libwim-15.dll");
string xzDllPath = Path.Combine(baseDir, arch, "liblzma.dll");
Joveler.ZLibWrapper.ZLibInit.GlobalInit(zLibDllPath, 64 * 1024);
ManagedWimLib.Wim.GlobalInit(wimLibDllPath);
PEBakery.XZLib.XZStream.GlobalInit(xzDllPath, 64 * 1024);
}
[AssemblyCleanup]
public static void AssemblyCleanup()
{
EngineTests.Logger?.Dispose();
Joveler.ZLibWrapper.ZLibInit.GlobalCleanup();
ManagedWimLib.Wim.GlobalCleanup();
PEBakery.XZLib.XZStream.GlobalCleanup();
}
#endregion
}
}