Browse Source

Demonstrate leak in test.

pull/467/head
Steven Kirk 10 years ago
parent
commit
ba008e987d
  1. 35
      tests/Perspex.LeakTests/ControlTests.cs
  2. 18
      tests/Perspex.UnitTests/TestServices.cs

35
tests/Perspex.LeakTests/ControlTests.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.dotMemoryUnit;
using Perspex.Collections;
using Perspex.Controls;
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
@ -207,6 +208,40 @@ namespace Perspex.LeakTests
}
}
[Fact]
public void TextBox_Class_Listeners_Are_Freed()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
TextBox textBox;
var window = new Window
{
Content = textBox = new TextBox()
};
// Do a layout and make sure that TextBox gets added to visual tree and its
// template applied.
LayoutManager.Instance.ExecuteInitialLayoutPass(window);
Assert.Same(textBox, window.Presenter.Child);
// Get the border from the TextBox template.
var border = textBox.GetTemplateChildren().FirstOrDefault(x => x.Name == "border");
// The TextBox should have subscriptions to its Classes collection from the
// default theme.
Assert.NotEmpty(((InccDebug)textBox.Classes).GetCollectionChangedSubscribers());
// Clear the content and ensure the TextBox is removed.
window.Content = null;
LayoutManager.Instance.ExecuteLayoutPass();
Assert.Null(window.Presenter.Child);
// Check that the TextBox has no subscriptions to its Classes collection.
Assert.Null(((InccDebug)textBox.Classes).GetCollectionChangedSubscribers());
}
}
[Fact]
public void TreeView_Is_Freed()
{

18
tests/Perspex.UnitTests/TestServices.cs

@ -6,6 +6,7 @@ using System.Reflection;
using Moq;
using Perspex.Input;
using Perspex.Layout;
using Perspex.Markup.Xaml;
using Perspex.Platform;
using Perspex.Shared.PlatformSupport;
using Perspex.Styling;
@ -26,7 +27,7 @@ namespace Perspex.UnitTests
renderInterface: s_fixture.Create<IPlatformRenderInterface>(),
standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
styler: new Styler(),
theme: () => new DefaultTheme(),
theme: () => CreateDefaultTheme(),
threadingInterface: Mock.Of<IPlatformThreadingInterface>(x => x.CurrentThreadIsLoopThread == true),
windowingPlatform: new MockWindowingPlatform());
@ -106,5 +107,20 @@ namespace Perspex.UnitTests
windowImpl: windowImpl ?? WindowImpl,
windowingPlatform: windowingPlatform ?? WindowingPlatform);
}
private static Styles CreateDefaultTheme()
{
var result = new Styles
{
new DefaultTheme(),
};
var loader = new PerspexXamlLoader();
var baseLight = (IStyle)loader.Load(
new Uri("resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"));
result.Add(baseLight);
return result;
}
}
}

Loading…
Cancel
Save