bug7172833.java revision 14851:980da45565c8
1/*
2 * Copyright (c) 2013, 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
25import java.awt.*;
26import java.awt.Frame;
27import java.awt.datatransfer.Clipboard;
28import java.awt.font.TextAttribute;
29import java.awt.im.InputMethodHighlight;
30import java.awt.image.ColorModel;
31import java.awt.image.ImageObserver;
32import java.awt.image.ImageProducer;
33import java.net.URL;
34import java.util.Map;
35import java.util.Properties;
36
37
38/**
39 * @test
40 * @key headful
41 * @bug 7172833
42 * @summary java.awt.Toolkit methods is/setDynamicLayout() should be consistent.
43 * @author Sergey Bylokhov
44 */
45public final class bug7172833 {
46
47    public static void main(final String[] args) throws Exception {
48        final StubbedToolkit t = new StubbedToolkit();
49        final Boolean dynamicLayoutSupported
50                = (Boolean) t.getDesktopProperty("awt.dynamicLayoutSupported");
51        t.setDynamicLayout(true);
52        if(!t.isDynamicLayoutSet()){
53            throw new RuntimeException("'true' expected but 'false' returned");
54        }
55        if (dynamicLayoutSupported) {
56            if (!t.isDynamicLayoutActive()) {
57                throw new RuntimeException("is inactive but set+supported");
58            }
59        } else {
60            if (t.isDynamicLayoutActive()) {
61                throw new RuntimeException("is active but unsupported");
62            }
63        }
64
65        t.setDynamicLayout(false);
66        if(t.isDynamicLayoutSet()){
67            throw new RuntimeException("'false' expected but 'true' returned");
68        }
69        if (dynamicLayoutSupported) {
70            // Layout is supported and was set to false, cannot verifym because
71            // the native system is free to ignore our request.
72        } else {
73            if (t.isDynamicLayoutActive()) {
74                throw new RuntimeException("is active but unset+unsupported");
75            }
76        }
77    }
78
79    static final class StubbedToolkit extends Toolkit {
80
81        @Override
82        protected boolean isDynamicLayoutSet() throws HeadlessException {
83            return super.isDynamicLayoutSet();
84        }
85
86
87        @Override
88        public Dimension getScreenSize() throws HeadlessException {
89            return null;
90        }
91
92        @Override
93        public int getScreenResolution() throws HeadlessException {
94            return 0;
95        }
96
97        @Override
98        public ColorModel getColorModel() throws HeadlessException {
99            return null;
100        }
101
102        @Override
103        public String[] getFontList() {
104            return new String[0];
105        }
106
107        @Override
108        public FontMetrics getFontMetrics(final Font font) {
109            return null;
110        }
111
112        @Override
113        public void sync() {
114
115        }
116
117        @Override
118        public Image getImage(final String filename) {
119            return null;
120        }
121
122        @Override
123        public Image getImage(final URL url) {
124            return null;
125        }
126
127        @Override
128        public Image createImage(final String filename) {
129            return null;
130        }
131
132        @Override
133        public Image createImage(final URL url) {
134            return null;
135        }
136
137        @Override
138        public boolean prepareImage(
139                final Image image, final int width, final int height,
140                                    final ImageObserver observer) {
141            return false;
142        }
143
144        @Override
145        public int checkImage(final Image image, final int width, final int height,
146                              final ImageObserver observer) {
147            return 0;
148        }
149
150        @Override
151        public Image createImage(final ImageProducer producer) {
152            return null;
153        }
154
155        @Override
156        public Image createImage(final byte[] imagedata, final int imageoffset,
157                                 final int imagelength) {
158            return null;
159        }
160
161        @Override
162        public PrintJob getPrintJob(final Frame frame, final String jobtitle,
163                                    final Properties props) {
164            return null;
165        }
166
167        @Override
168        public void beep() {
169
170        }
171
172        @Override
173        public Clipboard getSystemClipboard() throws HeadlessException {
174            return null;
175        }
176
177        @Override
178        protected EventQueue getSystemEventQueueImpl() {
179            return null;
180        }
181
182        @Override
183        public boolean isModalityTypeSupported(
184                final Dialog.ModalityType modalityType) {
185            return false;
186        }
187
188        @Override
189        public boolean isModalExclusionTypeSupported(
190                final Dialog.ModalExclusionType modalExclusionType) {
191            return false;
192        }
193
194        @Override
195        public Map<TextAttribute, ?> mapInputMethodHighlight(
196                final InputMethodHighlight highlight) throws HeadlessException {
197            return null;
198        }
199    }
200}
201