2023-08-06 15:57:01 +02:00
|
|
|
#include "util/XDGHelper.hpp"
|
|
|
|
|
2024-04-21 22:52:44 +02:00
|
|
|
#include "TestHelpers.hpp"
|
|
|
|
|
2023-08-06 15:57:01 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2023-08-21 19:00:37 +02:00
|
|
|
#if defined(Q_OS_UNIX) and !defined(Q_OS_DARWIN)
|
|
|
|
|
2023-08-06 15:57:01 +02:00
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
TEST(XDGHelper, ParseDesktopExecProgram)
|
|
|
|
{
|
|
|
|
struct TestCase {
|
|
|
|
QString input;
|
|
|
|
QString expectedOutput;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<TestCase> testCases{
|
|
|
|
{
|
|
|
|
// Sanity check: Ensure simple Exec lines aren't made messed with
|
|
|
|
"firefox",
|
|
|
|
"firefox",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Simple trim after the first space
|
|
|
|
"/usr/lib/firefox/firefox %u",
|
|
|
|
"/usr/lib/firefox/firefox",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Simple unquote
|
|
|
|
"\"/usr/lib/firefox/firefox\"",
|
|
|
|
"/usr/lib/firefox/firefox",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Unquote + trim
|
|
|
|
"\"/usr/lib/firefox/firefox\" %u",
|
|
|
|
"/usr/lib/firefox/firefox",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Test malformed exec key (only one quote)
|
|
|
|
"\"/usr/lib/firefox/firefox",
|
|
|
|
"/usr/lib/firefox/firefox",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Quoted executable name with space
|
|
|
|
"\"/usr/bin/my cool browser\"",
|
|
|
|
"/usr/bin/my cool browser",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Executable name with reserved character
|
|
|
|
"/usr/bin/\\$hadowwizardmoneybrowser",
|
|
|
|
"/usr/bin/$hadowwizardmoneybrowser",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &test : testCases)
|
|
|
|
{
|
|
|
|
auto output = parseDesktopExecProgram(test.input);
|
|
|
|
|
|
|
|
EXPECT_EQ(output, test.expectedOutput)
|
2024-04-21 22:52:44 +02:00
|
|
|
<< "Input '" << test.input << "' failed. Expected '"
|
|
|
|
<< test.expectedOutput << "' but got '" << output << "'";
|
2023-08-06 15:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-21 19:00:37 +02:00
|
|
|
|
|
|
|
#endif
|