configure.ac : Detect the size of off_t.
[platform/upstream/flac.git] / src / test_libFLAC / metadata_manip.c
index 8d6b4a8..e720056 100644 (file)
@@ -1,5 +1,5 @@
 /* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2002,2003,2004,2005,2006  Josh Coalson
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -11,9 +11,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #if HAVE_CONFIG_H
 
 #include <stdio.h>
 #include <stdlib.h> /* for malloc() */
+#include <string.h> /* for memcpy()/memset() */
 #if defined _MSC_VER || defined __MINGW32__
 #include <sys/utime.h> /* for utime() */
 #include <io.h> /* for chmod() */
-#if _MSC_VER <= 1200 /* @@@ [2G limit] */
-#define fseeko fseek
-#define ftello ftell
-#endif
 #else
 #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
 #include <utime.h> /* for utime() */
 #include "FLAC/stream_decoder.h"
 #include "FLAC/metadata.h"
 #include "share/grabbag.h"
+#include "share/compat.h"
+#include "share/macros.h"
 #include "test_libs_common/file_utils_flac.h"
 #include "test_libs_common/metadata_utils.h"
+#include "metadata.h"
 
 
 /******************************************************************************
@@ -71,7 +71,7 @@ static unsigned mc_our_block_number_ = 0;
 
 static const char *flacfilename(FLAC__bool is_ogg)
 {
-       return is_ogg? "metadata.ogg" : "metadata.flac";
+       return is_ogg? "metadata.oga" : "metadata.flac";
 }
 
 static FLAC__bool die_(const char *msg)
@@ -183,11 +183,11 @@ static void delete_from_our_metadata_(unsigned position)
  * This wad of functions supports filename- and callback-based chain reading/writing.
  * Everything up to set_file_stats_() is copied from libFLAC/metadata_iterators.c
  */
-FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+static FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
 {
        static const char *tempfile_suffix = ".metadata_edit";
 
-       if(0 == (*tempfilename = (char*)malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
+       if(0 == (*tempfilename = malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
                return false;
        strcpy(*tempfilename, filename);
        strcat(*tempfilename, tempfile_suffix);
@@ -198,7 +198,7 @@ FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfile
        return true;
 }
 
-void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
+static void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
 {
        if(0 != *tempfile) {
                (void)fclose(*tempfile);
@@ -212,7 +212,7 @@ void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
        }
 }
 
-FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
 {
        FLAC__ASSERT(0 != filename);
        FLAC__ASSERT(0 != tempfile);
@@ -242,14 +242,14 @@ FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tem
        return true;
 }
 
-FLAC__bool get_file_stats_(const char *filename, struct stat *stats)
+static FLAC__bool get_file_stats_(const char *filename, struct stat *stats)
 {
        FLAC__ASSERT(0 != filename);
        FLAC__ASSERT(0 != stats);
        return (0 == stat(filename, stats));
 }
 
-void set_file_stats_(const char *filename, struct stat *stats)
+static void set_file_stats_(const char *filename, struct stat *stats)
 {
        struct utimbuf srctime;
 
@@ -260,9 +260,9 @@ void set_file_stats_(const char *filename, struct stat *stats)
        srctime.modtime = stats->st_mtime;
        (void)chmod(filename, stats->st_mode);
        (void)utime(filename, &srctime);
-#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
-       (void)chown(filename, stats->st_uid, -1);
-       (void)chown(filename, -1, stats->st_gid);
+#if !defined _MSC_VER && !defined __MINGW32__
+       FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1));
+       FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid));
 #endif
 }
 
@@ -313,7 +313,7 @@ static FLAC__bool write_chain_(FLAC__Metadata_Chain *chain, FLAC__bool use_paddi
 
                if(FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) {
                        struct stat stats;
-                       FILE *file, *tempfile;
+                       FILE *file, *tempfile = 0;
                        char *tempfilename;
                        if(preserve_file_stats) {
                                if(!get_file_stats_(filename, &stats))
@@ -609,6 +609,10 @@ static FLAC__bool generate_file_(FLAC__bool include_extras, FLAC__bool is_ogg)
 
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
        free(picture.data.picture.mime_type);
+       free(picture.data.picture.description);
+       free(picture.data.picture.data);
+       if(!include_extras)
+               FLAC__metadata_object_delete(cuesheet);
 
        return true;
 }
@@ -680,7 +684,7 @@ static FLAC__bool remove_file_(const char *filename)
        return true;
 }
 
-static FLAC__bool test_level_0_()
+static FLAC__bool test_level_0_(void)
 {
        FLAC__StreamMetadata streaminfo;
        FLAC__StreamMetadata *tags = 0;
@@ -759,7 +763,7 @@ static FLAC__bool test_level_0_()
        return true;
 }
 
-static FLAC__bool test_level_1_()
+static FLAC__bool test_level_1_(void)
 {
        FLAC__Metadata_SimpleIterator *iterator;
        FLAC__StreamMetadata *block, *app, *padding;
@@ -2092,7 +2096,7 @@ static FLAC__bool test_level_2_misc_(FLAC__bool is_ogg)
        return true;
 }
 
-FLAC__bool test_metadata_file_manipulation()
+FLAC__bool test_metadata_file_manipulation(void)
 {
        printf("\n+++ libFLAC unit test: metadata manipulation\n\n");
 
@@ -2111,15 +2115,17 @@ FLAC__bool test_metadata_file_manipulation()
        if(!test_level_2_misc_(/*is_ogg=*/false))
                return false;
 
-       if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */
-               return false;
-       if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */
-               return false;
+       if(FLAC_API_SUPPORTS_OGG_FLAC) {
+               if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */
+                       return false;
+               if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */
+                       return false;
 #if 0
-       /* when ogg flac write is supported, will have to add this: */
-       if(!test_level_2_misc_(/*is_ogg=*/true))
-               return false;
+               /* when ogg flac write is supported, will have to add this: */
+               if(!test_level_2_misc_(/*is_ogg=*/true))
+                       return false;
 #endif
+       }
 
        return true;
 }