forked from wieslawsoltes/Svg.Skia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61990af
commit 3837ce8
Showing
9 changed files
with
2,252 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="UITests.App" RequestedThemeVariant="Light"> | ||
<Application.Styles> | ||
<FluentTheme /> | ||
</Application.Styles> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Controls.Primitives; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace UITests | ||
{ | ||
public partial class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
desktop.MainWindow = new Window(); | ||
} | ||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} | ||
} |
1,978 changes: 1,978 additions & 0 deletions
1,978
tests/Avalonia.Svg.Skia.UnitTests/Assets/__tiger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Threading; | ||
|
||
namespace UITests | ||
{ | ||
public static class AvaloniaApp | ||
{ | ||
public static void Stop() | ||
{ | ||
var app = GetApp(); | ||
if (app is IDisposable disposable) | ||
{ | ||
Dispatcher.UIThread.Post(disposable.Dispose); | ||
} | ||
|
||
if (app != null) | ||
Dispatcher.UIThread.Post(() => app.Shutdown()); | ||
} | ||
|
||
public static Window? GetMainWindow() => GetApp()?.MainWindow; | ||
|
||
public static IClassicDesktopStyleApplicationLifetime? GetApp() => | ||
(IClassicDesktopStyleApplicationLifetime?)Application.Current?.ApplicationLifetime; | ||
|
||
public static AppBuilder BuildAvaloniaApp() => | ||
AppBuilder | ||
.Configure<App>() | ||
.UsePlatformDetect(); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
tests/Avalonia.Svg.Skia.UnitTests/AvaloniaUiTestFramework.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Avalonia; | ||
|
||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
[assembly: TestFramework("UITests.AvaloniaUiTestFramework", "Avalonia.Svg.Skia.UnitTests")] | ||
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true, MaxParallelThreads = 1)] | ||
namespace UITests | ||
{ | ||
|
||
public class AvaloniaUiTestFramework : XunitTestFramework | ||
{ | ||
public AvaloniaUiTestFramework(IMessageSink messageSink) | ||
: base(messageSink) | ||
{ | ||
} | ||
|
||
protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName) | ||
=> new Executor(assemblyName, SourceInformationProvider, DiagnosticMessageSink); | ||
|
||
private class Executor : XunitTestFrameworkExecutor | ||
{ | ||
public Executor( | ||
AssemblyName assemblyName, | ||
ISourceInformationProvider sourceInformationProvider, | ||
IMessageSink diagnosticMessageSink) | ||
: base( | ||
assemblyName, | ||
sourceInformationProvider, | ||
diagnosticMessageSink) | ||
{ | ||
|
||
} | ||
|
||
protected override async void RunTestCases(IEnumerable<IXunitTestCase> testCases, | ||
IMessageSink executionMessageSink, | ||
ITestFrameworkExecutionOptions executionOptions) | ||
{ | ||
executionOptions.SetValue("xunit.execution.DisableParallelization", false); | ||
using var assemblyRunner = new Runner( | ||
TestAssembly, testCases, DiagnosticMessageSink, executionMessageSink, | ||
executionOptions); | ||
|
||
await assemblyRunner.RunAsync(); | ||
} | ||
} | ||
|
||
private class Runner : XunitTestAssemblyRunner | ||
{ | ||
public Runner( | ||
ITestAssembly testAssembly, | ||
IEnumerable<IXunitTestCase> testCases, | ||
IMessageSink diagnosticMessageSink, | ||
IMessageSink executionMessageSink, | ||
ITestFrameworkExecutionOptions executionOptions) | ||
: base( | ||
testAssembly, | ||
testCases, | ||
diagnosticMessageSink, | ||
executionMessageSink, | ||
executionOptions) | ||
{ | ||
|
||
} | ||
|
||
public override void Dispose() | ||
{ | ||
AvaloniaApp.Stop(); | ||
|
||
base.Dispose(); | ||
} | ||
|
||
protected override void SetupSyncContext(int maxParallelThreads) | ||
{ | ||
var tcs = new TaskCompletionSource<SynchronizationContext>(); | ||
var thread = new Thread(() => | ||
{ | ||
try | ||
{ | ||
//AvaloniaApp.RegisterDependencies(); | ||
|
||
AvaloniaApp | ||
.BuildAvaloniaApp() | ||
.AfterSetup(_ => | ||
{ | ||
tcs.SetResult(SynchronizationContext.Current!); | ||
}) | ||
.StartWithClassicDesktopLifetime(new string[0]); | ||
} | ||
catch (Exception e) | ||
{ | ||
tcs.SetException(e); | ||
} | ||
}) | ||
{ | ||
IsBackground = true | ||
}; | ||
|
||
thread.Start(); | ||
|
||
SynchronizationContext.SetSynchronizationContext(tcs.Task.Result); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Avalonia.Controls; | ||
using Avalonia.Media; | ||
using Avalonia.Media.Imaging; | ||
using Avalonia.Platform; | ||
using Avalonia.Threading; | ||
using Svg.Skia; | ||
using Xunit; | ||
|
||
namespace Avalonia.Svg.Skia.UnitTests; | ||
|
||
public class SvgImageReloadTests | ||
{ | ||
Image test; | ||
private string css = ".Black { fill: #FF0000; }"; | ||
Window window; | ||
[Fact] | ||
public async void SvgImage_ReLoad() | ||
{ | ||
SKSvg.CacheOriginalStream = true; | ||
var uri = new Uri($"avares://Avalonia.Svg.Skia.UnitTests/Assets/__tiger.svg"); | ||
var assetLoader = new StandardAssetLoader(); // AvaloniaLocator.Current.GetService<IAssetLoader>() | ||
|
||
var svgFile = assetLoader.Open(uri); | ||
|
||
var svgSource = SvgSource.LoadFromStream(svgFile); | ||
var svgImage = new SvgImage() { Source = svgSource }; | ||
|
||
test = new Image(); | ||
test.Source = svgImage; | ||
|
||
window = new Window(); | ||
window.Content = test; | ||
window.Show(); | ||
|
||
var timer = new DispatcherTimer(); | ||
timer.Interval = TimeSpan.FromMilliseconds(10); | ||
timer.Tick += Timer_Tick; | ||
timer.Start(); | ||
|
||
await Task.Delay(10000); | ||
|
||
timer?.Stop(); | ||
window?.Close(); | ||
} | ||
|
||
|
||
|
||
private void Timer_Tick(object sender, EventArgs e) | ||
{ | ||
var image = (SvgImage)test.Source; | ||
(image.CurrentCss, css) = (css, image.CurrentCss); | ||
test.InvalidateVisual(); | ||
} | ||
} |