Skip to content

Commit b974bf0

Browse files
author
duke
committed
Backport ed153ee2c4614c814da92c23c4741eed68ce1a0c
1 parent 5228b25 commit b974bf0

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright Amazon.com Inc. 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.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.color.ColorSpace;
25+
import java.awt.color.ICC_Profile;
26+
import java.io.ByteArrayOutputStream;
27+
import java.io.ObjectOutputStream;
28+
29+
/**
30+
* @test
31+
* @bug 8369032
32+
* @summary Checks the size of the serialized ICC_Profile for standard and
33+
* non-standard profiles.
34+
*/
35+
public final class SerializedFormSize {
36+
37+
private static final ICC_Profile[] PROFILES = {
38+
ICC_Profile.getInstance(ColorSpace.CS_sRGB),
39+
ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB),
40+
ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ),
41+
ICC_Profile.getInstance(ColorSpace.CS_PYCC),
42+
ICC_Profile.getInstance(ColorSpace.CS_GRAY)
43+
};
44+
45+
public static void main(String[] args) throws Exception {
46+
for (ICC_Profile profile : PROFILES) {
47+
byte[] data = profile.getData();
48+
int dataSize = data.length;
49+
int min = 3; // At least version, name and data fields
50+
int max = 200; // Small enough to confirm no data saved
51+
52+
// Standard profile: should serialize to a small size, no data
53+
test(profile, min, max);
54+
// Non-standard profile: includes full data, but only once
55+
test(ICC_Profile.getInstance(data), dataSize, dataSize + max);
56+
}
57+
}
58+
59+
private static void test(ICC_Profile p, int min, int max) throws Exception {
60+
try (var bos = new ByteArrayOutputStream();
61+
var oos = new ObjectOutputStream(bos))
62+
{
63+
oos.writeObject(p);
64+
int size = bos.size();
65+
if (size < min || size > max) {
66+
System.err.println("Expected: >= " + min + " and <= " + max);
67+
System.err.println("Actual: " + size);
68+
throw new RuntimeException("Wrong size");
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)