diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/Makefile.am | 11 | ||||
-rw-r--r-- | src/main/test_extractor.c | 140 |
2 files changed, 151 insertions, 0 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 2d32ca6..33acdf7 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -56,12 +56,23 @@ extract_SOURCES = \ | |||
56 | getopt.c getopt.h getopt1.c | 56 | getopt.c getopt.h getopt1.c |
57 | 57 | ||
58 | 58 | ||
59 | |||
59 | LDADD = \ | 60 | LDADD = \ |
60 | $(top_builddir)/src/main/libextractor.la | 61 | $(top_builddir)/src/main/libextractor.la |
61 | 62 | ||
62 | TESTS_ENVIRONMENT = testdatadir=$(top_srcdir)/test | 63 | TESTS_ENVIRONMENT = testdatadir=$(top_srcdir)/test |
63 | TESTS_ENVIRONMENT += bindir=${bindir} | 64 | TESTS_ENVIRONMENT += bindir=${bindir} |
64 | 65 | ||
66 | noinst_LTLIBRARIES = \ | ||
67 | libextractor_test.la | ||
68 | |||
69 | libextractor_test_la_SOURCES = \ | ||
70 | test_extractor.c | ||
71 | libextractor_test_la_LDFLAGS = \ | ||
72 | $(PLUGINFLAGS) | ||
73 | libextractor_test_la_LIBADD = \ | ||
74 | $(LE_LIBINTL) | ||
75 | |||
65 | check_PROGRAMS = \ | 76 | check_PROGRAMS = \ |
66 | test_trivial \ | 77 | test_trivial \ |
67 | test_plugin_loading \ | 78 | test_plugin_loading \ |
diff --git a/src/main/test_extractor.c b/src/main/test_extractor.c new file mode 100644 index 0000000..f1d3b85 --- /dev/null +++ b/src/main/test_extractor.c | |||
@@ -0,0 +1,140 @@ | |||
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_extractor.c | ||
22 | * @brief plugin for testing GNU libextractor | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "extractor.h" | ||
27 | #include <string.h> | ||
28 | #include <stdio.h> | ||
29 | #include <sys/types.h> | ||
30 | #include <sys/stat.h> | ||
31 | #include <unistd.h> | ||
32 | #include <stdlib.h> | ||
33 | |||
34 | |||
35 | |||
36 | /** | ||
37 | * Signature of the extract method that each plugin | ||
38 | * must provide. | ||
39 | * | ||
40 | * @param ec extraction context provided to the plugin | ||
41 | */ | ||
42 | void | ||
43 | EXTRACTOR_test_extract_method (struct EXTRACTOR_ExtractContext *ec) | ||
44 | { | ||
45 | unsigned char *dp; | ||
46 | |||
47 | if ( (NULL == ec->config) || | ||
48 | (0 != strcmp (ec->config, "test")) ) | ||
49 | return; /* only run in test mode */ | ||
50 | if ( (4 != ec->read (ec->cls, | ||
51 | &dp, | ||
52 | 4)) || | ||
53 | (0 != strncmp ("test", | ||
54 | (const char*) dp, | ||
55 | 4) ) ) | ||
56 | { | ||
57 | fprintf (stderr, "Reading at offset 0 failed\n"); | ||
58 | abort (); | ||
59 | } | ||
60 | if (1024 * 150 != | ||
61 | ec->get_size (ec->cls)) | ||
62 | { | ||
63 | fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); | ||
64 | abort (); | ||
65 | } | ||
66 | if (1024 * 100 != | ||
67 | ec->seek (ec->cls, | ||
68 | 1024 * 100 + 4, | ||
69 | SEEK_SET)) | ||
70 | { | ||
71 | fprintf (stderr, "Failure to seek (SEEK_SET)\n"); | ||
72 | abort (); | ||
73 | } | ||
74 | if ( (1 != ec->read (ec->cls, | ||
75 | &dp, | ||
76 | 1)) || | ||
77 | ((1024 * 100 + 4) % 256 != *dp) ) | ||
78 | { | ||
79 | fprintf (stderr, "Failure to read at 100k + 4\n"); | ||
80 | abort (); | ||
81 | } | ||
82 | if (1024 * 50 - 3 != | ||
83 | ec->seek (ec->cls, | ||
84 | - (1024 * 50 + 7), | ||
85 | SEEK_CUR)) | ||
86 | { | ||
87 | fprintf (stderr, "Failure to seek (SEEK_SET)\n"); | ||
88 | abort (); | ||
89 | } | ||
90 | if ( (1 != ec->read (ec->cls, | ||
91 | &dp, | ||
92 | 1)) || | ||
93 | ((1024 * 50 - 3) % 256 != *dp) ) | ||
94 | { | ||
95 | fprintf (stderr, "Failure to read at 50k - 3\n"); | ||
96 | abort (); | ||
97 | } | ||
98 | if (1024 * 150 - 3 != | ||
99 | ec->seek (ec->cls, | ||
100 | - 2, | ||
101 | SEEK_END)) | ||
102 | { | ||
103 | fprintf (stderr, "Failure to seek (SEEK_SET)\n"); | ||
104 | abort (); | ||
105 | } | ||
106 | if ( (1 != ec->read (ec->cls, | ||
107 | &dp, | ||
108 | 1)) || | ||
109 | ((1024 * 150 - 2) % 256 != *dp) ) | ||
110 | { | ||
111 | fprintf (stderr, "Failure to read at 150k - 2\n"); | ||
112 | abort (); | ||
113 | } | ||
114 | if (0 != | ||
115 | ec->proc (ec->cls, | ||
116 | "test", | ||
117 | EXTRACTOR_METATYPE_COMMENT, | ||
118 | EXTRACTOR_METAFORMAT_UTF8, | ||
119 | "<no mime>", | ||
120 | "Hello world!", | ||
121 | strlen ("Hello world!") + 1)) | ||
122 | { | ||
123 | fprintf (stderr, "Unexpected return value from 'proc'\n"); | ||
124 | abort (); | ||
125 | } | ||
126 | if (1 != | ||
127 | ec->proc (ec->cls, | ||
128 | "test", | ||
129 | EXTRACTOR_METATYPE_COMMENT, | ||
130 | EXTRACTOR_METAFORMAT_UTF8, | ||
131 | "<no mime>", | ||
132 | "Goodbye!", | ||
133 | strlen ("Goodbye!") + 1)) | ||
134 | { | ||
135 | fprintf (stderr, "Unexpected return value from 'proc'\n"); | ||
136 | abort (); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | /* end of test_extractor.c */ | ||