diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-08-03 23:05:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-08-03 23:05:01 +0000 |
commit | 14a5820190d667cb1a95368f35b82542a45217af (patch) | |
tree | 9ded5d445b862dc8cbd810194b3190706e601316 | |
parent | 9dfb9eba8b2216462b90e2815da39bda7e2f6b18 (diff) | |
download | libextractor-14a5820190d667cb1a95368f35b82542a45217af.tar.gz libextractor-14a5820190d667cb1a95368f35b82542a45217af.zip |
adding test for IO with file
-rw-r--r-- | src/main/Makefile.am | 6 | ||||
-rw-r--r-- | src/main/test_file.c | 154 | ||||
-rw-r--r-- | src/main/test_file.dat | bin | 0 -> 153600 bytes |
3 files changed, 159 insertions, 1 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index d793a31..d5245f9 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -84,7 +84,8 @@ check_PROGRAMS = \ | |||
84 | test_trivial \ | 84 | test_trivial \ |
85 | test_plugin_loading \ | 85 | test_plugin_loading \ |
86 | test_plugin_load_multi \ | 86 | test_plugin_load_multi \ |
87 | test_ipc | 87 | test_ipc \ |
88 | test_file | ||
88 | 89 | ||
89 | TESTS = $(check_PROGRAMS) | 90 | TESTS = $(check_PROGRAMS) |
90 | 91 | ||
@@ -100,3 +101,6 @@ test_plugin_load_multi_SOURCES = \ | |||
100 | test_ipc_SOURCES = \ | 101 | test_ipc_SOURCES = \ |
101 | test_ipc.c | 102 | test_ipc.c |
102 | 103 | ||
104 | test_file_SOURCES = \ | ||
105 | test_file.c | ||
106 | |||
diff --git a/src/main/test_file.c b/src/main/test_file.c new file mode 100644 index 0000000..95c6ffb --- /dev/null +++ b/src/main/test_file.c | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (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., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file main/test_file.c | ||
22 | * @brief testcase for the extractor file-IO part (using IPC logic) | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "extractor.h" | ||
27 | |||
28 | /** | ||
29 | * Return value from main, set to 0 for test to succeed. | ||
30 | */ | ||
31 | static int ret = 2; | ||
32 | |||
33 | #define HLO "Hello world!" | ||
34 | #define GOB "Goodbye!" | ||
35 | |||
36 | /** | ||
37 | * Function that libextractor calls for each | ||
38 | * meta data item found. Should be called once | ||
39 | * with 'Hello World!" and once with "Goodbye!". | ||
40 | * | ||
41 | * @param cls closure should be "main-cls" | ||
42 | * @param plugin_name should be "test" | ||
43 | * @param type should be "COMMENT" | ||
44 | * @param format should be "UTF8" | ||
45 | * @param data_mime_type should be "<no mime>" | ||
46 | * @param data hello world or good bye | ||
47 | * @param data_len number of bytes in data | ||
48 | * @return 0 on hello world, 1 on goodbye | ||
49 | */ | ||
50 | static int | ||
51 | process_replies (void *cls, | ||
52 | const char *plugin_name, | ||
53 | enum EXTRACTOR_MetaType type, | ||
54 | enum EXTRACTOR_MetaFormat format, | ||
55 | const char *data_mime_type, | ||
56 | const char *data, | ||
57 | size_t data_len) | ||
58 | { | ||
59 | if (0 != strcmp (cls, | ||
60 | "main-cls")) | ||
61 | { | ||
62 | fprintf (stderr, "closure invalid\n"); | ||
63 | ret = 3; | ||
64 | return 1; | ||
65 | } | ||
66 | if (0 != strcmp (plugin_name, | ||
67 | "test")) | ||
68 | { | ||
69 | fprintf (stderr, "plugin name invalid\n"); | ||
70 | ret = 4; | ||
71 | return 1; | ||
72 | } | ||
73 | if (EXTRACTOR_METATYPE_COMMENT != type) | ||
74 | { | ||
75 | fprintf (stderr, "type invalid\n"); | ||
76 | ret = 5; | ||
77 | return 1; | ||
78 | } | ||
79 | if (EXTRACTOR_METAFORMAT_UTF8 != format) | ||
80 | { | ||
81 | fprintf (stderr, "format invalid\n"); | ||
82 | ret = 6; | ||
83 | return 1; | ||
84 | } | ||
85 | if ( (NULL == data_mime_type) || | ||
86 | (0 != strcmp ("<no mime>", | ||
87 | data_mime_type) ) ) | ||
88 | { | ||
89 | fprintf (stderr, "bad mime type\n"); | ||
90 | ret = 7; | ||
91 | return 1; | ||
92 | } | ||
93 | if ( (2 == ret) && | ||
94 | (data_len == strlen (HLO) + 1) && | ||
95 | (0 == strncmp (data, | ||
96 | HLO, | ||
97 | strlen (HLO))) ) | ||
98 | { | ||
99 | #if 0 | ||
100 | fprintf (stderr, "Received '%s'\n", HLO); | ||
101 | #endif | ||
102 | ret = 1; | ||
103 | return 0; | ||
104 | } | ||
105 | if ( (1 == ret) && | ||
106 | (data_len == strlen (GOB) + 1) && | ||
107 | (0 == strncmp (data, | ||
108 | GOB, | ||
109 | strlen (GOB))) ) | ||
110 | { | ||
111 | #if 0 | ||
112 | fprintf (stderr, "Received '%s'\n", GOB); | ||
113 | #endif | ||
114 | ret = 0; | ||
115 | return 1; | ||
116 | } | ||
117 | fprintf (stderr, "Invalid meta data\n"); | ||
118 | ret = 8; | ||
119 | return 1; | ||
120 | } | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Main function for the file-IO testcase. | ||
125 | * | ||
126 | * @param argc number of arguments (ignored) | ||
127 | * @param argv arguments (ignored) | ||
128 | * @return 0 on success | ||
129 | */ | ||
130 | int | ||
131 | main (int argc, char *argv[]) | ||
132 | { | ||
133 | struct EXTRACTOR_PluginList *pl; | ||
134 | |||
135 | /* change environment to find 'extractor_test' plugin which is | ||
136 | not installed but should be in the current directory (or .libs) | ||
137 | on 'make check' */ | ||
138 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) | ||
139 | fprintf (stderr, | ||
140 | "Failed to update my environment, plugin loading may fail: %s\n", | ||
141 | strerror (errno)); | ||
142 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", | ||
143 | EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
144 | if (NULL == pl) | ||
145 | { | ||
146 | fprintf (stderr, "failed to load test plugin\n"); | ||
147 | return 1; | ||
148 | } | ||
149 | EXTRACTOR_extract (pl, "test_file.dat", NULL, 0, &process_replies, "main-cls"); | ||
150 | EXTRACTOR_plugin_remove_all (pl); | ||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | /* end of test_file.c */ | ||
diff --git a/src/main/test_file.dat b/src/main/test_file.dat new file mode 100644 index 0000000..458bcfc --- /dev/null +++ b/src/main/test_file.dat | |||
Binary files differ | |||