Fixed more bad code

This commit is contained in:
Tig
2024-03-25 16:54:08 -06:00
parent 9c0fb02593
commit 6ebee8d42b
15 changed files with 193 additions and 187 deletions

View File

@@ -974,15 +974,20 @@ public class ApplicationTests
Assert.NotNull (Application.Top);
Application.RequestStop ();
};
Application.Run (null, driver);
var top = Application.Run (null, driver);
#if DEBUG_IDISPOSABLE
Assert.False (Application.Top.WasDisposed);
Assert.Equal(top, Application.Top);
Assert.False (top.WasDisposed);
var exception = Record.Exception (() => Application.Shutdown ());
Assert.NotNull (exception);
Assert.False (Application.Top.WasDisposed);
Assert.False (top.WasDisposed);
#endif
// It's up to caller to dispose it
Application.Top.Dispose ();
Assert.True (Application.Top.WasDisposed);
top.Dispose ();
#if DEBUG_IDISPOSABLE
Assert.True (top.WasDisposed);
#endif
Assert.NotNull (Application.Top);

View File

@@ -46,7 +46,7 @@ public class SyncrhonizationContextTests
);
// blocks here until the RequestStop is processed at the end of the test
Application.Run ();
Application.Run ().Dispose ();
Assert.True (success);
}
@@ -79,7 +79,7 @@ public class SyncrhonizationContextTests
);
// blocks here until the RequestStop is processed at the end of the test
Application.Run ();
Application.Run ().Dispose ();
Assert.True (success);
}
}

View File

@@ -1126,8 +1126,7 @@ public class DialogTests
}
};
Run ();
Top.Dispose ();
Run ().Dispose ();
Shutdown ();
Assert.Equal (4, iterations);

View File

@@ -41,7 +41,7 @@ public class MessageBoxTests
break;
}
};
Application.Run ();
Application.Run ().Dispose ();
Assert.Equal (1, result);
}
@@ -77,7 +77,7 @@ public class MessageBoxTests
break;
}
};
Application.Run ();
Application.Run ().Dispose ();
Assert.Equal (-1, result);
}
@@ -115,7 +115,7 @@ public class MessageBoxTests
break;
}
};
Application.Run ();
Application.Run ().Dispose ();
Assert.Equal (1, result);
}
@@ -152,7 +152,7 @@ public class MessageBoxTests
}
};
Application.Run ();
Application.Run ().Dispose ();
}
[Theory]
@@ -233,7 +233,7 @@ public class MessageBoxTests
}
};
Application.Run ();
Application.Run ().Dispose ();
}
[Fact]
@@ -604,7 +604,7 @@ ffffffffffffffffffff
}
};
Application.Run ();
Application.Run ().Dispose ();
}
[Fact]
@@ -655,7 +655,7 @@ ffffffffffffffffffff
}
};
Application.Run ();
Application.Run ().Dispose ();
}
[Fact]
@@ -756,7 +756,7 @@ ffffffffffffffffffff
}
};
Application.Run ();
Application.Run ().Dispose ();
}
[Theory]
@@ -905,6 +905,6 @@ ffffffffffffffffffff
}
};
Application.Run ();
Application.Run ().Dispose ();
}
}

View File

@@ -53,29 +53,28 @@ public class ScenarioTests
uint abortTime = 500;
// If the scenario doesn't close within 500ms, this will force it to quit
Func<bool> forceCloseCallback = () =>
{
if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0)
{
Application.RequestStop ();
bool ForceCloseCallback ()
{
if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0)
{
Application.RequestStop ();
// See #2474 for why this is commented out
Assert.Fail (
$"'{
scenario.GetName ()
}' failed to Quit with {
Application.QuitKey
} after {
abortTime
}ms. Force quit."
);
}
// See #2474 for why this is commented out
Assert.Fail (
$"'{
scenario.GetName ()
}' failed to Quit with {
Application.QuitKey
} after {
abortTime
}ms. Force quit.");
}
return false;
};
return false;
}
//output.WriteLine ($" Add timeout to force quit after {abortTime}ms");
_ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), forceCloseCallback);
_ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
Application.Iteration += (s, a) =>
{
@@ -87,9 +86,7 @@ public class ScenarioTests
}
};
scenario.Init ();
scenario.Setup ();
scenario.Run ();
scenario.Main ();
scenario.Dispose ();
Application.Shutdown ();
@@ -135,7 +132,7 @@ public class ScenarioTests
Application.Init (new FakeDriver ());
Toplevel Top = new Toplevel ();
Toplevel top = new Toplevel ();
_viewClasses = GetAllViewClassesCollection ()
.OrderBy (t => t.Name)
@@ -321,9 +318,9 @@ public class ScenarioTests
_hRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
Top.Add (_leftPane, _settingsPane, _hostPane);
top.Add (_leftPane, _settingsPane, _hostPane);
Top.LayoutSubviews ();
top.LayoutSubviews ();
_curView = CreateClass (_viewClasses.First ().Value);
@@ -348,11 +345,11 @@ public class ScenarioTests
}
};
Application.Run (Top);
Application.Run (top);
Assert.Equal (_viewClasses.Count, iterations);
Top.Dispose ();
top.Dispose ();
Application.Shutdown ();
void DimPosChanged (View view)
@@ -631,9 +628,7 @@ public class ScenarioTests
Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, args.KeyCode);
};
generic.Init ();
generic.Setup ();
generic.Run ();
generic.Main ();
Assert.Equal (0, abortCount);

View File

@@ -175,7 +175,7 @@ CTRL-O Open {
iteration++;
};
Application.Run ();
Application.Run ().Dispose ();
}
[Fact]

View File

@@ -1839,10 +1839,10 @@ public class ToplevelTests
BorderStyle = LineStyle.Single
};
Assert.Equal (testWindow, Application.Current);
Application.Current.DrawContentComplete += testWindow_DrawContentComplete;
Application.Current.DrawContentComplete += OnDrawContentComplete;
top.Add (viewAddedToTop);
void testWindow_DrawContentComplete (object sender, DrawEventArgs e)
void OnDrawContentComplete (object sender, DrawEventArgs e)
{
Assert.Equal (new Rectangle (1, 3, 18, 16), viewAddedToTop.Frame);
@@ -1857,7 +1857,7 @@ public class ToplevelTests
View.Driver.AddStr ("Three");
Application.Driver.Clip = savedClip;
Application.Current.DrawContentComplete -= testWindow_DrawContentComplete;
Application.Current.DrawContentComplete -= OnDrawContentComplete;
}
};
RunState rsTestWindow = Application.Begin (testWindow);
@@ -1936,6 +1936,8 @@ public class ToplevelTests
Application.End (rsTop);
}
private void OnDrawContentComplete (object sender, DrawEventArgs e) { throw new NotImplementedException (); }
[Fact]
[AutoInitShutdown]
public void Activating_MenuBar_By_Alt_Key_Does_Not_Throw ()