test_rtf.c (10217B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 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_rtf.c 22 * @brief testcase for the rtf plugin 23 * @author Christian Grothoff 24 * 25 * See testdata/README for where the sample documents come from and 26 * under what terms they are redistributed here. 27 */ 28 #include "platform.h" 29 #include "test_lib.h" 30 31 32 /** 33 * Shorthand for a UTF-8 text solution entry. 34 * 35 * @param t meta data type to expect 36 * @param s string value to expect 37 */ 38 #define TXT(t, s) { t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, \ 39 strlen (s) + 1, 0 } 40 41 42 /** 43 * Main function for the rtf testcase. 44 * 45 * @param argc number of arguments (ignored) 46 * @param argv arguments (ignored) 47 * @return 0 on success 48 */ 49 int 50 main (int argc, char *argv[]) 51 { 52 /* A memorandum from the National Institute of Neurological Disorders 53 and Stroke. The account that wrote it is a role account rather 54 than a person, but the document still records which one, when it 55 was written, when it was last saved and how long somebody spent 56 editing it. */ 57 struct SolutionData rtf_nih_sol[] = { 58 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 59 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, "Microsoft Word 11.0.6568"), 60 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "NINDS"), 61 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, "NINDS"), 62 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2006-09-29T12:02:00"), 63 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2006-09-29T12:30:00"), 64 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "3"), 65 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "28"), 66 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "1"), 67 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "170"), 68 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "973"), 69 TXT (EXTRACTOR_METATYPE_COMPANY, "NIH"), 70 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "CP1252"), 71 { 0, 0, NULL, NULL, 0, -1 } 72 }; 73 74 /* An FDA advisory committee announcement. Same shape, and the same 75 `CDER USER' role account that the OLE2 PowerPoint sample uses -- 76 see test_ole2.c. */ 77 struct SolutionData rtf_fda_sol[] = { 78 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 79 TXT (EXTRACTOR_METATYPE_TITLE, 80 "MEDICAL IMAGING DRUGS ADVISORY COMMITTEE (MIDAC)"), 81 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "CDER USER"), 82 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, "CDER USER"), 83 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2000-04-21T11:08:00"), 84 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2000-07-06T12:40:00"), 85 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "5"), 86 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "14"), 87 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "2"), 88 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "320"), 89 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "1829"), 90 TXT (EXTRACTOR_METATYPE_COMPANY, "FDA.CDER"), 91 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "CP1252"), 92 { 0, 0, NULL, NULL, 0, -1 } 93 }; 94 95 /* A NASA Goddard document. This one shows why `\author' and 96 `\operator' are worth reporting separately: the file was created 97 under a civil servant's login and last saved by the contractor 98 that ran the office. */ 99 struct SolutionData rtf_nasa_sol[] = { 100 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 101 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "WLBEHNKE"), 102 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, "INTELLISOURCE"), 103 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2000-02-11T07:11:00"), 104 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2001-05-30T07:26:00"), 105 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "6"), 106 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "12"), 107 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "1"), 108 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "158"), 109 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "905"), 110 TXT (EXTRACTOR_METATYPE_COMPANY, "GSFC/NASA"), 111 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "CP1252"), 112 { 0, 0, NULL, NULL, 0, -1 } 113 }; 114 115 /* A Federal Transit Administration document produced by scanning 116 software, which left both its own name and a custom document 117 property behind. */ 118 struct SolutionData rtf_fta_sol[] = { 119 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 120 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, "Microsoft Word 10.0.6764"), 121 TXT (EXTRACTOR_METATYPE_TITLE, "OCR Document"), 122 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "Readiris"), 123 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, "FTA"), 124 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2005-09-30T12:48:00"), 125 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2005-09-30T13:18:00"), 126 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "3"), 127 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "3"), 128 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "1"), 129 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "285"), 130 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "1625"), 131 TXT (EXTRACTOR_METATYPE_COMPANY, "I.R.I.S."), 132 TXT (EXTRACTOR_METATYPE_UNKNOWN, "Editor: Readiris"), 133 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "CP1252"), 134 { 0, 0, NULL, NULL, 0, -1 } 135 }; 136 137 /* Written with Word for the Macintosh, which says so by declaring 138 the Mac OS Roman character set. The apostrophe in the title is 139 `\'d5', which is U+2019 in that character set but would be a 140 capital O with tilde if we assumed the Windows default. */ 141 struct SolutionData rtf_doe_mac_sol[] = { 142 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 143 TXT (EXTRACTOR_METATYPE_TITLE, 144 "Review of the Yucca Mountain Igneous Consequences Peer Review" 145 " Panel\u2019s Interim Report presented August 23, 2002"), 146 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "berts"), 147 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, "berts"), 148 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2002-09-19T11:39:00"), 149 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2002-09-21T16:31:00"), 150 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "8"), 151 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "94"), 152 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "2"), 153 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "1070"), 154 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "6100"), 155 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "MACINTOSH"), 156 TXT (EXTRACTOR_METATYPE_AUTHORING_OS, "Macintosh"), 157 { 0, 0, NULL, NULL, 0, -1 } 158 }; 159 160 /* Synthetic, so that the paths that carry personal data can be 161 tested without republishing anybody's. Covers the revision table, 162 the three flavours of revision mark, comment authors and dates, 163 the Outlook review properties, a template path, `\uN' and `\'hh' 164 escapes. */ 165 struct SolutionData rtf_review_sol[] = { 166 TXT (EXTRACTOR_METATYPE_MIMETYPE, "text/rtf"), 167 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 168 "libextractor test fixture 1.0"), 169 TXT (EXTRACTOR_METATYPE_CONTRIBUTOR_NAME, "Records Management Office"), 170 TXT (EXTRACTOR_METATYPE_CONTRIBUTOR_NAME, 171 "Office of the Inspector General"), 172 TXT (EXTRACTOR_METATYPE_CONTRIBUTOR_NAME, "RMO"), 173 TXT (EXTRACTOR_METATYPE_TITLE, "Quarterly Compliance Review \u2014 2019"), 174 TXT (EXTRACTOR_METATYPE_SUBJECT, "Records management"), 175 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "Records Management Office"), 176 TXT (EXTRACTOR_METATYPE_LAST_SAVED_BY, 177 "Office of the Inspector General"), 178 TXT (EXTRACTOR_METATYPE_COMPANY, "Example Agency \u2013 Region 5"), 179 TXT (EXTRACTOR_METATYPE_MANAGER, "Division Chief"), 180 TXT (EXTRACTOR_METATYPE_SECTION, "Internal"), 181 TXT (EXTRACTOR_METATYPE_KEYWORDS, "compliance, records, retention"), 182 TXT (EXTRACTOR_METATYPE_COMMENT, "Draft circulated for comment"), 183 TXT (EXTRACTOR_METATYPE_URL, "http://www.example.org/records/"), 184 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2019-03-04T09:15:00"), 185 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2019-03-11T16:48:00"), 186 TXT (EXTRACTOR_METATYPE_LAST_PRINTED, "2019-03-12T08:05:00"), 187 TXT (EXTRACTOR_METATYPE_REVISION_NUMBER, "4"), 188 TXT (EXTRACTOR_METATYPE_TOTAL_EDITING_TIME, "37"), 189 TXT (EXTRACTOR_METATYPE_PAGE_COUNT, "2"), 190 TXT (EXTRACTOR_METATYPE_WORD_COUNT, "480"), 191 TXT (EXTRACTOR_METATYPE_CHARACTER_COUNT, "2650"), 192 TXT (EXTRACTOR_METATYPE_AUTHOR_EMAIL, "records@example.org"), 193 TXT (EXTRACTOR_METATYPE_SUBJECT, "Please review by Friday"), 194 TXT (EXTRACTOR_METATYPE_UNKNOWN, "Retention Schedule: GRS 4.1"), 195 TXT (EXTRACTOR_METATYPE_TEMPLATE, 196 "C:\\Program Files\\Example Agency\\Templates\\Memorandum.dot"), 197 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "CP1252"), 198 TXT (EXTRACTOR_METATYPE_REVISION_HISTORY, 199 "Author `Records Management Office' commented on the document on" 200 " `2019-03-11T16:48:00'"), 201 TXT (EXTRACTOR_METATYPE_REVISION_HISTORY, 202 "Author `Records Management Office' edited the document on" 203 " `2019-03-05T14:32:00'"), 204 TXT (EXTRACTOR_METATYPE_REVISION_HISTORY, 205 "Author `Office of the Inspector General' edited the document on" 206 " `2019-03-08T09:07:00'"), 207 TXT (EXTRACTOR_METATYPE_REVISION_HISTORY, 208 "Author `Records Management Office' edited the document on" 209 " `2019-03-11T16:48:00'"), 210 { 0, 0, NULL, NULL, 0, -1 } 211 }; 212 213 struct ProblemSet ps[] = { 214 { "testdata/rtf_nih.rtf", 215 rtf_nih_sol }, 216 { "testdata/rtf_fda.rtf", 217 rtf_fda_sol }, 218 { "testdata/rtf_nasa.rtf", 219 rtf_nasa_sol }, 220 { "testdata/rtf_fta.rtf", 221 rtf_fta_sol }, 222 #if HAVE_ICONV 223 { "testdata/rtf_doe_mac.rtf", 224 rtf_doe_mac_sol }, 225 #endif 226 { "testdata/rtf_review.rtf", 227 rtf_review_sol }, 228 { NULL, NULL } 229 }; 230 return ET_main ("rtf", ps); 231 } 232 233 234 /* end of test_rtf.c */