コード例 #1
0
 private static string CompatTestExtensionValid(this DetourTestSources self, int param1, string param2)
 {
     return(null);
 }
コード例 #2
0
 public static void Overload(this DetourTestSources self, float asd, float qwe)
 {
     DetourTests.Logger.Message("overload float");
 }
コード例 #3
0
        public override void Initialize()
        {
            base.Initialize();
            // instance tests
            Logger.Message("Running tests...");
            Type sourceType           = typeof(DetourTestSources);
            DetourTestSources sources = new DetourTestSources();

            sources.PublicInstanceMethod();
            sourceType.GetMethod("PrivateInstanceMethod", Helpers.AllBindingFlags).Invoke(sources, null);

            // static tests
            DetourTestSources.PublicStaticMethod();
            sourceType.GetMethod("PrivateStaticMethod", Helpers.AllBindingFlags).Invoke(null, null);

            // overloads
            sources.Overload(1, 1);
            sources.Overload("asd", "qwe");
            sources.Overload(1.1f, 1.1f);

            // properties
            var x = sources.GetterOnly;

            sources.GetterOnly = "asd";
            x = sources.SetterOnly;
            sources.SetterOnly = "asd";
            x            = sources.Both;
            sources.Both = "asd";

            // source-destinaton compatibility
            // these cover only some of the possible cases and should be refactored into a proper test suite
            var sourceMethod = typeof(DetourTestSources).GetMethod("CompatTest", Helpers.AllBindingFlags);

            if (DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestDestinations).GetMethod("CompatTestReturn", Helpers.AllBindingFlags)))
            {
                Logger.Error("non-matching return types passed");
            }
            if (DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestDestinations).GetMethod("CompatTestParamsTypes", Helpers.AllBindingFlags)))
            {
                Logger.Error("non-matching param types passed");
            }
            if (DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestDestinations).GetMethod("CompatTestParamsCount", Helpers.AllBindingFlags)))
            {
                Logger.Error("non-matching param count passed");
            }
            if (DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestContainerWithField).GetMethod("CompatTest", Helpers.AllBindingFlags)))
            {
                Logger.Error("type with field passed");
            }
            sourceMethod = typeof(DetourTestSources).GetMethod("CompatTestTwo", Helpers.AllBindingFlags);
            if (DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestContainerStatic).GetMethod("CompatTestExtensionInvalid", Helpers.AllBindingFlags)))
            {
                Logger.Error("invalid extension method passed");
            }
            if (!DetourValidator.IsValidDetourPair(sourceMethod, typeof(DetourTestContainerStatic).GetMethod("CompatTestExtensionValid", Helpers.AllBindingFlags)))
            {
                Logger.Error("valid extension method failed");
            }

            Logger.Message("detour tests finished");
        }