diff --git a/.travis.yml b/.travis.yml index b526e274..c5ec8862 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ addons: packages: - libcppunit-dev - zlib1g-dev -script: cmake -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON . && make && make check +script: cmake -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_BINDINGS=ON . && make && make check diff --git a/CMakeLists.txt b/CMakeLists.txt index dd5d2e81..d98dc1ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,34 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") -option(ENABLE_STATIC "Make static version of libtag" OFF) +option(ENABLE_STATIC "Make static version of libtag" OFF) if(ENABLE_STATIC) add_definitions(-DTAGLIB_STATIC) set(BUILD_SHARED_LIBS OFF) else() set(BUILD_SHARED_LIBS ON) endif() -OPTION(ENABLE_STATIC_RUNTIME "Visual Studio, link with runtime statically" OFF) +option(ENABLE_STATIC_RUNTIME "Visual Studio, link with runtime statically" OFF) -option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) -if(VISIBILITY_HIDDEN) - add_definitions (-fvisibility=hidden) +option(ENABLE_CCACHE "Use ccache when building libtag" OFF) +if(ENABLE_CCACHE) + find_program(CCACHE_FOUND ccache) + if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + endif() endif() -option(BUILD_TESTS "Build the test suite" OFF) -option(BUILD_EXAMPLES "Build the examples" OFF) +option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) +if(VISIBILITY_HIDDEN) + add_definitions(-fvisibility=hidden) +endif() -option(NO_ITUNES_HACKS "Disable workarounds for iTunes bugs" OFF) +option(BUILD_TESTS "Build the test suite" OFF) +option(BUILD_EXAMPLES "Build the examples" OFF) +option(BUILD_BINDINGS "Build the bindings" ON) + +option(NO_ITUNES_HACKS "Disable workarounds for iTunes bugs" OFF) add_definitions(-DHAVE_CONFIG_H) set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/") @@ -46,6 +56,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() + if(MSVC AND ENABLE_STATIC_RUNTIME) foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") @@ -77,7 +88,7 @@ endif() # 1. If the library source code has changed at all since the last update, then increment revision. # 2. If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0. # 3. If any interfaces have been added since the last public release, then increment age. -# 4. If any interfaces have been removed since the last public release, then set age to 0. +# 4. If any interfaces have been removed since the last public release, then set age to 0. set(TAGLIB_SOVERSION_CURRENT 16) set(TAGLIB_SOVERSION_REVISION 1) set(TAGLIB_SOVERSION_AGE 15) @@ -116,25 +127,28 @@ if(TRACE_IN_RELEASE) set(TRACE_IN_RELEASE TRUE) endif() -add_subdirectory(taglib) -add_subdirectory(bindings) +add_subdirectory(taglib) + +if(BUILD_BINDINGS) + add_subdirectory(bindings) +endif() + if(BUILD_TESTS) enable_testing() add_subdirectory(tests) -endif(BUILD_TESTS) -add_subdirectory(examples) +endif() + +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") file(COPY doc/taglib.png DESTINATION doc) add_custom_target(docs doxygen) # uninstall target -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) if(NOT TARGET uninstall) - add_custom_target(uninstall - COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") + add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") endif() diff --git a/NEWS b/NEWS index baf214b2..86680008 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ * Fixed crash when calling File::properties() after strip(). * Fixed possible file corruptions when saving ASF files. * Fixed updating the comment field of Vorbis comments. + * Added BUILD_BINDINGS build option. + * Added ENABLE_CCACHE build option. * Marked ByteVector::null and ByteVector::isNull() deprecated. * Marked String::null and ByteVector::isNull() deprecated. * Marked XiphComment::removeField() deprecated. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7812d2e9..6a35ac82 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,58 +1,43 @@ -if(BUILD_EXAMPLES) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../taglib - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/toolkit - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ape - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v1 - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2 - ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mp4 - ${CMAKE_CURRENT_SOURCE_DIR}/../bindings/c/ ) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/toolkit + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ape + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v1 + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2 + ${CMAKE_CURRENT_SOURCE_DIR}/../bindings/c/ +) if(ENABLE_STATIC) - add_definitions(-DTAGLIB_STATIC) + add_definitions(-DTAGLIB_STATIC) endif(ENABLE_STATIC) ########### next target ############### -ADD_EXECUTABLE(tagreader tagreader.cpp) - -TARGET_LINK_LIBRARIES(tagreader tag ) - +add_executable(tagreader tagreader.cpp) +target_link_libraries(tagreader tag) ########### next target ############### -ADD_EXECUTABLE(tagreader_c tagreader_c.c) - -TARGET_LINK_LIBRARIES(tagreader_c tag_c ) - +add_executable(tagreader_c tagreader_c.c) +target_link_libraries(tagreader_c tag_c) ########### next target ############### -ADD_EXECUTABLE(tagwriter tagwriter.cpp) - -TARGET_LINK_LIBRARIES(tagwriter tag ) - +add_executable(tagwriter tagwriter.cpp) +target_link_libraries(tagwriter tag) ########### next target ############### -ADD_EXECUTABLE(framelist framelist.cpp) - -TARGET_LINK_LIBRARIES(framelist tag ) - +add_executable(framelist framelist.cpp) +target_link_libraries(framelist tag) ########### next target ############### -ADD_EXECUTABLE(strip-id3v1 strip-id3v1.cpp) - -TARGET_LINK_LIBRARIES(strip-id3v1 tag ) - +add_executable(strip-id3v1 strip-id3v1.cpp) +target_link_libraries(strip-id3v1 tag) ########### next target ############### -ADD_EXECUTABLE(inspect inspect.cpp) - -TARGET_LINK_LIBRARIES(inspect tag ) - - -endif(BUILD_EXAMPLES) - +add_executable(inspect inspect.cpp) +target_link_libraries(inspect tag) diff --git a/taglib/ape/apefile.cpp b/taglib/ape/apefile.cpp index 59510c12..4a54c0e8 100644 --- a/taglib/ape/apefile.cpp +++ b/taglib/ape/apefile.cpp @@ -273,7 +273,7 @@ void APE::File::read(bool readProperties) if(d->APELocation >= 0) { d->tag.set(ApeAPEIndex, new APE::Tag(this, d->APELocation)); d->APESize = APETag()->footer()->completeTagSize(); - d->APELocation = d->APELocation + APETag()->footer()->size() - d->APESize; + d->APELocation = d->APELocation + APE::Footer::size() - d->APESize; d->hasAPE = true; } diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 21e90be9..67bce9fa 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -195,9 +195,6 @@ public: FileRefPrivate(File *f) : file(f) {} - FileRefPrivate(const SHARED_PTR &f) : - file(f) {} - SHARED_PTR file; }; @@ -227,7 +224,7 @@ FileRef::FileRef(File *file) : } FileRef::FileRef(const FileRef &ref) : - d(new FileRefPrivate(ref.d->file)) + d(new FileRefPrivate(*ref.d)) { } diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 79f25dcf..872526e8 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -45,7 +45,7 @@ MP4::Atom::Atom(File *file) offset = file->tell(); ByteVector header = file->readBlock(8); - if (header.size() != 8) { + if(header.size() != 8) { // The atom header must be 8 bytes long, otherwise there is either // trailing garbage or the file is truncated debug("MP4: Couldn't read 8 bytes of data for atom header"); @@ -79,7 +79,7 @@ MP4::Atom::Atom(File *file) while(file->tell() < offset + length) { MP4::Atom *child = new MP4::Atom(file); children.append(child); - if (child->length == 0) + if(child->length == 0) return; } return; diff --git a/taglib/mpc/mpcfile.cpp b/taglib/mpc/mpcfile.cpp index 06cd2b2f..91e2bc6b 100644 --- a/taglib/mpc/mpcfile.cpp +++ b/taglib/mpc/mpcfile.cpp @@ -272,7 +272,7 @@ void MPC::File::read(bool readProperties) d->tag.set(MPCAPEIndex, new APE::Tag(this, d->APELocation)); d->APESize = APETag()->footer()->completeTagSize(); - d->APELocation = d->APELocation + APETag()->footer()->size() - d->APESize; + d->APELocation = d->APELocation + APE::Footer::size() - d->APESize; d->hasAPE = true; } diff --git a/taglib/wavpack/wavpackfile.cpp b/taglib/wavpack/wavpackfile.cpp index 2411ef08..603cd02b 100644 --- a/taglib/wavpack/wavpackfile.cpp +++ b/taglib/wavpack/wavpackfile.cpp @@ -248,7 +248,7 @@ void WavPack::File::read(bool readProperties) if(d->APELocation >= 0) { d->tag.set(WavAPEIndex, new APE::Tag(this, d->APELocation)); d->APESize = APETag()->footer()->completeTagSize(); - d->APELocation = d->APELocation + APETag()->footer()->size() - d->APESize; + d->APELocation = d->APELocation + APE::Footer::size() - d->APESize; d->hasAPE = true; } diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index 7ab12030..119a768a 100644 --- a/tests/test_asf.cpp +++ b/tests/test_asf.cpp @@ -75,17 +75,18 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; - values.append("Foo"); - values.append("Bar"); - f->tag()->setAttribute("WM/AlbumTitle", values); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(2, (int)f->tag()->attributeListMap()["WM/AlbumTitle"].size()); - delete f; + { + ASF::File f(newname.c_str()); + ASF::AttributeList values; + values.append("Foo"); + values.append("Bar"); + f.tag()->setAttribute("WM/AlbumTitle", values); + f.save(); + } + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(2, (int)f.tag()->attributeListMap()["WM/AlbumTitle"].size()); + } } void testDWordTrackNumber() @@ -93,27 +94,28 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(!f->tag()->contains("WM/TrackNumber")); - f->tag()->setAttribute("WM/TrackNumber", (unsigned int)(123)); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber")); - CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType, - f->tag()->attribute("WM/TrackNumber").front().type()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(123), f->tag()->track()); - f->tag()->setTrack(234); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("WM/TrackNumber")); - CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType, - f->tag()->attribute("WM/TrackNumber").front().type()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(234), f->tag()->track()); - delete f; + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT(!f.tag()->contains("WM/TrackNumber")); + f.tag()->setAttribute("WM/TrackNumber", (unsigned int)(123)); + f.save(); + } + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber")); + CPPUNIT_ASSERT_EQUAL(ASF::Attribute::DWordType, + f.tag()->attribute("WM/TrackNumber").front().type()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(123), f.tag()->track()); + f.tag()->setTrack(234); + f.save(); + } + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("WM/TrackNumber")); + CPPUNIT_ASSERT_EQUAL(ASF::Attribute::UnicodeType, + f.tag()->attribute("WM/TrackNumber").front().type()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(234), f.tag()->track()); + } } void testSaveStream() @@ -121,16 +123,18 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::Attribute attr("Foo"); - attr.setStream(43); - f->tag()->setAttribute("WM/AlbumTitle", attr); - f->save(); - delete f; + { + ASF::File f(newname.c_str()); + ASF::Attribute attr("Foo"); + attr.setStream(43); + f.tag()->setAttribute("WM/AlbumTitle", attr); + f.save(); + } - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(43, f->tag()->attribute("WM/AlbumTitle").front().stream()); - delete f; + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(43, f.tag()->attribute("WM/AlbumTitle").front().stream()); + } } void testSaveLanguage() @@ -138,18 +142,19 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::Attribute attr("Foo"); - attr.setStream(32); - attr.setLanguage(56); - f->tag()->setAttribute("WM/AlbumTitle", attr); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(32, f->tag()->attribute("WM/AlbumTitle").front().stream()); - CPPUNIT_ASSERT_EQUAL(56, f->tag()->attribute("WM/AlbumTitle").front().language()); - delete f; + { + ASF::File f(newname.c_str()); + ASF::Attribute attr("Foo"); + attr.setStream(32); + attr.setLanguage(56); + f.tag()->setAttribute("WM/AlbumTitle", attr); + f.save(); + } + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(32, f.tag()->attribute("WM/AlbumTitle").front().stream()); + CPPUNIT_ASSERT_EQUAL(56, f.tag()->attribute("WM/AlbumTitle").front().language()); + } } void testSaveLargeValue() @@ -157,16 +162,17 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::Attribute attr(ByteVector(70000, 'x')); - f->tag()->setAttribute("WM/Blob", attr); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'), - f->tag()->attribute("WM/Blob").front().toByteVector()); - delete f; + { + ASF::File f(newname.c_str()); + ASF::Attribute attr(ByteVector(70000, 'x')); + f.tag()->setAttribute("WM/Blob", attr); + f.save(); + } + { + ASF::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'), + f.tag()->attribute("WM/Blob").front().toByteVector()); + } } void testSavePicture() @@ -174,27 +180,28 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::Picture picture; - picture.setMimeType("image/jpeg"); - picture.setType(ASF::Picture::FrontCover); - picture.setDescription("description"); - picture.setPicture("data"); - f->tag()->setAttribute("WM/Picture", picture); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - ASF::AttributeList values2 = f->tag()->attribute("WM/Picture"); - CPPUNIT_ASSERT_EQUAL(size_t(1), values2.size()); - ASF::Attribute attr2 = values2.front(); - ASF::Picture picture2 = attr2.toPicture(); - CPPUNIT_ASSERT(picture2.isValid()); - CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture2.mimeType()); - CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture2.type()); - CPPUNIT_ASSERT_EQUAL(String("description"), picture2.description()); - CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture2.picture()); - delete f; + { + ASF::File f(newname.c_str()); + ASF::Picture picture; + picture.setMimeType("image/jpeg"); + picture.setType(ASF::Picture::FrontCover); + picture.setDescription("description"); + picture.setPicture("data"); + f.tag()->setAttribute("WM/Picture", picture); + f.save(); + } + { + ASF::File f(newname.c_str()); + ASF::AttributeList values2 = f.tag()->attribute("WM/Picture"); + CPPUNIT_ASSERT_EQUAL(size_t(1), values2.size()); + ASF::Attribute attr2 = values2.front(); + ASF::Picture picture2 = attr2.toPicture(); + CPPUNIT_ASSERT(picture2.isValid()); + CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture2.mimeType()); + CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture2.type()); + CPPUNIT_ASSERT_EQUAL(String("description"), picture2.description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture2.picture()); + } } void testSaveMultiplePictures() @@ -202,40 +209,41 @@ public: ScopedFileCopy copy("silence-1", ".wma"); string newname = copy.fileName(); - ASF::File *f = new ASF::File(newname.c_str()); - ASF::AttributeList values; - ASF::Picture picture; - picture.setMimeType("image/jpeg"); - picture.setType(ASF::Picture::FrontCover); - picture.setDescription("description"); - picture.setPicture("data"); - values.append(ASF::Attribute(picture)); - ASF::Picture picture2; - picture2.setMimeType("image/png"); - picture2.setType(ASF::Picture::BackCover); - picture2.setDescription("back cover"); - picture2.setPicture("PNG data"); - values.append(ASF::Attribute(picture2)); - f->tag()->setAttribute("WM/Picture", values); - f->save(); - delete f; - - f = new ASF::File(newname.c_str()); - ASF::AttributeList values2 = f->tag()->attribute("WM/Picture"); - CPPUNIT_ASSERT_EQUAL(size_t(2), values2.size()); - ASF::Picture picture3 = values2[1].toPicture(); - CPPUNIT_ASSERT(picture3.isValid()); - CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture3.mimeType()); - CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture3.type()); - CPPUNIT_ASSERT_EQUAL(String("description"), picture3.description()); - CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture3.picture()); - ASF::Picture picture4 = values2[0].toPicture(); - CPPUNIT_ASSERT(picture4.isValid()); - CPPUNIT_ASSERT_EQUAL(String("image/png"), picture4.mimeType()); - CPPUNIT_ASSERT_EQUAL(ASF::Picture::BackCover, picture4.type()); - CPPUNIT_ASSERT_EQUAL(String("back cover"), picture4.description()); - CPPUNIT_ASSERT_EQUAL(ByteVector("PNG data"), picture4.picture()); - delete f; + { + ASF::File f(newname.c_str()); + ASF::AttributeList values; + ASF::Picture picture; + picture.setMimeType("image/jpeg"); + picture.setType(ASF::Picture::FrontCover); + picture.setDescription("description"); + picture.setPicture("data"); + values.append(ASF::Attribute(picture)); + ASF::Picture picture2; + picture2.setMimeType("image/png"); + picture2.setType(ASF::Picture::BackCover); + picture2.setDescription("back cover"); + picture2.setPicture("PNG data"); + values.append(ASF::Attribute(picture2)); + f.tag()->setAttribute("WM/Picture", values); + f.save(); + } + { + ASF::File f(newname.c_str()); + ASF::AttributeList values2 = f.tag()->attribute("WM/Picture"); + CPPUNIT_ASSERT_EQUAL(size_t(2), values2.size()); + ASF::Picture picture3 = values2[1].toPicture(); + CPPUNIT_ASSERT(picture3.isValid()); + CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture3.mimeType()); + CPPUNIT_ASSERT_EQUAL(ASF::Picture::FrontCover, picture3.type()); + CPPUNIT_ASSERT_EQUAL(String("description"), picture3.description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("data"), picture3.picture()); + ASF::Picture picture4 = values2[0].toPicture(); + CPPUNIT_ASSERT(picture4.isValid()); + CPPUNIT_ASSERT_EQUAL(String("image/png"), picture4.mimeType()); + CPPUNIT_ASSERT_EQUAL(ASF::Picture::BackCover, picture4.type()); + CPPUNIT_ASSERT_EQUAL(String("back cover"), picture4.description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("PNG data"), picture4.picture()); + } } void testProperties() diff --git a/tests/test_fileref.cpp b/tests/test_fileref.cpp index 1e28d48f..29258c86 100644 --- a/tests/test_fileref.cpp +++ b/tests/test_fileref.cpp @@ -54,57 +54,55 @@ public: ScopedFileCopy copy(filename, ext); string newname = copy.fileName(); - FileRef *f = new FileRef(newname.c_str()); - CPPUNIT_ASSERT(f->isValid()); - CPPUNIT_ASSERT(!f->isNull()); - f->tag()->setArtist("test artist"); - f->tag()->setTitle("test title"); - f->tag()->setGenre("Test!"); - f->tag()->setAlbum("albummmm"); - f->tag()->setTrack(5); - f->tag()->setYear(2020); - f->save(); - delete f; - - f = new FileRef(newname.c_str()); - CPPUNIT_ASSERT(f->isValid()); - CPPUNIT_ASSERT(!f->isNull()); - CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("test artist")); - CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("test title")); - CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("Test!")); - CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("albummmm")); - CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(5)); - CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2020)); - f->tag()->setArtist("ttest artist"); - f->tag()->setTitle("ytest title"); - f->tag()->setGenre("uTest!"); - f->tag()->setAlbum("ialbummmm"); - f->tag()->setTrack(7); - f->tag()->setYear(2080); - f->save(); - delete f; - - f = new FileRef(newname.c_str()); - CPPUNIT_ASSERT(f->isValid()); - CPPUNIT_ASSERT(!f->isNull()); - CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist")); - CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title")); - CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!")); - CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm")); - CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7)); - CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080)); - delete f; - - FileStream fs(newname.c_str()); - f = new FileRef(&fs); - CPPUNIT_ASSERT(!f->isNull()); - CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist")); - CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title")); - CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!")); - CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm")); - CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7)); - CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080)); - delete f; + { + FileRef f(newname.c_str()); + CPPUNIT_ASSERT(!f.isNull()); + f.tag()->setArtist("test artist"); + f.tag()->setTitle("test title"); + f.tag()->setGenre("Test!"); + f.tag()->setAlbum("albummmm"); + f.tag()->setTrack(5); + f.tag()->setYear(2020); + f.save(); + } + { + FileRef f(newname.c_str()); + CPPUNIT_ASSERT(!f.isNull()); + CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("test artist")); + CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("test title")); + CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("Test!")); + CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("albummmm")); + CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(5)); + CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2020)); + f.tag()->setArtist("ttest artist"); + f.tag()->setTitle("ytest title"); + f.tag()->setGenre("uTest!"); + f.tag()->setAlbum("ialbummmm"); + f.tag()->setTrack(7); + f.tag()->setYear(2080); + f.save(); + } + { + FileRef f(newname.c_str()); + CPPUNIT_ASSERT(!f.isNull()); + CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("ttest artist")); + CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("ytest title")); + CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("uTest!")); + CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("ialbummmm")); + CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(7)); + CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2080)); + } + { + FileStream fs(newname.c_str()); + FileRef f(&fs); + CPPUNIT_ASSERT(!f.isNull()); + CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("ttest artist")); + CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("ytest title")); + CPPUNIT_ASSERT_EQUAL(f.tag()->genre(), String("uTest!")); + CPPUNIT_ASSERT_EQUAL(f.tag()->album(), String("ialbummmm")); + CPPUNIT_ASSERT_EQUAL(f.tag()->track(), TagLib::uint(7)); + CPPUNIT_ASSERT_EQUAL(f.tag()->year(), TagLib::uint(2080)); + } } void testMusepack() @@ -174,18 +172,16 @@ public: void testOGA_FLAC() { - FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_flac.oga")); - CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); - CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); - delete f; + FileRef f(TEST_FILE_PATH_C("empty_flac.oga")); + CPPUNIT_ASSERT(dynamic_cast(f.file()) == NULL); + CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); } void testOGA_Vorbis() { - FileRef *f = new FileRef(TEST_FILE_PATH_C("empty_vorbis.oga")); - CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); - CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); - delete f; + FileRef f(TEST_FILE_PATH_C("empty_vorbis.oga")); + CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); + CPPUNIT_ASSERT(dynamic_cast(f.file()) == NULL); } void testAPE() @@ -204,16 +200,18 @@ public: void testFileResolver() { - FileRef *f = new FileRef(TEST_FILE_PATH_C("xing.mp3")); - CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); - delete f; + { + FileRef f(TEST_FILE_PATH_C("xing.mp3")); + CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); + } DummyResolver resolver; FileRef::addFileTypeResolver(&resolver); - f = new FileRef(TEST_FILE_PATH_C("xing.mp3")); - CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); - delete f; + { + FileRef f(TEST_FILE_PATH_C("xing.mp3")); + CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); + } } }; diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index 9c5b6d14..049f2dce 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -44,15 +44,16 @@ public: ScopedFileCopy copy("multiple-vc", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f->tag()->artist()); - f->tag()->setArtist("The Artist"); - f->save(); - delete f; - - f = new FLAC::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist()); - delete f; + { + FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f.tag()->artist()); + f.tag()->setArtist("The Artist"); + f.save(); + } + { + FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist()); + } } void testReadPicture() @@ -60,8 +61,8 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - List lst = f->pictureList(); + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); FLAC::Picture *pic = lst.front(); @@ -73,7 +74,6 @@ public: CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size()); - delete f; } void testAddPicture() @@ -81,47 +81,48 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); - FLAC::Picture *newpic = new FLAC::Picture(); - newpic->setType(FLAC::Picture::BackCover); - newpic->setWidth(5); - newpic->setHeight(6); - newpic->setColorDepth(16); - newpic->setNumColors(7); - newpic->setMimeType("image/jpeg"); - newpic->setDescription("new image"); - newpic->setData("JPEG data"); - f->addPicture(newpic); - f->save(); - delete f; + FLAC::Picture *newpic = new FLAC::Picture(); + newpic->setType(FLAC::Picture::BackCover); + newpic->setWidth(5); + newpic->setHeight(6); + newpic->setColorDepth(16); + newpic->setNumColors(7); + newpic->setMimeType("image/jpeg"); + newpic->setDescription("new image"); + newpic->setData("JPEG data"); + f.addPicture(newpic); + f.save(); + } + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(2), lst.size()); - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(2), lst.size()); + FLAC::Picture *pic = lst[0]; + CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); + CPPUNIT_ASSERT_EQUAL(1, pic->width()); + CPPUNIT_ASSERT_EQUAL(1, pic->height()); + CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth()); + CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); + CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); + CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); + CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size()); - FLAC::Picture *pic = lst[0]; - CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); - CPPUNIT_ASSERT_EQUAL(1, pic->width()); - CPPUNIT_ASSERT_EQUAL(1, pic->height()); - CPPUNIT_ASSERT_EQUAL(24, pic->colorDepth()); - CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); - CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); - CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); - CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size()); - - pic = lst[1]; - CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); - CPPUNIT_ASSERT_EQUAL(5, pic->width()); - CPPUNIT_ASSERT_EQUAL(6, pic->height()); - CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth()); - CPPUNIT_ASSERT_EQUAL(7, pic->numColors()); - CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType()); - CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description()); - CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data()); - delete f; + pic = lst[1]; + CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); + CPPUNIT_ASSERT_EQUAL(5, pic->width()); + CPPUNIT_ASSERT_EQUAL(6, pic->height()); + CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth()); + CPPUNIT_ASSERT_EQUAL(7, pic->numColors()); + CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType()); + CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data()); + } } void testReplacePicture() @@ -129,38 +130,39 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); - FLAC::Picture *newpic = new FLAC::Picture(); - newpic->setType(FLAC::Picture::BackCover); - newpic->setWidth(5); - newpic->setHeight(6); - newpic->setColorDepth(16); - newpic->setNumColors(7); - newpic->setMimeType("image/jpeg"); - newpic->setDescription("new image"); - newpic->setData("JPEG data"); - f->removePictures(); - f->addPicture(newpic); - f->save(); - delete f; + FLAC::Picture *newpic = new FLAC::Picture(); + newpic->setType(FLAC::Picture::BackCover); + newpic->setWidth(5); + newpic->setHeight(6); + newpic->setColorDepth(16); + newpic->setNumColors(7); + newpic->setMimeType("image/jpeg"); + newpic->setDescription("new image"); + newpic->setData("JPEG data"); + f.removePictures(); + f.addPicture(newpic); + f.save(); + } + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); - - FLAC::Picture *pic = lst[0]; - CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); - CPPUNIT_ASSERT_EQUAL(5, pic->width()); - CPPUNIT_ASSERT_EQUAL(6, pic->height()); - CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth()); - CPPUNIT_ASSERT_EQUAL(7, pic->numColors()); - CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType()); - CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description()); - CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data()); - delete f; + FLAC::Picture *pic = lst[0]; + CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); + CPPUNIT_ASSERT_EQUAL(5, pic->width()); + CPPUNIT_ASSERT_EQUAL(6, pic->height()); + CPPUNIT_ASSERT_EQUAL(16, pic->colorDepth()); + CPPUNIT_ASSERT_EQUAL(7, pic->numColors()); + CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), pic->mimeType()); + CPPUNIT_ASSERT_EQUAL(String("new image"), pic->description()); + CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), pic->data()); + } } void testRemoveAllPictures() @@ -168,18 +170,19 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); - f->removePictures(); - f->save(); - delete f; - - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(size_t(0), lst.size()); - delete f; + f.removePictures(); + f.save(); + } + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(size_t(0), lst.size()); + } } void testRepeatedSave() @@ -187,21 +190,20 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - Tag *tag = f->tag(); - CPPUNIT_ASSERT_EQUAL(String("Silence"), tag->title()); - tag->setTitle("NEW TITLE"); - f->save(); - CPPUNIT_ASSERT_EQUAL(String("NEW TITLE"), tag->title()); - tag->setTitle("NEW TITLE 2"); - f->save(); - CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title()); - delete f; - - f = new FLAC::File(newname.c_str()); - tag = f->tag(); - CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), tag->title()); - delete f; + { + FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("Silence"), f.tag()->title()); + f.tag()->setTitle("NEW TITLE"); + f.save(); + CPPUNIT_ASSERT_EQUAL(String("NEW TITLE"), f.tag()->title()); + f.tag()->setTitle("NEW TITLE 2"); + f.save(); + CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title()); + } + { + FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title()); + } } void testSaveMultipleValues() @@ -209,20 +211,19 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - Ogg::XiphComment* c = f->xiphComment(true); - c->addField("ARTIST", "artist 1", true); - c->addField("ARTIST", "artist 2", false); - f->save(); - delete f; - - f = new FLAC::File(newname.c_str()); - c = f->xiphComment(true); - Ogg::FieldListMap m = c->fieldListMap(); - CPPUNIT_ASSERT_EQUAL(size_t(2), m["ARTIST"].size()); - CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]); - CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]); - delete f; + { + FLAC::File f(newname.c_str()); + f.xiphComment(true)->addField("ARTIST", "artist 1", true); + f.xiphComment(true)->addField("ARTIST", "artist 2", false); + f.save(); + } + { + FLAC::File f(newname.c_str()); + Ogg::FieldListMap m = f.xiphComment()->fieldListMap(); + CPPUNIT_ASSERT_EQUAL(size_t(2), m["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]); + CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]); + } } void testDict() diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 59c23869..51420870 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -111,46 +111,45 @@ public: ScopedFileCopy copy("no-tags", ".3g2"); string filename = copy.fileName(); - MP4::File *f = new MP4::File(filename.c_str()); - f->tag()->setArtist(ByteVector(3000, 'x')); - ByteVectorList data1; + { - MP4::Atoms a(f); + MP4::File f(filename.c_str()); + f.tag()->setArtist(ByteVector(3000, 'x')); + + MP4::Atoms a(&f); MP4::Atom *stco = a.find("moov")->findall("stco", true)[0]; - f->seek(stco->offset + 12); - ByteVector data = f->readBlock(static_cast(stco->length - 12)); - unsigned int count = data.toUInt32BE(0); - size_t pos = 4; + f.seek(stco->offset + 12); + ByteVector data = f.readBlock(static_cast(stco->length - 12)); + unsigned int count = data.mid(0, 4).toUInt32BE(0); + int pos = 4; while (count--) { - unsigned int offset = data.toUInt32BE(pos); - f->seek(offset); - data1.append(f->readBlock(20)); + unsigned int offset = data.mid(pos, 4).toUInt32BE(0); + f.seek(offset); + data1.append(f.readBlock(20)); pos += 4; } + + f.save(); } - f->save(); - delete f; - f = new MP4::File(filename.c_str()); - { - MP4::Atoms a(f); + MP4::File f(filename.c_str()); + + MP4::Atoms a(&f); MP4::Atom *stco = a.find("moov")->findall("stco", true)[0]; - f->seek(stco->offset + 12); - ByteVector data = f->readBlock(static_cast(stco->length - 12)); - unsigned int count = data.toUInt32BE(0); - size_t pos = 4, i = 0; + f.seek(stco->offset + 12); + ByteVector data = f.readBlock(static_cast(stco->length - 12)); + unsigned int count = data.mid(0, 4).toUInt32BE(0); + int pos = 4, i = 0; while (count--) { - unsigned int offset = data.toUInt32BE(pos); - f->seek(offset); - CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20)); + unsigned int offset = data.mid(pos, 4).toUInt32BE(0); + f.seek(offset); + CPPUNIT_ASSERT_EQUAL(data1[i], f.readBlock(20)); pos += 4; i++; } } - - delete f; } void testFreeForm() @@ -158,18 +157,19 @@ public: ScopedFileCopy copy("has-tags", ".m4a"); string filename = copy.fileName(); - MP4::File *f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("----:com.apple.iTunes:iTunNORM")); - f->tag()->setItem("----:org.kde.TagLib:Foo", StringList("Bar")); - f->save(); - delete f; - - f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("----:org.kde.TagLib:Foo")); - CPPUNIT_ASSERT_EQUAL(String("Bar"), - f->tag()->item("----:org.kde.TagLib:Foo").toStringList().front()); - f->save(); - delete f; + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("----:com.apple.iTunes:iTunNORM")); + f.tag()->setItem("----:org.kde.TagLib:Foo", StringList("Bar")); + f.save(); + } + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("----:org.kde.TagLib:Foo")); + CPPUNIT_ASSERT_EQUAL(String("Bar"), + f.tag()->item("----:org.kde.TagLib:Foo").toStringList().front()); + f.save(); + } } void testSaveExisingWhenIlstIsLast() @@ -177,20 +177,21 @@ public: ScopedFileCopy copy("ilst-is-last", ".m4a"); string filename = copy.fileName(); - MP4::File *f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(String("82,164"), - f->tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front()); - CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist()); - f->tag()->setComment("foo"); - f->save(); - delete f; - - f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(String("82,164"), - f->tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front()); - CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist()); - CPPUNIT_ASSERT_EQUAL(String("foo"), f->tag()->comment()); - delete f; + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(String("82,164"), + f.tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front()); + CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f.tag()->artist()); + f.tag()->setComment("foo"); + f.save(); + } + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(String("82,164"), + f.tag()->item("----:com.apple.iTunes:replaygain_track_minmax").toStringList().front()); + CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f.tag()->artist()); + CPPUNIT_ASSERT_EQUAL(String("foo"), f.tag()->comment()); + } } void test64BitAtom() @@ -198,48 +199,45 @@ public: ScopedFileCopy copy("64bit", ".mp4"); string filename = copy.fileName(); - MP4::File *f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemMap()["cpil"].toBool()); + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(true, f.tag()->itemMap()["cpil"].toBool()); - MP4::Atoms *atoms = new MP4::Atoms(f); - MP4::Atom *moov = atoms->atoms[0]; - CPPUNIT_ASSERT_EQUAL(offset_t(77), moov->length); + MP4::Atoms atoms(&f); + MP4::Atom *moov = atoms.atoms[0]; + CPPUNIT_ASSERT_EQUAL(offset_t(77), moov->length); - f->tag()->setItem("pgap", true); - f->save(); - delete atoms; - delete f; + f.tag()->setItem("pgap", true); + f.save(); + } + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(true, f.tag()->item("cpil").toBool()); + CPPUNIT_ASSERT_EQUAL(true, f.tag()->item("pgap").toBool()); - f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(true, f->tag()->item("cpil").toBool()); - CPPUNIT_ASSERT_EQUAL(true, f->tag()->item("pgap").toBool()); - - atoms = new MP4::Atoms(f); - moov = atoms->atoms[0]; - // original size + 'pgap' size + padding - CPPUNIT_ASSERT_EQUAL(offset_t(77 + 25 + 974), moov->length); - delete atoms; - delete f; + MP4::Atoms atoms(&f); + MP4::Atom *moov = atoms.atoms[0]; + // original size + 'pgap' size + padding + CPPUNIT_ASSERT_EQUAL(offset_t(77 + 25 + 974), moov->length); + } } void testGnre() { - MP4::File *f = new MP4::File(TEST_FILE_PATH_C("gnre.m4a")); - CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f->tag()->genre()); - delete f; + MP4::File f(TEST_FILE_PATH_C("gnre.m4a")); + CPPUNIT_ASSERT_EQUAL(TagLib::String("Ska"), f.tag()->genre()); } void testCovrRead() { - MP4::File *f = new MP4::File(TEST_FILE_PATH_C("has-tags.m4a")); - CPPUNIT_ASSERT(f->tag()->contains("covr")); - MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList(); + MP4::File f(TEST_FILE_PATH_C("has-tags.m4a")); + CPPUNIT_ASSERT(f.tag()->contains("covr")); + MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList(); CPPUNIT_ASSERT_EQUAL(size_t(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); - delete f; } void testCovrWrite() @@ -247,38 +245,38 @@ public: ScopedFileCopy copy("has-tags", ".m4a"); string filename = copy.fileName(); - MP4::File *f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("covr")); - MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList(); - l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo")); - f->tag()->setItem("covr", l); - f->save(); - delete f; - - f = new MP4::File(filename.c_str()); - CPPUNIT_ASSERT(f->tag()->contains("covr")); - l = f->tag()->item("covr").toCoverArtList(); - CPPUNIT_ASSERT_EQUAL(size_t(3), l.size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); - CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); - CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format()); - CPPUNIT_ASSERT_EQUAL(size_t(3), l[2].data().size()); - delete f; + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("covr")); + MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList(); + l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo")); + f.tag()->setItem("covr", l); + f.save(); + } + { + MP4::File f(filename.c_str()); + CPPUNIT_ASSERT(f.tag()->contains("covr")); + MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList(); + CPPUNIT_ASSERT_EQUAL(size_t(3), l.size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); + CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); + CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format()); + CPPUNIT_ASSERT_EQUAL(size_t(3), l[2].data().size()); + } } void testCovrRead2() { - MP4::File *f = new MP4::File(TEST_FILE_PATH_C("covr-junk.m4a")); - CPPUNIT_ASSERT(f->tag()->contains("covr")); - MP4::CoverArtList l = f->tag()->item("covr").toCoverArtList(); + MP4::File f(TEST_FILE_PATH_C("covr-junk.m4a")); + CPPUNIT_ASSERT(f.tag()->contains("covr")); + MP4::CoverArtList l = f.tag()->item("covr").toCoverArtList(); CPPUNIT_ASSERT_EQUAL(size_t(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); - delete f; } void testProperties() diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index f3abf793..f7993c28 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -31,14 +31,15 @@ public: ScopedFileCopy copy("empty", ".ogg"); string newname = copy.fileName(); - Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); - f->tag()->setArtist("The Artist"); - f->save(); - delete f; - - f = new Ogg::Vorbis::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist()); - delete f; + { + Ogg::Vorbis::File f(newname.c_str()); + f.tag()->setArtist("The Artist"); + f.save(); + } + { + Ogg::Vorbis::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist()); + } } void testSplitPackets() @@ -50,24 +51,40 @@ public: for (size_t i = 0; i < longText.length(); ++i) longText[i] = static_cast(L'A' + (i % 26)); - Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); - f->tag()->setTitle(longText); - f->save(); - delete f; + { + Ogg::Vorbis::File f(newname.c_str()); + f.tag()->setTitle(longText); + f.save(); + } + { + Ogg::Vorbis::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)136383, f.length()); + CPPUNIT_ASSERT_EQUAL(19, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)30, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)131127, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)3832, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); - f = new Ogg::Vorbis::File(newname.c_str()); - CPPUNIT_ASSERT(f->isValid()); - CPPUNIT_ASSERT_EQUAL(19, f->lastPageHeader()->pageSequenceNumber()); - CPPUNIT_ASSERT_EQUAL(longText, f->tag()->title()); - f->tag()->setTitle("ABCDE"); - f->save(); - delete f; + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); - f = new Ogg::Vorbis::File(newname.c_str()); - CPPUNIT_ASSERT(f->isValid()); - CPPUNIT_ASSERT_EQUAL(3, f->lastPageHeader()->pageSequenceNumber()); - CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f->tag()->title()); - delete f; + f.tag()->setTitle("ABCDE"); + f.save(); + } + { + Ogg::Vorbis::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)4370, f.length()); + CPPUNIT_ASSERT_EQUAL(3, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)30, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)60, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)3832, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); + } } void testDictInterface1() @@ -75,22 +92,20 @@ public: ScopedFileCopy copy("empty", ".ogg"); string newname = copy.fileName(); - Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); + Ogg::Vorbis::File f(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(size_t(0), f->tag()->properties().size()); + CPPUNIT_ASSERT_EQUAL(size_t(0), f.tag()->properties().size()); PropertyMap newTags; StringList values("value 1"); values.append("value 2"); newTags["ARTIST"] = values; - f->tag()->setProperties(newTags); + f.tag()->setProperties(newTags); - PropertyMap map = f->tag()->properties(); + PropertyMap map = f.tag()->properties(); CPPUNIT_ASSERT_EQUAL(size_t(1), map.size()); CPPUNIT_ASSERT_EQUAL(size_t(2), map["ARTIST"].size()); CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]); - delete f; - } void testDictInterface2() @@ -98,8 +113,8 @@ public: ScopedFileCopy copy("test", ".ogg"); string newname = copy.fileName(); - Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); - PropertyMap tags = f->tag()->properties(); + Ogg::Vorbis::File f(newname.c_str()); + PropertyMap tags = f.tag()->properties(); CPPUNIT_ASSERT_EQUAL(size_t(2), tags["UNUSUALTAG"].size()); CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]); @@ -111,13 +126,11 @@ public: tags["UNICODETAG"][0] = String( "\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8); tags.erase("UNUSUALTAG"); - f->tag()->setProperties(tags); + f.tag()->setProperties(tags); CPPUNIT_ASSERT_EQUAL( String("\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8), - f->tag()->properties()["UNICODETAG"][0]); - CPPUNIT_ASSERT_EQUAL(false, f->tag()->properties().contains("UNUSUALTAG")); - - delete f; + f.tag()->properties()["UNICODETAG"][0]); + CPPUNIT_ASSERT_EQUAL(false, f.tag()->properties().contains("UNUSUALTAG")); } void testAudioProperties() diff --git a/tests/test_oggflac.cpp b/tests/test_oggflac.cpp index 32784b21..f0bf4910 100644 --- a/tests/test_oggflac.cpp +++ b/tests/test_oggflac.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "utils.h" @@ -16,6 +17,7 @@ class TestOggFLAC : public CppUnit::TestFixture CPPUNIT_TEST_SUITE(TestOggFLAC); CPPUNIT_TEST(testFramingBit); CPPUNIT_TEST(testFuzzedFile); + CPPUNIT_TEST(testSplitPackets); CPPUNIT_TEST_SUITE_END(); public: @@ -25,19 +27,18 @@ public: ScopedFileCopy copy("empty_flac", ".oga"); string newname = copy.fileName(); - Ogg::FLAC::File *f = new Ogg::FLAC::File(newname.c_str()); - f->tag()->setArtist("The Artist"); - f->save(); - delete f; + { + Ogg::FLAC::File f(newname.c_str()); + f.tag()->setArtist("The Artist"); + f.save(); + } + { + Ogg::FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist()); - f = new Ogg::FLAC::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist()); - - f->seek(0, File::End); - offset_t size = f->tell(); - CPPUNIT_ASSERT_EQUAL((offset_t)9134, size); - - delete f; + f.seek(0, File::End); + CPPUNIT_ASSERT_EQUAL((offset_t)9134, f.tell()); + } } void testFuzzedFile() @@ -46,6 +47,53 @@ public: CPPUNIT_ASSERT(!f.isValid()); } + void testSplitPackets() + { + ScopedFileCopy copy("empty_flac", ".oga"); + string newname = copy.fileName(); + + String longText(std::string(128 * 1024, ' ').c_str()); + for(size_t i = 0; i < longText.length(); ++i) + longText[i] = static_cast(L'A' + (i % 26)); + + { + Ogg::FLAC::File f(newname.c_str()); + f.tag()->setTitle(longText); + f.save(); + } + { + Ogg::FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)141141, f.length()); + CPPUNIT_ASSERT_EQUAL(21, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)51, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)131126, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)22, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)8196, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds()); + + f.tag()->setTitle("ABCDE"); + f.save(); + } + { + Ogg::FLAC::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)9128, f.length()); + CPPUNIT_ASSERT_EQUAL(5, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)51, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)59, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)22, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)8196, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestOggFLAC); diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 73863bf8..659df743 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "utils.h" @@ -15,6 +16,7 @@ class TestOpus : public CppUnit::TestFixture CPPUNIT_TEST(testAudioProperties); CPPUNIT_TEST(testReadComments); CPPUNIT_TEST(testWriteComments); + CPPUNIT_TEST(testSplitPackets); CPPUNIT_TEST_SUITE_END(); public: @@ -47,17 +49,65 @@ public: ScopedFileCopy copy("correctness_gain_silent_output", ".opus"); string filename = copy.fileName(); - Ogg::Opus::File *f = new Ogg::Opus::File(filename.c_str()); - f->tag()->setArtist("Your Tester"); - f->save(); - delete f; + { + Ogg::Opus::File f(filename.c_str()); + f.tag()->setArtist("Your Tester"); + f.save(); + } + { + Ogg::Opus::File f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f.tag()->fieldListMap()["ENCODER"]); + CPPUNIT_ASSERT(f.tag()->fieldListMap().contains("TESTDESCRIPTION")); + CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f.tag()->fieldListMap()["ARTIST"]); + CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f.tag()->vendorID()); + } + } - f = new Ogg::Opus::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f->tag()->fieldListMap()["ENCODER"]); - CPPUNIT_ASSERT(f->tag()->fieldListMap().contains("TESTDESCRIPTION")); - CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f->tag()->fieldListMap()["ARTIST"]); - CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f->tag()->vendorID()); - delete f; + void testSplitPackets() + { + ScopedFileCopy copy("correctness_gain_silent_output", ".opus"); + string newname = copy.fileName(); + + String longText(std::string(128 * 1024, ' ').c_str()); + for(size_t i = 0; i < longText.length(); ++i) + longText[i] = static_cast(L'A' + (i % 26)); + + { + Ogg::Opus::File f(newname.c_str()); + f.tag()->setTitle(longText); + f.save(); + } + { + Ogg::Opus::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)167534, f.length()); + CPPUNIT_ASSERT_EQUAL(27, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)19, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)131380, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds()); + + f.tag()->setTitle("ABCDE"); + f.save(); + } + { + Ogg::Opus::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)35521, f.length()); + CPPUNIT_ASSERT_EQUAL(11, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)19, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)313, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)5, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds()); + } } }; diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index a5bce476..735f1c14 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -50,44 +50,42 @@ public: ScopedFileCopy copy("empty", ".aiff"); string filename = copy.fileName(); - PublicRIFF *f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2)); + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f.chunkOffset(2)); - f->setChunkData("TEST", "foo"); - delete f; + f.setChunkData("TEST", "foo"); + } + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f.chunkOffset(2)); - f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2)); + f.setChunkData("SSND", "abcd"); - f->setChunkData("SSND", "abcd"); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.chunkData(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->chunkData(1)); + f.seek(f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.readBlock(4)); - f->seek(f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->readBlock(4)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2)); + f.seek(f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.readBlock(3)); + } + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f.chunkData(1)); - f->seek(f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->readBlock(3)); - - delete f; - - f = new PublicRIFF(filename.c_str()); - - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("abcd"), f->chunkData(1)); - - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2)); - - delete f; + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f.chunkData(2)); + } } void testLastChunkAtEvenPosition() @@ -95,36 +93,37 @@ public: ScopedFileCopy copy("noise", ".aif"); string filename = copy.fileName(); - PublicRIFF *f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4400), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abcd"); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f->riffSize()); - delete f; - - f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4400), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abcd"); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f.riffSize()); + } + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f.length()); + } } void testLastChunkAtEvenPosition2() @@ -132,36 +131,37 @@ public: ScopedFileCopy copy("noise_odd", ".aif"); string filename = copy.fileName(); - PublicRIFF *f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4399), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abcd"); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f->riffSize()); - delete f; - - f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4399), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abcd"); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4412 - 8), f.riffSize()); + } + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f.length()); + } } void testLastChunkAtEvenPosition3() @@ -169,36 +169,37 @@ public: ScopedFileCopy copy("noise_odd", ".aif"); string filename = copy.fileName(); - PublicRIFF *f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4399), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abc"); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4411 - 8), f->riffSize()); - delete f; - - f = new PublicRIFF(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(offset_t(4088), f->chunkOffset(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(4408), f->chunkOffset(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(3)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(0xff0 + 8), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4399), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abc"); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4411 - 8), f.riffSize()); + } + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(offset_t(4088), f.chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f.chunkDataSize(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(4408), f.chunkOffset(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f.chunkDataSize(3)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f.chunkPadding(3)); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f.length()); + } } void testChunkOffset() @@ -206,56 +207,54 @@ public: ScopedFileCopy copy("empty", ".aiff"); string filename = copy.fileName(); - PublicRIFF *f = new PublicRIFF(filename.c_str()); + PublicRIFF f(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->chunkName(0)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f->chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.chunkName(0)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x1728 + 8), f.chunkOffset(2)); const ByteVector data(0x400, ' '); - f->setChunkData("SSND", data); - CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x042E + 8), f->chunkOffset(2)); + f.setChunkData("SSND", data); + CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x0026 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x042E + 8), f.chunkOffset(2)); - f->seek(f->chunkOffset(0) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); - f->seek(f->chunkOffset(1) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4)); - f->seek(f->chunkOffset(2) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + f.seek(f.chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4)); + f.seek(f.chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.readBlock(4)); + f.seek(f.chunkOffset(2) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); - f->setChunkData(0, data); - CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x081C + 8), f->chunkOffset(2)); + f.setChunkData(0, data); + CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x081C + 8), f.chunkOffset(2)); - f->seek(f->chunkOffset(0) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); - f->seek(f->chunkOffset(1) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4)); - f->seek(f->chunkOffset(2) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + f.seek(f.chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4)); + f.seek(f.chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.readBlock(4)); + f.seek(f.chunkOffset(2) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); - f->removeChunk("SSND"); - CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f->chunkOffset(1)); + f.removeChunk("SSND"); + CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(offset_t(0x0414 + 8), f.chunkOffset(1)); - f->seek(f->chunkOffset(0) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); - f->seek(f->chunkOffset(1) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + f.seek(f.chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.readBlock(4)); + f.seek(f.chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); - f->removeChunk(0); - CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f->chunkOffset(0)); + f.removeChunk(0); + CPPUNIT_ASSERT_EQUAL(offset_t(0x000C + 8), f.chunkOffset(0)); - f->seek(f->chunkOffset(0) - 8); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); - - delete f; + f.seek(f.chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); } }; diff --git a/tests/test_speex.cpp b/tests/test_speex.cpp index 577adb3e..06d3276f 100644 --- a/tests/test_speex.cpp +++ b/tests/test_speex.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "utils.h" @@ -9,6 +10,7 @@ class TestSpeex : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestSpeex); CPPUNIT_TEST(testAudioProperties); + CPPUNIT_TEST(testSplitPackets); CPPUNIT_TEST_SUITE_END(); public: @@ -26,6 +28,53 @@ public: CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); } + void testSplitPackets() + { + ScopedFileCopy copy("empty", ".spx"); + string newname = copy.fileName(); + + String longText(std::string(128 * 1024, ' ').c_str()); + for (size_t i = 0; i < longText.length(); ++i) + longText[i] = static_cast(L'A' + (i % 26)); + + { + Ogg::Speex::File f(newname.c_str()); + f.tag()->setTitle(longText); + f.save(); + } + { + Ogg::Speex::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)156330, f.length()); + CPPUNIT_ASSERT_EQUAL(23, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)80, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)131116, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(longText, f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); + + f.tag()->setTitle("ABCDE"); + f.save(); + } + { + Ogg::Speex::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL((offset_t)24317, f.length()); + CPPUNIT_ASSERT_EQUAL(7, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL((size_t)80, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL((size_t)49, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL((size_t)93, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestSpeex); diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp index d209fdae..057a677a 100644 --- a/tests/test_wav.cpp +++ b/tests/test_wav.cpp @@ -154,36 +154,37 @@ public: ScopedFileCopy copy("empty", ".wav"); string filename = copy.fileName(); - RIFF::WAV::File *f = new RIFF::WAV::File(filename.c_str()); - f->ID3v2Tag()->setTitle("test title"); - f->InfoTag()->setTitle("test title"); - f->save(); - delete f; - - f = new RIFF::WAV::File(filename.c_str()); - CPPUNIT_ASSERT(f->hasID3v2Tag()); - CPPUNIT_ASSERT(f->hasInfoTag()); - f->save(RIFF::WAV::File::ID3v2, true); - delete f; - - f = new RIFF::WAV::File(filename.c_str()); - CPPUNIT_ASSERT(f->hasID3v2Tag()); - CPPUNIT_ASSERT(!f->hasInfoTag()); - f->ID3v2Tag()->setTitle("test title"); - f->InfoTag()->setTitle("test title"); - f->save(); - delete f; - - f = new RIFF::WAV::File(filename.c_str()); - CPPUNIT_ASSERT(f->hasID3v2Tag()); - CPPUNIT_ASSERT(f->hasInfoTag()); - f->save(RIFF::WAV::File::Info, true); - delete f; - - f = new RIFF::WAV::File(filename.c_str()); - CPPUNIT_ASSERT(!f->hasID3v2Tag()); - CPPUNIT_ASSERT(f->hasInfoTag()); - delete f; + { + RIFF::WAV::File f(filename.c_str()); + f.ID3v2Tag()->setTitle("test title"); + f.InfoTag()->setTitle("test title"); + f.save(); + } + { + RIFF::WAV::File f(filename.c_str()); + CPPUNIT_ASSERT(f.hasID3v2Tag()); + CPPUNIT_ASSERT(f.hasInfoTag()); + f.save(RIFF::WAV::File::ID3v2, true); + } + { + RIFF::WAV::File f(filename.c_str()); + CPPUNIT_ASSERT(f.hasID3v2Tag()); + CPPUNIT_ASSERT(!f.hasInfoTag()); + f.ID3v2Tag()->setTitle("test title"); + f.InfoTag()->setTitle("test title"); + f.save(); + } + { + RIFF::WAV::File f(filename.c_str()); + CPPUNIT_ASSERT(f.hasID3v2Tag()); + CPPUNIT_ASSERT(f.hasInfoTag()); + f.save(RIFF::WAV::File::Info, true); + } + { + RIFF::WAV::File f(filename.c_str()); + CPPUNIT_ASSERT(!f.hasID3v2Tag()); + CPPUNIT_ASSERT(f.hasInfoTag()); + } } void testDuplicateTags() diff --git a/tests/utils.h b/tests/utils.h index de51c04c..99a7c669 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -30,17 +30,11 @@ inline string copyFile(const string &filename, const string &ext) char testFileName[1024]; #ifdef _WIN32 - GetTempPathA(sizeof(testFileName), testFileName); - GetTempFileNameA(testFileName, "tag", 0, testFileName); - DeleteFileA(testFileName); -# if defined(_MSC_VER) && _MSC_VER > 1500 - strcat_s(testFileName, ext.c_str()); -# else - strcat(testFileName, ext.c_str()); -# endif + char tempDir[MAX_PATH + 1]; + GetTempPathA(sizeof(tempDir), tempDir); + wsprintfA(testFileName, "%s\\taglib-test%s", tempDir, ext.c_str()); #else - snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test-XXXXXX%s", P_tmpdir, ext.c_str()); - static_cast(mkstemps(testFileName, 6)); + snprintf(testFileName, sizeof(testFileName), "/%s/taglib-test%s", P_tmpdir, ext.c_str()); #endif string sourceFileName = testFilePath(filename) + ext;