Skip to content

Commit

Permalink
chore: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Jul 25, 2024
1 parent d8e0ca1 commit c0a795e
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public void Read_GenericSimple()
[Test]
public void Read_GenericWithProperty()
{
const string not_win = "{http://uno.ui/not_win}";
var sequence = new SequenceItem[] {
new SequenceItem { NodeType = XamlNodeType.NamespaceDeclaration, },
new SequenceItem { NodeType = XamlNodeType.NamespaceDeclaration, },
Expand All @@ -382,16 +383,18 @@ public void Read_GenericWithProperty()
new SequenceItem { NodeType = XamlNodeType.EndMember, },

new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml}_UnknownContent", },
new SequenceItem { NodeType = XamlNodeType.StartObject, TypeName = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style"},
new SequenceItem { NodeType = XamlNodeType.StartObject, TypeName = $"{not_win}Style"},
new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml}Key", },
new SequenceItem { NodeType = XamlNodeType.Value, Value = "DefaultComboBoxItemStyle", },
new SequenceItem { NodeType = XamlNodeType.EndMember, },
new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style.OtherProperty", },
new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = $"{not_win}Style.OtherProperty", },
new SequenceItem { NodeType = XamlNodeType.Value, Value = "test", },
new SequenceItem { NodeType = XamlNodeType.EndMember, },
#if false // XamlXmlReader fails to read any xmlns'd node/attribute with invalid uri (such as a guid or 'using:System.Somewhere')
new SequenceItem { NodeType = XamlNodeType.StartMember, MemberType = "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Style.TargetType", },
new SequenceItem { NodeType = XamlNodeType.Value, Value = "SelectorItem", },
new SequenceItem { NodeType = XamlNodeType.EndMember, },
#endif
new SequenceItem { NodeType = XamlNodeType.EndObject, },
new SequenceItem { NodeType = XamlNodeType.EndMember, },
new SequenceItem { NodeType = XamlNodeType.EndObject, },
Expand Down Expand Up @@ -2507,9 +2510,30 @@ public void Bug680385 ()
}
#endregion

private string GetXml(string fileName)
{
var directory = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath);
var path = Path.Combine(directory, "Test/XmlFiles", fileName);

return File.ReadAllText(path).Replace("System.Xaml_test_net_4_0", "Uno.Xaml.Tests");
}

private IEnumerable<(XamlNodeType, string, string, object, string)> ReadAllTokens(string fileName)
{
var r = GetReader(fileName);
int i = 0;
while (r.Read())
{
yield return (r.NodeType, r.Member?.ToString(), r.Member?.Name, r.Value, r.Type?.ToString());
}
}

private void ReadSequence(string fileName, IEnumerable<SequenceItem> sequence)
{
//ReadTest(fileName);
#if DEBUG && false
var xml = GetXml(fileName);
var tokens = ReadAllTokens(fileName).ToArray();
#endif

var r = GetReader(fileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ internal partial class Inner : DependencyObject
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Uno.Disposables;
using System.Runtime.CompilerServices;
Expand All @@ -112,7 +113,7 @@ internal partial class Inner : DependencyObject
partial class OuterClass
{
[global::Microsoft.UI.Xaml.Data.Bindable]
partial class Inner : IDependencyObjectStoreProvider, IWeakReferenceProvider
partial class Inner : IDependencyObjectStoreProvider, ITemplatedParentProvider, IWeakReferenceProvider
{
private DependencyObjectStore __storeBackingField;
public global::Windows.UI.Core.CoreDispatcher Dispatcher => global::Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;
Expand All @@ -123,7 +124,7 @@ private DependencyObjectStore __Store
{
if(__storeBackingField == null)
{
__storeBackingField = new DependencyObjectStore(this, DataContextProperty, TemplatedParentProperty);
__storeBackingField = new DependencyObjectStore(this, DataContextProperty);
__InitializeBinder();
}
return __storeBackingField;
Expand All @@ -138,6 +139,28 @@ private DependencyObjectStore __Store
public object GetAnimationBaseValue(DependencyProperty dp) => __Store.GetAnimationBaseValue(dp);
public long RegisterPropertyChangedCallback(DependencyProperty dp, DependencyPropertyChangedCallback callback) => __Store.RegisterPropertyChangedCallback(dp, callback);
public void UnregisterPropertyChangedCallback(DependencyProperty dp, long token) => __Store.UnregisterPropertyChangedCallback(dp, token);

[EditorBrowsable(EditorBrowsableState.Never)]private ManagedWeakReference _templatedParentWeakRef;
[EditorBrowsable(EditorBrowsableState.Never)]public ManagedWeakReference GetTemplatedParentWeakRef() => _templatedParentWeakRef;

[EditorBrowsable(EditorBrowsableState.Never)]public DependencyObject GetTemplatedParent() => _templatedParentWeakRef?.Target as DependencyObject;
[EditorBrowsable(EditorBrowsableState.Never)]public void SetTemplatedParent(DependencyObject parent)
{
//if (parent != null)
//{
// global::System.Diagnostics.Debug.Assert(parent
// is global::Windows.UI.Xaml.Controls.Control
// or global::Windows.UI.Xaml.Controls.ContentPresenter
// or global::Windows.UI.Xaml.Controls.ItemsPresenter);
// global::System.Diagnostics.Debug.Assert(GetTemplatedParent() == null);
//}

SetTemplatedParentImpl(parent);
}
[EditorBrowsable(EditorBrowsableState.Never)]private protected virtual void SetTemplatedParentImpl(DependencyObject parent)
{
_templatedParentWeakRef = (parent as IWeakReferenceProvider)?.WeakReference;
}

private readonly static IEventProvider _binderTrace = Tracing.Get(DependencyObjectStore.TraceProvider.Id);
private BinderReferenceHolder _refHolder;
Expand Down Expand Up @@ -220,36 +243,6 @@ internal protected virtual void OnDataContextChanged(DependencyPropertyChangedEv

#endregion

#region TemplatedParent DependencyProperty

public DependencyObject TemplatedParent
{
get => (DependencyObject)GetValue(TemplatedParentProperty);
set => SetValue(TemplatedParentProperty, value);
}

// Using a DependencyProperty as the backing store for TemplatedParent. This enables animation, styling, binding, etc...
public static DependencyProperty TemplatedParentProperty { get ; } =
DependencyProperty.Register(
name: nameof(TemplatedParent),
propertyType: typeof(DependencyObject),
ownerType: typeof(Inner),
typeMetadata: new FrameworkPropertyMetadata(
defaultValue: null,
options: FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.ValueDoesNotInheritDataContext | FrameworkPropertyMetadataOptions.WeakStorage,
propertyChangedCallback: (s, e) => ((Inner)s).OnTemplatedParentChanged(e)
)
);


internal protected virtual void OnTemplatedParentChanged(DependencyPropertyChangedEventArgs e)
{
__Store.SetTemplatedParent(e.NewValue as FrameworkElement);
OnTemplatedParentChangedPartial(e);
}

#endregion

public void SetBinding(object target, string dependencyProperty, global::Microsoft.UI.Xaml.Data.BindingBase binding)
{
__Store.SetBinding(target, dependencyProperty, binding);
Expand All @@ -275,8 +268,6 @@ public void SetBindingValue(object value, [CallerMemberName] string propertyName

partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e);

partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e);

public global::Microsoft.UI.Xaml.Data.BindingExpression GetBindingExpression(DependencyProperty dependencyProperty)
=> __Store.GetBindingExpression(dependencyProperty);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void InitializeComponent()
"MyItemTemplate"
] =
new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 =>
new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner)
new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner, __settings)
) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6");
Expand All @@ -125,7 +125,7 @@ private void InitializeComponent()
{
IsParsing = true,
Name = "TheListView",
HeaderTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1>()).Build(__owner)
HeaderTemplate = new global::Microsoft.UI.Xaml.DataTemplate(this, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1>()).Build(__owner, __settings)
) .GenericApply(__that, __nameScope, ((c7, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c7, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L42:8");
Expand Down Expand Up @@ -312,7 +312,7 @@ private void InitializeComponent()
}
internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0
{
_View Build(object owner);
_View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings);
}
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -323,7 +323,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 :
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
public _View Build(object __ResourceOwner_1)
public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings)
{
_View __rootInstance = null;
var __that = this;
Expand All @@ -341,6 +341,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c17, __that, __nameScope) =>
{
c17.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c17);
c17.SetBinding(
global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty,
new Microsoft.UI.Xaml.Data.Binding()
Expand All @@ -361,6 +363,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c18, __that, __nameScope) =>
{
c18.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c18);
/* _isTopLevelDictionary:False */
__that._component_0 = c18;
global::Uno.UI.ResourceResolverSingleton.Instance.ApplyResource(c18, global::Microsoft.UI.Xaml.Controls.Button.StyleProperty, "MyCustomButtonStyle", isThemeResourceExtension: false, isHotReloadSupported: true, context: global::MyProject.GlobalStaticResources.__ParseContext_);
Expand All @@ -373,6 +377,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c19, __that, __nameScope) =>
{
c19.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c19);
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c19, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 14, 8);
c19.CreationComplete();
}
Expand Down Expand Up @@ -413,7 +419,7 @@ public _View Build(object __ResourceOwner_1)
}
internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1
{
_View Build(object owner);
_View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings);
}
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -424,7 +430,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC1 :
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
public _View Build(object __ResourceOwner_1)
public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings)
{
_View __rootInstance = null;
var __that = this;
Expand All @@ -437,6 +443,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c20, __that, __nameScope) =>
{
c20.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c20);
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c20, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 43, 10);
c20.CreationComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void InitializeComponent()
"MyItemTemplate"
] =
new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 =>
new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1 , __owner => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner)
new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner, __settings) => ((I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0)global::Uno.UI.Helpers.TypeMappings.CreateInstance<_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0>()).Build(__owner, __settings)
) .GenericApply(__that, __nameScope, ((c6, __that, __nameScope) =>
{
global::Uno.UI.Helpers.MarkupHelper.SetElementProperty(c6, "OriginalSourceLocation", "file:///C:/Project/0/MainPage.xaml#L13:6");
Expand Down Expand Up @@ -167,7 +167,7 @@ private void InitializeComponent()
partial void OnInitializeCompleted();
internal interface I_MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0
{
_View Build(object owner);
_View Build(object owner, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings);
}
[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -178,7 +178,7 @@ private class _MainPage_d6cd66944958ced0c513e0a04797b51d_TestReproMainPageSC0 :
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/";
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
public _View Build(object __ResourceOwner_1)
public _View Build(object __ResourceOwner_1, global::Microsoft.UI.Xaml.TemplateMaterializationSettings __settings)
{
_View __rootInstance = null;
var __that = this;
Expand All @@ -196,6 +196,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c10, __that, __nameScope) =>
{
c10.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c10);
c10.SetBinding(
global::Microsoft.UI.Xaml.Controls.TextBlock.TextProperty,
new Microsoft.UI.Xaml.Data.Binding()
Expand All @@ -216,6 +218,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c11, __that, __nameScope) =>
{
c11.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c11);
/* _isTopLevelDictionary:False */
__that._component_0 = c11;
global::Uno.UI.ResourceResolverSingleton.Instance.ApplyResource(c11, global::Microsoft.UI.Xaml.Controls.Button.StyleProperty, "MyCustomButtonStyle", isThemeResourceExtension: false, isHotReloadSupported: true, context: global::MyProject.GlobalStaticResources.__ParseContext_);
Expand All @@ -228,6 +232,8 @@ public _View Build(object __ResourceOwner_1)
}
.GenericApply(__that, __nameScope, ((c12, __that, __nameScope) =>
{
c12.SetTemplatedParent(__settings?.TemplatedParent);
__settings?.TemplateMemberCreatedCallback?.Invoke(c12);
global::Uno.UI.FrameworkElementHelper.SetBaseUri(c12, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d, "file:///C:/Project/0/MainPage.xaml", 14, 8);
c12.CreationComplete();
}
Expand Down
Loading

0 comments on commit c0a795e

Please sign in to comment.