public void OpenFormsTest() { IntPtr dummy = IntPtr.Zero; Form f1 = null, f2 = null; try { f1 = new OpenFormsTestForm(); Assert.AreEqual(0, Application.OpenForms.Count, "#1"); dummy = f1.Handle; Assert.AreEqual(0, Application.OpenForms.Count, "#2"); f1.Close(); Assert.AreEqual(0, Application.OpenForms.Count, "#3"); f1.Dispose(); Assert.AreEqual(0, Application.OpenForms.Count, "#4"); f1 = new OpenFormsTestForm(); Assert.AreEqual(0, Application.OpenForms.Count, "#5"); f1.Show(); Assert.AreEqual(1, Application.OpenForms.Count, "#6"); f1.Close(); Assert.AreEqual(0, Application.OpenForms.Count, "#7"); f1.Dispose(); Assert.AreEqual(0, Application.OpenForms.Count, "#8"); f1 = new OpenFormsTestForm(); Assert.AreEqual(0, Application.OpenForms.Count, "#9"); dummy = f1.Handle; Assert.AreEqual(0, Application.OpenForms.Count, "#10"); f1.GetType().GetMethod("RecreateHandle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.ExactBinding).Invoke(f1, new object [] {}); Assert.AreEqual(0, Application.OpenForms.Count, "#11"); f1.Dispose(); Assert.AreEqual(0, Application.OpenForms.Count, "#12"); f1 = new OpenFormsTestForm(); Assert.AreEqual(0, Application.OpenForms.Count, "#13"); f1.Show(); Assert.AreEqual(1, Application.OpenForms.Count, "#14"); f2 = new OpenFormsTestForm(); Assert.AreEqual(1, Application.OpenForms.Count, "#15"); f2.Show(); Assert.AreEqual(2, Application.OpenForms.Count, "#16"); f1.Dispose(); Assert.AreEqual(1, Application.OpenForms.Count, "#17"); f2.Close(); Assert.AreEqual(0, Application.OpenForms.Count, "#18"); f1 = new OpenFormsTestForm(); Assert.AreEqual(0, Application.OpenForms.Count, "#19"); f1.Show(); Assert.AreEqual(1, Application.OpenForms.Count, "#20"); f2 = new OpenFormsTestForm(); Assert.AreEqual(1, Application.OpenForms.Count, "#21"); f2.Show(); Assert.AreEqual(2, Application.OpenForms.Count, "#22"); f1.Visible = false; Assert.AreEqual(2, Application.OpenForms.Count, "#23"); f2.Visible = false; Assert.AreEqual(2, Application.OpenForms.Count, "#24"); f1.Dispose(); Assert.AreEqual(1, Application.OpenForms.Count, "#25"); f2.Close(); Assert.AreEqual(0, Application.OpenForms.Count, "#26"); } finally { if (f1 != null) { f1.Dispose(); } if (f2 != null) { f2.Dispose(); } } TestHelper.RemoveWarning(dummy); }
public void OpenFormsTest () { IntPtr dummy = IntPtr.Zero; Form f1 = null, f2 = null; try { f1 = new OpenFormsTestForm (); Assert.AreEqual (0, Application.OpenForms.Count, "#1"); dummy = f1.Handle; Assert.AreEqual (0, Application.OpenForms.Count, "#2"); f1.Close (); Assert.AreEqual (0, Application.OpenForms.Count, "#3"); f1.Dispose (); Assert.AreEqual (0, Application.OpenForms.Count, "#4"); f1 = new OpenFormsTestForm (); Assert.AreEqual (0, Application.OpenForms.Count, "#5"); f1.Show (); Assert.AreEqual (1, Application.OpenForms.Count, "#6"); f1.Close (); Assert.AreEqual (0, Application.OpenForms.Count, "#7"); f1.Dispose (); Assert.AreEqual (0, Application.OpenForms.Count, "#8"); f1 = new OpenFormsTestForm (); Assert.AreEqual (0, Application.OpenForms.Count, "#9"); dummy = f1.Handle; Assert.AreEqual (0, Application.OpenForms.Count, "#10"); f1.GetType ().GetMethod ("RecreateHandle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.ExactBinding).Invoke (f1, new object [] {}); Assert.AreEqual (0, Application.OpenForms.Count, "#11"); f1.Dispose (); Assert.AreEqual (0, Application.OpenForms.Count, "#12"); f1 = new OpenFormsTestForm (); Assert.AreEqual (0, Application.OpenForms.Count, "#13"); f1.Show (); Assert.AreEqual (1, Application.OpenForms.Count, "#14"); f2 = new OpenFormsTestForm (); Assert.AreEqual (1, Application.OpenForms.Count, "#15"); f2.Show (); Assert.AreEqual (2, Application.OpenForms.Count, "#16"); f1.Dispose (); Assert.AreEqual (1, Application.OpenForms.Count, "#17"); f2.Close (); Assert.AreEqual (0, Application.OpenForms.Count, "#18"); f1 = new OpenFormsTestForm (); Assert.AreEqual (0, Application.OpenForms.Count, "#19"); f1.Show (); Assert.AreEqual (1, Application.OpenForms.Count, "#20"); f2 = new OpenFormsTestForm (); Assert.AreEqual (1, Application.OpenForms.Count, "#21"); f2.Show (); Assert.AreEqual (2, Application.OpenForms.Count, "#22"); f1.Visible = false; Assert.AreEqual (2, Application.OpenForms.Count, "#23"); f2.Visible = false; Assert.AreEqual (2, Application.OpenForms.Count, "#24"); f1.Dispose (); Assert.AreEqual (1, Application.OpenForms.Count, "#25"); f2.Close (); Assert.AreEqual (0, Application.OpenForms.Count, "#26"); } finally { if (f1 != null) { f1.Dispose (); } if (f2 != null) { f2.Dispose (); } } TestHelper.RemoveWarning (dummy); }