-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for SeratoMarkers2 feature
- Loading branch information
Showing
1 changed file
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "track/seratomarkers2.h" | ||
#include "util/memory.h" | ||
|
||
#include <taglib/tstring.h> | ||
#include <taglib/textidentificationframe.h> | ||
#include <QtDebug> | ||
|
||
namespace { | ||
|
||
class SeratoMarkers2Test : public testing::Test { | ||
protected: | ||
void parseBpmlockEntry(const QByteArray inputValue, bool valid, bool locked) { | ||
const mixxx::SeratoMarkers2EntryPointer parsedEntry = mixxx::SeratoMarkers2BpmlockEntry::parse(inputValue); | ||
if (!parsedEntry) { | ||
EXPECT_FALSE(valid); | ||
return; | ||
} | ||
EXPECT_TRUE(valid); | ||
const mixxx::SeratoMarkers2BpmlockEntry *bpmlockEntry = static_cast<mixxx::SeratoMarkers2BpmlockEntry*>(parsedEntry.get()); | ||
|
||
EXPECT_EQ(locked, bpmlockEntry->isLocked()); | ||
|
||
EXPECT_EQ(inputValue, bpmlockEntry->data()); | ||
} | ||
|
||
void parseColorEntry(const QByteArray inputValue, bool valid, QColor color) { | ||
const mixxx::SeratoMarkers2EntryPointer parsedEntry = mixxx::SeratoMarkers2ColorEntry::parse(inputValue); | ||
if (!parsedEntry) { | ||
EXPECT_FALSE(valid); | ||
return; | ||
} | ||
EXPECT_TRUE(valid); | ||
const mixxx::SeratoMarkers2ColorEntry *colorEntry = static_cast<mixxx::SeratoMarkers2ColorEntry*>(parsedEntry.get()); | ||
|
||
EXPECT_EQ(color, colorEntry->getColor()); | ||
|
||
EXPECT_EQ(inputValue, colorEntry->data()); | ||
} | ||
|
||
void parseCueEntry(const QByteArray inputValue, bool valid, quint8 index, quint32 position, QColor color, QString label) { | ||
const mixxx::SeratoMarkers2EntryPointer parsedEntry = mixxx::SeratoMarkers2CueEntry::parse(inputValue); | ||
if (!parsedEntry) { | ||
EXPECT_FALSE(valid); | ||
return; | ||
} | ||
EXPECT_TRUE(valid); | ||
const mixxx::SeratoMarkers2CueEntry *cueEntry = static_cast<mixxx::SeratoMarkers2CueEntry*>(parsedEntry.get()); | ||
|
||
EXPECT_EQ(index, cueEntry->getIndex()); | ||
EXPECT_EQ(position, cueEntry->getPosition()); | ||
EXPECT_EQ(color, cueEntry->getColor()); | ||
EXPECT_EQ(label, cueEntry->getLabel()); | ||
|
||
EXPECT_EQ(inputValue, cueEntry->data()); | ||
} | ||
|
||
void parseLoopEntry(const QByteArray inputValue, bool valid, quint8 index, quint32 startposition, quint32 endposition, bool locked, QString label) { | ||
const mixxx::SeratoMarkers2EntryPointer parsedEntry = mixxx::SeratoMarkers2LoopEntry::parse(inputValue); | ||
if (!parsedEntry) { | ||
EXPECT_FALSE(valid); | ||
return; | ||
} | ||
EXPECT_TRUE(valid); | ||
const mixxx::SeratoMarkers2LoopEntry *loopEntry = static_cast<mixxx::SeratoMarkers2LoopEntry*>(parsedEntry.get()); | ||
|
||
EXPECT_EQ(index, loopEntry->getIndex()); | ||
EXPECT_EQ(startposition, loopEntry->getStartPosition()); | ||
EXPECT_EQ(endposition, loopEntry->getEndPosition()); | ||
EXPECT_EQ(locked, loopEntry->isLocked()); | ||
EXPECT_EQ(label, loopEntry->getLabel()); | ||
|
||
EXPECT_EQ(inputValue, loopEntry->data()); | ||
} | ||
}; | ||
|
||
TEST_F(SeratoMarkers2Test, ParseBpmlockEntry) { | ||
parseBpmlockEntry(QByteArray("\x00", 1), true, false); | ||
parseBpmlockEntry(QByteArray("\x01", 1), true, true); | ||
parseBpmlockEntry(QByteArray("\x00\x00", 2), false, false); // Invalid size | ||
} | ||
|
||
TEST_F(SeratoMarkers2Test, ParseColorEntry) { | ||
parseColorEntry(QByteArray("\x00\xcc\x00\x00", 4), true, QColor(0xcc, 0, 0)); | ||
parseColorEntry(QByteArray("\x00\x00\xcc\x00", 4), true, QColor(0, 0xcc, 0)); | ||
parseColorEntry(QByteArray("\x00\x00\x00\xcc", 4), true, QColor(0, 0, 0xcc)); | ||
parseColorEntry(QByteArray("\x00\x89\xab\xcd", 4), true, QColor(0x89, 0xab, 0xcd)); | ||
|
||
// Invalid value | ||
parseColorEntry(QByteArray("\x01\xff\x00\x00", 1), false, QColor()); | ||
|
||
// Invalid size | ||
parseColorEntry(QByteArray("\x00", 1), false, QColor()); | ||
parseColorEntry(QByteArray("\x00\xff\x00\x00\x00", 5), false, QColor()); | ||
} | ||
|
||
TEST_F(SeratoMarkers2Test, ParseCueEntry) { | ||
parseCueEntry( | ||
QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 13), | ||
true, | ||
0, 0, QColor(0, 0, 0), QString("")); | ||
parseCueEntry( | ||
QByteArray("\x00\x01\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x00Test\x00", 17), | ||
true, | ||
1, 4096, QColor(0xcc, 0, 0), QString("Test")); | ||
parseCueEntry( | ||
QByteArray("\x00\x02\x00\x00\x00\xff\x00\x00\xcc\x00\x00\x00\xc3\xa4\xc3\xbc\xc3\xb6\xc3\x9f\xc3\xa9\xc3\xa8!\x00", 26), | ||
true, | ||
2, 255, QColor(0, 0xcc, 0), QString("äüößéè!")); | ||
parseCueEntry( | ||
QByteArray("\x00\x03\x02\x03\x04\x05\x00\x06\x07\x08\x00\x00Hello World\x00", 24), | ||
true, | ||
3, 33752069, QColor(0x06, 0x07, 0x08), QString("Hello World")); | ||
|
||
// Invalid value | ||
parseCueEntry( | ||
QByteArray("\x01\x04\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x00Test\x00", 17), | ||
false, | ||
0, 0, QColor(), QString()); | ||
parseCueEntry( | ||
QByteArray("\x00\x05\x00\x00\x10\x00\x01\xcc\x00\x00\x00\x00Test\x00", 17), | ||
false, | ||
0, 0, QColor(), QString()); | ||
parseCueEntry( | ||
QByteArray("\x00\x06\x00\x00\x10\x00\x00\xcc\x00\x00\x01\x00Test\x00", 17), | ||
false, | ||
0, 0, QColor(), QString()); | ||
parseCueEntry( | ||
QByteArray("\x00\x07\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x01Test\x00", 17), | ||
false, | ||
0, 0, QColor(), QString()); | ||
|
||
// Missing null terminator | ||
parseCueEntry( | ||
QByteArray("\x00\x08\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x00Test", 16), | ||
false, | ||
0, 0, QColor(), QString()); | ||
|
||
//Invalid size | ||
parseCueEntry( | ||
QByteArray("\x00\x09\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x00", 12), | ||
false, | ||
0, 0, QColor(), QString()); | ||
parseCueEntry( | ||
QByteArray("\x00\x0a\x00\x00\x10\x00\x00\xcc\x00\x00\x00\x00\x00\x00", 14), | ||
false, | ||
0, 0, QColor(), QString()); | ||
} | ||
|
||
TEST_F(SeratoMarkers2Test, ParseLoopEntry) { | ||
parseLoopEntry( | ||
QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00\x00", 21), | ||
true, | ||
0, 0, 0, false, QString("")); | ||
parseLoopEntry( | ||
QByteArray("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x01Test\x00", 25), | ||
true, | ||
1, 33752069, 101124105, true, QString("Test")); | ||
parseLoopEntry( | ||
QByteArray("\x00\x02\x00\x00\x00\xff\x00\x00\x10\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00\xc3\xa4\xc3\xbc\xc3\xb6\xc3\x9f\xc3\xa9\xc3\xa8!\x00", 34), | ||
true, | ||
2, 255, 4096, false, QString("äüößéè!")); | ||
parseLoopEntry( | ||
QByteArray("\x00\x03\x00\x00\x00\x00\x00\x00\x01\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x01Hello World\x00", 32), | ||
true, | ||
3, 0, 256, true, QString("Hello World")); | ||
|
||
// Invalid value | ||
parseLoopEntry( | ||
QByteArray("\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\x00\x27\xaa\xe1\x00\x00\x00", 21), | ||
false, | ||
0, 0, 0, false, QString()); | ||
parseLoopEntry( | ||
QByteArray("\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x01\x27\xaa\xe1\x00\x00\x00\x00", 23), | ||
false, | ||
0, 0, 0, false, QString()); | ||
parseLoopEntry( | ||
QByteArray("\x01\x05\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00\x00\x00", 23), | ||
false, | ||
0, 0, 0, false, QString()); | ||
parseLoopEntry( | ||
QByteArray("\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x01\x00\x00\x00", 23), | ||
false, | ||
0, 0, 0, false, QString()); | ||
|
||
// Missing null terminator | ||
parseLoopEntry( | ||
QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00Test", 24), | ||
false, | ||
0, 0, 0, false, QString()); | ||
|
||
//Invalid size | ||
parseLoopEntry( | ||
QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00", 20), | ||
false, | ||
0, 0, 0, false, QString()); | ||
parseLoopEntry( | ||
QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x27\xaa\xe1\x00\x00\x00\x00", 22), | ||
false, | ||
0, 0, 0, false, QString()); | ||
} | ||
} // namespace |