obj.getinfoの実行テストを追加
このコミットが含まれているのは:
2ファイル変更
+101
-1
検索条件に一致するファイルはありません
@@ -77,6 +77,59 @@ namespace LuaScript.Tests
|
||||
Assert.Equal(1d, ctx.X);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInfoExposesEnvironmentInfo()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
ctx.ScriptPath = @"C:\plugins\LuaScript\";
|
||||
ctx.HostVersion = 44402d;
|
||||
ctx.IsSaving = true;
|
||||
ctx.Bpm = 128d;
|
||||
ctx.BpmBeat = 4;
|
||||
ctx.BpmOffset = 1.5d;
|
||||
|
||||
engine.Execute(
|
||||
"local mw, mh = obj.getinfo('image_max')\n" +
|
||||
"obj.x = mw\n" +
|
||||
"obj.y = mh\n" +
|
||||
"obj.z = obj.getinfo('saving') and 1 or 0\n" +
|
||||
"local tempo, beat, off = obj.getinfo('bpm')\n" +
|
||||
"obj.ox = tempo\n" +
|
||||
"obj.oy = beat\n" +
|
||||
"obj.oz = off\n" +
|
||||
"obj.alpha = obj.getinfo('version')", ctx);
|
||||
|
||||
Assert.Equal(200d, ctx.X);
|
||||
Assert.Equal(160d, ctx.Y);
|
||||
Assert.Equal(1d, ctx.Z);
|
||||
Assert.Equal(128d, ctx.Ox);
|
||||
Assert.Equal(4d, ctx.Oy);
|
||||
Assert.Equal(1.5d, ctx.Oz);
|
||||
Assert.Equal(44402d, ctx.Alpha);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInfoReportsPathFilterAndTimers()
|
||||
{
|
||||
using var engine = CreateEngine();
|
||||
var ctx = NewContext();
|
||||
ctx.ScriptPath = @"C:\plugins\LuaScript\";
|
||||
|
||||
engine.Execute(
|
||||
"obj.x = string.len(obj.getinfo('script_path'))\n" +
|
||||
"obj.y = obj.getinfo('filter') and 1 or 0\n" +
|
||||
"obj.z = obj.getinfo('clock') >= 0 and 1 or 0\n" +
|
||||
"obj.ox = obj.getinfo('script_time') >= 0 and 1 or 0\n" +
|
||||
"obj.oy = obj.getinfo('unknown') == nil and 1 or 0", ctx);
|
||||
|
||||
Assert.Equal(ctx.ScriptPath.Length, ctx.X);
|
||||
Assert.Equal(1d, ctx.Y);
|
||||
Assert.Equal(1d, ctx.Z);
|
||||
Assert.Equal(1d, ctx.Ox);
|
||||
Assert.Equal(1d, ctx.Oy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ObjectWritesFlowBackToContext()
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace LuaScript.Tests
|
||||
public class NativeWorkerRoundTripTests : IDisposable
|
||||
{
|
||||
private static string NativeDir => Path.Combine(AppContext.BaseDirectory, "native");
|
||||
private static readonly string ScriptPath = AppContext.BaseDirectory + Path.DirectorySeparatorChar;
|
||||
|
||||
private static readonly Func<string, int, SceneObjectInfo?> NoResolver = (_, _) => null;
|
||||
private static readonly Func<string, int, double, double, double, (byte[] buffer, int w, int h)> NoLoadFigure = (_, _, _, _, _) => ([], 1, 1);
|
||||
@@ -18,7 +19,7 @@ namespace LuaScript.Tests
|
||||
private static readonly Action<string, int, bool, int, double[]> NoSetAnchor = (_, _, _, _, _) => { };
|
||||
private static readonly System.Collections.Generic.IReadOnlyDictionary<string, string> NoStringParams = new System.Collections.Generic.Dictionary<string, string>();
|
||||
|
||||
private readonly LuaJitWorker _worker = new(NativeDir);
|
||||
private readonly LuaJitWorker _worker = new(NativeDir, ScriptPath);
|
||||
|
||||
private Func<string, SceneValue> _sceneGet = _ => SceneValue.Nil;
|
||||
private Action<string, SceneValue> _sceneSet = (_, _) => { };
|
||||
@@ -150,6 +151,52 @@ namespace LuaScript.Tests
|
||||
Assert.Equal(System.Text.Encoding.UTF8.GetByteCount("C:/サンプル/画像.png"), fields[NativeProtocol.Alpha]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInfo_ExposesEnvironmentInfo()
|
||||
{
|
||||
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
|
||||
|
||||
var fields = Fields(2, 2, 0d);
|
||||
fields[NativeProtocol.SceneWidth] = 1920d;
|
||||
fields[NativeProtocol.SceneHeight] = 1080d;
|
||||
fields[NativeProtocol.IsSaving] = 1d;
|
||||
fields[NativeProtocol.HostVersion] = 44402d;
|
||||
fields[NativeProtocol.Bpm] = 128d;
|
||||
fields[NativeProtocol.BpmBeat] = 4d;
|
||||
fields[NativeProtocol.BpmOffset] = 1.5d;
|
||||
var pixels = new byte[16];
|
||||
|
||||
const string script =
|
||||
"local mw, mh = obj.getinfo('image_max')\n" +
|
||||
"obj.x = mw\n" +
|
||||
"obj.y = mh\n" +
|
||||
"obj.z = obj.getinfo('saving') and 1 or 0\n" +
|
||||
"obj.ox = obj.getinfo('version')\n" +
|
||||
"local tempo, beat, off = obj.getinfo('bpm')\n" +
|
||||
"obj.oy = tempo\n" +
|
||||
"obj.oz = beat\n" +
|
||||
"obj.sx = off\n" +
|
||||
"obj.sy = string.len(obj.getinfo('script_path'))\n" +
|
||||
"obj.rx = obj.getinfo('filter') and 1 or 0\n" +
|
||||
"obj.ry = (obj.getinfo('clock') >= 0 and obj.getinfo('script_time') >= 0) and 1 or 0";
|
||||
|
||||
bool ok = RunWorker(
|
||||
script,
|
||||
fields, NoStringParams, () => pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor, out _, out _, out _, out _, out _, out string? error);
|
||||
|
||||
Assert.True(ok, error);
|
||||
Assert.Equal(1920d, fields[NativeProtocol.X]);
|
||||
Assert.Equal(1080d, fields[NativeProtocol.Y]);
|
||||
Assert.Equal(1d, fields[NativeProtocol.Z]);
|
||||
Assert.Equal(44402d, fields[NativeProtocol.Ox]);
|
||||
Assert.Equal(128d, fields[NativeProtocol.Oy]);
|
||||
Assert.Equal(4d, fields[NativeProtocol.Oz]);
|
||||
Assert.Equal(1.5d, fields[NativeProtocol.Sx]);
|
||||
Assert.Equal(System.Text.Encoding.UTF8.GetByteCount(ScriptPath), fields[NativeProtocol.Sy]);
|
||||
Assert.Equal(1d, fields[NativeProtocol.Rx]);
|
||||
Assert.Equal(1d, fields[NativeProtocol.Ry]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringParameters_GrowAndShrinkAroundCapacity()
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする