Debian Codegraph @

tests/test_s3m.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2011 by Mathias Panzenböck
3 email : [email protected]
4 ***************************************************************************/
5
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
25
26 #include <cassert>
27 #include "s3mfile.h"
28 #include <cppunit/extensions/HelperMacros.h>
29 #include "utils.h"
30
31 using namespace std;
32 using namespace TagLib;
33
34 static const String titleBefore("test song name");
35 static const String titleAfter("changed title");
36
37 static const String commentBefore(
38 "This is an instrument name.\n"
39 "Module file formats\n"
40 "abuse instrument names\n"
41 "as multiline comments.\n"
42 " ");
43
44 static const String newComment(
45 "This is an instrument name!\n"
46 "Module file formats\n"
47 "abuse instrument names\n"
48 "as multiline comments.\n"
49 "-----------------------------------\n"
50 "This line will be dropped and the previous is truncated.");
51
52 static const String commentAfter(
53 "This is an instrument name!\n"
54 "Module file formats\n"
55 "abuse instrument names\n"
56 "as multiline comments.\n"
57 "---------------------------");
58
59 class TestS3M : public CppUnit::TestFixture
60 {
61 CPPUNIT_TEST_SUITE(TestS3M);
62 CPPUNIT_TEST(testReadTags);
63 CPPUNIT_TEST(testWriteTags);
64 CPPUNIT_TEST_SUITE_END();
65
66 public:
67 void testReadTags()
68 {
69 testRead(TEST_FILE_PATH_C("test.s3m"), titleBefore, commentBefore);
70 }
71
72 void testWriteTags()
73 {
74 ScopedFileCopy copy("test", ".s3m");
75 {
76 S3M::File file(copy.fileName().c_str());
77 CPPUNIT_ASSERT(file.tag() != nullptr);
78 file.tag()->setTitle(titleAfter);
79 file.tag()->setComment(newComment);
80 file.tag()->setTrackerName("won't be saved");
81 CPPUNIT_ASSERT(file.save());
82 }
83 testRead(copy.fileName().c_str(), titleAfter, commentAfter);
84 CPPUNIT_ASSERT(fileEqual(
85 copy.fileName(),
86 testFilePath("changed.s3m")));
87 }
88
89 private:
90 void testRead(FileName fileName, const String &title, const String &comment)
91 {
92 S3M::File file(fileName);
93
94 CPPUNIT_ASSERT(file.isValid());
95
96 S3M::Properties *p = file.audioProperties();
97 Mod::Tag *t = file.tag();
98
99 CPPUNIT_ASSERT(nullptr != p);
100 CPPUNIT_ASSERT(nullptr != t);
101 assert(p != nullptr); // to silence the clang analyzer
102
103 CPPUNIT_ASSERT_EQUAL( 0, p->lengthInSeconds());
104 CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
105 CPPUNIT_ASSERT_EQUAL( 0, p->sampleRate());
106 CPPUNIT_ASSERT_EQUAL(16, p->channels());
107 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->lengthInPatterns());
108 CPPUNIT_ASSERT_EQUAL(false, p->stereo());
109 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5), p->sampleCount());
110 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->patternCount());
111 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->flags());
112 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(4896), p->trackerVersion());
113 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), p->fileFormatVersion());
114 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(64), p->globalVolume());
115 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(48), p->masterVolume());
116 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(125), p->tempo());
117 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(6), p->bpmSpeed());
118 CPPUNIT_ASSERT_EQUAL(title, t->title());
119 CPPUNIT_ASSERT_EQUAL(String(), t->artist());
120 CPPUNIT_ASSERT_EQUAL(String(), t->album());
121 CPPUNIT_ASSERT_EQUAL(comment, t->comment());
122 CPPUNIT_ASSERT_EQUAL(String(), t->genre());
123 CPPUNIT_ASSERT_EQUAL(0U, t->year());
124 CPPUNIT_ASSERT_EQUAL(0U, t->track());
125 CPPUNIT_ASSERT_EQUAL(String("ScreamTracker III"), t->trackerName());
126 }
127 };
128
129 CPPUNIT_TEST_SUITE_REGISTRATION(TestS3M);