Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3b959dca authored by Michal Policht's avatar Michal Policht

Fix new line characters.

Windows-style line endings leaked into Linux environment, causing CRLF
pollution.
parent db7c27a1
import qbs
import cutehmi
cutehmi.Test
{
Depends { name: "CuteHMI.2" }
Depends { name: "CuteHMI.Test.0" }
}
import qbs
import cutehmi
cutehmi.Test
{
Depends { name: "CuteHMI.2" }
Depends { name: "CuteHMI.Test.0" }
}
//(c)MP: Copyright © 2018, Michal Policht. All rights reserved.
//(c)MP: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
import qbs
import cutehmi
import "TestCase.qbs" as TestCase
Project {
TestCase {
name: "logging"
files: [
"tst_logging.cpp",
]
}
TestCase {
name: "Exception"
files: [
"tst_Exception.cpp"
]
Depends { name: "Qt.concurrent" }
}
TestCase {
name: "ExceptionMixin"
files: [
"tst_ExceptionMixin.cpp"
]
Depends { name: "Qt.concurrent" }
}
TestCase {
name: "Prompt"
files: [
"tst_Prompt.cpp",
]
}
TestCase {
name: "PopupBridge"
files: [
"tst_PopupBridge.cpp",
]
}
TestCase {
name: "PopupBridgeQML"
files: [
"tst_PopupBridge.qml",
"tst_PopupBridgeQML.cpp",
]
}
}
import qbs
import cutehmi
import "TestCase.qbs" as TestCase
Project {
TestCase {
name: "logging"
files: [
"tst_logging.cpp",
]
}
TestCase {
name: "Exception"
files: [
"tst_Exception.cpp"
]
Depends { name: "Qt.concurrent" }
}
TestCase {
name: "ExceptionMixin"
files: [
"tst_ExceptionMixin.cpp"
]
Depends { name: "Qt.concurrent" }
}
TestCase {
name: "Prompt"
files: [
"tst_Prompt.cpp",
]
}
TestCase {
name: "PopupBridge"
files: [
"tst_PopupBridge.cpp",
]
}
TestCase {
name: "PopupBridgeQML"
files: [
"tst_PopupBridge.qml",
"tst_PopupBridgeQML.cpp",
]
}
}
//(c)MP: Copyright © 2018, Michal Policht. All rights reserved.
//(c)MP: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <cutehmi/Exception.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
#include <QtConcurrent>
namespace cutehmi {
class tst_Exception:
public QObject
{
Q_OBJECT
private slots:
void what();
void concurrent();
};
void tst_Exception::what()
{
try {
throw Exception("Exception test.");
} catch (Exception & e) {
QCOMPARE(e.what(), "Exception test.");
}
QString randomString = test::rand<QString>();
try {
throw Exception(randomString);
} catch (Exception & e) {
QCOMPARE(e.what(), randomString.toLocal8Bit().constData());
}
}
void tst_Exception::concurrent()
{
try {
int arr[1];
QtConcurrent::blockingMap(arr, arr + 1, [](int){throw Exception("Exception thrown from QtConcurrent::blockingMap.");});
} catch (Exception & e) {
QCOMPARE(e.what(), "Exception thrown from QtConcurrent::blockingMap.");
}
}
}
QTEST_MAIN(cutehmi::tst_Exception)
#include "tst_Exception.moc"
#include <cutehmi/Exception.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
#include <QtConcurrent>
namespace cutehmi {
class tst_Exception:
public QObject
{
Q_OBJECT
private slots:
void what();
void concurrent();
};
void tst_Exception::what()
{
try {
throw Exception("Exception test.");
} catch (Exception & e) {
QCOMPARE(e.what(), "Exception test.");
}
QString randomString = test::rand<QString>();
try {
throw Exception(randomString);
} catch (Exception & e) {
QCOMPARE(e.what(), randomString.toLocal8Bit().constData());
}
}
void tst_Exception::concurrent()
{
try {
int arr[1];
QtConcurrent::blockingMap(arr, arr + 1, [](int){throw Exception("Exception thrown from QtConcurrent::blockingMap.");});
} catch (Exception & e) {
QCOMPARE(e.what(), "Exception thrown from QtConcurrent::blockingMap.");
}
}
}
QTEST_MAIN(cutehmi::tst_Exception)
#include "tst_Exception.moc"
//(c)MP: Copyright © 2018, Michal Policht. All rights reserved.
//(c)MP: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <cutehmi/ExceptionMixin.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
#include <QtConcurrent>
namespace cutehmi {
class TestException:
public ExceptionMixin<TestException>
{
public:
explicit TestException(const QString & message):
ExceptionMixin<TestException>(message)
{
}
TestException(const TestException & other) = default;
~TestException() override;
};
TestException::~TestException()
{
}
class tst_ExceptionMixin:
public QObject
{
Q_OBJECT
private slots:
void what();
void concurrent();
};
void tst_ExceptionMixin::what()
{
try {
throw TestException("Exception test.");
} catch (TestException & e) {
QCOMPARE(e.what(), "Exception test.");
}
QString randomString = test::rand<QString>();
try {
throw TestException(randomString);
} catch (TestException & e) {
QCOMPARE(e.what(), randomString.toLocal8Bit().constData());
}
}
void tst_ExceptionMixin::concurrent()
{
try {
int arr[1];
QtConcurrent::blockingMap(arr, arr + 1, [](int){throw TestException("Exception thrown from QtConcurrent::blockingMap.");});
} catch (TestException & e) {
QCOMPARE(e.what(), "Exception thrown from QtConcurrent::blockingMap.");
}
}
}
QTEST_MAIN(cutehmi::tst_ExceptionMixin)
#include "tst_ExceptionMixin.moc"
#include <cutehmi/ExceptionMixin.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
#include <QtConcurrent>
namespace cutehmi {
class TestException:
public ExceptionMixin<TestException>
{
public:
explicit TestException(const QString & message):
ExceptionMixin<TestException>(message)
{
}
TestException(const TestException & other) = default;
~TestException() override;
};
TestException::~TestException()
{
}
class tst_ExceptionMixin:
public QObject
{
Q_OBJECT
private slots:
void what();
void concurrent();
};
void tst_ExceptionMixin::what()
{
try {
throw TestException("Exception test.");
} catch (TestException & e) {
QCOMPARE(e.what(), "Exception test.");
}
QString randomString = test::rand<QString>();
try {
throw TestException(randomString);
} catch (TestException & e) {
QCOMPARE(e.what(), randomString.toLocal8Bit().constData());
}
}
void tst_ExceptionMixin::concurrent()
{
try {
int arr[1];
QtConcurrent::blockingMap(arr, arr + 1, [](int){throw TestException("Exception thrown from QtConcurrent::blockingMap.");});
} catch (TestException & e) {
QCOMPARE(e.what(), "Exception thrown from QtConcurrent::blockingMap.");
}
}
}
QTEST_MAIN(cutehmi::tst_ExceptionMixin)
#include "tst_ExceptionMixin.moc"
//(c)MP: Copyright © 2018, Michal Policht. All rights reserved.
//(c)MP: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <cutehmi/PopupBridge.hpp>
#include <cutehmi/Prompt.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
namespace cutehmi {
class tst_PopupBridge:
public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void noAdvertiser();
void advertise();
void note();
void warning();
void question();
void critical();
};
class AdvertiserMock:
public QObject
{
Q_OBJECT
public:
Prompt::Button response;
public slots:
void createPrompt(QVariant prompt);
};
void tst_PopupBridge::initTestCase()
{
qRegisterMetaType<cutehmi::Prompt::Button>();
}
void tst_PopupBridge::noAdvertiser()
{
PopupBridge bridge;
Prompt prompt(Prompt::NOTE, "Message", Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
try {
bridge.advertise(& prompt);
} catch (const PopupBridge::NoAdvertiserException & e) {
QCOMPARE(e.prompt()->type(), Prompt::NOTE);
QCOMPARE(e.prompt()->text(), "Message");
QCOMPARE(e.prompt()->buttons(), Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
}
}
void tst_PopupBridge::advertise()
{
PopupBridge bridge;
Prompt prompt(Prompt::NOTE, "Message", Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
AdvertiserMock advertiserMock;
advertiserMock.response = Prompt::BUTTON_CANCEL;
bridge.resetAdvertiser(& advertiserMock);
bridge.advertise(& prompt);
QCOMPARE(prompt.response(), advertiserMock.response);
}
void tst_PopupBridge::note()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.note("Note.");
QCOMPARE(prompt->type(), Prompt::NOTE);
QCOMPARE(prompt->text(), "Note.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::warning()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.warning("Warning.");
QCOMPARE(prompt->type(), Prompt::WARNING);
QCOMPARE(prompt->text(), "Warning.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::question()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.question("Question?");
QCOMPARE(prompt->type(), Prompt::QUESTION);
QCOMPARE(prompt->text(), "Question?");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_YES | Prompt::BUTTON_NO);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::critical()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.critical("Critical.");
QCOMPARE(prompt->type(), Prompt::CRITICAL);
QCOMPARE(prompt->text(), "Critical.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
try {
ErrorInfo err{1, "class", "Error."};
std::unique_ptr<Prompt> prompt2 = bridge.critical(err);
QCOMPARE(prompt2->type(), Prompt::CRITICAL);
QCOMPARE(prompt2->text(), err.toString());
QCOMPARE(prompt2->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void AdvertiserMock::createPrompt(QVariant prompt)
{
Q_UNUSED(prompt)
prompt.value<Prompt *>()->acceptResponse(response);
}
}
QTEST_MAIN(cutehmi::tst_PopupBridge)
#include "tst_PopupBridge.moc"
#include <cutehmi/PopupBridge.hpp>
#include <cutehmi/Prompt.hpp>
#include <cutehmi/test/random.hpp>
#include <QtTest/QtTest>
namespace cutehmi {
class tst_PopupBridge:
public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void noAdvertiser();
void advertise();
void note();
void warning();
void question();
void critical();
};
class AdvertiserMock:
public QObject
{
Q_OBJECT
public:
Prompt::Button response;
public slots:
void createPrompt(QVariant prompt);
};
void tst_PopupBridge::initTestCase()
{
qRegisterMetaType<cutehmi::Prompt::Button>();
}
void tst_PopupBridge::noAdvertiser()
{
PopupBridge bridge;
Prompt prompt(Prompt::NOTE, "Message", Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
try {
bridge.advertise(& prompt);
} catch (const PopupBridge::NoAdvertiserException & e) {
QCOMPARE(e.prompt()->type(), Prompt::NOTE);
QCOMPARE(e.prompt()->text(), "Message");
QCOMPARE(e.prompt()->buttons(), Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
}
}
void tst_PopupBridge::advertise()
{
PopupBridge bridge;
Prompt prompt(Prompt::NOTE, "Message", Prompt::BUTTON_APPLY | Prompt::BUTTON_CANCEL);
AdvertiserMock advertiserMock;
advertiserMock.response = Prompt::BUTTON_CANCEL;
bridge.resetAdvertiser(& advertiserMock);
bridge.advertise(& prompt);
QCOMPARE(prompt.response(), advertiserMock.response);
}
void tst_PopupBridge::note()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.note("Note.");
QCOMPARE(prompt->type(), Prompt::NOTE);
QCOMPARE(prompt->text(), "Note.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::warning()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.warning("Warning.");
QCOMPARE(prompt->type(), Prompt::WARNING);
QCOMPARE(prompt->text(), "Warning.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::question()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.question("Question?");
QCOMPARE(prompt->type(), Prompt::QUESTION);
QCOMPARE(prompt->text(), "Question?");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_YES | Prompt::BUTTON_NO);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void tst_PopupBridge::critical()
{
PopupBridge bridge;
try {
std::unique_ptr<Prompt> prompt = bridge.critical("Critical.");
QCOMPARE(prompt->type(), Prompt::CRITICAL);
QCOMPARE(prompt->text(), "Critical.");
QCOMPARE(prompt->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
try {
ErrorInfo err{1, "class", "Error."};
std::unique_ptr<Prompt> prompt2 = bridge.critical(err);
QCOMPARE(prompt2->type(), Prompt::CRITICAL);
QCOMPARE(prompt2->text(), err.toString());
QCOMPARE(prompt2->buttons(), Prompt::BUTTON_OK);
} catch (const PopupBridge::NoAdvertiserException & ) {
}
}
void AdvertiserMock::createPrompt(QVariant prompt)
{
Q_UNUSED(prompt)
prompt.value<Prompt *>()->acceptResponse(response);
}