mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
Self-contained .NET (#22217)
* dotnet sc
* MD preview - C# app
- working self-contained
* Gcode preview - C# app
* DevFiles preview - C# app
* Fix passing path with spaces as cmd arg and monacocpp proj file
* Pdf preview - C# app
* Svg preview - C# app
* Fix comment
* Gcode thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix GcodeThumbnailProviderCpp.vcxproj
* Svg thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix Svg tests
* Thumbnail providers - installer
* Self-contained Hosts and FileLocksmith
* Fix hardcoded <RuntimeIdentifier>
* Remove unneeded files
* Try to fix Nuget in PR CI
* Prefix new dlls with PowerToys.
Sign new dlls and exes
* Add new .exe files to ProcessList
* ci: debug by listing all env vars
* ci: try setting variable in the right ci file
* Bring back hardcoded RuntimeIdentifier
* ci: Add comment and remove debug action
* Remove unneeded lib
* [WIP] Platform conditional dotnet files & hardlinks
* Cleanup
* Update expect.txt
* Test fix - ARM installer
* Fix uninstall bug
* Update docs
* Fix failing test
* Add dll details
* Minor cleanup
* Improve resizing
* Add some logs
* Test fix - release build
* Remove InvokeOnControlThread
* Test fix: logger initialization
* Fix arm64 installer
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
This commit is contained in:
@@ -2,16 +2,11 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Common.ComInterlop;
|
||||
using Microsoft.PowerToys.STATestExtension;
|
||||
using Microsoft.PowerToys.ThumbnailHandler.Stl;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
namespace StlThumbnailProviderUnitTests
|
||||
{
|
||||
@@ -22,48 +17,39 @@ namespace StlThumbnailProviderUnitTests
|
||||
public void GetThumbnailValidStreamStl()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.stl");
|
||||
var filePath = "HelperFiles/sample.stl";
|
||||
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider();
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider(filePath);
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
Bitmap bitmap = provider.GetThumbnail(256);
|
||||
|
||||
provider.GetThumbnail(256, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap != IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_ARGB);
|
||||
Assert.IsTrue(bitmap != null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetThumbnailInValidSizeStl()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.stl");
|
||||
var filePath = "HelperFiles/sample.stl";
|
||||
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider();
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider(filePath);
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
Bitmap bitmap = provider.GetThumbnail(0);
|
||||
|
||||
provider.GetThumbnail(0, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap == IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_UNKNOWN);
|
||||
Assert.IsTrue(bitmap == null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetThumbnailToBigStl()
|
||||
{
|
||||
// Act
|
||||
var file = File.ReadAllBytes("HelperFiles/sample.stl");
|
||||
var filePath = "HelperFiles/sample.stl";
|
||||
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider();
|
||||
StlThumbnailProvider provider = new StlThumbnailProvider(filePath);
|
||||
|
||||
provider.Initialize(GetMockStream(file), 0);
|
||||
Bitmap bitmap = provider.GetThumbnail(10001);
|
||||
|
||||
provider.GetThumbnail(10001, out IntPtr bitmap, out WTS_ALPHATYPE alphaType);
|
||||
|
||||
Assert.IsTrue(bitmap == IntPtr.Zero);
|
||||
Assert.IsTrue(alphaType == WTS_ALPHATYPE.WTSAT_UNKNOWN);
|
||||
Assert.IsTrue(bitmap == null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -82,30 +68,5 @@ namespace StlThumbnailProviderUnitTests
|
||||
Bitmap thumbnail = StlThumbnailProvider.GetThumbnail(null, 256);
|
||||
Assert.IsTrue(thumbnail == null);
|
||||
}
|
||||
|
||||
private static IStream GetMockStream(byte[] sourceArray)
|
||||
{
|
||||
var streamMock = new Mock<IStream>();
|
||||
int bytesRead = 0;
|
||||
|
||||
streamMock
|
||||
.Setup(x => x.Read(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<IntPtr>()))
|
||||
.Callback<byte[], int, IntPtr>((buffer, countToRead, bytesReadPtr) =>
|
||||
{
|
||||
int actualCountToRead = Math.Min(sourceArray.Length - bytesRead, countToRead);
|
||||
if (actualCountToRead > 0)
|
||||
{
|
||||
Array.Copy(sourceArray, bytesRead, buffer, 0, actualCountToRead);
|
||||
Marshal.WriteInt32(bytesReadPtr, actualCountToRead);
|
||||
bytesRead += actualCountToRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
Marshal.WriteInt32(bytesReadPtr, 0);
|
||||
}
|
||||
});
|
||||
|
||||
return streamMock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user