2021-12-10 11:53:01 +00:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// 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.Gcode;
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
using Moq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace GcodeThumbnailProviderUnitTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[STATestClass]
|
|
|
|
|
|
public class GcodeThumbnailProviderTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void GetThumbnailValidStreamGcode()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Act
|
2022-12-14 13:37:23 +01:00
|
|
|
|
var filePath = "HelperFiles/sample.gcode";
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Bitmap bitmap = provider.GetThumbnail(256);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Assert.IsTrue(bitmap != null);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void GetThumbnailInValidSizeGcode()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Act
|
2022-12-14 13:37:23 +01:00
|
|
|
|
var filePath = "HelperFiles/sample.gcode";
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Bitmap bitmap = provider.GetThumbnail(0);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Assert.IsTrue(bitmap == null);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void GetThumbnailToBigGcode()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Act
|
2022-12-14 13:37:23 +01:00
|
|
|
|
var filePath = "HelperFiles/sample.gcode";
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Bitmap bitmap = provider.GetThumbnail(10001);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
|
2022-12-14 13:37:23 +01:00
|
|
|
|
Assert.IsTrue(bitmap == null);
|
2021-12-10 11:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void CheckNoGcodeEmptyStringShouldReturnNullBitmap()
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var reader = new StringReader(string.Empty))
|
|
|
|
|
|
{
|
|
|
|
|
|
Bitmap thumbnail = GcodeThumbnailProvider.GetThumbnail(reader, 256);
|
|
|
|
|
|
Assert.IsTrue(thumbnail == null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void CheckNoGcodeNullStringShouldReturnNullBitmap()
|
|
|
|
|
|
{
|
|
|
|
|
|
Bitmap thumbnail = GcodeThumbnailProvider.GetThumbnail(null, 256);
|
|
|
|
|
|
Assert.IsTrue(thumbnail == null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|