Source

libtaginfo / tests / lyrics_ogg / main.cc

#include "taginfo.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace TagInfo;
//using namespace std;


int main( void ) {
    Info * info;
    std::string val   = TESTDIR "samples/sample.ogg";
    
    //std::cout << std::endl << "val: " << val << std::endl;
    std::string target = "/tmp/out_01.ogg";
    
    std::ifstream  src(val.c_str());
    std::ofstream  dst(target.c_str());
    dst << src.rdbuf();
    
    char* data;
    int data_length;
    
    struct stat filestatus;
    
    
    std::string lyrics = "these are lyrics öäüß\n ldskjfslkd\n öäüß";
    
    info = Info::create_tag_info(target);
    if(info) {
        if(!info->set_lyrics(lyrics.c_str())) {
            delete info;
            return EXIT_FAILURE;
        }
        info->write();
    }
    delete info;
    info = NULL;
    
    info = Info::create_tag_info(target);
    char* read;
    if(info) {
        if(info->read()) {
            const char* res = info->get_lyrics().toCString(false);
            if(strcmp(lyrics.c_str(), res) != 0) {
                delete info;
                if(remove(target.c_str()) != 0 ) {
                    return EXIT_FAILURE;
                }
            }
            if(remove(target.c_str()) != 0 )
                return EXIT_FAILURE;
            return EXIT_SUCCESS;
        }
        delete info;
        if(remove(target.c_str()) != 0 )
            return EXIT_FAILURE;
        return EXIT_FAILURE;
    }
    else {
        delete info;
        if(remove(target.c_str()) != 0 )
            return EXIT_FAILURE;
        return EXIT_FAILURE;
    }
    return EXIT_FAILURE;
}