Move COM object lifetime control tests to CoreCLR. (#24990)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Thu, 6 Jun 2019 21:39:42 +0000 (14:39 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Jun 2019 21:39:42 +0000 (14:39 -0700)
* Add COM object lifetime control tests to CoreCLR.

* Combine cleanup control test into NETClientPrimitives.

tests/src/Interop/COM/NETClients/Primitives/Program.cs

index 4225caf..0b58ef9 100644 (file)
@@ -5,6 +5,9 @@
 namespace NetClient
 {
     using System;
+    using System.Threading;
+    using System.Runtime.InteropServices;
+    using TestLibrary;
 
     class Program
     {
@@ -18,11 +21,12 @@ namespace NetClient
 
             try
             {
-                new NumericTests().Run();
-                new ArrayTests().Run();
-                new StringTests().Run();
-                new ErrorTests().Run();
-                new ColorTests().Run();
+                RunTests();
+                Console.WriteLine("Testing COM object lifetime control methods.");
+                Thread.CurrentThread.DisableComObjectEagerCleanup();
+                RunTests();
+                Marshal.CleanupUnusedObjectsInCurrentContext();
+                Assert.IsFalse(Marshal.AreComObjectsAvailableForCleanup());
             }
             catch (Exception e)
             {
@@ -32,5 +36,14 @@ namespace NetClient
 
             return 100;
         }
+
+        private static void RunTests()
+        {
+            new NumericTests().Run();
+            new ArrayTests().Run();
+            new StringTests().Run();
+            new ErrorTests().Run();
+            new ColorTests().Run();
+        }
     }
 }