summaryrefslogtreecommitdiffstats
path: root/src/test/effectchainslottest.cpp
blob: 8e82937d7a23c721001643e1b72c2c61a19a34a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <gtest/gtest.h>
#include <gmock/gmock.h>

#include <QtDebug>
#include <QScopedPointer>

#include "mixxxtest.h"
#include "control/controlobject.h"
#include "effects/effectchain.h"
#include "effects/effectchainslot.h"
#include "effects/effectrack.h"
#include "effects/effectsmanager.h"
#include "test/baseeffecttest.h"

using ::testing::Return;
using ::testing::_;

class EffectChainSlotTest : public BaseEffectTest {
  protected:
    EffectChainSlotTest()
            : m_master(m_factory.getOrCreateHandle("[Master]"), "[Master]"),
              m_headphone(m_factory.getOrCreateHandle("[Headphone]"), "[Headphone]") {
        m_pEffectsManager->registerChannel(m_master);
        m_pEffectsManager->registerChannel(m_headphone);
    }

    ChannelHandleFactory m_factory;
    ChannelHandleAndGroup m_master;
    ChannelHandleAndGroup m_headphone;
};

TEST_F(EffectChainSlotTest, ChainSlotMirrorsLoadedChain) {
    EffectChainPointer pChain(new EffectChain(m_pEffectsManager.data(),
                                              "org.mixxx.test.chain1"));
    int iRackNumber = 0;
    int iChainNumber = 0;

    StandardEffectRackPointer pRack = m_pEffectsManager->addStandardEffectRack();
    EffectChainSlotPointer pChainSlot = pRack->addEffectChainSlot();

    QString group = StandardEffectRack::formatEffectChainSlotGroupString(
        iRackNumber, iChainNumber);
    pChainSlot->loadEffectChain(pChain);

    pChain->setEnabled(true);
    EXPECT_LT(0.0, ControlObject::get(ConfigKey(group, "enabled")));

    pChain->setEnabled(false);
    EXPECT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(group, "enabled")));

    ControlObject::set(ConfigKey(group, "enabled"), 1.0);
    EXPECT_TRUE(pChain->enabled());

    // Loaded is read-only. Sets to it should not do anything.
    ControlObject::set(ConfigKey(group, "loaded"), 0);
    EXPECT_TRUE(ControlObject::get(ConfigKey(group, "loaded")) > 0.0);

    // numEffects is read-only. Sets to it should not do anything.
    ControlObject::set(ConfigKey(group, "num_effects"), 1);
    EXPECT_EQ(0U, pChain->numEffects());

    pChain->setMix(1.0);
    EXPECT_DOUBLE_EQ(pChain->mix(),
                     ControlObject::get(ConfigKey(group, "mix")));

    ControlObject::set(ConfigKey(group, "mix"), 0.5);
    EXPECT_DOUBLE_EQ(0.5, pChain->mix());

    pChain->setInsertionType(EffectChain::SEND);
    EXPECT_DOUBLE_EQ(pChain->insertionType(),
                     ControlObject::get(ConfigKey(group, "insertion_type")));

    ControlObject::set(ConfigKey(group, "insertion_type"), EffectChain::INSERT);
    EXPECT_DOUBLE_EQ(EffectChain::INSERT, pChain->insertionType());

    EXPECT_FALSE(pChain->enabledForChannel(m_master));
    pChain->enableForChannel(m_master);
    EXPECT_LT(0.0, ControlObject::get(ConfigKey(group, "group_[Master]_enable")));

    ControlObject::set(ConfigKey(group, "group_[Master]_enable"), 0);
    EXPECT_FALSE(pChain->enabledForChannel(m_master));
}

TEST_F(EffectChainSlotTest, ChainSlotMirrorsLoadedChain_StartsWithChainLoaded) {
    EffectChainPointer pChain(new EffectChain(m_pEffectsManager.data(),
                                              "org.mixxx.test.chain1"));
    int iRackNumber = 0;
    int iChainNumber = 0;

    StandardEffectRackPointer pRack = m_pEffectsManager->addStandardEffectRack();
    EffectChainSlotPointer pChainSlot = pRack->addEffectChainSlot();
    pChainSlot->loadEffectChain(pChain); 
    QString group = StandardEffectRack::formatEffectChainSlotGroupString(
        iRackNumber, iChainNumber);
    EXPECT_DOUBLE_EQ(1.0, ControlObject::get(ConfigKey(group, "loaded")));
}

TEST_F(EffectChainSlotTest, ChainSlotMirrorsLoadedChain_Clear) {
    EffectChainPointer pChain(new EffectChain(m_pEffectsManager.data(),
                                              "org.mixxx.test.chain1"));

    int iRackNumber = 0;
    int iChainNumber = 0;

    StandardEffectRackPointer pRack = m_pEffectsManager->addStandardEffectRack();
    EffectChainSlotPointer pChainSlot = pRack->addEffectChainSlot();

    QString group = StandardEffectRack::formatEffectChainSlotGroupString(
        iRackNumber, iChainNumber);
    EXPECT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(group, "loaded")));
    pChainSlot->loadEffectChain(pChain);
    EXPECT_DOUBLE_EQ(1.0, ControlObject::get(ConfigKey(group, "loaded")));
    ControlObject::set(ConfigKey(group, "clear"), 1.0);
    EXPECT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(group, "loaded")));
}