Debian Codegraph @

tests/test_opus.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2012 by Lukas Lalinsky
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 <string>
27 #include <cstdio>
28
29 #include "tbytevectorlist.h"
30 #include "tag.h"
31 #include "opusfile.h"
32 #include "oggpageheader.h"
33 #include <cppunit/extensions/HelperMacros.h>
34 #include "utils.h"
35
36 using namespace std;
37 using namespace TagLib;
38
39 class TestOpus : public CppUnit::TestFixture
40 {
41 CPPUNIT_TEST_SUITE(TestOpus);
42 CPPUNIT_TEST(testAudioProperties);
43 CPPUNIT_TEST(testReadComments);
44 CPPUNIT_TEST(testWriteComments);
45 CPPUNIT_TEST(testSplitPackets);
46 CPPUNIT_TEST_SUITE_END();
47
48 public:
49
50 void testAudioProperties()
51 {
52 Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
53 CPPUNIT_ASSERT(f.audioProperties());
54 CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->lengthInSeconds());
55 CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
56 CPPUNIT_ASSERT_EQUAL(36, f.audioProperties()->bitrate());
57 CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
58 CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
59 CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->inputSampleRate());
60 CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->opusVersion());
61 CPPUNIT_ASSERT_EQUAL(-17920, f.audioProperties()->outputGain());
62 }
63
64 void testReadComments()
65 {
66 Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
67 CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f.tag()->fieldListMap()["ENCODER"]);
68 CPPUNIT_ASSERT(f.tag()->fieldListMap().contains("TESTDESCRIPTION"));
69 CPPUNIT_ASSERT(!f.tag()->fieldListMap().contains("ARTIST"));
70 CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f.tag()->vendorID());
71 }
72
73 void testWriteComments()
74 {
75 ScopedFileCopy copy("correctness_gain_silent_output", ".opus");
76 string filename = copy.fileName();
77
78 {
79 Ogg::Opus::File f(filename.c_str());
80 f.tag()->setArtist("Your Tester");
81 f.save();
82 }
83 {
84 Ogg::Opus::File f(filename.c_str());
85 CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f.tag()->fieldListMap()["ENCODER"]);
86 CPPUNIT_ASSERT(f.tag()->fieldListMap().contains("TESTDESCRIPTION"));
87 CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f.tag()->fieldListMap()["ARTIST"]);
88 CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f.tag()->vendorID());
89 }
90 }
91
92 void testSplitPackets()
93 {
94 ScopedFileCopy copy("correctness_gain_silent_output", ".opus");
95 string newname = copy.fileName();
96
97 const String text = longText(128 * 1024, true);
98
99 {
100 Ogg::Opus::File f(newname.c_str());
101 f.tag()->setTitle(text);
102 f.save();
103 }
104 {
105 Ogg::Opus::File f(newname.c_str());
106 CPPUNIT_ASSERT(f.isValid());
107 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(167534), f.length());
108 CPPUNIT_ASSERT_EQUAL(27, f.lastPageHeader()->pageSequenceNumber());
109 CPPUNIT_ASSERT_EQUAL(19U, f.packet(0).size());
110 CPPUNIT_ASSERT_EQUAL(131380U, f.packet(1).size());
111 CPPUNIT_ASSERT_EQUAL(5U, f.packet(2).size());
112 CPPUNIT_ASSERT_EQUAL(5U, f.packet(3).size());
113 CPPUNIT_ASSERT_EQUAL(text, f.tag()->title());
114
115 CPPUNIT_ASSERT(f.audioProperties());
116 CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
117
118 f.tag()->setTitle("ABCDE");
119 f.save();
120 }
121 {
122 Ogg::Opus::File f(newname.c_str());
123 CPPUNIT_ASSERT(f.isValid());
124 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(35521), f.length());
125 CPPUNIT_ASSERT_EQUAL(11, f.lastPageHeader()->pageSequenceNumber());
126 CPPUNIT_ASSERT_EQUAL(19U, f.packet(0).size());
127 CPPUNIT_ASSERT_EQUAL(313U, f.packet(1).size());
128 CPPUNIT_ASSERT_EQUAL(5U, f.packet(2).size());
129 CPPUNIT_ASSERT_EQUAL(5U, f.packet(3).size());
130 CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
131
132 CPPUNIT_ASSERT(f.audioProperties());
133 CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds());
134 }
135 }
136
137 };
138
139 CPPUNIT_TEST_SUITE_REGISTRATION(TestOpus);