libextractor

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

commit 14a5820190d667cb1a95368f35b82542a45217af
parent 9dfb9eba8b2216462b90e2815da39bda7e2f6b18
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri,  3 Aug 2012 23:05:01 +0000

adding test for IO with file

Diffstat:
Msrc/main/Makefile.am | 6+++++-
Asrc/main/test_file.c | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/main/test_file.dat | 0
3 files changed, 159 insertions(+), 1 deletion(-)

diff --git a/src/main/Makefile.am b/src/main/Makefile.am @@ -84,7 +84,8 @@ check_PROGRAMS = \ test_trivial \ test_plugin_loading \ test_plugin_load_multi \ - test_ipc + test_ipc \ + test_file TESTS = $(check_PROGRAMS) @@ -100,3 +101,6 @@ test_plugin_load_multi_SOURCES = \ test_ipc_SOURCES = \ test_ipc.c +test_file_SOURCES = \ + test_file.c + diff --git a/src/main/test_file.c b/src/main/test_file.c @@ -0,0 +1,154 @@ +/* + This file is part of libextractor. + (C) 2012 Vidyut Samanta and Christian Grothoff + + libextractor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + libextractor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file main/test_file.c + * @brief testcase for the extractor file-IO part (using IPC logic) + * @author Christian Grothoff + */ +#include "platform.h" +#include "extractor.h" + +/** + * Return value from main, set to 0 for test to succeed. + */ +static int ret = 2; + +#define HLO "Hello world!" +#define GOB "Goodbye!" + +/** + * Function that libextractor calls for each + * meta data item found. Should be called once + * with 'Hello World!" and once with "Goodbye!". + * + * @param cls closure should be "main-cls" + * @param plugin_name should be "test" + * @param type should be "COMMENT" + * @param format should be "UTF8" + * @param data_mime_type should be "<no mime>" + * @param data hello world or good bye + * @param data_len number of bytes in data + * @return 0 on hello world, 1 on goodbye + */ +static int +process_replies (void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) +{ + if (0 != strcmp (cls, + "main-cls")) + { + fprintf (stderr, "closure invalid\n"); + ret = 3; + return 1; + } + if (0 != strcmp (plugin_name, + "test")) + { + fprintf (stderr, "plugin name invalid\n"); + ret = 4; + return 1; + } + if (EXTRACTOR_METATYPE_COMMENT != type) + { + fprintf (stderr, "type invalid\n"); + ret = 5; + return 1; + } + if (EXTRACTOR_METAFORMAT_UTF8 != format) + { + fprintf (stderr, "format invalid\n"); + ret = 6; + return 1; + } + if ( (NULL == data_mime_type) || + (0 != strcmp ("<no mime>", + data_mime_type) ) ) + { + fprintf (stderr, "bad mime type\n"); + ret = 7; + return 1; + } + if ( (2 == ret) && + (data_len == strlen (HLO) + 1) && + (0 == strncmp (data, + HLO, + strlen (HLO))) ) + { +#if 0 + fprintf (stderr, "Received '%s'\n", HLO); +#endif + ret = 1; + return 0; + } + if ( (1 == ret) && + (data_len == strlen (GOB) + 1) && + (0 == strncmp (data, + GOB, + strlen (GOB))) ) + { +#if 0 + fprintf (stderr, "Received '%s'\n", GOB); +#endif + ret = 0; + return 1; + } + fprintf (stderr, "Invalid meta data\n"); + ret = 8; + return 1; +} + + +/** + * Main function for the file-IO testcase. + * + * @param argc number of arguments (ignored) + * @param argv arguments (ignored) + * @return 0 on success + */ +int +main (int argc, char *argv[]) +{ + struct EXTRACTOR_PluginList *pl; + + /* change environment to find 'extractor_test' plugin which is + not installed but should be in the current directory (or .libs) + on 'make check' */ + if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) + fprintf (stderr, + "Failed to update my environment, plugin loading may fail: %s\n", + strerror (errno)); + pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", + EXTRACTOR_OPTION_DEFAULT_POLICY); + if (NULL == pl) + { + fprintf (stderr, "failed to load test plugin\n"); + return 1; + } + EXTRACTOR_extract (pl, "test_file.dat", NULL, 0, &process_replies, "main-cls"); + EXTRACTOR_plugin_remove_all (pl); + return ret; +} + +/* end of test_file.c */ diff --git a/src/main/test_file.dat b/src/main/test_file.dat Binary files differ.