Skip to content
Snippets Groups Projects
Commit 3ad0b92d authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

link-preview: use non-ASCII UTF-8 characters in a UTF-8 test

Non-ASCII characters in UTF-8 are encoded with multiple bytes. Testing with these characters ensures that the decoder correctly interprets multi-byte sequences.

Gitlab: #1536
Change-Id: I0a92ee91b6cd26d70daab1f9baef3a9577aee02e
parent 91475c3a
No related branches found
No related tags found
No related merge requests found
......@@ -24,15 +24,17 @@ class PreviewEngineFixture : public ::testing::Test
public:
// Prepare unit test context. Called at
// prior each unit test execution
void SetUp() override {
void SetUp() override
{
server = new QHttpServer();
// Setup a server that can return an HTML body.
server->listen(QHostAddress::LocalHost, 8000);
}
// Close unit test context. Called
// after each unit test ending
void TearDown() override {
// Close unit test context. Called
// after each unit test ending
void TearDown() override
{
delete server;
}
......@@ -47,9 +49,8 @@ public:
TEST_F(PreviewEngineFixture, ParsingALinkEmitsInfoReadySignal)
{
auto link = QString("http://localhost:8000/test");
server->route("/test", [] () {
return QString("<meta property=\"og:title\" content=\"Test title\">");
});
server->route("/test",
[]() { return QString("<meta property=\"og:title\" content=\"Test title\">"); });
QSignalSpy infoReadySpy(globalEnv.previewEngine.data(), &PreviewEngine::infoReady);
......@@ -70,14 +71,14 @@ TEST_F(PreviewEngineFixture, ParsingALinkEmitsInfoReadySignal)
*/
TEST_F(PreviewEngineFixture, UTF8CharactersAreParsedCorrectly)
{
auto link = QString("http://localhost:8000/test");
server->route("/test", [] () {
return QString("<meta property=\"og:description\" content=\"Test de caractères Utf-8");
const auto testString = QString("liberté 自由 自由 свобода Szabadság ŐőŰű 자유 😊 € è ñ");
server->route("/test", [&]() {
return QString("<meta property=\"og:description\" content=\"%1\">").arg(testString);
});
QSignalSpy infoReadySpy(globalEnv.previewEngine.data(), &PreviewEngine::infoReady);
Q_EMIT globalEnv.previewEngine->parseLink("msgId_01", link);
Q_EMIT globalEnv.previewEngine->parseLink("msgId_01", "http://localhost:8000/test");
// Wait for the infoReady signal which should be emitted once.
infoReadySpy.wait();
......@@ -89,5 +90,5 @@ TEST_F(PreviewEngineFixture, UTF8CharactersAreParsedCorrectly)
// Check that the description is parsed correctly.
QVariantMap info = infoReadyArguments.at(1).toMap();
EXPECT_TRUE(info.contains("description"));
EXPECT_EQ(info["description"].toString(), "Test de caractères Utf-8");
EXPECT_EQ(info["description"].toString(), testString);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment