112 lines
5.6 KiB
Markdown
112 lines
5.6 KiB
Markdown
# QtTest regression tests
|
||
|
||
For instrumented builds, LCOV HTML reports, and Qt Creator coverage configuration,
|
||
see [Measuring code coverage](../README.md#measuring-code-coverage).
|
||
For the complete IDE build/run configuration set, see
|
||
[Configure all build variants in Qt Creator](../README.md#configure-all-build-variants-in-qt-creator).
|
||
The Coverage configuration uses `coverage_report.sh` after its instrumented
|
||
build; the script takes the source and build directories as its two arguments.
|
||
|
||
Open the repository's root `dbc.pro` in Qt Creator. It contains `core` (a static
|
||
C++17 library) and `tests` (the `dbc_tests` QtTest executable). Core is built first;
|
||
tests link its archive rather than compiling its implementation again.
|
||
Qt Core and Qt Test development packages are required for tests only.
|
||
The optional model tests also link QtGui, which is provided by Qt base development
|
||
packages. The adapter library itself still links only QtCore.
|
||
|
||
Build from the repository root with the installed Qt 6.8.2:
|
||
|
||
```sh
|
||
mkdir build
|
||
cd build
|
||
qmake6 ../dbc.pro
|
||
make -j
|
||
make check
|
||
```
|
||
|
||
Or run `./tests/dbc_tests` directly. Parser, decoder, and additional coverage
|
||
suites run, and the executable returns nonzero when any suite fails. Decoder cases appear as
|
||
individual QtTest data rows; parser checks are grouped into named test slots.
|
||
Checks also run in release builds.
|
||
|
||
To build tests separately against an existing core build:
|
||
|
||
```sh
|
||
mkdir /tmp/dbc-tests-build
|
||
cd /tmp/dbc-tests-build
|
||
qmake6 /absolute/path/to/dbc/tests/tests.pro \
|
||
DBC_CORE_BUILD_DIR=/absolute/path/to/build/core
|
||
make
|
||
make check
|
||
```
|
||
|
||
`parser_tests.pri` and `decoder_tests.pri` include the original test sources;
|
||
`tests.pro` also includes `dbc_coverage_test.cpp`.
|
||
`../core/core.pri` supplies the library include path and linkage.
|
||
|
||
## Decoder coverage
|
||
|
||
Coverage includes Motorola bit numbering within and across bytes, unaligned
|
||
signals, signed values, scaling, 64-bit extraction, signed/unsigned boundary values
|
||
(including `INT64_MIN`, `INT64_MAX`, and `UINT64_MAX`), numeric output, invalid lengths, insufficient
|
||
payloads, and Intel regression cases. Frame validity means the definition was
|
||
found; insufficient payloads are checked through signal validity.
|
||
|
||
## Parser coverage
|
||
|
||
Parser tests cover standard and extended CAN IDs, whitespace, payload storage
|
||
boundaries, missing fields, malformed and overflowing numbers, reserved ID bits,
|
||
error paths and line numbers, and integration with signals and comments.
|
||
Duplicate definitions are rejected at their source lines, including equivalent
|
||
extended ID encodings and repeated signal names within a frame. Standard and
|
||
extended frames may share a numeric ID, and separate frames may reuse signal names.
|
||
Signal tests cover complete syntax and numeric validation, scientific notation,
|
||
finite physical parameters and ordered ranges, spaces and tabs, receiver lists,
|
||
unsupported multiplexing, and Intel/Motorola declared-payload boundaries.
|
||
Value-description tests cover full `VAL_` syntax, whitespace, escaped quotes,
|
||
empty text, exact integer boundaries, duplicate keys within and across statements,
|
||
deferred and normalized frame references, missing targets, error locations,
|
||
raw lookup with scaling, unknown/invalid values, and both database builders.
|
||
Temporary DBC fixtures are created in the system temporary directory and removed
|
||
automatically.
|
||
|
||
Dispatch tests also verify exact keyword matching, handler construction and reuse,
|
||
unknown statements, and independent parsing sessions, including recovery after errors.
|
||
|
||
## Tree and optional model tests
|
||
|
||
`tree_node_test.cpp` is a standalone C++17 executable without Qt; see the root
|
||
README for its compiler command. It checks parents, sibling positions, null
|
||
children, bounds, and unique_ptr transfer.
|
||
|
||
Enable `CONFIG+=dbc_qt` in the root qmake invocation to build `dbc_qt` and
|
||
`dbc_model_tests` alongside existing tests. Qt 6.8.2 is required.
|
||
`make check` runs all suites. Model tests parse a temporary DBC fixture and use
|
||
QAbstractItemModelTester, verify navigation across columns, invalid/foreign
|
||
indexes, metadata and exact VAL_ integers, and persistent-index invalidation
|
||
when reloading or clearing the tree. Their QGuiApplication registers graphical
|
||
metatypes used by QAbstractItemModelTester, avoiding the invalid QPixmap type
|
||
warning in Qt 6.8.2. The test executable defaults to `QT_QPA_PLATFORM=offscreen`
|
||
when the variable is unset or empty, so no display server is needed. An explicit
|
||
platform setting is preserved.
|
||
|
||
Basic multiplexing coverage includes selector declarations after branches,
|
||
Intel/Motorola branch overlap, signed active values and VAL_ lookup, unconditional
|
||
signals, inactive branches, missing selector/branch payloads, exact UINT64_MAX
|
||
selector matching, malformed runtime selectors, source locations, and rejection
|
||
of invalid markers, selector references/ranges, overlaps, and SG_MUL_VAL_.
|
||
|
||
## Additional regression coverage
|
||
|
||
`dbc_coverage_test.cpp` runs as part of `dbc_tests`. It covers signed boundaries
|
||
below 64 bits, deterministic extraction comparisons for both byte orders across
|
||
lengths 1–64, frame lookup failures, exact decode statuses, malformed runtime
|
||
multiplexing, PGN boundaries, comment handling, file formatting, metadata copying
|
||
and source lifetime, physical conversion, and TypeFactory registration/creation.
|
||
Direct resolver tests construct ambiguous databases through the public metadata
|
||
API, verify source locations, and check that ambiguous targets receive no values.
|
||
|
||
All QtTest targets use Qt 6.8.2 and `QVERIFY_THROWS_EXCEPTION`. Exception tests
|
||
explicitly discard `nodiscard` results when only the exception is being checked.
|
||
The standalone tree test requires only a C++17 compiler.
|