Debian Codegraph @

sejda-sambox/src/test/java/org/sejda/impl/sambox/component/optimization/OptimizationRulerTest.java

raw
1 /*
2 * Created on 04 feb 2016
3 * Copyright 2015 by Andrea Vacondio ([email protected]).
4 * This file is part of Sejda.
5 *
6 * Sejda is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Sejda is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Sejda. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package org.sejda.impl.sambox.component.optimization;
20
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 import static org.mockito.Mockito.mock;
24
25 import java.io.IOException;
26
27 import org.junit.Test;
28 import org.sejda.io.SeekableSources;
29 import org.sejda.model.optimization.OptimizationPolicy;
30 import org.sejda.sambox.input.PDFParser;
31 import org.sejda.sambox.pdmodel.PDDocument;
32
33 /**
34 * @author Andrea Vacondio
35 *
36 */
37 public class OptimizationRulerTest {
38
39 @Test
40 public void noPolicy() {
41 assertFalse(new OptimizationRuler(OptimizationPolicy.NO).apply(mock(PDDocument.class)));
42 }
43
44 @Test
45 public void yesPolicy() {
46 assertTrue(new OptimizationRuler(OptimizationPolicy.YES).apply(mock(PDDocument.class)));
47 }
48
49 @Test
50 public void sharedResourceWithImagesDictionary() throws IOException {
51 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
52 getClass().getClassLoader().getResourceAsStream("pdf/shared_resource_dic_w_images.pdf")))) {
53 assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
54 }
55 }
56
57 @Test
58 public void sharedResourceWithFontsDictionary() throws IOException {
59 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
60 getClass().getClassLoader().getResourceAsStream("pdf/shared_resource_dic_w_fonts.pdf")))) {
61 assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
62 }
63 }
64
65 @Test
66 public void sharedResourceWithExtGStateDictionary() throws IOException {
67 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(getClass()
68 .getClassLoader().getResourceAsStream("pdf/shared_pages_res_extgstate_smasks_own_res.pdf")))) {
69 assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
70 }
71 }
72
73 @Test
74 public void sharedXobjectsDictionary() throws IOException {
75 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
76 getClass().getClassLoader().getResourceAsStream("pdf/shared_xobjects_dics.pdf")))) {
77 assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
78 }
79 }
80
81 @Test
82 public void sharedFontsDictionary() throws IOException {
83 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
84 getClass().getClassLoader().getResourceAsStream("pdf/shared_fonts_dics.pdf")))) {
85 assertTrue(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
86 }
87 }
88
89 @Test
90 public void notSharedResources() throws IOException {
91 try (PDDocument document = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
92 getClass().getClassLoader().getResourceAsStream("pdf/resources_not_shared.pdf")))) {
93 assertFalse(new OptimizationRuler(OptimizationPolicy.AUTO).apply(document));
94 }
95 }
96 }