Skip to content

Commit

Permalink
[release/9.0.1xx-preview7] Obsolete legacy measure calls (#23948)
Browse files Browse the repository at this point in the history
* Obsolete legacy measure calls

* - no warn

* - fix more no warn

* - more no warn

---------

Co-authored-by: Shane Neuville <[email protected]>
  • Loading branch information
github-actions[bot] and PureWeen authored Jul 31, 2024
1 parent 2317e1a commit 62197f4
Show file tree
Hide file tree
Showing 82 changed files with 1,015 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<!--<DefineConstants>$(DefineConstants);HAVE_OPENTK</DefineConstants>-->
<NoWarn>IL2036;0618;0612</NoWarn>
<NoWarn>IL2036;0618;0612;CS0672;CS0618</NoWarn>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Microsoft.Maui.Controls.Compatibility.ControlGallery</AssemblyName>
<RootNamespace>Microsoft.Maui.Controls.Compatibility.ControlGallery</RootNamespace>
<WarningLevel>4</WarningLevel>
<NoWarn>0114;0108;0109;4014;0649;0169;0472;0414;0168;0219;0429;0618;0612</NoWarn>
<NoWarn>0114;0108;0109;4014;0649;0169;0472;0414;0168;0219;0429;0618;0612;CS0672;CS0618</NoWarn>
<WarningsNotAsErrors>$(WarningsNotAsErrors);XC0022;XC0023</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Compatibility/ControlGallery/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<SampleProject>true</SampleProject>
<UseMaui Condition=" '$(UseWorkload)' == 'true' ">true</UseMaui>
<DefaultXamlRuntime Condition=" '$(UseWorkload)' != 'true' ">Maui</DefaultXamlRuntime>
<NoWarn>$(NoWarn);CS0672;CS0618</NoWarn>
</PropertyGroup>
<Import Project="../../../../Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>disable</Nullable>
<!--<DefineConstants>$(DefineConstants);HAVE_OPENTK</DefineConstants>-->
<!--<MtouchLink Condition="'$(CI)' == 'true'">Full</MtouchLink>-->
<NoWarn>0612</NoWarn>
<NoWarn>0612;CS0672;CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
<RootNamespace>Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<NoWarn>1701;1702;CS8305;8305;CA1416;0612</NoWarn>
<NoWarn>1701;1702;CS8305;8305;CA1416;0612;CS0672;CS0618</NoWarn>
<EnableDefaultPageItems>true</EnableDefaultPageItems>
<EnableDefaultXamlItems>false</EnableDefaultXamlItems>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>disable</Nullable>
<!--<DefineConstants>$(DefineConstants);HAVE_OPENTK</DefineConstants>-->
<!--<MtouchLink Condition="'$(CI)' == 'true'">Full</MtouchLink>-->
<NoWarn>0612</NoWarn>
<NoWarn>0612;CS0672;CS0618</NoWarn>
<SupportedOSPlatformVersion>15.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion>15.0</TargetPlatformMinVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<DefineConstants>$(DefineConstants);__ANDROID__;UITEST;__SHELL__;ANDROID</DefineConstants>
<NoWarn>1701;1702;0618;0612;CA1307;CA1309</NoWarn>
<NoWarn>1701;1702;0618;0612;CA1307;CA1309;CS0672;CS0618</NoWarn>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<DefineConstants>$(DefineConstants);WINDOWS;UITEST</DefineConstants>
<NoWarn>0114;0108;4014;0649;0169;0168;0219;0618;0612;CA1307;CA1309</NoWarn>
<NoWarn>0114;0108;4014;0649;0169;0168;0219;0618;0612;CA1307;CA1309;CS0672;CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<Nullable>disable</Nullable>
<DefineConstants>$(DefineConstants);__IOS__;UITEST;__SHELL__;IOS;iOS</DefineConstants>
<NoWarn>1701;1702;0618;0612;CA1307;CA1309</NoWarn>
<NoWarn>1701;1702;0618;0612;CA1307;CA1309;CS0672;CS0618</NoWarn>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Compatibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<IsAotCompatible Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsAotCompatible>
<MauiGenerateResourceDesigner>true</MauiGenerateResourceDesigner>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn);CS1591;CS0672;CS0618</NoWarn>
<DefineConstants>$(DefineConstants);COMPATIBILITY</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Globalization;
using System.Threading;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.UnitTests;
using Xunit;

// By default, xUnit will run test collections (the tests in each class) in parallel
// with other test collections. Unfortunately, a _ton_ of the Controls legacy tests
// interact with properties on static classes (e.g., Application.Current), and if we
// let them run in parallel they'll step on one another. So we tell xUnit to consider
// the whole assembly as a single collection for now, so all the tests run in sequence.
// (Hopefully in the future we can untangle some of the singletons and run these in parallel,
// because it'll be a lot faster.)
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]

namespace Microsoft.Maui.Controls.Core.UnitTests
{
public class BaseTestFixture : IDisposable
{
CultureInfo _defaultCulture;
CultureInfo _defaultUICulture;

public BaseTestFixture()
{
Microsoft.Maui.Controls.Hosting.CompatibilityCheck.UseCompatibility();
_defaultCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
_defaultUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
DeviceDisplay.SetCurrent(null);
DeviceInfo.SetCurrent(null);
AppInfo.SetCurrent(null);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

bool _disposed;

protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}

if (disposing)
{
AppInfo.SetCurrent(null);
DeviceDisplay.SetCurrent(null);
DeviceInfo.SetCurrent(null);
System.Threading.Thread.CurrentThread.CurrentCulture = _defaultCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = _defaultUICulture;
DispatcherProvider.SetCurrent(null);
}

_disposed = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void TestFlexDirectionColumnWithoutHeight()
Direction = FlexDirection.Column,
};

var sizeRequest = layout.Measure(100, double.PositiveInfinity);
var sizeRequest = layout.Measure(100, double.PositiveInfinity, MeasureFlags.None);
layout.Layout(new Rect(0, 0, sizeRequest.Request.Width, sizeRequest.Request.Height));
Assert.Equal(layout.Bounds, new Rect(0, 0, 100, 30));
Assert.Equal(view0.Bounds, new Rect(0, 0, 100, 10));
Expand All @@ -56,7 +56,7 @@ public void TestFlexDirectionRowNoWidth()
};


var measure = layout.Measure(double.PositiveInfinity, 100);
var measure = layout.Measure(double.PositiveInfinity, 100, MeasureFlags.None);
layout.Layout(new Rect(0, 0, measure.Request.Width, measure.Request.Height));
Assert.Equal(layout.Bounds, new Rect(0, 0, 30, 100));
Assert.Equal(view0.Bounds, new Rect(0, 0, 10, 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ public void TestSizeThatFits()
layout.Children.Add(label2);
layout.Layout(new Rect(0, 0, 320, 50));

var label2Size = label2.Measure(double.PositiveInfinity, double.PositiveInfinity);
var label2Size = label2.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.None);
Assert.Equal(10, label2Size.Request.Height);
Assert.Equal(10, label2Size.Request.Width);

var label1Size = label1.Measure(double.PositiveInfinity, double.PositiveInfinity);
var label1Size = label1.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.None);
// var layoutSize = layout.Measure(-1, -1);
}

Expand Down Expand Up @@ -331,15 +331,15 @@ public void TestMeasuring()
};

//measure sith +inf as main-axis
var measure = Layout.Measure(double.PositiveInfinity, 40);
var measure = Layout.Measure(double.PositiveInfinity, 40, MeasureFlags.None);
Assert.Equal(measure.Request, new Size(100, 40));

//measure sith +inf as cross-axis
measure = Layout.Measure(200, double.PositiveInfinity);
measure = Layout.Measure(200, double.PositiveInfinity, MeasureFlags.None);
Assert.Equal(measure.Request, new Size(200, 20));

//measure with +inf as both axis
measure = Layout.Measure(double.PositiveInfinity, double.PositiveInfinity);
measure = Layout.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.None);
Assert.Equal(measure.Request, new Size(100, 20));

}
Expand Down Expand Up @@ -370,7 +370,7 @@ public void TestMarginsWithWrap()
}
};

var measure = layout.Measure(300, double.PositiveInfinity);
var measure = layout.Measure(300, double.PositiveInfinity, MeasureFlags.None);
Assert.Equal(measure.Request, new Size(300, 52));
layout.Layout(new Rect(0, 0, 300, 300));
Assert.Equal(label0.Bounds, new Rect(6, 6, 138, 20));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Linq;
using Microsoft.Maui.Graphics;
using Xunit;


namespace Microsoft.Maui.Controls.Core.UnitTests;

public class FrameUnitTests : BaseTestFixture
{
[Fact]
public void TestPackWithoutChild()
{
Frame frame = new Frame();

var parent = new NaiveLayout();

bool thrown = false;
try
{
parent.Children.Add(frame);
}
catch
{
thrown = true;
}

Assert.False(thrown);
}

[Fact]
public void TestPackWithChild()
{
Frame frame = new Frame
{
Content = new View()
};

var parent = new NaiveLayout();

bool thrown = false;
try
{
parent.Children.Add(frame);
}
catch
{
thrown = true;
}

Assert.False(thrown);
}
}
Loading

0 comments on commit 62197f4

Please sign in to comment.