committed by
GitHub
7 changed files with 127 additions and 51 deletions
@ -0,0 +1,84 @@ |
|||
using System; |
|||
using System.Reactive.Subjects; |
|||
using JetBrains.dotMemoryUnit; |
|||
using Xunit; |
|||
using Xunit.Abstractions; |
|||
|
|||
namespace Avalonia.LeakTests |
|||
{ |
|||
public class AvaloniaObjectTests |
|||
{ |
|||
public AvaloniaObjectTests(ITestOutputHelper atr) |
|||
{ |
|||
DotMemoryUnitTestOutput.SetOutputMethod(atr.WriteLine); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Binding_To_Direct_Property_Does_Not_Get_Collected() |
|||
{ |
|||
var target = new Class1(); |
|||
|
|||
Func<WeakReference> setupBinding = () => |
|||
{ |
|||
var source = new Subject<string>(); |
|||
var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); |
|||
source.OnNext("foo"); |
|||
return new WeakReference(source); |
|||
}; |
|||
|
|||
var weakSource = setupBinding(); |
|||
|
|||
GC.Collect(); |
|||
|
|||
Assert.Equal("foo", target.Foo); |
|||
Assert.True(weakSource.IsAlive); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Binding_To_Direct_Property_Gets_Collected_When_Completed() |
|||
{ |
|||
var target = new Class1(); |
|||
|
|||
Func<WeakReference> setupBinding = () => |
|||
{ |
|||
var source = new Subject<string>(); |
|||
var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); |
|||
return new WeakReference(source); |
|||
}; |
|||
|
|||
var weakSource = setupBinding(); |
|||
|
|||
Action completeSource = () => |
|||
{ |
|||
((ISubject<string>)weakSource.Target).OnCompleted(); |
|||
}; |
|||
|
|||
completeSource(); |
|||
GC.Collect(); |
|||
|
|||
Assert.False(weakSource.IsAlive); |
|||
} |
|||
|
|||
private class Class1 : AvaloniaObject |
|||
{ |
|||
public static readonly DirectProperty<Class1, string> FooProperty = |
|||
AvaloniaProperty.RegisterDirect<Class1, string>( |
|||
"Foo", |
|||
o => o.Foo, |
|||
(o, v) => o.Foo = v, |
|||
unsetValue: "unset"); |
|||
|
|||
private string _foo = "initial2"; |
|||
|
|||
static Class1() |
|||
{ |
|||
} |
|||
|
|||
public string Foo |
|||
{ |
|||
get { return _foo; } |
|||
set { SetAndRaise(FooProperty, ref _foo, value); } |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
# !/bin/bash |
|||
|
|||
cd "$(dirname "$0")" |
|||
|
|||
tests=(Avalonia.*.UnitTests/) |
|||
exclude=("*Direct2D*/") |
|||
result=0 |
|||
|
|||
for del in ${exclude[@]}; do |
|||
tests=(${tests[@]/$del}) |
|||
done |
|||
|
|||
for test in ${tests[@]}; do |
|||
echo Running test $test |
|||
mono ../testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ${test}bin/Release/${test%/}.dll -parallel none |
|||
|
|||
if [ $? -ne 0 ]; then result=1 ; fi |
|||
done |
|||
|
|||
exit $result |
|||
Loading…
Reference in new issue