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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#include <gtest/gtest.h>
#include "track/replaygain.h"
#include <QtDebug>
namespace {
class ReplayGainTest : public testing::Test {
protected:
double ratioFromString(QString inputValue, bool expectedResult, double expectedValue) {
//qDebug() << "ratioFromString" << inputValue << expectedResult << expectedValue;
bool actualResult;
const double actualValue = mixxx::ReplayGain::ratioFromString(inputValue, &actualResult);
EXPECT_EQ(expectedResult, actualResult);
EXPECT_FLOAT_EQ(expectedValue, actualValue);
return actualResult;
}
void normalizeRatio(double expectedResult) {
const double actualResult = mixxx::ReplayGain::normalizeRatio(expectedResult);
if (mixxx::ReplayGain::isValidRatio(expectedResult)) {
EXPECT_EQ(expectedResult, actualResult);
} else {
EXPECT_EQ(mixxx::ReplayGain::kRatioUndefined, actualResult);
}
}
CSAMPLE peakFromString(QString inputValue, bool expectedResult, CSAMPLE expectedValue) {
//qDebug() << "peakFromString" << inputValue << expectedResult << expectedValue;
bool actualResult;
const CSAMPLE actualValue = mixxx::ReplayGain::peakFromString(inputValue, &actualResult);
EXPECT_EQ(expectedResult, actualResult);
EXPECT_FLOAT_EQ(expectedValue, actualValue);
return actualResult;
}
void normalizePeak(CSAMPLE expectedResult) {
const CSAMPLE actualResult = mixxx::ReplayGain::normalizePeak(expectedResult);
if (mixxx::ReplayGain::isValidPeak(expectedResult)) {
EXPECT_EQ(expectedResult, actualResult);
} else {
EXPECT_EQ(mixxx::ReplayGain::kPeakUndefined, actualResult);
}
}
};
TEST_F(ReplayGainTest, RatioFromString0dB) {
ratioFromString("0 dB", true, mixxx::ReplayGain::kRatio0dB);
ratioFromString("0.0dB", true, mixxx::ReplayGain::kRatio0dB);
ratioFromString("0 DB", true, mixxx::ReplayGain::kRatio0dB);
ratioFromString("-0 Db", true, mixxx::ReplayGain::kRatio0dB);
ratioFromString("+0db", true, mixxx::ReplayGain::kRatio0dB);
}
TEST_F(ReplayGainTest, RatioFromStringValidRange) {
for (int replayGainDb = -100; 100 >= replayGainDb; ++replayGainDb) {
const QString inputValues[] = {
QString("%1 ").arg(replayGainDb),
QString(" %1dB ").arg(replayGainDb),
QString(" %1 DB ").arg(replayGainDb),
QString(" %1db ").arg(replayGainDb)
};
float expectedValue;
expectedValue = db2ratio(double(replayGainDb));
for (size_t i = 0; i < sizeof(inputValues) / sizeof(inputValues[0]); ++i) {
ratioFromString(inputValues[i], true, expectedValue);
if (0 <= replayGainDb) {
ratioFromString(QString(" + ") + inputValues[i], true, expectedValue);
}
}
}
}
TEST_F(ReplayGainTest, RatioFromStringInvalid) {
ratioFromString("", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("abcde", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("0 dBA", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("--2 dB", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("+-2 dB", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("-+2 dB", false, mixxx::ReplayGain::kRatioUndefined);
ratioFromString("++2 dB", false, mixxx::ReplayGain::kRatioUndefined);
}
TEST_F(ReplayGainTest, NormalizeRatio) {
normalizeRatio(mixxx::ReplayGain::kRatioUndefined);
normalizeRatio(mixxx::ReplayGain::kRatioMin);
normalizeRatio(-mixxx::ReplayGain::kRatioMin);
normalizeRatio(mixxx::ReplayGain::kRatio0dB);
normalizeRatio(-mixxx::ReplayGain::kRatio0dB);
}
TEST_F(ReplayGainTest, PeakFromStringValid) {
peakFromString("0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("+0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("-0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("0.0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("+0.0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("-0.0", true, mixxx::ReplayGain::kPeakMin);
peakFromString("1", true, mixxx::ReplayGain::kPeakClip);
peakFromString("+1", true, mixxx::ReplayGain::kPeakClip);
peakFromString("1.0", true, mixxx::ReplayGain::kPeakClip);
peakFromString("+1.0", true, mixxx::ReplayGain::kPeakClip);
peakFromString(" 0.12345 ", true, 0.12345);
peakFromString(" 1.2345", true, 1.2345);
}
TEST_F(ReplayGainTest, PeakFromStringInvalid) {
peakFromString("", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("-1", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("-0.12345", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("--1.0", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("+-1.0", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("-+1.0", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("++1.0", false, mixxx::ReplayGain::kPeakUndefined);
peakFromString("+abcde", false, mixxx::ReplayGain::kPeakUndefined);
}
TEST_F(ReplayGainTest, NormalizePeak) {
normalizePeak(mixxx::ReplayGain::kPeakUndefined);
normalizePeak(mixxx::ReplayGain::kPeakMin);
normalizePeak(-mixxx::ReplayGain::kPeakMin);
normalizePeak(mixxx::ReplayGain::kPeakClip);
normalizePeak(-mixxx::ReplayGain::kPeakClip);
normalizePeak(mixxx::ReplayGain::kPeakClip + mixxx::ReplayGain::kPeakClip);
}
} // anonymous namespace
|