Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controllers/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> data, unsigned int length = 0) {
Q_INVOKABLE virtual void send(QList<int> data, unsigned int length = 0) {
Q_UNUSED(length);
m_pController->send(data, data.length());
}
Expand Down
29 changes: 19 additions & 10 deletions src/controllers/engine/controllerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>("QMessageBox::StandardButton");

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/engine/controllerengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -201,6 +203,8 @@ class ControllerEngine : public QObject {
QFileSystemWatcher m_scriptWatcher;
QList<QString> m_lastScriptPaths;

bool m_bTesting;

friend class ScriptConnection;
friend class ControllerEngineJSProxy;
friend class ControllerEngineTest;
Expand Down
34 changes: 33 additions & 1 deletion src/test/controller_preset_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> data, unsigned int length = 0) override {
Q_UNUSED(data);
Q_UNUSED(length);
}

Q_INVOKABLE void sendSysexMsg(QList<int> 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();
Expand All @@ -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();
Expand Down Expand Up @@ -116,6 +147,8 @@ class FakeController : public Controller {
FakeController::FakeController()
: m_bMidiPreset(false),
m_bHidPreset(false) {
startEngine();
getEngine()->setTesting(true);
}

FakeController::~FakeController() {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/controllerengine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ControllerEngineTest : public MixxxTest {
}

bool evaluateScriptFile(const QString& scriptName, QList<QString> scriptPaths = QList<QString>()) {
return cEngine->evaluateScriptFile(scriptName, scriptPaths);
return cEngine->evaluateScriptFile(scriptName, scriptPaths);
}

ControllerEngine *cEngine;
Expand Down