65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
|
//
|
|
// This file is part of Mocha.NET.
|
|
//
|
|
// Mocha.NET is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Mocha.NET is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
using Mocha.Core.Oop;
|
|
using Mocha.Core.Oop.Methods;
|
|
|
|
namespace Mocha.Core.Tests.MethodTests;
|
|
|
|
public class CommonTests : MethodTestsBase
|
|
{
|
|
|
|
[Test]
|
|
public void NonStaticMethodInStaticContext()
|
|
{
|
|
InstanceHandle irTestClass = Oms.GetInstance(TEST_CLASS_GUID);
|
|
Assert.That(irTestClass, Is.Not.EqualTo(InstanceHandle.Empty));
|
|
|
|
// create a Work Set to hold our data
|
|
WorkSet ws = Oms.CreateWorkSet("Test Work Set");
|
|
|
|
OmsMethodBuilder methodBuilder = new OmsMethodBuilder(Oms);
|
|
|
|
GetSpecifiedInstancesMethod dummyMethod = methodBuilder.CreateGetSpecifiedInstancesMethod(irTestClass, "get", "Empty Set", null, false, ws, new InstanceHandle[0]);
|
|
ReturnInstanceSetMethodBinding dummyMethodRsmb = methodBuilder.CreateReturnInstanceSetMethodBinding(dummyMethod);
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
|
|
Assert.That(delegate ()
|
|
{
|
|
IEnumerable<InstanceHandle> specifiedInstances = Oms.ExecuteStaticMethodReturningInstanceSet(context, dummyMethodRsmb);
|
|
}, Throws.InvalidOperationException);
|
|
}
|
|
|
|
[Test]
|
|
public void RuntimeVersionMatches()
|
|
{
|
|
InstanceHandle c_OMS = Oms.GetInstance(KnownInstanceGuids.Classes.OMS);
|
|
|
|
//*** Wow, this actually works!!! ***//
|
|
// ... but I wonder how long it would actually take to sift through 1000s of methods...
|
|
Method m = Oms.GetMethod(c_OMS, "get", "Runtime Version");
|
|
Assert.That(m, Is.Not.Null, "OMS does not define method `OMS@get Runtime Version (GAS)*P`");
|
|
|
|
OmsContext context = Oms.CreateContext();
|
|
InstanceHandle workData = Oms.Execute(context, m);
|
|
object? value = context.GetWorkData(workData);
|
|
|
|
Assert.That(value is string);
|
|
Assert.That((string?)value, Is.EqualTo(Oms.RuntimeVersion.ToString()));
|
|
}
|
|
} |