示例#1
0
        static int Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT || TestLibrary.Utilities.IsWindows7 || TestLibrary.Utilities.IsWindowsNanoServer)
            {
                return(100);
            }

            // Use the same seed for consistency between runs.
            int seed = 42;

            try
            {
                Assembly    ijwNativeDll = IjwHelper.LoadIjwAssembly("IjwNativeVarargs");
                Type        testType     = ijwNativeDll.GetType("TestClass");
                object      testInstance = Activator.CreateInstance(testType);
                MethodInfo  testMethod   = testType.GetMethod("RunTests");
                IEnumerable failedTests  = (IEnumerable)testMethod.Invoke(testInstance, BindingFlags.DoNotWrapExceptions, null, new object[] { seed }, null);

                if (failedTests.OfType <object>().Any())
                {
                    Console.WriteLine("Failed Varargs tests:");
                    foreach (var failedTest in failedTests)
                    {
                        Console.WriteLine($"\t{failedTest}");
                    }
                    return(102);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(101);
            }
            return(100);
        }
        static int Main(string[] args)
        {
            // Disable running on Windows 7 until IJW activation work is complete.
            if (Environment.OSVersion.Platform != PlatformID.Win32NT || TestLibrary.Utilities.IsWindows7)
            {
                return(100);
            }

            bool     success      = true;
            Assembly ijwNativeDll = IjwHelper.LoadIjwAssembly("IjwNativeDll");

            TestFramework.BeginTestCase("Call native method returning int");
            Type       testType     = ijwNativeDll.GetType("TestClass");
            object     testInstance = Activator.CreateInstance(testType);
            MethodInfo testMethod   = testType.GetMethod("ManagedEntryPoint");
            int        result       = (int)testMethod.Invoke(testInstance, null);

            if (result != 100)
            {
                TestFramework.LogError("IJW", "Incorrect result returned: " + result);
                success = false;
            }
            TestFramework.EndTestCase();

            TestFramework.BeginTestCase("Negative: Load IJW dll as byte array");
            byte[] ijwBytes = File.ReadAllBytes("IjwNativeDll.dll");
            try
            {
                Assembly.Load(ijwBytes);
                TestFramework.LogError("IJW", "Loading IJW dll as byte array should have thrown");
                success = false;
            }
            catch { }
            TestFramework.EndTestCase();

            TestFramework.BeginTestCase("Ensure .NET Framework was not loaded");
            IntPtr clrHandle = GetModuleHandle("mscoreei.dll");

            if (clrHandle != IntPtr.Zero)
            {
                TestFramework.LogError("IJW", ".NET Framework loaded by IJw module load");
                success = false;
            }
            TestFramework.EndTestCase();

            return(success ? 100 : 99);
        }
示例#3
0
        static int Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT || TestLibrary.Utilities.IsWindows7)
            {
                return(100);
            }

            try
            {
                Assembly   ijwNativeDll = IjwHelper.LoadIjwAssembly("IjwCopyConstructorMarshaler");
                Type       testType     = ijwNativeDll.GetType("TestClass");
                object     testInstance = Activator.CreateInstance(testType);
                MethodInfo testMethod   = testType.GetMethod("PInvokeNumCopies");

                // PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter.
                Assert.AreEqual(2, (int)testMethod.Invoke(testInstance, null));

                testMethod = testType.GetMethod("ReversePInvokeNumCopies");

                // Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke,
                // and the third is from the reverse P/Invoke call.
                Assert.AreEqual(3, (int)testMethod.Invoke(testInstance, null));

                testMethod = testType.GetMethod("PInvokeNumCopiesDerivedType");

                // PInvoke will copy twice. Once from argument to parameter, and once from the managed to native parameter.
                Assert.AreEqual(2, (int)testMethod.Invoke(testInstance, null));

                testMethod = testType.GetMethod("ReversePInvokeNumCopiesDerivedType");

                // Reverse PInvoke will copy 3 times. Two are from the same paths as the PInvoke,
                // and the third is from the reverse P/Invoke call.
                Assert.AreEqual(3, (int)testMethod.Invoke(testInstance, null));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(101);
            }
            return(100);
        }