public bool Equals(IEngineObject other)
        {
            UnityEngineGameObjectAdapter otherGO = null;

            //can't is/as down cast interface.
            if (other.GetType() == typeof(UnityEngineGameObjectAdapter))
            {
                otherGO = Convert.ChangeType(other, typeof(UnityEngineGameObjectAdapter)) as UnityEngineGameObjectAdapter;
            }

            return(otherGO == null ? false : (otherGO.unityGameObjectAdaptee == unityGameObjectAdaptee));
        }
Exemple #2
0
        private bool SuperTreeContainsProperty(IEngineObject engineClassSuperType, EngineClass.Property property)
        {
            if (engineClassSuperType == null ||
                !(engineClassSuperType is EngineClass @class))
            {
                return(false);
            }

            foreach (EngineClass.Property other in @class.Properties)
            {
                if (other.Equals(property))
                {
                    return(true);
                }
            }

            return(SuperTreeContainsProperty(@class.SuperType, property));
        }
        public static void Test_ReferenceDictionary_Register()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            bool result = map.Register(testEngineObject, testObject);

            //assert
            Assert.IsTrue(result);
            Assert.IsTrue(map.ContainsKey(testEngineObject));
            Assert.AreEqual(testObject, map[testEngineObject]);

            //not in the dictionary so it should throw
            Assert.Throws <KeyNotFoundException>(() => { var o = map[Mock.Of <IEngineObject>()]; });
            Assert.IsFalse(map.ContainsKey(Mock.Of <IEngineObject>()));            //shouldn't contain some new key value. Might fail due to Moq setup.
        }
        public static void Test_ReferenceDictionary_TryLookup()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            map.Register(testEngineObject, testObject);

            //assert
            Assert.AreEqual(testObject, map.TryLookup(testEngineObject));
            Assert.AreNotEqual(testObject, map.TryLookup(Mock.Of <IEngineObject>()));
            Assert.IsNull(map.TryLookup(Mock.Of <IEngineObject>()));

            Assert.Throws <ArgumentNullException>(() => map.TryLookup(null));
            Assert.Throws <ArgumentNullException>(() => map.Register(null, testObject));
            Assert.Throws <ArgumentNullException>(() => map.Register(testEngineObject, null));
            Assert.Throws <ArgumentNullException>(() => map.Register(null, null));
        }
        public static void Test_ReferenceDictionary_Unregister()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            map.Register(testEngineObject, testObject);
            var result       = map.TryUnregister(testEngineObject);
            var failedResult = map.TryUnregister(testEngineObject);

            //assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Value, testObject);

            //check the intentional failed result
            Assert.IsFalse(failedResult.Success);
            Assert.IsNull(failedResult.Value);
        }
Exemple #6
0
        public static string GetReturnString(IEngineObject type, string variable)
        {
            StringBuilder result = new StringBuilder();

            if (type.ManagedType != "void")
            {
                result.Append("return ");
            }

            if (type is EngineEnum @enum)
            {
                result.Append($"({@enum.ManagedType}){variable}");
            }
            else if (type.NativeReturnType == "IntPtr" && type.ManagedType == "string")
            {
                result.Append($"StringMarshal.IntPtrToUtf8String({variable})");
            }
            else if (type.NativeReturnType == "IntPtr" && type.ManagedType != "IntPtr")
            {
                if (type.ManagedType == "SimObjectPtr*")
                {
                    result.Append($"(SimObjectPtr*){variable}");
                }
                else
                {
                    result.Append($"new {type.ManagedType}({variable})");
                }
            }
            else if (type is EngineStruct)
            {
                result.Append($"new {type.ManagedType}({variable})");
            }
            else
            {
                result.Append(variable);
            }

            return(result.ToString().Trim());
        }
Exemple #7
0
        public static void Test_Engine_Script_Component_Test_Equality()
        {
            //arrange
            Mock <EngineScriptComponent> engineScriptComponentMock = new Mock <EngineScriptComponent>(MockBehavior.Loose);
            Mock <EngineScriptComponent> engineScriptComponentSecondNonEqualMock = new Mock <EngineScriptComponent>(MockBehavior.Loose);

            engineScriptComponentMock.CallBase = true;
            engineScriptComponentSecondNonEqualMock.CallBase = true;

            EngineScriptComponent engineScriptComponent = engineScriptComponentMock.Object;
            EngineScriptComponent engineScriptComponentSecondNonEqual = engineScriptComponentSecondNonEqualMock.Object;

            //act (cast to interface for equal testing.
            IEngineObject engineObjectInterface         = engineScriptComponent;
            IEngineObject engineObjectInterfaceTwo      = engineScriptComponent;
            IEngineObject engineObjectInterfaceNotEqual = engineScriptComponentSecondNonEqual;

            //this tests equivalence. Not really Important because mostly you won't have references to the underlying script component and can't overload the equals.
            //assert
            Assert.AreEqual(engineScriptComponent, engineObjectInterface);
            Assert.IsTrue(engineScriptComponent == engineObjectInterface);
            Assert.IsTrue(engineObjectInterface == engineScriptComponent);
            Assert.IsTrue(engineObjectInterface.Equals(engineObjectInterfaceTwo));
            Assert.IsTrue(engineObjectInterface == engineObjectInterfaceTwo);

            Assert.IsTrue(engineScriptComponent.Equals(engineObjectInterface) == engineObjectInterface.Equals(engineScriptComponent));
            Assert.IsTrue(engineScriptComponent.Equals(engineObjectInterface));
            Assert.IsTrue(engineObjectInterface.Equals(engineScriptComponent));

            Assert.IsTrue(engineScriptComponentSecondNonEqual != engineScriptComponent);
            Assert.IsTrue(engineScriptComponent != engineScriptComponentSecondNonEqual);
            Assert.IsTrue(engineObjectInterface != engineObjectInterfaceNotEqual);

            Assert.IsTrue(engineScriptComponentSecondNonEqual != (IEngineObject)engineScriptComponent);
            Assert.IsTrue((IEngineObject)engineScriptComponentSecondNonEqual != engineScriptComponent);

            Assert.IsFalse(engineObjectInterface.Equals(engineScriptComponentSecondNonEqual));
            Assert.IsFalse(engineScriptComponent.Equals(engineScriptComponentSecondNonEqual));
        }
Exemple #8
0
        private bool SuperTreeContainsMethod(IEngineObject engineClassSuperType, EngineFunction method)
        {
            if (engineClassSuperType == null ||
                !(engineClassSuperType is EngineClass @class))
            {
                return(false);
            }

            foreach (EngineFunction other in @class.Methods)
            {
                if (!other.Name.Equals(method.Name) ||
                    other.Arguments.Count != method.Arguments.Count)
                {
                    continue;
                }

                bool alike = true;
                for (var index = 0; index < method.Arguments.Count; index++)
                {
                    EngineFunction.Argument argument      = method.Arguments[index];
                    EngineFunction.Argument otherArgument = other.Arguments[index];
                    if (argument.Type == otherArgument.Type)
                    {
                        continue;
                    }

                    alike = false;
                    break;
                }

                if (alike)
                {
                    return(true);
                }
            }

            return(SuperTreeContainsMethod(@class.SuperType, method));
        }
 public bool Equals(IEngineObject other)
 {
     return this == other;
 }
        public bool Equals(IEngineObject other)
        {
            UnityEngineGameObjectAdapter otherGO = null;

            //can't is/as down cast interface.
            if (other.GetType() == typeof(UnityEngineGameObjectAdapter))
                otherGO = Convert.ChangeType(other, typeof(UnityEngineGameObjectAdapter)) as UnityEngineGameObjectAdapter;

            return otherGO == null ? false : (otherGO.unityGameObjectAdaptee == unityGameObjectAdaptee);
        }
Exemple #11
0
 public bool Equals(IEngineObject other)
 {
     return(this == other);
 }
 public PlayerMover(IEngineObject enginePlayer, IEngineTime engineTime)
 {
     _enginePlayer = enginePlayer;
     _engineTime   = engineTime;
 }