1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/*
SPDX-FileCopyrightText: 2021 Igor Kushnir <igorkuo@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "test_languagecontroller.h"
#include <ilanguagecontroller.h>
#include <language/interfaces/ilanguagesupport.h>
#include <tests/testhelpers.h>
#include <QString>
#include <QTest>
#include <QUrl>
#include <future>
void TestLanguageController::testLanguagesForUrlInTheMainThread()
{
QFETCH(QUrl, url);
QFETCH(QString, languageName);
const auto languages = m_subject->languagesForUrl(url);
QCOMPARE(languages.size(), 1);
QCOMPARE(languages.back()->name(), languageName);
}
void TestLanguageController::testLanguagesForUrlInTheMainThread_data()
{
matchingLanguagesForUrlTestData();
}
void TestLanguageController::testLanguagesForUrlWithCache()
{
QFETCH(QUrl, url);
QFETCH(QString, languageName);
// Add the MIME type to LanguageController's cache for use in the background thread.
const auto languages = m_subject->languagesForUrl(url);
QCOMPARE(languages.size(), 1);
QCOMPARE(languages.back()->name(), languageName);
auto future = std::async(std::launch::async, [&] {
const auto languages = m_subject->languagesForUrl(url);
QCOMPARE_RETURN(languages.size(), 1, false);
QCOMPARE_RETURN(languages.back()->name(), languageName, false);
return true;
});
QVERIFY(future.get());
}
void TestLanguageController::testLanguagesForUrlWithCache_data()
{
matchingLanguagesForUrlInBackgroundThreadTestData();
}
void TestLanguageController::testLanguagesForUrlNoCache()
{
QFETCH(QUrl, url);
auto future = std::async(std::launch::async, [&] {
const auto languages = m_subject->languagesForUrl(url);
// When languagesForUrl() is called from a non-main thread, it cannot
// determine languages for a MIME type without a cache.
QVERIFY_RETURN(languages.empty(), false);
return true;
});
QVERIFY(future.get());
}
void TestLanguageController::testLanguagesForUrlNoCache_data()
{
matchingLanguagesForUrlTestData();
}
void TestLanguageController::testLanguagesForUrlNoMatch()
{
QFETCH(QUrl, url);
const auto languages = m_subject->languagesForUrl(url);
QVERIFY(languages.empty());
}
void TestLanguageController::testLanguagesForUrlNoMatch_data()
{
nonmatchingLanguagesForUrlTestData();
}
QTEST_MAIN(TestLanguageController)
|