From 35d5ba4eff0421e10aeedecabe382a1d01e21849 Mon Sep 17 00:00:00 2001 From: Festus Hagen Date: Wed, 20 May 2015 03:06:03 -0400 Subject: [PATCH 01/12] Add BUILD_BINDINGS option, moved if(BUILD_EXAMPLES) to taglib/CMakeLists, plus some cleanup. --- .travis.yml | 2 +- CMakeLists.txt | 52 +++++++++++++++++++++++------------------ examples/CMakeLists.txt | 51 ++++++++++++++++------------------------ 3 files changed, 50 insertions(+), 55 deletions(-) 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 4bde0d0a..a5e9bb9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,25 @@ 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) +option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) if(VISIBILITY_HIDDEN) - add_definitions (-fvisibility=hidden) + add_definitions(-fvisibility=hidden) endif() -option(BUILD_TESTS "Build the test suite" OFF) -option(BUILD_EXAMPLES "Build the examples" 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) +option(NO_ITUNES_HACKS "Disable workarounds for iTunes bugs" OFF) add_definitions(-DHAVE_CONFIG_H) set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/") @@ -38,14 +39,15 @@ set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The su set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The subdirectory to the header prefix" FORCE) if(APPLE) - option(BUILD_FRAMEWORK "Build an OS X framework" OFF) - set(FRAMEWORK_INSTALL_DIR "/Library/Frameworks" CACHE STRING "Directory to install frameworks to.") + option(BUILD_FRAMEWORK "Build an OS X framework" OFF) + set(FRAMEWORK_INSTALL_DIR "/Library/Frameworks" CACHE STRING "Directory to install frameworks to.") endif() 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}}") @@ -61,7 +63,7 @@ set(TAGLIB_LIB_VERSION_STRING "${TAGLIB_LIB_MAJOR_VERSION}.${TAGLIB_LIB_MINOR_VE # 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 0) set(TAGLIB_SOVERSION_AGE 15) @@ -109,25 +111,29 @@ endif() configure_file(taglib/taglib_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/taglib_config.h") -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) + enable_testing() + add_subdirectory(tests) +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") -endif() \ No newline at end of file + add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") +endif() + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 17d4bd6b..7792a2a6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,50 +1,39 @@ -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}/../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 ) - - -endif(BUILD_EXAMPLES) +add_executable(strip-id3v1 strip-id3v1.cpp) +target_link_libraries(strip-id3v1 tag) From 3612c2cc241324376c9de26d9c11a6ad8eab8fcf Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 24 Nov 2015 15:45:38 +0900 Subject: [PATCH 02/12] Small cosmetic fix. --- taglib/toolkit/tstring.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index d15fbad7..829fe477 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -597,7 +597,8 @@ int String::toInt(bool *ok) const *ok = (*ok && value > INT_MIN && value < INT_MAX); } - return static_cast(value);} + return static_cast(value); +} String String::stripWhiteSpace() const { From fa4289e0440b1be75fa3cd63a1b085c88885e1a4 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 24 Nov 2015 16:36:50 +0900 Subject: [PATCH 03/12] Fix instance references to a static member function. --- taglib/ape/apefile.cpp | 2 +- taglib/mpc/mpcfile.cpp | 2 +- taglib/wavpack/wavpackfile.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/taglib/ape/apefile.cpp b/taglib/ape/apefile.cpp index caefe737..24171145 100644 --- a/taglib/ape/apefile.cpp +++ b/taglib/ape/apefile.cpp @@ -283,7 +283,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/mpc/mpcfile.cpp b/taglib/mpc/mpcfile.cpp index 1d798212..015bc0e0 100644 --- a/taglib/mpc/mpcfile.cpp +++ b/taglib/mpc/mpcfile.cpp @@ -282,7 +282,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 7273e103..f7c97f7e 100644 --- a/taglib/wavpack/wavpackfile.cpp +++ b/taglib/wavpack/wavpackfile.cpp @@ -258,7 +258,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; } From 66dd0b8a6fd750a9e137137773bbcb24b3a7636f Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 25 Nov 2015 00:12:18 +0900 Subject: [PATCH 04/12] Small cosmetic fixes. --- taglib/mp4/mp4atom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 681589d8..1a5c3208 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -47,7 +47,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"); @@ -96,7 +96,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; From 14f3b6c928c9e2843a34c63bd5abbac5eee35d46 Mon Sep 17 00:00:00 2001 From: g-coder Date: Thu, 26 Nov 2015 15:12:23 +0530 Subject: [PATCH 05/12] Added ccache support for faster compilation ccache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. It provides support for C/C++ languages. It makes compilation fast if it is available on the machine. https://ccache.samba.org/ --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fe1dadb..27c146a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,12 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake" "${CMAKE_CURRENT_BIN file(COPY doc/taglib.png DESTINATION doc) add_custom_target(docs doxygen) +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(CCACHE_FOUND) + # uninstall target configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" From e1bcb101f03e235cb6f829e05bc36d0c37ad6dd2 Mon Sep 17 00:00:00 2001 From: g-coder Date: Thu, 26 Nov 2015 15:51:42 +0530 Subject: [PATCH 06/12] Update CMakeLists.txt --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27c146a9..1b99fb59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,8 +139,8 @@ add_custom_target(docs doxygen) find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) endif(CCACHE_FOUND) # uninstall target From 3f84621d58c6a8174266d5e023a00cd524135e12 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 27 Nov 2015 02:27:24 +0900 Subject: [PATCH 07/12] Small cleanups in CMakeLists.txt. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b99fb59..985ceef6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,7 @@ add_subdirectory(bindings) if(BUILD_TESTS) enable_testing() add_subdirectory(tests) -endif(BUILD_TESTS) +endif() add_subdirectory(examples) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") @@ -141,7 +141,7 @@ 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(CCACHE_FOUND) +endif() # uninstall target configure_file( From 67cbf2c0a83c6b2d09bfc2e729773d423abad1ce Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 27 Nov 2015 02:45:33 +0900 Subject: [PATCH 08/12] Silence a GCC warning in tests about ignoring a return value. --- tests/utils.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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; From f5a3f2b6c132a2c83d445c2c2947e6f365fdab4b Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 27 Nov 2015 09:37:29 +0900 Subject: [PATCH 09/12] Update NEWS. --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index baf214b2..ade98dba 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ * 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. * Marked ByteVector::null and ByteVector::isNull() deprecated. * Marked String::null and ByteVector::isNull() deprecated. * Marked XiphComment::removeField() deprecated. From 6b836c6ba70a4b8f4c213fcf8e30effa35797354 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 27 Nov 2015 12:15:03 +0900 Subject: [PATCH 10/12] Add ENABLE_CCACHE build option to allow users opt in to use ccache. --- CMakeLists.txt | 15 +++++++++------ NEWS | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dcb72b4..9491d47f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,15 @@ else() endif() option(ENABLE_STATIC_RUNTIME "Visual Studio, link with runtime statically" OFF) +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(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF) if(VISIBILITY_HIDDEN) add_definitions(-fvisibility=hidden) @@ -146,12 +155,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake" "${CMAKE_CURRENT_BIN file(COPY doc/taglib.png DESTINATION doc) add_custom_target(docs doxygen) -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() - # uninstall target configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) diff --git a/NEWS b/NEWS index ade98dba..86680008 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ * 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. From 8130b3039738866f6f0f9a9aae903021e85802d7 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 27 Nov 2015 15:20:16 +0900 Subject: [PATCH 11/12] Close temporary files regardless if the tests are successful or not. delete statements are skipped when assertions fail. --- tests/test_asf.cpp | 244 ++++++++++++++++--------------- tests/test_fileref.cpp | 125 ++++++++-------- tests/test_flac.cpp | 271 +++++++++++++++++----------------- tests/test_mp4.cpp | 186 ++++++++++++------------ tests/test_ogg.cpp | 76 +++++----- tests/test_oggflac.cpp | 23 ++- tests/test_opus.cpp | 23 +-- tests/test_riff.cpp | 321 ++++++++++++++++++++--------------------- tests/test_wav.cpp | 61 ++++---- 9 files changed, 668 insertions(+), 662 deletions(-) diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index 37614b0c..2dfcb64d 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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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 a389cfd3..f0122c83 100644 --- a/tests/test_fileref.cpp +++ b/tests/test_fileref.cpp @@ -52,54 +52,55 @@ public: ScopedFileCopy copy(filename, ext); string newname = copy.fileName(); - FileRef *f = new FileRef(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(); - delete f; - - f = new FileRef(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(); - delete f; - - f = new FileRef(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)); - 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() @@ -159,18 +160,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() @@ -189,16 +188,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 54104cc5..9fdd51e1 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(TagLib::uint(1), lst.size()); FLAC::Picture *pic = lst.front(); @@ -73,8 +74,6 @@ public: CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size()); - - delete f; } void testAddPicture() @@ -82,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(TagLib::uint(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(2), lst.size()); - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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() @@ -130,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(TagLib::uint(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(1), lst.size()); - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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() @@ -169,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(TagLib::uint(1), lst.size()); + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); - f->removePictures(); - f->save(); - delete f; - - f = new FLAC::File(newname.c_str()); - lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), lst.size()); - delete f; + f.removePictures(); + f.save(); + } + { + FLAC::File f(newname.c_str()); + List lst = f.pictureList(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), lst.size()); + } } void testRepeatedSave() @@ -188,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() @@ -210,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(TagLib::uint(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(TagLib::uint(2), m["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]); + CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]); + } } void testDict() @@ -232,20 +232,21 @@ public: ScopedFileCopy copy("silence-44-s", ".flac"); string newname = copy.fileName(); - FLAC::File *f = new FLAC::File(newname.c_str()); - PropertyMap dict; - dict["ARTIST"].append("artøst 1"); - dict["ARTIST"].append("artöst 2"); - f->setProperties(dict); - f->save(); - delete f; - - f = new FLAC::File(newname.c_str()); - dict = f->properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["ARTIST"].size()); - CPPUNIT_ASSERT_EQUAL(String("artøst 1"), dict["ARTIST"][0]); - CPPUNIT_ASSERT_EQUAL(String("artöst 2"), dict["ARTIST"][1]); - delete f; + { + FLAC::File f(newname.c_str()); + PropertyMap dict; + dict["ARTIST"].append("artøst 1"); + dict["ARTIST"].append("artöst 2"); + f.setProperties(dict); + f.save(); + } + { + FLAC::File f(newname.c_str()); + PropertyMap dict = f.properties(); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(String("artøst 1"), dict["ARTIST"][0]); + CPPUNIT_ASSERT_EQUAL(String("artöst 2"), dict["ARTIST"][1]); + } } void testInvalid() diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 58dbae42..42d33b28 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(stco->length - 12); + f.seek(stco->offset + 12); + ByteVector data = f.readBlock(stco->length - 12); unsigned int count = data.mid(0, 4).toUInt(); int pos = 4; while (count--) { unsigned int offset = data.mid(pos, 4).toUInt(); - f->seek(offset); - data1.append(f->readBlock(20)); + 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(stco->length - 12); + f.seek(stco->offset + 12); + ByteVector data = f.readBlock(stco->length - 12); unsigned int count = data.mid(0, 4).toUInt(); int pos = 4, i = 0; while (count--) { unsigned int offset = data.mid(pos, 4).toUInt(); - f->seek(offset); - CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20)); + 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(long(77), moov->length); + MP4::Atoms atoms(&f); + MP4::Atom *moov = atoms.atoms[0]; + CPPUNIT_ASSERT_EQUAL(long(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(long(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(long(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(TagLib::uint(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(3), l.size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); - CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(3), l.size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); - delete f; } void testProperties() diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index 90ae162d..0fc7cfef 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -31,14 +31,15 @@ public: ScopedFileCopy copy("empty", ".ogg"); string newname = copy.fileName(); - Vorbis::File *f = new Vorbis::File(newname.c_str()); - f->tag()->setArtist("The Artist"); - f->save(); - delete f; - - f = new Vorbis::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist()); - delete f; + { + Vorbis::File f(newname.c_str()); + f.tag()->setArtist("The Artist"); + f.save(); + } + { + Vorbis::File f(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist()); + } } void testSplitPackets() @@ -50,24 +51,25 @@ public: for (size_t i = 0; i < longText.length(); ++i) longText[i] = static_cast(L'A' + (i % 26)); - Vorbis::File *f = new Vorbis::File(newname.c_str()); - f->tag()->setTitle(longText); - f->save(); - delete f; - - f = new 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; - - f = new 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; + { + Vorbis::File f(newname.c_str()); + f.tag()->setTitle(longText); + f.save(); + } + { + Vorbis::File f(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(); + } + { + Vorbis::File f(newname.c_str()); + CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL(3, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + } } void testDictInterface1() @@ -75,22 +77,20 @@ public: ScopedFileCopy copy("empty", ".ogg"); string newname = copy.fileName(); - Vorbis::File *f = new Vorbis::File(newname.c_str()); + Vorbis::File f(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->tag()->properties().size()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(1), map.size()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), map["ARTIST"].size()); CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]); - delete f; - } void testDictInterface2() @@ -98,8 +98,8 @@ public: ScopedFileCopy copy("test", ".ogg"); string newname = copy.fileName(); - Vorbis::File *f = new Vorbis::File(newname.c_str()); - PropertyMap tags = f->tag()->properties(); + Vorbis::File f(newname.c_str()); + PropertyMap tags = f.tag()->properties(); CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), tags["UNUSUALTAG"].size()); CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]); @@ -111,13 +111,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 975af44e..e0f5bb16 100644 --- a/tests/test_oggflac.cpp +++ b/tests/test_oggflac.cpp @@ -25,19 +25,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); - int size = f->tell(); - CPPUNIT_ASSERT_EQUAL(9134, size); - - delete f; + f.seek(0, File::End); + CPPUNIT_ASSERT_EQUAL(9134L, f.tell()); + } } void testFuzzedFile() diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 73863bf8..398e7e91 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -47,17 +47,18 @@ 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; - - 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; + { + 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()); + } } }; diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index e07687f1..4ee8d080 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(TagLib::uint(0x1728 + 8), f->chunkOffset(2)); + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(4400), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abcd"); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(long(4400), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abcd"); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(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(TagLib::uint(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(long(4399), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abcd"); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(long(4399), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abcd"); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(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(TagLib::uint(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(long(4399), f->length()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); - f->setChunkData("TEST", "abc"); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(4412), f->length()); - delete f; + { + PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(long(4399), f.length()); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f.riffSize()); + f.setChunkData("TEST", "abc"); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(TagLib::uint(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(long(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(TagLib::uint(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2)); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.chunkName(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f.chunkOffset(2)); const ByteVector data(0x400, ' '); - f->setChunkData("SSND", data); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x042E + 8), f->chunkOffset(2)); + f.setChunkData("SSND", data); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x081C + 8), f->chunkOffset(2)); + f.setChunkData(0, data); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f.chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(0x000C + 8), f->chunkOffset(0)); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1)); + f.removeChunk("SSND"); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f.chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + f.removeChunk(0); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(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_wav.cpp b/tests/test_wav.cpp index 24bb02c5..d7bc4881 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() From 1fa677e2ef4984941531e62f6023578ab3cfd159 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 29 Nov 2015 01:57:15 +0900 Subject: [PATCH 12/12] Add some tests about splitting/merging Ogg pages. --- tests/test_ogg.cpp | 15 +++++++++++++ tests/test_oggflac.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ tests/test_opus.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ tests/test_speex.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index 0fc7cfef..6a671d48 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -59,16 +59,31 @@ public: { Vorbis::File f(newname.c_str()); CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL(136383L, f.length()); CPPUNIT_ASSERT_EQUAL(19, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(30U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(131127U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(3832U, f.packet(2).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(); } { Vorbis::File f(newname.c_str()); CPPUNIT_ASSERT(f.isValid()); + CPPUNIT_ASSERT_EQUAL(4370L, f.length()); CPPUNIT_ASSERT_EQUAL(3, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(30U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(60U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(3832U, f.packet(2).size()); CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); } } diff --git a/tests/test_oggflac.cpp b/tests/test_oggflac.cpp index e0f5bb16..737a7261 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: @@ -45,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(141141L, f.length()); + CPPUNIT_ASSERT_EQUAL(21, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(51U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(131126U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(22U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(8196U, 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(9128L, f.length()); + CPPUNIT_ASSERT_EQUAL(5, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(51U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(59U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(22U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(8196U, 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 398e7e91..3113e55f 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: @@ -61,6 +63,53 @@ public: } } + 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(167534L, f.length()); + CPPUNIT_ASSERT_EQUAL(27, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(19U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(131380U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(5U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(5U, 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(35521L, f.length()); + CPPUNIT_ASSERT_EQUAL(11, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(19U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(313U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(5U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(5U, f.packet(3).size()); + CPPUNIT_ASSERT_EQUAL(String("ABCDE"), f.tag()->title()); + + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(7737, f.audioProperties()->lengthInMilliseconds()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestOpus); diff --git a/tests/test_speex.cpp b/tests/test_speex.cpp index 577adb3e..258795ab 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(156330L, f.length()); + CPPUNIT_ASSERT_EQUAL(23, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(80U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(131116U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(93U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(93U, 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(24317L, f.length()); + CPPUNIT_ASSERT_EQUAL(7, f.lastPageHeader()->pageSequenceNumber()); + CPPUNIT_ASSERT_EQUAL(80U, f.packet(0).size()); + CPPUNIT_ASSERT_EQUAL(49U, f.packet(1).size()); + CPPUNIT_ASSERT_EQUAL(93U, f.packet(2).size()); + CPPUNIT_ASSERT_EQUAL(93U, 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);