mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdecore: add test for some conversion classes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8770241e2b
commit
d87e0f8a38
3 changed files with 90 additions and 0 deletions
|
@ -62,6 +62,7 @@ KDECORE_UNIT_TESTS(
|
|||
qcoreapptest
|
||||
kdebug_qcoreapptest
|
||||
kmimetype_nomimetypes
|
||||
kunitconversiontest
|
||||
)
|
||||
|
||||
KDECORE_EXECUTABLE_TESTS(
|
||||
|
|
55
kdecore/tests/kunitconversiontest.cpp
Normal file
55
kdecore/tests/kunitconversiontest.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kunitconversiontest.h"
|
||||
#include "kunitconversion.h"
|
||||
#include "qtest_kde.h"
|
||||
|
||||
QTEST_KDEMAIN_CORE(KUnitConversionTest)
|
||||
|
||||
void KUnitConversionTest::initTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testRound()
|
||||
{
|
||||
static const double toround = 1.23456789;
|
||||
QCOMPARE(KUnitConversion::round(toround, 1), 1.2);
|
||||
QCOMPARE(KUnitConversion::round(toround, 2), 1.23);
|
||||
QCOMPARE(KUnitConversion::round(toround, 3), 1.235);
|
||||
}
|
||||
|
||||
void KUnitConversionTest::testTemperature()
|
||||
{
|
||||
KTemperature invalidtemp(12, "");
|
||||
QCOMPARE(invalidtemp.unitEnum(), KTemperature::Invalid);
|
||||
|
||||
KTemperature utf8celsiustemp(12, "°C");
|
||||
QCOMPARE(utf8celsiustemp.unitEnum(), KTemperature::Celsius);
|
||||
|
||||
KTemperature ccelsiustemp(12, "C");
|
||||
QCOMPARE(ccelsiustemp.unitEnum(), KTemperature::Celsius);
|
||||
|
||||
KTemperature tostringtemp(123.4, "°F");
|
||||
QCOMPARE(tostringtemp.toString(), QString::fromUtf8("123.4 °F"));
|
||||
|
||||
KTemperature converttotemp(123.4, "°F");
|
||||
QCOMPARE(KUnitConversion::round(converttotemp.convertTo(KTemperature::Celsius), 1), 50.8);
|
||||
}
|
||||
|
||||
#include "moc_kunitconversiontest.cpp"
|
34
kdecore/tests/kunitconversiontest.h
Normal file
34
kdecore/tests/kunitconversiontest.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2021 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KUNITCONVERSIONTEST_H
|
||||
#define KUNITCONVERSIONTEST_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class KUnitConversionTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testRound();
|
||||
void testTemperature();
|
||||
};
|
||||
|
||||
#endif // KUNITCONVERSIONTEST_H
|
Loading…
Add table
Reference in a new issue