libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

test_previewgst.c (2898B)


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