test_Exception.cpp 1.67 KB
Newer Older
Michal Policht's avatar
Michal Policht committed
1 2 3 4 5 6 7 8 9
#include <cutehmi/Exception.hpp>

#include <cutehmi/test/random.hpp>

#include <QtTest/QtTest>
#include <QtConcurrent>

namespace cutehmi {

10
class test_Exception:
Michal Policht's avatar
Michal Policht committed
11 12 13 14 15 16 17 18 19 20
	public QObject
{
	Q_OBJECT

	private slots:
		void what();

		void concurrent();
};

21
void test_Exception::what()
Michal Policht's avatar
Michal Policht committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
{
	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());
	}
}

37
void test_Exception::concurrent()
Michal Policht's avatar
Michal Policht committed
38 39 40 41 42 43 44 45 46 47 48
{
	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.");
	}
}

}

49 50
QTEST_MAIN(cutehmi::test_Exception)
#include "test_Exception.moc"
Michal Policht's avatar
Michal Policht committed
51

Michal Policht's avatar
Michal Policht committed
52 53 54 55 56
//(c)MP: Copyright © 2019, Michal Policht <michpolicht@gmail.com>. All rights reserved.
//(c)MP: This file is a part of CuteHMI.
//(c)MP: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//(c)MP: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
//(c)MP: You should have received a copy of the GNU Lesser General Public License along with CuteHMI.  If not, see <https://www.gnu.org/licenses/>.