mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-03 00:45:56 +00:00
add string formatter
This commit is contained in:
@ -27,7 +27,7 @@ set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSO
|
||||
## modules
|
||||
set(TEST_MODULES
|
||||
abstractextitem extquotes extscript extupgrade extweather
|
||||
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter
|
||||
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter stringformatter
|
||||
extitemaggregator
|
||||
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
|
||||
awconfighelper awkeycache awkeys awpatternfunctions awupdatehelper
|
||||
|
@ -49,8 +49,7 @@ void TestAWFloatFormatter::test_count()
|
||||
QCOMPARE(formatter->count(), count);
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
@ -67,8 +66,7 @@ void TestAWFloatFormatter::test_fillChar()
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
int value = AWTestLibrary::randomInt();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomInt());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
|
||||
// reset
|
||||
@ -77,6 +75,24 @@ void TestAWFloatFormatter::test_fillChar()
|
||||
}
|
||||
|
||||
|
||||
void TestAWFloatFormatter::test_forceWidth()
|
||||
{
|
||||
// assign
|
||||
int count = AWTestLibrary::randomInt(6);
|
||||
formatter->setForceWidth(true);
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->forceWidth(), true);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setForceWidth(false);
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWFloatFormatter::test_format()
|
||||
{
|
||||
// assign
|
||||
@ -87,8 +103,7 @@ void TestAWFloatFormatter::test_format()
|
||||
QCOMPARE(formatter->format(), 'e');
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QVERIFY(output.contains('e'));
|
||||
|
||||
// reset
|
||||
@ -104,8 +119,7 @@ void TestAWFloatFormatter::test_precision()
|
||||
QCOMPARE(formatter->precision(), precision);
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
output.remove(QString("0."));
|
||||
QCOMPARE(output.count(), precision);
|
||||
|
||||
@ -157,6 +171,7 @@ void TestAWFloatFormatter::test_copy()
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
QCOMPARE(newFormatter->forceWidth(), formatter->forceWidth());
|
||||
QCOMPARE(newFormatter->format(), formatter->format());
|
||||
QCOMPARE(newFormatter->multiplier(), formatter->multiplier());
|
||||
QCOMPARE(newFormatter->precision(), formatter->precision());
|
||||
@ -171,6 +186,7 @@ void TestAWFloatFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
formatter->setFormat(AWTestLibrary::randomChar());
|
||||
formatter->setMultiplier(AWTestLibrary::randomDouble());
|
||||
formatter->setPrecision(AWTestLibrary::randomInt());
|
||||
|
@ -36,6 +36,7 @@ private slots:
|
||||
void test_values();
|
||||
void test_count();
|
||||
void test_fillChar();
|
||||
void test_forceWidth();
|
||||
void test_format();
|
||||
void test_precision();
|
||||
void test_multiplier();
|
||||
|
118
sources/test/teststringformatter.cpp
Normal file
118
sources/test/teststringformatter.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "teststringformatter.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awstringformatter.h"
|
||||
#include "awtestlibrary.h"
|
||||
|
||||
|
||||
void TestAWStringFormatter::initTestCase()
|
||||
{
|
||||
formatter = new AWStringFormatter(nullptr);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::cleanupTestCase()
|
||||
{
|
||||
delete formatter;
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_values()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_count()
|
||||
{
|
||||
// assign
|
||||
int count = 10 + AWTestLibrary::randomInt();
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->count(), count);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_fillChar()
|
||||
{
|
||||
// assign
|
||||
char c = AWTestLibrary::randomChar();
|
||||
formatter->setFillChar(QChar(c));
|
||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
|
||||
// reset
|
||||
formatter->setFillChar(QChar());
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_forceWidth()
|
||||
{
|
||||
// assign
|
||||
int count = AWTestLibrary::randomInt();
|
||||
formatter->setForceWidth(true);
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->forceWidth(), true);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setForceWidth(false);
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_copy()
|
||||
{
|
||||
doRandom();
|
||||
AWStringFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
QCOMPARE(newFormatter->forceWidth(), formatter->forceWidth());
|
||||
QCOMPARE(newFormatter->number(), 1);
|
||||
|
||||
delete newFormatter;
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAWStringFormatter);
|
48
sources/test/teststringformatter.h
Normal file
48
sources/test/teststringformatter.h
Normal file
@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef TESTSTRINGFORMATTER_H
|
||||
#define TESTSTRINGFORMATTER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class AWStringFormatter;
|
||||
|
||||
class TestAWStringFormatter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_values();
|
||||
void test_count();
|
||||
void test_fillChar();
|
||||
void test_forceWidth();
|
||||
void test_copy();
|
||||
|
||||
private:
|
||||
void doRandom();
|
||||
AWStringFormatter *formatter = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTSTRINGFORMATTER_H */
|
Reference in New Issue
Block a user