Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlobjectscripttest cleanup #4599

Merged
Merged
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
50 changes: 26 additions & 24 deletions src/test/controlobjectscripttest.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <QtDebug>

#include "control/controlobject.h"
#include "control/controlobjectscript.h"
#include "test/mixxxtest.h"
Expand Down Expand Up @@ -83,6 +81,14 @@ class ControlObjectScriptTest : public MixxxTest {
coScript4->removeScriptConnection(conn4);
}

void processEvents() {
// Calling processEvents() twice ensures that at least all queued and
// the next round of emitted events are processed.
// Test fails occurred here for a local debug build on Linux, but not on CI (see https://github.com/mixxxdj/mixxx/pull/4588)
application()->processEvents();
application()->processEvents();
}

ConfigKey ck1, ck2, ck4;
std::unique_ptr<ControlObject> co1;
std::unique_ptr<ControlObject> co2;
Expand All @@ -98,14 +104,13 @@ class ControlObjectScriptTest : public MixxxTest {
TEST_F(ControlObjectScriptTest, CompressingProxyCompareCount1) {
// Check that slotValueChanged callback is never called for conn2
EXPECT_CALL(*coScript2, slotValueChanged(_, _))
.Times(0)
.WillOnce(Return());
.Times(0);
// Check that slotValueChanged callback is called only once (independent of the value)
EXPECT_CALL(*coScript1, slotValueChanged(_, _))
.Times(1)
.WillOnce(Return());
co1->set(1.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, CompressingProxyCompareValue1) {
Expand All @@ -114,21 +119,20 @@ TEST_F(ControlObjectScriptTest, CompressingProxyCompareValue1) {
.WillOnce(Return());

co1->set(2.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, CompressingProxyCompareCount2) {
// Check that slotValueChanged callback is never called for conn2
EXPECT_CALL(*coScript2, slotValueChanged(_, _))
.Times(0)
.WillOnce(Return());
.Times(0);
// Check that slotValueChanged callback for conn1 is called only once (independent of the value)
EXPECT_CALL(*coScript1, slotValueChanged(_, _))
.Times(1)
.WillOnce(Return());
co1->set(3.0);
co1->set(4.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, CompressingProxyCompareValue2) {
Expand All @@ -138,21 +142,20 @@ TEST_F(ControlObjectScriptTest, CompressingProxyCompareValue2) {
.WillOnce(Return());
co1->set(5.0);
co1->set(6.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, QueuedCompareCount2) {
// Check that slotValueChanged callback is never called for conn4
EXPECT_CALL(*coScript2, slotValueChanged(_, _))
.Times(0)
.WillOnce(Return());
.Times(0);
// Check that slotValueChanged callback for conn1 is called only twice (independent of the value), because proxy is disabled
EXPECT_CALL(*coScript4, slotValueChanged(_, _))
.Times(2)
.WillOnce(Return());
co4->set(53.0);
co4->set(54.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, QueuedCompareValue2) {
Expand All @@ -165,7 +168,7 @@ TEST_F(ControlObjectScriptTest, QueuedCompareValue2) {
.WillOnce(Return());
co4->set(55.0);
co4->set(56.0);
application()->processEvents();
processEvents();
}
TEST_F(ControlObjectScriptTest, CompressingProxyCompareCountMulti) {
// Check that slotValueChanged callback for conn1 and conn2 is called only once (independent of the value)
Expand All @@ -176,7 +179,7 @@ TEST_F(ControlObjectScriptTest, CompressingProxyCompareCountMulti) {
co2->set(11.0);
co1->set(12.0);
co2->set(13.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, CompressingProxyCompareValueMulti) {
Expand All @@ -191,7 +194,7 @@ TEST_F(ControlObjectScriptTest, CompressingProxyCompareValueMulti) {
co2->set(21.0);
co1->set(22.0);
co2->set(23.0);
application()->processEvents();
processEvents();
}

TEST_F(ControlObjectScriptTest, CompressingProxyMultiConnection) {
Expand All @@ -208,7 +211,7 @@ TEST_F(ControlObjectScriptTest, CompressingProxyMultiConnection) {
co2->set(31.0);
co1->set(32.0);
co2->set(33.0);
application()->processEvents();
processEvents();

coScript2->removeScriptConnection(conn3);
}
Expand All @@ -235,14 +238,14 @@ TEST_F(ControlObjectScriptTest, QueuedFallbackMultiConnection) {
co2->set(61.0);
co1->set(62.0);
co2->set(63.0);
application()->processEvents();
processEvents();
conn3.skipSuperseded = false;
coScript2->addScriptConnection(conn3);
co1->set(64.0);
co2->set(65.0);
co1->set(66.0);
co2->set(67.0);
application()->processEvents();
processEvents();

coScript2->removeScriptConnection(conn3);
conn3.skipSuperseded = true;
Expand All @@ -267,19 +270,18 @@ TEST_F(ControlObjectScriptTest, CompressingProxyManyEvents) {
co2->set(42);

// Event queue should be cleared
application()->processEvents();
processEvents();
EXPECT_CALL(*coScript1, slotValueChanged(_, _))
.Times(0)
.WillOnce(Return());
application()->processEvents();
.Times(0);
processEvents();

// Verify that compressing proxy works again after clearing event queue
EXPECT_CALL(*coScript1, slotValueChanged(2, _))
.Times(1)
.WillOnce(Return());
co1->set(1);
co1->set(2);
application()->processEvents();
processEvents();
}

} // namespace