mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[Powertoys Run] Implemented "hidden files" flag in native Windows Search (#5500)
* Implemented "hidden files" flag in native Windows Search * add missing file * Change InitQueryHelper back to static * Fix Line Endings * Add files via github Co-authored-by: Roy <royvou@hotmailcom>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// 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.
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper = null;
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, maxCount);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, maxCount, api.DisplayHiddenFiles);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(queryHelper);
|
||||
@@ -48,8 +48,8 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "*";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "tt*^&)";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
@@ -82,7 +82,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "tt%^&)";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
@@ -99,7 +99,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "tt_^&)";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
@@ -116,7 +116,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "tt?^&)";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
@@ -133,7 +133,7 @@ namespace Wox.Test.Plugins
|
||||
ISearchQueryHelper queryHelper;
|
||||
string pattern = "tt^&)bc";
|
||||
WindowsSearchAPI api = GetWindowsSearchAPI();
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10);
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles);
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
@@ -158,11 +158,11 @@ namespace Wox.Test.Plugins
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldShowHiddenFiles_WhenDisplayHiddenFilesIsTrue()
|
||||
public void WindowsSearchAPI_ShouldReturnResults_WhenSearchWasExecuted()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", "file1.txt", 0x0L });
|
||||
OleDBResult hiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt", 0x2L });
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", "file1.txt" });
|
||||
OleDBResult hiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt" });
|
||||
List<OleDBResult> results = new List<OleDBResult>() { hiddenFile, unHiddenFile };
|
||||
var mock = new Mock<ISearch>();
|
||||
mock.Setup(x => x.Query(It.IsAny<string>(), It.IsAny<string>())).Returns(results);
|
||||
@@ -177,34 +177,13 @@ namespace Wox.Test.Plugins
|
||||
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldNotShowHiddenFiles_WhenDisplayHiddenFilesIsFalse()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", "file1.txt", 0x0L });
|
||||
OleDBResult hiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt", 0x2L });
|
||||
List<OleDBResult> results = new List<OleDBResult>() { hiddenFile, unHiddenFile };
|
||||
var mock = new Mock<ISearch>();
|
||||
mock.Setup(x => x.Query(It.IsAny<string>(), It.IsAny<string>())).Returns(results);
|
||||
WindowsSearchAPI api = new WindowsSearchAPI(mock.Object, false);
|
||||
|
||||
// Act
|
||||
var windowsSearchAPIResults = api.Search("FilePath");
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(windowsSearchAPIResults.Count() == 1);
|
||||
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file1.txt"));
|
||||
Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldNotReturnResultsWithNullValue_WhenDbResultHasANullColumn()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult file1 = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value, 0x0L });
|
||||
OleDBResult file2 = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt", 0x0L });
|
||||
|
||||
List<OleDBResult> results = new List<OleDBResult>() { file1, file2 };
|
||||
OleDBResult unHiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value });
|
||||
OleDBResult hiddenFile = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt" });
|
||||
List<OleDBResult> results = new List<OleDBResult>() { hiddenFile, unHiddenFile };
|
||||
var mock = new Mock<ISearch>();
|
||||
mock.Setup(x => x.Query(It.IsAny<string>(), It.IsAny<string>())).Returns(results);
|
||||
WindowsSearchAPI api = new WindowsSearchAPI(mock.Object, false);
|
||||
@@ -218,6 +197,58 @@ namespace Wox.Test.Plugins
|
||||
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestNormalRequest_WhenDisplayHiddenFilesIsTrue()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
String pattern = "notepad";
|
||||
WindowsSearchAPI _api = GetWindowsSearchAPI();
|
||||
_api.DisplayHiddenFiles = true;
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, _api.DisplayHiddenFiles);
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestFilteredRequest_WhenDisplayHiddenFilesIsFalse()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
String pattern = "notepad";
|
||||
WindowsSearchAPI _api = GetWindowsSearchAPI();
|
||||
_api.DisplayHiddenFiles = false;
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, _api.DisplayHiddenFiles);
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void WindowsSearchAPI_ShouldRequestNormalRequest_WhenDisplayHiddenFilesIsTrue_AfterRuntimeSwap()
|
||||
{
|
||||
ISearchQueryHelper queryHelper;
|
||||
String pattern = "notepad";
|
||||
WindowsSearchAPI _api = GetWindowsSearchAPI();
|
||||
_api.DisplayHiddenFiles = false;
|
||||
|
||||
// Act
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, _api.DisplayHiddenFiles);
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
_api.DisplayHiddenFiles = true;
|
||||
WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, _api.DisplayHiddenFiles);
|
||||
WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern);
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2"));
|
||||
}
|
||||
|
||||
[TestCase("item.exe")]
|
||||
[TestCase("item.bat")]
|
||||
[TestCase("item.appref-ms")]
|
||||
@@ -379,8 +410,8 @@ namespace Wox.Test.Plugins
|
||||
public void WindowsSearchAPI_ShouldReturnEmptyResults_WhenIsFullQueryIsTrueAndTheQueryDoesNotRequireLIKESyntax()
|
||||
{
|
||||
// Arrange
|
||||
OleDBResult file1 = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value, (Int64)0x0 });
|
||||
OleDBResult file2 = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt", (Int64)0x0 });
|
||||
OleDBResult file1 = new OleDBResult(new List<object>() { "C:/test/path/file1.txt", DBNull.Value });
|
||||
OleDBResult file2 = new OleDBResult(new List<object>() { "C:/test/path/file2.txt", "file2.txt" });
|
||||
|
||||
List<OleDBResult> results = new List<OleDBResult>() { file1, file2 };
|
||||
var mock = new Mock<ISearch>();
|
||||
|
||||
Reference in New Issue
Block a user