diff --git a/src/MaaFramework.Binding.Native/MaaResource.cs b/src/MaaFramework.Binding.Native/MaaResource.cs index 258681a..5b467b4 100644 --- a/src/MaaFramework.Binding.Native/MaaResource.cs +++ b/src/MaaFramework.Binding.Native/MaaResource.cs @@ -217,17 +217,16 @@ public MaaJobStatus Wait(MaaJob job) public bool SetOption(ResourceOption opt, T value) { ArgumentNullException.ThrowIfNull(value); - throw new InvalidOperationException(); - /* - byte[] optValue = (value, opt) switch + var optValue = (value, opt) switch { - (int vvvv, ResourceOption.Invalid) => vvvv.ToMaaOptionValues(), + (int vvvv, ResourceOption.InferenceDevice) => MaaMarshaller.ConvertToMaaOptionValue(vvvv), + (InferenceDevice v, ResourceOption.InferenceDevice) => MaaMarshaller.ConvertToMaaOptionValue((int)v), + _ => throw new InvalidOperationException(), }; return MaaResourceSetOption(Handle, (MaaResOption)opt, optValue, (MaaOptionValueSize)optValue.Length); - */ } /// diff --git a/src/MaaFramework.Binding.UnitTests/Test_IMaaResource.cs b/src/MaaFramework.Binding.UnitTests/Test_IMaaResource.cs index 17173b9..7839621 100644 --- a/src/MaaFramework.Binding.UnitTests/Test_IMaaResource.cs +++ b/src/MaaFramework.Binding.UnitTests/Test_IMaaResource.cs @@ -27,6 +27,7 @@ public static void InitializeClass(TestContext context) { Assert.IsFalse(data.IsInvalid); data.Callback += Common.Callback; + data.SetOption(ResourceOption.InferenceDevice, InferenceDevice.CPU); } } @@ -99,6 +100,16 @@ public void Interface_Hash_TaskList(MaaTypes type, IMaaResource maaResource) maaResource.TaskList.Any(s => s == "EmptyTask")); } + [TestMethod] + [MaaData(MaaTypes.All, nameof(Data), ResourceOption.InferenceDevice, InferenceDevice.CPU)] + public void Interface_SetOption(MaaTypes type, IMaaResource maaResource, ResourceOption opt, object arg) + { + Assert.IsNotNull(maaResource); + + Assert.IsTrue( + maaResource.SetOption(opt, arg)); + } + #region Invalid data tests [TestMethod] diff --git a/src/MaaFramework.Binding.UnitTests/Test_IMaaTasker.cs b/src/MaaFramework.Binding.UnitTests/Test_IMaaTasker.cs index 678892b..7d1cb8c 100644 --- a/src/MaaFramework.Binding.UnitTests/Test_IMaaTasker.cs +++ b/src/MaaFramework.Binding.UnitTests/Test_IMaaTasker.cs @@ -41,6 +41,8 @@ public static void InitializeClass(TestContext context) .AppendPath(Common.ResourcePath) .Wait() .ThrowIfNot(MaaJobStatus.Succeeded); + data.Resource + .SetOption(ResourceOption.InferenceDevice, InferenceDevice.CPU); data.Controller .LinkStart() .Wait()