From fed2c020fe90d66c928e51231e0538d299b014c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Fri, 23 Nov 2007 06:54:22 +0000 Subject: [PATCH] Fix TTA audio properties reading. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@740388 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/trueaudio/trueaudiofile.cpp | 13 +++++++++--- taglib/trueaudio/trueaudioproperties.cpp | 2 +- tests/CMakeLists.txt | 2 ++ tests/Makefile.am | 2 ++ tests/test_trueaudio.cpp | 26 ++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 tests/test_trueaudio.cpp diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp index b91e3f9b..18b7a911 100644 --- a/taglib/trueaudio/trueaudiofile.cpp +++ b/taglib/trueaudio/trueaudiofile.cpp @@ -273,9 +273,16 @@ void TrueAudio::File::read(bool readProperties, Properties::ReadStyle /* propert // Look for TrueAudio metadata if(readProperties) { - seek(d->ID3v2Location + d->ID3v2OriginalSize); - d->properties = new Properties(readBlock(TrueAudio::HeaderSize), - length() - d->ID3v2OriginalSize); + if(d->ID3v2Location >= 0) { + seek(d->ID3v2Location + d->ID3v2OriginalSize); + d->properties = new Properties(readBlock(TrueAudio::HeaderSize), + length() - d->ID3v2OriginalSize); + } + else { + seek(0); + d->properties = new Properties(readBlock(TrueAudio::HeaderSize), + length()); + } } } diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index ef7bdd51..ff65edf9 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -112,7 +112,7 @@ int TrueAudio::Properties::ttaVersion() const void TrueAudio::Properties::read() { - if(!d->data.startsWith("TrueAudio")) + if(!d->data.startsWith("TTA")) return; int pos = 3; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 72040d0f..88c08098 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2 ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2/frames ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/trueaudio ) SET(test_runner_SRCS @@ -15,6 +16,7 @@ SET(test_runner_SRCS test_map.cpp test_mpeg.cpp test_synchdata.cpp + test_trueaudio.cpp test_bytevector.cpp test_string.cpp test_fileref.cpp diff --git a/tests/Makefile.am b/tests/Makefile.am index 1c24d94f..65191808 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ INCLUDES = \ -I$(top_srcdir)/taglib\ -I$(top_srcdir)/taglib/toolkit \ + -I$(top_srcdir)/taglib/trueaudio \ -I$(top_srcdir)/taglib/mpeg \ -I$(top_srcdir)/taglib/mpeg/id3v1 \ -I$(top_srcdir)/taglib/mpeg/id3v2 \ @@ -12,6 +13,7 @@ test_runner_SOURCES = \ test_map.cpp \ test_mpeg.cpp \ test_synchdata.cpp \ + test_trueaudio.cpp \ test_bytevector.cpp \ test_string.cpp \ test_fileref.cpp \ diff --git a/tests/test_trueaudio.cpp b/tests/test_trueaudio.cpp new file mode 100644 index 00000000..b300eef9 --- /dev/null +++ b/tests/test_trueaudio.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +using namespace std; +using namespace TagLib; + +class TestTrueAudio : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(TestTrueAudio); + CPPUNIT_TEST(testReadPropertiesWithoutID3v2); + CPPUNIT_TEST_SUITE_END(); + +public: + + void testReadPropertiesWithoutID3v2() + { + TrueAudio::File f("data/empty.tta"); + CPPUNIT_ASSERT(f.audioProperties()); + CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length()); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(TestTrueAudio);