aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java
blob: 5028a85e6b488737b9e2338f6d3686df8bafe45d (plain)
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
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

package org.apache.poi.hwpf.usermodel;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.StyleSheet;
import org.junit.jupiter.api.Test;

public final class TestBug49820 {

  @Test
  void test() throws IOException {
    try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49820.doc")) {

      Range documentRange = doc.getRange();
      StyleSheet styleSheet = doc.getStyleSheet();

      // JUnit asserts
      assertLevels(documentRange, styleSheet, 0, 0, 0);
      assertLevels(documentRange, styleSheet, 1, 1, 1);
      assertLevels(documentRange, styleSheet, 2, 2, 2);
      assertLevels(documentRange, styleSheet, 3, 3, 3);
      assertLevels(documentRange, styleSheet, 4, 4, 4);
      assertLevels(documentRange, styleSheet, 5, 5, 5);
      assertLevels(documentRange, styleSheet, 6, 6, 6);
      assertLevels(documentRange, styleSheet, 7, 7, 7);
      assertLevels(documentRange, styleSheet, 8, 8, 8);
      assertLevels(documentRange, styleSheet, 9, 9, 9);
      assertLevels(documentRange, styleSheet, 10, 9, 0);
      assertLevels(documentRange, styleSheet, 11, 9, 4);

      // output to console
    /*for (int i=0; i<documentRange.numParagraphs(); i++) {
      Paragraph par = documentRange.getParagraph(i);
      int styleLvl = styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl();
      int parLvl = par.getLvl();
      System.out.println("Style level: " + styleLvl + ", paragraph level: " + parLvl + ", text: " + par.text());
    }*/
    }
  }

  private void assertLevels(Range documentRange, StyleSheet styleSheet, int parIndex, int expectedStyleLvl, int expectedParLvl) {
    Paragraph par = documentRange.getParagraph(parIndex);
    assertEquals(expectedStyleLvl, styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl());
    assertEquals(expectedParLvl, par.getLvl());
  }
}