Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using SizeBench.GUI.Controls;

namespace SizeBench.GUI.Converters.Tests;
#nullable disable // WPF's IValueConverter is not correctly nullable-annotated, so we disable nullable for the source and tests of the value converters.
Expand All @@ -11,10 +12,10 @@ public void TargetTypeMustBeObject()
=> Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { 5 }, typeof(int), null /* ConverterParameter */, null /* CultureInfo */));

[TestMethod]
public void MoreThanTwoInputsNotAccepted()
public void MoreThanThreeInputsNotAccepted()
{
Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { "disasm 1", "disasm 2", "disasm 3" }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */));
Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { "disasm 1", "disasm 2", "disasm 3", "disasm 4" }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */));
Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { "disasm 1", "disasm 2", "disasm 3", "disasm 4", "disasm 5" }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */));
}

[TestMethod]
Expand All @@ -34,6 +35,10 @@ public void IfEitherInputIsNotAStringThrow()
Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { 0.8f, "disasm 2" }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */));
}

[TestMethod]
public void ThirdArgumentMustBeZoomPercentInt()
=> Assert.ThrowsExactly<ArgumentException>(() => TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { "disasm 1", "disasm 2", "100" }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */));

[TestMethod]
public void IfBothInputsAreStringsReturnsSomething()
{
Expand All @@ -45,4 +50,11 @@ public void IfBothInputsAreStringsReturnsSomething()
[TestMethod]
public void ConvertBackThrows()
=> Assert.ThrowsExactly<NotImplementedException>(() => TwoStringsToDiffViewerUIConverter.Instance.ConvertBack(new FrameworkElement(), new Type[] { typeof(string), typeof(string) }, null /* ConverterParameter */, null /* CultureInfo */));

[TestMethod]
public void ThirdArgumentControlsFontSize()
{
var diffViewer = (SelectableDiffViewer)TwoStringsToDiffViewerUIConverter.Instance.Convert(new object[] { "disasm 1", "disasm 2", 120 }, typeof(object), null /* ConverterParameter */, null /* CultureInfo */);
Assert.AreEqual(19.2, diffViewer.EffectiveFontSize, 0.001);
}
}
33 changes: 33 additions & 0 deletions src/SizeBench.GUI.Tests/DisassemblySettingsStoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.IO;
using SizeBench.TestInfrastructure;

namespace SizeBench.GUI.Tests;

[TestClass]
public sealed class DisassemblySettingsStoreTests
{
[TestMethod]
public void ZoomPercentPersistsAcrossStoreInstances()
{
var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDirectory);

try
{
var storagePath = Path.Combine(tempDirectory, "DisassemblySettings.json");
using var logger = new TestNoOpApplicationLogger();
var store = new DisassemblySettingsStore(logger, storagePath);

Assert.AreEqual(DisassemblySettingsStore.DefaultZoomPercent, store.TemplateFoldabilityDisassemblyZoomPercent);

store.TemplateFoldabilityDisassemblyZoomPercent = 140;

var reloadedStore = new DisassemblySettingsStore(logger, storagePath);
Assert.AreEqual(140, reloadedStore.TemplateFoldabilityDisassemblyZoomPercent);
}
finally
{
Directory.Delete(tempDirectory, recursive: true);
}
}
}
185 changes: 176 additions & 9 deletions src/SizeBench.GUI.Tests/MainWindowViewModelTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public async Task SymbolsInitializeWhenTabSelected()
await tcsTestResultsComplete.Task;

Assert.AreSequenceEqual(allSymbolDiffsInBinarySection, viewmodel.Symbols, Microsoft.VisualStudio.TestTools.UnitTesting.SequenceOrder.InAnyOrder);
Assert.AreEqual(allSymbolDiffsInBinarySection.Count, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());

// We should have started 2 long-running tasks, one for the binary section load and one for the symbols
this.MockUITaskScheduler.Verify(uits => uits.StartLongRunningUITask(It.IsAny<string>(), It.IsAny<Func<CancellationToken, Task>>()), Times.Exactly(2));
Expand Down Expand Up @@ -336,7 +337,10 @@ public async Task ExcelExportWorksForEveryTab()
viewmodel.SelectedTab = (int)BinarySectionPageViewModel.BinarySectionPageTabIndex.SymbolsTab;
Assert.IsTrue(viewmodel.ExportSymbolsToExcelCommand.CanExecute());
viewmodel.ExportSymbolsToExcelCommand.Execute();
this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object, allSymbolDiffsInBinarySection), Times.Exactly(1));
this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object,
It.Is<IReadOnlyList<SymbolDiff>>(symbols => symbols.Count == allSymbolDiffsInBinarySection.Count &&
!symbols.Except(allSymbolDiffsInBinarySection).Any())),
Times.Exactly(1));
}

public void Dispose() => this.TestDataGenerator.Dispose();
Expand Down
63 changes: 62 additions & 1 deletion src/SizeBench.GUI.Tests/Pages/COFFGroupDiffPageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task AssertInitialStateThenFillInAsyncLoads(COFFGroupDiffPageViewM
sawCompilandsPropertyChange &&
sawLibsPropertyChange)
{
tcsTestResultsComplete.SetResult(new object());
tcsTestResultsComplete.TrySetResult(new object());
}
};

Expand Down Expand Up @@ -153,6 +153,7 @@ await AssertInitialStateThenFillInAsyncLoads(viewmodel,
Assert.AreEqual("COFFGroupContributionDiffsByName[.text$mn].SizeDiff", viewmodel.ContributionSizeSortMemberPath);
Assert.AreEqual("COFFGroupContributionDiffsByName[.text$mn].VirtualSizeDiff", viewmodel.ContributionVirtualSizeSortMemberPath);
Assert.IsTrue(ReferenceEquals(symbolList, viewmodel.SymbolDiffs));
Assert.AreEqual(symbolList.Count, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());

// Verify libs are filtered to the CG
Assert.HasCount(4, this.TestDataGenerator.LibDiffs);
Expand All @@ -168,6 +169,66 @@ await AssertInitialStateThenFillInAsyncLoads(viewmodel,

[Timeout(5 * 1000, CooperativeCancellation = true)]
[TestMethod]
public async Task SymbolFiltersCanShowBaselineOnlyUpdateOnlyAndModified()
{
var textMnCGDiff = this.TestDataGenerator.TextMnCGDiff;
var viewmodel = CreateViewmodelForTesting(textMnCGDiff,
out var tcsTestResultsComplete,
out var symbolList,
out var tcsCOFFGroupReady,
out var tcsSymbolsReady,
out var tcsLibsReady,
out var tcsCompilandsReady);

viewmodel.SetQueryString(new Dictionary<string, string>()
{
{ "COFFGroup", ".text$mn" }
});

var initTask = viewmodel.InitializeAsync();

await AssertInitialStateThenFillInAsyncLoads(viewmodel,
tcsTestResultsComplete,
symbolList,
tcsCOFFGroupReady,
tcsSymbolsReady,
tcsLibsReady,
tcsCompilandsReady);

await initTask;

var baselineOnlyCount = symbolList.Count(sd => sd.BeforeSymbol != null && sd.AfterSymbol is null);
var updateOnlyCount = symbolList.Count(sd => sd.BeforeSymbol is null && sd.AfterSymbol != null);
var modifiedCount = symbolList.Count(sd => sd.BeforeSymbol != null && sd.AfterSymbol != null && (sd.SizeDiff != 0 || sd.VirtualSizeDiff != 0));
var identicalCount = symbolList.Count(sd => sd.BeforeSymbol != null && sd.AfterSymbol != null && sd.SizeDiff == 0 && sd.VirtualSizeDiff == 0);

viewmodel.IncludeModifiedSymbols = false;
viewmodel.IncludeSymbolsOnlyInUpdate = false;
CollectionAssert.AreEquivalent(symbolList.Where(sd => sd.BeforeSymbol != null && sd.AfterSymbol is null).ToList(),
viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().ToList());
Assert.AreEqual(baselineOnlyCount, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());

viewmodel.IncludeSymbolsOnlyInBaseline = false;
viewmodel.IncludeModifiedSymbols = true;
CollectionAssert.AreEquivalent(symbolList.Where(sd => sd.BeforeSymbol != null && sd.AfterSymbol != null).ToList(),
viewmodel.FilteredSymbolDiffs.Cast<SymbolDiff>().ToList());
Assert.AreEqual(modifiedCount, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());

viewmodel.IncludeModifiedSymbols = false;
viewmodel.IncludeIdenticalSymbols = true;
CollectionAssert.AreEquivalent(symbolList.Where(sd => sd.BeforeSymbol != null && sd.AfterSymbol != null && sd.SizeDiff == 0 && sd.VirtualSizeDiff == 0).ToList(),
viewmodel.FilteredSymbolDiffs.Cast<SymbolDiff>().ToList());
Assert.AreEqual(identicalCount, viewmodel.FilteredSymbolDiffs.Cast<SymbolDiff>().Count());

viewmodel.IncludeIdenticalSymbols = false;
viewmodel.IncludeSymbolsOnlyInUpdate = true;
CollectionAssert.AreEquivalent(symbolList.Where(sd => sd.BeforeSymbol is null && sd.AfterSymbol != null).ToList(),
viewmodel.FilteredSymbolDiffs.Cast<SymbolDiff>().ToList());
Assert.AreEqual(updateOnlyCount, viewmodel.FilteredSymbolDiffs.Cast<SymbolDiff>().Count());
}

[Timeout(5 * 1000)]
[TestMethod]
public async Task CancelingSymbolLoadingIsFine()
{
var textMnCGDiff = this.TestDataGenerator.TextMnCGDiff;
Expand Down
17 changes: 12 additions & 5 deletions src/SizeBench.GUI.Tests/Pages/CompilandDiffPageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ public async Task SymbolsInitializeAsync()
});
var initTask = viewmodel.InitializeAsync();

var propertyNameResult = String.Empty;
var sawSymbolDiffsPropertyChange = false;

viewmodel.PropertyChanged += (s, e) =>
{
propertyNameResult = e.PropertyName;
tcsTestResultsComplete.SetResult(new object());
if (e.PropertyName == nameof(CompilandDiffPageViewModel.SymbolDiffs))
{
sawSymbolDiffsPropertyChange = true;
tcsTestResultsComplete.TrySetResult(new object());
}
};

tcsSymbolsReady.SetResult(allSymbolsInCompilandDiff);
await tcsTestResultsComplete.Task;
await initTask;

Assert.AreEqual(nameof(CompilandDiffPageViewModel.SymbolDiffs), propertyNameResult);
Assert.IsTrue(sawSymbolDiffsPropertyChange);
Assert.AreSequenceEqual(allSymbolsInCompilandDiff, viewmodel.SymbolDiffs!.ToList());
Assert.AreEqual(allSymbolsInCompilandDiff.Count, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());
}

[Timeout(1000 * 5, CooperativeCancellation = true)] // 5s
Expand Down Expand Up @@ -93,7 +97,10 @@ public async Task CanExportSymbolsToExcel()

viewmodel.ExportSymbolsToExcelCommand.Execute();

this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object, allSymbolsInCompilandDiff), Times.Exactly(1));
this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object,
It.Is<IReadOnlyList<SymbolDiff>>(symbols => symbols.Count == allSymbolsInCompilandDiff.Count &&
!symbols.Except(allSymbolsInCompilandDiff).Any())),
Times.Exactly(1));
}

public void Dispose() => this.TestDataGenerator.Dispose();
Expand Down
17 changes: 12 additions & 5 deletions src/SizeBench.GUI.Tests/Pages/LibDiffPageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ public async Task SymbolsInitializeAsyncFromConstruction()
});
var initTask = viewmodel.InitializeAsync();

var propertyNameResult = String.Empty;
var sawSymbolDiffsPropertyChange = false;

viewmodel.PropertyChanged += (s, e) =>
{
propertyNameResult = e.PropertyName;
tcsTestResultsComplete.SetResult(new object());
if (e.PropertyName == nameof(LibDiffPageViewModel.SymbolDiffs))
{
sawSymbolDiffsPropertyChange = true;
tcsTestResultsComplete.TrySetResult(new object());
}
};

tcsSymbolsReady.SetResult(allSymbolDiffsInLibDiff);
await tcsTestResultsComplete.Task;
await initTask;

Assert.AreEqual(nameof(LibDiffPageViewModel.SymbolDiffs), propertyNameResult);
Assert.IsTrue(sawSymbolDiffsPropertyChange);
Assert.AreSequenceEqual(allSymbolDiffsInLibDiff, viewmodel.SymbolDiffs!.ToList());
Assert.AreEqual(allSymbolDiffsInLibDiff.Count, viewmodel.FilteredSymbolDiffs!.Cast<SymbolDiff>().Count());
}

[Timeout(1000 * 5, CooperativeCancellation = true)] // 5s
Expand Down Expand Up @@ -90,7 +94,10 @@ public async Task CanExportSymbolsToExcel()

viewmodel.ExportSymbolsToExcelCommand.Execute();

this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object, allSymbolsInLibDiff), Times.Exactly(1));
this.MockUITaskScheduler.Verify(uits => uits.StartExcelExport(this.MockExcelExporter.Object,
It.Is<IReadOnlyList<SymbolDiff>>(symbols => symbols.Count == allSymbolsInLibDiff.Count &&
!symbols.Except(allSymbolsInLibDiff).Any())),
Times.Exactly(1));
}

public void Dispose() => this.TestDataGenerator.Dispose();
Expand Down
Loading