diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/Makefile.am | 11 | ||||
-rw-r--r-- | src/main/test2_extractor.c | 145 | ||||
-rw-r--r-- | src/main/test_ipc.c | 5 |
3 files changed, 160 insertions, 1 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 4577ae0..8e8c086 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -74,7 +74,8 @@ TESTS_ENVIRONMENT = testdatadir=$(top_srcdir)/test | |||
74 | TESTS_ENVIRONMENT += bindir=${bindir} | 74 | TESTS_ENVIRONMENT += bindir=${bindir} |
75 | 75 | ||
76 | tmp_LTLIBRARIES = \ | 76 | tmp_LTLIBRARIES = \ |
77 | libextractor_test.la | 77 | libextractor_test.la \ |
78 | libextractor_test2.la | ||
78 | 79 | ||
79 | libextractor_test_la_SOURCES = \ | 80 | libextractor_test_la_SOURCES = \ |
80 | test_extractor.c | 81 | test_extractor.c |
@@ -83,6 +84,14 @@ libextractor_test_la_LDFLAGS = \ | |||
83 | libextractor_test_la_LIBADD = \ | 84 | libextractor_test_la_LIBADD = \ |
84 | $(LE_LIBINTL) | 85 | $(LE_LIBINTL) |
85 | 86 | ||
87 | libextractor_test2_la_SOURCES = \ | ||
88 | test2_extractor.c | ||
89 | libextractor_test2_la_LDFLAGS = \ | ||
90 | $(PLUGINFLAGS) | ||
91 | libextractor_test2_la_LIBADD = \ | ||
92 | $(LE_LIBINTL) | ||
93 | |||
94 | |||
86 | check_PROGRAMS = \ | 95 | check_PROGRAMS = \ |
87 | test_trivial \ | 96 | test_trivial \ |
88 | test_plugin_loading \ | 97 | test_plugin_loading \ |
diff --git a/src/main/test2_extractor.c b/src/main/test2_extractor.c new file mode 100644 index 0000000..ce6424b --- /dev/null +++ b/src/main/test2_extractor.c | |||
@@ -0,0 +1,145 @@ | |||
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/test2_extractor.c | ||
22 | * @brief plugin for testing GNU libextractor | ||
23 | * Data file (or buffer) for this test must be 150 * 1024 bytes long, | ||
24 | * first 4 bytes must be "test", all other bytes should be equal to | ||
25 | * <FILE_OFFSET> % 256. The test client must return 0 after seeing | ||
26 | * "Hello World!" metadata, and return 1 after seeing "Goodbye!" | ||
27 | * metadata. | ||
28 | * @author Christian Grothoff | ||
29 | */ | ||
30 | #include "platform.h" | ||
31 | #include "extractor.h" | ||
32 | #include <string.h> | ||
33 | #include <stdio.h> | ||
34 | #include <sys/types.h> | ||
35 | #include <sys/stat.h> | ||
36 | #include <unistd.h> | ||
37 | #include <stdlib.h> | ||
38 | |||
39 | |||
40 | |||
41 | /** | ||
42 | * Signature of the extract method that each plugin | ||
43 | * must provide. | ||
44 | * | ||
45 | * @param ec extraction context provided to the plugin | ||
46 | */ | ||
47 | void | ||
48 | EXTRACTOR_test2_extract_method (struct EXTRACTOR_ExtractContext *ec) | ||
49 | { | ||
50 | void *dp; | ||
51 | |||
52 | if ((NULL == ec->config) || (0 != strcmp (ec->config, "test2"))) | ||
53 | return; /* only run in test mode */ | ||
54 | if (4 != ec->read (ec->cls, &dp, 4)) | ||
55 | { | ||
56 | fprintf (stderr, "Reading at offset 0 failed\n"); | ||
57 | ABORT (); | ||
58 | } | ||
59 | if (0 != strncmp ("test", dp, 4)) | ||
60 | { | ||
61 | fprintf (stderr, "Unexpected data at offset 0\n"); | ||
62 | ABORT (); | ||
63 | } | ||
64 | if ( (1024 * 150 != ec->get_size (ec->cls)) && | ||
65 | (UINT64_MAX != ec->get_size (ec->cls)) ) | ||
66 | { | ||
67 | fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); | ||
68 | ABORT (); | ||
69 | } | ||
70 | if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET)) | ||
71 | { | ||
72 | fprintf (stderr, "Failure to seek (SEEK_SET)\n"); | ||
73 | ABORT (); | ||
74 | } | ||
75 | if (1 != ec->read (ec->cls, &dp, 1)) | ||
76 | { | ||
77 | fprintf (stderr, "Failure to read at 100k + 4\n"); | ||
78 | ABORT (); | ||
79 | } | ||
80 | if ((1024 * 100 + 4) % 256 != * (unsigned char *) dp) | ||
81 | { | ||
82 | fprintf (stderr, "Unexpected data at offset 100k + 4\n"); | ||
83 | ABORT (); | ||
84 | } | ||
85 | if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) != | ||
86 | ec->seek (ec->cls, - (1024 * 50 + 7), SEEK_CUR)) | ||
87 | { | ||
88 | fprintf (stderr, "Failure to seek (SEEK_SET)\n"); | ||
89 | ABORT (); | ||
90 | } | ||
91 | if (1 != ec->read (ec->cls, &dp, 1)) | ||
92 | { | ||
93 | fprintf (stderr, "Failure to read at 50k - 3\n"); | ||
94 | ABORT (); | ||
95 | } | ||
96 | if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != * (unsigned char *) dp) | ||
97 | { | ||
98 | fprintf (stderr, "Unexpected data at offset 100k - 3\n"); | ||
99 | ABORT (); | ||
100 | } | ||
101 | if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END)) | ||
102 | { | ||
103 | fprintf (stderr, "Failure to seek (SEEK_END)\n"); | ||
104 | ABORT (); | ||
105 | } | ||
106 | if (0 != ec->read (ec->cls, &dp, 1)) | ||
107 | { | ||
108 | fprintf (stderr, "Failed to receive EOF at 150k\n"); | ||
109 | ABORT (); | ||
110 | } | ||
111 | if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END)) | ||
112 | { | ||
113 | fprintf (stderr, "Failure to seek (SEEK_END - 2)\n"); | ||
114 | ABORT (); | ||
115 | } | ||
116 | if (1 != ec->read (ec->cls, &dp, 1)) | ||
117 | { | ||
118 | fprintf (stderr, "Failure to read at 150k - 3\n"); | ||
119 | ABORT (); | ||
120 | } | ||
121 | if ((1024 * 150 - 2) % 256 != * (unsigned char *) dp) | ||
122 | { | ||
123 | fprintf (stderr, "Unexpected data at offset 150k - 3\n"); | ||
124 | ABORT (); | ||
125 | } | ||
126 | if (0 != ec->proc (ec->cls, "test2", EXTRACTOR_METATYPE_COMMENT, | ||
127 | EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Hello world!", | ||
128 | strlen ("Hello world!") + 1)) | ||
129 | { | ||
130 | fprintf (stderr, "Unexpected return value from 'proc'\n"); | ||
131 | ABORT (); | ||
132 | } | ||
133 | /* The test assumes that client orders us to stop extraction | ||
134 | * after seeing "Goodbye!". | ||
135 | */ | ||
136 | if (1 != ec->proc (ec->cls, "test2", EXTRACTOR_METATYPE_COMMENT, | ||
137 | EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Goodbye!", | ||
138 | strlen ("Goodbye!") + 1)) | ||
139 | { | ||
140 | fprintf (stderr, "Unexpected return value from 'proc'\n"); | ||
141 | ABORT (); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | /* end of test2_extractor.c */ | ||
diff --git a/src/main/test_ipc.c b/src/main/test_ipc.c index b0b09cb..4d03d84 100644 --- a/src/main/test_ipc.c +++ b/src/main/test_ipc.c | |||
@@ -63,6 +63,9 @@ process_replies (void *cls, | |||
63 | ret = 3; | 63 | ret = 3; |
64 | return 1; | 64 | return 1; |
65 | } | 65 | } |
66 | if (0 == strcmp (plugin_name, | ||
67 | "test2")) | ||
68 | return 0; /* ignore 'test2' plugins */ | ||
66 | if (0 != strcmp (plugin_name, | 69 | if (0 != strcmp (plugin_name, |
67 | "test")) | 70 | "test")) |
68 | { | 71 | { |
@@ -148,6 +151,8 @@ main (int argc, char *argv[]) | |||
148 | strerror (errno)); | 151 | strerror (errno)); |
149 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", | 152 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", |
150 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 153 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
154 | pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)", | ||
155 | EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
151 | if (NULL == pl) | 156 | if (NULL == pl) |
152 | { | 157 | { |
153 | fprintf (stderr, "failed to load test plugin\n"); | 158 | fprintf (stderr, "failed to load test plugin\n"); |