Changeset View
Changeset View
Standalone View
Standalone View
autotests/taglibwritertest.cpp
Show All 9 Lines | |||||
10 | #include <QTest> | 10 | #include <QTest> | ||
11 | #include <QDir> | 11 | #include <QDir> | ||
12 | #include <QFile> | 12 | #include <QFile> | ||
13 | 13 | | |||
14 | #define TEST_FILENAME "writertest.opus" | 14 | #define TEST_FILENAME "writertest.opus" | ||
15 | 15 | | |||
16 | using namespace KFileMetaData; | 16 | using namespace KFileMetaData; | ||
17 | 17 | | |||
18 | static QString t2q(const TagLib::String& t) | 18 | static QString t2q(const TagLib::String& t) | ||
bruns: Side note - bad implementation, see D13700
Also see inverse q2t in taglibwritertest.cpp | |||||
I have that on my todo list to switch to taglib's builtin functions astippich: I have that on my todo list to switch to taglib's builtin functions | |||||
19 | { | 19 | { | ||
20 | return QString::fromWCharArray((const wchar_t*)t.toCWString(), t.length()); | 20 | return QString::fromWCharArray((const wchar_t*)t.toCWString(), t.length()); | ||
21 | } | 21 | } | ||
22 | 22 | | |||
23 | QString TagLibWriterTest::testFilePath(const QString& fileName) const | 23 | QString TagLibWriterTest::testFilePath(const QString& fileName) const | ||
24 | { | 24 | { | ||
25 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; | 25 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; | ||
26 | } | 26 | } | ||
27 | 27 | | |||
28 | void TagLibWriterTest::initTestCase() | 28 | void TagLibWriterTest::initTestCase() | ||
29 | { | 29 | { | ||
30 | QFile testFile(testFilePath("test.opus")); | 30 | QFile testFile(testFilePath("test.opus")); | ||
31 | QFile writerTestFile(testFilePath(TEST_FILENAME)); | 31 | QFile writerTestFile(testFilePath(TEST_FILENAME)); | ||
32 | QFile::copy(testFilePath("test.opus"), testFilePath(TEST_FILENAME)); | 32 | QFile::copy(testFilePath("test.opus"), testFilePath(TEST_FILENAME)); | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | void TagLibWriterTest::test() | 35 | void TagLibWriterTest::test() | ||
36 | { | 36 | { | ||
37 | TagLibWriter writerPlugin{this}; | 37 | TagLibWriter writerPlugin{this}; | ||
38 | 38 | | |||
39 | WriteData data(testFilePath(TEST_FILENAME), "audio/opus"); | 39 | WriteData data(testFilePath(TEST_FILENAME), "audio/opus"); | ||
40 | data.add(Property::Title, "Title1"); | 40 | data.add(Property::Title, "Title1"); | ||
41 | data.add(Property::Artist, "Artist1"); | 41 | data.add(Property::Artist, "Artist1"); | ||
42 | data.add(Property::Album, "Album1"); | ||||
43 | data.add(Property::TrackNumber, 10); | ||||
44 | data.add(Property::ReleaseYear, 1999); | ||||
45 | data.add(Property::Genre, "Genre1"); | ||||
46 | data.add(Property::Comment, "Comment1"); | ||||
42 | writerPlugin.write(data); | 47 | writerPlugin.write(data); | ||
43 | 48 | | |||
44 | TagLib::FileRef file(testFilePath(TEST_FILENAME).toUtf8().constData(), true); | 49 | TagLib::FileRef file(testFilePath(TEST_FILENAME).toUtf8().constData(), true); | ||
45 | TagLib::Tag* tags = file.tag(); | 50 | TagLib::Tag* tags = file.tag(); | ||
46 | 51 | | |||
47 | QString extractedTitle = t2q(tags->title()); | 52 | QString extractedTitle = t2q(tags->title()); | ||
48 | QString extractedArtist = t2q(tags->artist()); | 53 | QString extractedArtist = t2q(tags->artist()); | ||
54 | QString extractedAlbum = t2q(tags->album()); | ||||
55 | uint extractedTrackNumber = tags->track(); | ||||
56 | uint extractedYear = tags->year(); | ||||
57 | QString extractedGenre = t2q(tags->genre()); | ||||
58 | QString extractedComment = t2q(tags->comment()); | ||||
49 | 59 | | |||
50 | QCOMPARE(extractedTitle, QStringLiteral("Title1")); | 60 | QCOMPARE(extractedTitle, QStringLiteral("Title1")); | ||
51 | QCOMPARE(extractedArtist, QStringLiteral("Artist1")); | 61 | QCOMPARE(extractedArtist, QStringLiteral("Artist1")); | ||
62 | QCOMPARE(extractedAlbum, QStringLiteral("Album1")); | ||||
63 | QCOMPARE(extractedTrackNumber, 10u); | ||||
64 | QCOMPARE(extractedYear, 1999u); | ||||
65 | QCOMPARE(extractedGenre, QStringLiteral("Genre1")); | ||||
66 | QCOMPARE(extractedComment, QStringLiteral("Comment1")); | ||||
52 | } | 67 | } | ||
53 | 68 | | |||
54 | void TagLibWriterTest::cleanupTestCase() | 69 | void TagLibWriterTest::cleanupTestCase() | ||
55 | { | 70 | { | ||
56 | QFile::remove(testFilePath(TEST_FILENAME)); | 71 | QFile::remove(testFilePath(TEST_FILENAME)); | ||
57 | } | 72 | } | ||
58 | 73 | | |||
59 | QTEST_GUILESS_MAIN(TagLibWriterTest) | 74 | QTEST_GUILESS_MAIN(TagLibWriterTest) |
Side note - bad implementation, see D13700
Also see inverse q2t in taglibwritertest.cpp