Skip to content

Commit

Permalink
Merge pull request #18497 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.5/pr-18466

fix: Fix potential crash in PropertyValue.AreEqualImpl (backport #18466)
  • Loading branch information
jeromelaban authored Oct 17, 2024
2 parents 0e83d1d + 3249be7 commit 8dcbdb1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/Uno.Foundation/PropertyValue.Internal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace Windows.Foundation;

Expand Down Expand Up @@ -90,7 +91,8 @@ bool CompareOtherType()
//}
if (oldValueType.IsEnum)
{
return oldValue switch
var oldValueUnwrapped = Convert.ChangeType(oldValue, oldValueType.GetEnumUnderlyingType(), CultureInfo.InvariantCulture);
return oldValueUnwrapped switch
{
byte oldValueAsByte => oldValueAsByte == (byte)newValue,
sbyte oldValueAsSByte => oldValueAsSByte == (sbyte)newValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
Expand All @@ -20,24 +21,20 @@
using Uno.UI.RuntimeTests.Tests.ComboBoxTests;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.Storage.Pickers;
using Windows.UI.Input.Preview.Injection;
using static Private.Infrastructure.TestServices;

#if WINAPPSDK
using ComboBoxHelper = Microsoft.UI.Xaml.Tests.Common.ComboBoxHelper;
using Uno.UI.Extensions;
#elif __IOS__
using UIKit;

#if __IOS__
using _UIViewController = UIKit.UIViewController;
using Uno.UI.Controls;

using Windows.UI.Core;
using Microsoft.UI.Xaml.Media.Animation;
using static Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.MultiFrame;
using Microsoft.UI.Xaml.Controls.Primitives;

#elif __MACOS__
using AppKit;
#else
#endif

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
Expand Down Expand Up @@ -1293,6 +1290,31 @@ public async Task When_Customized_Popup_Placement(PopupPlacementMode mode, doubl
}
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Items_Are_Enum_Values()
{
var comboBox = new ComboBox();
comboBox.ItemsSource = Enum.GetValues(typeof(PickerLocationId)).Cast<PickerLocationId>();
comboBox.SelectedIndex = 0;
TestServices.WindowHelper.WindowContent = comboBox;
await TestServices.WindowHelper.WaitForLoaded(comboBox);

await ComboBoxHelper.OpenComboBox(comboBox, ComboBoxHelper.OpenMethod.Programmatic);
await TestServices.WindowHelper.WaitForIdle();

Assert.IsTrue(comboBox.IsDropDownOpen);

await TestServices.WindowHelper.WaitForIdle();

var popup = VisualTreeHelper.GetOpenPopupsForXamlRoot(comboBox.XamlRoot).FirstOrDefault();
Assert.IsNotNull(popup);

var child = (FrameworkElement)popup.Child;
var comboBoxItems = child.GetAllChildren().OfType<ComboBoxItem>().ToArray();
Assert.AreEqual(Enum.GetValues(typeof(PickerLocationId)).Length, comboBoxItems.Length);
}

#if HAS_UNO
[TestMethod]
[RunsOnUIThread]
Expand Down Expand Up @@ -1514,7 +1536,7 @@ public async Task OpenModal(FrameSectionsTransitionInfo transitionInfo, Page pag
{
var uiViewController = new UiViewController(page);

var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var rootController = UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController;

await rootController.PresentViewControllerAsync(uiViewController, animated: false);
}
Expand All @@ -1523,7 +1545,7 @@ public async Task CloseModal()
{
try
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var rootController = UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController;

await rootController.DismissViewControllerAsync(false);
}
Expand Down Expand Up @@ -1655,7 +1677,7 @@ public Task Run(Frame frameToHide, Frame frameToShow, bool frameToShowIsAboveFra

public class UIViewControllerSectionsTransitionInfo : FrameSectionsTransitionInfo
{
public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = true, UIModalPresentationStyle modalPresentationStyle = UIModalPresentationStyle.PageSheet, UIModalTransitionStyle modalTransitionStyle = UIModalTransitionStyle.CoverVertical)
public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = true, UIKit.UIModalPresentationStyle modalPresentationStyle = UIKit.UIModalPresentationStyle.PageSheet, UIKit.UIModalTransitionStyle modalTransitionStyle = UIKit.UIModalTransitionStyle.CoverVertical)
{
AllowDismissFromGesture = allowDismissFromGesture;
ModalPresentationStyle = modalPresentationStyle;
Expand All @@ -1664,9 +1686,9 @@ public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = tru

public bool AllowDismissFromGesture { get; }

public UIModalPresentationStyle ModalPresentationStyle { get; }
public UIKit.UIModalPresentationStyle ModalPresentationStyle { get; }

public UIModalTransitionStyle ModalTransitionStyle { get; }
public UIKit.UIModalTransitionStyle ModalTransitionStyle { get; }

public override FrameSectionsTransitionInfoTypes Type => FrameSectionsTransitionInfoTypes.UIViewControllerBased;
}
Expand Down

0 comments on commit 8dcbdb1

Please sign in to comment.