]> granicus.if.org Git - taglib/commitdiff
Fix segfaults when calling File::properties() after strip().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 3 Aug 2015 14:41:26 +0000 (23:41 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 25 Aug 2015 02:03:00 +0000 (11:03 +0900)
Backport TagUnion::properties() and TagUnion::removeUnsupportedProperties() from taglib2.

15 files changed:
taglib/ape/apefile.cpp
taglib/flac/flacfile.cpp
taglib/mpc/mpcfile.cpp
taglib/mpeg/mpegfile.cpp
taglib/riff/wav/wavfile.cpp
taglib/tagunion.cpp
taglib/tagunion.h
taglib/trueaudio/trueaudiofile.cpp
taglib/wavpack/wavpackfile.cpp
tests/test_ape.cpp
tests/test_mpc.cpp
tests/test_mpeg.cpp
tests/test_trueaudio.cpp
tests/test_wav.cpp
tests/test_wavpack.cpp

index c774f5160bdece12fc4e1ab9cb74fdd475de02e8..1349dfa3066b13aad39084743af02bf592d97736 100644 (file)
@@ -125,26 +125,20 @@ TagLib::Tag *APE::File::tag() const
 
 PropertyMap APE::File::properties() const
 {
-  if(d->hasAPE)
-    return d->tag.access<APE::Tag>(ApeAPEIndex, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(ApeID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
 void APE::File::removeUnsupportedProperties(const StringList &properties)
 {
-  if(d->hasAPE)
-    d->tag.access<APE::Tag>(ApeAPEIndex, false)->removeUnsupportedProperties(properties);
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(ApeID3v1Index, false)->removeUnsupportedProperties(properties);
+  d->tag.removeUnsupportedProperties(properties);
 }
 
 PropertyMap APE::File::setProperties(const PropertyMap &properties)
 {
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(ApeID3v1Index, false)->setProperties(properties);
-  return d->tag.access<APE::Tag>(ApeAPEIndex, true)->setProperties(properties);
+  if(ID3v1Tag())
+    ID3v1Tag()->setProperties(properties);
+
+  return APETag(true)->setProperties(properties);
 }
 
 APE::Properties *APE::File::audioProperties() const
index 4d2d69e65a9614df2ffe32fa08c888e055bc8235..dc8f4011ed4251df38b84662e6f01c9606e68bcf 100644 (file)
@@ -141,30 +141,17 @@ TagLib::Tag *FLAC::File::tag() const
 
 PropertyMap FLAC::File::properties() const
 {
-  // once Tag::properties() is virtual, this case distinction could actually be done
-  // within TagUnion.
-  if(d->hasXiphComment)
-    return d->tag.access<Ogg::XiphComment>(FlacXiphIndex, false)->properties();
-  if(d->hasID3v2)
-    return d->tag.access<ID3v2::Tag>(FlacID3v2Index, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(FlacID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
 void FLAC::File::removeUnsupportedProperties(const StringList &unsupported)
 {
-  if(d->hasXiphComment)
-    d->tag.access<Ogg::XiphComment>(FlacXiphIndex, false)->removeUnsupportedProperties(unsupported);
-  if(d->hasID3v2)
-    d->tag.access<ID3v2::Tag>(FlacID3v2Index, false)->removeUnsupportedProperties(unsupported);
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(FlacID3v1Index, false)->removeUnsupportedProperties(unsupported);
+  d->tag.removeUnsupportedProperties(unsupported);
 }
 
 PropertyMap FLAC::File::setProperties(const PropertyMap &properties)
 {
-  return d->tag.access<Ogg::XiphComment>(FlacXiphIndex, true)->setProperties(properties);
+  return xiphComment(true)->setProperties(properties);
 }
 
 FLAC::Properties *FLAC::File::audioProperties() const
index cf5f38d8a90fd2b5947deec857340104bf313747..6d8dae5a197204ed48c9288fc6b4193b26f7dbf4 100644 (file)
@@ -116,26 +116,20 @@ TagLib::Tag *MPC::File::tag() const
 
 PropertyMap MPC::File::properties() const
 {
-  if(d->hasAPE)
-    return d->tag.access<APE::Tag>(MPCAPEIndex, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(MPCID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
 void MPC::File::removeUnsupportedProperties(const StringList &properties)
 {
-  if(d->hasAPE)
-    d->tag.access<APE::Tag>(MPCAPEIndex, false)->removeUnsupportedProperties(properties);
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(MPCID3v1Index, false)->removeUnsupportedProperties(properties);
+  d->tag.removeUnsupportedProperties(properties);
 }
 
 PropertyMap MPC::File::setProperties(const PropertyMap &properties)
 {
-  if(d->hasID3v1)
-    d->tag.access<APE::Tag>(MPCID3v1Index, false)->setProperties(properties);
-  return d->tag.access<APE::Tag>(MPCAPEIndex, true)->setProperties(properties);
+  if(ID3v1Tag())
+    ID3v1Tag()->setProperties(properties);
+
+  return APETag(true)->setProperties(properties);
 }
 
 MPC::Properties *MPC::File::audioProperties() const
index 43075cfc091528eebde9ee374ef015ba987ced28..5ced51ef76a2d21640ad9e9bf95a297ddde31ce2 100644 (file)
@@ -149,33 +149,22 @@ TagLib::Tag *MPEG::File::tag() const
 
 PropertyMap MPEG::File::properties() const
 {
-  // once Tag::properties() is virtual, this case distinction could actually be done
-  // within TagUnion.
-  if(d->hasID3v2)
-    return d->tag.access<ID3v2::Tag>(ID3v2Index, false)->properties();
-  if(d->hasAPE)
-    return d->tag.access<APE::Tag>(APEIndex, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(ID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
 void MPEG::File::removeUnsupportedProperties(const StringList &properties)
 {
-  if(d->hasID3v2)
-    d->tag.access<ID3v2::Tag>(ID3v2Index, false)->removeUnsupportedProperties(properties);
-  else if(d->hasAPE)
-    d->tag.access<APE::Tag>(APEIndex, false)->removeUnsupportedProperties(properties);
-  else if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->removeUnsupportedProperties(properties);
+  d->tag.removeUnsupportedProperties(properties);
 }
 
 PropertyMap MPEG::File::setProperties(const PropertyMap &properties)
 {
-  if(d->hasID3v1)
-    // update ID3v1 tag if it exists, but ignore the return value
-    d->tag.access<ID3v1::Tag>(ID3v1Index, false)->setProperties(properties);
-  return d->tag.access<ID3v2::Tag>(ID3v2Index, true)->setProperties(properties);
+  // update ID3v1 tag if it exists, but ignore the return value
+
+  if(ID3v1Tag())
+    ID3v1Tag()->setProperties(properties);
+
+  return ID3v2Tag(true)->setProperties(properties);
 }
 
 MPEG::Properties *MPEG::File::audioProperties() const
index cab8b33b6a3339cdd72f3fb0a5f6059e6dc8eaa4..d387d79e73e0d1abd56f1a57b64f1c3a25a5fc2f 100644 (file)
@@ -119,17 +119,18 @@ void RIFF::WAV::File::strip(TagTypes tags)
 
 PropertyMap RIFF::WAV::File::properties() const
 {
-  return tag()->properties();
+  return d->tag.properties();
 }
 
 void RIFF::WAV::File::removeUnsupportedProperties(const StringList &unsupported)
 {
-  tag()->removeUnsupportedProperties(unsupported);
+  d->tag.removeUnsupportedProperties(unsupported);
 }
 
 PropertyMap RIFF::WAV::File::setProperties(const PropertyMap &properties)
 {
-  return tag()->setProperties(properties);
+  InfoTag()->setProperties(properties);
+  return ID3v2Tag()->setProperties(properties);
 }
 
 RIFF::WAV::Properties *RIFF::WAV::File::audioProperties() const
index 52d7136b464fac2a147115bb7392e9d1cbbb8ec7..a6743d144939a1b5f384c369d3f733c0200e6c3f 100644 (file)
  *   http://www.mozilla.org/MPL/                                           *
  ***************************************************************************/
 
-#include "tagunion.h"
-#include "tstringlist.h"
+#include <tagunion.h>
+#include <tstringlist.h>
+#include <tpropertymap.h>
+
+#include "id3v1tag.h"
+#include "id3v2tag.h"
+#include "apetag.h"
+#include "xiphcomment.h"
+#include "infotag.h"
 
 using namespace TagLib;
 
@@ -102,6 +109,62 @@ void TagUnion::set(int index, Tag *tag)
   d->tags[index] = tag;
 }
 
+PropertyMap TagUnion::properties() const
+{
+  // This is an ugly workaround but we can't add a virtual function.
+  // Should be virtual in taglib2.
+
+  for(size_t i = 0; i < 3; ++i) {
+
+    if(d->tags[i] && !d->tags[i]->isEmpty()) {
+
+      if(dynamic_cast<const ID3v1::Tag *>(d->tags[i]))
+        return dynamic_cast<const ID3v1::Tag *>(d->tags[i])->properties();
+
+      else if(dynamic_cast<const ID3v2::Tag *>(d->tags[i]))
+        return dynamic_cast<const ID3v2::Tag *>(d->tags[i])->properties();
+
+      else if(dynamic_cast<const APE::Tag *>(d->tags[i]))
+        return dynamic_cast<const APE::Tag *>(d->tags[i])->properties();
+
+      else if(dynamic_cast<const Ogg::XiphComment *>(d->tags[i]))
+        return dynamic_cast<const Ogg::XiphComment *>(d->tags[i])->properties();
+
+      else if(dynamic_cast<const RIFF::Info::Tag *>(d->tags[i]))
+        return dynamic_cast<const RIFF::Info::Tag *>(d->tags[i])->properties();
+    }
+  }
+
+  return PropertyMap();
+}
+
+void TagUnion::removeUnsupportedProperties(const StringList &unsupported)
+{
+  // This is an ugly workaround but we can't add a virtual function.
+  // Should be virtual in taglib2.
+
+  for(size_t i = 0; i < 3; ++i) {
+
+    if(d->tags[i]) {
+
+      if(dynamic_cast<ID3v1::Tag *>(d->tags[i]))
+        dynamic_cast<ID3v1::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
+
+      else if(dynamic_cast<ID3v2::Tag *>(d->tags[i]))
+        dynamic_cast<ID3v2::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
+
+      else if(dynamic_cast<APE::Tag *>(d->tags[i]))
+        dynamic_cast<APE::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
+
+      else if(dynamic_cast<Ogg::XiphComment *>(d->tags[i]))
+        dynamic_cast<Ogg::XiphComment *>(d->tags[i])->removeUnsupportedProperties(unsupported);
+
+      else if(dynamic_cast<RIFF::Info::Tag *>(d->tags[i]))
+        dynamic_cast<RIFF::Info::Tag *>(d->tags[i])->removeUnsupportedProperties(unsupported);
+    }
+  }
+}
+
 String TagUnion::title() const
 {
   stringUnion(title);
index e94d523a3bd64575e49a189509a24611b5c947ad..0a3b3a209b7a353ecef0954338ce9acfa132314d 100644 (file)
@@ -56,6 +56,9 @@ namespace TagLib {
 
     void set(int index, Tag *tag);
 
+    PropertyMap properties() const;
+    void removeUnsupportedProperties(const StringList &unsupported);
+
     virtual String title() const;
     virtual String artist() const;
     virtual String album() const;
index 8f40564cdf60ac6dcc21b8a97db652b350a35cf3..4ca60915c2c9f0f7647ff8208f1b71c283a1d987 100644 (file)
@@ -130,26 +130,20 @@ TagLib::Tag *TrueAudio::File::tag() const
 
 PropertyMap TrueAudio::File::properties() const
 {
-  // once Tag::properties() is virtual, this case distinction could actually be done
-  // within TagUnion.
-  if(d->hasID3v2)
-    return d->tag.access<ID3v2::Tag>(TrueAudioID3v2Index, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(TrueAudioID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
 void TrueAudio::File::removeUnsupportedProperties(const StringList &unsupported)
 {
-  if(d->hasID3v2)
-    d->tag.access<ID3v2::Tag>(TrueAudioID3v2Index, false)->removeUnsupportedProperties(unsupported);
+  d->tag.removeUnsupportedProperties(unsupported);
 }
 
 PropertyMap TrueAudio::File::setProperties(const PropertyMap &properties)
 {
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(TrueAudioID3v1Index, false)->setProperties(properties);
-  return d->tag.access<ID3v2::Tag>(TrueAudioID3v2Index, true)->setProperties(properties);
+  if(ID3v1Tag())
+    ID3v1Tag()->setProperties(properties);
+
+  return ID3v2Tag(true)->setProperties(properties);
 }
 
 TrueAudio::Properties *TrueAudio::File::audioProperties() const
index de0ba4159c1efa256f1d8b7713a249a37a86a140..90f79d162974faeea49ca7820b9a5c9eab1610a2 100644 (file)
@@ -110,26 +110,20 @@ TagLib::Tag *WavPack::File::tag() const
 
 PropertyMap WavPack::File::properties() const
 {
-  if(d->hasAPE)
-    return d->tag.access<APE::Tag>(WavAPEIndex, false)->properties();
-  if(d->hasID3v1)
-    return d->tag.access<ID3v1::Tag>(WavID3v1Index, false)->properties();
-  return PropertyMap();
+  return d->tag.properties();
 }
 
-
 void WavPack::File::removeUnsupportedProperties(const StringList &unsupported)
 {
-  if(d->hasAPE)
-    d->tag.access<APE::Tag>(WavAPEIndex, false)->removeUnsupportedProperties(unsupported);
+  d->tag.removeUnsupportedProperties(unsupported);
 }
 
-
 PropertyMap WavPack::File::setProperties(const PropertyMap &properties)
 {
-  if(d->hasID3v1)
-    d->tag.access<ID3v1::Tag>(WavID3v1Index, false)->setProperties(properties);
-  return d->tag.access<APE::Tag>(WavAPEIndex, true)->setProperties(properties);
+  if(ID3v1Tag())
+    ID3v1Tag()->setProperties(properties);
+
+  return APETag(true)->setProperties(properties);
 }
 
 WavPack::Properties *WavPack::File::audioProperties() const
index 3ab3197b67d9090bb4211cbf0ef7cdadb8f0997c..64869c4c5b6f1261b2e09dc47ab1c6f314d32dc1 100644 (file)
@@ -1,8 +1,10 @@
 #include <string>
 #include <stdio.h>
-#include <tag.h>
+#include <apetag.h>
+#include <id3v1tag.h>
 #include <tstringlist.h>
 #include <tbytevectorlist.h>
+#include <tpropertymap.h>
 #include <apefile.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include "utils.h"
@@ -20,6 +22,7 @@ class TestAPE : public CppUnit::TestFixture
   CPPUNIT_TEST(testProperties390);
   CPPUNIT_TEST(testFuzzedFile1);
   CPPUNIT_TEST(testFuzzedFile2);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -111,6 +114,26 @@ public:
     CPPUNIT_ASSERT(f.isValid());
   }
 
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("mac-399", ".ape");
+
+    {
+      APE::File f(copy.fileName().c_str());
+      f.APETag(true)->setTitle("APE");
+      f.ID3v1Tag(true)->setTitle("ID3v1");
+      f.save();
+    }
+    {
+      APE::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
+      f.strip(APE::File::APE);
+      CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
+      f.strip(APE::File::ID3v1);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestAPE);
index 50a62d22a1b1ae1437604bb2bb9670cff445c4f0..ec1e9f1c1860635d0af62919b013af67ce9a0be3 100644 (file)
@@ -1,8 +1,10 @@
 #include <string>
 #include <stdio.h>
-#include <tag.h>
+#include <apetag.h>
+#include <id3v1tag.h>
 #include <tstringlist.h>
 #include <tbytevectorlist.h>
+#include <tpropertymap.h>
 #include <mpcfile.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include "utils.h"
@@ -21,6 +23,7 @@ class TestMPC : public CppUnit::TestFixture
   CPPUNIT_TEST(testFuzzedFile2);
   CPPUNIT_TEST(testFuzzedFile3);
   CPPUNIT_TEST(testFuzzedFile4);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -109,6 +112,26 @@ public:
     CPPUNIT_ASSERT(f.isValid());
   }
 
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("click", ".mpc");
+
+    {
+      MPC::File f(copy.fileName().c_str());
+      f.APETag(true)->setTitle("APE");
+      f.ID3v1Tag(true)->setTitle("ID3v1");
+      f.save();
+    }
+    {
+      MPC::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
+      f.strip(MPC::File::APE);
+      CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
+      f.strip(MPC::File::ID3v1);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestMPC);
index 8d49a8c7b039ae708c27b6ad2b904e514410c556..ee3575e34602968e69a4373625e62f14714dd6b6 100644 (file)
@@ -1,8 +1,11 @@
 #include <string>
 #include <stdio.h>
 #include <tstring.h>
+#include <tpropertymap.h>
 #include <mpegfile.h>
 #include <id3v2tag.h>
+#include <id3v1tag.h>
+#include <apetag.h>
 #include <mpegproperties.h>
 #include <xingheader.h>
 #include <mpegheader.h>
@@ -26,6 +29,7 @@ class TestMPEG : public CppUnit::TestFixture
   CPPUNIT_TEST(testDuplicateID3v2);
   CPPUNIT_TEST(testFuzzedFile);
   CPPUNIT_TEST(testFrameOffset);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -212,6 +216,29 @@ public:
     }
   }
 
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("xing", ".mp3");
+
+    {
+      MPEG::File f(copy.fileName().c_str());
+      f.ID3v2Tag(true)->setTitle("ID3v2");
+      f.APETag(true)->setTitle("APE");
+      f.ID3v1Tag(true)->setTitle("ID3v1");
+      f.save();
+    }
+    {
+      MPEG::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
+      f.strip(MPEG::File::ID3v2);
+      CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
+      f.strip(MPEG::File::APE);
+      CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
+      f.strip(MPEG::File::ID3v1);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG);
index 00b81edee9a994610efe8f40a55617fdfcafb5cc..8468e0ec3d6724e18d3dbfe2ba34a9b9c3a43115 100644 (file)
@@ -1,5 +1,8 @@
 #include <string>
 #include <stdio.h>
+#include <id3v1tag.h>
+#include <id3v2tag.h>
+#include <tpropertymap.h>
 #include <trueaudiofile.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include "utils.h"
@@ -12,6 +15,7 @@ class TestTrueAudio : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE(TestTrueAudio);
   CPPUNIT_TEST(testReadPropertiesWithoutID3v2);
   CPPUNIT_TEST(testReadPropertiesWithTags);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -46,6 +50,26 @@ public:
     CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion());
   }
 
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("empty", ".tta");
+
+    {
+      TrueAudio::File f(copy.fileName().c_str());
+      f.ID3v2Tag(true)->setTitle("ID3v2");
+      f.ID3v1Tag(true)->setTitle("ID3v1");
+      f.save();
+    }
+    {
+      TrueAudio::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
+      f.strip(TrueAudio::File::ID3v2);
+      CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
+      f.strip(TrueAudio::File::ID3v1);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestTrueAudio);
index bcb91753098ec923a8ca498dda95315014bd2749..e2463790e2e5a31006c013b5602b76a89a87cf90 100644 (file)
@@ -1,9 +1,9 @@
 #include <string>
 #include <stdio.h>
-#include <tag.h>
 #include <id3v2tag.h>
 #include <infotag.h>
 #include <tbytevectorlist.h>
+#include <tpropertymap.h>
 #include <wavfile.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include "utils.h"
@@ -24,6 +24,7 @@ class TestWAV : public CppUnit::TestFixture
   CPPUNIT_TEST(testDuplicateTags);
   CPPUNIT_TEST(testFuzzedFile1);
   CPPUNIT_TEST(testFuzzedFile2);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -211,6 +212,26 @@ public:
     CPPUNIT_ASSERT(f2.isValid());
   }
 
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("empty", ".wav");
+
+    {
+      RIFF::WAV::File f(copy.fileName().c_str());
+      f.ID3v2Tag()->setTitle("ID3v2");
+      f.InfoTag()->setTitle("INFO");
+      f.save();
+    }
+    {
+      RIFF::WAV::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
+      f.strip(RIFF::WAV::File::ID3v2);
+      CPPUNIT_ASSERT_EQUAL(String("INFO"), f.properties()["TITLE"].front());
+      f.strip(RIFF::WAV::File::Info);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);
index 5befbff3c0e8f3f897098832e8f949fe0b2c094a..eddc601d23c781905764aafc108445ccfc4a709b 100644 (file)
@@ -1,7 +1,9 @@
 #include <string>
 #include <stdio.h>
-#include <tag.h>
+#include <apetag.h>
+#include <id3v1tag.h>
 #include <tbytevectorlist.h>
+#include <tpropertymap.h>
 #include <wavpackfile.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include "utils.h"
@@ -16,6 +18,7 @@ class TestWavPack : public CppUnit::TestFixture
   CPPUNIT_TEST(testMultiChannelProperties);
   CPPUNIT_TEST(testTaggedProperties);
   CPPUNIT_TEST(testFuzzedFile);
+  CPPUNIT_TEST(testStripAndProperties);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -73,6 +76,27 @@ public:
     WavPack::File f(TEST_FILE_PATH_C("infloop.wv"));
     CPPUNIT_ASSERT(f.isValid());
   }
+
+  void testStripAndProperties()
+  {
+    ScopedFileCopy copy("click", ".wv");
+
+    {
+      WavPack::File f(copy.fileName().c_str());
+      f.APETag(true)->setTitle("APE");
+      f.ID3v1Tag(true)->setTitle("ID3v1");
+      f.save();
+    }
+    {
+      WavPack::File f(copy.fileName().c_str());
+      CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
+      f.strip(WavPack::File::APE);
+      CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
+      f.strip(WavPack::File::ID3v1);
+      CPPUNIT_ASSERT(f.properties().isEmpty());
+    }
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestWavPack);