1 // Copyright 2015 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "public/fpdf_text.h" 6 #include "testing/embedder_test.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 class CPDFParserEmbeddertest : public EmbedderTest {}; 10 11 TEST_F(CPDFParserEmbeddertest, LoadError_454695) { 12 // Test a dictionary with hex string instead of correct content. 13 // Verify that the defective pdf shouldn't be opened correctly. 14 EXPECT_FALSE(OpenDocument("bug_454695.pdf")); 15 } 16 17 TEST_F(CPDFParserEmbeddertest, Bug_481363) { 18 // Test colorspace object with malformed dictionary. 19 EXPECT_TRUE(OpenDocument("bug_481363.pdf")); 20 FPDF_PAGE page = LoadPage(0); 21 EXPECT_NE(nullptr, page); 22 UnloadPage(page); 23 } 24 25 TEST_F(CPDFParserEmbeddertest, Bug_544880) { 26 // Test self referencing /Pages object. 27 EXPECT_TRUE(OpenDocument("bug_544880.pdf")); 28 // Shouldn't crash. We don't check the return value here because we get the 29 // the count from the "/Count 1" in the testcase (at the time of writing) 30 // rather than the actual count (0). 31 (void)GetPageCount(); 32 } 33 34 TEST_F(CPDFParserEmbeddertest, Bug_325a) { 35 EXPECT_FALSE(OpenDocument("bug_325_a.pdf")); 36 } 37 38 TEST_F(CPDFParserEmbeddertest, Bug_325b) { 39 EXPECT_FALSE(OpenDocument("bug_325_b.pdf")); 40 } 41 42 TEST_F(CPDFParserEmbeddertest, Bug_602650) { 43 // Test the case that cross reference entries, which are well formed, 44 // but do not match with the objects. 45 EXPECT_TRUE(OpenDocument("bug_602650.pdf")); 46 FPDF_PAGE page = LoadPage(0); 47 EXPECT_NE(nullptr, page); 48 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); 49 EXPECT_NE(nullptr, text_page); 50 // The page should not be blank. 51 EXPECT_LT(0, FPDFText_CountChars(text_page)); 52 53 FPDFText_ClosePage(text_page); 54 UnloadPage(page); 55 } 56 57 TEST_F(CPDFParserEmbeddertest, Bug_757705) { 58 EXPECT_TRUE(OpenDocument("bug_757705.pdf")); 59 } 60 61 TEST_F(CPDFParserEmbeddertest, LoadMainCrossRefTable) { 62 EXPECT_TRUE(OpenDocumentLinearized("feature_linearized_loading.pdf")); 63 // To check that main cross ref table is loaded correctly,will be enough to 64 // check that the second page was correctly loaded. Because it is contains 65 // crossrefs for second page. 66 EXPECT_EQ(2, GetPageCount()); 67 FPDF_PAGE page = LoadPage(1); 68 EXPECT_NE(nullptr, page); 69 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); 70 EXPECT_NE(nullptr, text_page); 71 // The page should not be blank. 72 EXPECT_LT(0, FPDFText_CountChars(text_page)); 73 FPDFText_ClosePage(text_page); 74 UnloadPage(page); 75 } 76