Skip to content

Commit 93dc0bb

Browse files
Adds regression test.
Adds a regression for DK-8293776 : Adds CSS 4 and 8 digits hex coded Color #13
1 parent 5b36517 commit 93dc0bb

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
/*
27+
* @test
28+
* @bug 8293776
29+
* @summary Adds CSS 4 and 8 digits hex coded Color
30+
* @run main Hex3468DigitsColor
31+
* @author Guy Abossolo Foh - ScientificWare
32+
*/
33+
34+
import java.awt.Color;
35+
import javax.swing.text.html.StyleSheet;
36+
37+
public class Hex3468DigitsColor {
38+
39+
public static void main(String[] args) {
40+
StringBuilder result = new StringBuilder();
41+
boolean passed = true;
42+
StyleSheet styleSheet = new StyleSheet();
43+
// #rgba Should be interpreted as #rrggbbaa according CSS Color Level 4.
44+
// Then expecting r=255 g=17 b=34 a=170
45+
Color color = styleSheet.stringToColor("#f12a");
46+
int red = color.getRed();
47+
int green = color.getGreen();
48+
int blue = color.getBlue();
49+
int alpha = color.getAlpha();
50+
result.append(" Test for #f00a");
51+
if (red != 255) {
52+
result.append(", expected r=255 but r=%s found".formatted(red));
53+
passed = false;
54+
}
55+
if (green != 17) {
56+
result.append(", expected g=17 but g=%s found".formatted(green));
57+
passed = false;
58+
}
59+
if (blue != 34) {
60+
result.append(", expected b=34 but b=%s found".formatted(blue));
61+
passed = false;
62+
}
63+
if (alpha != 170) {
64+
result.append(", expected a=170 but a=%s found".formatted(alpha));
65+
passed = false;
66+
}
67+
// In #rrggbbaa last two digits should be interpreted as Alpha value according CSS Color Level 4.
68+
// Then expecting r=255 g=17 b=34 a=170
69+
color = styleSheet.stringToColor("#ff1122aa");
70+
alpha = color.getAlpha();
71+
result.append("\n Test for #ff1122aa");
72+
if (red != 255) {
73+
result.append(", expected r=255 but r=%s found".formatted(red));
74+
passed = false;
75+
}
76+
if (green != 17) {
77+
result.append(", expected g=17 but g=%s found".formatted(green));
78+
passed = false;
79+
}
80+
if (blue != 34) {
81+
result.append(", expected b=34 but b=%s found".formatted(blue));
82+
passed = false;
83+
}
84+
if (alpha != 170) {
85+
result.append(", expected a=170 but a=%s found".formatted(alpha));
86+
passed = false;
87+
}
88+
if (!passed) {
89+
result.insert(0, "Failed :");
90+
throw new RuntimeException(result.toString());
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)