forked from sumatrapdfreader/sumatrapdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegress00.cpp
69 lines (62 loc) · 2.25 KB
/
Regress00.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright 2021 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD (see COPYING.BSD) */
// must be #included from Regress.cpp
// test that a given epub file loads correctly. crash otherwise
static void RegressTestEpubLoading(const WCHAR *fileName)
{
WCHAR *filePath = path::Join(TestFilesDir(), fileName);
VerifyFileExists(filePath);
Kind kind = GuessFileType(filePath, true);
CrashAlwaysIf(!EpubDoc::IsSupportedFileType(kind));
EpubDoc *doc = EpubDoc::CreateFromFile(filePath);
CrashAlwaysIf(!doc);
delete doc;
}
// http://code.google.com/p/sumatrapdf/issues/detail?id=2102
static void Regress02()
{
RegressTestEpubLoading(L"epub\\sumatra-crash-nov-23-2012.epub");
}
// http://code.google.com/p/sumatrapdf/issues/detail?id=2091
static void Regress01()
{
RegressTestEpubLoading(L"epub\\sumatra-crash-nov-12-2012.epub");
}
// http://code.google.com/p/sumatrapdf/issues/detail?id=1926
static void Regress00()
{
WCHAR *filePath = path::Join(TestFilesDir(), L"epub\\widget-figure-gallery-20120405.epub");
VerifyFileExists(filePath);
Kind kind = GuessFileType(filePath, true);
CrashAlwaysIf(!EpubDoc::IsSupportedFileType(kind));
EpubDoc *doc = EpubDoc::CreateFromFile(filePath);
CrashAlwaysIf(!doc);
PoolAllocator textAllocator;
HtmlFormatterArgs *args = CreateFormatterDefaultArgs(820, 920, &textAllocator);
if (!args) {
return;
}
args->htmlStr = doc->GetHtmlData();
HtmlPage *pages[3];
HtmlFormatter *formatter = new EpubFormatter(args, doc);
int page = 0;
for (HtmlPage *pd = formatter->Next(); pd; pd = formatter->Next()) {
pages[page++] = pd;
if (page == dimof(pages))
break;
}
delete formatter;
delete args;
CrashAlwaysIf(page != 3);
args = CreateFormatterDefaultArgs(820, 920, &textAllocator);
args->htmlStr = doc->GetHtmlData();
args->reparseIdx = pages[2]->reparseIdx;
formatter = new EpubFormatter(args, doc);
// if bug is present, this will crash in formatter->Next()
for (HtmlPage *pd = formatter->Next(); pd; pd = formatter->Next()) {
delete pd;
}
delete formatter;
delete args;
delete doc;
}