add tests for project
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest>
|
||||
|
||||
#include "data/commoditydata.h"
|
||||
|
||||
class CommodityTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void defaultsAreZero()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
QCOMPARE(commodity.price().toDouble(), 0.0);
|
||||
QCOMPARE(commodity.count(), 0);
|
||||
QCOMPARE(commodity.vat(), Enums::NONE);
|
||||
QVERIFY(!commodity.favorite());
|
||||
}
|
||||
|
||||
void priceRoundTripUsesFixedPointStorage()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
commodity.setPrice(QDecDouble(19.9));
|
||||
|
||||
QVERIFY(qAbs(commodity.price().toDouble() - 19.9) < 0.0001);
|
||||
QCOMPARE(commodity.price(), commodity.unitPrice());
|
||||
}
|
||||
|
||||
void priceRoundTripHandlesWholeAmounts()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
commodity.setPrice(QDecDouble(125));
|
||||
|
||||
QCOMPARE(commodity.price().toDouble(), 125.0);
|
||||
}
|
||||
|
||||
void vatMirrorsShopItemInterface()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
commodity.setVat(Enums::HIGH);
|
||||
|
||||
QCOMPARE(commodity.vat(), Enums::HIGH);
|
||||
QCOMPARE(commodity.vatType(), Enums::HIGH);
|
||||
}
|
||||
|
||||
void pluginIdMatchesEmbeddedMetadata()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
QCOMPARE(commodity.pluginId(), QStringLiteral("COMMODITY"));
|
||||
}
|
||||
|
||||
void basicPropertiesRoundTrip()
|
||||
{
|
||||
CommodityData commodity;
|
||||
|
||||
commodity.setName(QStringLiteral("Položka"));
|
||||
commodity.setShortName(QStringLiteral("Pol."));
|
||||
commodity.setCode(QStringLiteral("A-01"));
|
||||
commodity.setCount(7);
|
||||
commodity.setFavorite(true);
|
||||
|
||||
QCOMPARE(commodity.name(), QStringLiteral("Položka"));
|
||||
QCOMPARE(commodity.shortName(), QStringLiteral("Pol."));
|
||||
QCOMPARE(commodity.code(), QStringLiteral("A-01"));
|
||||
QCOMPARE(commodity.count(), 7);
|
||||
QVERIFY(commodity.favorite());
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
CommodityTests tests;
|
||||
return QTest::qExec(&tests, argc, argv);
|
||||
}
|
||||
|
||||
#include "commodity_tests.moc"
|
||||
Reference in New Issue
Block a user