Fixes some potential memory leaks in unit tests, cleanup
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-09-23 20:18:52 +02:00
parent 2b6b3a40ed
commit 4588b2da10
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
7 changed files with 29 additions and 20 deletions

View File

@ -7,6 +7,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<WarningLevel>6</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>;NU1605;CA2000</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<None Update="libpkmn_lib.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -49,8 +49,8 @@ namespace PkmnLibSharp.Utils
return _ptr;
}
}
internal IntPtr TakeOwnership()
private IntPtr TakeOwnership()
{
if (!_isOwner)
{
@ -67,17 +67,12 @@ namespace PkmnLibSharp.Utils
return ptr;
}
internal void Invalidate()
private void Invalidate()
{
_isInvalidated = true;
CacheHandler.RemoveCache(_ptr);
}
~ExternPointer()
{
Dispose();
}
public void Dispose()
{
if (_isDisposed)

View File

@ -7,6 +7,12 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE</DefineConstants>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>;NU1605;CA2000</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />

View File

@ -9,9 +9,10 @@ namespace PkmnLibRSharpTests.StaticData
[Test]
public void BasicTests()
{
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) },
new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0), new[] { "foo", "bar" }, new[] { "set" },
new LearnableMoves(), Array.Empty<string>());
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
using var moves = new LearnableMoves();
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
Assert.AreEqual("foobar", form.Name);
Assert.AreEqual(0.2f, form.Height, 0.00001f);
Assert.AreEqual(5.8f, form.Weight, 0.00001f);
@ -22,7 +23,6 @@ namespace PkmnLibRSharpTests.StaticData
Assert.AreEqual("foo", form.Abilities[0]);
Assert.AreEqual("bar", form.Abilities[1]);
Assert.AreEqual("set", form.HiddenAbilities[0]);
}
}
}

View File

@ -13,15 +13,16 @@ namespace PkmnLibRSharpTests.StaticData.Libraries
using var lib = new SpeciesLibrary(0);
Assert.AreEqual(0, lib.Length);
}
[Test]
public void CreateAndAdd()
{
using var lib = new SpeciesLibrary(0);
Assert.AreEqual(0, lib.Length);
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) },
new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0), new[] { "foo", "bar" }, new[] { "set" },
new LearnableMoves(), Array.Empty<string>());
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
using var moves = new LearnableMoves();
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
using var species = new Species(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
lib.Add("foobar", species);
Assert.AreEqual(1, lib.Length);

View File

@ -11,7 +11,7 @@ namespace PkmnLibRSharpTests.StaticData
[Values] Statistic decreasedStat
)
{
var nature = new Nature(increasedStat, decreasedStat);
using var nature = new Nature(increasedStat, decreasedStat);
Assert.AreEqual(increasedStat, nature.IncreasedStat);
Assert.AreEqual(decreasedStat, nature.DecreasedStat);
if (increasedStat == decreasedStat)

View File

@ -9,9 +9,10 @@ namespace PkmnLibRSharpTests.StaticData
[Test]
public void BasicTests()
{
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) },
new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0), new[] { "foo", "bar" }, new[] { "set" },
new LearnableMoves(), Array.Empty<string>());
using var stats = new StaticStatisticSet<short>(5, 10, 30, 20, 2, 0);
using var moves = new LearnableMoves();
using var form = new Form("foobar", 0.2f, 5.8f, 300, new TypeIdentifier[] { new(1), new(2) }, stats,
new[] { "foo", "bar" }, new[] { "set" }, moves, Array.Empty<string>());
using var species = new Species(10, "testSpecies", 0.2f, "growth", 120, form, Array.Empty<string>());
Assert.AreEqual(10, species.Id);
Assert.AreEqual("testSpecies", species.Name);