|
| 1 | +// This file is part of Noteahead. |
| 2 | +// Copyright (C) 2026 Jussi Lind <jussi.lind@iki.fi> |
| 3 | +// |
| 4 | +// Noteahead is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// Noteahead is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU General Public License |
| 14 | +// along with Noteahead. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +#include "device_rack_controller_test.hpp" |
| 17 | + |
| 18 | +#include "../../application/service/device_rack_controller.hpp" |
| 19 | +#include "../../application/service/device_service.hpp" |
| 20 | +#include "../../application/service/editor_service.hpp" |
| 21 | +#include "../../application/service/sampler_controller.hpp" |
| 22 | +#include "../../application/service/synth_controller.hpp" |
| 23 | +#include "../../common/constants.hpp" |
| 24 | + |
| 25 | +#include <QSignalSpy> |
| 26 | +#include <QTest> |
| 27 | + |
| 28 | +namespace noteahead { |
| 29 | + |
| 30 | +class MockDeviceService : public DeviceService |
| 31 | +{ |
| 32 | +public: |
| 33 | + MockDeviceService() : DeviceService(nullptr) {} |
| 34 | + QStringList internalDeviceNamesQt() const override { return m_names; } |
| 35 | + void setMockNames(const QStringList & names) { m_names = names; } |
| 36 | +private: |
| 37 | + QStringList m_names; |
| 38 | +}; |
| 39 | + |
| 40 | +class MockEditorService : public EditorService |
| 41 | +{ |
| 42 | +public: |
| 43 | + std::vector<quint64> trackIndices() const override { return m_indices; } |
| 44 | + void setMockIndices(const std::vector<quint64> & indices) { m_indices = indices; } |
| 45 | + |
| 46 | + QString trackName(quint64 trackIndex) const override { return m_names.at(trackIndex); } |
| 47 | + void setMockTrackName(quint64 trackIndex, const QString & name) { m_names[trackIndex] = name; } |
| 48 | + |
| 49 | + QString instrumentPortName(quint64 trackIndex) const override { return m_ports.at(trackIndex); } |
| 50 | + void setMockInstrumentPortName(quint64 trackIndex, const QString & port) { m_ports[trackIndex] = port; } |
| 51 | + |
| 52 | +private: |
| 53 | + std::vector<quint64> m_indices; |
| 54 | + std::map<quint64, QString> m_names; |
| 55 | + std::map<quint64, QString> m_ports; |
| 56 | +}; |
| 57 | + |
| 58 | +void DeviceRackControllerTest::test_devices() |
| 59 | +{ |
| 60 | + const auto deviceService = std::make_shared<MockDeviceService>(); |
| 61 | + const auto names = QStringList { "Sampler 1", "Synth 1" }; |
| 62 | + deviceService->setMockNames(names); |
| 63 | + |
| 64 | + DeviceRackController controller(deviceService, nullptr, nullptr, nullptr); |
| 65 | + QCOMPARE(controller.rowCount(), 2); |
| 66 | + QCOMPARE(controller.data(controller.index(0), static_cast<int>(DeviceRackController::DataRole::Name)).toString(), names.at(0)); |
| 67 | + QCOMPARE(controller.data(controller.index(1), static_cast<int>(DeviceRackController::DataRole::Name)).toString(), names.at(1)); |
| 68 | +} |
| 69 | + |
| 70 | +void DeviceRackControllerTest::test_trackNames() |
| 71 | +{ |
| 72 | + const auto deviceService = std::make_shared<MockDeviceService>(); |
| 73 | + deviceService->setMockNames({ "Sampler 1", "Synth 1" }); |
| 74 | + |
| 75 | + const auto editorService = std::make_shared<MockEditorService>(); |
| 76 | + editorService->setMockIndices({ 0, 1, 2, 3 }); |
| 77 | + editorService->setMockTrackName(0, "Track 1"); |
| 78 | + editorService->setMockInstrumentPortName(0, "Sampler 1"); |
| 79 | + editorService->setMockTrackName(1, "Track 2"); |
| 80 | + editorService->setMockInstrumentPortName(1, "Synth 1"); |
| 81 | + editorService->setMockTrackName(2, "Track 3"); |
| 82 | + editorService->setMockInstrumentPortName(2, "Sampler 1"); |
| 83 | + editorService->setMockTrackName(3, "Track 4"); |
| 84 | + editorService->setMockInstrumentPortName(3, "Synth 1"); |
| 85 | + |
| 86 | + DeviceRackController controller(deviceService, nullptr, nullptr, editorService); |
| 87 | + |
| 88 | + QCOMPARE(controller.data(controller.index(0), static_cast<int>(DeviceRackController::DataRole::TrackNames)).toString(), QString("Track 1, Track 3")); |
| 89 | + QCOMPARE(controller.data(controller.index(1), static_cast<int>(DeviceRackController::DataRole::TrackNames)).toString(), QString("Track 2, Track 4")); |
| 90 | +} |
| 91 | + |
| 92 | +void DeviceRackControllerTest::test_openDevice() |
| 93 | +{ |
| 94 | + // This test would require more complex mocking of DeviceService to return real Device objects |
| 95 | + // or further mocking of Sampler/Synth controllers. |
| 96 | + // For now, let's focus on the requested trackNames functionality. |
| 97 | +} |
| 98 | + |
| 99 | +} // namespace noteahead |
| 100 | + |
| 101 | +QTEST_GUILESS_MAIN(noteahead::DeviceRackControllerTest) |
0 commit comments