44 lines
1.9 KiB
C++
44 lines
1.9 KiB
C++
#include <windows.h>
|
|
#include "../src/utilities.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
|
|
int main()
|
|
{
|
|
namespace fs = std::filesystem;
|
|
auto root = fs::temp_directory_path() / (L"KSwitcher-utilities-" + std::to_wstring(GetCurrentProcessId()));
|
|
try
|
|
{
|
|
std::error_code error;
|
|
if (!ks::discoverUtilities(root / L"missing", error).empty() || error)
|
|
throw std::runtime_error("Missing folder must be empty, not an error");
|
|
fs::create_directories(root / L"tools" / L"nested");
|
|
fs::create_directory(root / L"tools" / L"directory.exe");
|
|
for (auto name : {L"Zed.exe", L"alpha.EXE", L"A & B.exe", L"readme.txt", L"shortcut.lnk"})
|
|
std::ofstream(root / L"tools" / name).put('x');
|
|
std::ofstream(root / L"tools" / L"nested" / L"hidden.exe").put('x');
|
|
auto found = ks::discoverUtilities(root / L"tools", error);
|
|
if (error || found.size() != 3 || found[0].filename() != L"A & B.exe" ||
|
|
found[1].filename() != L"alpha.EXE" || found[2].filename() != L"Zed.exe")
|
|
throw std::runtime_error("Scan must filter direct executable files and sort names");
|
|
if (ks::utilityMenuLabel(found[0]) != L"A && B")
|
|
throw std::runtime_error("Ampersand must be displayed literally");
|
|
fs::remove(found[1]);
|
|
if (ks::discoverUtilities(root / L"tools", error).size() != 2)
|
|
throw std::runtime_error("Scan must refresh after a file is removed");
|
|
ks::discoverUtilities(root / L"tools" / L"readme.txt", error);
|
|
if (!error) throw std::runtime_error("Non-directory must report an error");
|
|
fs::remove_all(root);
|
|
std::cout << "Utilities regression tests passed\n";
|
|
return 0;
|
|
}
|
|
catch (const std::exception &e)
|
|
{
|
|
std::error_code ignored;
|
|
fs::remove_all(root, ignored);
|
|
std::cerr << e.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|