test_id3.c (5874B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_id3.c 22 * @brief testcase for the id3 plugin 23 * @author Christian Grothoff 24 * 25 * The file under test is described in contrib/gen_id3_testdata.sh. 26 * The expectations worth understanding: 27 * 28 * - The title, artist and album prove the four ID3v2 text encodings: 29 * they are stored as UTF-8, as UTF-16 with a byte order mark and as 30 * ISO-8859-1 respectively, and all three carry characters outside 31 * ASCII, so a plugin that passed the bytes through unchanged would 32 * fail here rather than silently emit mojibake. 33 * - The genre is stored as "(52)" and has to come back resolved. 34 * - The lyrics and the cover picture are both longer than 127 bytes, 35 * which is where the synchsafe frame size of ID3v2.4 first differs 36 * from the plain integer of 2.3. Everything after them in the tag 37 * only parses if that was handled correctly. 38 * - The publication date and the comment are the only two items that 39 * come from the ID3v1 tag at the end of the file; every other field 40 * of that tag is deliberately different from its ID3v2 counterpart 41 * and must lose to it. 42 * - The encoder, encoder version, encoder settings, track gain, 43 * bitrate, bitrate mode and duration all come out of the Xing and 44 * LAME tags inside the first audio frame. 45 */ 46 #include "platform.h" 47 #include "test_lib.h" 48 49 50 /** 51 * Expected string item. 52 */ 53 #define STR(t, s) { t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, \ 54 strlen (s) + 1, 0, 0, NULL } 55 56 57 /** 58 * Main function for the ID3 testcase. 59 * 60 * @param argc number of arguments (ignored) 61 * @param argv arguments (ignored) 62 * @return 0 on success 63 */ 64 int 65 main (int argc, char *argv[]) 66 { 67 struct SolutionData id3_test_sol[] = { 68 STR (EXTRACTOR_METATYPE_MIMETYPE, "audio/mpeg"), 69 STR (EXTRACTOR_METATYPE_FORMAT_VERSION, "ID3v2.4.0"), 70 /* text frames, one per encoding */ 71 STR (EXTRACTOR_METATYPE_TITLE, "Grüße aus Köln"), 72 STR (EXTRACTOR_METATYPE_ARTIST, "Bœuf Trio"), 73 STR (EXTRACTOR_METATYPE_ALBUM, "Café Sessions"), 74 STR (EXTRACTOR_METATYPE_GENRE, "Electronic"), 75 STR (EXTRACTOR_METATYPE_TRACK_NUMBER, "3/12"), 76 STR (EXTRACTOR_METATYPE_DISC_NUMBER, "1/2"), 77 STR (EXTRACTOR_METATYPE_CREATION_DATE, "2024-03-14"), 78 STR (EXTRACTOR_METATYPE_COMPOSER, "Ada Lovelace"), 79 STR (EXTRACTOR_METATYPE_CONDUCTOR, "Grace Hopper"), 80 STR (EXTRACTOR_METATYPE_PUBLISHER, "GNU Records"), 81 STR (EXTRACTOR_METATYPE_COPYRIGHT, "2026 GNU libextractor"), 82 STR (EXTRACTOR_METATYPE_LANGUAGE, "deu"), 83 STR (EXTRACTOR_METATYPE_BEATS_PER_MINUTE, "128"), 84 STR (EXTRACTOR_METATYPE_LYRICS, 85 "One two three four five six seven eight nine ten. " 86 "This lyric frame exists only to be longer than one hundred " 87 "and twenty seven bytes, so that the synchsafe frame size of " 88 "ID3v2.4 differs from a plain big endian integer here."), 89 /* provenance */ 90 STR (EXTRACTOR_METATYPE_ENCODED_BY, "GNU libextractor test rig"), 91 STR (EXTRACTOR_METATYPE_ENCODER_SETTINGS, 92 "LAME 3.100 -V 5 --vbr-new"), 93 STR (EXTRACTOR_METATYPE_OWNER_USER, "licensee@example.org"), 94 STR (EXTRACTOR_METATYPE_SOURCE_DEVICE, "MPG/3"), 95 STR (EXTRACTOR_METATYPE_SOURCE_DEVICE, "DIG/A/T"), 96 STR (EXTRACTOR_METATYPE_SERIAL, 97 "http://musicbrainz.org: 9f1a3e6c-0000-4000-8000-0123456789ab"), 98 STR (EXTRACTOR_METATYPE_APPLICATION_ID, "com.apple.iTunes"), 99 STR (EXTRACTOR_METATYPE_PURCHASE_ACCOUNT, "buyer@example.org"), 100 STR (EXTRACTOR_METATYPE_URL, 101 "https://www.gnu.org/software/libextractor/"), 102 STR (EXTRACTOR_METATYPE_URL, "https://www.gnu.org/"), 103 { 104 EXTRACTOR_METATYPE_COVER_PICTURE, 105 EXTRACTOR_METAFORMAT_BINARY, 106 "image/png", 107 "\x89PNG\r\n\x1a\n", 108 8, 109 0, 0, NULL 110 }, 111 /* the MPEG frame header, the Xing tag and the LAME tag */ 112 STR (EXTRACTOR_METATYPE_CODEC, "MPEG 1 Layer III"), 113 STR (EXTRACTOR_METATYPE_FORMAT, "MPEG 1 Layer III, mono"), 114 STR (EXTRACTOR_METATYPE_SAMPLE_RATE, "44100"), 115 STR (EXTRACTOR_METATYPE_CHANNELS, "1"), 116 STR (EXTRACTOR_METATYPE_NOMINAL_BITRATE, "128000"), 117 STR (EXTRACTOR_METATYPE_BITRATE, "40233"), 118 STR (EXTRACTOR_METATYPE_BITRATE_MODE, "VBR"), 119 STR (EXTRACTOR_METATYPE_DURATION, "0:00:01"), 120 STR (EXTRACTOR_METATYPE_ENCODER, "LAME3.100"), 121 STR (EXTRACTOR_METATYPE_ENCODER_VERSION, "3.100"), 122 STR (EXTRACTOR_METATYPE_ENCODER_SETTINGS, 123 "lowpass 17000 Hz, quality 50, VBR method 5, " 124 "min bitrate 32 kbit/s, preset 450, delay 576, padding 1404"), 125 STR (EXTRACTOR_METATYPE_TRACK_GAIN, "-6.1 dB"), 126 /* the only two items the ID3v1 tag is allowed to contribute */ 127 STR (EXTRACTOR_METATYPE_PUBLICATION_DATE, "1999"), 128 STR (EXTRACTOR_METATYPE_COMMENT, "ID3v1 comment field"), 129 { 0, 0, NULL, NULL, 0, -1, 0, NULL } 130 }; 131 struct ProblemSet ps[] = { 132 { "testdata/id3_test.mp3", 133 id3_test_sol }, 134 { NULL, NULL } 135 }; 136 137 (void) argc; 138 (void) argv; 139 return ET_main ("id3", ps); 140 } 141 142 143 /* end of test_id3.c */