libextractor

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

test_mime.c (3663B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2012 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_mime.c
     22  * @brief testcase for ogg plugin
     23  * @author Christian Grothoff
     24  */
     25 #include "platform.h"
     26 #include "test_lib.h"
     27 #include <magic.h>
     28 
     29 
     30 /**
     31  * Main function for the MIME testcase.
     32  *
     33  * @param argc number of arguments (ignored)
     34  * @param argv arguments (ignored)
     35  * @return 0 on success
     36  */
     37 int
     38 main (int argc, char *argv[])
     39 {
     40   int result = 0;
     41   int test_result;
     42   int test_result_around_19, test_result_around_22;
     43   struct SolutionData courseclear_file_around_19_sol[] = {
     44     {
     45       EXTRACTOR_METATYPE_MIMETYPE,
     46       EXTRACTOR_METAFORMAT_UTF8,
     47       "text/plain",
     48       /* not sure which is the exact version, but old ones do
     49          not even define MAGIC_VERSION, so this is approximately
     50          right. Users where this tests fail should report
     51          their version number from "magic.h" so we can adjust
     52          if necessary. */
     53 #ifdef MAGIC_VERSION
     54       "audio/ogg",
     55       strlen ("audio/ogg") + 1,
     56 #else
     57       "application/ogg",
     58       strlen ("application/ogg") + 1,
     59 #endif
     60       0
     61     },
     62     { 0, 0, NULL, NULL, 0, -1 }
     63   };
     64   struct SolutionData courseclear_file_around_22_sol[] = {
     65     {
     66       EXTRACTOR_METATYPE_MIMETYPE,
     67       EXTRACTOR_METAFORMAT_UTF8,
     68       "text/plain",
     69       "audio/ogg",
     70       strlen ("audio/ogg") + 1,
     71       0
     72     },
     73     { 0, 0, NULL, NULL, 0, -1 }
     74   };
     75   struct SolutionData gif_image_sol[] = {
     76     {
     77       EXTRACTOR_METATYPE_MIMETYPE,
     78       EXTRACTOR_METAFORMAT_UTF8,
     79       "text/plain",
     80       "image/gif",
     81       strlen ("image/gif") + 1,
     82       0
     83     },
     84     { 0, 0, NULL, NULL, 0, -1 }
     85   };
     86   struct ProblemSet ps_gif[] = {
     87     { "testdata/gif_image.gif",
     88       gif_image_sol },
     89     { NULL, NULL }
     90   };
     91   struct ProblemSet ps_ogg_around_19[] = {
     92     { "testdata/ogg_courseclear.ogg",
     93       courseclear_file_around_19_sol },
     94     { NULL, NULL }
     95   };
     96   struct ProblemSet ps_ogg_around_22[] = {
     97     { "testdata/ogg_courseclear.ogg",
     98       courseclear_file_around_22_sol },
     99     { NULL, NULL }
    100   };
    101   printf ("Running gif test on libmagic:\n");
    102   test_result = (0 == ET_main ("mime", ps_gif) ? 0 : 1);
    103   printf ("gif libmagic test result: %s\n", test_result == 0 ? "OK" : "FAILED");
    104   result += test_result;
    105 
    106   printf ("Running ogg test on libmagic, assuming version ~5.19:\n");
    107   test_result_around_19 = (0 == ET_main ("mime", ps_ogg_around_19) ? 0 : 1);
    108   printf ("ogg libmagic test result: %s\n", test_result_around_19 == 0 ? "OK" :
    109           "FAILED");
    110 
    111   printf ("Running ogg test on libmagic, assuming version ~5.22:\n");
    112   test_result_around_22 = (0 == ET_main ("mime", ps_ogg_around_22) ? 0 : 1);
    113   printf ("ogg libmagic test result: %s\n", test_result_around_22 == 0 ? "OK" :
    114           "FAILED");
    115 
    116   if ((test_result_around_19 != 0) && (test_result_around_22 != 0))
    117     result++;
    118   return result;
    119 }
    120 
    121 
    122 /* end of test_mime.c */