test_previewopus.c (2937B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2013, 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_previewopus.c 22 * @brief testcase for the previewopus plugin 23 * @author Bruno Cabral 24 * @author Christian Grothoff 25 * 26 * What comes out is an Opus stream, and comparing that byte for byte 27 * would mean pinning down a particular version of libopus. So we check 28 * that it is a well formed Ogg stream carrying the OpusHead 29 * identification header of RFC 7845, and that it is neither empty nor 30 * absurdly large. 31 */ 32 #include "platform.h" 33 #include "test_lib.h" 34 #include "test_media_lib.h" 35 36 37 /** 38 * Check that the preview is a plausible Ogg Opus stream. 39 * 40 * @param data the preview the plugin produced 41 * @param data_len number of bytes in @a data 42 * @return non-zero if the preview looks right 43 */ 44 static int 45 validate_opus (const void *data, 46 size_t data_len) 47 { 48 if (data_len < 1024) 49 { 50 fprintf (stderr, 51 "Audio preview of %u bytes is too short to be 15s of Opus\n", 52 (unsigned int) data_len); 53 return 0; 54 } 55 return TEST_media_is_ogg_opus (data, 56 data_len); 57 } 58 59 60 /** 61 * Main function for the previewopus testcase. 62 * 63 * @param argc number of arguments (ignored) 64 * @param argv arguments (ignored) 65 * @return 0 on success 66 */ 67 int 68 main (int argc, char *argv[]) 69 { 70 struct SolutionData previewopus_sol[] = { 71 { 72 EXTRACTOR_METATYPE_AUDIO_PREVIEW, 73 EXTRACTOR_METAFORMAT_BINARY, 74 "audio/ogg", 75 "OggS", 76 strlen ("OggS"), 77 0, 78 0, 79 &validate_opus 80 }, 81 { 0, 0, NULL, NULL, 0, -1 } 82 }; 83 struct SolutionData previewopus_video_sol[] = { 84 { 85 EXTRACTOR_METATYPE_AUDIO_PREVIEW, 86 EXTRACTOR_METAFORMAT_BINARY, 87 "audio/ogg", 88 "OggS", 89 strlen ("OggS"), 90 0, 91 0, 92 &validate_opus 93 }, 94 { 0, 0, NULL, NULL, 0, -1 } 95 }; 96 struct ProblemSet ps[] = { 97 { "testdata/preview_tone.ogg", 98 previewopus_sol }, 99 { "testdata/preview_tone.ogv", 100 previewopus_video_sol }, 101 { NULL, NULL } 102 }; 103 104 return ET_main ("previewopus", 105 ps); 106 } 107 108 109 /* end of test_previewopus.c */