Browse Source

Added failing Carousel leak test.

As found by @donandren.
pull/366/head
Steven Kirk 11 years ago
parent
commit
dc757851c1
  1. 12
      tests/Perspex.LeakTests/ControlTests.cs
  2. 59
      tests/Perspex.LeakTests/StyleTests.cs

12
tests/Perspex.LeakTests/ControlTests.cs

@ -269,12 +269,12 @@ namespace Perspex.LeakTests
Content = target = new TreeView
{
DataTemplates = new DataTemplates
{
new FuncTreeDataTemplate<Node>(
x => new TextBlock { Text = x.Name },
x => x.Children,
x => true)
},
{
new FuncTreeDataTemplate<Node>(
x => new TextBlock { Text = x.Name },
x => x.Children,
x => true)
},
Items = nodes
}
};

59
tests/Perspex.LeakTests/StyleTests.cs

@ -65,5 +65,64 @@ namespace Perspex.LeakTests
dotMemory.Check(memory =>
Assert.Equal(0, memory.GetObjects(where => where.Type.Is<StyleActivator>()).ObjectsCount));
}
[Fact]
public void Changing_Carousel_SelectedIndex_Should_Not_Leak_StyleActivators()
{
Func<Window> run = () =>
{
Carousel target;
var window = new Window
{
Styles = new Styles
{
new Style(x => x.OfType<ContentControl>().Class("foo"))
{
Setters = new[]
{
new Setter(Visual.OpacityProperty, 0.5),
}
}
},
Content = target = new Carousel
{
Items = new[]
{
new ContentControl
{
Name = "item1",
Classes = new Classes("foo"),
Content = "item1",
},
new ContentControl
{
Name = "item2",
Classes = new Classes("foo"),
Content = "item2",
},
}
}
};
// Do a layout and make sure that Carousel gets added to visual tree.
window.LayoutManager.ExecuteLayoutPass();
Assert.IsType<Carousel>(window.Presenter.Child);
target.SelectedIndex = 1;
window.LayoutManager.ExecuteLayoutPass();
target.SelectedIndex = 0;
window.LayoutManager.ExecuteLayoutPass();
target.SelectedIndex = 1;
window.LayoutManager.ExecuteLayoutPass();
return window;
};
var result = run();
dotMemory.Check(memory =>
Assert.Equal(1, memory.GetObjects(where => where.Type.Is<StyleActivator>()).ObjectsCount));
}
}
}

Loading…
Cancel
Save