diff --git a/src/controllers/controller.h b/src/controllers/controller.h index 5df89a0f1206..b0b9e2cc7320 100644 --- a/src/controllers/controller.h +++ b/src/controllers/controller.h @@ -188,7 +188,7 @@ class ControllerJSProxy: public QObject { // The length parameter is here for backwards compatibility for when scripts // were required to specify it. - Q_INVOKABLE void send(QList data, unsigned int length = 0) { + Q_INVOKABLE virtual void send(QList data, unsigned int length = 0) { Q_UNUSED(length); m_pController->send(data, data.length()); } diff --git a/src/controllers/engine/controllerengine.cpp b/src/controllers/engine/controllerengine.cpp index f06efbb847a5..ca699d95363d 100644 --- a/src/controllers/engine/controllerengine.cpp +++ b/src/controllers/engine/controllerengine.cpp @@ -33,7 +33,8 @@ const double kAlphaBetaDt = kScratchTimerMs / 1000.0; ControllerEngine::ControllerEngine(Controller* controller) : m_bDisplayingExceptionDialog(false), m_pScriptEngine(nullptr), - m_pController(controller) { + m_pController(controller), + m_bTesting(false) { // Handle error dialog buttons qRegisterMetaType("QMessageBox::StandardButton"); @@ -615,9 +616,13 @@ QJSValue ControllerEngine::makeConnection(QString group, QString name, ControlObjectScript* coScript = getControlObjectScript(group, name); if (coScript == nullptr) { - throwJSError("ControllerEngine: script tried to connect to ControlObject (" + - group + ", " + name + - ") which is non-existent."); + // The test setups do not run all of Mixxx, so ControlObjects not + // existing during tests is okay. + if (!m_bTesting) { + throwJSError("ControllerEngine: script tried to connect to ControlObject (" + + group + ", " + name + + ") which is non-existent."); + } return QJSValue(); } @@ -728,12 +733,16 @@ QJSValue ControllerEngine::connectControl( // This check is redundant with makeConnection, but the // ControlObjectScript is also needed here to check for duplicate connections. if (coScript == nullptr) { - if (disconnect) { - qWarning() << "ControllerEngine: script tried to disconnect from ControlObject (" + - group + ", " + name + ") which is non-existent, ignoring."; - } else { - qWarning() << "ControllerEngine: script tried to connect to ControlObject (" + - group + ", " + name + ") which is non-existent, ignoring."; + // The test setups do not run all of Mixxx, so ControlObjects not + // existing during tests is okay. + if (!m_bTesting) { + if (disconnect) { + throwJSError("ControllerEngine: script tried to disconnect from ControlObject (" + + group + ", " + name + ") which is non-existent."); + } else { + throwJSError("ControllerEngine: script tried to connect to ControlObject (" + + group + ", " + name + ") which is non-existent."); + } } // This is inconsistent with other failures, which return false. // QJSValue() with no arguments is undefined in JavaScript. diff --git a/src/controllers/engine/controllerengine.h b/src/controllers/engine/controllerengine.h index 4067d8feecfa..28b7ef2acbe1 100644 --- a/src/controllers/engine/controllerengine.h +++ b/src/controllers/engine/controllerengine.h @@ -97,6 +97,8 @@ class ControllerEngine : public QObject { void removeScriptConnection(const ScriptConnection conn); void triggerScriptConnection(const ScriptConnection conn); + inline void setTesting(bool testing) { m_bTesting = testing; }; + protected: double getValue(QString group, QString name); void setValue(QString group, QString name, double newValue); @@ -201,6 +203,8 @@ class ControllerEngine : public QObject { QFileSystemWatcher m_scriptWatcher; QList m_lastScriptPaths; + bool m_bTesting; + friend class ScriptConnection; friend class ControllerEngineJSProxy; friend class ControllerEngineTest; diff --git a/src/test/controller_preset_validation_test.cpp b/src/test/controller_preset_validation_test.cpp index a280dca5fca5..39b6b4070230 100644 --- a/src/test/controller_preset_validation_test.cpp +++ b/src/test/controller_preset_validation_test.cpp @@ -13,6 +13,33 @@ #include "controllers/defs_controllers.h" #include "test/mixxxtest.h" +class FakeControllerJSProxy : public ControllerJSProxy { + Q_OBJECT + public: + FakeControllerJSProxy(); + + Q_INVOKABLE void send(QList data, unsigned int length = 0) override { + Q_UNUSED(data); + Q_UNUSED(length); + } + + Q_INVOKABLE void sendSysexMsg(QList data, unsigned int length = 0) { + Q_UNUSED(data); + Q_UNUSED(length); + } + + Q_INVOKABLE void sendShortMsg(unsigned char status, + unsigned char byte1, unsigned char byte2) { + Q_UNUSED(status); + Q_UNUSED(byte1); + Q_UNUSED(byte2); + } +}; + +FakeControllerJSProxy::FakeControllerJSProxy() + : ControllerJSProxy(nullptr) { +} + class FakeController : public Controller { public: FakeController(); @@ -23,6 +50,10 @@ class FakeController : public Controller { return ".test.xml"; } + ControllerJSProxy* jsProxy() override { + return new FakeControllerJSProxy(); + } + ControllerPresetPointer getPreset() const override { if (m_bHidPreset) { HidControllerPreset* pClone = new HidControllerPreset(); @@ -116,6 +147,8 @@ class FakeController : public Controller { FakeController::FakeController() : m_bMidiPreset(false), m_bHidPreset(false) { + startEngine(); + getEngine()->setTesting(true); } FakeController::~FakeController() { @@ -138,7 +171,6 @@ class ControllerPresetValidationTest : public MixxxTest { FakeController controller; controller.setDeviceName("Test Controller"); - controller.startEngine(); controller.setPreset(*pPreset); // Do not initialize the scripts. bool result = controller.applyPreset(m_presetPaths, false); diff --git a/src/test/controllerengine_test.cpp b/src/test/controllerengine_test.cpp index 642673e7fa81..7ee67ac296e2 100644 --- a/src/test/controllerengine_test.cpp +++ b/src/test/controllerengine_test.cpp @@ -33,7 +33,7 @@ class ControllerEngineTest : public MixxxTest { } bool evaluateScriptFile(const QString& scriptName, QList scriptPaths = QList()) { - return cEngine->evaluateScriptFile(scriptName, scriptPaths); + return cEngine->evaluateScriptFile(scriptName, scriptPaths); } ControllerEngine *cEngine;