Skip to content

Commit

Permalink
.NET8 SIL.Core.Desktop.Tests (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmyers authored Oct 10, 2024
1 parent cd24738 commit bfa445e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
1 change: 1 addition & 0 deletions SIL.Core.Desktop.Tests/SIL.Core.Desktop.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AssemblyName>SIL.Core.Desktop.Tests</AssemblyName>
<Description>Unit tests for SIL.Core.Desktop</Description>
<IsPackable>false</IsPackable>
<TargetFrameworks>$(TargetFrameworks);net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions SIL.Core.Desktop.Tests/UsbDrive/Linux/UDiskDeviceTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !NET
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -75,3 +76,4 @@ public void DriveConnectionInterface_USBDrive_USB()

}
}
#endif
2 changes: 2 additions & 0 deletions SIL.Core.Desktop.Tests/UsbDrive/Linux/UDisksTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !NET
using System;
using System.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -83,3 +84,4 @@ public void EnumerateUSB_HasOnlyPartitions()

}
}
#endif
5 changes: 3 additions & 2 deletions SIL.Core.Desktop.Tests/UsbDrive/UsbDeviceInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using NUnit.Framework;
using SIL.PlatformUtilities;
using SIL.UsbDrive;
using SIL.UsbDrive.Linux;

namespace SIL.Tests.UsbDrive
{
Expand Down Expand Up @@ -177,6 +176,7 @@ public void IsReady_2DrivesAreNotMounted_ReturnsFalse()
Assert.IsFalse(usbDrives[1].IsReady);
}

#if !NET
[Test]
[Category("RequiresUSB")]
[Category("SkipOnTeamCity")]
Expand All @@ -185,7 +185,7 @@ public void RootDirectory_FirstDriveIsNotMounted_Throws()
var usbDrives = UsbDriveInfo.GetDrives();
if (usbDrives.Count < 1)
Assert.Ignore("Need at least 1 USB drive plugged in");
if (Platform.IsWindows || UsbDriveInfoUDisks2.IsUDisks2Available)
if (Platform.IsWindows || SIL.UsbDrive.Linux.UsbDriveInfoUDisks2.IsUDisks2Available)
Assert.Ignore("On windows, or on linux with udisks2 GetDrives() only returns mounted drives");

Assert.Throws<ArgumentOutOfRangeException>(
Expand All @@ -195,5 +195,6 @@ public void RootDirectory_FirstDriveIsNotMounted_Throws()
}
);
}
#endif
}
}
75 changes: 45 additions & 30 deletions SIL.Windows.Forms.Tests/Miscellaneous/PortableClipboardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class PortableClipboardTests
{
private const string TestImageDir = "SIL.Windows.Forms.Tests/Miscellaneous/PortableClipboardTestImages";

// This prevents flakiness (ExternalException) with tests running in parallel with utilizing the clipboard
private static readonly object _lock = new object();

[SetUp]
public void Setup()
{
Expand All @@ -26,16 +29,19 @@ private static string GetPathToImage(string requestedImage)
[Platform(Exclude = "Linux", Reason = "Linux code to copy image to clipboard not yet implemented.")]
public void ClipboardRoundTripWorks_Png()
{
var imagePath = GetPathToImage("LineSpacing.png");
using (var image = PalasoImage.FromFileRobustly(imagePath))
lock (_lock)
{
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
var imagePath = GetPathToImage("LineSpacing.png");
using (var image = PalasoImage.FromFileRobustly(imagePath))
{
// There is no working PalasoImage.Equals(), so just try a few properties
Assert.AreEqual(image.FileName, resultingImage.FileName);
Assert.AreEqual(image.Image.Size, resultingImage.Image.Size);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
{
// There is no working PalasoImage.Equals(), so just try a few properties
Assert.AreEqual(image.FileName, resultingImage.FileName);
Assert.AreEqual(image.Image.Size, resultingImage.Image.Size);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
}
}
}
}
Expand All @@ -44,16 +50,19 @@ public void ClipboardRoundTripWorks_Png()
[Platform(Exclude = "Linux", Reason = "Linux code to copy image to clipboard not yet implemented.")]
public void ClipboardRoundTripWorks_Bmp()
{
var imagePath = GetPathToImage("PasteHS.bmp");
using (var image = PalasoImage.FromFileRobustly(imagePath))
lock (_lock)
{
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
var imagePath = GetPathToImage("PasteHS.bmp");
using (var image = PalasoImage.FromFileRobustly(imagePath))
{
// There is no working PalasoImage.Equals(), so just try a few properties
Assert.AreEqual(image.FileName, resultingImage.FileName);
Assert.AreEqual(image.Image.Size, resultingImage.Image.Size);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
{
// There is no working PalasoImage.Equals(), so just try a few properties
Assert.AreEqual(image.FileName, resultingImage.FileName);
Assert.AreEqual(image.Image.Size, resultingImage.Image.Size);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
}
}
}
}
Expand All @@ -62,19 +71,22 @@ public void ClipboardRoundTripWorks_Bmp()
[Platform(Exclude = "Linux", Reason = "Linux code to copy image to clipboard not yet implemented.")]
public void ClipboardRoundTripWorks_GetsExistingMetadata()
{
var imagePath = GetPathToImage("AOR_EAG00864.png");
using (var image = PalasoImage.FromFileRobustly(imagePath))
lock (_lock)
{
var preCopyLicense = image.Metadata.License.Token;
var preCopyCollectionUri = image.Metadata.CollectionUri;
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
var imagePath = GetPathToImage("AOR_EAG00864.png");
using (var image = PalasoImage.FromFileRobustly(imagePath))
{
// Test that the same metadata came through
Assert.IsTrue(resultingImage.Metadata.IsMinimallyComplete);
Assert.AreEqual(preCopyLicense, resultingImage.Metadata.License.Token);
Assert.AreEqual(preCopyCollectionUri, resultingImage.Metadata.CollectionUri);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
var preCopyLicense = image.Metadata.License.Token;
var preCopyCollectionUri = image.Metadata.CollectionUri;
PortableClipboard.CopyImageToClipboard(image);
using (var resultingImage = PortableClipboard.GetImageFromClipboard())
{
// Test that the same metadata came through
Assert.IsTrue(resultingImage.Metadata.IsMinimallyComplete);
Assert.AreEqual(preCopyLicense, resultingImage.Metadata.License.Token);
Assert.AreEqual(preCopyCollectionUri, resultingImage.Metadata.CollectionUri);
Assert.AreEqual(image.Image.Flags, resultingImage.Image.Flags);
}
}
}
}
Expand All @@ -83,9 +95,12 @@ public void ClipboardRoundTripWorks_GetsExistingMetadata()
[Platform(Exclude = "Linux", Reason = "This requires a GTK message loop to run or something like this")]
public void ClipboardRoundTripWorks_Text()
{
PortableClipboard.SetText("Hello world");
Assert.That(PortableClipboard.ContainsText(), Is.True);
Assert.That(PortableClipboard.GetText(), Is.EqualTo("Hello world"));
lock (_lock)
{
PortableClipboard.SetText("Hello world");
Assert.That(PortableClipboard.ContainsText(), Is.True);
Assert.That(PortableClipboard.GetText(), Is.EqualTo("Hello world"));
}
}
}
}
5 changes: 3 additions & 2 deletions SIL.WritingSystems.Tests/SldrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public void Dispose()
Sldr.Cleanup();
// clear out SLDR cache
var di = new DirectoryInfo(sldrCachePath);
foreach (var fi in di.GetFiles())
fi.Delete();
if (di.Exists)
foreach (var fi in di.GetFiles())
fi.Delete();
// The OfflineSldrAttribute has been assigned to the entire test assembly, so we reinitialize
// the SLDR back to what it was
Sldr.Initialize(true, sldrCachePath);
Expand Down

0 comments on commit bfa445e

Please sign in to comment.