Add unit tests for the TetraIF modules in a unit-test folder
New TetraIF/unit-test/ directory with one QtTest executable per TetraIF release-scope module, wired into ctest and the DEB pipeline: - coprtcnv_unit_test: central and radio telegram header fields, payload access, length checks, fragmentation/reassembly roundtrip, telegram-id string helpers - logview_unit_test: IntegerCalculator arithmetic, operator priority, parentheses, error codes and variables (compiles the LogView class source directly; the class otherwise lives in the LogView executable) - prtcnv_unit_test: PrtCnvMember state and fragmented-telegram handling (compiles the class source directly because PrtCnvLib is built with hidden visibility) TetraIF/CMakeLists.txt adds the unit-test subdirectory and new_docker_build.sh builds and ctest-runs the three new targets.
This commit is contained in:
1 parent
2d1b12b5d8
commit
cebc456bc1
6 files changed
+495
No files matched your search
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Unit tests for the LogView module: IntegerCalculator (the module's pure
|
||||
// logic class, compiled from the LogView sources).
|
||||
//
|
||||
#include "../LogView/IntegerCalculator.hpp"
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <string>
|
||||
|
||||
using IntegerCalculator = N_SST::IntegerCalculator;
|
||||
using E_Error = IntegerCalculator::E_Error;
|
||||
|
||||
class logview_unit_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void basicArithmetic();
|
||||
void operatorPriority();
|
||||
void parentheses();
|
||||
void unaryMinus();
|
||||
void divisionByZero();
|
||||
void noOperandBetweenOperators();
|
||||
void missingRightParanthesis();
|
||||
void missingLeftParanthesis();
|
||||
void unknownVariable();
|
||||
void variables();
|
||||
};
|
||||
|
||||
void logview_unit_test::basicArithmetic()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_UnknownError;
|
||||
|
||||
QCOMPARE(calc.calc("1+2", error), 3);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("10-4", error), 6);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("6*7", error), 42);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("84/4", error), 21);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
}
|
||||
|
||||
void logview_unit_test::operatorPriority()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_UnknownError;
|
||||
|
||||
QCOMPARE(calc.calc("1+2*3", error), 7);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("2*3+4", error), 10);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("10-2*3", error), 4);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
}
|
||||
|
||||
void logview_unit_test::parentheses()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_UnknownError;
|
||||
|
||||
QCOMPARE(calc.calc("(1+2)*3", error), 9);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
QCOMPARE(calc.calc("((2+3)*4)", error), 20);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
}
|
||||
|
||||
void logview_unit_test::unaryMinus()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_UnknownError;
|
||||
|
||||
QCOMPARE(calc.calc("-3+5", error), 2);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
}
|
||||
|
||||
void logview_unit_test::divisionByZero()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_Ok;
|
||||
|
||||
(void)calc.calc("1/0", error);
|
||||
QCOMPARE(error, E_Error::e_DivisionByZero);
|
||||
}
|
||||
|
||||
void logview_unit_test::noOperandBetweenOperators()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_Ok;
|
||||
|
||||
(void)calc.calc("1+*2", error);
|
||||
QCOMPARE(error, E_Error::e_NoOperandBetweenOperators);
|
||||
}
|
||||
|
||||
void logview_unit_test::missingRightParanthesis()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_Ok;
|
||||
|
||||
(void)calc.calc("(1+2", error);
|
||||
QCOMPARE(error, E_Error::e_MissingRightParanthesis);
|
||||
}
|
||||
|
||||
void logview_unit_test::missingLeftParanthesis()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_Ok;
|
||||
|
||||
(void)calc.calc("1+2)", error);
|
||||
QCOMPARE(error, E_Error::e_MissingLeftParanthesis);
|
||||
}
|
||||
|
||||
void logview_unit_test::unknownVariable()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_Ok;
|
||||
|
||||
(void)calc.calc("y", error);
|
||||
QCOMPARE(error, E_Error::e_UnknownOperationOrVariable);
|
||||
}
|
||||
|
||||
void logview_unit_test::variables()
|
||||
{
|
||||
IntegerCalculator calc;
|
||||
E_Error error = E_Error::e_UnknownError;
|
||||
|
||||
calc.addVariable("x", 5);
|
||||
QCOMPARE(calc.calc("x*2", error), 10);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
calc.addVariable("y", -3);
|
||||
QCOMPARE(calc.calc("x+y", error), 2);
|
||||
QCOMPARE(error, E_Error::e_Ok);
|
||||
|
||||
calc.removeVariable("x");
|
||||
error = E_Error::e_Ok;
|
||||
(void)calc.calc("x", error);
|
||||
QCOMPARE(error, E_Error::e_UnknownOperationOrVariable);
|
||||
}
|
||||
|
||||
QTEST_MAIN(logview_unit_test)
|
||||
#include "logview_unit_test.moc"
|
||||
Reference in new issue
Block a user