1/*
2 * Copyright (c) 2016, 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.
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/* @test
25 * @bug 8139192
26 * @summary Test to check OffScreenImageSource handles
27 *          ImageFilter.imageComplete() behaviors
28 * @run main ImageFilterTest
29 */
30
31import java.awt.Image;
32import java.awt.Toolkit;
33import java.awt.image.BufferedImage;
34import java.awt.image.FilteredImageSource;
35import java.awt.image.ImageFilter;
36
37
38public class ImageFilterTest {
39
40    public static void main(String[] args) {
41        String[] scenarios = {
42            "SUCCESS",
43            "SINGLEFRAMEDONE exception",
44            "STATICIMAGEDONE exception"
45        };
46
47        for (String str : scenarios) {
48            MyImageFilter testFilter = new MyImageFilter(str);
49            test(testFilter);
50        }
51    }
52
53    public static void test(MyImageFilter testFilter) {
54        Image image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
55        FilteredImageSource filtered =
56                new FilteredImageSource(image.getSource(), testFilter);
57
58        Image img = Toolkit.getDefaultToolkit().createImage(filtered);
59
60        BufferedImage buffImage = new BufferedImage(img.getWidth(null),
61                img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
62    }
63}
64
65class MyImageFilter extends ImageFilter {
66
67    private String testScenario;
68    private boolean intermediateStatus;
69
70    public MyImageFilter(String scenario) {
71        super();
72
73        testScenario = scenario;
74        intermediateStatus = false;
75    }
76
77    @Override
78    public void imageComplete(int status) {
79        switch (testScenario) {
80            case "SUCCESS":
81                if (status == SINGLEFRAMEDONE) {
82                    intermediateStatus = true;
83                }
84
85                if (status == STATICIMAGEDONE) {
86                    if (!intermediateStatus) {
87                        throw new RuntimeException("STATICIMAGEDONE is not expected");
88                    }
89                }
90
91                if (status == IMAGEERROR) {
92                    throw new RuntimeException("IMAGEERROR is not expected");
93                }
94                break;
95
96            case "SINGLEFRAMEDONE exception":
97                if (status == SINGLEFRAMEDONE) {
98                    intermediateStatus = true;
99
100                    throw new NullPointerException("NullPointerException for testing purpose");
101                }
102
103                if (status == IMAGEERROR) {
104                    if (!intermediateStatus) {
105                        throw new RuntimeException("IMAGEERROR is not expected");
106                    }
107                }
108
109                if (status == STATICIMAGEDONE) {
110                    throw new RuntimeException("STATICIMAGEDONE is not expected");
111                }
112                break;
113
114            case "STATICIMAGEDONE exception":
115                if (status == SINGLEFRAMEDONE) {
116                    intermediateStatus = true;
117                }
118
119                if (status == STATICIMAGEDONE) {
120                    if (intermediateStatus) {
121                        throw new RuntimeException("RuntimeException for testing purpose");
122                    }
123                }
124
125                if (status == IMAGEERROR) {
126                    throw new RuntimeException("IMAGEERROR is not expected");
127                }
128                break;
129
130            default:
131                throw new RuntimeException("Invalid Test Scenario");
132        }
133    }
134}
135
136
137