Browse Source

Merge branch 'master' into Save-WindowIcon

pull/797/head
danwalmsley 10 years ago
committed by GitHub
parent
commit
166e24f078
  1. 24
      build.cake
  2. 5
      src/Avalonia.Controls/Generators/IItemContainerGenerator.cs
  3. 3
      src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
  4. 3
      src/Avalonia.Controls/Generators/ItemContainerGenerator`1.cs
  5. 50
      src/Avalonia.Controls/ItemsControl.cs
  6. 2
      src/Skia/Avalonia.Skia/FormattedTextImpl.cs
  7. 5
      tests/Avalonia.Controls.UnitTests/CarouselTests.cs
  8. 33
      tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs
  9. 4
      tests/Avalonia.DesignerSupport.TestApp/Avalonia.DesignerSupport.TestApp.csproj
  10. 10
      tests/Avalonia.DesignerSupport.Tests/Avalonia.DesignerSupport.Tests.csproj
  11. 4
      tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs
  12. 4
      tests/Avalonia.RenderTests/Avalonia.Cairo.RenderTests.csproj
  13. 8
      tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj
  14. 6
      tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj
  15. 10
      tests/Avalonia.RenderTests/Media/FormattedTextImplTests.cs
  16. 20
      tests/Avalonia.RenderTests/TestBase.cs

24
build.cake

@ -662,11 +662,9 @@ Task("Run-Unit-Tests")
if (isRunningOnWindows)
{
var windowsTests = GetFiles("./tests/Avalonia.DesignerSupport.Tests/bin/" + dirSuffix + "/*.Tests.dll") +
GetFiles("./tests/Avalonia.LeakTests/bin/" + dirSuffix + "/*.LeakTests.dll") +
GetFiles("./tests/Avalonia.RenderTests/bin/" + dirSuffix + "/*.RenderTests.dll");
var leakTests = GetFiles("./tests/Avalonia.LeakTests/bin/" + dirSuffix + "/*.LeakTests.dll");
unitTests.AddRange(windowsTests);
unitTests.AddRange(leakTests);
}
var toolPath = (isPlatformAnyCPU || isPlatformX86) ?
@ -688,20 +686,32 @@ Task("Run-Unit-Tests")
.WithFilter("-[Avalonia.*]OmniXaml.* -[Avalonia.*]Glass.*")
.WithFilter("-[Avalonia.HtmlRenderer]TheArtOfDev.HtmlRenderer.* +[Avalonia.HtmlRenderer]TheArtOfDev.HtmlRenderer.Avalonia.* -[Avalonia.ReactiveUI]*");
foreach(var test in unitTests)
openCoverSettings.ReturnTargetCodeOffset = 0;
foreach(var test in unitTests.Where(testFile => FileExists(testFile)))
{
CopyDirectory(test.GetDirectory(), testsRoot);
}
var testsInDirectoryToRun = new List<FilePath>();
if(isRunningOnWindows)
{
testsInDirectoryToRun.AddRange(GetFiles("./artifacts/tests/*Tests.dll"));
}
else
{
testsInDirectoryToRun.AddRange(GetFiles("./artifacts/tests/*.UnitTests.dll"));
}
if(isRunningOnWindows)
{
OpenCover(context => {
context.XUnit2(unitTests.Select(test => testsRoot.GetFilePath(test).FullPath), xUnitSettings);
context.XUnit2(testsInDirectoryToRun, xUnitSettings);
}, openCoverOutput, openCoverSettings);
}
else
{
XUnit2(unitTests.Select(test => test.FullPath), xUnitSettings);
XUnit2(testsInDirectoryToRun, xUnitSettings);
}
});

5
src/Avalonia.Controls/Generators/IItemContainerGenerator.cs

@ -22,6 +22,11 @@ namespace Avalonia.Controls.Generators
/// </summary>
IDataTemplate ItemTemplate { get; set; }
/// <summary>
/// Gets the ContainerType, or null if its an untyped ContainerGenerator.
/// </summary>
Type ContainerType { get; }
/// <summary>
/// Signalled whenever new containers are materialized.
/// </summary>

3
src/Avalonia.Controls/Generators/ItemContainerGenerator.cs

@ -50,6 +50,9 @@ namespace Avalonia.Controls.Generators
/// </summary>
public IControl Owner { get; }
/// <inheritdoc/>
public virtual Type ContainerType => null;
/// <inheritdoc/>
public ItemContainerInfo Materialize(
int index,

3
src/Avalonia.Controls/Generators/ItemContainerGenerator`1.cs

@ -34,6 +34,9 @@ namespace Avalonia.Controls.Generators
ContentTemplateProperty = contentTemplateProperty;
}
/// <inheritdoc/>
public override Type ContainerType => typeof(T);
/// <summary>
/// Gets the container's Content property.
/// </summary>

50
src/Avalonia.Controls/ItemsControl.cs

@ -4,7 +4,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Generators;
@ -226,19 +225,35 @@ namespace Avalonia.Controls
/// <param name="e">The details of the containers.</param>
protected virtual void OnContainersMaterialized(ItemContainerEventArgs e)
{
var toAdd = new List<ILogical>();
foreach (var container in e.Containers)
{
// If the item is its own container, then it will be added to the logical tree when
// it was added to the Items collection.
if (container.ContainerControl != null && container.ContainerControl != container.Item)
{
toAdd.Add(container.ContainerControl);
if (ItemContainerGenerator.ContainerType == null)
{
var containerControl = container.ContainerControl as ContentPresenter;
if (containerControl != null)
{
((ISetLogicalParent)containerControl).SetParent(this);
containerControl.SetValue(TemplatedParentProperty, null);
containerControl.UpdateChild();
if (containerControl.Child != null)
{
LogicalChildren.Add(containerControl.Child);
}
}
}
else
{
LogicalChildren.Add(container.ContainerControl);
}
}
}
LogicalChildren.AddRange(toAdd);
}
/// <summary>
@ -248,19 +263,32 @@ namespace Avalonia.Controls
/// <param name="e">The details of the containers.</param>
protected virtual void OnContainersDematerialized(ItemContainerEventArgs e)
{
var toRemove = new List<ILogical>();
foreach (var container in e.Containers)
{
// If the item is its own container, then it will be removed from the logical tree
// when it is removed from the Items collection.
if (container?.ContainerControl != container?.Item)
{
toRemove.Add(container.ContainerControl);
if (ItemContainerGenerator.ContainerType == null)
{
var containerControl = container.ContainerControl as ContentPresenter;
if (containerControl != null)
{
((ISetLogicalParent)containerControl).SetParent(null);
if (containerControl.Child != null)
{
LogicalChildren.Remove(containerControl.Child);
}
}
}
else
{
LogicalChildren.Remove(container.ContainerControl);
}
}
}
LogicalChildren.RemoveAll(toRemove);
}
/// <summary>

2
src/Skia/Avalonia.Skia/FormattedTextImpl.cs

@ -585,7 +585,7 @@ namespace Avalonia.Skia
if (_skiaLines.Count == 0)
{
_lines.Add(new FormattedTextLine(0, _lineHeight));
_size = new Size(0, _lineHeight + lastLineDescent);
_size = new Size(0, _lineHeight);
}
else
{

5
tests/Avalonia.Controls.UnitTests/CarouselTests.cs

@ -50,8 +50,9 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(1, target.GetLogicalChildren().Count());
var child = target.GetLogicalChildren().Single();
Assert.IsType<ContentPresenter>(child);
Assert.Equal("Foo", ((ContentPresenter)child).Content);
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
}
[Fact]

33
tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

@ -9,6 +9,8 @@ using Avalonia.Controls.Templates;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using Xunit;
using System.Collections.ObjectModel;
using Avalonia.UnitTests;
namespace Avalonia.Controls.UnitTests
{
@ -61,6 +63,32 @@ namespace Avalonia.Controls.UnitTests
Assert.Null(container.TemplatedParent);
}
[Fact]
public void Container_Child_Should_Have_LogicalParent_Set_To_Container()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var root = new Window();
var target = new ItemsControl();
root.Content = target;
var templatedParent = new Button();
target.TemplatedParent = templatedParent;
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
root.ApplyTemplate();
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
var container = (ContentPresenter)target.Presenter.Panel.Children[0];
Assert.Equal(container, container.Child.Parent);
}
}
[Fact]
public void Control_Item_Should_Be_Logical_Child_Before_ApplyTemplate()
{
@ -138,7 +166,7 @@ namespace Avalonia.Controls.UnitTests
}
[Fact]
public void Adding_String_Item_Should_Make_ContentPresenter_Appear_In_LogicalChildren()
public void Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
var child = new Control();
@ -150,7 +178,7 @@ namespace Avalonia.Controls.UnitTests
var logical = (ILogical)target;
Assert.Equal(1, logical.LogicalChildren.Count);
Assert.IsType<ContentPresenter>(logical.LogicalChildren[0]);
Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
}
[Fact]
@ -171,6 +199,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new ILogical[0], target.GetLogicalChildren());
}
[Fact]
public void Setting_Items_Should_Fire_LogicalChildren_CollectionChanged()
{

4
tests/Avalonia.DesignerSupport.TestApp/Avalonia.DesignerSupport.TestApp.csproj

@ -18,7 +18,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -27,7 +27,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

10
tests/Avalonia.DesignerSupport.Tests/Avalonia.DesignerSupport.Tests.csproj

@ -16,7 +16,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -24,7 +24,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -69,6 +69,12 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.DesignerSupport.TestApp\Avalonia.DesignerSupport.TestApp.csproj">
<Project>{f1381f98-4d24-409a-a6c5-1c5b1e08bb08}</Project>
<Name>Avalonia.DesignerSupport.TestApp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

4
tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs

@ -12,8 +12,8 @@ namespace Avalonia.DesignerSupport.Tests
public class DesignerSupportTests
{
[Theory,
InlineData(@"..\..\..\Avalonia.DesignerSupport.TestApp\bin\$BUILD\Avalonia.DesignerSupport.TestApp.exe", @"..\..\..\Avalonia.DesignerSupport.TestApp\MainWindow.xaml"),
InlineData(@"..\..\..\..\samples\ControlCatalog.Desktop\bin\$BUILD\ControlCatalog.dll", @"..\..\..\..\samples\ControlCatalog\MainWindow.xaml")]
InlineData(@"Avalonia.DesignerSupport.TestApp.exe", @"..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml"),
InlineData(@"..\..\samples\ControlCatalog.Desktop\bin\$BUILD\ControlCatalog.dll", @"..\..\samples\ControlCatalog\MainWindow.xaml")]
public void DesgignerApiShoudBeOperational(string outputDir, string xamlFile)
{
var xaml = File.ReadAllText(xamlFile);

4
tests/Avalonia.RenderTests/Avalonia.Cairo.RenderTests.csproj

@ -23,7 +23,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;DEBUG;AVALONIA_CAIRO</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -31,7 +31,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;AVALONIA_CAIRO</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

8
tests/Avalonia.RenderTests/Avalonia.Direct2D1.RenderTests.csproj

@ -22,20 +22,22 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Avalonia.Direct2D1.RenderTests.XML</DocumentationFile>
<DocumentationFile>..\..\artifacts\tests\Avalonia.Direct2D1.RenderTests.XML</DocumentationFile>
<NoWarn>CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">

6
tests/Avalonia.RenderTests/Avalonia.Skia.RenderTests.csproj

@ -34,7 +34,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;DEBUG;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
@ -42,8 +42,8 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL</DefineConstants>
<OutputPath>..\..\artifacts\tests\</OutputPath>
<DefineConstants>TRACE;AVALONIA_SKIA;AVALONIA_SKIA_SKIP_FAIL;</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>

10
tests/Avalonia.RenderTests/Media/FormattedTextImplTests.cs

@ -101,20 +101,12 @@ namespace Avalonia.Direct2D1.RenderTests.Media
[InlineData(stringmiddlenewlines, FontSize, 72.01, 4 * FontSizeHeight)]
public void Should_Measure_String_Correctly(string input, double fontSize, double expWidth, double expHeight)
{
#if !AVALONIA_SKIA
double heightCorr = 0;
#else
//In skia there is a small descent added to last line,
//otherwise some letters are clipped at bottom
//4.55273438 for font 12 size
double heightCorr = 0.3793945*fontSize;
#endif
using (var fmt = Create(input, fontSize))
{
var size = fmt.Measure();
Assert.Equal(expWidth, size.Width, 2);
Assert.Equal(expHeight + heightCorr, size.Height, 2);
Assert.Equal(expHeight, size.Height, 2);
var linesHeight = fmt.GetLines().Sum(l => l.Height);

20
tests/Avalonia.RenderTests/TestBase.cs

@ -42,11 +42,11 @@ namespace Avalonia.Direct2D1.RenderTests
public TestBase(string outputPath)
{
#if AVALONIA_CAIRO
string testFiles = Path.GetFullPath(@"..\..\..\TestFiles\Cairo");
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Cairo");
#elif AVALONIA_SKIA
string testFiles = Path.GetFullPath(@"..\..\..\TestFiles\Skia");
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Skia");
#else
string testFiles = Path.GetFullPath(@"..\..\..\TestFiles\Direct2D1");
string testFiles = Path.GetFullPath(@"..\..\tests\TestFiles\Direct2D1");
#endif
OutputPath = Path.Combine(testFiles, outputPath);
}
@ -81,13 +81,15 @@ namespace Avalonia.Direct2D1.RenderTests
{
string expectedPath = Path.Combine(OutputPath, testName + ".expected.png");
string actualPath = Path.Combine(OutputPath, testName + ".out.png");
MagickImage expected = new MagickImage(expectedPath);
MagickImage actual = new MagickImage(actualPath);
double error = expected.Compare(actual, ErrorMetric.RootMeanSquared);
if (error > 0.022)
using (MagickImage expected = new MagickImage(expectedPath))
using (MagickImage actual = new MagickImage(actualPath))
{
Assert.True(false, actualPath + ": Error = " + error);
double error = expected.Compare(actual, ErrorMetric.RootMeanSquared);
if (error > 0.022)
{
Assert.True(false, actualPath + ": Error = " + error);
}
}
}
}

Loading…
Cancel
Save