Patrick Schurig c2eccd96e5 sunspec: add a failing test that sets up a Fronius connection
The existing suite only exercises free functions and the plugin JSON, so it
cannot see whether a thing class is dispatched at all. A thing class missing
from the dispatch in setupThing() falls into the final Q_ASSERT_X: in a debug
build the process dies, in a release build the assert is compiled out and
setupThing() returns without ever calling info->finish(), leaving the pairing
stuck with no message.

Split the tests into two suites. The logic one keeps its former scope and its
single dependency on libnymea-sunspec. The new one instantiates the plugin
behind the real ThingManager of libnymea-core and a faked HardwareManager, so
the dispatch of setupThing(), postSetupThing() and thingRemoved() is covered.
No network access takes place: the faked monitor is never reachable, so the
plugin never attempts a Modbus connection.

The four new cases fail: froniusConnection is not dispatched yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-01 16:18:41 +02:00

63 lines
2.2 KiB
Prolog

include(../../../sunspec.pri)
QT += testlib network serialbus
QT -= gui
CONFIG += console testcase c++17
CONFIG -= app_bundle
TEMPLATE = app
TARGET = tst_sunspecplugin
# Suite qui instancie reellement IntegrationPluginSunSpec, derriere un
# ThingManager reel (celui de libnymea-core) et un HardwareManager double. Elle
# couvre ce que la suite de logique pure ne peut pas voir : l'aiguillage de
# setupThing() / postSetupThing() / thingRemoved() sur la thingClass.
#
# Dependances supplementaires par rapport a ../logic : libnymea1-dev et
# libnymea-core (pkg-config nymea et nymea-core).
CONFIG += link_pkgconfig
PKGCONFIG += nymea nymea-core
PLUGIN_DIR = $$PWD/../..
INCLUDEPATH += $$PLUGIN_DIR
# Le plugin s'appuie sur les identifiants generes depuis son JSON. On les
# fabrique ici exactement comme le fait plugin.pri pour le plugin lui-meme :
# plugininfo.h (definitions, inclus par integrationpluginsunspec.cpp) et
# extern-plugininfo.h (declarations, inclus par les en-tetes et par le test).
JSONFILE = $$PLUGIN_DIR/integrationpluginsunspec.json
OTHER_FILES += $$JSONFILE
plugininfo.input = JSONFILE
plugininfo.output = plugininfo.h
plugininfo.commands = nymea-plugininfocompiler ${QMAKE_FILE_NAME} --output ${QMAKE_FILE_OUT}
plugininfo.dependency_type = TYPE_C
plugininfo.CONFIG += no_link combine
QMAKE_EXTRA_COMPILERS += plugininfo
extern_plugininfo.input = JSONFILE
extern_plugininfo.output = extern-plugininfo.h
extern_plugininfo.commands = nymea-plugininfocompiler ${QMAKE_FILE_NAME} --extern ${QMAKE_FILE_OUT}
extern_plugininfo.dependency_type = TYPE_C
extern_plugininfo.CONFIG += no_link combine
QMAKE_EXTRA_COMPILERS += extern_plugininfo
DEFINES += PLUGIN_JSON_PATH=\\\"$$JSONFILE\\\"
SOURCES += \
tst_sunspecplugin.cpp \
$$PLUGIN_DIR/integrationpluginsunspec.cpp \
$$PLUGIN_DIR/froniusrules.cpp \
$$PLUGIN_DIR/solaredgebattery.cpp \
$$PLUGIN_DIR/sunspecdiscovery.cpp \
$$PLUGIN_DIR/sunspecstoragelogic.cpp \
$$PLUGIN_DIR/sunspecthing.cpp
HEADERS += \
$$PLUGIN_DIR/integrationpluginsunspec.h \
$$PLUGIN_DIR/froniusrules.h \
$$PLUGIN_DIR/solaredgebattery.h \
$$PLUGIN_DIR/sunspecdiscovery.h \
$$PLUGIN_DIR/sunspecstoragelogic.h \
$$PLUGIN_DIR/sunspecthing.h