-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13853 from Swiftb0y/refactor/valuetransformer
Refactor `ValueTransformer` and `WBaseWidget`
- Loading branch information
Showing
13 changed files
with
338 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,59 @@ | ||
#include "widget/wpushbutton.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <QTestEventList> | ||
#include <QScopedPointer> | ||
#include <memory> | ||
|
||
#include "mixxxtest.h" | ||
#include "control/controlobject.h" | ||
#include "control/controlproxy.h" | ||
#include "control/controlpushbutton.h" | ||
#include "widget/wpushbutton.h" | ||
#include "util/valuetransformer.h" | ||
#include "widget/controlwidgetconnection.h" | ||
#include "widget/wbasewidget.h" | ||
|
||
class WPushButtonTest : public MixxxTest { | ||
class WPushButtonTest : public ::testing::Test { | ||
public: | ||
WPushButtonTest() | ||
: m_pGroup("[Channel1]") { | ||
} | ||
|
||
protected: | ||
void SetUp() override { | ||
m_pTouchShift.reset(new ControlPushButton(ConfigKey("[Controls]", "touch_shift"))); | ||
m_pButton.reset(new WPushButton()); | ||
m_pButton->setStates(2); | ||
// touchShift is needed internally to avoid a DEBUG_ASSERT | ||
ControlPushButton touchShift = ConfigKey( | ||
QStringLiteral("[Controls]"), QStringLiteral("touch_shift")); | ||
ControlPushButton pushControl = ConfigKey(QStringLiteral("[Test]"), QStringLiteral("push")); | ||
WPushButton pushButton = WPushButton(nullptr, | ||
mixxx::control::ButtonMode::LongPressLatching, | ||
mixxx::control::ButtonMode::Push); | ||
|
||
WPushButtonTest() { | ||
pushControl.setButtonMode(mixxx::control::ButtonMode::LongPressLatching); | ||
pushButton.setStates(2); | ||
pushButton.addConnection( | ||
std::make_unique<ControlParameterWidgetConnection>( | ||
&pushButton, | ||
pushControl.getKey(), | ||
nullptr, | ||
ControlParameterWidgetConnection::DIR_FROM_AND_TO_WIDGET, | ||
ControlParameterWidgetConnection::EMIT_ON_PRESS_AND_RELEASE), | ||
WBaseWidget::ConnectionSide::Left); | ||
} | ||
|
||
QScopedPointer<WPushButton> m_pButton; | ||
QScopedPointer<ControlPushButton> m_pTouchShift; | ||
QTestEventList m_Events; | ||
const char* m_pGroup; | ||
}; | ||
|
||
TEST_F(WPushButtonTest, QuickPressNoLatchTest) { | ||
QScopedPointer<ControlPushButton> pPushControl( | ||
new ControlPushButton(ConfigKey("[Test]", "push"))); | ||
pPushControl->setButtonMode(mixxx::control::ButtonMode::LongPressLatching); | ||
|
||
m_pButton.reset(new WPushButton(NULL, | ||
mixxx::control::ButtonMode::LongPressLatching, | ||
mixxx::control::ButtonMode::Push)); | ||
m_pButton->setStates(2); | ||
m_pButton->addLeftConnection( | ||
new ControlParameterWidgetConnection( | ||
m_pButton.data(), | ||
pPushControl->getKey(), NULL, | ||
ControlParameterWidgetConnection::DIR_FROM_AND_TO_WIDGET, | ||
ControlParameterWidgetConnection::EMIT_ON_PRESS_AND_RELEASE)); | ||
|
||
// This test can be flaky if the event simulator takes too long to deliver | ||
// the event. | ||
m_Events.addMousePress(Qt::LeftButton); | ||
m_Events.addDelay(100); | ||
m_Events.addMouseRelease(Qt::LeftButton); | ||
QTestEventList events; | ||
events.addMousePress(Qt::LeftButton); | ||
events.addDelay(100); | ||
events.addMouseRelease(Qt::LeftButton); | ||
|
||
m_Events.simulate(m_pButton.data()); | ||
events.simulate(&pushButton); | ||
|
||
ASSERT_EQ(0.0, m_pButton->getControlParameterLeft()); | ||
ASSERT_EQ(0.0, pushButton.getControlParameterLeft()); | ||
} | ||
|
||
TEST_F(WPushButtonTest, LongPressLatchTest) { | ||
QScopedPointer<ControlPushButton> pPushControl( | ||
new ControlPushButton(ConfigKey("[Test]", "push"))); | ||
pPushControl->setButtonMode(mixxx::control::ButtonMode::LongPressLatching); | ||
|
||
m_pButton.reset(new WPushButton(NULL, | ||
mixxx::control::ButtonMode::LongPressLatching, | ||
mixxx::control::ButtonMode::Push)); | ||
m_pButton->setStates(2); | ||
m_pButton->addLeftConnection( | ||
new ControlParameterWidgetConnection( | ||
m_pButton.data(), | ||
pPushControl->getKey(), NULL, | ||
ControlParameterWidgetConnection::DIR_FROM_AND_TO_WIDGET, | ||
ControlParameterWidgetConnection::EMIT_ON_PRESS_AND_RELEASE)); | ||
|
||
m_Events.addMousePress(Qt::LeftButton); | ||
m_Events.addDelay(1000); | ||
m_Events.addMouseRelease(Qt::LeftButton); | ||
QTestEventList events; | ||
events.addMousePress(Qt::LeftButton); | ||
events.addDelay(1000); | ||
events.addMouseRelease(Qt::LeftButton); | ||
|
||
m_Events.simulate(m_pButton.data()); | ||
events.simulate(&pushButton); | ||
|
||
ASSERT_EQ(1.0, m_pButton->getControlParameterLeft()); | ||
ASSERT_EQ(1.0, pushButton.getControlParameterLeft()); | ||
} |
Oops, something went wrong.