Skip to content

Commit

Permalink
Added unit tests for ExpressionFunctions.ColorLerpRgb and ColorLerpHsl
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe committed Jan 9, 2024
1 parent 0637901 commit e33f6dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/Animations/tests/Animations.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Test_AnimationBuilderStart.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_ExpressionFunctions.cs" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion components/Animations/tests/Test_AnimationBuilderStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace AnimationsExperiment.Tests;

[TestClass]
[TestCategory("Test_AnimationBuilderStart")]
[TestCategory(nameof(Test_AnimationBuilderStart))]
public class Test_AnimationBuilderStart : VisualUITestBase
{
[TestMethod]
Expand Down
59 changes: 59 additions & 0 deletions components/Animations/tests/Test_ExpressionFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if WINUI2
using Windows.UI.Composition;
using Windows.UI.Xaml.Hosting;
#elif WINUI3
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Hosting;
#endif

using System.Numerics;
using CommunityToolkit.Tests;
using CommunityToolkit.Tooling.TestGen;
using CommunityToolkit.WinUI.Animations.Expressions;

namespace AnimationsExperiment.Tests;

[TestClass]
[TestCategory(nameof(Test_ExpressionFunctions))]
public partial class Test_ExpressionFunctions : VisualUITestBase
{
[UIThreadTestMethod]
public void ColorLerpRgb(Grid rootGrid)
{
// See https://github.com/CommunityToolkit/Windows/issues/303
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
var brush = compositor.CreateColorBrush();
var temp = ExpressionFunctions.ColorRgb(255f, 255f, 0f, 0f);
var color = ExpressionFunctions.ColorLerpRgb(temp, temp, 0.5f);

brush.StartAnimation("Color", color);

var visual = compositor.CreateSpriteVisual();
visual.Brush = brush;
visual.RelativeSizeAdjustment = Vector2.One;

ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
}

[UIThreadTestMethod]
public void ColorLerpHsl(Grid rootGrid)
{
// See https://github.com/CommunityToolkit/Windows/issues/303
var compositor = ElementCompositionPreview.GetElementVisual(rootGrid).Compositor;
var brush = compositor.CreateColorBrush();
var temp = ExpressionFunctions.ColorHsl(255f, 255f, 0f);
var color = ExpressionFunctions.ColorLerpHsl(temp, temp, 0.5f);

brush.StartAnimation("Color", color);

var visual = compositor.CreateSpriteVisual();
visual.Brush = brush;
visual.RelativeSizeAdjustment = Vector2.One;

ElementCompositionPreview.SetElementChildVisual(rootGrid, visual);
}
}

0 comments on commit e33f6dd

Please sign in to comment.