diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-30 21:59:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-30 21:59:59 +0000 |
commit | adec71a99fd28652c17bc1f497e91e8ad76ddf84 (patch) | |
tree | 2f182dac2919efbb0cbc069e047eed216bca6f28 | |
parent | a802688810d4dd81d348d442672218fd795140ef (diff) | |
download | libextractor-adec71a99fd28652c17bc1f497e91e8ad76ddf84.tar.gz libextractor-adec71a99fd28652c17bc1f497e91e8ad76ddf84.zip |
writing IPC testcase
-rw-r--r-- | src/main/Makefile.am | 6 | ||||
-rw-r--r-- | src/main/extractor_plugpath.c | 2 | ||||
-rw-r--r-- | src/main/test_ipc.c | 153 |
3 files changed, 159 insertions, 2 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 33acdf7..f9bec0a 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -76,7 +76,8 @@ libextractor_test_la_LIBADD = \ | |||
76 | check_PROGRAMS = \ | 76 | check_PROGRAMS = \ |
77 | test_trivial \ | 77 | test_trivial \ |
78 | test_plugin_loading \ | 78 | test_plugin_loading \ |
79 | test_plugin_load_multi | 79 | test_plugin_load_multi \ |
80 | test_ipc | ||
80 | 81 | ||
81 | TESTS = $(check_PROGRAMS) | 82 | TESTS = $(check_PROGRAMS) |
82 | 83 | ||
@@ -89,3 +90,6 @@ test_plugin_loading_SOURCES = \ | |||
89 | test_plugin_load_multi_SOURCES = \ | 90 | test_plugin_load_multi_SOURCES = \ |
90 | test_plugin_load_multi.c | 91 | test_plugin_load_multi.c |
91 | 92 | ||
93 | test_ipc_SOURCES = \ | ||
94 | test_ipc.c | ||
95 | |||
diff --git a/src/main/extractor_plugpath.c b/src/main/extractor_plugpath.c index d45622e..62f0d96 100644 --- a/src/main/extractor_plugpath.c +++ b/src/main/extractor_plugpath.c | |||
@@ -436,7 +436,7 @@ get_installation_paths (EXTRACTOR_PathProcessor pp, | |||
436 | for (prefix = strtok (d, PATH_SEPARATOR_STR); | 436 | for (prefix = strtok (d, PATH_SEPARATOR_STR); |
437 | NULL != prefix; | 437 | NULL != prefix; |
438 | prefix = strtok (NULL, PATH_SEPARATOR_STR)) | 438 | prefix = strtok (NULL, PATH_SEPARATOR_STR)) |
439 | pp (pp_cls, prefix); | 439 | pp (pp_cls, prefix); |
440 | free (d); | 440 | free (d); |
441 | return; | 441 | return; |
442 | } | 442 | } |
diff --git a/src/main/test_ipc.c b/src/main/test_ipc.c new file mode 100644 index 0000000..35750b7 --- /dev/null +++ b/src/main/test_ipc.c | |||
@@ -0,0 +1,153 @@ | |||
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_ipc.c | ||
22 | * @brief testcase for the extractor IPC using the "test" plugin | ||
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 | |||
34 | /** | ||
35 | * Function that libextractor calls for each | ||
36 | * meta data item found. Should be called once | ||
37 | * with 'Hello World!" and once with "Goodbye!". | ||
38 | * | ||
39 | * @param cls closure should be "main-cls" | ||
40 | * @param plugin_name should be "test" | ||
41 | * @param type should be "COMMENT" | ||
42 | * @param format should be "UTF8" | ||
43 | * @param data_mime_type should be "<no mime>" | ||
44 | * @param data hello world or good bye | ||
45 | * @param data_len number of bytes in data | ||
46 | * @return 0 on hello world, 1 on goodbye | ||
47 | */ | ||
48 | static int | ||
49 | process_replies (void *cls, | ||
50 | const char *plugin_name, | ||
51 | enum EXTRACTOR_MetaType type, | ||
52 | enum EXTRACTOR_MetaFormat format, | ||
53 | const char *data_mime_type, | ||
54 | const char *data, | ||
55 | size_t data_len) | ||
56 | { | ||
57 | if (0 != strcmp (cls, | ||
58 | "main-cls")) | ||
59 | { | ||
60 | fprintf (stderr, "closure invalid\n"); | ||
61 | ret = 3; | ||
62 | return 1; | ||
63 | } | ||
64 | if (0 != strcmp (plugin_name, | ||
65 | "test")) | ||
66 | { | ||
67 | fprintf (stderr, "plugin name invalid\n"); | ||
68 | ret = 4; | ||
69 | return 1; | ||
70 | } | ||
71 | if (EXTRACTOR_METATYPE_COMMENT != type) | ||
72 | { | ||
73 | fprintf (stderr, "type invalid\n"); | ||
74 | ret = 5; | ||
75 | return 1; | ||
76 | } | ||
77 | if (EXTRACTOR_METAFORMAT_UTF8 != format) | ||
78 | { | ||
79 | fprintf (stderr, "format invalid\n"); | ||
80 | ret = 6; | ||
81 | return 1; | ||
82 | } | ||
83 | if ( (NULL == data_mime_type) || | ||
84 | (0 != strcmp ("<no mime>", | ||
85 | data_mime_type) ) ) | ||
86 | { | ||
87 | fprintf (stderr, "bad mime type\n"); | ||
88 | ret = 7; | ||
89 | return 1; | ||
90 | } | ||
91 | if ( (2 == ret) && | ||
92 | (data_len == strlen ("Hello world!") + 1) && | ||
93 | (0 == strncmp (data, | ||
94 | "Hello world!", | ||
95 | strlen ("Hello world!"))) ) | ||
96 | { | ||
97 | ret = 1; | ||
98 | return 0; | ||
99 | } | ||
100 | if ( (1 == ret) && | ||
101 | (data_len == strlen ("Goodbye!") + 1) && | ||
102 | (0 == strncmp (data, | ||
103 | "Goodbyte!", | ||
104 | strlen ("Goodbye!"))) ) | ||
105 | { | ||
106 | ret = 0; | ||
107 | return 1; | ||
108 | } | ||
109 | fprintf (stderr, "Invalid meta data\n"); | ||
110 | ret = 8; | ||
111 | return 1; | ||
112 | } | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Main function for the IPC testcase. | ||
117 | * | ||
118 | * @param argc number of arguments (ignored) | ||
119 | * @param argv arguments (ignored) | ||
120 | * @return 0 on success | ||
121 | */ | ||
122 | int | ||
123 | main (int argc, char *argv[]) | ||
124 | { | ||
125 | struct EXTRACTOR_PluginList *pl; | ||
126 | unsigned char buf[1024 * 150]; | ||
127 | size_t i; | ||
128 | |||
129 | /* initialize test buffer as expected by test plugin */ | ||
130 | for (i=0;i<sizeof(buf);i++) | ||
131 | buf[i] = (unsigned char) (i % 256); | ||
132 | memcpy (buf, "test", 4); | ||
133 | |||
134 | /* change environment to find 'extractor_test' plugin which is | ||
135 | not installed but should be in the current directory (or .libs) | ||
136 | on 'make check' */ | ||
137 | if (0 != setenv ("LIBEXTRACTOR_PREFIX", ".:.libs/", 1)) | ||
138 | fprintf (stderr, | ||
139 | "Failed to update my environment, plugin loading may fail: %s\n", | ||
140 | strerror (errno)); | ||
141 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", | ||
142 | EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
143 | if (NULL == pl) | ||
144 | { | ||
145 | fprintf (stderr, "failed to load test plugin\n"); | ||
146 | return 1; | ||
147 | } | ||
148 | EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); | ||
149 | EXTRACTOR_plugin_remove_all (pl); | ||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | /* end of test_ipc.c */ | ||