diff --git a/.editorconfig b/.editorconfig index 32b8a7df..f16a353f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,12 +8,12 @@ root = true insert_final_newline = true # 2 space indentation -[*.{h,cpp,tcc,cmake}] +[*.{h,cpp,tcc,cmake,yml}] indent_style = space indent_size = 2 # Trim traling whitespaces -[*.{h,cpp,tcc,cmake}] +[*.{h,cpp,tcc,cmake,yml}] trim_trailing_whitespace = true # UTF-8 without BOM diff --git a/.travis.yml b/.travis.yml index c5ec8862..d724ae9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,28 @@ language: cpp + sudo: false + +os: + - linux + - osx + compiler: - gcc - clang + addons: apt: packages: - - libcppunit-dev + - libcppunit-dev - zlib1g-dev + +matrix: + exclude: + - os: osx + compiler: gcc + +install: + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install cppunit; fi + script: cmake -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON -DBUILD_BINDINGS=ON . && make && make check diff --git a/AUTHORS b/AUTHORS index 6f4c983c..e2b73429 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,6 +2,8 @@ Scott Wheeler Author, maintainer Lukas Lalinsky Implementation of multiple new file formats, many bug fixes, maintainer +Tsuda Kageyu + A lot of bug fixes and performance improvements, maintainer. Ismael Orenstein Xing header implementation Allan Sandfeld Jensen @@ -10,8 +12,6 @@ Teemu Tervo Numerous bug reports and fixes Mathias Panzenböck Mod, S3M, IT and XM metadata implementations -Tsuda Kageyu - A lot of fixes and improvements, i.e. memory copy reduction, large files support, etc. Please send all patches and questions to taglib-devel@kde.org rather than to individual developers! diff --git a/CMakeLists.txt b/CMakeLists.txt index 6294f5fd..f210a565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ -project(taglib) - cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR) +project(taglib) + if(NOT ${CMAKE_VERSION} VERSION_LESS 2.8.12) cmake_policy(SET CMP0022 OLD) endif() @@ -12,6 +12,7 @@ if(DEFINED ENABLE_STATIC) message(FATAL_ERROR "This option is no longer available, use BUILD_SHARED_LIBS instead") endif() +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) if(NOT BUILD_SHARED_LIBS) add_definitions(-DTAGLIB_STATIC) endif() @@ -89,9 +90,9 @@ endif() # 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. -set(TAGLIB_SOVERSION_CURRENT 17) +set(TAGLIB_SOVERSION_CURRENT 18) set(TAGLIB_SOVERSION_REVISION 0) -set(TAGLIB_SOVERSION_AGE 16) +set(TAGLIB_SOVERSION_AGE 17) math(EXPR TAGLIB_SOVERSION_MAJOR "${TAGLIB_SOVERSION_CURRENT} - ${TAGLIB_SOVERSION_AGE}") math(EXPR TAGLIB_SOVERSION_MINOR "${TAGLIB_SOVERSION_AGE}") diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 93815cba..4654b6a9 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -45,6 +45,13 @@ if(NOT WIN32) endif() endif() +# Enable check_cxx_source_compiles() to work with Boost "header-only" libraries. + +find_package(Boost) +if(Boost_FOUND) + set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${Boost_INCLUDE_DIRS}") +endif() + # Determine which kind of atomic operations your compiler supports. check_cxx_source_compiles(" @@ -58,15 +65,12 @@ check_cxx_source_compiles(" " HAVE_STD_ATOMIC) if(NOT HAVE_STD_ATOMIC) - check_cxx_source_compiles(" - #include - int main() { - boost::atomic x(1); - x.fetch_add(1); - x.fetch_sub(1); - return 0; - } - " HAVE_BOOST_ATOMIC) + find_package(Boost COMPONENTS atomic) + if(Boost_ATOMIC_FOUND) + set(HAVE_BOOST_ATOMIC 1) + else() + set(HAVE_BOOST_ATOMIC 0) + endif() if(NOT HAVE_BOOST_ATOMIC) check_cxx_source_compiles(" @@ -255,6 +259,15 @@ if(NOT ZLIB_SOURCE) else() set(HAVE_ZLIB 0) endif() + + if(NOT HAVE_ZLIB) + find_package(Boost COMPONENTS iostreams zlib) + if(Boost_IOSTREAMS_FOUND AND Boost_ZLIB_FOUND) + set(HAVE_BOOST_ZLIB 1) + else() + set(HAVE_BOOST_ZLIB 0) + endif() + endif() endif() # Determine whether CppUnit is installed. diff --git a/NEWS b/NEWS index 787f2d3b..88e859a0 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,29 @@ -TagLib 1.11 (Jan 30, 2016) +============================ + + * Added support for WinRT. + +TagLib 1.11.1 (Oct 24, 2016) +============================ + + * Fixed binary incompatible change in TagLib::String. + * Fixed reading ID3v2 CTOC frames with a lot of entries. + * Fixed seeking ByteVectorStream from the end. + +TagLib 1.11 (Apr 29, 2016) ========================== +1.11: + + * Fixed reading APE items with long keys. + * Fixed reading ID3v2 SYLT frames when description is empty. + +1.11 BETA 2: + * Better handling of PCM WAV files with a 'fact' chunk. * Better handling of corrupted APE tags. + * Efficient decoding of unsynchronized ID3v2 frames. + * Fixed text encoding when saving certain frames in ID3v2.3 tags. + * Fixed updating the size of RIFF files when removing chunks. * Several smaller bug fixes and performance improvements. 1.11 BETA: @@ -34,7 +55,7 @@ TagLib 1.11 (Jan 30, 2016) * Fixed updating the comment field of Vorbis comments. * Fixed reading date and time in ID3v2.3 tags. * Marked ByteVector::null and ByteVector::isNull() deprecated. - * Marked String::null and ByteVector::isNull() deprecated. + * Marked String::null and String::isNull() deprecated. * Marked XiphComment::removeField() deprecated. * Marked Ogg::Page::getCopyWithNewPageSequenceNumber() deprecated. It returns null. * Marked custom integer types deprecated. diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index b6ee7bc8..bd3dffa7 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -50,7 +50,7 @@ namespace bool unicodeStrings = true; bool stringManagementEnabled = true; - inline char *stringToCharArray(const String &s) + char *stringToCharArray(const String &s) { const std::string str = s.to8Bit(unicodeStrings); @@ -65,7 +65,7 @@ namespace #endif } - inline String charArrayToString(const char *s) + String charArrayToString(const char *s) { return String(s, unicodeStrings ? String::UTF8 : String::Latin1); } diff --git a/bindings/c/tag_c.h b/bindings/c/tag_c.h index 2e8b752f..8d5f85ff 100644 --- a/bindings/c/tag_c.h +++ b/bindings/c/tag_c.h @@ -124,7 +124,7 @@ TAGLIB_C_EXPORT TagLib_File *taglib_file_new_type(const char *filename, TagLib_F TAGLIB_C_EXPORT void taglib_file_free(TagLib_File *file); /*! - * Returns true if the file is open and readble and valid information for + * Returns true if the file is open and readable and valid information for * the Tag and / or AudioProperties was found. */ @@ -137,7 +137,7 @@ TAGLIB_C_EXPORT BOOL taglib_file_is_valid(const TagLib_File *file); TAGLIB_C_EXPORT TagLib_Tag *taglib_file_tag(const TagLib_File *file); /*! - * Returns a pointer to the the audio properties associated with this file. This + * Returns a pointer to the audio properties associated with this file. This * will be freed automatically when the file is freed. */ TAGLIB_C_EXPORT const TagLib_AudioProperties *taglib_file_audioproperties(const TagLib_File *file); diff --git a/config.h.cmake b/config.h.cmake index bd8763c5..ed29dc6b 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -34,6 +34,7 @@ /* Defined if zlib is installed */ #cmakedefine HAVE_ZLIB 1 +#cmakedefine HAVE_BOOST_ZLIB 1 /* Indicates whether debug messages are shown even in release mode */ #cmakedefine TRACE_IN_RELEASE 1 diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 361b8a79..5eac169f 100644 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -35,6 +35,10 @@ elseif(HAVE_ZLIB_SOURCE) include_directories(${ZLIB_SOURCE}) endif() +if(HAVE_BOOST_BYTESWAP OR HAVE_BOOST_ATOMIC OR HAVE_BOOST_ZLIB) + include_directories(${Boost_INCLUDE_DIR}) +endif() + set(tag_HDRS tag.h fileref.h @@ -337,6 +341,7 @@ set(toolkit_SRCS toolkit/tpropertymap.cpp toolkit/trefcounter.cpp toolkit/tdebuglistener.cpp + toolkit/tzlib.cpp ) if(NOT WIN32) @@ -376,6 +381,14 @@ if(ZLIB_FOUND) target_link_libraries(tag ${ZLIB_LIBRARIES}) endif() +if(HAVE_BOOST_ATOMIC) + target_link_libraries(tag ${Boost_ATOMIC_LIBRARY}) +endif() + +if(HAVE_BOOST_ZLIB) + target_link_libraries(tag ${Boost_IOSTREAMS_LIBRARY} ${Boost_ZLIB_LIBRARY}) +endif() + set_target_properties(tag PROPERTIES VERSION ${TAGLIB_SOVERSION_MAJOR}.${TAGLIB_SOVERSION_MINOR}.${TAGLIB_SOVERSION_PATCH} SOVERSION ${TAGLIB_SOVERSION_MAJOR} diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index 64dbb487..9fa6115b 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -126,7 +126,7 @@ unsigned int APE::AudioProperties::sampleFrames() const namespace { - inline int headerVersion(const ByteVector &header) + int headerVersion(const ByteVector &header) { if(header.size() < 6 || !header.startsWith("MAC ")) return -1; diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index a8c181bf..62de4a89 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -48,11 +48,11 @@ using namespace APE; namespace { - inline bool isKeyValid(const char *key, size_t length) + bool isKeyValid(const char *key, size_t length) { const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 }; - if(length < 2 || length > 16) + if(length < 2 || length > 255) return false; // only allow printable ASCII including space (32..126) diff --git a/taglib/asf/asfutils.h b/taglib/asf/asfutils.h index 9cc51caa..29b0c0fb 100644 --- a/taglib/asf/asfutils.h +++ b/taglib/asf/asfutils.h @@ -34,65 +34,68 @@ namespace TagLib { namespace ASF { - - inline unsigned short readWORD(File *file, bool *ok = 0) + namespace { - const ByteVector v = file->readBlock(2); - if(v.size() != 2) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toUInt16LE(0); - } - inline unsigned int readDWORD(File *file, bool *ok = 0) - { - const ByteVector v = file->readBlock(4); - if(v.size() != 4) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toUInt32LE(0); - } - - inline long long readQWORD(File *file, bool *ok = 0) - { - const ByteVector v = file->readBlock(8); - if(v.size() != 8) { - if(ok) *ok = false; - return 0; - } - if(ok) *ok = true; - return v.toInt64LE(0); - } - - inline String readString(File *file, int length) - { - ByteVector data = file->readBlock(length); - size_t size = data.size(); - while(size >= 2) { - if(data[size - 1] != '\0' || data[size - 2] != '\0') { - break; + inline unsigned short readWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(2); + if(v.size() != 2) { + if(ok) *ok = false; + return 0; } - size -= 2; + if(ok) *ok = true; + return v.toUInt16LE(0); } - if(size != data.size()) { - data.resize(size); - } - return String(data, String::UTF16LE); - } - inline ByteVector renderString(const String &str, bool includeLength = false) - { - ByteVector data = str.data(String::UTF16LE) + ByteVector::fromUInt16LE(0); - if(includeLength) { - data = ByteVector::fromUInt16LE(data.size()) + data; + inline unsigned int readDWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(4); + if(v.size() != 4) { + if(ok) *ok = false; + return 0; + } + if(ok) *ok = true; + return v.toUInt32LE(0); } - return data; - } + inline long long readQWORD(File *file, bool *ok = 0) + { + const ByteVector v = file->readBlock(8); + if(v.size() != 8) { + if(ok) *ok = false; + return 0; + } + if(ok) *ok = true; + return v.toInt64LE(0); + } + + inline String readString(File *file, int length) + { + ByteVector data = file->readBlock(length); + unsigned int size = data.size(); + while (size >= 2) { + if(data[size - 1] != '\0' || data[size - 2] != '\0') { + break; + } + size -= 2; + } + if(size != data.size()) { + data.resize(size); + } + return String(data, String::UTF16LE); + } + + inline ByteVector renderString(const String &str, bool includeLength = false) + { + ByteVector data = str.data(String::UTF16LE) + ByteVector::fromUInt16LE(0); + if(includeLength) { + data = ByteVector::fromUInt16LE(data.size()) + data; + } + return data; + } + + } } } diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 9d33c83d..938f68b2 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -63,42 +63,42 @@ namespace // Templatized internal functions. T should be String or IOStream*. template - inline FileName toFileName(T arg) + FileName toFileName(T arg) { debug("FileRef::toFileName(): This version should never be called."); return FileName(L""); } template <> - inline FileName toFileName(IOStream *arg) + FileName toFileName(IOStream *arg) { return arg->name(); } template <> - inline FileName toFileName(FileName arg) + FileName toFileName(FileName arg) { return arg; } template - inline File *resolveFileType(T arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(T arg, bool readProperties, + AudioProperties::ReadStyle style) { debug("FileRef::resolveFileType(): This version should never be called."); return 0; } template <> - inline File *resolveFileType(IOStream *arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(IOStream *arg, bool readProperties, + AudioProperties::ReadStyle style) { return 0; } template <> - inline File *resolveFileType(FileName arg, bool readProperties, - AudioProperties::ReadStyle style) + File *resolveFileType(FileName arg, bool readProperties, + AudioProperties::ReadStyle style) { ResolverList::ConstIterator it = fileTypeResolvers.begin(); for(; it != fileTypeResolvers.end(); ++it) { diff --git a/taglib/fileref.h b/taglib/fileref.h index 71126aba..3ae58615 100644 --- a/taglib/fileref.h +++ b/taglib/fileref.h @@ -129,13 +129,16 @@ namespace TagLib { audioPropertiesStyle = AudioProperties::Average); /*! - * Construct a FileRef from an opened \a IOStream. If \a readAudioProperties is true then - * the audio properties will be read using \a audioPropertiesStyle. If - * \a readAudioProperties is false then \a audioPropertiesStyle will be + * Construct a FileRef from an opened \a IOStream. If \a readAudioProperties + * is true then the audio properties will be read using \a audioPropertiesStyle. + * If \a readAudioProperties is false then \a audioPropertiesStyle will be * ignored. * * Also see the note in the class documentation about why you may not want to * use this method in your application. + * + * \note TagLib will *not* take ownership of the stream, the caller is + * responsible for deleting it after the File object. */ explicit FileRef(IOStream* stream, bool readAudioProperties = true, diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index 65c92d3d..8ef72ac4 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "tstringlist.h" #include "itfile.h" #include "tdebug.h" diff --git a/taglib/it/itproperties.cpp b/taglib/it/itproperties.cpp index 03fac64e..82840e8a 100644 --- a/taglib/it/itproperties.cpp +++ b/taglib/it/itproperties.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "itproperties.h" using namespace TagLib; diff --git a/taglib/it/itproperties.h b/taglib/it/itproperties.h index 93d855b5..38edc7c3 100644 --- a/taglib/it/itproperties.h +++ b/taglib/it/itproperties.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_ITPROPERTIES_H diff --git a/taglib/mod/modfile.cpp b/taglib/mod/modfile.cpp index fd89b296..395bb4ae 100644 --- a/taglib/mod/modfile.cpp +++ b/taglib/mod/modfile.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "modfile.h" #include "tstringlist.h" #include "tdebug.h" diff --git a/taglib/mod/modfile.h b/taglib/mod/modfile.h index 9164ece5..ac28ba05 100644 --- a/taglib/mod/modfile.h +++ b/taglib/mod/modfile.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_MODFILE_H diff --git a/taglib/mod/modfilebase.cpp b/taglib/mod/modfilebase.cpp index cf5a5324..d59fa3e4 100644 --- a/taglib/mod/modfilebase.cpp +++ b/taglib/mod/modfilebase.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "tdebug.h" #include "modfilebase.h" @@ -48,7 +53,7 @@ bool Mod::FileBase::readString(String &s, unsigned int size) if(index != ByteVector::npos()) { data.resize(index); } - data.replace((char) 0xff, ' '); + data.replace('\xff', ' '); s = data; return true; diff --git a/taglib/mod/modfilebase.h b/taglib/mod/modfilebase.h index 039d3d8a..fabdbca8 100644 --- a/taglib/mod/modfilebase.h +++ b/taglib/mod/modfilebase.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_MODFILEBASE_H diff --git a/taglib/mod/modproperties.cpp b/taglib/mod/modproperties.cpp index 8c5cb149..8acfe5b8 100644 --- a/taglib/mod/modproperties.cpp +++ b/taglib/mod/modproperties.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "modproperties.h" using namespace TagLib; diff --git a/taglib/mod/modproperties.h b/taglib/mod/modproperties.h index 7b1fe70c..a5edd1f8 100644 --- a/taglib/mod/modproperties.h +++ b/taglib/mod/modproperties.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_MODPROPERTIES_H diff --git a/taglib/mod/modtag.cpp b/taglib/mod/modtag.cpp index 8ba23543..4ffbc194 100644 --- a/taglib/mod/modtag.cpp +++ b/taglib/mod/modtag.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "modtag.h" #include "tstringlist.h" #include "tpropertymap.h" diff --git a/taglib/mod/modtag.h b/taglib/mod/modtag.h index 60b363cf..bcdb2871 100644 --- a/taglib/mod/modtag.h +++ b/taglib/mod/modtag.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_MODTAG_H @@ -50,39 +54,39 @@ namespace TagLib { * Returns the track name; if no track name is present in the tag * String::null will be returned. */ - String title() const; + virtual String title() const; /*! * Not supported by module files. Therefore always returns String::null. */ - String artist() const; + virtual String artist() const; /*! * Not supported by module files. Therefore always returns String::null. */ - String album() const; + virtual String album() const; /*! * Returns the track comment derived from the instrument/sample/pattern * names; if no comment is present in the tag String::null will be * returned. */ - String comment() const; + virtual String comment() const; /*! * Not supported by module files. Therefore always returns String::null. */ - String genre() const; + virtual String genre() const; /*! * Not supported by module files. Therefore always returns 0. */ - unsigned int year() const; + virtual unsigned int year() const; /*! * Not supported by module files. Therefore always returns 0. */ - unsigned int track() const; + virtual unsigned int track() const; PictureMap pictures() const; @@ -103,17 +107,17 @@ namespace TagLib { * Mod 20 characters, S3M 27 characters, IT 25 characters and XM 20 * characters. */ - void setTitle(const String &title); + virtual void setTitle(const String &title); /*! * Not supported by module files and therefore ignored. */ - void setArtist(const String &artist); + virtual void setArtist(const String &artist); /*! * Not supported by module files and therefore ignored. */ - void setAlbum(const String &album); + virtual void setAlbum(const String &album); /*! * Sets the comment to \a comment. If \a comment is String::null then @@ -132,22 +136,22 @@ namespace TagLib { * Mod 22 characters, S3M 27 characters, IT 25 characters and XM 22 * characters. */ - void setComment(const String &comment); + virtual void setComment(const String &comment); /*! * Not supported by module files and therefore ignored. */ - void setGenre(const String &genre); + virtual void setGenre(const String &genre); /*! * Not supported by module files and therefore ignored. */ - void setYear(unsigned int year); + virtual void setYear(unsigned int year); /*! * Not supported by module files and therefore ignored. */ - void setTrack(unsigned int track); + virtual void setTrack(unsigned int track); void setPictures(const PictureMap &l); diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 2b4b1491..3e19b204 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -23,20 +23,17 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include + #include "mp4atom.h" using namespace TagLib; const char *MP4::Atom::containers[11] = { - "moov", "udta", "mdia", "meta", "ilst", - "stbl", "minf", "moof", "traf", "trak", - "stsd" + "moov", "udta", "mdia", "meta", "ilst", + "stbl", "minf", "moof", "traf", "trak", + "stsd" }; MP4::Atom::Atom(File *file) diff --git a/taglib/mp4/mp4file.cpp b/taglib/mp4/mp4file.cpp index 8a33f8f4..88c4aa21 100644 --- a/taglib/mp4/mp4file.cpp +++ b/taglib/mp4/mp4file.cpp @@ -34,7 +34,7 @@ using namespace TagLib; namespace { - inline bool checkValid(const MP4::AtomList &list) + bool checkValid(const MP4::AtomList &list) { for(MP4::AtomList::ConstIterator it = list.begin(); it != list.end(); ++it) { diff --git a/taglib/mp4/mp4tag.h b/taglib/mp4/mp4tag.h index bfea5334..2652c54d 100644 --- a/taglib/mp4/mp4tag.h +++ b/taglib/mp4/mp4tag.h @@ -50,26 +50,26 @@ namespace TagLib { public: Tag(); Tag(TagLib::File *file, Atoms *atoms); - ~Tag(); + virtual ~Tag(); bool save(); - String title() const; - String artist() const; - String album() const; - String comment() const; - String genre() const; - unsigned int year() const; - unsigned int track() const; - PictureMap pictures() const; + virtual String title() const; + virtual String artist() const; + virtual String album() const; + virtual String comment() const; + virtual String genre() const; + virtual unsigned int year() const; + virtual unsigned int track() const; + virtual PictureMap pictures() const; - void setTitle(const String &value); - void setArtist(const String &value); - void setAlbum(const String &value); - void setComment(const String &value); - void setGenre(const String &value); - void setYear(unsigned int value); - void setTrack(unsigned int value); - void setPictures(const PictureMap &l); + virtual void setTitle(const String &value); + virtual void setArtist(const String &value); + virtual void setAlbum(const String &value); + virtual void setComment(const String &value); + virtual void setGenre(const String &value); + virtual void setYear(unsigned int value); + virtual void setTrack(unsigned int value); + virtual void setPictures(const PictureMap &l); virtual bool isEmpty() const; diff --git a/taglib/mpeg/id3v2/frames/chapterframe.cpp b/taglib/mpeg/id3v2/frames/chapterframe.cpp index eabf5d38..3f56dca3 100644 --- a/taglib/mpeg/id3v2/frames/chapterframe.cpp +++ b/taglib/mpeg/id3v2/frames/chapterframe.cpp @@ -198,7 +198,7 @@ String ChapterFrame::toString() const s += ", start offset: " + String::number(d->startOffset); if(d->endOffset != 0xFFFFFFFF) - s += ", start offset: " + String::number(d->endOffset); + s += ", end offset: " + String::number(d->endOffset); if(!d->embeddedFrameList.isEmpty()) { StringList frameIDs; diff --git a/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp b/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp index f816bb9f..ac711181 100644 --- a/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp +++ b/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp @@ -1,6 +1,7 @@ /*************************************************************************** copyright : (C) 2002 - 2008 by Scott Wheeler email : wheeler@kde.org + copyright : (C) 2006 by Aaron VonderHaar email : avh4@users.sourceforge.net ***************************************************************************/ @@ -26,6 +27,7 @@ ***************************************************************************/ #include +#include #include "generalencapsulatedobjectframe.h" @@ -151,15 +153,21 @@ void GeneralEncapsulatedObjectFrame::parseFields(const ByteVector &data) ByteVector GeneralEncapsulatedObjectFrame::renderFields() const { + StringList sl; + sl.append(d->fileName); + sl.append(d->description); + + const String::Type encoding = checkTextEncoding(sl, d->textEncoding); + ByteVector data; - data.append(char(d->textEncoding)); + data.append(char(encoding)); data.append(d->mimeType.data(String::Latin1)); data.append(textDelimiter(String::Latin1)); - data.append(d->fileName.data(d->textEncoding)); - data.append(textDelimiter(d->textEncoding)); - data.append(d->description.data(d->textEncoding)); - data.append(textDelimiter(d->textEncoding)); + data.append(d->fileName.data(encoding)); + data.append(textDelimiter(encoding)); + data.append(d->description.data(encoding)); + data.append(textDelimiter(encoding)); data.append(d->data); return data; diff --git a/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.h b/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.h index 42f854cc..769dfb02 100644 --- a/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.h +++ b/taglib/mpeg/id3v2/frames/generalencapsulatedobjectframe.h @@ -1,6 +1,7 @@ /*************************************************************************** copyright : (C) 2002 - 2008 by Scott Wheeler email : wheeler@kde.org + copyright : (C) 2006 by Aaron VonderHaar email : avh4@users.sourceforge.net ***************************************************************************/ diff --git a/taglib/mpeg/id3v2/frames/ownershipframe.cpp b/taglib/mpeg/id3v2/frames/ownershipframe.cpp index e61cb0d6..15ef6ade 100644 --- a/taglib/mpeg/id3v2/frames/ownershipframe.cpp +++ b/taglib/mpeg/id3v2/frames/ownershipframe.cpp @@ -24,9 +24,10 @@ ***************************************************************************/ #include +#include +#include #include "ownershipframe.h" -#include using namespace TagLib; using namespace ID3v2; @@ -113,24 +114,24 @@ void OwnershipFrame::setTextEncoding(String::Type encoding) void OwnershipFrame::parseFields(const ByteVector &data) { size_t pos = 0; - + // Get the text encoding d->textEncoding = String::Type(data[0]); pos += 1; - + // Read the price paid this is a null terminate string d->pricePaid = readStringField(data, String::Latin1, pos); - + // If we don't have at least 8 bytes left then don't parse the rest of the // data if(data.size() - pos < 8) { return; } - + // Read the date purchased YYYYMMDD d->datePurchased = String(data.mid(pos, 8)); pos += 8; - + // Read the seller if(d->textEncoding == String::Latin1) d->seller = Tag::latin1StringHandler()->parse(data.mid(pos)); @@ -140,14 +141,19 @@ void OwnershipFrame::parseFields(const ByteVector &data) ByteVector OwnershipFrame::renderFields() const { + StringList sl; + sl.append(d->seller); + + const String::Type encoding = checkTextEncoding(sl, d->textEncoding); + ByteVector v; - - v.append(char(d->textEncoding)); + + v.append(char(encoding)); v.append(d->pricePaid.data(String::Latin1)); v.append(textDelimiter(String::Latin1)); v.append(d->datePurchased.data(String::Latin1)); - v.append(d->seller.data(d->textEncoding)); - + v.append(d->seller.data(encoding)); + return v; } diff --git a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp index ad31faf6..bbd7092a 100644 --- a/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp +++ b/taglib/mpeg/id3v2/frames/synchronizedlyricsframe.cpp @@ -158,7 +158,7 @@ void SynchronizedLyricsFrame::parseFields(const ByteVector &data) size_t pos = 6; d->description = readStringField(data, d->textEncoding, pos); - if(d->description.isEmpty()) + if(pos == 6) return; /* diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index 20298912..6eaabaad 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -272,9 +272,9 @@ void TableOfContentsFrame::parseFields(const ByteVector &data) size_t pos = 0; size_t embPos = 0; d->elementID = readStringField(data, String::Latin1, pos).data(String::Latin1); - d->isTopLevel = (data.at(pos) & 2) > 0; - d->isOrdered = (data.at(pos++) & 1) > 0; - unsigned int entryCount = data.at(pos++); + d->isTopLevel = (data.at(pos) & 2) != 0; + d->isOrdered = (data.at(pos++) & 1) != 0; + unsigned int entryCount = static_cast(data.at(pos++)); for(unsigned int i = 0; i < entryCount; i++) { ByteVector childElementID = readStringField(data, String::Latin1, pos).data(String::Latin1); d->childElements.append(childElementID); diff --git a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp index f97cdc5a..3d610c9a 100644 --- a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp +++ b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp @@ -1,6 +1,7 @@ /*************************************************************************** copyright : (C) 2002 - 2008 by Scott Wheeler email : wheeler@kde.org + copyright : (C) 2006 by Urs Fleisch email : ufleisch@users.sourceforge.net ***************************************************************************/ @@ -168,13 +169,19 @@ void UnsynchronizedLyricsFrame::parseFields(const ByteVector &data) ByteVector UnsynchronizedLyricsFrame::renderFields() const { + StringList sl; + sl.append(d->description); + sl.append(d->text); + + const String::Type encoding = checkTextEncoding(sl, d->textEncoding); + ByteVector v; - v.append(char(d->textEncoding)); + v.append(char(encoding)); v.append(d->language.size() == 3 ? d->language : "XXX"); - v.append(d->description.data(d->textEncoding)); - v.append(textDelimiter(d->textEncoding)); - v.append(d->text.data(d->textEncoding)); + v.append(d->description.data(encoding)); + v.append(textDelimiter(encoding)); + v.append(d->text.data(encoding)); return v; } diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 7852d103..dfd8013d 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -1,6 +1,7 @@ /*************************************************************************** copyright : (C) 2002 - 2008 by Scott Wheeler email : wheeler@kde.org + copyright : (C) 2006 by Urs Fleisch email : ufleisch@users.sourceforge.net ***************************************************************************/ diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.h b/taglib/mpeg/id3v2/frames/urllinkframe.h index 7ac966b2..d9ac1093 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.h +++ b/taglib/mpeg/id3v2/frames/urllinkframe.h @@ -1,6 +1,7 @@ /*************************************************************************** copyright : (C) 2002 - 2008 by Scott Wheeler email : wheeler@kde.org + copyright : (C) 2006 by Urs Fleisch email : ufleisch@users.sourceforge.net ***************************************************************************/ diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index 8bb3035b..e6dbe822 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -23,22 +23,16 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - -#if HAVE_ZLIB -#include -#endif - #include #include #include +#include #include "id3v2tag.h" #include "id3v2frame.h" #include "id3v2synchdata.h" + #include "tpropertymap.h" #include "frames/textidentificationframe.h" #include "frames/urllinkframe.h" @@ -97,10 +91,10 @@ unsigned int Frame::headerSize(unsigned int version) ByteVector Frame::textDelimiter(String::Type t) { - ByteVector d = char(0); if(t == String::UTF16 || t == String::UTF16BE || t == String::UTF16LE) - d.append(char(0)); - return d; + return ByteVector(2, '\0'); + else + return ByteVector(1, '\0'); } const String Frame::instrumentPrefix("PERFORMER:"); @@ -251,60 +245,21 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const frameDataOffset += 4; } -#if HAVE_ZLIB - if(d->header->compression() && - !d->header->encryption()) - { + if(zlib::isAvailable() && d->header->compression() && !d->header->encryption()) { if(frameData.size() <= frameDataOffset) { debug("Compressed frame doesn't have enough data to decode"); return ByteVector(); } - z_stream stream = {}; - - if(inflateInit(&stream) != Z_OK) - return ByteVector(); - - ByteVector inData = frameData; - - stream.avail_in = static_cast(inData.size() - frameDataOffset); - stream.next_in = reinterpret_cast(inData.data() + frameDataOffset); - - static const size_t chunkSize = 1024; - - ByteVector outData; - ByteVector chunk(chunkSize); - - do { - stream.avail_out = static_cast(chunk.size()); - stream.next_out = reinterpret_cast(chunk.data()); - - int result = inflate(&stream, Z_NO_FLUSH); - - if(result == Z_STREAM_ERROR || - result == Z_NEED_DICT || - result == Z_DATA_ERROR || - result == Z_MEM_ERROR) - { - if(result != Z_STREAM_ERROR) - inflateEnd(&stream); - debug("Error reading compressed stream"); - return ByteVector(); - } - - outData.append(stream.avail_out == 0 ? chunk : chunk.mid(0, chunk.size() - stream.avail_out)); - } while(stream.avail_out == 0); - - inflateEnd(&stream); - - if(frameDataLength != outData.size()) + const ByteVector outData = zlib::decompress(frameData.mid(frameDataOffset)); + if(!outData.isEmpty() && frameDataLength != outData.size()) { debug("frameDataLength does not match the data length returned by zlib"); + } return outData; } - else -#endif - return frameData.mid(frameDataOffset, frameDataLength); + + return frameData.mid(frameDataOffset, frameDataLength); } String Frame::readStringField(const ByteVector &data, String::Type encoding, size_t &position) diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index e5985a7f..f2987ef4 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -23,11 +23,8 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - #include +#include #include "id3v2framefactory.h" #include "id3v2synchdata.h" @@ -105,13 +102,14 @@ public: } }; +FrameFactory FrameFactory::factory; + //////////////////////////////////////////////////////////////////////////////// // public members //////////////////////////////////////////////////////////////////////////////// FrameFactory *FrameFactory::instance() { - static FrameFactory factory; return &factory; } @@ -162,12 +160,11 @@ Frame *FrameFactory::createFrame(const ByteVector &origData, const Header *tagHe // TagLib doesn't mess with encrypted frames, so just treat them // as unknown frames. -#if !defined(HAVE_ZLIB) || HAVE_ZLIB == 0 - if(header->compression()) { + if(!zlib::isAvailable() && header->compression()) { debug("Compressed frames are currently not supported."); return new UnknownFrame(data, header); } -#endif + if(header->encryption()) { debug("Encrypted frames are currently not supported."); return new UnknownFrame(data, header); @@ -530,4 +527,3 @@ bool FrameFactory::updateFrame(Frame::Header *header) const return true; } - diff --git a/taglib/mpeg/id3v2/id3v2framefactory.h b/taglib/mpeg/id3v2/id3v2framefactory.h index 53e64910..8699b828 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.h +++ b/taglib/mpeg/id3v2/id3v2framefactory.h @@ -66,7 +66,6 @@ namespace TagLib { { public: static FrameFactory *instance(); - /*! * Create a frame based on \a data. \a tagHeader should be a valid * ID3v2::Header instance. @@ -132,6 +131,8 @@ namespace TagLib { FrameFactory(const FrameFactory &); FrameFactory &operator=(const FrameFactory &); + static FrameFactory factory; + class FrameFactoryPrivate; FrameFactoryPrivate *d; }; diff --git a/taglib/mpeg/id3v2/id3v2synchdata.cpp b/taglib/mpeg/id3v2/id3v2synchdata.cpp index 8f81aafe..50d5b01a 100644 --- a/taglib/mpeg/id3v2/id3v2synchdata.cpp +++ b/taglib/mpeg/id3v2/id3v2synchdata.cpp @@ -74,11 +74,25 @@ ByteVector SynchData::fromUInt(unsigned int value) ByteVector SynchData::decode(const ByteVector &data) { - ByteVector result = data; + // We have this optimized method instead of using ByteVector::replace(), + // since it makes a great difference when decoding huge unsynchronized frames. - ByteVector pattern(2, char(0)); - pattern[0] = '\xFF'; - pattern[1] = '\x00'; + ByteVector result(data.size()); - return result.replace(pattern, '\xFF'); + ByteVector::ConstIterator src = data.begin(); + ByteVector::Iterator dst = result.begin(); + + while(src < data.end() - 1) { + *dst++ = *src++; + + if(*(src - 1) == '\xff' && *src == '\x00') + src++; + } + + if(src < data.end()) + *dst++ = *src++; + + result.resize(static_cast(dst - result.begin())); + + return result; } diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 2f21fe5a..3424095c 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -23,10 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include #include @@ -650,7 +646,7 @@ ByteVector ID3v2::Tag::render() const void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const { -#ifdef NO_ITUNES_HACKS +#ifdef NO_ITUNES_HACKS const char *unsupportedFrames[] = { "ASPI", "EQU2", "RVA2", "SEEK", "SIGN", "TDRL", "TDTG", "TMOO", "TPRO", "TSOA", "TSOT", "TSST", "TSOP", 0 diff --git a/taglib/mpeg/mpegutils.h b/taglib/mpeg/mpegutils.h index 5a7e0e6a..e35f752f 100644 --- a/taglib/mpeg/mpegutils.h +++ b/taglib/mpeg/mpegutils.h @@ -34,25 +34,27 @@ namespace TagLib { namespace MPEG { - - /*! - * MPEG frames can be recognized by the bit pattern 11111111 111, so the - * first byte is easy to check for, however checking to see if the second byte - * starts with \e 111 is a bit more tricky, hence these functions. - */ - - inline bool firstSyncByte(unsigned char byte) + namespace { - return (byte == 0xFF); + + /*! + * MPEG frames can be recognized by the bit pattern 11111111 111, so the + * first byte is easy to check for, however checking to see if the second byte + * starts with \e 111 is a bit more tricky, hence these functions. + */ + inline bool firstSyncByte(unsigned char byte) + { + return (byte == 0xFF); + } + + inline bool secondSynchByte(unsigned char byte) + { + // 0xFF is possible in theory, but it's very unlikely be a header. + + return (byte != 0xFF && ((byte & 0xE0) == 0xE0)); + } + } - - inline bool secondSynchByte(unsigned char byte) - { - // 0xFF is possible in theory, but it's very unlikely be a header. - - return (byte != 0xFF && ((byte & 0xE0) == 0xE0)); - } - } } diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index ea78f25e..1c6d2182 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -37,7 +37,7 @@ using namespace TagLib; namespace { // Returns the first packet index of the right next page to the given one. - inline unsigned int nextPacketIndex(const Ogg::Page *page) + unsigned int nextPacketIndex(const Ogg::Page *page) { if(page->header()->lastPacketCompleted()) return page->firstPacketIndex() + page->packetCount(); @@ -262,12 +262,13 @@ void Ogg::File::writePacket(unsigned int i, const ByteVector &packet) // TODO: This pagination method isn't accurate for what's being done here. // This should account for real possibilities like non-aligned packets and such. - const List pages = Page::paginate(packets, - Page::SinglePagePerGroup, - firstPage->header()->streamSerialNumber(), - firstPage->pageSequenceNumber(), - firstPage->header()->firstPacketContinued(), - lastPage->header()->lastPacketCompleted()); + List pages = Page::paginate(packets, + Page::SinglePagePerGroup, + firstPage->header()->streamSerialNumber(), + firstPage->pageSequenceNumber(), + firstPage->header()->firstPacketContinued(), + lastPage->header()->lastPacketCompleted()); + pages.setAutoDelete(true); // Write the pages. diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index e7ffb241..83251109 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -67,11 +67,14 @@ class RIFF::File::FilePrivate public: FilePrivate(ByteOrder endianness) : endianness(endianness), - size(0) {} + size(0), + sizeOffset(0) {} const ByteOrder endianness; unsigned int size; + long long sizeOffset; + std::vector chunks; }; @@ -116,31 +119,50 @@ size_t RIFF::File::chunkCount() const unsigned int RIFF::File::chunkDataSize(unsigned int i) const { + if(i >= d->chunks.size()) { + debug("RIFF::File::chunkPadding() - Index out of range. Returning 0."); + return 0; + } + return d->chunks[i].size; } long long RIFF::File::chunkOffset(unsigned int i) const { + if(i >= d->chunks.size()) { + debug("RIFF::File::chunkPadding() - Index out of range. Returning 0."); + return 0; + } + return d->chunks[i].offset; } unsigned int RIFF::File::chunkPadding(unsigned int i) const { + if(i >= d->chunks.size()) { + debug("RIFF::File::chunkPadding() - Index out of range. Returning 0."); + return 0; + } + return d->chunks[i].padding; } ByteVector RIFF::File::chunkName(unsigned int i) const { - if(i >= chunkCount()) + if(i >= d->chunks.size()) { + debug("RIFF::File::chunkName() - Index out of range. Returning an empty vector."); return ByteVector(); + } return d->chunks[i].name; } ByteVector RIFF::File::chunkData(unsigned int i) { - if(i >= chunkCount()) + if(i >= d->chunks.size()) { + debug("RIFF::File::chunkData() - Index out of range. Returning an empty vector."); return ByteVector(); + } seek(d->chunks[i].offset); return readBlock(d->chunks[i].size); @@ -148,22 +170,33 @@ ByteVector RIFF::File::chunkData(unsigned int i) void RIFF::File::setChunkData(unsigned int i, const ByteVector &data) { - // First we update the global size - - d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding); - insert(fromUInt32(d->size, d->endianness), 4, 4); + if(i >= d->chunks.size()) { + debug("RIFF::File::setChunkData() - Index out of range."); + return; + } // Now update the specific chunk - writeChunk(chunkName(i), data, d->chunks[i].offset - 8, d->chunks[i].size + d->chunks[i].padding + 8); + std::vector::iterator it = d->chunks.begin(); + std::advance(it, i); - d->chunks[i].size = static_cast(data.size()); - d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0; + const long long originalSize = static_cast(it->size) + it->padding; + + writeChunk(it->name, data, it->offset - 8, it->size + it->padding + 8); + + it->size = data.size(); + it->padding = data.size() % 2; + + const long long diff = static_cast(it->size) + it->padding - originalSize; // Now update the internal offsets - for(i++; i < d->chunks.size(); i++) - d->chunks[i].offset = d->chunks[i-1].offset + 8 + d->chunks[i-1].size + d->chunks[i-1].padding; + for(++it; it != d->chunks.end(); ++it) + it->offset += diff; + + // Update the global size. + + updateGlobalSize(); } void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data) @@ -194,45 +227,49 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo // Couldn't find an existing chunk, so let's create a new one. - long long offset = d->chunks.back().offset + d->chunks.back().size; + // Adjust the padding of the last chunk to place the new chunk at even position. - // First we update the global size + Chunk &last = d->chunks.back(); - d->size += static_cast((offset & 1) + data.size() + 8); - if(d->endianness == BigEndian) - insert(ByteVector::fromUInt32BE(d->size), 4, 4); - else - insert(ByteVector::fromUInt32LE(d->size), 4, 4); + long long offset = last.offset + last.size + last.padding; + if(offset & 1) { + if(last.padding == 1) { + last.padding = 0; // This should not happen unless the file is corrupted. + offset--; + removeBlock(offset, 1); + } + else { + insert(ByteVector("\0", 1), offset, 0); + last.padding = 1; + offset++; + } + } - // Now add the chunk to the file + // Now add the chunk to the file. - writeChunk( - name, - data, - offset, - static_cast(std::max(0LL, length() - offset)), - static_cast(offset & 1)); + writeChunk(name, data, offset, 0); // And update our internal structure - if(offset & 1) { - d->chunks.back().padding = 1; - offset++; - } - Chunk chunk; chunk.name = name; - chunk.size = static_cast(data.size()); + chunk.size = data.size(); chunk.offset = offset + 8; - chunk.padding = static_cast(data.size() & 1); + chunk.padding = data.size() % 2; d->chunks.push_back(chunk); + + // Update the global size. + + updateGlobalSize(); } void RIFF::File::removeChunk(unsigned int i) { - if(i >= d->chunks.size()) + if(i >= d->chunks.size()) { + debug("RIFF::File::removeChunk() - Index out of range."); return; + } std::vector::iterator it = d->chunks.begin(); std::advance(it, i); @@ -243,6 +280,10 @@ void RIFF::File::removeChunk(unsigned int i) for(; it != d->chunks.end(); ++it) it->offset -= removeSize; + + // Update the global size. + + updateGlobalSize(); } void RIFF::File::removeChunk(const ByteVector &name) @@ -259,15 +300,20 @@ void RIFF::File::removeChunk(const ByteVector &name) void RIFF::File::read() { - const long long baseOffset = tell(); + long long offset = tell(); - seek(baseOffset + 4); + offset += 4; + d->sizeOffset = offset; + + seek(offset); d->size = toUInt32(readBlock(4), 0, d->endianness); - seek(baseOffset + 12); + offset += 8; // + 8: chunk header at least, fix for additional junk bytes - while(tell() + 8 <= length()) { + while(offset + 8 <= length()) { + + seek(offset); const ByteVector chunkName = readBlock(4); const unsigned int chunkSize = toUInt32(readBlock(4), 0, d->endianness); @@ -277,30 +323,28 @@ void RIFF::File::read() break; } - if(tell() + chunkSize > length()) { + if(offset + 8 + chunkSize > length()) { debug("RIFF::File::read() -- Chunk '" + chunkName + "' has invalid size (larger than the file size)"); setValid(false); break; } Chunk chunk; - chunk.name = chunkName; - chunk.size = chunkSize; - chunk.offset = tell(); - - seek(chunk.size, Current); - - // check padding + chunk.name = chunkName; + chunk.size = chunkSize; + chunk.offset = offset + 8; chunk.padding = 0; - long long uPosNotPadded = tell(); - if(uPosNotPadded & 1) { - ByteVector iByte = readBlock(1); - if((iByte.size() != 1) || (iByte[0] != 0)) { - // not well formed, re-seek - seek(uPosNotPadded, Beginning); - } - else { + + offset = chunk.offset + chunk.size; + + // Check padding + + if(offset & 1) { + seek(offset); + const ByteVector iByte = readBlock(1); + if(iByte.size() == 1 && iByte[0] == '\0') { chunk.padding = 1; + offset++; } } @@ -309,20 +353,26 @@ void RIFF::File::read() } void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data, - long long offset, size_t replace, - unsigned int leadingPadding) + long long offset, size_t replace) { ByteVector combined; - if(leadingPadding) { - combined.append(ByteVector(leadingPadding, '\x00')); - } combined.append(name); combined.append(fromUInt32(data.size(), d->endianness)); combined.append(data); - if((data.size() & 0x01) != 0) { - combined.append('\x00'); - } + if(data.size() & 1) + combined.resize(combined.size() + 1, '\0'); + insert(combined, offset, replace); } + +void RIFF::File::updateGlobalSize() +{ + const Chunk first = d->chunks.front(); + const Chunk last = d->chunks.back(); + d->size = static_cast(last.offset + last.size + last.padding - first.offset + 12); + + const ByteVector data = fromUInt32(d->size, d->endianness); + insert(data, d->sizeOffset, 4); +} diff --git a/taglib/riff/rifffile.h b/taglib/riff/rifffile.h index 5fec8111..efcee4f8 100644 --- a/taglib/riff/rifffile.h +++ b/taglib/riff/rifffile.h @@ -142,8 +142,12 @@ namespace TagLib { void read(); void writeChunk(const ByteVector &name, const ByteVector &data, - long long offset, size_t replace = 0, - unsigned int leadingPadding = 0); + long long offset, size_t replace = 0); + + /*! + * Update the global RIFF size based on the current internal structure. + */ + void updateGlobalSize(); class FilePrivate; FilePrivate *d; diff --git a/taglib/riff/riffutils.h b/taglib/riff/riffutils.h index 14b8508e..ecb985a4 100644 --- a/taglib/riff/riffutils.h +++ b/taglib/riff/riffutils.h @@ -34,18 +34,23 @@ namespace TagLib { namespace RIFF { - inline bool isValidChunkName(const ByteVector &name) + namespace { - if(name.size() != 4) - return false; - for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) { - const int c = static_cast(*it); - if(c < 32 || 127 < c) + inline bool isValidChunkName(const ByteVector &name) + { + if(name.size() != 4) return false; + + for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) { + const int c = static_cast(*it); + if(c < 32 || 127 < c) + return false; + } + + return true; } - return true; } } } diff --git a/taglib/s3m/s3mfile.cpp b/taglib/s3m/s3mfile.cpp index 99f8a095..39bfb107 100644 --- a/taglib/s3m/s3mfile.cpp +++ b/taglib/s3m/s3mfile.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "s3mfile.h" #include "tstringlist.h" #include "tdebug.h" diff --git a/taglib/s3m/s3mfile.h b/taglib/s3m/s3mfile.h index d2d98fea..f89d40c0 100644 --- a/taglib/s3m/s3mfile.h +++ b/taglib/s3m/s3mfile.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_S3MFILE_H diff --git a/taglib/s3m/s3mproperties.cpp b/taglib/s3m/s3mproperties.cpp index 681e7563..03b6dd03 100644 --- a/taglib/s3m/s3mproperties.cpp +++ b/taglib/s3m/s3mproperties.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "s3mproperties.h" using namespace TagLib; diff --git a/taglib/s3m/s3mproperties.h b/taglib/s3m/s3mproperties.h index 67c1fd10..4747331f 100644 --- a/taglib/s3m/s3mproperties.h +++ b/taglib/s3m/s3mproperties.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_S3MPROPERTIES_H diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 7cc3718c..e7666c3b 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -28,7 +28,7 @@ #define TAGLIB_MAJOR_VERSION 1 #define TAGLIB_MINOR_VERSION 11 -#define TAGLIB_PATCH_VERSION 0 +#define TAGLIB_PATCH_VERSION 1 #if (defined(_MSC_VER) && _MSC_VER >= 1600) #define TAGLIB_CONSTRUCT_BITSET(x) static_cast(x) @@ -53,7 +53,9 @@ namespace TagLib LittleEndian, BigEndian }; + class String; + namespace Version { /*! diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 4851fc9f..08fced0d 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -23,10 +23,6 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include @@ -35,10 +31,10 @@ #include #include -#include "tstring.h" -#include "tdebug.h" -#include "tsmartptr.h" -#include "tutils.h" +#include +#include +#include +#include #include "tbytevector.h" @@ -472,18 +468,34 @@ bool ByteVector::endsWith(const ByteVector &pattern) const return containsAt(pattern, size() - pattern.size()); } +ByteVector &ByteVector::replace(char oldByte, char newByte) +{ + detach(); + + for(ByteVector::Iterator it = begin(); it != end(); ++it) { + if(*it == oldByte) + *it = newByte; + } + + return *this; +} + ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &with) { + // TODO: This takes O(n!) time in the worst case. Rewrite it to run in O(n) time. + if(pattern.size() == 0 || pattern.size() > size()) return *this; + if(pattern.size() == 1 && with.size() == 1) + return replace(pattern[0], with[0]); + const size_t withSize = with.size(); const size_t patternSize = pattern.size(); const ptrdiff_t diff = withSize - patternSize; size_t offset = 0; - while (true) - { + while (true) { offset = find(pattern, offset); if(offset == npos()) break; @@ -535,12 +547,16 @@ size_t ByteVector::endsWithPartialMatch(const ByteVector &pattern) const ByteVector &ByteVector::append(const ByteVector &v) { - if(v.d->length != 0) { - detach(); - size_t originalSize = size(); - resize(originalSize + v.size()); - ::memcpy(data() + originalSize, v.data(), v.size()); - } + if(v.isEmpty()) + return *this; + + detach(); + + const size_t originalSize = size(); + const size_t appendSize = v.size(); + + resize(originalSize + appendSize); + ::memcpy(data() + originalSize, v.data(), appendSize); return *this; } diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index 2f0ff9cd..b78fff02 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -178,6 +178,12 @@ namespace TagLib { */ bool endsWith(const ByteVector &pattern) const; + /*! + * Replaces \a oldByte with \a newByte and returns a reference to the + * ByteVector after the operation. This \e does modify the vector. + */ + ByteVector &replace(char oldByte, char newByte); + /*! * Replaces \a pattern with \a with and returns a reference to the ByteVector * after the operation. This \e does modify the vector. diff --git a/taglib/toolkit/tbytevectorstream.cpp b/taglib/toolkit/tbytevectorstream.cpp index 1c87a82d..f75fd5f4 100644 --- a/taglib/toolkit/tbytevectorstream.cpp +++ b/taglib/toolkit/tbytevectorstream.cpp @@ -144,7 +144,7 @@ void ByteVectorStream::seek(long long offset, Position p) d->position += offset; break; case End: - d->position = length() - offset; + d->position = length() + offset; // offset is expected to be negative break; } } diff --git a/taglib/toolkit/tdebug.cpp b/taglib/toolkit/tdebug.cpp index e9387656..a48e1919 100644 --- a/taglib/toolkit/tdebug.cpp +++ b/taglib/toolkit/tdebug.cpp @@ -27,6 +27,8 @@ #include #endif +#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) + #include "tdebug.h" #include "tstring.h" #include "tutils.h" @@ -42,17 +44,11 @@ namespace TagLib void debug(const String &s) { -#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) - debugListener->printMessage("TagLib: " + s + "\n"); - -#endif } void debugData(const ByteVector &v) { -#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) - for(size_t i = 0; i < v.size(); ++i) { std::string bits = std::bitset<8>(v[i]).to_string(); @@ -62,7 +58,7 @@ namespace TagLib debugListener->printMessage(msg); } - -#endif } } + +#endif diff --git a/taglib/toolkit/tdebug.h b/taglib/toolkit/tdebug.h index bd94d159..80d00d39 100644 --- a/taglib/toolkit/tdebug.h +++ b/taglib/toolkit/tdebug.h @@ -32,10 +32,11 @@ namespace TagLib { class ByteVector; #ifndef DO_NOT_DOCUMENT +#if !defined(NDEBUG) || defined(TRACE_IN_RELEASE) /*! - * A simple function that outputs the debug messages to the listener. - * The default listener redirects the messages to \a stderr when NDEBUG is + * A simple function that outputs the debug messages to the listener. + * The default listener redirects the messages to \a stderr when NDEBUG is * not defined. * * \warning Do not use this outside of TagLib, it could lead to undefined @@ -45,7 +46,7 @@ namespace TagLib { * \internal */ void debug(const String &s); - + /*! * For debugging binary data. * @@ -56,6 +57,13 @@ namespace TagLib { * \internal */ void debugData(const ByteVector &v); + +#else + + #define debug(x) ((void)0) + #define debugData(x) ((void)0) + +#endif } #endif diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 205bb083..a1809ca9 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -52,24 +52,28 @@ namespace const FileHandle InvalidFileHandle = INVALID_HANDLE_VALUE; - inline FileHandle openFile(const FileName &path, bool readOnly) + FileHandle openFile(const FileName &path, bool readOnly) { const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE); +#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602) + return CreateFile2(path.toString().toCWString(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL); +#else if(!path.wstr().empty()) return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); else if(!path.str().empty()) return CreateFileA(path.str().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); else return InvalidFileHandle; +#endif } - inline void closeFile(FileHandle file) + void closeFile(FileHandle file) { CloseHandle(file); } - inline size_t readFile(FileHandle file, ByteVector &buffer) + size_t readFile(FileHandle file, ByteVector &buffer) { DWORD length; if(ReadFile(file, buffer.data(), static_cast(buffer.size()), &length, NULL)) @@ -78,7 +82,7 @@ namespace return 0; } - inline size_t writeFile(FileHandle file, const ByteVector &buffer) + size_t writeFile(FileHandle file, const ByteVector &buffer) { DWORD length; if(WriteFile(file, buffer.data(), static_cast(buffer.size()), &length, NULL)) @@ -99,22 +103,22 @@ namespace const FileHandle InvalidFileHandle = 0; - inline FileHandle openFile(const FileName &path, bool readOnly) + FileHandle openFile(const FileName &path, bool readOnly) { return fopen(path, readOnly ? "rb" : "rb+"); } - inline void closeFile(FileHandle file) + void closeFile(FileHandle file) { fclose(file); } - inline size_t readFile(FileHandle file, ByteVector &buffer) + size_t readFile(FileHandle file, ByteVector &buffer) { return fread(buffer.data(), sizeof(char), buffer.size(), file); } - inline size_t writeFile(FileHandle file, const ByteVector &buffer) + size_t writeFile(FileHandle file, const ByteVector &buffer) { return fwrite(buffer.data(), sizeof(char), buffer.size(), file); } @@ -446,13 +450,16 @@ long long FileStream::length() #ifdef _WIN32 - LARGE_INTEGER fileSize; - fileSize.QuadPart = 0; - SetLastError(NO_ERROR); - fileSize.LowPart = GetFileSize(d->file, reinterpret_cast(&fileSize.HighPart)); +#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602) + LARGE_INTEGER fileSize; + GetFileSizeEx(d->file, &fileSize); +#else + ULARGE_INTEGER fileSize; + fileSize.LowPart = GetFileSize(d->file, &fileSize.HighPart); +#endif if(GetLastError() == NO_ERROR) { - return fileSize.QuadPart; + return static_cast(fileSize.QuadPart); } else { debug("FileStream::length() -- Failed to get the file size."); diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 1c6a47d9..b3e1ec3a 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "tpropertymap.h" using namespace TagLib; diff --git a/taglib/toolkit/tpropertymap.h b/taglib/toolkit/tpropertymap.h index c1b835be..5933b89b 100644 --- a/taglib/toolkit/tpropertymap.h +++ b/taglib/toolkit/tpropertymap.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_PROPERTYMAP_H_ diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index cdb12b06..2e77f349 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -25,16 +25,6 @@ // This class assumes that std::basic_string has a contiguous and null-terminated buffer. -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - #include #include #include @@ -47,12 +37,18 @@ # include "unicode.h" #endif +#include +#include +#include +#include + +#include "tstring.h" + namespace { using namespace TagLib; - inline size_t UTF16toUTF8( - const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) + size_t UTF16toUTF8(const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) { size_t len = 0; @@ -85,8 +81,7 @@ namespace return len; } - inline size_t UTF8toUTF16( - const char *src, size_t srcLength, wchar_t *dst, size_t dstLength) + size_t UTF8toUTF16(const char *src, size_t srcLength, wchar_t *dst, size_t dstLength) { size_t len = 0; @@ -120,7 +115,7 @@ namespace } // Returns the native format of std::wstring. - inline String::Type wcharByteOrder() + String::Type wcharByteOrder() { if(Utils::systemByteOrder() == LittleEndian) return String::UTF16LE; @@ -130,7 +125,7 @@ namespace // Converts a Latin-1 string into UTF-16(without BOM/CPU byte order) // and copies it to the internal buffer. - inline void copyFromLatin1(std::wstring &data, const char *s, size_t length) + void copyFromLatin1(std::wstring &data, const char *s, size_t length) { data.resize(length); @@ -140,7 +135,7 @@ namespace // Converts a UTF-8 string into UTF-16(without BOM/CPU byte order) // and copies it to the internal buffer. - inline void copyFromUTF8(std::wstring &data, const char *s, size_t length) + void copyFromUTF8(std::wstring &data, const char *s, size_t length) { data.resize(length); @@ -152,7 +147,7 @@ namespace // Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into // UTF-16(without BOM/CPU byte order) and copies it to the internal buffer. - inline void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t) + void copyFromUTF16(std::wstring &data, const wchar_t *s, size_t length, String::Type t) { bool swap; if(t == String::UTF16) { @@ -186,7 +181,7 @@ namespace // Converts a UTF-16 (with BOM), UTF-16LE or UTF16-BE string into // UTF-16(without BOM/CPU byte order) and copies it to the internal buffer. - inline void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t) + void copyFromUTF16(std::wstring &data, const char *s, size_t length, String::Type t) { bool swap; if(t == String::UTF16) { diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index d7adee29..3dc5cee5 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -55,224 +55,226 @@ namespace TagLib { namespace Utils { - - /*! - * Reverses the order of bytes in an 16-bit integer. - */ - inline unsigned short byteSwap(unsigned short x) + namespace { + + /*! + * Reverses the order of bytes in an 16-bit integer. + */ + inline unsigned short byteSwap(unsigned short x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(static_cast(x)); + return boost::endian::endian_reverse(static_cast(x)); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap16(x); + return __builtin_bswap16(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_ushort(x); + return _byteswap_ushort(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_16(x); + return __bswap_16(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt16(x); + return OSSwapInt16(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap16(x); + return swap16(x); #else - return ((x >> 8) & 0xff) | ((x & 0xff) << 8); + return ((x >> 8) & 0xff) | ((x & 0xff) << 8); #endif - } + } - /*! - * Reverses the order of bytes in an 32-bit integer. - */ - inline unsigned int byteSwap(unsigned int x) - { + /*! + * Reverses the order of bytes in an 32-bit integer. + */ + inline unsigned int byteSwap(unsigned int x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(static_cast(x)); + return boost::endian::endian_reverse(static_cast(x)); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap32(x); + return __builtin_bswap32(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_ulong(x); + return _byteswap_ulong(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_32(x); + return __bswap_32(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt32(x); + return OSSwapInt32(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap32(x); + return swap32(x); #else - return ((x & 0xff000000u) >> 24) - | ((x & 0x00ff0000u) >> 8) - | ((x & 0x0000ff00u) << 8) - | ((x & 0x000000ffu) << 24); + return ((x & 0xff000000u) >> 24) + | ((x & 0x00ff0000u) >> 8) + | ((x & 0x0000ff00u) << 8) + | ((x & 0x000000ffu) << 24); #endif - } + } - /*! - * Reverses the order of bytes in an 64-bit integer. - */ - inline unsigned long long byteSwap(unsigned long long x) - { + /*! + * Reverses the order of bytes in an 64-bit integer. + */ + inline unsigned long long byteSwap(unsigned long long x) + { #if defined(HAVE_BOOST_BYTESWAP) - return boost::endian::endian_reverse(static_cast(x)); + return boost::endian::endian_reverse(static_cast(x)); #elif defined(HAVE_GCC_BYTESWAP) - return __builtin_bswap64(x); + return __builtin_bswap64(x); #elif defined(HAVE_MSC_BYTESWAP) - return _byteswap_uint64(x); + return _byteswap_uint64(x); #elif defined(HAVE_GLIBC_BYTESWAP) - return __bswap_64(x); + return __bswap_64(x); #elif defined(HAVE_MAC_BYTESWAP) - return OSSwapInt64(x); + return OSSwapInt64(x); #elif defined(HAVE_OPENBSD_BYTESWAP) - return swap64(x); + return swap64(x); #else - return ((x & 0xff00000000000000ull) >> 56) - | ((x & 0x00ff000000000000ull) >> 40) - | ((x & 0x0000ff0000000000ull) >> 24) - | ((x & 0x000000ff00000000ull) >> 8) - | ((x & 0x00000000ff000000ull) << 8) - | ((x & 0x0000000000ff0000ull) << 24) - | ((x & 0x000000000000ff00ull) << 40) - | ((x & 0x00000000000000ffull) << 56); + return ((x & 0xff00000000000000ull) >> 56) + | ((x & 0x00ff000000000000ull) >> 40) + | ((x & 0x0000ff0000000000ull) >> 24) + | ((x & 0x000000ff00000000ull) >> 8) + | ((x & 0x00000000ff000000ull) << 8) + | ((x & 0x0000000000ff0000ull) << 24) + | ((x & 0x000000000000ff00ull) << 40) + | ((x & 0x00000000000000ffull) << 56); #endif - } + } - /*! - * Returns a formatted string just like standard sprintf(), but makes use of - * safer functions such as snprintf() if available. - */ - inline String formatString(const char *format, ...) - { - // Sufficient buffer size for the current internal uses. - // Consider changing this value when you use this function. + /*! + * Returns a formatted string just like standard sprintf(), but makes use of + * safer functions such as snprintf() if available. + */ + inline String formatString(const char *format, ...) + { + // Sufficient buffer size for the current internal uses. + // Consider changing this value when you use this function. - static const size_t BufferSize = 128; + static const size_t BufferSize = 128; - va_list args; - va_start(args, format); + va_list args; + va_start(args, format); - char buf[BufferSize]; - int length; + char buf[BufferSize]; + int length; #if defined(HAVE_VSNPRINTF) - length = vsnprintf(buf, BufferSize, format, args); + length = vsnprintf(buf, BufferSize, format, args); #elif defined(HAVE_VSPRINTF_S) - length = vsprintf_s(buf, format, args); + length = vsprintf_s(buf, format, args); #else - // The last resort. May cause a buffer overflow. + // The last resort. May cause a buffer overflow. - length = vsprintf(buf, format, args); - if(length >= BufferSize) { - debug("Utils::formatString() - Buffer overflow! Returning an empty string."); - length = -1; - } + length = vsprintf(buf, format, args); + if(length >= BufferSize) { + debug("Utils::formatString() - Buffer overflow! Returning an empty string."); + length = -1; + } #endif - va_end(args); + va_end(args); - if(length > 0) - return String(buf); - else - return String(); - } - - /*! - * Returns whether the two strings s1 and s2 are equal, ignoring the case of - * the characters. - * - * We took the trouble to define this one here, since there are some - * incompatible variations of case insensitive strcmp(). - */ - inline bool equalsIgnoreCase(const char *s1, const char *s2) - { - while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) { - s1++; - s2++; + if(length > 0) + return String(buf); + else + return String(); } - return (*s1 == '\0' && *s2 == '\0'); + /*! + * Returns whether the two strings s1 and s2 are equal, ignoring the case of + * the characters. + * + * We took the trouble to define this one here, since there are some + * incompatible variations of case insensitive strcmp(). + */ + inline bool equalsIgnoreCase(const char *s1, const char *s2) + { + while(*s1 != '\0' && *s2 != '\0' && ::tolower(*s1) == ::tolower(*s2)) { + s1++; + s2++; + } + + return (*s1 == '\0' && *s2 == '\0'); + } + + /*! + * Returns the integer byte order of the system. + */ + inline ByteOrder systemByteOrder() + { + union { + int i; + char c; + } u; + + u.i = 1; + if(u.c == 1) + return LittleEndian; + else + return BigEndian; + } + + /*! + * Returns the IEEE754 byte order of the system. + */ + inline ByteOrder floatByteOrder() + { + union { + double d; + char c; + } u; + + // 1.0 is stored in memory like 0x3FF0000000000000 in canonical form. + // So the first byte is zero if little endian. + + u.d = 1.0; + if(u.c == 0) + return LittleEndian; + else + return BigEndian; + } } - - /*! - * Returns the integer byte order of the system. - */ - inline ByteOrder systemByteOrder() - { - union { - int i; - char c; - } u; - - u.i = 1; - if(u.c == 1) - return LittleEndian; - else - return BigEndian; - } - - /*! - * Returns the IEEE754 byte order of the system. - */ - inline ByteOrder floatByteOrder() - { - union { - double d; - char c; - } u; - - // 1.0 is stored in memory like 0x3FF0000000000000 in canonical form. - // So the first byte is zero if little endian. - - u.d = 1.0; - if(u.c == 0) - return LittleEndian; - else - return BigEndian; - } - } } diff --git a/taglib/toolkit/tzlib.cpp b/taglib/toolkit/tzlib.cpp new file mode 100644 index 00000000..40158fd2 --- /dev/null +++ b/taglib/toolkit/tzlib.cpp @@ -0,0 +1,142 @@ +/*************************************************************************** + copyright : (C) 2016 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#if defined(HAVE_ZLIB) +# include +#elif defined(HAVE_BOOST_ZLIB) +# include +# include +#endif + +#include +#include + +#include "tzlib.h" + +using namespace TagLib; + +bool zlib::isAvailable() +{ +#if defined(HAVE_ZLIB) || defined(HAVE_BOOST_ZLIB) + + return true; + +#else + + return false; + +#endif +} + +ByteVector zlib::decompress(const ByteVector &data) +{ +#if defined(HAVE_ZLIB) + + z_stream stream = {}; + + if(inflateInit(&stream) != Z_OK) { + debug("zlib::decompress() - Failed to initizlize zlib."); + return ByteVector(); + } + + ByteVector inData = data; + + stream.avail_in = static_cast(inData.size()); + stream.next_in = reinterpret_cast(inData.data()); + + const unsigned int chunkSize = 1024; + + ByteVector outData; + + do { + const size_t offset = outData.size(); + outData.resize(outData.size() + chunkSize); + + stream.avail_out = static_cast(chunkSize); + stream.next_out = reinterpret_cast(outData.data() + offset); + + const int result = inflate(&stream, Z_NO_FLUSH); + + if(result == Z_STREAM_ERROR || + result == Z_NEED_DICT || + result == Z_DATA_ERROR || + result == Z_MEM_ERROR) + { + if(result != Z_STREAM_ERROR) + inflateEnd(&stream); + + debug("zlib::decompress() - Error reading compressed stream."); + return ByteVector(); + } + + outData.resize(outData.size() - stream.avail_out); + } while(stream.avail_out == 0); + + inflateEnd(&stream); + + return outData; + +#elif defined(HAVE_BOOST_ZLIB) + + using namespace boost::iostreams; + + struct : public sink + { + ByteVector data; + + typedef char char_type; + typedef sink_tag category; + + std::streamsize write(char const* s, std::streamsize n) + { + const unsigned int originalSize = data.size(); + + data.resize(static_cast(originalSize + n)); + ::memcpy(data.data() + originalSize, s, static_cast(n)); + + return n; + } + } sink; + + try { + zlib_decompressor().write(sink, data.data(), data.size()); + } + catch(const zlib_error &) { + debug("zlib::decompress() - Error reading compressed stream."); + return ByteVector(); + } + + return sink.data; + +#else + + return ByteVector(); + +#endif +} diff --git a/taglib/toolkit/tzlib.h b/taglib/toolkit/tzlib.h new file mode 100644 index 00000000..b1f1fcaf --- /dev/null +++ b/taglib/toolkit/tzlib.h @@ -0,0 +1,54 @@ +/*************************************************************************** + copyright : (C) 2016 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifndef TAGLIB_TZLIB_H +#define TAGLIB_TZLIB_H + +#include + +// THIS FILE IS NOT A PART OF THE TAGLIB API + +#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header + +namespace TagLib { + + namespace zlib { + + /*! + * Returns whether or not zlib is installed and ready to use. + */ + bool isAvailable(); + + /*! + * Decompress \a data by zlib. + */ + ByteVector decompress(const ByteVector &data); + + } +} + +#endif + +#endif diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index d0f57779..bb8d6493 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include "tstringlist.h" @@ -129,11 +133,11 @@ namespace { ByteVector data = file.readBlock(std::min(m_size, limit)); size_t count = data.size(); - const size_t index = data.find((char) 0); - if(index != ByteVector::npos()) { + int index = data.find((char) 0); + if(index > -1) { data.resize(index); } - data.replace((char) 0xff, ' '); + data.replace('\xff', ' '); value = data; return static_cast(count); } diff --git a/taglib/xm/xmfile.h b/taglib/xm/xmfile.h index 8ba67ad4..dafae060 100644 --- a/taglib/xm/xmfile.h +++ b/taglib/xm/xmfile.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_XMFILE_H diff --git a/taglib/xm/xmproperties.cpp b/taglib/xm/xmproperties.cpp index 200eae50..c053a3e0 100644 --- a/taglib/xm/xmproperties.cpp +++ b/taglib/xm/xmproperties.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - copyright :(C) 2011 by Mathias Panzenböck + copyright : (C) 2011 by Mathias Panzenböck email : grosser.meister.morti@gmx.net ***************************************************************************/ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,10 +15,15 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ + #include "xmproperties.h" using namespace TagLib; diff --git a/taglib/xm/xmproperties.h b/taglib/xm/xmproperties.h index ad6b8037..a7de582b 100644 --- a/taglib/xm/xmproperties.h +++ b/taglib/xm/xmproperties.h @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #ifndef TAGLIB_XMPROPERTIES_H diff --git a/tests/data/id3v22-tda.mp3 b/tests/data/id3v22-tda.mp3 index d89ae1c4..b0545ea6 100644 Binary files a/tests/data/id3v22-tda.mp3 and b/tests/data/id3v22-tda.mp3 differ diff --git a/tests/data/toc_many_children.mp3 b/tests/data/toc_many_children.mp3 new file mode 100644 index 00000000..168c4798 Binary files /dev/null and b/tests/data/toc_many_children.mp3 differ diff --git a/tests/main.cpp b/tests/main.cpp index c83c9d13..86a4208c 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_aiff.cpp b/tests/test_aiff.cpp index b7aa8385..139c56a6 100644 --- a/tests/test_aiff.cpp +++ b/tests/test_aiff.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_ape.cpp b/tests/test_ape.cpp index 12ca2db8..81f4425d 100644 --- a/tests/test_ape.cpp +++ b/tests/test_ape.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2010 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_apetag.cpp b/tests/test_apetag.cpp index 02e15faa..ce4f08db 100644 --- a/tests/test_apetag.cpp +++ b/tests/test_apetag.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2010 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index fe50b821..73af3828 100644 --- a/tests/test_asf.cpp +++ b/tests/test_asf.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2008 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index e38d664b..bd8c6088 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -1,28 +1,30 @@ -/* Copyright (C) 2003 Scott Wheeler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ -#include +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#define _USE_MATH_DEFINES +#include #include #include #include @@ -36,47 +38,35 @@ class TestByteVector : public CppUnit::TestFixture CPPUNIT_TEST(testByteVector); CPPUNIT_TEST(testFind1); CPPUNIT_TEST(testFind2); + CPPUNIT_TEST(testFind3); CPPUNIT_TEST(testRfind1); CPPUNIT_TEST(testRfind2); + CPPUNIT_TEST(testRfind3); CPPUNIT_TEST(testToHex); - CPPUNIT_TEST(testNumericCoversion); + CPPUNIT_TEST(testIntegerConversion); + CPPUNIT_TEST(testFloatingPointConversion); CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testIterator); CPPUNIT_TEST(testResize); - CPPUNIT_TEST(testAppend); + CPPUNIT_TEST(testAppend1); + CPPUNIT_TEST(testAppend2); CPPUNIT_TEST(testBase64); CPPUNIT_TEST_SUITE_END(); public: - void testByteVector() { - ByteVector v("foobar"); - - CPPUNIT_ASSERT(v.find("ob") == 2); - CPPUNIT_ASSERT(v.find('b') == 3); - - ByteVector a1("foo"); - a1.append("bar"); - CPPUNIT_ASSERT(a1 == "foobar"); - - ByteVector a2("foo"); - a2.append("b"); - CPPUNIT_ASSERT(a2 == "foob"); - - ByteVector a3; - a3.append("b"); - CPPUNIT_ASSERT(a3 == "b"); - ByteVector s1("foo"); CPPUNIT_ASSERT(ByteVectorList::split(s1, " ").size() == 1); ByteVector s2("f"); CPPUNIT_ASSERT(ByteVectorList::split(s2, " ").size() == 1); - CPPUNIT_ASSERT(ByteVector().size() == 0); - CPPUNIT_ASSERT(ByteVector("asdf").clear().size() == 0); - CPPUNIT_ASSERT(ByteVector("asdf").clear() == ByteVector()); + CPPUNIT_ASSERT(ByteVector().isEmpty()); + CPPUNIT_ASSERT_EQUAL(0U, ByteVector().size()); + CPPUNIT_ASSERT(ByteVector("asdf").clear().isEmpty()); + CPPUNIT_ASSERT_EQUAL(0U, ByteVector("asdf").clear().size()); + CPPUNIT_ASSERT_EQUAL(ByteVector(), ByteVector("asdf").clear()); ByteVector i("blah blah"); ByteVector j("blah"); @@ -116,6 +106,20 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("\x01\x02", 2).find("\x01\x03")); } + void testFind3() + { + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S')); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S', 0)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S', 1)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S', 2)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S', 3)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find('S', 4)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find('S', 5)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find('S', 6)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find('S', 7)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find('S', 8)); + } + void testRfind1() { CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 0)); @@ -152,6 +156,20 @@ public: CPPUNIT_ASSERT_EQUAL((size_t)10, r4.rfind("OggS", 12)); } + void testRfind3() + { + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 0)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 1)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 2)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 3)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 4)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 5)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 6)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 7)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O', 8)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind('O')); + } + void testToHex() { ByteVector v("\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f", 16); @@ -159,77 +177,71 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("f0e1d2c3b4a5968778695a4b3c2d1e0f"), v.toHex()); } - void testNumericCoversion() + void testIntegerConversion() { - // n = { 0x00, 0x88, 0x11, 0x99, ..., 0x77, 0xFF } - ByteVector n(16, 0); - for(size_t i = 0; i < 8; ++i) { - n[i * 2 ] = static_cast(0x11 * i); - n[i * 2 + 1] = static_cast(0x11 * (i + 8)); - } + const ByteVector data("\x00\xff\x01\xff\x00\xff\x01\xff\x00\xff\x01\xff\x00\xff", 14); - CPPUNIT_ASSERT(n.toUInt16LE(1) == 4488); - CPPUNIT_ASSERT(n.toUInt16BE(2) == 4505); - CPPUNIT_ASSERT(n.toUInt24LE(3) == 11149977); - CPPUNIT_ASSERT(n.toUInt24BE(4) == 2271795); - CPPUNIT_ASSERT(n.toUInt32LE(5) == 1153119146); - CPPUNIT_ASSERT(n.toUInt32BE(6) == 867910860); - CPPUNIT_ASSERT(n.toInt16LE(3) == 8857); - CPPUNIT_ASSERT(n.toInt16BE(7) == -17596); - CPPUNIT_ASSERT(n.toInt16LE(10) == -8875); - CPPUNIT_ASSERT(n.toInt16BE(14) == 30719); - CPPUNIT_ASSERT(n.toInt64LE(5) == 7412174897536512938ll); - CPPUNIT_ASSERT(n.toInt64BE(3) == -7412174897536512939ll); - CPPUNIT_ASSERT(n.toInt64LE(6) == -1268082884489200845ll); - CPPUNIT_ASSERT(n.toInt64BE(4) == 2497865822736504285ll); + CPPUNIT_ASSERT_EQUAL((short)0x00ff, data.toInt16BE(0)); + CPPUNIT_ASSERT_EQUAL((short)0xff00, data.toInt16LE(0)); + CPPUNIT_ASSERT_EQUAL((short)0xff01, data.toInt16BE(5)); + CPPUNIT_ASSERT_EQUAL((short)0x01ff, data.toInt16LE(5)); + CPPUNIT_ASSERT_EQUAL((short)0xff, data.toInt16BE(13)); + CPPUNIT_ASSERT_EQUAL((short)0xff, data.toInt16LE(13)); - CPPUNIT_ASSERT(ByteVector::fromUInt16LE(n.toInt16LE(5)) == n.mid(5, 2)); - CPPUNIT_ASSERT(ByteVector::fromUInt16BE(n.toInt16BE(9)) == n.mid(9, 2)); - CPPUNIT_ASSERT(ByteVector::fromUInt32LE(n.toUInt32LE(4)) == n.mid(4, 4)); - CPPUNIT_ASSERT(ByteVector::fromUInt32BE(n.toUInt32BE(7)) == n.mid(7, 4)); - CPPUNIT_ASSERT(ByteVector::fromUInt64LE(n.toInt64LE(1)) == n.mid(1, 8)); - CPPUNIT_ASSERT(ByteVector::fromUInt64BE(n.toInt64BE(6)) == n.mid(6, 8)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0x00ff, data.toUInt16BE(0)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xff00, data.toUInt16LE(0)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xff01, data.toUInt16BE(5)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0x01ff, data.toUInt16LE(5)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xff, data.toUInt16BE(13)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xff, data.toUInt16LE(13)); - CPPUNIT_ASSERT(ByteVector::fromUInt16LE(4386) == ByteVector::fromUInt16BE(8721)); - CPPUNIT_ASSERT(ByteVector::fromUInt32LE(287454020) == ByteVector::fromUInt32BE(1144201745)); - CPPUNIT_ASSERT(ByteVector::fromUInt64LE(1234605615291183940ll) == ByteVector::fromUInt64BE(4914309075945333265ll)); + CPPUNIT_ASSERT_EQUAL(0x00ff01ffU, data.toUInt32BE(0)); + CPPUNIT_ASSERT_EQUAL(0xff01ff00U, data.toUInt32LE(0)); + CPPUNIT_ASSERT_EQUAL(0xff01ff00U, data.toUInt32BE(5)); + CPPUNIT_ASSERT_EQUAL(0x00ff01ffU, data.toUInt32LE(5)); + CPPUNIT_ASSERT_EQUAL(0x00ffU, data.toUInt32BE(12)); + CPPUNIT_ASSERT_EQUAL(0xff00U, data.toUInt32LE(12)); - const unsigned char PI32LE[] = { 0x00, 0xdb, 0x0f, 0x49, 0x40 }; - const unsigned char PI32BE[] = { 0x00, 0x40, 0x49, 0x0f, 0xdb }; - const unsigned char PI64LE[] = { 0x00, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40 }; - const unsigned char PI64BE[] = { 0x00, 0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18 }; - const unsigned char PI80LE[] = { 0x00, 0x00, 0xc0, 0x68, 0x21, 0xa2, 0xda, 0x0f, 0xc9, 0x00, 0x40 }; - const unsigned char PI80BE[] = { 0x00, 0x40, 0x00, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc0, 0x00 }; + CPPUNIT_ASSERT_EQUAL(0x00ff01U, data.toUInt24BE(0)); + CPPUNIT_ASSERT_EQUAL(0x01ff00U, data.toUInt24LE(0)); + CPPUNIT_ASSERT_EQUAL(0xff01ffU, data.toUInt24BE(5)); + CPPUNIT_ASSERT_EQUAL(0xff01ffU, data.toUInt24LE(5)); + CPPUNIT_ASSERT_EQUAL(0x00ffU, data.toUInt24BE(12)); + CPPUNIT_ASSERT_EQUAL(0xff00U, data.toUInt24LE(12)); - ByteVector pi32le(reinterpret_cast(PI32LE), 5); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi32le.toFloat32LE(1) * 10000)); + CPPUNIT_ASSERT_EQUAL((long long)0x00ff01ff00ff01ffULL, data.toInt64BE(0)); + CPPUNIT_ASSERT_EQUAL((long long)0xff01ff00ff01ff00ULL, data.toInt64LE(0)); + CPPUNIT_ASSERT_EQUAL((long long)0xff01ff00ff01ff00ULL, data.toInt64BE(5)); + CPPUNIT_ASSERT_EQUAL((long long)0x00ff01ff00ff01ffULL, data.toInt64LE(5)); + CPPUNIT_ASSERT_EQUAL((long long)0x00ffU, data.toInt64BE(12)); + CPPUNIT_ASSERT_EQUAL((long long)0xff00U, data.toInt64LE(12)); +} - ByteVector pi32be(reinterpret_cast(PI32BE), 5); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi32be.toFloat32BE(1) * 10000)); + void testFloatingPointConversion() + { + const double Tolerance = 1.0e-7; - ByteVector pi64le(reinterpret_cast(PI64LE), 9); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi64le.toFloat64LE(1) * 10000)); + const ByteVector pi32le("\xdb\x0f\x49\x40", 4); + CPPUNIT_ASSERT(std::abs(pi32le.toFloat32LE(0) - M_PI) < Tolerance); + CPPUNIT_ASSERT_EQUAL(pi32le, ByteVector::fromFloat32LE(pi32le.toFloat32LE(0))); - ByteVector pi64be(reinterpret_cast(PI64BE), 9); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi64be.toFloat64BE(1) * 10000)); + const ByteVector pi32be("\x40\x49\x0f\xdb", 4); + CPPUNIT_ASSERT(std::abs(pi32be.toFloat32BE(0) - M_PI) < Tolerance); + CPPUNIT_ASSERT_EQUAL(pi32be, ByteVector::fromFloat32BE(pi32be.toFloat32BE(0))); - ByteVector pi80le(reinterpret_cast(PI80LE), 11); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi80le.toFloat80LE(1) * 10000)); + const ByteVector pi64le("\x18\x2d\x44\x54\xfb\x21\x09\x40", 8); + CPPUNIT_ASSERT(std::abs(pi64le.toFloat64LE(0) - M_PI) < Tolerance); + CPPUNIT_ASSERT_EQUAL(pi64le, ByteVector::fromFloat64LE(pi64le.toFloat64LE(0))); - ByteVector pi80be(reinterpret_cast(PI80BE), 11); - CPPUNIT_ASSERT_EQUAL(31415, static_cast(pi80be.toFloat80BE(1) * 10000)); + const ByteVector pi64be("\x40\x09\x21\xfb\x54\x44\x2d\x18", 8); + CPPUNIT_ASSERT(std::abs(pi64be.toFloat64BE(0) - M_PI) < Tolerance); + CPPUNIT_ASSERT_EQUAL(pi64be, ByteVector::fromFloat64BE(pi64be.toFloat64BE(0))); - ByteVector pi32le2 = ByteVector::fromFloat32LE(pi32le.toFloat32LE(1)); - CPPUNIT_ASSERT(memcmp(pi32le.data() + 1, pi32le2.data(), 4) == 0); + const ByteVector pi80le("\x00\xc0\x68\x21\xa2\xda\x0f\xc9\x00\x40", 10); + CPPUNIT_ASSERT(std::abs(pi80le.toFloat80LE(0) - M_PI) < Tolerance); - ByteVector pi32be2 = ByteVector::fromFloat32BE(pi32be.toFloat32BE(1)); - CPPUNIT_ASSERT(memcmp(pi32be.data() + 1, pi32be2.data(), 4) == 0); - - ByteVector pi64le2 = ByteVector::fromFloat64LE(pi64le.toFloat64LE(1)); - CPPUNIT_ASSERT(memcmp(pi64le.data() + 1, pi64le2.data(), 8) == 0); - - ByteVector pi64be2 = ByteVector::fromFloat64BE(pi64be.toFloat64BE(1)); - CPPUNIT_ASSERT(memcmp(pi64be.data() + 1, pi64be2.data(), 8) == 0); + const ByteVector pi80be("\x40\x00\xc9\x0f\xda\xa2\x21\x68\xc0\x00", 10); + CPPUNIT_ASSERT(std::abs(pi80be.toFloat80BE(0) - M_PI) < Tolerance); } void testReplace() @@ -253,31 +265,50 @@ public: ByteVector a("abcdabf"); a.replace(ByteVector("a"), ByteVector("x")); CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a); + a.replace(ByteVector("x"), ByteVector("a")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), a); + } + { + ByteVector a("abcdabf"); + a.replace('a', 'x'); + CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a); + a.replace('x', 'a'); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), a); } { ByteVector a("abcdabf"); a.replace(ByteVector("ab"), ByteVector("xy")); CPPUNIT_ASSERT_EQUAL(ByteVector("xycdxyf"), a); + a.replace(ByteVector("xy"), ByteVector("ab")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), a); } { ByteVector a("abcdabf"); a.replace(ByteVector("a"), ByteVector("")); CPPUNIT_ASSERT_EQUAL(ByteVector("bcdbf"), a); + a.replace(ByteVector(""), ByteVector("a")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), a); } { ByteVector a("abcdabf"); - a.replace(ByteVector("ab"), ByteVector("x")); - CPPUNIT_ASSERT_EQUAL(ByteVector("xcdxf"), a); + a.replace(ByteVector("b"), ByteVector("")); + CPPUNIT_ASSERT_EQUAL(ByteVector("acdaf"), a); + a.replace(ByteVector(""), ByteVector("b")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabf"), a); } { - ByteVector a("abcdabf"); - a.replace(ByteVector("ab"), ByteVector()); - CPPUNIT_ASSERT_EQUAL(ByteVector("cdf"), a); + ByteVector a("abcdabc"); + a.replace(ByteVector("c"), ByteVector("")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abdab"), a); + a.replace(ByteVector(""), ByteVector("c")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdabc"), a); } { - ByteVector a("abcdabf"); - a.replace(ByteVector("bf"), ByteVector("x")); - CPPUNIT_ASSERT_EQUAL(ByteVector("abcdax"), a); + ByteVector a("abcdaba"); + a.replace(ByteVector("a"), ByteVector("")); + CPPUNIT_ASSERT_EQUAL(ByteVector("bcdb"), a); + a.replace(ByteVector(""), ByteVector("a")); + CPPUNIT_ASSERT_EQUAL(ByteVector("abcdaba"), a); } } @@ -372,18 +403,49 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), c.find('C')); } - void testAppend() + void testAppend1() { - ByteVector v1("taglib"); - ByteVector v2 = v1; + ByteVector v1("foo"); + v1.append("bar"); + CPPUNIT_ASSERT_EQUAL(ByteVector("foobar"), v1); - v1.append("ABC"); - CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC"), v1); - v1.append('1'); - v1.append('2'); - v1.append('3'); - CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC123"), v1); - CPPUNIT_ASSERT_EQUAL(ByteVector("taglib"), v2); + ByteVector v2("foo"); + v2.append("b"); + CPPUNIT_ASSERT_EQUAL(ByteVector("foob"), v2); + + ByteVector v3; + v3.append("b"); + CPPUNIT_ASSERT_EQUAL(ByteVector("b"), v3); + + ByteVector v4("foo"); + v4.append(v1); + CPPUNIT_ASSERT_EQUAL(ByteVector("foofoobar"), v4); + + ByteVector v5("foo"); + v5.append('b'); + CPPUNIT_ASSERT_EQUAL(ByteVector("foob"), v5); + + ByteVector v6; + v6.append('b'); + CPPUNIT_ASSERT_EQUAL(ByteVector("b"), v6); + + ByteVector v7("taglib"); + ByteVector v8 = v7; + + v7.append("ABC"); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC"), v7); + v7.append('1'); + v7.append('2'); + v7.append('3'); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglibABC123"), v7); + CPPUNIT_ASSERT_EQUAL(ByteVector("taglib"), v8); + } + + void testAppend2() + { + ByteVector a("1234"); + a.append(a); + CPPUNIT_ASSERT_EQUAL(ByteVector("12341234"), a); } void testBase64() @@ -411,7 +473,7 @@ public: CPPUNIT_ASSERT_EQUAL(e3, s3.toBase64()); // Decode - CPPUNIT_ASSERT_EQUAL(sempty, eempty.toBase64()); + CPPUNIT_ASSERT_EQUAL(sempty, ByteVector::fromBase64(eempty)); CPPUNIT_ASSERT_EQUAL(s0, ByteVector::fromBase64(e0)); CPPUNIT_ASSERT_EQUAL(s1, ByteVector::fromBase64(e1)); CPPUNIT_ASSERT_EQUAL(s2, ByteVector::fromBase64(e2)); diff --git a/tests/test_bytevectorlist.cpp b/tests/test_bytevectorlist.cpp index 5c3475d8..3e26aefc 100644 --- a/tests/test_bytevectorlist.cpp +++ b/tests/test_bytevectorlist.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_bytevectorstream.cpp b/tests/test_bytevectorstream.cpp index 7f6df152..452c64c5 100644 --- a/tests/test_bytevectorstream.cpp +++ b/tests/test_bytevectorstream.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2011 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include @@ -13,6 +38,7 @@ class TestByteVectorStream : public CppUnit::TestFixture CPPUNIT_TEST(testReadBlock); CPPUNIT_TEST(testRemoveBlock); CPPUNIT_TEST(testInsert); + CPPUNIT_TEST(testSeekEnd); CPPUNIT_TEST_SUITE_END(); public: @@ -87,6 +113,19 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("yyx123foa"), *stream.data()); } + void testSeekEnd() + { + ByteVector v("abcdefghijklmnopqrstuvwxyz"); + ByteVectorStream stream(v); + CPPUNIT_ASSERT_EQUAL(26LL, stream.length()); + + stream.seek(-4, IOStream::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("w"), stream.readBlock(1)); + + stream.seek(-25, IOStream::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("b"), stream.readBlock(1)); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVectorStream); diff --git a/tests/test_file.cpp b/tests/test_file.cpp index e1e9af6c..42087ee5 100644 --- a/tests/test_file.cpp +++ b/tests/test_file.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - copyright : (C) 2014 by Lukas Lalinsky - email : lukas@oxygene.sk + copyright : (C) 2015 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com ***************************************************************************/ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include @@ -41,6 +45,7 @@ class TestFile : public CppUnit::TestFixture CPPUNIT_TEST(testFindInSmallFile); CPPUNIT_TEST(testRFindInSmallFile); CPPUNIT_TEST(testSeek); + CPPUNIT_TEST(testTruncate); CPPUNIT_TEST_SUITE_END(); public: @@ -125,6 +130,24 @@ public: CPPUNIT_ASSERT_EQUAL(4428LL, f.tell()); } + void testTruncate() + { + ScopedFileCopy copy("empty", ".ogg"); + std::string name = copy.fileName(); + + { + PlainFile f(name.c_str()); + CPPUNIT_ASSERT_EQUAL(4328LL, f.length()); + + f.truncate(2000); + CPPUNIT_ASSERT_EQUAL(2000LL, f.length()); + } + { + PlainFile f(name.c_str()); + CPPUNIT_ASSERT_EQUAL(2000LL, f.length()); + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestFile); diff --git a/tests/test_fileref.cpp b/tests/test_fileref.cpp index 2d9f0a43..2d77682a 100644 --- a/tests/test_fileref.cpp +++ b/tests/test_fileref.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include @@ -5,6 +30,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include "utils.h" #include @@ -42,14 +76,15 @@ class TestFileRef : public CppUnit::TestFixture CPPUNIT_TEST(testTrueAudio); CPPUNIT_TEST(testAPE); CPPUNIT_TEST(testWav); - CPPUNIT_TEST(testAIFF); - CPPUNIT_TEST(testAIFC); + CPPUNIT_TEST(testAIFF_1); + CPPUNIT_TEST(testAIFF_2); CPPUNIT_TEST(testUnsupported); CPPUNIT_TEST(testFileResolver); CPPUNIT_TEST_SUITE_END(); public: + template void fileRefSave(const string &filename, const string &ext) { ScopedFileCopy copy(filename, ext); @@ -57,6 +92,7 @@ public: { FileRef f(newname.c_str()); + CPPUNIT_ASSERT(dynamic_cast(f.file())); CPPUNIT_ASSERT(!f.isNull()); f.tag()->setArtist("test artist"); f.tag()->setTitle("test title"); @@ -96,6 +132,7 @@ public: { FileStream fs(newname.c_str()); FileRef f(&fs); + CPPUNIT_ASSERT(dynamic_cast(f.file())); CPPUNIT_ASSERT(!f.isNull()); CPPUNIT_ASSERT_EQUAL(f.tag()->artist(), String("ttest artist")); CPPUNIT_ASSERT_EQUAL(f.tag()->title(), String("ytest title")); @@ -108,91 +145,87 @@ public: void testMusepack() { - fileRefSave("click", ".mpc"); + fileRefSave("click", ".mpc"); } void testASF() { - fileRefSave("silence-1", ".wma"); + fileRefSave("silence-1", ".wma"); } void testVorbis() { - fileRefSave("empty", ".ogg"); + fileRefSave("empty", ".ogg"); } void testSpeex() { - fileRefSave("empty", ".spx"); + fileRefSave("empty", ".spx"); } void testFLAC() { - fileRefSave("no-tags", ".flac"); + fileRefSave("no-tags", ".flac"); } void testMP3() { - fileRefSave("xing", ".mp3"); + fileRefSave("xing", ".mp3"); } void testTrueAudio() { - fileRefSave("empty", ".tta"); + fileRefSave("empty", ".tta"); } void testMP4_1() { - fileRefSave("has-tags", ".m4a"); + fileRefSave("has-tags", ".m4a"); } void testMP4_2() { - fileRefSave("no-tags", ".m4a"); + fileRefSave("no-tags", ".m4a"); } void testMP4_3() { - fileRefSave("no-tags", ".3g2"); + fileRefSave("no-tags", ".3g2"); } void testMP4_4() { - fileRefSave("blank_video", ".m4v"); + fileRefSave("blank_video", ".m4v"); } void testWav() { - fileRefSave("empty", ".wav"); - } - - void testAIFF() - { - fileRefSave("empty", ".aiff"); - } - - void testAIFC() - { - fileRefSave("alaw", ".aifc"); + fileRefSave("empty", ".wav"); } void testOGA_FLAC() { - FileRef f(TEST_FILE_PATH_C("empty_flac.oga")); - CPPUNIT_ASSERT(dynamic_cast(f.file()) == NULL); - CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); + fileRefSave("empty_flac", ".oga"); } void testOGA_Vorbis() { - FileRef f(TEST_FILE_PATH_C("empty_vorbis.oga")); - CPPUNIT_ASSERT(dynamic_cast(f.file()) != NULL); - CPPUNIT_ASSERT(dynamic_cast(f.file()) == NULL); + fileRefSave("empty_vorbis", ".oga"); } void testAPE() { - fileRefSave("mac-399", ".ape"); + fileRefSave("mac-399", ".ape"); + } + + void testAIFF_1() + { + fileRefSave("empty", ".aiff"); + } + + void testAIFF_2() + { + fileRefSave("alaw", ".aifc"); } void testUnsupported() diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index e03c89f7..c77d78f5 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_flacpicture.cpp b/tests/test_flacpicture.cpp index d9a7bff0..ee0a525c 100644 --- a/tests/test_flacpicture.cpp +++ b/tests/test_flacpicture.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2010 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_flacunknownmetadatablock.cpp b/tests/test_flacunknownmetadatablock.cpp index 881078dd..d08a9bae 100644 --- a/tests/test_flacunknownmetadatablock.cpp +++ b/tests/test_flacunknownmetadatablock.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2012 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_id3v1.cpp b/tests/test_id3v1.cpp index e778419a..3358aead 100644 --- a/tests/test_id3v1.cpp +++ b/tests/test_id3v1.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 8ecf5447..9569d14f 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -1,6 +1,27 @@ -#ifdef HAVE_CONFIG_H -#include -#endif +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ #include #include @@ -23,6 +44,7 @@ #include #include #include +#include #include #include "utils.h" @@ -47,7 +69,8 @@ class TestID3v2 : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestID3v2); CPPUNIT_TEST(testUnsynchDecode); - CPPUNIT_TEST(testDowngradeUTF8ForID3v23); + CPPUNIT_TEST(testDowngradeUTF8ForID3v23_1); + CPPUNIT_TEST(testDowngradeUTF8ForID3v23_2); CPPUNIT_TEST(testUTF16BEDelimiter); CPPUNIT_TEST(testUTF16Delimiter); CPPUNIT_TEST(testReadStringField); @@ -73,6 +96,7 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testParseOwnershipFrame); CPPUNIT_TEST(testRenderOwnershipFrame); CPPUNIT_TEST(testParseSynchronizedLyricsFrame); + CPPUNIT_TEST(testParseSynchronizedLyricsFrameWithEmptyDescritpion); CPPUNIT_TEST(testRenderSynchronizedLyricsFrame); CPPUNIT_TEST(testParseEventTimingCodesFrame); CPPUNIT_TEST(testRenderEventTimingCodesFrame); @@ -96,6 +120,7 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testShrinkPadding); CPPUNIT_TEST(testEmptyFrame); CPPUNIT_TEST(testDuplicateTags); + CPPUNIT_TEST(testParseTOCFrameWithManyChildren); CPPUNIT_TEST_SUITE_END(); public: @@ -107,7 +132,7 @@ public: CPPUNIT_ASSERT_EQUAL(String("My babe just cares for me"), f.tag()->title()); } - void testDowngradeUTF8ForID3v23() + void testDowngradeUTF8ForID3v23_1() { ScopedFileCopy copy("xing", ".mp3"); string newname = copy.fileName(); @@ -131,6 +156,27 @@ public: CPPUNIT_ASSERT_EQUAL(String::UTF16, f2.textEncoding()); } + void testDowngradeUTF8ForID3v23_2() + { + ScopedFileCopy copy("xing", ".mp3"); + + ID3v2::UnsynchronizedLyricsFrame *f + = new ID3v2::UnsynchronizedLyricsFrame(String::UTF8); + f->setText("Foo"); + + MPEG::File file(copy.fileName().c_str()); + file.ID3v2Tag(true)->addFrame(f); + file.save(MPEG::File::ID3v2, true, 3); + CPPUNIT_ASSERT(file.hasID3v2Tag()); + + ByteVector data = f->render(); + CPPUNIT_ASSERT_EQUAL((unsigned int)(4+4+2+1+3+2+2+6+2), data.size()); + + ID3v2::UnsynchronizedLyricsFrame f2(data); + CPPUNIT_ASSERT_EQUAL(String("Foo"), f2.text()); + CPPUNIT_ASSERT_EQUAL(String::UTF16, f2.textEncoding()); + } + void testUTF16BEDelimiter() { ID3v2::TextIdentificationFrame f(ByteVector("TPE1"), String::UTF16BE); @@ -208,7 +254,7 @@ public: ID3v2::Header header; header.setMajorVersion(2); ID3v2::AttachedPictureFrame *frame = - static_cast(factory->createFrame(data, &header)); + dynamic_cast(factory->createFrame(data, &header)); CPPUNIT_ASSERT(frame); CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), frame->mimeType()); @@ -230,8 +276,8 @@ public: "\x00", 14); ID3v2::Header header; header.setMajorVersion(2); - ID3v2::AttachedPictureFrame *frame = - static_cast(factory->createFrame(data, &header)); + ID3v2::UnknownFrame *frame = + dynamic_cast(factory->createFrame(data, &header)); CPPUNIT_ASSERT(frame); @@ -489,6 +535,35 @@ public: CPPUNIT_ASSERT_EQUAL((unsigned int)4567, stl[1].time); } + void testParseSynchronizedLyricsFrameWithEmptyDescritpion() + { + ID3v2::SynchronizedLyricsFrame f( + ByteVector("SYLT" // Frame ID + "\x00\x00\x00\x21" // Frame size + "\x00\x00" // Frame flags + "\x00" // Text encoding + "eng" // Language + "\x02" // Time stamp format + "\x01" // Content type + "\x00" // Content descriptor + "Example\x00" // 1st text + "\x00\x00\x04\xd2" // 1st time stamp + "Lyrics\x00" // 2nd text + "\x00\x00\x11\xd7", 40)); // 2nd time stamp + CPPUNIT_ASSERT_EQUAL(String::Latin1, f.textEncoding()); + CPPUNIT_ASSERT_EQUAL(ByteVector("eng", 3), f.language()); + CPPUNIT_ASSERT_EQUAL(ID3v2::SynchronizedLyricsFrame::AbsoluteMilliseconds, + f.timestampFormat()); + CPPUNIT_ASSERT_EQUAL(ID3v2::SynchronizedLyricsFrame::Lyrics, f.type()); + CPPUNIT_ASSERT(f.description().isEmpty()); + ID3v2::SynchronizedLyricsFrame::SynchedTextList stl = f.synchedText(); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, stl.size()); + CPPUNIT_ASSERT_EQUAL(String("Example"), stl[0].text); + CPPUNIT_ASSERT_EQUAL((unsigned int)1234, stl[0].time); + CPPUNIT_ASSERT_EQUAL(String("Lyrics"), stl[1].text); + CPPUNIT_ASSERT_EQUAL((unsigned int)4567, stl[1].time); + } + void testRenderSynchronizedLyricsFrame() { ID3v2::SynchronizedLyricsFrame f; @@ -597,8 +672,8 @@ public: ID3v2::Header header; header.setMajorVersion(3); ID3v2::TextIdentificationFrame *frame = - static_cast(factory->createFrame(data, &header)); - CPPUNIT_ASSERT_EQUAL((size_t)1, frame->fieldList().size()); + dynamic_cast(factory->createFrame(data, &header)); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("Death Metal"), frame->fieldList()[0]); ID3v2::Tag tag; @@ -618,8 +693,8 @@ public: ID3v2::Header header; header.setMajorVersion(3); ID3v2::TextIdentificationFrame *frame = - static_cast(factory->createFrame(data, &header)); - CPPUNIT_ASSERT_EQUAL((size_t)2, frame->fieldList().size()); + dynamic_cast(factory->createFrame(data, &header)); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("4"), frame->fieldList()[0]); CPPUNIT_ASSERT_EQUAL(String("Eurodisco"), frame->fieldList()[1]); @@ -638,8 +713,8 @@ public: "14\0Eurodisco", 23); // Text ID3v2::Header header; ID3v2::TextIdentificationFrame *frame = - static_cast(factory->createFrame(data, &header)); - CPPUNIT_ASSERT_EQUAL((size_t)2, frame->fieldList().size()); + dynamic_cast(factory->createFrame(data, &header)); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("14"), frame->fieldList()[0]); CPPUNIT_ASSERT_EQUAL(String("Eurodisco"), frame->fieldList()[1]); @@ -694,11 +769,11 @@ public: } { MPEG::File bar(newname.c_str()); - tf = static_cast(bar.ID3v2Tag()->frameList("TDOR").front()); + tf = dynamic_cast(bar.ID3v2Tag()->frameList("TDOR").front()); CPPUNIT_ASSERT(tf); CPPUNIT_ASSERT_EQUAL((size_t)1, tf->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("2011"), tf->fieldList().front()); - tf = static_cast(bar.ID3v2Tag()->frameList("TDRC").front()); + tf = dynamic_cast(bar.ID3v2Tag()->frameList("TDRC").front()); CPPUNIT_ASSERT(tf); CPPUNIT_ASSERT_EQUAL((size_t)1, tf->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("2012-04-17T12:01"), tf->fieldList().front()); @@ -731,26 +806,23 @@ public: MPEG::File f(TEST_FILE_PATH_C("compressed_id3_frame.mp3"), false); CPPUNIT_ASSERT(f.ID3v2Tag()->frameListMap().contains("APIC")); -#ifdef HAVE_ZLIB + if(zlib::isAvailable()) { + ID3v2::AttachedPictureFrame *frame + = dynamic_cast(f.ID3v2Tag()->frameListMap()["APIC"].front()); + CPPUNIT_ASSERT(frame); + CPPUNIT_ASSERT_EQUAL(String("image/bmp"), frame->mimeType()); + CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::Other, frame->type()); + CPPUNIT_ASSERT_EQUAL(String(""), frame->description()); + CPPUNIT_ASSERT_EQUAL((unsigned int)86414, frame->picture().size()); + } + else { + // Skip the test if ZLIB is not installed. + // The message "Compressed frames are currently not supported." will be displayed. - ID3v2::AttachedPictureFrame *frame - = dynamic_cast(f.ID3v2Tag()->frameListMap()["APIC"].front()); - CPPUNIT_ASSERT(frame); - CPPUNIT_ASSERT_EQUAL(String("image/bmp"), frame->mimeType()); - CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::Other, frame->type()); - CPPUNIT_ASSERT_EQUAL(String(""), frame->description()); - CPPUNIT_ASSERT_EQUAL((size_t)86414, frame->picture().size()); - -#else - - // Skip the test if ZLIB is not installed. - // The message "Compressed frames are currently not supported." will be displayed. - - ID3v2::UnknownFrame *frame - = dynamic_cast(f.ID3v2Tag()->frameListMap()["APIC"].front()); - CPPUNIT_ASSERT(frame); - -#endif + ID3v2::UnknownFrame *frame + = dynamic_cast(f.ID3v2Tag()->frameListMap()["APIC"].front()); + CPPUNIT_ASSERT(frame); + } } void testW000() @@ -1157,6 +1229,12 @@ public: } } + void testParseTOCFrameWithManyChildren() + { + MPEG::File f(TEST_FILE_PATH_C("toc_many_children.mp3")); + CPPUNIT_ASSERT(f.isValid()); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2); diff --git a/tests/test_info.cpp b/tests/test_info.cpp index ba0f47ee..46e040d7 100644 --- a/tests/test_info.cpp +++ b/tests/test_info.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2012 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_it.cpp b/tests/test_it.cpp index 2fca0540..2604ec9d 100644 --- a/tests/test_it.cpp +++ b/tests/test_it.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include diff --git a/tests/test_list.cpp b/tests/test_list.cpp index fc303220..e314836a 100644 --- a/tests/test_list.cpp +++ b/tests/test_list.cpp @@ -1,26 +1,27 @@ -/* Copyright (C) 2003 Scott Wheeler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ #include #include diff --git a/tests/test_map.cpp b/tests/test_map.cpp index c8f6b7f7..3096ff69 100644 --- a/tests/test_map.cpp +++ b/tests/test_map.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_mod.cpp b/tests/test_mod.cpp index 489f6e26..8208ae29 100644 --- a/tests/test_mod.cpp +++ b/tests/test_mod.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 3c7ebc56..af2e69a2 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2008 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_mp4coverart.cpp b/tests/test_mp4coverart.cpp index 812a2e5d..49ef0470 100644 --- a/tests/test_mp4coverart.cpp +++ b/tests/test_mp4coverart.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_mp4item.cpp b/tests/test_mp4item.cpp index 37d3f719..a9a5c99a 100644 --- a/tests/test_mp4item.cpp +++ b/tests/test_mp4item.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_mpc.cpp b/tests/test_mpc.cpp index 94613c1e..d8ed984e 100644 --- a/tests/test_mpc.cpp +++ b/tests/test_mpc.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2012 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_mpeg.cpp b/tests/test_mpeg.cpp index 72398146..adfc5986 100644 --- a/tests/test_mpeg.cpp +++ b/tests/test_mpeg.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index a648915c..801321ef 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_oggflac.cpp b/tests/test_oggflac.cpp index b8551571..aa9cedc1 100644 --- a/tests/test_oggflac.cpp +++ b/tests/test_oggflac.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_opus.cpp b/tests/test_opus.cpp index 7b8b326a..ac34076c 100644 --- a/tests/test_opus.cpp +++ b/tests/test_opus.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2012 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_propertymap.cpp b/tests/test_propertymap.cpp index aac7430e..76f2862f 100644 --- a/tests/test_propertymap.cpp +++ b/tests/test_propertymap.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2012 by Michael Helmling + email : helmling@mathematik.uni-kl.de + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index 193f32ab..249fd482 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include @@ -186,7 +211,7 @@ public: CPPUNIT_ASSERT_EQUAL((unsigned int)(3), f.chunkDataSize(3)); CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.chunkName(3)); CPPUNIT_ASSERT_EQUAL((unsigned int)(1), f.chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL((unsigned int)(4411 - 8), f.riffSize()); + CPPUNIT_ASSERT_EQUAL((unsigned int)(4412 - 8), f.riffSize()); } { PublicRIFF f(filename.c_str()); @@ -209,6 +234,8 @@ public: PublicRIFF f(filename.c_str()); + CPPUNIT_ASSERT_EQUAL(5928U, f.riffSize()); + CPPUNIT_ASSERT_EQUAL(5936LL, f.length()); CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f.chunkName(0)); CPPUNIT_ASSERT_EQUAL((long long)(0x000C + 8), f.chunkOffset(0)); CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f.chunkName(1)); @@ -218,6 +245,8 @@ public: const ByteVector data(0x400, ' '); f.setChunkData("SSND", data); + CPPUNIT_ASSERT_EQUAL(1070U, f.riffSize()); + CPPUNIT_ASSERT_EQUAL(1078LL, f.length()); CPPUNIT_ASSERT_EQUAL((long long)(0x000C + 8), f.chunkOffset(0)); CPPUNIT_ASSERT_EQUAL((long long)(0x0026 + 8), f.chunkOffset(1)); CPPUNIT_ASSERT_EQUAL((long long)(0x042E + 8), f.chunkOffset(2)); @@ -230,6 +259,8 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); f.setChunkData(0, data); + CPPUNIT_ASSERT_EQUAL(2076U, f.riffSize()); + CPPUNIT_ASSERT_EQUAL(2084LL, f.length()); CPPUNIT_ASSERT_EQUAL((long long)(0x000C + 8), f.chunkOffset(0)); CPPUNIT_ASSERT_EQUAL((long long)(0x0414 + 8), f.chunkOffset(1)); CPPUNIT_ASSERT_EQUAL((long long)(0x081C + 8), f.chunkOffset(2)); @@ -242,6 +273,8 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); f.removeChunk("SSND"); + CPPUNIT_ASSERT_EQUAL(1044U, f.riffSize()); + CPPUNIT_ASSERT_EQUAL(1052LL, f.length()); CPPUNIT_ASSERT_EQUAL((long long)(0x000C + 8), f.chunkOffset(0)); CPPUNIT_ASSERT_EQUAL((long long)(0x0414 + 8), f.chunkOffset(1)); @@ -251,6 +284,7 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f.readBlock(4)); f.removeChunk(0); + CPPUNIT_ASSERT_EQUAL(12U, f.riffSize()); CPPUNIT_ASSERT_EQUAL((long long)(0x000C + 8), f.chunkOffset(0)); f.seek(f.chunkOffset(0) - 8); diff --git a/tests/test_s3m.cpp b/tests/test_s3m.cpp index b55430d6..a2cc05ae 100644 --- a/tests/test_s3m.cpp +++ b/tests/test_s3m.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include diff --git a/tests/test_speex.cpp b/tests/test_speex.cpp index b61afa35..8af9de16 100644 --- a/tests/test_speex.cpp +++ b/tests/test_speex.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2015 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_string.cpp b/tests/test_string.cpp index 0aa8cfdd..e0e298f6 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -1,26 +1,27 @@ -/* Copyright (C) 2003 Scott Wheeler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ #include #include @@ -46,7 +47,8 @@ class TestString : public CppUnit::TestFixture CPPUNIT_TEST(testSubstr); CPPUNIT_TEST(testNewline); CPPUNIT_TEST(testUpper); - CPPUNIT_TEST(testEncode); + CPPUNIT_TEST(testEncodeNonLatin1); + CPPUNIT_TEST(testEncodeEmpty); CPPUNIT_TEST(testIterator); CPPUNIT_TEST_SUITE_END(); @@ -104,29 +106,12 @@ public: String unicode6(L"\u65e5\u672c\u8a9e", String::UTF16LE); CPPUNIT_ASSERT(unicode6[1] == (littleEndian ? L'\u672c' : L'\u2c67')); - std::wstring stduni = L"\u65e5\u672c\u8a9e"; - - String unicode7(stduni); - CPPUNIT_ASSERT(unicode7[1] == L'\u672c'); - - String unicode8(stduni, String::UTF16BE); - CPPUNIT_ASSERT(unicode8[1] == (littleEndian ? L'\u2c67' : L'\u672c')); - - String unicode9(stduni, String::UTF16LE); - CPPUNIT_ASSERT(unicode9[1] == (littleEndian ? L'\u672c' : L'\u2c67')); - CPPUNIT_ASSERT(String(" foo ").stripWhiteSpace() == String("foo")); CPPUNIT_ASSERT(String("foo ").stripWhiteSpace() == String("foo")); CPPUNIT_ASSERT(String(" foo").stripWhiteSpace() == String("foo")); CPPUNIT_ASSERT(memcmp(String("foo").data(String::Latin1).data(), "foo", 3) == 0); CPPUNIT_ASSERT(memcmp(String("f").data(String::Latin1).data(), "f", 1) == 0); - - // Check to make sure that the BOM is there and that the data size is correct - - const ByteVector utf16 = unicode.data(String::UTF16); - CPPUNIT_ASSERT(utf16.size() == 2 + (unicode.size() * 2)); - CPPUNIT_ASSERT(unicode == String(utf16, String::UTF16)); } void testUTF16Encode() @@ -258,6 +243,9 @@ public: String("9999999999").toInt(&ok); CPPUNIT_ASSERT_EQUAL(ok, false); + CPPUNIT_ASSERT_EQUAL(String("0000").toInt(), 0); + CPPUNIT_ASSERT_EQUAL(String("0001").toInt(), 1); + String("2147483648").toInt(&ok); CPPUNIT_ASSERT_EQUAL(ok, false); @@ -267,8 +255,9 @@ public: void testFromInt() { - CPPUNIT_ASSERT_EQUAL(String("123"), String::number(123)); - CPPUNIT_ASSERT_EQUAL(String("-123"), String::number(-123)); + CPPUNIT_ASSERT_EQUAL(String::number(0), String("0")); + CPPUNIT_ASSERT_EQUAL(String::number(12345678), String("12345678")); + CPPUNIT_ASSERT_EQUAL(String::number(-12345678), String("-12345678")); } void testSubstr() @@ -302,41 +291,28 @@ public: CPPUNIT_ASSERT_EQUAL(String("TAGLIB 012 STRING"), s2); } - void testEncode() + void testEncodeNonLatin1() { - String jpn(L"\u65E5\u672C\u8A9E"); - ByteVector jpn1 = jpn.data(String::Latin1); - ByteVector jpn2 = jpn.data(String::UTF8); - ByteVector jpn3 = jpn.data(String::UTF16); - ByteVector jpn4 = jpn.data(String::UTF16LE); - ByteVector jpn5 = jpn.data(String::UTF16BE); - std::string jpn6 = jpn.to8Bit(false); - std::string jpn7 = jpn.to8Bit(true); + const String jpn(L"\u65E5\u672C\u8A9E"); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x2C\x9E"), jpn.data(String::Latin1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn.data(String::UTF8)); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE\xE5\x65\x2C\x67\x9E\x8A"), jpn.data(String::UTF16)); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x65\x2C\x67\x9E\x8A"), jpn.data(String::UTF16LE)); + CPPUNIT_ASSERT_EQUAL(ByteVector("\x65\xE5\x67\x2C\x8A\x9E"), jpn.data(String::UTF16BE)); + CPPUNIT_ASSERT_EQUAL(std::string("\xE5\x2C\x9E"), jpn.to8Bit(false)); + CPPUNIT_ASSERT_EQUAL(std::string("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn.to8Bit(true)); + } - CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x2C\x9E"), jpn1); - CPPUNIT_ASSERT_EQUAL(ByteVector("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn2); - CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE\xE5\x65\x2C\x67\x9E\x8A"), jpn3); - CPPUNIT_ASSERT_EQUAL(ByteVector("\xE5\x65\x2C\x67\x9E\x8A"), jpn4); - CPPUNIT_ASSERT_EQUAL(ByteVector("\x65\xE5\x67\x2C\x8A\x9E"), jpn5); - CPPUNIT_ASSERT_EQUAL(std::string("\xE5\x2C\x9E"), jpn6); - CPPUNIT_ASSERT_EQUAL(std::string("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E"), jpn7); - - String empty; - ByteVector empty1 = empty.data(String::Latin1); - ByteVector empty2 = empty.data(String::UTF8); - ByteVector empty3 = empty.data(String::UTF16); - ByteVector empty4 = empty.data(String::UTF16LE); - ByteVector empty5 = empty.data(String::UTF16BE); - std::string empty6 = empty.to8Bit(false); - std::string empty7 = empty.to8Bit(true); - - CPPUNIT_ASSERT(empty1.isEmpty()); - CPPUNIT_ASSERT(empty2.isEmpty()); - CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE"), empty3); - CPPUNIT_ASSERT(empty4.isEmpty()); - CPPUNIT_ASSERT(empty5.isEmpty()); - CPPUNIT_ASSERT(empty6.empty()); - CPPUNIT_ASSERT(empty7.empty()); + void testEncodeEmpty() + { + const String empty; + CPPUNIT_ASSERT(empty.data(String::Latin1).isEmpty()); + CPPUNIT_ASSERT(empty.data(String::UTF8).isEmpty()); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xFF\xFE"), empty.data(String::UTF16)); + CPPUNIT_ASSERT(empty.data(String::UTF16LE).isEmpty()); + CPPUNIT_ASSERT(empty.data(String::UTF16BE).isEmpty()); + CPPUNIT_ASSERT(empty.to8Bit(false).empty()); + CPPUNIT_ASSERT(empty.to8Bit(true).empty()); } void testIterator() diff --git a/tests/test_synchdata.cpp b/tests/test_synchdata.cpp index 46bd4229..c593e93d 100644 --- a/tests/test_synchdata.cpp +++ b/tests/test_synchdata.cpp @@ -1,26 +1,28 @@ -/* Copyright (C) 2003 Scott Wheeler - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include @@ -38,6 +40,8 @@ class TestID3v2SynchData : public CppUnit::TestFixture CPPUNIT_TEST(testToUIntBrokenAndTooLarge); CPPUNIT_TEST(testDecode1); CPPUNIT_TEST(testDecode2); + CPPUNIT_TEST(testDecode3); + CPPUNIT_TEST(testDecode4); CPPUNIT_TEST_SUITE_END(); public: @@ -102,6 +106,22 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("\xff\x44", 2), a); } + void testDecode3() + { + ByteVector a("\xff\xff\x00", 3); + a = ID3v2::SynchData::decode(a); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, a.size()); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xff\xff", 2), a); + } + + void testDecode4() + { + ByteVector a("\xff\xff\xff", 3); + a = ID3v2::SynchData::decode(a); + CPPUNIT_ASSERT_EQUAL((unsigned int)3, a.size()); + CPPUNIT_ASSERT_EQUAL(ByteVector("\xff\xff\xff", 3), a); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2SynchData); diff --git a/tests/test_trueaudio.cpp b/tests/test_trueaudio.cpp index c960f5f7..81393ff3 100644 --- a/tests/test_trueaudio.cpp +++ b/tests/test_trueaudio.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp index ade4f3f7..fdddc628 100644 --- a/tests/test_wav.cpp +++ b/tests/test_wav.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2010 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_wavpack.cpp b/tests/test_wavpack.cpp index 39bc1edd..65a27c76 100644 --- a/tests/test_wavpack.cpp +++ b/tests/test_wavpack.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2010 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_xiphcomment.cpp b/tests/test_xiphcomment.cpp index 20a8a6f6..3dcfb4d2 100644 --- a/tests/test_xiphcomment.cpp +++ b/tests/test_xiphcomment.cpp @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2009 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #include #include #include diff --git a/tests/test_xm.cpp b/tests/test_xm.cpp index 51200de5..3b9c3110 100644 --- a/tests/test_xm.cpp +++ b/tests/test_xm.cpp @@ -5,7 +5,7 @@ /*************************************************************************** * This library is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License version * + * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, but * @@ -15,8 +15,12 @@ * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301 USA * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * ***************************************************************************/ #include diff --git a/tests/utils.h b/tests/utils.h index 99a7c669..7cfe9a8d 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,3 +1,28 @@ +/*************************************************************************** + copyright : (C) 2007 by Lukas Lalinsky + email : lukas@oxygene.sk + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + #ifdef HAVE_CONFIG_H #include #endif