mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
test: Add tests to see what happens
This commit is contained in:
parent
f6cf266e99
commit
80ec740b58
4 changed files with 89 additions and 7 deletions
76
Dalamud.Test/Compliance/PublicApiTests.cs
Normal file
76
Dalamud.Test/Compliance/PublicApiTests.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
||||
namespace Dalamud.Test.Compliance;
|
||||
|
||||
public class PublicApiTests
|
||||
{
|
||||
private readonly ITestOutputHelper testOutputHelper;
|
||||
public PublicApiTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
this.testOutputHelper = testOutputHelper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoClientStructsTypes()
|
||||
{
|
||||
var clientStructsAssembly = typeof(FFXIVClientStructs.ThisAssembly).Assembly;
|
||||
|
||||
var publicTypes = typeof(Dalamud).Assembly.GetTypes().Where(t => t.IsPublic);
|
||||
|
||||
foreach (var t in publicTypes)
|
||||
{
|
||||
if (t.GetCustomAttribute<ObsoleteAttribute>() != null) continue;
|
||||
|
||||
var methods = t.GetMethods().Where(m => m.IsPublic && !m.IsSpecialName);
|
||||
|
||||
foreach (var m in methods)
|
||||
{
|
||||
if (m.GetCustomAttribute<ObsoleteAttribute>() != null || m.GetCustomAttribute<Api14ToDoAttribute>() != null) continue;
|
||||
if (m.IsPrivate) continue;
|
||||
|
||||
if (m.ReturnType.Assembly == clientStructsAssembly)
|
||||
{
|
||||
Assert.Fail($"Method {t.FullName}.{m.Name} returns a type from FFXIVClientStructs: {m.ReturnType.FullName}");
|
||||
}
|
||||
|
||||
foreach (var param in m.GetParameters())
|
||||
{
|
||||
if (param.ParameterType.Assembly == clientStructsAssembly)
|
||||
{
|
||||
Assert.Fail($"Method {t.FullName}.{m.Name} has a parameter from FFXIVClientStructs: {param.ParameterType.FullName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var p in t.GetProperties())
|
||||
{
|
||||
if (p.GetCustomAttribute<ObsoleteAttribute>() != null || p.GetCustomAttribute<Api14ToDoAttribute>() != null) continue;
|
||||
if (p.GetMethod?.IsPrivate == true && p.SetMethod?.IsPrivate == true) continue;
|
||||
|
||||
if (p.PropertyType.Assembly == clientStructsAssembly)
|
||||
{
|
||||
Assert.Fail($"Property {t.FullName}.{p.Name} is a type from FFXIVClientStructs: {p.PropertyType.FullName}");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var field in t.GetFields())
|
||||
{
|
||||
if (field.GetCustomAttribute<ObsoleteAttribute>() != null || field.GetCustomAttribute<Api14ToDoAttribute>() != null) continue;
|
||||
if (field.IsPrivate) continue;
|
||||
|
||||
if (field.FieldType.Assembly == clientStructsAssembly)
|
||||
{
|
||||
Assert.Fail($"Field {t.FullName}.{field.Name} is of a type from FFXIVClientStructs: {field.FieldType.FullName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,14 +43,14 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
|
||||
<PackageReference Include="xunit.assert" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.4.1">
|
||||
<PackageReference Include="xunit.analyzers" Version="1.0.0" />
|
||||
<PackageReference Include="xunit.assert" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.4.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
|||
|
|
@ -382,6 +382,8 @@ public static unsafe class MemoryHelper
|
|||
/// <param name="utf8String">The memory address to read from.</param>
|
||||
/// <returns>The read in string.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Obsolete("CS types in Dalamud are deprecated.")]
|
||||
[Api14ToDo(Api14ToDoAttribute.Remove)]
|
||||
public static SeString ReadSeString(Utf8String* utf8String) =>
|
||||
utf8String == null ? string.Empty : SeString.Parse(utf8String->AsSpan());
|
||||
|
||||
|
|
@ -613,6 +615,8 @@ public static unsafe class MemoryHelper
|
|||
/// <param name="utf8String">The memory address to read from.</param>
|
||||
/// <param name="value">The read in string.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[Obsolete("CS types in Dalamud are deprecated.")]
|
||||
[Api14ToDo(Api14ToDoAttribute.Remove)]
|
||||
public static unsafe void ReadSeString(Utf8String* utf8String, out SeString value)
|
||||
=> value = ReadSeString(utf8String);
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ public static class VectorExtensions
|
|||
return new Vector2(v.X, y);
|
||||
}
|
||||
|
||||
[Obsolete("CS type is deprecated. Use ByteColor instead.")]
|
||||
[Api14ToDo(Api14ToDoAttribute.Remove)]
|
||||
public static ByteColor ToByteColor(this Vector4 v)
|
||||
{
|
||||
return new ByteColor { A = (byte)(v.W * 255), R = (byte)(v.X * 255), G = (byte)(v.Y * 255), B = (byte)(v.Z * 255) };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue