libextractor

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

test_lib.h (2845B)


      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_lib.h
     22  * @brief helper library for writing testcases
     23  * @author Christian Grothoff
     24  */
     25 #ifndef TEST_LIB_H
     26 #define TEST_LIB_H
     27 
     28 #include "extractor.h"
     29 
     30 /**
     31  * Expected outcome from the plugin.
     32  */
     33 struct SolutionData
     34 {
     35   /**
     36    * Expected type.
     37    */
     38   enum EXTRACTOR_MetaType type;
     39 
     40   /**
     41    * Expected format.
     42    */
     43   enum EXTRACTOR_MetaFormat format;
     44 
     45   /**
     46    * Expected data mime type.
     47    */
     48   const char *data_mime_type;
     49 
     50   /**
     51    * Expected meta data.
     52    */
     53   const char *data;
     54 
     55   /**
     56    * Expected number of bytes in meta data.
     57    */
     58   size_t data_len;
     59 
     60   /**
     61    * Internally used flag to say if this solution was
     62    * provided by the plugin; 0 for no, 1 for yes; -1 to
     63    * terminate the list.
     64    */
     65   int solved;
     66 
     67   /**
     68    * Treat solution as a regex that must match.
     69    */
     70   int regex;
     71 
     72   /**
     73    * Optional additional check on the meta data, for values that cannot
     74    * be spelled out in a test (an encoder's output, say, of which only
     75    * the header is predictable).  Called after type, format, mime type
     76    * and the @e data prefix matched; the item only counts as solved if
     77    * this returns non-zero.  NULL to skip.
     78    *
     79    * @param data the meta data the plugin produced
     80    * @param data_len number of bytes in @a data
     81    * @return non-zero if @a data is acceptable
     82    */
     83   int (*validate)(const void *data,
     84                   size_t data_len);
     85 };
     86 
     87 
     88 /**
     89  * Set of problems
     90  */
     91 struct ProblemSet
     92 {
     93   /**
     94    * File to run the extractor on, NULL
     95    * to terminate the array.
     96    */
     97   const char *filename;
     98 
     99   /**
    100    * Expected meta data.  Terminate array with -1 in 'solved'.
    101    */
    102   struct SolutionData *solution;
    103 
    104 };
    105 
    106 
    107 /**
    108  * Main function to be called to test a plugin.
    109  *
    110  * @param plugin_name name of the plugin to load
    111  * @param ps array of problems the plugin should solve;
    112  *        NULL in filename terminates the array.
    113  * @return 0 on success, 1 on failure
    114  */
    115 int
    116 ET_main (const char *plugin_name,
    117          struct ProblemSet *ps);
    118 
    119 #endif