~ubuntu-branches/ubuntu/raring/flac/raring

« back to all changes in this revision

Viewing changes to src/test_libFLAC/metadata_object.c

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* test_libFLAC - Unit tester for libFLAC
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
16
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
17
 */
18
18
 
 
19
#if HAVE_CONFIG_H
 
20
#  include <config.h>
 
21
#endif
 
22
 
19
23
#include "FLAC/assert.h"
20
24
#include "FLAC/metadata.h"
21
 
#include "metadata_utils.h"
 
25
#include "test_libs_common/metadata_utils.h"
22
26
#include <stdio.h>
23
27
#include <stdlib.h> /* for malloc() */
24
28
#include <string.h> /* for memcmp() */
42
46
        unsigned i;
43
47
 
44
48
        if(from->offset != to->offset) {
45
 
                printf("FAILED, track offset mismatch, expected %llu, got %llu\n", to->offset, from->offset);
 
49
#ifdef _MSC_VER
 
50
                printf("FAILED, track offset mismatch, expected %I64u, got %I64u\n", to->offset, from->offset);
 
51
#else
 
52
                printf("FAILED, track offset mismatch, expected %llu, got %llu\n", (unsigned long long)to->offset, (unsigned long long)from->offset);
 
53
#endif
46
54
                return false;
47
55
        }
48
56
        if(from->number != to->number) {
74
82
        else {
75
83
                for(i = 0; i < to->num_indices; i++) {
76
84
                        if(from->indices[i].offset != to->indices[i].offset) {
77
 
                                printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, to->indices[i].offset, from->indices[i].offset);
 
85
#ifdef _MSC_VER
 
86
                                printf("FAILED, track indices[%u].offset mismatch, expected %I64u, got %I64u\n", i, to->indices[i].offset, from->indices[i].offset);
 
87
#else
 
88
                                printf("FAILED, track indices[%u].offset mismatch, expected %llu, got %llu\n", i, (unsigned long long)to->indices[i].offset, (unsigned long long)from->indices[i].offset);
 
89
#endif
78
90
                                return false;
79
91
                        }
80
92
                        if(from->indices[i].number != to->indices[i].number) {
96
108
 
97
109
        for(i = 0; i < n; i++) {
98
110
                if(from[i].sample_number != to[i].sample_number) {
99
 
                        printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
 
111
#ifdef _MSC_VER
 
112
                        printf("FAILED, point[%u].sample_number mismatch, expected %I64u, got %I64u\n", i, to[i].sample_number, from[i].sample_number);
 
113
#else
 
114
                        printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, (unsigned long long)to[i].sample_number, (unsigned long long)from[i].sample_number);
 
115
#endif
100
116
                        return false;
101
117
                }
102
118
                if(from[i].stream_offset != to[i].stream_offset) {
103
 
                        printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
 
119
#ifdef _MSC_VER
 
120
                        printf("FAILED, point[%u].stream_offset mismatch, expected %I64u, got %I64u\n", i, to[i].stream_offset, from[i].stream_offset);
 
121
#else
 
122
                        printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, (unsigned long long)to[i].stream_offset, (unsigned long long)from[i].stream_offset);
 
123
#endif
104
124
                        return false;
105
125
                }
106
126
                if(from[i].frame_samples != to[i].frame_samples) {
208
228
        unsigned i;
209
229
        for(i = start; i < block->data.vorbis_comment.num_comments; i++) {
210
230
                const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i];
211
 
                if(entry->length > n && 0 == strncmp(entry->entry, name, n) && entry->entry[n] == '=')
 
231
                if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=')
212
232
                        return (int)i;
213
233
        }
214
234
        return -1;
459
479
        cs_calc_len_(block);
460
480
}
461
481
 
462
 
 
463
 
FLAC__bool test_metadata_object()
464
 
{
465
 
        FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet;
466
 
        FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
 
482
static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s)
 
483
{
 
484
        if(block->data.picture.mime_type) {
 
485
                block->length -= strlen(block->data.picture.mime_type);
 
486
                free(block->data.picture.mime_type);
 
487
        }
 
488
        block->data.picture.mime_type = strdup(s);
 
489
        FLAC__ASSERT(block->data.picture.mime_type);
 
490
        block->length += strlen(block->data.picture.mime_type);
 
491
}
 
492
 
 
493
static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s)
 
494
{
 
495
        if(block->data.picture.description) {
 
496
                block->length -= strlen((const char *)block->data.picture.description);
 
497
                free(block->data.picture.description);
 
498
        }
 
499
        block->data.picture.description = (FLAC__byte*)strdup((const char *)s);
 
500
        FLAC__ASSERT(block->data.picture.description);
 
501
        block->length += strlen((const char *)block->data.picture.description);
 
502
}
 
503
 
 
504
static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len)
 
505
{
 
506
        if(block->data.picture.data) {
 
507
                block->length -= block->data.picture.data_length;
 
508
                free(block->data.picture.data);
 
509
        }
 
510
        block->data.picture.data = (FLAC__byte*)strdup((const char *)data);
 
511
        FLAC__ASSERT(block->data.picture.data);
 
512
        block->data.picture.data_length = len;
 
513
        block->length += len;
 
514
}
 
515
 
 
516
FLAC__bool test_metadata_object(void)
 
517
{
 
518
        FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture;
 
519
        FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
467
520
        FLAC__StreamMetadata_VorbisComment_Entry entry;
468
521
        FLAC__StreamMetadata_CueSheet_Index index;
469
522
        FLAC__StreamMetadata_CueSheet_Track track;
875
928
        if(!check_seektable_(block, seekpoints, seekpoint_array))
876
929
                return false;
877
930
 
 
931
        seekpoint_array[seekpoints++].sample_number = 0;
 
932
        seekpoint_array[seekpoints++].sample_number = 10;
 
933
        seekpoint_array[seekpoints++].sample_number = 20;
 
934
        printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
 
935
        if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
 
936
                printf("FAILED, returned false\n");
 
937
                return false;
 
938
        }
 
939
        if(!check_seektable_(block, seekpoints, seekpoint_array))
 
940
                return false;
 
941
 
 
942
        seekpoint_array[seekpoints++].sample_number = 0;
 
943
        seekpoint_array[seekpoints++].sample_number = 11;
 
944
        seekpoint_array[seekpoints++].sample_number = 22;
 
945
        printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
 
946
        if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
 
947
                printf("FAILED, returned false\n");
 
948
                return false;
 
949
        }
 
950
        if(!check_seektable_(block, seekpoints, seekpoint_array))
 
951
                return false;
 
952
 
878
953
        printf("testing FLAC__metadata_object_delete()... ");
879
954
        FLAC__metadata_object_delete(block);
880
955
        printf("OK\n");
891
966
                        printf("FAILED, returned false\n");
892
967
                        return false;
893
968
                }
894
 
                if(strcmp(entry_.entry, "name=value")) {
 
969
                if(strcmp((const char *)entry_.entry, "name=value")) {
895
970
                        printf("FAILED, field mismatch\n");
896
971
                        return false;
897
972
                }
1970
2045
        printf("OK\n");
1971
2046
 
1972
2047
 
 
2048
        printf("testing PICTURE\n");
 
2049
 
 
2050
        printf("testing FLAC__metadata_object_new()... ");
 
2051
        block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
 
2052
        if(0 == block) {
 
2053
                printf("FAILED, returned NULL\n");
 
2054
                return false;
 
2055
        }
 
2056
        expected_length = (
 
2057
                FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
 
2058
                FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
 
2059
                FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
 
2060
                FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
 
2061
                FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
 
2062
                FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
 
2063
                FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
 
2064
                FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
 
2065
        ) / 8;
 
2066
        if(block->length != expected_length) {
 
2067
                printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
 
2068
                return false;
 
2069
        }
 
2070
        printf("OK\n");
 
2071
 
 
2072
        printf("testing FLAC__metadata_object_clone()... ");
 
2073
        picture = FLAC__metadata_object_clone(block);
 
2074
        if(0 == picture) {
 
2075
                printf("FAILED, returned NULL\n");
 
2076
                return false;
 
2077
        }
 
2078
        if(!mutils__compare_block(picture, block))
 
2079
                return false;
 
2080
        printf("OK\n");
 
2081
 
 
2082
        pi_set_mime_type(picture, "image/png\t");
 
2083
        printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
 
2084
        if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) {
 
2085
                printf("FAILED, returned false\n");
 
2086
                return false;
 
2087
        }
 
2088
        if(!mutils__compare_block(picture, block))
 
2089
                return false;
 
2090
        printf("OK\n");
 
2091
 
 
2092
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2093
        {
 
2094
                const char *violation;
 
2095
                if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2096
                        printf("FAILED, returned true when expecting false\n");
 
2097
                        return false;
 
2098
                }
 
2099
                printf("returned false as expected, violation=\"%s\" OK\n", violation);
 
2100
        }
 
2101
 
 
2102
        pi_set_mime_type(picture, "image/png");
 
2103
        printf("testing FLAC__metadata_object_picture_set_mime_type(copy)...");
 
2104
        if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) {
 
2105
                printf("FAILED, returned false\n");
 
2106
                return false;
 
2107
        }
 
2108
        if(!mutils__compare_block(picture, block))
 
2109
                return false;
 
2110
        printf("OK\n");
 
2111
 
 
2112
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2113
        {
 
2114
                const char *violation;
 
2115
                if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2116
                        printf("FAILED, returned false, violation=\"%s\"\n", violation);
 
2117
                        return false;
 
2118
                }
 
2119
                printf("OK\n");
 
2120
        }
 
2121
 
 
2122
        pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
 
2123
        printf("testing FLAC__metadata_object_picture_set_description(copy)...");
 
2124
        if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) {
 
2125
                printf("FAILED, returned false\n");
 
2126
                return false;
 
2127
        }
 
2128
        if(!mutils__compare_block(picture, block))
 
2129
                return false;
 
2130
        printf("OK\n");
 
2131
 
 
2132
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2133
        {
 
2134
                const char *violation;
 
2135
                if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2136
                        printf("FAILED, returned true when expecting false\n");
 
2137
                        return false;
 
2138
                }
 
2139
                printf("returned false as expected, violation=\"%s\" OK\n", violation);
 
2140
        }
 
2141
 
 
2142
        pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
 
2143
        printf("testing FLAC__metadata_object_picture_set_description(copy)...");
 
2144
        if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) {
 
2145
                printf("FAILED, returned false\n");
 
2146
                return false;
 
2147
        }
 
2148
        if(!mutils__compare_block(picture, block))
 
2149
                return false;
 
2150
        printf("OK\n");
 
2151
 
 
2152
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2153
        {
 
2154
                const char *violation;
 
2155
                if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2156
                        printf("FAILED, returned false, violation=\"%s\"\n", violation);
 
2157
                        return false;
 
2158
                }
 
2159
                printf("OK\n");
 
2160
        }
 
2161
 
 
2162
 
 
2163
        pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
 
2164
        printf("testing FLAC__metadata_object_picture_set_data(copy)...");
 
2165
        if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) {
 
2166
                printf("FAILED, returned false\n");
 
2167
                return false;
 
2168
        }
 
2169
        if(!mutils__compare_block(picture, block))
 
2170
                return false;
 
2171
        printf("OK\n");
 
2172
 
 
2173
        printf("testing FLAC__metadata_object_clone()... ");
 
2174
        blockcopy = FLAC__metadata_object_clone(block);
 
2175
        if(0 == blockcopy) {
 
2176
                printf("FAILED, returned NULL\n");
 
2177
                return false;
 
2178
        }
 
2179
        if(!mutils__compare_block(block, blockcopy))
 
2180
                return false;
 
2181
        printf("OK\n");
 
2182
 
 
2183
        printf("testing FLAC__metadata_object_delete()... ");
 
2184
        FLAC__metadata_object_delete(blockcopy);
 
2185
        printf("OK\n");
 
2186
 
 
2187
        pi_set_mime_type(picture, "image/png\t");
 
2188
        printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
 
2189
        if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) {
 
2190
                printf("FAILED, returned false\n");
 
2191
                return false;
 
2192
        }
 
2193
        if(!mutils__compare_block(picture, block))
 
2194
                return false;
 
2195
        printf("OK\n");
 
2196
 
 
2197
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2198
        {
 
2199
                const char *violation;
 
2200
                if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2201
                        printf("FAILED, returned true when expecting false\n");
 
2202
                        return false;
 
2203
                }
 
2204
                printf("returned false as expected, violation=\"%s\" OK\n", violation);
 
2205
        }
 
2206
 
 
2207
        pi_set_mime_type(picture, "image/png");
 
2208
        printf("testing FLAC__metadata_object_picture_set_mime_type(own)...");
 
2209
        if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) {
 
2210
                printf("FAILED, returned false\n");
 
2211
                return false;
 
2212
        }
 
2213
        if(!mutils__compare_block(picture, block))
 
2214
                return false;
 
2215
        printf("OK\n");
 
2216
 
 
2217
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2218
        {
 
2219
                const char *violation;
 
2220
                if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2221
                        printf("FAILED, returned false, violation=\"%s\"\n", violation);
 
2222
                        return false;
 
2223
                }
 
2224
                printf("OK\n");
 
2225
        }
 
2226
 
 
2227
        pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff");
 
2228
        printf("testing FLAC__metadata_object_picture_set_description(own)...");
 
2229
        if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) {
 
2230
                printf("FAILED, returned false\n");
 
2231
                return false;
 
2232
        }
 
2233
        if(!mutils__compare_block(picture, block))
 
2234
                return false;
 
2235
        printf("OK\n");
 
2236
 
 
2237
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2238
        {
 
2239
                const char *violation;
 
2240
                if(FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2241
                        printf("FAILED, returned true when expecting false\n");
 
2242
                        return false;
 
2243
                }
 
2244
                printf("returned false as expected, violation=\"%s\" OK\n", violation);
 
2245
        }
 
2246
 
 
2247
        pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION");
 
2248
        printf("testing FLAC__metadata_object_picture_set_description(own)...");
 
2249
        if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) {
 
2250
                printf("FAILED, returned false\n");
 
2251
                return false;
 
2252
        }
 
2253
        if(!mutils__compare_block(picture, block))
 
2254
                return false;
 
2255
        printf("OK\n");
 
2256
 
 
2257
        printf("testing FLAC__metadata_object_picture_is_legal()...");
 
2258
        {
 
2259
                const char *violation;
 
2260
                if(!FLAC__metadata_object_picture_is_legal(block, &violation)) {
 
2261
                        printf("FAILED, returned false, violation=\"%s\"\n", violation);
 
2262
                        return false;
 
2263
                }
 
2264
                printf("OK\n");
 
2265
        }
 
2266
 
 
2267
        pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA"));
 
2268
        printf("testing FLAC__metadata_object_picture_set_data(own)...");
 
2269
        if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) {
 
2270
                printf("FAILED, returned false\n");
 
2271
                return false;
 
2272
        }
 
2273
        if(!mutils__compare_block(picture, block))
 
2274
                return false;
 
2275
        printf("OK\n");
 
2276
 
 
2277
        printf("testing FLAC__metadata_object_clone()... ");
 
2278
        blockcopy = FLAC__metadata_object_clone(block);
 
2279
        if(0 == blockcopy) {
 
2280
                printf("FAILED, returned NULL\n");
 
2281
                return false;
 
2282
        }
 
2283
        if(!mutils__compare_block(block, blockcopy))
 
2284
                return false;
 
2285
        printf("OK\n");
 
2286
 
 
2287
        printf("testing FLAC__metadata_object_delete()... ");
 
2288
        FLAC__metadata_object_delete(blockcopy);
 
2289
        printf("OK\n");
 
2290
 
 
2291
        printf("testing FLAC__metadata_object_delete()... ");
 
2292
        FLAC__metadata_object_delete(picture);
 
2293
        FLAC__metadata_object_delete(block);
 
2294
        printf("OK\n");
 
2295
 
 
2296
 
1973
2297
        return true;
1974
2298
}