Debian Codegraph @

tests/test_speex.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2015 by Tsuda Kageyu
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 "speexfile.h"
27 #include "oggpageheader.h"
28 #include <cppunit/extensions/HelperMacros.h>
29 #include "utils.h"
30
31 using namespace std;
32 using namespace TagLib;
33
34 class TestSpeex : public CppUnit::TestFixture
35 {
36 CPPUNIT_TEST_SUITE(TestSpeex);
37 CPPUNIT_TEST(testAudioProperties);
38 CPPUNIT_TEST(testSplitPackets);
39 CPPUNIT_TEST_SUITE_END();
40
41 public:
42
43 void testAudioProperties()
44 {
45 Ogg::Speex::File f(TEST_FILE_PATH_C("empty.spx"));
46 CPPUNIT_ASSERT(f.audioProperties());
47 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
48 CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
49 CPPUNIT_ASSERT_EQUAL(53, f.audioProperties()->bitrate());
50 CPPUNIT_ASSERT_EQUAL(-1, f.audioProperties()->bitrateNominal());
51 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
52 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
53 }
54
55 void testSplitPackets()
56 {
57 ScopedFileCopy copy("empty", ".spx");
58 string newname = copy.fileName();
59
60 const String text = longText(128 * 1024, true);
61
62 {
63 Ogg::Speex::File f(newname.c_str());
64 f.tag()->setTitle(text);
65 f.save();
66 }
67 {
68 Ogg::Speex::File f(newname.c_str());
69 CPPUNIT_ASSERT(f.isValid());
70 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(156330), f.length());
71 CPPUNIT_ASSERT_EQUAL(23, f.lastPageHeader()->pageSequenceNumber());
72 CPPUNIT_ASSERT_EQUAL(80U, f.packet(0).size());
73 CPPUNIT_ASSERT_EQUAL(131116U, f.packet(1).size());
74 CPPUNIT_ASSERT_EQUAL(93U, f.packet(2).size());
75 CPPUNIT_ASSERT_EQUAL(93U, f.packet(3).size());
76 CPPUNIT_ASSERT_EQUAL(text, f.tag()->title());
77
78 CPPUNIT_ASSERT(f.audioProperties());
79 CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
80
81 f.tag()->setTitle("ABCDE");
82 f.save();
83 }
84 {
85 Ogg::Speex::File f(newname.c_str());
86 CPPUNIT_ASSERT(f.isValid());
87 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(24317), f.length());
88 CPPUNIT_ASSERT_EQUAL(7, f.lastPageHeader()->pageSequenceNumber());
89 CPPUNIT_ASSERT_EQUAL(80U, f.packet(0).size());
90 CPPUNIT_ASSERT_EQUAL(49U, f.packet(1).size());
91 CPPUNIT_ASSERT_EQUAL(93U, f.packet(2).size());
92 CPPUNIT_ASSERT_EQUAL(93U, f.packet(3).size());
93 CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
94
95 CPPUNIT_ASSERT(f.audioProperties());
96 CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
97 }
98 }
99
100 };
101
102 CPPUNIT_TEST_SUITE_REGISTRATION(TestSpeex);