feat: add self test

This commit is contained in:
goat 2021-08-10 23:33:37 +02:00
parent 409ce984da
commit a8e00f91e7
No known key found for this signature in database
GPG key ID: F18F057873895461
18 changed files with 1004 additions and 0 deletions

View file

@ -0,0 +1,45 @@
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the Actor Table.
/// </summary>
internal class ActorTableAgingStep : IAgingStep
{
private int index = 0;
/// <inheritdoc/>
public string Name => "Test ActorTable";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Checking actor table...");
if (this.index == dalamud.ClientState.Actors.Length - 1)
{
return SelfTestStepResult.Pass;
}
var actor = dalamud.ClientState.Actors[this.index];
this.index++;
if (actor == null)
{
return SelfTestStepResult.Waiting;
}
Util.ShowObject(actor);
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,68 @@
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for Chat.
/// </summary>
internal class ChatAgingStep : IAgingStep
{
private int step = 0;
private bool subscribed = false;
private bool hasPassed = false;
/// <inheritdoc/>
public string Name => "Test Chat";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
switch (this.step)
{
case 0:
dalamud.Framework.Gui.Chat.Print("Testing!");
this.step++;
break;
case 1:
ImGui.Text("Type \"/e DALAMUD\" in chat...");
if (!this.subscribed)
{
this.subscribed = true;
dalamud.Framework.Gui.Chat.OnChatMessage += this.ChatOnOnChatMessage;
}
if (this.hasPassed)
{
dalamud.Framework.Gui.Chat.OnChatMessage -= this.ChatOnOnChatMessage;
this.subscribed = false;
return SelfTestStepResult.Pass;
}
break;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
dalamud.Framework.Gui.Chat.OnChatMessage -= this.ChatOnOnChatMessage;
this.subscribed = false;
}
private void ChatOnOnChatMessage(
XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool ishandled)
{
if (type == XivChatType.Echo && message.TextValue == "DALAMUD")
{
this.hasPassed = true;
}
}
}
}

View file

@ -0,0 +1,35 @@
using Dalamud.Game.ClientState.Conditions;
using ImGuiNET;
using Serilog;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for Condition.
/// </summary>
internal class ConditionAgingStep : IAgingStep
{
/// <inheritdoc/>
public string Name => "Test Condition";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
if (!dalamud.ClientState.Condition.Any())
{
Log.Error("No condition flags present.");
return SelfTestStepResult.Fail;
}
ImGui.Text("Please jump...");
return dalamud.ClientState.Condition[ConditionFlag.Jumping] ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,65 @@
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for Territory Change.
/// </summary>
internal class EnterTerritoryAgingStep : IAgingStep
{
private readonly ushort territory;
private readonly string terriName;
private bool subscribed = false;
private bool hasPassed = false;
/// <summary>
/// Initializes a new instance of the <see cref="EnterTerritoryAgingStep"/> class.
/// </summary>
/// <param name="terri">The territory to check for.</param>
/// <param name="name">Name to show.</param>
public EnterTerritoryAgingStep(ushort terri, string name)
{
this.terriName = name;
this.territory = terri;
}
/// <inheritdoc/>
public string Name => $"Enter Terri: {this.terriName}";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.TextUnformatted(this.Name);
if (!this.subscribed)
{
dalamud.ClientState.TerritoryChanged += this.ClientStateOnTerritoryChanged;
this.subscribed = true;
}
if (this.hasPassed)
{
dalamud.ClientState.TerritoryChanged -= this.ClientStateOnTerritoryChanged;
this.subscribed = false;
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
dalamud.ClientState.TerritoryChanged -= this.ClientStateOnTerritoryChanged;
this.subscribed = false;
}
private void ClientStateOnTerritoryChanged(object sender, ushort e)
{
if (e == this.territory)
{
this.hasPassed = true;
}
}
}
}

View file

@ -0,0 +1,45 @@
using Dalamud.Utility;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the Fate Table.
/// </summary>
internal class FateTableAgingStep : IAgingStep
{
private int index = 0;
/// <inheritdoc/>
public string Name => "Test FateTable";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Checking fate table...");
if (this.index == dalamud.ClientState.Fates.Length - 1)
{
return SelfTestStepResult.Pass;
}
var actor = dalamud.ClientState.Fates[this.index];
this.index++;
if (actor == null)
{
return SelfTestStepResult.Waiting;
}
Util.ShowObject(actor);
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,35 @@
using Dalamud.Game.ClientState.GamePad;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the Gamepad State.
/// </summary>
internal class GamepadStateAgingStep : IAgingStep
{
/// <inheritdoc/>
public string Name => "Test GamePadState";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Hold down North, East, L1");
if (dalamud.ClientState.GamepadState.Pressed(GamepadButtons.North) == 1
&& dalamud.ClientState.GamepadState.Pressed(GamepadButtons.East) == 1
&& dalamud.ClientState.GamepadState.Pressed(GamepadButtons.L1) == 1)
{
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,58 @@
using Dalamud.Game.Gui;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the Hover events.
/// </summary>
internal class HoverAgingStep : IAgingStep
{
private bool clearedItem = false;
private bool clearedAction = false;
/// <inheritdoc/>
public string Name => "Test Hover";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
var hoverItem = dalamud.Framework.Gui.HoveredItem;
var hoverAction = dalamud.Framework.Gui.HoveredAction;
if (!this.clearedItem)
{
ImGui.Text("Hover WHM soul crystal...");
if (hoverItem == 4547)
{
this.clearedItem = true;
}
}
if (!this.clearedAction)
{
ImGui.Text("Hover \"Open Linkshells\" action...");
if (hoverAction != null && hoverAction.ActionKind == HoverActionKind.MainCommand &&
hoverAction.ActionID == 28)
{
this.clearedAction = true;
}
}
if (this.clearedItem && this.clearedAction)
{
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,26 @@
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Interface for test implementations.
/// </summary>
internal interface IAgingStep
{
/// <summary>
/// Gets the name of the test.
/// </summary>
public string Name { get; }
/// <summary>
/// Run the test step, once per frame it is active.
/// </summary>
/// <param name="dalamud">Dalamud instance to act on.</param>
/// <returns>The result of this frame, test is discarded once a result other than <see cref="SelfTestStepResult.Waiting"/> is returned.</returns>
public SelfTestStepResult RunStep(Dalamud dalamud);
/// <summary>
/// Clean up this test.
/// </summary>
/// <param name="dalamud">Dalamud instance to act on.</param>
public void CleanUp(Dalamud dalamud);
}
}

View file

@ -0,0 +1,37 @@
using Dalamud.Game.ClientState.Keys;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the Key State.
/// </summary>
internal class KeyStateAgingStep : IAgingStep
{
/// <inheritdoc/>
public string Name => "Test KeyState";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Hold down D,A,L,M,U");
if (dalamud.ClientState.KeyState[VirtualKey.D]
&& dalamud.ClientState.KeyState[VirtualKey.A]
&& dalamud.ClientState.KeyState[VirtualKey.L]
&& dalamud.ClientState.KeyState[VirtualKey.M]
&& dalamud.ClientState.KeyState[VirtualKey.U])
{
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,54 @@
using System;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for the login events.
/// </summary>
internal class LoginEventAgingStep : IAgingStep
{
private bool isSubscribed = false;
private bool hasPassed = false;
/// <inheritdoc/>
public string Name => "Test Log-In";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
ImGui.Text("Log in now...");
if (!this.isSubscribed)
{
dalamud.ClientState.OnLogin += this.ClientStateOnOnLogin;
this.isSubscribed = true;
}
if (this.hasPassed)
{
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
this.isSubscribed = false;
return SelfTestStepResult.Pass;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
if (this.isSubscribed)
{
dalamud.ClientState.OnLogin -= this.ClientStateOnOnLogin;
this.isSubscribed = false;
}
}
private void ClientStateOnOnLogin(object sender, EventArgs e)
{
this.hasPassed = true;
}
}
}

View file

@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Linq;
using Dalamud.Utility;
using Lumina.Excel;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for Lumina.
/// </summary>
/// <typeparam name="T">ExcelRow to run test on.</typeparam>
internal class LuminaAgingStep<T> : IAgingStep
where T : ExcelRow
{
private int step = 0;
private List<T> rows;
/// <inheritdoc/>
public string Name => "Test Lumina";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
this.rows ??= dalamud.Data.GetExcelSheet<T>().ToList();
Util.ShowObject(this.rows[this.step]);
this.step++;
return this.step >= this.rows.Count ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,53 @@
using Dalamud.Game.Gui.PartyFinder.Types;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for Party Finder events.
/// </summary>
internal class PartyFinderAgingStep : IAgingStep
{
private bool subscribed = false;
private bool hasPassed = false;
/// <inheritdoc/>
public string Name => "Test Party Finder";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
if (!this.subscribed)
{
dalamud.Framework.Gui.PartyFinder.ReceiveListing += this.PartyFinderOnReceiveListing;
this.subscribed = true;
}
if (this.hasPassed)
{
dalamud.Framework.Gui.PartyFinder.ReceiveListing -= this.PartyFinderOnReceiveListing;
this.subscribed = false;
return SelfTestStepResult.Pass;
}
ImGui.Text("Open Party Finder");
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
if (this.subscribed)
{
dalamud.Framework.Gui.PartyFinder.ReceiveListing -= this.PartyFinderOnReceiveListing;
this.subscribed = false;
}
}
private void PartyFinderOnReceiveListing(PartyFinderListing listing, PartyFinderListingEventArgs args)
{
this.hasPassed = true;
}
}
}

View file

@ -0,0 +1,73 @@
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for targets.
/// </summary>
internal class TargetAgingStep : IAgingStep
{
private int step = 0;
/// <inheritdoc/>
public string Name => "Test Target";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
switch (this.step)
{
case 0:
dalamud.ClientState.Targets.ClearCurrentTarget();
dalamud.ClientState.Targets.ClearFocusTarget();
this.step++;
break;
case 1:
ImGui.Text("Target a player...");
var cTarget = dalamud.ClientState.Targets.CurrentTarget;
if (cTarget is PlayerCharacter)
{
this.step++;
}
break;
case 2:
ImGui.Text("Focus-Target a Battle NPC...");
var fTarget = dalamud.ClientState.Targets.FocusTarget;
if (fTarget is BattleNpc)
{
this.step++;
}
break;
case 3:
ImGui.Text("Soft-Target an EventObj...");
var sTarget = dalamud.ClientState.Targets.FocusTarget;
if (sTarget is EventObj)
{
return SelfTestStepResult.Pass;
}
break;
}
return SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,26 @@
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test setup for toasts.
/// </summary>
internal class ToastAgingStep : IAgingStep
{
/// <inheritdoc/>
public string Name => "Test Toasts";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
dalamud.Framework.Gui.Toast.ShowNormal("Normal Toast");
dalamud.Framework.Gui.Toast.ShowError("Error Toast");
return SelfTestStepResult.Pass;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
// ignored
}
}
}

View file

@ -0,0 +1,38 @@
namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
{
/// <summary>
/// Test that waits N frames.
/// </summary>
internal class WaitFramesAgingStep : IAgingStep
{
private readonly int frames;
private int cFrames;
/// <summary>
/// Initializes a new instance of the <see cref="WaitFramesAgingStep"/> class.
/// </summary>
/// <param name="frames">Amount of frames to wait.</param>
public WaitFramesAgingStep(int frames)
{
this.frames = frames;
this.cFrames = frames;
}
/// <inheritdoc/>
public string Name => $"Wait {this.cFrames} frames";
/// <inheritdoc/>
public SelfTestStepResult RunStep(Dalamud dalamud)
{
this.cFrames--;
return this.cFrames <= 0 ? SelfTestStepResult.Pass : SelfTestStepResult.Waiting;
}
/// <inheritdoc/>
public void CleanUp(Dalamud dalamud)
{
this.cFrames = this.frames;
}
}
}