Browse Source

Added StyleActivator leak test.

Trying to locate source of StyleActivator leaks - this test doesn't find
it.
pull/366/head
Steven Kirk 10 years ago
parent
commit
4d6572b74e
  1. 14
      src/Perspex.Styling/Styling/Style.cs
  2. 1
      tests/Perspex.LeakTests/Perspex.LeakTests.csproj
  3. 69
      tests/Perspex.LeakTests/StyleTests.cs

14
src/Perspex.Styling/Styling/Style.cs

@ -60,13 +60,13 @@ namespace Perspex.Styling
var activator = match.ObservableResult ??
Observable.Never<bool>().StartWith(true);
if (visual != null)
{
var detached = Observable.FromEventPattern<VisualTreeAttachmentEventArgs>(
x => visual.DetachedFromVisualTree += x,
x => visual.DetachedFromVisualTree -= x);
activator = activator.TakeUntil(detached);
}
//if (visual != null)
//{
// var detached = Observable.FromEventPattern<VisualTreeAttachmentEventArgs>(
// x => visual.DetachedFromVisualTree += x,
// x => visual.DetachedFromVisualTree -= x);
// activator = activator.TakeUntil(detached);
//}
foreach (var setter in Setters)
{

1
tests/Perspex.LeakTests/Perspex.LeakTests.csproj

@ -88,6 +88,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="StyleTests.cs" />
<Compile Include="ControlTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestApp.cs" />

69
tests/Perspex.LeakTests/StyleTests.cs

@ -0,0 +1,69 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.dotMemoryUnit;
using Perspex.Controls;
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
using Perspex.Styling;
using Perspex.VisualTree;
using Xunit;
using Xunit.Abstractions;
namespace Perspex.LeakTests
{
[DotMemoryUnit(FailIfRunWithoutSupport = false)]
public class StyleTests
{
public StyleTests(ITestOutputHelper atr)
{
TestApp.Initialize();
DotMemoryUnitTestOutput.SetOutputMethod(atr.WriteLine);
}
[Fact]
public void StyleActivator_Should_Be_Released()
{
Func<Window> run = () =>
{
var window = new Window
{
Styles = new Styles
{
new Style(x => x.OfType<Canvas>().Class("foo"))
{
Setters = new[]
{
new Setter(Canvas.WidthProperty, 100),
}
}
},
Content = new Canvas
{
Classes = new Classes("foo"),
}
};
// Do a layout and make sure that styled Canvas gets added to visual tree.
window.LayoutManager.ExecuteLayoutPass();
Assert.IsType<Canvas>(window.Presenter.Child);
Assert.Equal(100, (window.Presenter.Child).Width);
// Clear the content and ensure the Canvas is removed.
window.Content = null;
window.LayoutManager.ExecuteLayoutPass();
Assert.Null(window.Presenter.Child);
return window;
};
var result = run();
dotMemory.Check(memory =>
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<StyleActivator>()).ObjectsCount));
}
}
}
Loading…
Cancel
Save