Debian Codegraph @

tests/test_oggflac.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2009 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 "tstringlist.h"
30 #include "tag.h"
31 #include "oggfile.h"
32 #include "oggflacfile.h"
33 #include "oggpageheader.h"
34 #include <cppunit/extensions/HelperMacros.h>
35 #include "utils.h"
36
37 using namespace std;
38 using namespace TagLib;
39
40 class TestOggFLAC : public CppUnit::TestFixture
41 {
42 CPPUNIT_TEST_SUITE(TestOggFLAC);
43 CPPUNIT_TEST(testFramingBit);
44 CPPUNIT_TEST(testFuzzedFile);
45 CPPUNIT_TEST(testSplitPackets);
46 CPPUNIT_TEST_SUITE_END();
47
48 public:
49
50 void testFramingBit()
51 {
52 ScopedFileCopy copy("empty_flac", ".oga");
53 string newname = copy.fileName();
54
55 {
56 Ogg::FLAC::File f(newname.c_str());
57 f.tag()->setArtist("The Artist");
58 f.save();
59 }
60 {
61 Ogg::FLAC::File f(newname.c_str());
62 CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
63
64 f.seek(0, File::End);
65 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(9134), f.tell());
66 }
67 }
68
69 void testFuzzedFile()
70 {
71 Ogg::FLAC::File f(TEST_FILE_PATH_C("segfault.oga"));
72 CPPUNIT_ASSERT(!f.isValid());
73 }
74
75 void testSplitPackets()
76 {
77 ScopedFileCopy copy("empty_flac", ".oga");
78 string newname = copy.fileName();
79
80 const String text = longText(128 * 1024, true);
81
82 {
83 Ogg::FLAC::File f(newname.c_str());
84 f.tag()->setTitle(text);
85 f.save();
86 }
87 {
88 Ogg::FLAC::File f(newname.c_str());
89 CPPUNIT_ASSERT(f.isValid());
90 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(141141), f.length());
91 CPPUNIT_ASSERT_EQUAL(21, f.lastPageHeader()->pageSequenceNumber());
92 CPPUNIT_ASSERT_EQUAL(51U, f.packet(0).size());
93 CPPUNIT_ASSERT_EQUAL(131126U, f.packet(1).size());
94 CPPUNIT_ASSERT_EQUAL(22U, f.packet(2).size());
95 CPPUNIT_ASSERT_EQUAL(8196U, f.packet(3).size());
96 CPPUNIT_ASSERT_EQUAL(text, f.tag()->title());
97
98 CPPUNIT_ASSERT(f.audioProperties());
99 CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
100
101 f.tag()->setTitle("ABCDE");
102 f.save();
103 }
104 {
105 Ogg::FLAC::File f(newname.c_str());
106 CPPUNIT_ASSERT(f.isValid());
107 CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(9128), f.length());
108 CPPUNIT_ASSERT_EQUAL(5, f.lastPageHeader()->pageSequenceNumber());
109 CPPUNIT_ASSERT_EQUAL(51U, f.packet(0).size());
110 CPPUNIT_ASSERT_EQUAL(59U, f.packet(1).size());
111 CPPUNIT_ASSERT_EQUAL(22U, f.packet(2).size());
112 CPPUNIT_ASSERT_EQUAL(8196U, f.packet(3).size());
113 CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title());
114
115 CPPUNIT_ASSERT(f.audioProperties());
116 CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
117 }
118 }
119
120 };
121
122 CPPUNIT_TEST_SUITE_REGISTRATION(TestOggFLAC);