Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Miscellaneous cleanup to the NativeLibrary tests #27753

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions tests/src/Interop/NativeLibrary/NativeLibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,32 @@ static TestResult Run (Func<TestResult> test)
{
result = test();
}
catch (ArgumentNullException e)
catch (ArgumentNullException)
{
return TestResult.ArgumentNull;
return TestResult.ArgumentNull;
}
catch (ArgumentException e)
catch (ArgumentException)
{
return TestResult.ArgumentBad;
}
catch (DllNotFoundException e)
catch (DllNotFoundException)
{
return TestResult.DllNotFound;
}
catch (BadImageFormatException e)
catch (BadImageFormatException)
{
return TestResult.BadImage;
}
catch (InvalidOperationException e)
catch (InvalidOperationException)
{
return TestResult.InvalidOperation;
}
catch (EntryPointNotFoundException e)
catch (EntryPointNotFoundException)
{
return TestResult.EntryPointNotFound;
}
catch (Exception e)
catch (Exception)
{
//Console.WriteLine(e.ToString());
return TestResult.GenericException;
}

Expand All @@ -283,7 +282,7 @@ static TestResult LoadLibrarySimple(string libPath)
TestResult result = Run(() => {
handle = NativeLibrary.Load(libPath);
if (handle == IntPtr.Zero)
return TestResult.ReturnNull;
return TestResult.ReturnNull;
return TestResult.Success;
});

Expand All @@ -300,10 +299,10 @@ static TestResult TryLoadLibrarySimple(string libPath)

TestResult result = Run(() => {
bool success = NativeLibrary.TryLoad(libPath, out handle);
if(!success)
if (!success)
return TestResult.ReturnFailure;
if (handle == null)
return TestResult.ReturnNull;
if (handle == IntPtr.Zero)
return TestResult.ReturnNull;
return TestResult.Success;
});

Expand All @@ -322,7 +321,7 @@ static TestResult LoadLibraryAdvanced(string libName, Assembly assembly, DllImpo
TestResult result = Run(() => {
handle = NativeLibrary.Load(libName, assembly, searchPath);
if (handle == IntPtr.Zero)
return TestResult.ReturnNull;
return TestResult.ReturnNull;
return TestResult.Success;
});

Expand All @@ -340,9 +339,9 @@ static TestResult TryLoadLibraryAdvanced(string libName, Assembly assembly, DllI
TestResult result = Run(() => {
bool success = NativeLibrary.TryLoad(libName, assembly, searchPath, out handle);
if (!success)
return TestResult.ReturnFailure;
return TestResult.ReturnFailure;
if (handle == IntPtr.Zero)
return TestResult.ReturnNull;
return TestResult.ReturnNull;
return TestResult.Success;
});

Expand All @@ -367,8 +366,8 @@ static TestResult GetLibraryExport(IntPtr handle, string name)

return Run(() => {
IntPtr address = NativeLibrary.GetExport(handle, name);
if (address == null)
return TestResult.ReturnNull;
if (address == IntPtr.Zero)
return TestResult.ReturnNull;
if (RunExportedFunction(address, 1, 1) != 2)
return TestResult.IncorrectEvaluation;
return TestResult.Success;
Expand All @@ -383,9 +382,9 @@ static TestResult TryGetLibraryExport(IntPtr handle, string name)
IntPtr address = IntPtr.Zero;
bool success = NativeLibrary.TryGetExport(handle, name, out address);
if (!success)
return TestResult.ReturnFailure;
if (address == null)
return TestResult.ReturnNull;
return TestResult.ReturnFailure;
if (address == IntPtr.Zero)
return TestResult.ReturnNull;
if (RunExportedFunction(address, 1, 1) != 2)
return TestResult.IncorrectEvaluation;
return TestResult.Success;
Expand Down