KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > TestHSSFRichTextString


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.usermodel;
18
19 import junit.framework.TestCase;
20
21 public class TestHSSFRichTextString extends TestCase
22 {
23     public void testApplyFont() throws Exception JavaDoc
24     {
25
26         HSSFRichTextString r = new HSSFRichTextString("testing");
27         assertEquals(1,r.numFormattingRuns());
28         r.applyFont(2,4, new HSSFFont((short)1, null));
29         assertEquals(3,r.numFormattingRuns());
30         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
31         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
32         assertEquals(1, r.getFontAtIndex(2));
33         assertEquals(1, r.getFontAtIndex(3));
34         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
35         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
36         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(6));
37
38         r.applyFont(6,7, new HSSFFont((short)2, null));
39         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
40         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
41         assertEquals(1, r.getFontAtIndex(2));
42         assertEquals(1, r.getFontAtIndex(3));
43         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
44         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
45         assertEquals(2, r.getFontAtIndex(6));
46
47         r.applyFont(HSSFRichTextString.NO_FONT);
48         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
49         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
50         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(2));
51         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(3));
52         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
53         assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
54
55         r.applyFont(new HSSFFont((short)1, null));
56         assertEquals(1, r.getFontAtIndex(0));
57         assertEquals(1, r.getFontAtIndex(1));
58         assertEquals(1, r.getFontAtIndex(2));
59         assertEquals(1, r.getFontAtIndex(3));
60         assertEquals(1, r.getFontAtIndex(4));
61         assertEquals(1, r.getFontAtIndex(5));
62         assertEquals(1, r.getFontAtIndex(6));
63
64     }
65
66 }
67
Popular Tags