#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <QString>
#include <QScopedPointer>
#include "test/librarytest.h"
#include "library/autodj/autodjprocessor.h"
#include "control/controlpushbutton.h"
#include "control/controlpotmeter.h"
#include "control/controllinpotmeter.h"
#include "mixer/playermanager.h"
#include "mixer/basetrackplayer.h"
#include "track/track.h"
#include "sources/soundsourceproxy.h"
using ::testing::_;
using ::testing::Return;
static int kDefaultTransitionTime = 10;
const QString kTrackLocationTest(QDir::currentPath() %
"/src/test/id3-test-data/cover-test-png.mp3");
class FakeMaster {
public:
FakeMaster()
: crossfader(ConfigKey("[Master]", "crossfader"), -1.0, 1.0),
crossfaderReverse(ConfigKey("[Mixer Profile]", "xFaderReverse")) {
crossfaderReverse.setButtonMode(ControlPushButton::TOGGLE);
}
ControlPotmeter crossfader;
ControlPushButton crossfaderReverse;
};
class FakeDeck : public BaseTrackPlayer {
public:
FakeDeck(const QString& group)
: BaseTrackPlayer(NULL, group),
playposition(ConfigKey(group, "playposition"), 0.0, 1.0, true),
play(ConfigKey(group, "play")),
repeat(ConfigKey(group, "repeat")) {
play.setButtonMode(ControlPushButton::TOGGLE);
repeat.setButtonMode(ControlPushButton::TOGGLE);
}
void fakeTrackLoadedEvent(TrackPointer pTrack) {
loadedTrack = pTrack;
emit(newTrackLoaded(pTrack));
}
void fakeTrackLoadFailedEvent(TrackPointer pTrack) {
// The real EngineBuffer ejects the track first which clears a variety
// of controls (play, track_samples, track_samplerate, playposition,
// etc.).
fakeUnloadingTrackEvent(pTrack);
}
void fakeUnloadingTrackEvent(TrackPointer pTrack) {
play.set(0.0);
emit(loadingTrack(TrackPointer(), pTrack));
loadedTrack.reset();
emit(playerEmpty());
}
TrackPointer getLoadedTrack() const {
return loadedTrack;
}
// This method emulates requesting a track load to a player and emits no
// signals. Normally, the reader thread attempts to load the file and emits
// a success or failure signal. To simulate a load success, call
// fakeTrackLoadedEvent. To simulate a failure, call
// fakeTrackLoadFailedEvent.
void slotLoadTrack(TrackPointer pTrack, bool bPlay) override {
loadedTrack = pTrack;
play.set(bPlay);
}
TrackPointer loadedTrack;
ControlLinPotmeter playposition;
ControlPushButton play;
ControlPushButton repeat;
};
class MockPlayerManager : public PlayerManagerInterface {
public:
MockPlayerManager()
: numDecks(ConfigKey("[Master]", "num_decks"), true),
numSamplers(ConfigKey("[Master]", "num_samplers"), true),
numPreviewDecks(ConfigKey("[Master]", "num_preview_decks"),
true) {
}
virtual ~MockPlayerManager() {
}
MOCK_CONST_METHOD1(getPlayer, BaseTrackPlayer*(QString));
MOCK_CONST_METHOD1(getDeck, Deck*(unsigned int));
MOCK_CONST_METHOD1(getPreviewDeck, PreviewDeck*(unsigned int));
MOCK_CONST_METHOD1(getSampler, Sampler*(unsigned int));
unsigned int numberOfDecks() const {
return static_cast<unsigned int>(numDecks.get());
}
unsigned int