I am running C # binding tests for an unmanaged dll. how can I write tests that I make sure that the .dll is unloaded and loaded again for the next test so that no state in the dll code goes to the next test?
dll methods are imported with the DllImport attribute.
DECISION:
my dll does some initialization in a static constructor, so I have to call this initialization code after it unloads. so the code is as follows:
private static int SDllHandle;
private static bool SInitializationRequired;
[SetUp]
public static void Init()
{
SDllHandle = LoadLibrary("my.dll");
if (SInitializationRequired)
{
SInitializationRequired = false;
}
}
[DllImport("kernel32")]
static extern int LoadLibrary(string lpLibFileName);
[DllImport("kernel32")]
static extern bool FreeLibrary(int hModule);
[TearDown]
public static void End()
{
while(FreeLibrary(SDllHandle))
{
SInitializationRequired = true;
}
}
thalm source
share