test_dvi.c (7312B)
1 /* 2 This file is part of libextractor. 3 Copyright (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., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_dvi.c 22 * @brief testcase for dvi plugin 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include "test_lib.h" 27 #include "test_paged_fulltext.h" 28 29 30 /** 31 * Check the full text of testdata/dvi_fulltext.dvi. 32 * 33 * @param data the full text 34 * @param data_len number of bytes in @a data 35 * @return 1 if acceptable 36 */ 37 static int 38 validate_dvi_fulltext (const void *data, 39 size_t data_len) 40 { 41 static const char *const pars[] = { 42 "Introduction", 43 "Paged documents scatter their words", 44 "The second paragraph is indented", 45 "Short paragraph number three.", 46 "The fourth paragraph", 47 "The fifth paragraph runs across the page break", 48 "The sixth paragraph", 49 "The seventh paragraph is set in the T1 encoding", 50 NULL 51 }; 52 static const char *const needles[] = { 53 /* OT1 accents: \'e and \"\i */ 54 "The caf\xc3\xa9 serves na\xc3\xafve guests.", 55 /* T1 glyphs */ 56 "The seventh paragraph is set in the T1 encoding: Stra\xc3\x9f" "e, " 57 "\xc3\x9c" "berma\xc3\x9f, \xc3\xa9tude and \xc3\xa7" "a va.", 58 NULL 59 }; 60 static const char *const absent[] = { 61 NULL 62 }; 63 const char *s = data; 64 65 if (0 == check_form (s, data_len)) 66 { 67 fprintf (stderr, "Malformed full text\n"); 68 return 0; 69 } 70 return check_paragraphs (s, pars) && 71 check_contains (s, common_needles, common_absent) && 72 check_contains (s, needles, absent) && 73 check_no_numbers (s); 74 } 75 76 77 /** 78 * Check the full text of testdata/dvi_ora.dvi. 79 * 80 * @param data the full text 81 * @param data_len number of bytes in @a data 82 * @return 1 if acceptable 83 */ 84 static int 85 validate_ora_fulltext (const void *data, 86 size_t data_len) 87 { 88 static const char *const needles[] = { 89 "Optimal Bitwise Register Allocation using Integer Linear Programming" 90 "\n\n", 91 "\n\nAbstract\n\nThis paper addresses the problem of optimal global " 92 "register allocation.", 93 "\n\nThe traditional approach towards optimal register allocation is " 94 "to color the interference graph [7].", 95 NULL 96 }; 97 static const char *const absent[] = { 98 NULL 99 }; 100 const char *s = data; 101 102 if (0 == check_form (s, data_len)) 103 { 104 fprintf (stderr, "Malformed full text\n"); 105 return 0; 106 } 107 return check_contains (s, needles, absent); 108 } 109 110 111 /** 112 * Main function for the DVI testcase. 113 * 114 * @param argc number of arguments (ignored) 115 * @param argv arguments (ignored) 116 * @return 0 on success 117 */ 118 int 119 main (int argc, char *argv[]) 120 { 121 struct SolutionData dvi_ora_sol[] = { 122 { 123 EXTRACTOR_METATYPE_MIMETYPE, 124 EXTRACTOR_METAFORMAT_UTF8, 125 "text/plain", 126 "application/x-dvi", 127 strlen ("application/x-dvi") + 1, 128 0 129 }, 130 { 131 EXTRACTOR_METATYPE_PAGE_COUNT, 132 EXTRACTOR_METAFORMAT_UTF8, 133 "text/plain", 134 "10", 135 strlen ("10") + 1, 136 0 137 }, 138 { 139 EXTRACTOR_METATYPE_TITLE, 140 EXTRACTOR_METAFORMAT_C_STRING, 141 "text/plain", 142 "Optimal Bitwise Register Allocation using Integer Linear Programming", 143 strlen ( 144 "Optimal Bitwise Register Allocation using Integer Linear Programming") 145 + 1, 146 0 147 }, 148 { 149 EXTRACTOR_METATYPE_SUBJECT, 150 EXTRACTOR_METAFORMAT_C_STRING, 151 "text/plain", 152 "Register Allocation", 153 strlen ("Register Allocation") + 1, 154 0 155 }, 156 { 157 EXTRACTOR_METATYPE_COMMENT, 158 EXTRACTOR_METAFORMAT_C_STRING, 159 "text/plain", 160 " TeX output 2005.02.06:0725", 161 strlen (" TeX output 2005.02.06:0725") + 1, 162 0 163 }, 164 { 165 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 166 EXTRACTOR_METAFORMAT_C_STRING, 167 "text/plain", 168 "LaTeX with hyperref package", 169 strlen ("LaTeX with hyperref package") + 1, 170 0 171 }, 172 { 173 EXTRACTOR_METATYPE_AUTHOR_NAME, 174 EXTRACTOR_METAFORMAT_C_STRING, 175 "text/plain", 176 "Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa", 177 strlen ( 178 "Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa") 179 + 1, 180 0 181 }, 182 { 183 EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE, 184 EXTRACTOR_METAFORMAT_C_STRING, 185 "text/plain", 186 "dvips + Distiller", 187 strlen ("dvips + Distiller") + 1, 188 0 189 }, 190 { 191 EXTRACTOR_METATYPE_KEYWORDS, 192 EXTRACTOR_METAFORMAT_C_STRING, 193 "text/plain", 194 "register allocation integer linear programming bit-wise spilling coalesing rematerialization", 195 strlen ( 196 "register allocation integer linear programming bit-wise spilling coalesing rematerialization") 197 + 1, 198 0 199 }, 200 { 0, 0, NULL, NULL, 0, -1 } 201 }; 202 struct SolutionData dvi_fulltext_sol[] = { 203 { 204 EXTRACTOR_METATYPE_MIMETYPE, 205 EXTRACTOR_METAFORMAT_UTF8, 206 "text/plain", 207 "application/x-dvi", 208 strlen ("application/x-dvi") + 1, 209 0 210 }, 211 { 212 EXTRACTOR_METATYPE_PAGE_COUNT, 213 EXTRACTOR_METAFORMAT_UTF8, 214 "text/plain", 215 "3", 216 strlen ("3") + 1, 217 0 218 }, 219 { 220 EXTRACTOR_METATYPE_FULL_TEXT, 221 EXTRACTOR_METAFORMAT_UTF8, 222 "text/plain", 223 "^Introduction\n\nPaged documents scatter", 224 0, 225 0, 226 1, 227 &validate_dvi_fulltext 228 }, 229 { 0, 0, NULL, NULL, 0, -1 } 230 }; 231 struct SolutionData dvi_ora_ft_sol[] = { 232 { 233 EXTRACTOR_METATYPE_FULL_TEXT, 234 EXTRACTOR_METAFORMAT_UTF8, 235 "text/plain", 236 "^Optimal Bitwise Register Allocation", 237 0, 238 0, 239 1, 240 &validate_ora_fulltext 241 }, 242 { 0, 0, NULL, NULL, 0, -1 } 243 }; 244 struct ProblemSet ps[] = { 245 { "testdata/dvi_ora.dvi", 246 dvi_ora_sol }, 247 { NULL, NULL } 248 }; 249 struct ProblemSet ps_ft[] = { 250 { "testdata/dvi_fulltext.dvi", 251 dvi_fulltext_sol }, 252 { "testdata/dvi_ora.dvi", 253 dvi_ora_ft_sol }, 254 { NULL, NULL } 255 }; 256 int ret = 0; 257 258 ret |= ET_main ("dvi", ps); 259 /* without the option, there must be no full text */ 260 ret |= check_fulltext_count ("dvi", 261 "testdata/dvi_fulltext.dvi", 262 0); 263 ret |= check_fulltext_count ("dvi", 264 "testdata/dvi_ora.dvi", 265 0); 266 ret |= ET_main ("dvi(fulltext)", ps_ft); 267 ret |= check_fulltext_count ("dvi(fulltext)", 268 "testdata/dvi_fulltext.dvi", 269 1); 270 return ret; 271 } 272 273 274 /* end of test_dvi.c */