File: SynthesizerTest.cpp

package info (click to toggle)
sfxr-qt 1.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,988 kB
  • sloc: cpp: 48,737; python: 1,885; sh: 385; makefile: 4
file content (70 lines) | stat: -rw-r--r-- 1,991 bytes parent folder | download
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
#include "Sound.h"
#include "Synthesizer.h"
#include "TestConfig.h"
#include "TestUtils.h"
#include "WavSaver.h"
#include "WaveForm.h"

#include <QDebug>
#include <QDir>
#include <QTemporaryDir>

#include <catch2/catch_test_macros.hpp>

static constexpr char FIXTURES_DIR[] = TEST_FIXTURES_DIR "/synthesizer";

static QStringList listTestNames() {
    QStringList lst;
    auto inputDir = QString("%1/input").arg(FIXTURES_DIR);
    for (const auto& info : QDir(inputDir).entryInfoList({"*.sfxj"})) {
        lst << info.baseName();
    }
    return lst;
}

namespace SynthesizerTest {

void updateExpectedFiles() {
    WaveForm::registerType();
    WavSaver wavSaver;

    for (const auto& name : listTestNames()) {
        auto soundPath = QString("%1/input/%2.sfxj").arg(FIXTURES_DIR, name);
        auto expectedPath = QString("%1/expected/%2.wav").arg(FIXTURES_DIR, name);

        qInfo() << "Updating" << expectedPath;
        Sound sound;
        sound.load(QUrl::fromLocalFile(soundPath));
        wavSaver.save(&sound, QUrl::fromLocalFile(expectedPath));
    }
}

} // namespace SynthesizerTest

TEST_CASE("Synthesizer") {
    WaveForm::registerType();
    QTemporaryDir tempDir;
    WavSaver wavSaver;

    for (const auto& name : listTestNames()) {
        SECTION(name.toUtf8().data()) {
            auto soundPath = QString("%1/input/%2.sfxj").arg(FIXTURES_DIR, name);
            auto expectedPath = QString("%1/expected/%2.wav").arg(FIXTURES_DIR, name);
            auto resultPath = tempDir.filePath(name + ".wav");

            Sound sound;
            sound.load(QUrl::fromLocalFile(soundPath));

            // We test Synthesizer through WavSaver
            wavSaver.save(&sound, QUrl::fromLocalFile(resultPath));

            QByteArray expected = loadFile(expectedPath);
            REQUIRE(!expected.isEmpty());

            QByteArray result = loadFile(resultPath);
            REQUIRE(!result.isEmpty());

            REQUIRE(result == expected);
        }
    }
}