Skip to content

Commit

Permalink
New Engine Structure Tests (#776)
Browse files Browse the repository at this point in the history
* Implement generic ItemProperty test.

* Implement ItemProperty tests.

* Seal classes.

* Add event test.

* Add basic tests for other engine types.

* Fix ItemProperty.OnMonsterHitProperties method.

* Cleanup.

* Correct test parameters.

* Set cost table value to -1.
  • Loading branch information
jhett12321 authored Sep 13, 2024
1 parent 6be0db7 commit beddf0c
Show file tree
Hide file tree
Showing 7 changed files with 794 additions and 1 deletion.
19 changes: 19 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/EventTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NUnit.Framework;
using NWN.Core;
using Event = Anvil.API.Event;

namespace Anvil.Tests.API
{
[TestFixture(Category = "API.EngineStructure")]
public sealed class EventTests
{
[Test(Description = "Creating an event and disposing the event explicitly frees the associated memory.")]
public void CreateAndDisposeEventFreesNativeStructure()
{
Event nwEvent = NWScript.EventUserDefined(0xDEAD)!;
Assert.That(nwEvent.IsValid, Is.True, "Event was not valid after creation.");
nwEvent.Dispose();
Assert.That(nwEvent.IsValid, Is.False, "Event was still valid after disposing.");
}
}
}
697 changes: 697 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/ItemPropertyTests.cs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/JsonTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Anvil.API;
using NUnit.Framework;

namespace Anvil.Tests.API
{
[TestFixture(Category = "API.EngineStructure")]
public sealed class JsonTests
{
[Test(Description = "Creating a json structure and disposing it explicitly frees the associated memory.")]
public void CreateAndDisposeJsonFreesNativeStructure()
{
int[] test = { 1, 2 };
Json json = JsonUtility.ToJsonStructure(test);

Assert.That(json.IsValid, Is.True, "Json struct was not valid after creation.");
json.Dispose();
Assert.That(json.IsValid, Is.False, "Json struct was still valid after disposing.");
}
}
}
18 changes: 18 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/LocationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Anvil.API;
using NUnit.Framework;

namespace Anvil.Tests.API
{
[TestFixture(Category = "API.EngineStructure")]
public class LocationTests
{
[Test(Description = "Creating a location and disposing the location explicitly frees the associated memory.")]
public void CreateAndDisposeLocationFreesNativeStructure()
{
Location location = NwModule.Instance.StartingLocation;
Assert.That(location.IsValid, Is.True, "Location was not valid after creation.");
location.Dispose();
Assert.That(location.IsValid, Is.False, "Location was still valid after disposing.");
}
}
}
18 changes: 18 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/SQLQueryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Anvil.API;
using NUnit.Framework;

namespace Anvil.Tests.API
{
[TestFixture(Category = "API.EngineStructure")]
public class SQLQueryTests
{
[Test(Description = "Creating a SQL query and disposing the query explicitly frees the associated memory.")]
public void CreateAndDisposeSQLQueryFreesNativeStructure()
{
SQLQuery query = NwModule.Instance.PrepareSQLQuery("SELECT * FROM 'test'");
Assert.That(query.IsValid, Is.True, "SQL query was not valid after creation.");
query.Dispose();
Assert.That(query.IsValid, Is.False, "SQL query was still valid after disposing.");
}
}
}
18 changes: 18 additions & 0 deletions NWN.Anvil.Tests/src/main/API/EngineStructures/TalentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Anvil.API;
using NUnit.Framework;

namespace Anvil.Tests.API
{
[TestFixture(Category = "API.EngineStructure")]
public class TalentTests
{
[Test(Description = "Creating a talent and disposing the talent explicitly frees the associated memory.")]
public void CreateAndDisposeTalentFreesNativeStructure()
{
Talent talent = NwSkill.FromSkillType(Skill.Intimidate)!.ToTalent();
Assert.That(talent.IsValid, Is.True, "Talent was not valid after creation.");
talent.Dispose();
Assert.That(talent.IsValid, Is.False, "Talent was still valid after disposing.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ public static ItemProperty OnHitEffect(IPOnHitSaveDC saveDC, HitEffect effect)

public static ItemProperty OnMonsterHitProperties(MonsterHitEffect effect)
{
return NWScript.ItemPropertyOnMonsterHitProperties(effect.Property, effect.Special)!;
ItemProperty property = NWScript.ItemPropertyCustom((int)ItemPropertyType.OnMonsterHit, effect.Property, -1, effect.Special)!;
property.IntParams[2] = -1;

return property;
}

public static ItemProperty Quality(IPQuality quality)
Expand Down

0 comments on commit beddf0c

Please sign in to comment.