Exemplo n.º 1
0
 void testIsEmpty2()
 {
   APE::Tag tag;
   CPPUNIT_ASSERT(tag.isEmpty());
   tag.setArtist("Mike Oldfield");
   CPPUNIT_ASSERT(!tag.isEmpty());
 }
Exemplo n.º 2
0
 void testIsEmpty()
 {
   APE::Tag tag;
   CPPUNIT_ASSERT(tag.isEmpty());
   tag.addValue("COMPOSER", "Mike Oldfield");
   CPPUNIT_ASSERT(!tag.isEmpty());
 }
Exemplo n.º 3
0
  void testPropertyInterface2()
  {
    APE::Tag tag;
    APE::Item item1 = APE::Item("TRACK", "17");
    tag.setItem("TRACK", item1);

    APE::Item item2 = APE::Item();
    item2.setType(APE::Item::Binary);
    tag.setItem("TESTBINARY", item2);

    PropertyMap properties = tag.properties();
    CPPUNIT_ASSERT_EQUAL(1u, properties.unsupportedData().size());
    CPPUNIT_ASSERT(properties.contains("TRACKNUMBER"));
    CPPUNIT_ASSERT(!properties.contains("TRACK"));
    CPPUNIT_ASSERT(tag.itemListMap().contains("TESTBINARY"));

    tag.removeUnsupportedProperties(properties.unsupportedData());
    CPPUNIT_ASSERT(!tag.itemListMap().contains("TESTBINARY"));

    APE::Item item3 = APE::Item("TRACKNUMBER", "29");
    tag.setItem("TRACKNUMBER", item3);
    properties = tag.properties();
    CPPUNIT_ASSERT_EQUAL((unsigned int)2, properties["TRACKNUMBER"].size());
    CPPUNIT_ASSERT_EQUAL(String("17"), properties["TRACKNUMBER"][0]);
    CPPUNIT_ASSERT_EQUAL(String("29"), properties["TRACKNUMBER"][1]);

  }
Exemplo n.º 4
0
  void testInvalidKeys()
  {
    PropertyMap properties;
    properties["A"] = String("invalid key: one character");
    properties["MP+"] = String("invalid key: forbidden string");
    properties["A B~C"] = String("valid key: space and tilde");
    properties["ARTIST"] = String("valid key: normal one");

    APE::Tag tag;
    PropertyMap unsuccessful = tag.setProperties(properties);
    CPPUNIT_ASSERT_EQUAL((unsigned int)2, unsuccessful.size());
    CPPUNIT_ASSERT(unsuccessful.contains("A"));
    CPPUNIT_ASSERT(unsuccessful.contains("MP+"));
  }
Exemplo n.º 5
0
 void testPropertyInterface1()
 {
   APE::Tag tag;
   PropertyMap dict = tag.properties();
   CPPUNIT_ASSERT(dict.isEmpty());
   dict["ARTIST"] = String("artist 1");
   dict["ARTIST"].append("artist 2");
   dict["TRACKNUMBER"].append("17");
   tag.setProperties(dict);
   CPPUNIT_ASSERT_EQUAL(String("17"), tag.itemListMap()["TRACK"].values()[0]);
   CPPUNIT_ASSERT_EQUAL(2u, tag.itemListMap()["ARTIST"].values().size());
   CPPUNIT_ASSERT_EQUAL(String("artist 1 artist 2"), tag.artist());
   CPPUNIT_ASSERT_EQUAL(17u, tag.track());
 }
Exemplo n.º 6
0
  void testInvalidKeys()
  {
    PropertyMap properties;
    properties["A"] = String("invalid key: one character");
    properties["MP+"] = String("invalid key: forbidden string");
    properties["A B~C"] = String("valid key: space and tilde");
    properties["ARTIST"] = String("valid key: normal one");

    APE::Tag tag;
    PropertyMap unsuccessful = tag.setProperties(properties);
    CPPUNIT_ASSERT_EQUAL((unsigned int)2, unsuccessful.size());
    CPPUNIT_ASSERT(unsuccessful.contains("A"));
    CPPUNIT_ASSERT(unsuccessful.contains("MP+"));

    CPPUNIT_ASSERT_EQUAL((unsigned int)2, tag.itemListMap().size());
    tag.addValue("VALID KEY", "Test Value 1");
    tag.addValue("INVALID KEY \x7f", "Test Value 2");
    CPPUNIT_ASSERT_EQUAL((unsigned int)3, tag.itemListMap().size());
  }
Exemplo n.º 7
0
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags)
{
  if(tags == NoTags && stripOthers)
    return strip(AllTags);

  if(!ID3v2Tag() && !ID3v1Tag() && !APETag()) {

    if((d->hasID3v1 || d->hasID3v2 || d->hasAPE) && stripOthers)
      return strip(AllTags);

    return true;
  }

  if(readOnly()) {
    debug("MPEG::File::save() -- File is read only.");
    return false;
  }

  // Create the tags if we've been asked to.

  if (duplicateTags) {

    // Copy the values from the tag that does exist into the new tag,
    // except if the existing tag is to be stripped.

    if((tags & ID3v2) && ID3v1Tag() && !(stripOthers && !(tags & ID3v1)))
      Tag::duplicate(ID3v1Tag(), ID3v2Tag(true), false);

    if((tags & ID3v1) && d->tag[ID3v2Index] && !(stripOthers && !(tags & ID3v2)))
      Tag::duplicate(ID3v2Tag(), ID3v1Tag(true), false);
  }

  bool success = true;

  if(ID3v2 & tags) {

    if(ID3v2Tag() && !ID3v2Tag()->isEmpty()) {

      if(!d->hasID3v2)
        d->ID3v2Location = 0;

      insert(ID3v2Tag()->render(id3v2Version), d->ID3v2Location, d->ID3v2OriginalSize);

      d->hasID3v2 = true;

      // v1 tag location has changed, update if it exists

      if(ID3v1Tag())
        d->ID3v1Location = findID3v1();

      // APE tag location has changed, update if it exists

      if(APETag())
        findAPE();
    }
    else if(stripOthers)
      success = strip(ID3v2, false) && success;
  }
  else if(d->hasID3v2 && stripOthers)
    success = strip(ID3v2) && success;

  if(ID3v1 & tags) {
    if(ID3v1Tag() && !ID3v1Tag()->isEmpty()) {
      int offset = d->hasID3v1 ? -128 : 0;
      seek(offset, End);
      writeBlock(ID3v1Tag()->render());
      d->hasID3v1 = true;
      d->ID3v1Location = findID3v1();
    }
    else if(stripOthers)
      success = strip(ID3v1) && success;
  }
  else if(d->hasID3v1 && stripOthers)
    success = strip(ID3v1, false) && success;

  // Dont save an APE-tag unless one has been created

  if((APE & tags) && APETag()) {
    if(d->hasAPE)
      insert(APETag()->render(), d->APELocation, d->APEOriginalSize);
    else {
      if(d->hasID3v1) {
        insert(APETag()->render(), d->ID3v1Location, 0);
        d->APEOriginalSize = APETag()->footer()->completeTagSize();
        d->hasAPE = true;
        d->APELocation = d->ID3v1Location;
        d->ID3v1Location += d->APEOriginalSize;
      }
      else {
        seek(0, End);
        d->APELocation = tell();
        APE::Tag *apeTag = d->tag.access<APE::Tag>(APEIndex, false);
        d->APEFooterLocation = d->APELocation
                               + apeTag->footer()->completeTagSize()
                               - APE::Footer::size();
        writeBlock(APETag()->render());
        d->APEOriginalSize = APETag()->footer()->completeTagSize();
        d->hasAPE = true;
      }
    }
  }
  else if(d->hasAPE && stripOthers)
    success = strip(APE, false) && success;

  return success;
}