Commits

shuerhaaken  committed 4329da4

add image read/write test for flac

  • Participants
  • Parent commits b3f07d1

Comments (0)

Files changed (3)

+commit b3f07d1d13e19ca1ef861654497a9648bb0575ff
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 21 09:24:25 2013 +0100
+
+    update project info 2
+
+commit 04cb8f3e785416b04acd0435ec8834d04c7aac21
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 21 09:21:53 2013 +0100
+
+    update project info
+
 commit bff36f33d0abccb3b4ed5653bc7e032b5b115fda
 Author: Jörn Magens <shuerhaaken@googlemail.com>
 Date:   Thu Mar 21 09:08:25 2013 +0100

File tests/Makefile.am

     write_wma/test \
     ctest_read/test \
     ctest_write/test \
+    write_image_flac/test \
     write_image_mp3/test \
     write_image_mpc/test \
     write_image_ogg/test \
 
 
 
-basic_test_SOURCES            = basic/main.cc
-basic_test_LDADD              = $(taginfo_ldadd)
+basic_test_SOURCES              = basic/main.cc
+basic_test_LDADD                = $(taginfo_ldadd)
 
-read_aif_test_SOURCES         = read_aif/main.cc
-read_aif_test_LDADD           = $(taginfo_ldadd)
+read_aif_test_SOURCES           = read_aif/main.cc
+read_aif_test_LDADD             = $(taginfo_ldadd)
 
-read_ape_test_SOURCES         = read_ape/main.cc
-read_ape_test_LDADD           = $(taginfo_ldadd)
+read_ape_test_SOURCES           = read_ape/main.cc
+read_ape_test_LDADD             = $(taginfo_ldadd)
 
-read_flac_test_SOURCES        = read_flac/main.cc
-read_flac_test_LDADD          = $(taginfo_ldadd)
+read_flac_test_SOURCES          = read_flac/main.cc
+read_flac_test_LDADD            = $(taginfo_ldadd)
 
-read_ext_header_test_SOURCES  = read_ext_header/main.cc
-read_ext_header_test_LDADD    = $(taginfo_ldadd)
+read_ext_header_test_SOURCES    = read_ext_header/main.cc
+read_ext_header_test_LDADD      = $(taginfo_ldadd)
 
-read_m4a_test_SOURCES         = read_m4a/main.cc
-read_m4a_test_LDADD           = $(taginfo_ldadd)
+read_m4a_test_SOURCES           = read_m4a/main.cc
+read_m4a_test_LDADD             = $(taginfo_ldadd)
 
-read_mp3_v1_test_SOURCES      = read_mp3_v1/main.cc
-read_mp3_v1_test_LDADD        = $(taginfo_ldadd)
+read_mp3_v1_test_SOURCES        = read_mp3_v1/main.cc
+read_mp3_v1_test_LDADD          = $(taginfo_ldadd)
 
-read_mp3_v2_test_SOURCES      = read_mp3_v2/main.cc
-read_mp3_v2_test_LDADD        = $(taginfo_ldadd)
+read_mp3_v2_test_SOURCES        = read_mp3_v2/main.cc
+read_mp3_v2_test_LDADD          = $(taginfo_ldadd)
 
-read_mpc_test_SOURCES         = read_mpc/main.cc
-read_mpc_test_LDADD           = $(taginfo_ldadd)
+read_mpc_test_SOURCES           = read_mpc/main.cc
+read_mpc_test_LDADD             = $(taginfo_ldadd)
 
-read_ogg_test_SOURCES         = read_ogg/main.cc
-read_ogg_test_LDADD           = $(taginfo_ldadd)
+read_ogg_test_SOURCES           = read_ogg/main.cc
+read_ogg_test_LDADD             = $(taginfo_ldadd)
 
-read_wma_test_SOURCES         = read_wma/main.cc
-read_wma_test_LDADD           = $(taginfo_ldadd)
+read_wma_test_SOURCES           = read_wma/main.cc
+read_wma_test_LDADD             = $(taginfo_ldadd)
 
-write_ape_test_SOURCES        = write_ape/main.cc
-write_ape_test_LDADD          = $(taginfo_ldadd)
+write_ape_test_SOURCES          = write_ape/main.cc
+write_ape_test_LDADD            = $(taginfo_ldadd)
 
-write_flac_test_SOURCES       = write_flac/main.cc
-write_flac_test_LDADD         = $(taginfo_ldadd)
+write_flac_test_SOURCES         = write_flac/main.cc
+write_flac_test_LDADD           = $(taginfo_ldadd)
 
-write_speex_test_SOURCES      = write_speex/main.cc
-write_speex_test_LDADD        = $(taginfo_ldadd)
+write_speex_test_SOURCES        = write_speex/main.cc
+write_speex_test_LDADD          = $(taginfo_ldadd)
 
-write_mp3_test_SOURCES        = write_mp3/main.cc
-write_mp3_test_LDADD          = $(taginfo_ldadd)
+write_mp3_test_SOURCES          = write_mp3/main.cc
+write_mp3_test_LDADD            = $(taginfo_ldadd)
 
-write_m4a_test_SOURCES        = write_m4a/main.cc
-write_m4a_test_LDADD          = $(taginfo_ldadd)
+write_m4a_test_SOURCES          = write_m4a/main.cc
+write_m4a_test_LDADD            = $(taginfo_ldadd)
 
-write_mpc_test_SOURCES        = write_mpc/main.cc
-write_mpc_test_LDADD          = $(taginfo_ldadd)
+write_mpc_test_SOURCES          = write_mpc/main.cc
+write_mpc_test_LDADD            = $(taginfo_ldadd)
 
-write_ogg_test_SOURCES        = write_ogg/main.cc
-write_ogg_test_LDADD          = $(taginfo_ldadd)
+write_ogg_test_SOURCES          = write_ogg/main.cc
+write_ogg_test_LDADD            = $(taginfo_ldadd)
 
-write_tta_test_SOURCES        = write_tta/main.cc
-write_tta_test_LDADD          = $(taginfo_ldadd)
+write_tta_test_SOURCES          = write_tta/main.cc
+write_tta_test_LDADD            = $(taginfo_ldadd)
 
-write_wma_test_SOURCES        = write_wma/main.cc
-write_wma_test_LDADD          = $(taginfo_ldadd)
+write_wma_test_SOURCES          = write_wma/main.cc
+write_wma_test_LDADD            = $(taginfo_ldadd)
 
-write_wav_test_SOURCES         = write_wav/main.cc
-write_wav_test_LDADD           = $(taginfo_ldadd)
+write_wav_test_SOURCES          = write_wav/main.cc
+write_wav_test_LDADD            = $(taginfo_ldadd)
 
-ctest_read_test_SOURCES        = ctest_read/main.c
-ctest_read_test_LDADD          = $(top_builddir)/bindings/c/libtaginfo_c.la
+ctest_read_test_SOURCES         = ctest_read/main.c
+ctest_read_test_LDADD           = $(top_builddir)/bindings/c/libtaginfo_c.la
 
 ctest_write_test_SOURCES        = ctest_write/main.c
 ctest_write_test_LDADD          = $(top_builddir)/bindings/c/libtaginfo_c.la
 
+write_image_flac_test_SOURCES   = write_image_flac/main.cc
+write_image_flac_test_LDADD     = $(taginfo_ldadd)
+
 write_image_mp3_test_SOURCES    = write_image_mp3/main.cc
 write_image_mp3_test_LDADD      = $(taginfo_ldadd)
 

File tests/write_image_flac/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;
+
+void clean_up(char* map, int size, int fd) {
+    if(munmap(map, size) == -1) {
+        perror("Error un-mmapping the file");
+    }
+    if(fd != 0)
+        close(fd);
+}
+
+int main( void ) {
+    Info * info;
+    std::string val   = TESTDIR "samples/sample.flac";
+    std::string image = TESTDIR "samples/test.jpg";
+    
+    //std::cout << std::endl << "val: " << val << std::endl;
+    std::string target = "/tmp/out_01.flac";
+    
+    std::ifstream  src(val.c_str());
+    std::ofstream  dst(target.c_str());
+    dst << src.rdbuf();
+    
+    char* data;
+    int data_length;
+    ImageType image_type = IMAGE_TYPE_JPEG;
+    
+    struct stat filestatus;
+    stat( image.c_str(), &filestatus );
+    //cout << filestatus.st_size << " bytes\n";
+    data_length = filestatus.st_size;
+    int fd;
+    
+    fd = open(image.c_str(), O_RDONLY);
+    if (fd == -1) {
+        perror("Error opening file for reading");
+        EXIT_FAILURE;
+    }
+    
+    data = (char*)mmap(0, data_length, PROT_READ, MAP_SHARED, fd, 0);
+    if(data == MAP_FAILED) {
+        close(fd);
+        perror("Error mmapping the file");
+        EXIT_FAILURE;
+    }
+    
+    info = Info::create_tag_info(target);
+    if(info) {
+        if(!info->set_image(data, data_length, image_type)) {
+            clean_up(data, data_length, fd);
+            delete info;
+            return EXIT_FAILURE;
+        }
+        info->write();
+    }
+    delete info;
+    info = NULL;
+    
+    info = Info::create_tag_info(target);
+    char* read;
+    int read_length;
+    ImageType read_type;
+    if(info) {
+        if(info->read()) {
+            if(!info->get_image(read, read_length, read_type)) {
+                delete info;
+                if(remove(target.c_str()) != 0 ) {
+                    clean_up(data, data_length, fd);
+                    return EXIT_FAILURE;
+                }
+            }
+            int i;
+            for(i = 0; i<data_length; i++) {
+                if(data[i] != read[i]) {
+                    clean_up(data, data_length, fd);
+                    free(read);
+                    return EXIT_FAILURE;
+                }
+            }
+            clean_up(data, data_length, fd);
+            free(read);
+            if(remove(target.c_str()) != 0 )
+                return EXIT_FAILURE;
+            return EXIT_SUCCESS;
+        }
+        delete info;
+        clean_up(data, data_length, fd);
+        if(remove(target.c_str()) != 0 )
+            return EXIT_FAILURE;
+        return EXIT_FAILURE;
+    }
+    else {
+       delete info;
+        clean_up(data, data_length, fd);
+        if(remove(target.c_str()) != 0 )
+            return EXIT_FAILURE;
+        return EXIT_FAILURE;
+    }
+    return EXIT_FAILURE;
+}
+