test_ebook.c (5374B)
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_ebook.c 22 * @brief testcase for the ebook plugin 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include "test_lib.h" 27 28 29 /** 30 * Shorthand for a UTF-8 text item; @a s is compared as a prefix of what 31 * the plugin produced. 32 */ 33 #define TXT(type, s) { type, EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ 34 s, strlen (s) + 1, 0 } 35 36 37 /** 38 * Main function for the ebook testcase. 39 * 40 * @param argc number of arguments (ignored) 41 * @param argv arguments (ignored) 42 * @return 0 on success 43 */ 44 int 45 main (int argc, char *argv[]) 46 { 47 struct SolutionData epub_sol[] = { 48 TXT (EXTRACTOR_METATYPE_MIMETYPE, "application/epub+zip"), 49 /* <package version="3.0"> */ 50 TXT (EXTRACTOR_METATYPE_FORMAT_VERSION, "3.0"), 51 TXT (EXTRACTOR_METATYPE_TITLE, "The libextractor Test Book"), 52 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "Christian Grothoff"), 53 /* dc:contributor with opf:role="bkp" is the tool, not a person */ 54 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 55 "calibre (7.2.0) [https://calibre-ebook.com]"), 56 TXT (EXTRACTOR_METATYPE_PUBLISHER, "GNU Press"), 57 TXT (EXTRACTOR_METATYPE_LANGUAGE, "en-GB"), 58 TXT (EXTRACTOR_METATYPE_PUBLICATION_DATE, "2026-01-01T00:00:00+00:00"), 59 TXT (EXTRACTOR_METATYPE_KEYWORDS, "digital forensics"), 60 TXT (EXTRACTOR_METATYPE_KEYWORDS, "metadata extraction"), 61 /* the description is indented across three lines in the OPF, so 62 this also proves the white space collapsing */ 63 TXT (EXTRACTOR_METATYPE_DESCRIPTION, 64 "A minimal EPUB built by gen_ebook_testdata.sh, used to check" 65 " that the ebook plugin reads Dublin Core out of the OPF" 66 " package document."), 67 /* "&" has to come back as a bare ampersand */ 68 TXT (EXTRACTOR_METATYPE_RIGHTS, "Public domain (CC0) & nothing else"), 69 /* dc:identifier with opf:scheme="ISBN" */ 70 TXT (EXTRACTOR_METATYPE_ISBN, "978-3-16-148410-0"), 71 /* ... and the one that is not an ISBN */ 72 TXT (EXTRACTOR_METATYPE_URI, 73 "urn:uuid:0f9d5a1e-1719-4c0b-9a3e-000000001719"), 74 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2026-01-01T00:00:00+00:00"), 75 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, "gen_ebook_testdata.sh"), 76 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2026-02-01T00:00:00Z"), 77 /* seven <item> entries in the manifest, and not the three 78 <itemref> entries in the spine */ 79 TXT (EXTRACTOR_METATYPE_ENTRY_COUNT, "7"), 80 TXT (EXTRACTOR_METATYPE_ENCRYPTION, 81 "META-INF/encryption.xml present (DRM or font obfuscation)"), 82 { 0, 0, NULL, NULL, 0, -1 } 83 }; 84 struct SolutionData mobi_sol[] = { 85 TXT (EXTRACTOR_METATYPE_MIMETYPE, "application/x-mobipocket-ebook"), 86 /* PDB header offsets 36/40, seconds since 1904 */ 87 TXT (EXTRACTOR_METATYPE_CREATION_DATE, "2026-01-01T00:00:00Z"), 88 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2026-02-01T00:00:00Z"), 89 /* ... and the same moment again, from EXTH 502 */ 90 TXT (EXTRACTOR_METATYPE_MODIFICATION_DATE, "2026-02-01T00:00:00+00:00"), 91 TXT (EXTRACTOR_METATYPE_ENTRY_COUNT, "3"), 92 /* PalmDOC header offset 12 */ 93 TXT (EXTRACTOR_METATYPE_ENCRYPTION, "old Mobipocket encryption"), 94 /* MOBI header offset 28 */ 95 TXT (EXTRACTOR_METATYPE_CHARACTER_SET, "UTF-8"), 96 TXT (EXTRACTOR_METATYPE_AUTHOR_NAME, "Christian Grothoff"), 97 TXT (EXTRACTOR_METATYPE_PUBLISHER, "GNU Press"), 98 TXT (EXTRACTOR_METATYPE_DESCRIPTION, 99 "A hand-built minimal MOBI file used by the libextractor" 100 " test suite."), 101 TXT (EXTRACTOR_METATYPE_ISBN, "978-3-16-148410-0"), 102 TXT (EXTRACTOR_METATYPE_KEYWORDS, "digital forensics"), 103 TXT (EXTRACTOR_METATYPE_PUBLICATION_DATE, "2026-01-01"), 104 TXT (EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 105 "calibre (7.2.0) [https://calibre-ebook.com]"), 106 TXT (EXTRACTOR_METATYPE_RIGHTS, "Public domain (CC0)"), 107 TXT (EXTRACTOR_METATYPE_SERIAL, "B00LIBEXTR7"), 108 TXT (EXTRACTOR_METATYPE_WATERMARK, "libextractor-test-watermark"), 109 TXT (EXTRACTOR_METATYPE_ATTRIBUTES, "cdetype: EBOK"), 110 /* EXTH 503, which is why the PDB database name 111 "The_libextractor_Test_Book" is not reported as the title */ 112 TXT (EXTRACTOR_METATYPE_TITLE, "The libextractor Test Book"), 113 TXT (EXTRACTOR_METATYPE_LANGUAGE, "en-gb"), 114 { 0, 0, NULL, NULL, 0, -1 } 115 }; 116 struct ProblemSet ps[] = { 117 { "testdata/ebook_test.epub", epub_sol }, 118 { "testdata/ebook_test.mobi", mobi_sol }, 119 { NULL, NULL } 120 }; 121 122 return ET_main ("ebook", ps); 123 } 124 125 126 /* end of test_ebook.c */