Skip to content

Commit

Permalink
Merge pull request unoplatform#6192 from unoplatform/dev/cdb-dr/calen…
Browse files Browse the repository at this point in the history
…dar-leftovers

CalendarView Leftovers
  • Loading branch information
carldebilly authored Jun 9, 2021
2 parents 6a8fb37 + daa5a16 commit f838557
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,38 +513,49 @@ private async Task ExecuteTestsForInstance(

try
{
var shouldRunIgnored = runIgnored.IsChecked ?? false;

foreach (var testMethod in tests)
{
string testName = testMethod.Name;

if (IsIgnored(testMethod, out var ignoreMessage))
{
if (shouldRunIgnored)
{
ignoreMessage = $"\n--> [Ignored] IS BYPASSED...";
}

_currentRun.Ignored++;
ReportTestResult(testName, TimeSpan.Zero, TestResult.Skipped, message: ignoreMessage);
continue;

if (!shouldRunIgnored)
{
continue;
}
}

var runsOnUIThread =
HasCustomAttribute<RunsOnUIThreadAttribute>(testMethod) ||
HasCustomAttribute<RunsOnUIThreadAttribute>(testMethod.DeclaringType);
var requiresFullWindow =
HasCustomAttribute<RequiresFullWindowAttribute>(testMethod) ||
HasCustomAttribute<RequiresFullWindowAttribute>(testMethod.DeclaringType);
var expectedException = testMethod.GetCustomAttributes<ExpectedExceptionAttribute>()
.SingleOrDefault();
var dataRows = testMethod.GetCustomAttributes<DataRowAttribute>();
if (dataRows.Any())
{
foreach (var row in dataRows)
var runsOnUIThread =
HasCustomAttribute<RunsOnUIThreadAttribute>(testMethod) ||
HasCustomAttribute<RunsOnUIThreadAttribute>(testMethod.DeclaringType);
var requiresFullWindow =
HasCustomAttribute<RequiresFullWindowAttribute>(testMethod) ||
HasCustomAttribute<RequiresFullWindowAttribute>(testMethod.DeclaringType);
var expectedException = testMethod.GetCustomAttributes<ExpectedExceptionAttribute>()
.SingleOrDefault();
var dataRows = testMethod.GetCustomAttributes<DataRowAttribute>();
if (dataRows.Any())
{
var d = row.Data;
await InvokeTestMethod(d);
foreach (var row in dataRows)
{
var d = row.Data;
await InvokeTestMethod(d);
}
}
else
{
await InvokeTestMethod(new object[0]);
}
}
else
{
await InvokeTestMethod(new object[0]);
}

async Task InvokeTestMethod(object[] parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<ToggleButton x:Name="consoleOutput"
not_skia:Content="🖥️ Console Output"
skia:Content="Console Output" />
<ToggleButton x:Name="runIgnored"
not_skia:Content="🚫 Run [Ignore]"
skia:Content="Run [Ignore]" />
</StackPanel>

<StackPanel Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static DateTimeOffset ConvertToDateTime(
{
var calendar = new Calendar
{
Era = era,
//Era = era, -- REMOVE FOR https://github.com/unoplatform/uno/issues/6160
Year = year,
Month = month,
Day = day,
Expand Down Expand Up @@ -319,7 +319,7 @@ DependencyObject GetTemplateChild(DependencyObject root, string childName)
{
var child = VisualTreeHelper.GetChild(root, i);
var childAsFE = child as FrameworkElement;
if (childAsFE.Name == childName)
if (childAsFE?.Name == childName)
{
return child;
}
Expand Down
22 changes: 18 additions & 4 deletions src/Uno.UI.RuntimeTests/IntegrationTests/common/TestServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,30 @@ public static void VERIFY_THROWS_WINRT<TExpectedException>(Action action, string
}
}

internal static void VERIFY_ARE_EQUAL<T>(T actual, T expected)
internal static void VERIFY_ARE_EQUAL<T>(T actual, T expected, string message = null)
{
//Assert.AreEqual(expected: expected, actual: actual);
actual­.Should().Be(expected);
actual­.Should().Be(expected, message);
}

internal static void VERIFY_ARE_VERY_CLOSE(double actual, double expected, double tolerance = 0.1d)
internal static void VERIFY_ARE_VERY_CLOSE(double actual, double expected, double tolerance = 0.1d, string message = null)
{
var difference = Math.Abs(actual - expected);
Assert.IsTrue(difference <= tolerance, $"Expected <{expected}>, actual <{actual}> (tolerance = {tolerance})");
Assert.IsTrue(difference <= tolerance, $"Expected <{expected}>, actual <{actual}> (tolerance = {tolerance}) {message}");
}

internal static void VERIFY_DATES_ARE_EQUAL(DateTimeOffset actual, DateTimeOffset expected, string message = null)
{
actual.Date.Should().Be(expected.Date, message);
}

internal static void VERIFY_DATES_ARE_EQUAL(long actualTicks, long expectedTicks, string message = null)
{
VERIFY_DATES_ARE_EQUAL(
new DateTimeOffset(actualTicks, TimeSpan.Zero),
new DateTimeOffset(expectedTicks, TimeSpan.Zero),
message);

}

internal static void LOG_OUTPUT(string log, params object[] arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ protected static void VERIFY_IS_FALSE(bool value, string message = null)
TestServices.VERIFY_IS_FALSE(value, message);
}

protected static void VERIFY_ARE_EQUAL<T>(T actual, T expected)
protected static void VERIFY_ARE_EQUAL<T>(T actual, T expected, string message = null)
{
TestServices.VERIFY_ARE_EQUAL(actual, expected);
TestServices.VERIFY_ARE_EQUAL(actual, expected, message);
}

protected static void VERIFY_IS_NULL(object value)
Expand Down
59 changes: 22 additions & 37 deletions src/Uno.UI.RuntimeTests/IntegrationTests/dxaml/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,47 @@ namespace Windows.UI.Xaml.Tests.Enterprise
{
internal class Event
{
private readonly ManualResetEventSlim _event = new ManualResetEventSlim();

internal int FiredCount { get; private set; }

private TaskCompletionSource<bool> _tcs;

internal async Task<bool> WaitForDefault(int timeout = 5000, CancellationToken ct = default)
{
var h = _event.WaitHandle;
RegisteredWaitHandle registration = default;
try
{
if (h.WaitOne(0))
{
return true;
}
var tcs = EnsureTcs();

if (timeout == 0)
{
return false;
}
var timeoutTask = Task.Delay(timeout, ct);

var tcs = new TaskCompletionSource<bool>();
var winningTask = await Task.WhenAny(timeoutTask, tcs.Task);

using var _ = ct.Register(() => tcs.TrySetCanceled());

registration = ThreadPool
.RegisterWaitForSingleObject(
h,
(_, __) =>
{
tcs.TrySetResult(true);
},
null,
timeout,
executeOnlyOnce: true);

return await tcs.Task;
}
finally
if (winningTask == timeoutTask)
{
registration?.Unregister(h);
return false;
}

return await tcs.Task;
}

private TaskCompletionSource<bool> EnsureTcs()
{
var newTcs = new TaskCompletionSource<bool>();
var tcs = Interlocked.CompareExchange(ref _tcs, newTcs, null) ?? newTcs;
return tcs;
}

internal void Set()
{
EnsureTcs().TrySetResult(true);
FiredCount++;
_event.Set();
}

internal bool HasFired() => _event.IsSet;

public void Reset()
internal bool HasFired()
{
_event.Reset();
var tcs = _tcs;
return tcs != null && tcs.Task.IsCompleted;
}

public void Reset() => Interlocked.Exchange(ref _tcs, null)?.TrySetCanceled();

public Task WaitFor(TimeSpan timeout, CancellationToken ct = default)
{
return WaitForDefault((int)timeout.TotalMilliseconds, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
namespace Windows.UI.Xaml.Tests.Enterprise.CalendarDatePickerTests
{
[TestClass]
[Ignore("Validating regressions only for now")]
public partial class CalendarDatePickerIntegrationTests : BaseDxamlTestClass
{
[ClassInitialize]
Expand Down Expand Up @@ -184,6 +183,7 @@ await RunOnUIThread(() =>


[TestMethod]
[Ignore("UNO TODO - TestServices.KeyboardHelper not implemented yet.")]
public async Task CanOpenFlyoutByKeyboard()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -398,23 +398,24 @@ await RunOnUIThread(() =>
await RunOnUIThread(() =>
{
VERIFY_IS_NOT_NULL(cp.Date);
VERIFY_ARE_EQUAL(cp.Date.Value.UniversalTime(), ConvertToDateTime(1, 2001, 1, 1).UniversalTime());
VERIFY_DATES_ARE_EQUAL(cp.Date.Value.UniversalTime(), ConvertToDateTime(1, 2001, 1, 1).UniversalTime());

// make date beyond the range.
// it should be coerced to min/max
cp.Date = ConvertToDateTime(1, 2010, 1, 1);
cp.UpdateLayout();
VERIFY_IS_NOT_NULL(cp.Date);
VERIFY_ARE_EQUAL(cp.Date.Value.UniversalTime(), cp.MaxDate.UniversalTime());
VERIFY_DATES_ARE_EQUAL(cp.Date.Value.UniversalTime(), cp.MaxDate.UniversalTime());

cp.Date = ConvertToDateTime(1, 1999, 1, 1);
cp.UpdateLayout();
VERIFY_IS_NOT_NULL(cp.Date);
VERIFY_ARE_EQUAL(cp.Date.Value.UniversalTime(), cp.MinDate.UniversalTime());
VERIFY_DATES_ARE_EQUAL(cp.Date.Value.UniversalTime(), cp.MinDate.UniversalTime());
});
}

[TestMethod]
[Ignore("UNO TODO - Calendar formatting is still not properly implemented")]
public async Task CanFormatDate()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -455,11 +456,12 @@ await RunOnUIThread(() =>
cp.UpdateLayout();

LOG_OUTPUT("actual text: %s.", dateText.Text);
VERIFY_IS_TRUE(dateText.Text == "Monday, January 1, 2001");
VERIFY_ARE_EQUAL(dateText.Text, "Monday, January 1, 2001");
});
}

[TestMethod]
[Ignore("UNO TODO - Fix custom date formatting")]
public async Task SettingCalendarIdentifierChangesDateFormat()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -580,6 +582,7 @@ await RunOnUIThread(() =>
}

[TestMethod]
[Ignore("Asserts")]
public async Task ValidateUIElementTree()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -622,6 +625,7 @@ await RunOnUIThread(() =>
}

[TestMethod]
[Ignore("Assert errors in tests")]
public async Task ValidateVisualStates()
{
//WUCRenderingScopeGuard guard(DCompRendering.WUCCompleteSynchronousCompTree, false /* resizeWindow */);
Expand Down Expand Up @@ -696,6 +700,7 @@ await RunOnUIThread(() =>

#if !WINDOWS_UWP
[TestMethod]
[Ignore("Causing bugs in asserts")]
public async Task DonotResizeCalendarView()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -741,6 +746,7 @@ await RunOnUIThread(() =>
#endif

[TestMethod]
[Ignore("Asserts")]
public async Task CanPresetDate()
{
TestCleanupWrapper cleanup;
Expand Down Expand Up @@ -793,7 +799,7 @@ await RunOnUIThread(() =>
VERIFY_IS_TRUE(dateText.Text == "‎10‎/‎21‎/‎2000");

VERIFY_ARE_EQUAL(calendarView.SelectedDates.Count, 1);
VERIFY_ARE_EQUAL(calendarView.SelectedDates.GetAt(0).UniversalTime(), date1.UniversalTime());
VERIFY_DATES_ARE_EQUAL(calendarView.SelectedDates.GetAt(0).UniversalTime(), date1.UniversalTime());
});

await TestServices.WindowHelper.WaitForIdle();
Expand Down Expand Up @@ -832,7 +838,7 @@ await RunOnUIThread(() =>
VERIFY_IS_TRUE(dateText.Text == "‎1‎/‎1‎/‎2003");

VERIFY_ARE_EQUAL(calendarView.SelectedDates.Count, 1);
VERIFY_ARE_EQUAL(calendarView.SelectedDates.GetAt(0).UniversalTime(), date2.UniversalTime());
VERIFY_DATES_ARE_EQUAL(calendarView.SelectedDates.GetAt(0).UniversalTime(), date2.UniversalTime());

cp.IsCalendarOpen = false;
});
Expand Down Expand Up @@ -876,12 +882,12 @@ await RunOnUIThread(() =>
// we can't test the scenario that cdp1.Date is null
CalendarHelper.DumpDate(cdp1.Date.Value, "Changing cdp1.Date to");
CalendarHelper.DumpDate(cdp2.Date.Value, "Now cdp2.Date is");
VERIFY_ARE_EQUAL(cdp1.Date.Value.UniversalTime(), cdp2.Date.Value.UniversalTime());
VERIFY_DATES_ARE_EQUAL(cdp1.Date.Value.UniversalTime(), cdp2.Date.Value.UniversalTime());

cdp2.Date = date2;
CalendarHelper.DumpDate(cdp2.Date.Value, "Changing cdp2.Date to");
CalendarHelper.DumpDate(cdp1.Date.Value, "Now cdp1.Date is");
VERIFY_ARE_EQUAL(cdp1.Date.Value.UniversalTime(), cdp2.Date.Value.UniversalTime());
VERIFY_DATES_ARE_EQUAL(cdp1.Date.Value.UniversalTime(), cdp2.Date.Value.UniversalTime());
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
namespace Windows.UI.Tests.Enterprise.CalendarViewTests
{
[TestClass]
[Ignore("Validating regressions only for now")]
public class CalendarViewAutomationPeerIntegrationTests : BaseDxamlTestClass
{
// PeerFromProvider is protected even though conceptually it's a static method.
Expand Down
Loading

0 comments on commit f838557

Please sign in to comment.