mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Added unit testing
This commit is contained in:
parent
f40d4fc782
commit
374e1f6207
3 changed files with 75 additions and 42 deletions
|
|
@ -38,6 +38,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Program\Flow.Launcher.Plugin.Program.csproj" />
|
||||||
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Url\Flow.Launcher.Plugin.Url.csproj" />
|
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Url\Flow.Launcher.Plugin.Url.csproj" />
|
||||||
<ProjectReference Include="..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
|
<ProjectReference Include="..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
|
||||||
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
|
<ProjectReference Include="..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
|
||||||
|
|
|
||||||
30
Flow.Launcher.Test/Plugins/ProgramTest.cs
Normal file
30
Flow.Launcher.Test/Plugins/ProgramTest.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using Flow.Launcher.Plugin.Program.Programs;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
using Windows.ApplicationModel;
|
||||||
|
|
||||||
|
namespace Flow.Launcher.Test.Plugins
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ProgramTest
|
||||||
|
{
|
||||||
|
[TestCase("Microsoft.WindowsCamera", "ms-resource:LensSDK/Resources/AppTitle", "ms-resource://Microsoft.WindowsCamera/LensSDK/Resources/AppTitle")]
|
||||||
|
[TestCase("microsoft.windowscommunicationsapps", "ms-resource://microsoft.windowscommunicationsapps/hxoutlookintl/AppManifest_MailDesktop_DisplayName",
|
||||||
|
"ms-resource://microsoft.windowscommunicationsapps/hxoutlookintl/AppManifest_MailDesktop_DisplayName")]
|
||||||
|
[TestCase("windows.immersivecontrolpanel", "ms-resource:DisplayName", "ms-resource://windows.immersivecontrolpanel/Resources/DisplayName")]
|
||||||
|
[TestCase("Microsoft.MSPaint", "ms-resource:AppName", "ms-resource://Microsoft.MSPaint/Resources/AppName")]
|
||||||
|
public void WhenGivenPriReferenceValueShouldReturnCorrectFormat(string packageName, string rawPriReferenceValue, string expectedFormat)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var app = new UWP.Application();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = app.FormattedPriReferenceValue(packageName, rawPriReferenceValue);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsTrue(result == expectedFormat,
|
||||||
|
$"Expected Pri reference format: {expectedFormat}{Environment.NewLine} " +
|
||||||
|
$"Actual: {result}{Environment.NewLine}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -263,6 +263,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
public string LogoPath { get; set; }
|
public string LogoPath { get; set; }
|
||||||
public UWP Package { get; set; }
|
public UWP Package { get; set; }
|
||||||
|
|
||||||
|
public Application(){}
|
||||||
|
|
||||||
private int Score(string query)
|
private int Score(string query)
|
||||||
{
|
{
|
||||||
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||||
|
|
@ -371,62 +373,62 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string ResourceFromPri(string packageFullName, string packageName, string resourceReference)
|
internal string ResourceFromPri(string packageFullName, string packageName, string rawReferenceValue)
|
||||||
{
|
{
|
||||||
const string prefix = "ms-resource:";
|
if (string.IsNullOrWhiteSpace(rawReferenceValue) || !rawReferenceValue.StartsWith("ms-resource:"))
|
||||||
if (!string.IsNullOrWhiteSpace(resourceReference) && resourceReference.StartsWith(prefix))
|
return rawReferenceValue;
|
||||||
|
|
||||||
|
var formattedPriReference = FormattedPriReferenceValue(packageName, rawReferenceValue);
|
||||||
|
|
||||||
|
var outBuffer = new StringBuilder(128);
|
||||||
|
string source = $"@{{{packageFullName}? {formattedPriReference}}}";
|
||||||
|
var capacity = (uint)outBuffer.Capacity;
|
||||||
|
var hResult = SHLoadIndirectString(source, outBuffer, capacity, IntPtr.Zero);
|
||||||
|
if (hResult == Hresult.Ok)
|
||||||
{
|
{
|
||||||
string key = resourceReference.Substring(prefix.Length);
|
var loaded = outBuffer.ToString();
|
||||||
string parsed;
|
if (!string.IsNullOrEmpty(loaded))
|
||||||
if (key.StartsWith("//"))
|
|
||||||
{
|
{
|
||||||
parsed = $"{prefix}{key}";
|
return loaded;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!key.StartsWith("/"))
|
ProgramLogger.LogException($"|UWP|ResourceFromPri|{Package.Location}|Can't load null or empty result "
|
||||||
{
|
+ $"pri {source} in uwp location {Package.Location}", new NullReferenceException());
|
||||||
key = $"/{key}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!key.ToLower().Contains("resources"))
|
|
||||||
{
|
|
||||||
key = $"/Resources{key}";
|
|
||||||
}
|
|
||||||
parsed = $"{prefix}//{packageName}{key}";
|
|
||||||
}
|
|
||||||
|
|
||||||
var outBuffer = new StringBuilder(128);
|
|
||||||
string source = $"@{{{packageFullName}? {parsed}}}";
|
|
||||||
var capacity = (uint)outBuffer.Capacity;
|
|
||||||
var hResult = SHLoadIndirectString(source, outBuffer, capacity, IntPtr.Zero);
|
|
||||||
if (hResult == Hresult.Ok)
|
|
||||||
{
|
|
||||||
var loaded = outBuffer.ToString();
|
|
||||||
if (!string.IsNullOrEmpty(loaded))
|
|
||||||
{
|
|
||||||
return loaded;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ProgramLogger.LogException($"|UWP|ResourceFromPri|{Package.Location}|Can't load null or empty result "
|
|
||||||
+ $"pri {source} in uwp location {Package.Location}", new NullReferenceException());
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var e = Marshal.GetExceptionForHR((int)hResult);
|
|
||||||
ProgramLogger.LogException($"|UWP|ResourceFromPri|{Package.Location}|Load pri failed {source} with HResult {hResult} and location {Package.Location}", e);
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return resourceReference;
|
var e = Marshal.GetExceptionForHR((int)hResult);
|
||||||
|
ProgramLogger.LogException($"|UWP|ResourceFromPri|{Package.Location}|Load pri failed {source} with HResult {hResult} and location {Package.Location}", e);
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string FormattedPriReferenceValue(string packageName, string rawPriReferenceValue)
|
||||||
|
{
|
||||||
|
const string prefix = "ms-resource:";
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rawPriReferenceValue) || !rawPriReferenceValue.StartsWith(prefix))
|
||||||
|
return rawPriReferenceValue;
|
||||||
|
|
||||||
|
string key = rawPriReferenceValue.Substring(prefix.Length);
|
||||||
|
if (key.StartsWith("//"))
|
||||||
|
return $"{prefix}{key}";
|
||||||
|
|
||||||
|
if (!key.StartsWith("/"))
|
||||||
|
{
|
||||||
|
key = $"/{key}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key.ToLower().Contains("resources"))
|
||||||
|
{
|
||||||
|
key = $"/Resources{key}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{prefix}//{packageName}{key}";
|
||||||
|
}
|
||||||
|
|
||||||
internal string LogoUriFromManifest(IAppxManifestApplication app)
|
internal string LogoUriFromManifest(IAppxManifestApplication app)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue