Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made changes in test repo for making Setter.Value the ContentProperty for Setter #321

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions src/Test/Common/Code/Microsoft/Test/Markup/XamlComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System.Collections;
using Microsoft.Test.Logging;
using Microsoft.Test.Serialization;
using Microsoft.Test.Windows;
using System.Reflection;

namespace Microsoft.Test.Markup
{
Expand Down Expand Up @@ -301,6 +303,59 @@ private static bool CompareXmlNode(XmlNode node1, XmlNode node2)
return true;
}

private static bool IsContentProperty(XmlNode xmlNode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not getting the implementation of this function. As of now what I can get is that we are reading the propertiesToSkip.xml and working on that check only. There should be more checks in my understanding to validate if it is a ContentProperty or not.

{
string fileName = "PropertiesToSkip.xml";

//
// Load PropertiesToSkip.xml document from assembly resources.
//
XmlDocument doc = new XmlDocument();
Stream xmlFileStream = null;
if (File.Exists(fileName))
{
SendCompareMessage("Opening '" + fileName + "' from the current directory.");
xmlFileStream = File.OpenRead(fileName);
}
else
{
SendCompareMessage("Opening '" + fileName + "' from the Assembly.");
Assembly asm = Assembly.GetAssembly(typeof(TreeComparer));
xmlFileStream = asm.GetManifestResourceStream(fileName);

if (xmlFileStream == null)
{
throw new ArgumentException("The file '" + fileName + "' cannot be loaded.", "fileName");
}
}

try
{
StreamReader reader = new StreamReader(xmlFileStream);
doc.LoadXml(reader.ReadToEnd());
}
finally
{
xmlFileStream.Close();
}

//
// Store properties to skip in collection.
//
XmlNodeList nodeList = doc.GetElementsByTagName("PropertyToSkip");

foreach (XmlNode node in nodeList)
{
string property = TreeComparer.GetAttributeValue(node, "Owner");
if (property != null && (xmlNode.Name).Contains(property))
{
return true;
}

}
return false;
}

private static bool CompareMappings()
{
if (_mappingTables[0].Count != _mappingTables[1].Count)
Expand Down Expand Up @@ -423,7 +478,7 @@ private static bool CompareAttributes(XmlNode node1, XmlNode node2)
}
}

//Record how many attibutes that is not xmlns and remains uncompared.
//Record how many attributes that is not xmlns and remains uncompared.
int activeNonXmlnsAttributeCount = attributesTable2.Count;

// Verify each attribute in the first node matches one in the second
Expand Down Expand Up @@ -506,8 +561,8 @@ private static bool CompareChildren(XmlNode node1, XmlNode node2)
return false;
}

ArrayList childrenArray1 = SeperateMappingOut(children1, 0);
ArrayList childrenArray2 = SeperateMappingOut(children2, 1);
ArrayList childrenArray1 = SeparateMappingOut(children1, 0);
ArrayList childrenArray2 = SeparateMappingOut(children2, 1);

if (ShouldConsiderSequence(node1.LocalName))
{
Expand All @@ -530,6 +585,11 @@ private static ArrayList GetComplexPropertiesOut(ArrayList children)
//Get all properties, whose name contains a ".".
foreach (XmlNode node in children)
{
if (IsContentProperty(node))
{
return properties;
}

if (node.Name.Contains("."))
{
properties.Add(node);
Expand All @@ -543,12 +603,17 @@ private static ArrayList GetComplexPropertiesOut(ArrayList children)
return properties;
}

private static ArrayList SeperateMappingOut(XmlNodeList list, int index)
private static ArrayList SeparateMappingOut(XmlNodeList list, int index)
{
ArrayList listWithoutMapping = new ArrayList();

foreach (XmlNode node in list)
{
if (IsContentProperty(node))
{
return listWithoutMapping;
}

if ("Mapping" == node.LocalName)
{
AddToMappingTable(node, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public static Dictionary<string, PropertyToIgnore> ReadSkipProperties(string fil
return PropertiesToSkip;
}

private static string GetAttributeValue(
internal static string GetAttributeValue(
XmlNode node,
string attributeName)
{
Expand Down
1 change: 1 addition & 0 deletions src/Test/Common/Data/Windows/PropertiesToSkip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<PropertyToSkip PropertyName="LCID" Owner="CultureInfo" />
<!-- With DWM turned on, Button.BorderBrush changes-->
<PropertyToSkip PropertyName="BorderBrush" Owner="Button" />
<PropertyToSkip PropertyName="Value" Owner="Setter" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand how we are using the PropertiesToSkip.xaml to skip the properties for the comparison and why are we making a change here. The rationale for the question is that we were checking it earlier and now we are skipping this check, so skipping needs better reasoning.

<!-- Transform.Inverse property always returns a new Transform, thus putting us into an infinite loop -->
<PropertyToSkip PropertyName="Inverse" Owner="Transform" />
<PropertyToSkip PropertyName="Inverse" Owner="Transform3D" />
Expand Down
64 changes: 64 additions & 0 deletions src/Test/ElementServices/DRT/Parser/Parser/DRTParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public ParserTest()
new DateTimeTests(),
new InitializationStringTest(),
new NoDefaultXmlNsTest(),
new XamlValidationTest(),
null
};

Expand Down Expand Up @@ -2007,6 +2008,69 @@ private void RunTest()
FrameworkElement _rootElement;
}

public class XamlValidationTest : ParserSuites
{
public XamlValidationTest() : base("XAML Validation Test")
{
}

public override DrtTest[] PrepareTests()
{
return new DrtTest[]{
new DrtTest(RunXamlValidationTest),
};
}

private void RunXamlValidationTest()
{
Console.WriteLine("XAML validation test started.");

// Define the path to the XAML file
string xamlPath = @"DrtFiles\Parser\DrtParser10.xaml";
Stream xamlStream = LoadTestFile(xamlPath);

try
{
// Parse the XAML
ParserContext parserContext = new ParserContext();
object rootElement = XamlReader.Load(xamlStream, parserContext);

// Check if the root element is a Window
if (rootElement is Window window)
{
// Show and close the window
window.Show();
window.Close();
Console.WriteLine("XAML validation test passed. The XAML is valid and renders correctly.");
}
else if (rootElement is UIElement uiElement)
{
// Render the element if it's a UIElement
Render(uiElement);
Console.WriteLine("XAML validation test passed. The XAML is valid and renders correctly.");
}
else
{
Console.WriteLine("XAML validation test failed. The root element is not a UIElement or Window.");
}
}
catch (Exception ex)
{
Console.WriteLine($"XAML validation test failed with exception: {ex.Message}");
}
}

private void Render(UIElement element)
{
// Create a new window to render the UIElement
Window window = new Window
{
Content = element,
Width = 800,
Height = 600
};
window.Show();
window.Close();
}
}
}
Loading