author | rupashka |
Sat, 13 Nov 2010 19:31:00 +0300 | |
changeset 7161 | 75ca9d01ff2b |
permissions | -rw-r--r-- |
7161
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
1 |
/* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
4 |
* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
8 |
* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
13 |
* accompanied this code). |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
14 |
* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
18 |
* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
21 |
* questions. |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
22 |
*/ |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
23 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
24 |
/* |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
25 |
* @test |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
26 |
* @bug 6771184 |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
27 |
* @summary Some methods in text package don't throw BadLocationException when expected |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
28 |
* @author Pavel Porvatov |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
29 |
*/ |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
30 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
31 |
import javax.swing.*; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
32 |
import javax.swing.text.BadLocationException; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
33 |
import javax.swing.text.Highlighter; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
34 |
import javax.swing.text.JTextComponent; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
35 |
import java.awt.*; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
36 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
37 |
public class bug6771184 { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
38 |
public static void main(String[] args) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
39 |
SwingUtilities.invokeLater(new Runnable() { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
40 |
public void run() { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
41 |
JTextArea textArea = new JTextArea("Tested string"); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
42 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
43 |
Highlighter highlighter = textArea.getHighlighter(); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
44 |
Highlighter.HighlightPainter myPainter = new Highlighter.HighlightPainter() { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
45 |
public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
46 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
47 |
}; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
48 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
49 |
int negativeTestedData[][] = {{50, 0}, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
50 |
{-1, 1}, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
51 |
{-5, -4}, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
52 |
{Integer.MAX_VALUE, Integer.MIN_VALUE}, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
53 |
{Integer.MIN_VALUE, Integer.MAX_VALUE}, |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
54 |
{Integer.MIN_VALUE, Integer.MIN_VALUE}}; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
55 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
56 |
for (int[] data : negativeTestedData) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
57 |
try { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
58 |
highlighter.addHighlight(data[0], data[1], myPainter); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
59 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
60 |
throw new RuntimeException("Method addHighlight() does not throw BadLocationException for (" + |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
61 |
data[0] + ", " + data[1] + ") "); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
62 |
} catch (BadLocationException e) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
63 |
// Ok |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
64 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
65 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
66 |
Object objRef; |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
67 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
68 |
try { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
69 |
objRef = highlighter.addHighlight(0, 1, myPainter); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
70 |
} catch (BadLocationException e) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
71 |
throw new RuntimeException("highlighter.addHighlight(0, 1, myPainter) throws exception", e); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
72 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
73 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
74 |
try { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
75 |
highlighter.changeHighlight(objRef, data[0], data[1]); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
76 |
|
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
77 |
throw new RuntimeException("Method changeHighlight() does not throw BadLocationException for (" + |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
78 |
data[0] + ", " + data[1] + ") "); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
79 |
} catch (BadLocationException e) { |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
80 |
// Ok |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
81 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
82 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
83 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
84 |
}); |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
85 |
} |
75ca9d01ff2b
6771184: Some methods in text package don't throw BadLocationException when expected
rupashka
parents:
diff
changeset
|
86 |
} |