diff options
Diffstat (limited to 'src/plugins/test_lib.c')
-rw-r--r-- | src/plugins/test_lib.c | 141 |
1 files changed, 71 insertions, 70 deletions
diff --git a/src/plugins/test_lib.c b/src/plugins/test_lib.c index ebc8f04..efbe2cf 100644 --- a/src/plugins/test_lib.c +++ b/src/plugins/test_lib.c | |||
@@ -38,56 +38,56 @@ | |||
38 | * @param data hello world or good bye | 38 | * @param data hello world or good bye |
39 | * @param data_len number of bytes in data | 39 | * @param data_len number of bytes in data |
40 | * @return 0 (always) | 40 | * @return 0 (always) |
41 | */ | 41 | */ |
42 | static int | 42 | static int |
43 | process_replies (void *cls, | 43 | process_replies (void *cls, |
44 | const char *plugin_name, | 44 | const char *plugin_name, |
45 | enum EXTRACTOR_MetaType type, | 45 | enum EXTRACTOR_MetaType type, |
46 | enum EXTRACTOR_MetaFormat format, | 46 | enum EXTRACTOR_MetaFormat format, |
47 | const char *data_mime_type, | 47 | const char *data_mime_type, |
48 | const char *data, | 48 | const char *data, |
49 | size_t data_len) | 49 | size_t data_len) |
50 | { | 50 | { |
51 | struct SolutionData *sd = cls; | 51 | struct SolutionData *sd = cls; |
52 | unsigned int i; | 52 | unsigned int i; |
53 | 53 | ||
54 | for (i=0; -1 != sd[i].solved; i++) | 54 | for (i = 0; -1 != sd[i].solved; i++) |
55 | { | ||
56 | if ( (0 != sd[i].solved) || | ||
57 | (sd[i].type != type) || | ||
58 | (sd[i].format != format) ) | ||
59 | continue; | ||
60 | if ( (EXTRACTOR_METAFORMAT_BINARY != format) && | ||
61 | ( (sd[i].data_len != data_len) || | ||
62 | (0 != memcmp (sd[i].data, data, data_len)) ) ) | ||
63 | continue; | ||
64 | if ( (EXTRACTOR_METAFORMAT_BINARY == format) && | ||
65 | ( (sd[i].data_len > data_len) || | ||
66 | (0 != memcmp (sd[i].data, data, sd[i].data_len)) ) ) | ||
67 | continue; | ||
68 | |||
69 | if (NULL != sd[i].data_mime_type) | ||
55 | { | 70 | { |
56 | if ( (0 != sd[i].solved) || | 71 | if (NULL == data_mime_type) |
57 | (sd[i].type != type) || | 72 | continue; |
58 | (sd[i].format != format) ) | 73 | if (0 != strcmp (sd[i].data_mime_type, data_mime_type)) |
59 | continue; | 74 | continue; |
60 | if ( (EXTRACTOR_METAFORMAT_BINARY != format) && | ||
61 | ( (sd[i].data_len != data_len) || | ||
62 | (0 != memcmp (sd[i].data, data, data_len)) ) ) | ||
63 | continue; | ||
64 | if ( (EXTRACTOR_METAFORMAT_BINARY == format) && | ||
65 | ( (sd[i].data_len > data_len) || | ||
66 | (0 != memcmp (sd[i].data, data, sd[i].data_len)) ) ) | ||
67 | continue; | ||
68 | |||
69 | if (NULL != sd[i].data_mime_type) | ||
70 | { | ||
71 | if (NULL == data_mime_type) | ||
72 | continue; | ||
73 | if (0 != strcmp (sd[i].data_mime_type, data_mime_type)) | ||
74 | continue; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | if (NULL != data_mime_type) | ||
79 | continue; | ||
80 | } | ||
81 | sd[i].solved = 1; | ||
82 | return 0; | ||
83 | } | 75 | } |
84 | fprintf (stderr, | 76 | else |
85 | "Got additional meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", | 77 | { |
86 | type, | 78 | if (NULL != data_mime_type) |
87 | format, | 79 | continue; |
88 | (int) data_len, | 80 | } |
89 | data, | 81 | sd[i].solved = 1; |
90 | plugin_name); | 82 | return 0; |
83 | } | ||
84 | fprintf (stderr, | ||
85 | "Got additional meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", | ||
86 | type, | ||
87 | format, | ||
88 | (int) data_len, | ||
89 | data, | ||
90 | plugin_name); | ||
91 | return 0; | 91 | return 0; |
92 | } | 92 | } |
93 | 93 | ||
@@ -97,11 +97,11 @@ process_replies (void *cls, | |||
97 | * | 97 | * |
98 | * @param plugin_name name of the plugin to load | 98 | * @param plugin_name name of the plugin to load |
99 | * @param ps array of problems the plugin should solve; | 99 | * @param ps array of problems the plugin should solve; |
100 | * NULL in filename terminates the array. | 100 | * NULL in filename terminates the array. |
101 | * @param opt options to use for loading the plugin | 101 | * @param opt options to use for loading the plugin |
102 | * @return 0 on success, 1 on failure | 102 | * @return 0 on success, 1 on failure |
103 | */ | 103 | */ |
104 | static int | 104 | static int |
105 | run (const char *plugin_name, | 105 | run (const char *plugin_name, |
106 | struct ProblemSet *ps, | 106 | struct ProblemSet *ps, |
107 | enum EXTRACTOR_Options opt) | 107 | enum EXTRACTOR_Options opt) |
@@ -111,32 +111,33 @@ run (const char *plugin_name, | |||
111 | unsigned int j; | 111 | unsigned int j; |
112 | int ret; | 112 | int ret; |
113 | 113 | ||
114 | pl = EXTRACTOR_plugin_add_config (NULL, | 114 | pl = EXTRACTOR_plugin_add_config (NULL, |
115 | plugin_name, | 115 | plugin_name, |
116 | opt); | 116 | opt); |
117 | for (i=0; NULL != ps[i].filename; i++) | 117 | for (i = 0; NULL != ps[i].filename; i++) |
118 | EXTRACTOR_extract (pl, | 118 | EXTRACTOR_extract (pl, |
119 | ps[i].filename, | 119 | ps[i].filename, |
120 | NULL, 0, | 120 | NULL, 0, |
121 | &process_replies, | 121 | &process_replies, |
122 | ps[i].solution); | 122 | ps[i].solution); |
123 | EXTRACTOR_plugin_remove_all (pl); | 123 | EXTRACTOR_plugin_remove_all (pl); |
124 | ret = 0; | 124 | ret = 0; |
125 | for (i=0; NULL != ps[i].filename; i++) | 125 | for (i = 0; NULL != ps[i].filename; i++) |
126 | for (j=0; -1 != ps[i].solution[j].solved; j++) | 126 | for (j = 0; -1 != ps[i].solution[j].solved; j++) |
127 | if (0 == ps[i].solution[j].solved) | 127 | if (0 == ps[i].solution[j].solved) |
128 | { | 128 | { |
129 | ret = 1; | 129 | ret = 1; |
130 | fprintf (stderr, | 130 | fprintf (stderr, |
131 | "Did not get expected meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", | 131 | "Did not get expected meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", |
132 | ps[i].solution[j].type, | 132 | ps[i].solution[j].type, |
133 | ps[i].solution[j].format, | 133 | ps[i].solution[j].format, |
134 | (int) ps[i].solution[j].data_len, | 134 | (int) ps[i].solution[j].data_len, |
135 | ps[i].solution[j].data, | 135 | ps[i].solution[j].data, |
136 | plugin_name); | 136 | plugin_name); |
137 | } | 137 | } |
138 | else | 138 | else |
139 | ps[i].solution[j].solved = 0; /* reset for next round */ | 139 | ps[i].solution[j].solved = 0; |
140 | /* reset for next round */ | ||
140 | return ret; | 141 | return ret; |
141 | } | 142 | } |
142 | 143 | ||
@@ -146,22 +147,22 @@ run (const char *plugin_name, | |||
146 | * | 147 | * |
147 | * @param plugin_name name of the plugin to load | 148 | * @param plugin_name name of the plugin to load |
148 | * @param ps array of problems the plugin should solve; | 149 | * @param ps array of problems the plugin should solve; |
149 | * NULL in filename terminates the array. | 150 | * NULL in filename terminates the array. |
150 | * @return 0 on success, 1 on failure | 151 | * @return 0 on success, 1 on failure |
151 | */ | 152 | */ |
152 | int | 153 | int |
153 | ET_main (const char *plugin_name, | 154 | ET_main (const char *plugin_name, |
154 | struct ProblemSet *ps) | 155 | struct ProblemSet *ps) |
155 | { | 156 | { |
156 | int ret; | 157 | int ret; |
157 | 158 | ||
158 | /* change environment to find plugins which may not yet be | 159 | /* change environment to find plugins which may not yet be |
159 | not installed but should be in the current directory (or .libs) | 160 | not installed but should be in the current directory (or .libs) |
160 | on 'make check' */ | 161 | on 'make check' */ |
161 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) | 162 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) |
162 | fprintf (stderr, | 163 | fprintf (stderr, |
163 | "Failed to update my environment, plugin loading may fail: %s\n", | 164 | "Failed to update my environment, plugin loading may fail: %s\n", |
164 | strerror (errno)); | 165 | strerror (errno)); |
165 | ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY); | 166 | ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY); |
166 | if (0 != ret) | 167 | if (0 != ret) |
167 | return ret; | 168 | return ret; |