Fix a couple of Windows 2Gig file size issues.
[platform/upstream/flac.git] / src / test_libFLAC++ / metadata_manip.cpp
index 2168d3e..ff02416 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 */
+#ifdef _MSC_VER
+#include <sys/utime.h>
+#else
 #include <utime.h> /* for utime() */
+#endif
+#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
 #include <unistd.h> /* for chown(), unlink() */
 #endif
 #include <sys/stat.h> /* for stat(), maybe chmod() */
@@ -40,6 +37,8 @@
 #include "FLAC++/decoder.h"
 #include "FLAC++/metadata.h"
 #include "share/grabbag.h"
+#include "share/compat.h"
+#include "share/macros.h"
 extern "C" {
 #include "test_libs_common/file_utils_flac.h"
 }
@@ -80,7 +79,7 @@ static unsigned mc_our_block_number_ = 0;
 
 static const char *flacfilename(bool is_ogg)
 {
-       return is_ogg? "metadata.ogg" : "metadata.flac";
+       return is_ogg? "metadata.oga" : "metadata.flac";
 }
 
 static bool die_(const char *msg)
@@ -278,8 +277,8 @@ void set_file_stats_(const char *filename, struct stat *stats)
        (void)chmod(filename, stats->st_mode);
        (void)utime(filename, &srctime);
 #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
-       (void)chown(filename, stats->st_uid, (gid_t)(-1));
-       (void)chown(filename, (uid_t)(-1), stats->st_gid);
+       FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1)));
+       FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid));
 #endif
 }
 
@@ -296,7 +295,7 @@ static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, ::FLAC
 
 static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
 {
-       off_t o = (off_t)offset;
+       FLAC__off_t o = (FLAC__off_t)offset;
        FLAC__ASSERT(offset == o);
        return fseeko((FILE*)handle, o, whence);
 }
@@ -360,8 +359,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
                        FILE *file = fopen(filename, "r+b");
                        if(0 == file)
                                return false; /*@@@@ chain status still says OK though */
-                       if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks))
+                       if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) {
+                               fclose(file);
                                return false;
+                       }
                        fclose(file);
                }
        }
@@ -600,6 +601,9 @@ static bool generate_file_(bool include_extras, bool is_ogg)
                return die_("creating the encoded file");
 
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
+       free(picture.data.picture.mime_type);
+       free(picture.data.picture.description);
+       free(picture.data.picture.data);
 
        return true;
 }
@@ -2191,15 +2195,17 @@ 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;
 }