Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running compat unit tests for iOS & Android #27114

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ Task("dotnet-test")
"**/Resizetizer.UnitTests.csproj",
"**/Graphics.Tests.csproj",
"**/Compatibility.Core.UnitTests.csproj",
"**/Compatibility.iOS.UnitTests.csproj",
"**/Compatibility.Android.UnitTests.csproj",
};

var success = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ public void SecondaryToolbarItemsDontChangeColor()
SetupToolBar(settings, MauiContext);
AToolBar aToolBar = settings.ToolBar;
IMenuItem menuItem = settings.MenuItemsCreated.First();

#pragma warning disable XAOBS001 // Type or member is obsolete
MenuItemImpl menuItemImpl = (MenuItemImpl)menuItem;
#pragma warning restore XAOBS001 // Type or member is obsolete
Assert.IsNotNull(menuItemImpl, "menuItem is not of type MenuItemImpl");

if (menuItemImpl.TitleFormatted is SpannableString tf)
Expand Down Expand Up @@ -202,9 +203,11 @@ public void Layout(int width = 800, int height = 200)
public Color TintColor;
public List<IMenuItem> MenuItemsCreated;

#pragma warning disable XAOBS001 // Type or member is obsolete
public IEnumerable<ActionMenuItemView> TextViews =>
ToolBar.GetChildrenOfType<ActionMenuItemView>()
.OrderBy(x => x.Text);
#pragma warning restore XAOBS001 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
<ProjectReference Include="..\..\..\Core\src\Compatibility.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\ControlGallery\src\UITests.Shared\Utilities\NumericExtensions.cs" />
<Compile Include="..\..\..\ControlGallery\src\UITests.Shared\Utilities\ParsingUtils.cs" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions src/Compatibility/Core/tests/iOS/RotationTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using static Microsoft.Maui.Controls.Compatibility.UITests.NumericExtensions;
using static Microsoft.Maui.Controls.Compatibility.UITests.ParsingUtils;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS.UnitTests
{
Expand Down
2 changes: 0 additions & 2 deletions src/Compatibility/Core/tests/iOS/ScaleTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using static Microsoft.Maui.Controls.Compatibility.UITests.NumericExtensions;
using static Microsoft.Maui.Controls.Compatibility.UITests.ParsingUtils;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS.UnitTests
{
Expand Down
2 changes: 0 additions & 2 deletions src/Compatibility/Core/tests/iOS/ShapeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using NUnit.Framework;
using ObjCRuntime;
using UIKit;
using static Microsoft.Maui.Controls.Compatibility.UITests.NumericExtensions;
using static Microsoft.Maui.Controls.Compatibility.UITests.ParsingUtils;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS.UnitTests
Expand Down
168 changes: 168 additions & 0 deletions src/Compatibility/Core/tests/iOS/Utilities/NumericExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using System;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS.UnitTests
{
internal class Matrix : Object
{
public double M00, M01, M02, M03;
public double M10, M11, M12, M13;
public double M20, M21, M22, M23;
public double M30, M31, M32, M33;

public void Log()
{

//Logger.LogLine ();

//Logger.LogLine (string.Format ("{0,-3}, {1,-3}, {2,-3}, {3,-3}", M00, M01, M02, M03));
//Logger.LogLine (string.Format ("{0,-3}, {1,-3}, {2,-3}, {3,-3}", M10, M11, M12, M13));
//Logger.LogLine (string.Format ("{0,-3}, {1,-3}, {2,-3}, {3,-3}", M20, M21, M22, M23));
//Logger.LogLine (string.Format ("{0,-3}, {1,-3}, {2,-3}, {3,-3}", M30, M31, M32, M33));

//Logger.LogLine ();
}

public override bool Equals(object obj)
{
if (obj == null)
return false;

var transform = obj as Matrix;
if (transform is null)
return false;

const double tolerance = 0.01;
bool result =
Math.Abs(M00 - transform.M00) < tolerance &&
Math.Abs(M01 - transform.M01) < tolerance &&
Math.Abs(M02 - transform.M02) < tolerance &&
Math.Abs(M03 - transform.M03) < tolerance &&
Math.Abs(M10 - transform.M10) < tolerance &&
Math.Abs(M11 - transform.M11) < tolerance &&
Math.Abs(M12 - transform.M12) < tolerance &&
Math.Abs(M13 - transform.M13) < tolerance &&
Math.Abs(M20 - transform.M20) < tolerance &&
Math.Abs(M21 - transform.M21) < tolerance &&
Math.Abs(M22 - transform.M22) < tolerance &&
Math.Abs(M23 - transform.M23) < tolerance &&
Math.Abs(M30 - transform.M30) < tolerance &&
Math.Abs(M31 - transform.M31) < tolerance &&
Math.Abs(M32 - transform.M32) < tolerance &&
Math.Abs(M33 - transform.M33) < tolerance;

return result;
}

public override int GetHashCode()
{
return 0;
}
}

internal enum Axis
{
X,
Y,
Z
}

internal static class NumericExtensions
{
public static double ToRadians(this float val)
{
return (Math.PI / 180.0) * val;
}

public static Matrix CalculateRotationMatrixForDegrees(float degrees, Axis rotationAxis)
{
var angle = degrees.ToRadians();

var transform = new Matrix();
if (rotationAxis == Axis.X)
{
transform.M00 = 1;
transform.M01 = 0;
transform.M02 = 0;
transform.M03 = 0;
transform.M10 = 0;
transform.M11 = (float)Math.Cos(angle);
transform.M12 = (float)Math.Sin(angle);
transform.M13 = 0;
transform.M20 = 0;
transform.M21 = -(float)Math.Sin(angle);
transform.M22 = (float)Math.Cos(angle);
transform.M23 = 0;
transform.M30 = 0;
transform.M31 = 0;
transform.M32 = 0;
transform.M33 = 1;
}
else if (rotationAxis == Axis.Y)
{
transform.M00 = (float)Math.Cos(angle);
transform.M01 = 0;
transform.M02 = -(float)Math.Sin(angle);
transform.M03 = 0;
transform.M10 = 0;
transform.M11 = 1;
transform.M12 = 0;
transform.M13 = 0;
transform.M20 = (float)Math.Sin(angle);
transform.M21 = 0;
transform.M22 = (float)Math.Cos(angle);
transform.M23 = 0;
transform.M30 = 0;
transform.M31 = 0;
transform.M32 = 0;
transform.M33 = 1;
}
else
{
transform.M00 = (float)Math.Cos(angle);
transform.M01 = (float)Math.Sin(angle);
transform.M02 = 0;
transform.M03 = 0;
transform.M10 = -(float)Math.Sin(angle);
transform.M11 = (float)Math.Cos(angle);
transform.M12 = 0;
transform.M13 = 0;
transform.M20 = 0;
transform.M21 = 0;
transform.M22 = 1;
transform.M23 = 0;
transform.M30 = 0;
transform.M31 = 0;
transform.M32 = 0;
transform.M33 = 1;
}

return transform;
}

public static Matrix BuildScaleMatrix(float scale)
{
var transform = new Matrix();

transform.M00 = scale;
transform.M01 = 0;
transform.M02 = 0;
transform.M03 = 0;
transform.M10 = 0;
transform.M11 = scale;
transform.M12 = 0;
transform.M13 = 0;
transform.M20 = 0;
transform.M21 = 0;
transform.M22 = scale;
transform.M23 = 0;
transform.M30 = 0;
transform.M31 = 0;
transform.M32 = 0;
transform.M33 = 1;

return transform;
}

}

}
77 changes: 77 additions & 0 deletions src/Compatibility/Core/tests/iOS/Utilities/ParsingUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS.UnitTests
{

internal static class ParsingUtils
{
public static Font ParseUIFont(string font)
{
FontAttributes fontAttrs = FontAttributes.None;

// Logger.LogLine ("TEST PARSING");

if (font.IndexOf("font-weight: bold;", StringComparison.Ordinal) != -1)
{
// Logger.LogLine ("Found Bold");
fontAttrs = FontAttributes.Bold;
}

return new Font().WithAttributes(fontAttrs);
}

public static Color ParseUIColor(string backgroundColor)
{
var delimiters = new char[] { ' ' };
string[] words = backgroundColor.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
return new Color(float.Parse(words[1]), float.Parse(words[2]), float.Parse(words[3]), float.Parse(words[4]));
}

public static Point ParseCGPoint(object CGPoint)
{
var point = new Point { X = 0, Y = 0 };
return point;
}

public static Matrix ParseCATransform3D(string CATransform3D)
{
// Logger.Log (CATransform3D);
char[] delimiters = { '[', ' ', ']', ';' };
string[] words = CATransform3D.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

List<double> numbers = new List<double>();

// Each number is represented by 2 blocks returned by server
for (int i = 0; i < words.Length; i++)
{
numbers.Add(Convert.ToDouble(words[i]));
}

var transformationMatrix = new Matrix();
transformationMatrix.M00 = numbers[0];
transformationMatrix.M01 = numbers[1];
transformationMatrix.M02 = numbers[2];
transformationMatrix.M03 = numbers[3];
transformationMatrix.M10 = numbers[4];
transformationMatrix.M11 = numbers[5];
transformationMatrix.M12 = numbers[6];
transformationMatrix.M13 = numbers[7];
transformationMatrix.M20 = numbers[8];
transformationMatrix.M21 = numbers[9];
transformationMatrix.M22 = numbers[10];
transformationMatrix.M23 = numbers[11];
transformationMatrix.M30 = numbers[12];
transformationMatrix.M31 = numbers[13];
transformationMatrix.M32 = numbers[14];
transformationMatrix.M33 = numbers[15];

return transformationMatrix;
}

}

}
Loading