Skip to content

Commit

Permalink
Merge pull request #2658 from cwensley/curtis/fix-some-unit-tests
Browse files Browse the repository at this point in the history
Fix some tests with Splitter, EnsureUIThread, and NativeControl
  • Loading branch information
cwensley authored May 28, 2024
2 parents 60fc80f + 39a80d8 commit 36ca020
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/Controls/NativeControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ NSView CreateHost(object nativeControl)
{
if (nativeControl == null)
{
return new NSView();
return new MacPanelView();
}
else if (nativeControl is NSView view)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Eto.Mac/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ void ResizeSubviews(CGSize oldSize2)
}
}

if (newFrame.Width <= 0)
panel1Rect.Width = panel1Rect.X = panel2Rect.Width = panel2Rect.X = 0;
if (newFrame.Height <= 0)
panel1Rect.Height = panel1Rect.Y = panel2Rect.Height = panel2Rect.Y = 0;

splitView.Subviews[0].Frame = panel1Rect;
splitView.Subviews[1].Frame = panel2Rect;
//Console.WriteLine($"Splitter resize: frame: {splitView.Frame.Size}, position: {position}, panel1({panel1?.Visible}): {panel1Rect}, panel2({panel2?.Visible}): {panel2Rect}");
Expand Down
10 changes: 0 additions & 10 deletions src/Eto/Forms/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public enum UIThreadCheckMode
/// <summary>
/// Exception thrown when a control method is accessed in a non-UI thread using <see cref="Application.EnsureUIThread"/>.
/// </summary>
#if NETSTANDARD2_0_OR_GREATER
[System.Serializable]
#endif
public class UIThreadAccessException : System.Exception
{
/// <summary>
Expand All @@ -42,7 +40,6 @@ public UIThreadAccessException(string message) : base(message) { }
/// <param name="message">Message for the exception</param>
/// <param name="inner">Inner exception</param>
public UIThreadAccessException(string message, System.Exception inner) : base(message, inner) { }
#if NETSTANDARD2_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the UIThreadAccessException class from serialization
/// </summary>
Expand All @@ -51,7 +48,6 @@ public UIThreadAccessException(string message, System.Exception inner) : base(me
protected UIThreadAccessException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
#endif
}

/// <summary>
Expand All @@ -65,9 +61,7 @@ protected UIThreadAccessException(
[Handler(typeof(Application.IHandler))]
public class Application : Widget
{
#if NETSTANDARD2_0_OR_GREATER
Thread mainThread;
#endif
LocalizeEventArgs localizeArgs;
readonly object localizeLock = new object();
static readonly object ApplicationKey = new object();
Expand Down Expand Up @@ -313,9 +307,7 @@ public Application(Platform platform)
: this(InitializePlatform(platform))
{
Instance = this;
#if NETSTANDARD2_0_OR_GREATER
mainThread = System.Threading.Thread.CurrentThread;
#endif
}

Application(InitHelper init)
Expand Down Expand Up @@ -350,7 +342,6 @@ static InitHelper InitializePlatform(Platform platform)
/// </summary>
public void EnsureUIThread()
{
#if NETSTANDARD2_0_OR_GREATER
if (UIThreadCheckMode == UIThreadCheckMode.None)
return;
if (mainThread == Thread.CurrentThread)
Expand All @@ -359,7 +350,6 @@ public void EnsureUIThread()
System.Diagnostics.Trace.WriteLine("Warning: Accessing UI object from a non-UI thread. UI objects can only be used from the main thread.");
else if (UIThreadCheckMode == UIThreadCheckMode.Error)
throw new UIThreadAccessException();
#endif
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/Eto.Test.Mac/UnitTests/ButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ButtonNaturalSizeShouldBeConsistent()
var b = new EtoButton(NSButtonType.MomentaryPushIn);
var originalSize = b.GetAlignmentRectForFrame(new CGRect(CGPoint.Empty, b.FittingSize)).Size;
Assert.AreEqual(defaultButtonHeight, originalSize.Height, "#2.1");
Assert.AreEqual((nfloat)defaultButtonHeight, originalSize.Height, "#2.1");
var preferred = handler.GetPreferredSize(SizeF.PositiveInfinity);
Assert.AreEqual(originalSize.Height, preferred.Height, "#2.1");
Expand Down
19 changes: 19 additions & 0 deletions test/Eto.Test/UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ public static void ManualForm(string description, Func<Form, Label, Control> ini
form.Close();
}
};
form.KeyDown += (sender, e) =>
{
if (e.KeyData == Keys.Escape)
{
failButton.PerformClick();
e.Handled = true;
}
};
row.Cells.Add(failButton);
}
Expand All @@ -361,6 +369,15 @@ public static void ManualForm(string description, Func<Form, Label, Control> ini
var passButton = new Button { Text = "Pass" };
passButton.Click += (sender, e) => form.Close();
row.Cells.Add(passButton);
form.KeyDown += (sender, e) =>
{
if (e.KeyData == Keys.Enter)
{
passButton.PerformClick();
e.Handled = true;
}
};
}
layout.Items.Add(new StackLayoutItem(table, HorizontalAlignment.Center));
}
Expand Down Expand Up @@ -458,6 +475,8 @@ public static void ManualDialog(string description, Func<Dialog, Label, Control>
var passButton = new Button { Text = "Pass" };
passButton.Click += (sender, e) => dialog.Close();
dialog.DefaultButton = passButton;
dialog.AbortButton = failButton;
dialog.Content = new StackLayout
{
Expand Down

0 comments on commit 36ca020

Please sign in to comment.