Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Desktop/OpenByUNCPathNameTest/OpenByUNCPathNameTest.java
41153 views
1
/*
2
* Copyright (c) 2013, 2020, 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 6550588
26
@key headful
27
@requires (os.family == "windows")
28
@summary java.awt.Desktop cannot open file with Windows UNC filename
29
@author Anton Litvinov
30
@run main/manual OpenByUNCPathNameTest
31
*/
32
33
import javax.swing.JButton;
34
import javax.swing.JFrame;
35
import javax.swing.JPanel;
36
import javax.swing.JTextArea;
37
import javax.swing.SwingUtilities;
38
import javax.swing.WindowConstants;
39
import java.awt.BorderLayout;
40
import java.awt.Desktop;
41
import java.awt.FlowLayout;
42
import java.io.IOException;
43
import java.io.File;
44
import java.util.concurrent.CountDownLatch;
45
import java.util.concurrent.TimeUnit;
46
47
public class OpenByUNCPathNameTest {
48
private static volatile CountDownLatch countDownLatch;
49
private static JFrame instructionFrame;
50
private static JFrame testFrame;
51
private static volatile boolean testPassed = false;
52
private static File file;
53
54
private static boolean validatePlatform() {
55
String osName = System.getProperty("os.name");
56
if (osName == null) {
57
throw new RuntimeException("Name of the current OS could not be" +
58
" retrieved.");
59
}
60
return osName.startsWith("Windows");
61
}
62
63
private static void createInstructionUI() {
64
SwingUtilities.invokeLater(() -> {
65
String instructions =
66
"1. Make sure that disk C is shared \n"
67
+ "2. Click on openFileByLocalPath Button to test Test"
68
+ " opening of the file with Windows local file path\n"
69
+ "3. Check that the file is opened successfully\n"
70
+ "4. Close the file\n"
71
+ "5. Click on openFileByUNCPath Button to test Test"
72
+ " opening of the file with Windows UNC pathname\n"
73
+ "6. Check that the file is opened successfully\n"
74
+ "7. Close the file\n"
75
+ "8. If all the conditions are met then press PASS else "
76
+ "press FAIL";
77
instructionFrame = new JFrame("InstructionFrame");
78
JTextArea textArea = new JTextArea(instructions);
79
textArea.setEditable(false);
80
final JButton passButton = new JButton("PASS");
81
passButton.addActionListener((e) -> {
82
testPassed = true;
83
instructionFrame.dispose();
84
testFrame.dispose();
85
file.delete();
86
countDownLatch.countDown();
87
});
88
final JButton failButton = new JButton("FAIL");
89
failButton.addActionListener((e) -> {
90
instructionFrame.dispose();
91
testFrame.dispose();
92
file.delete();
93
countDownLatch.countDown();
94
});
95
96
97
JPanel mainPanel = new JPanel(new BorderLayout());
98
mainPanel.add(textArea, BorderLayout.CENTER);
99
100
JPanel buttonPanel = new JPanel(new FlowLayout());
101
buttonPanel.add(passButton);
102
buttonPanel.add(failButton);
103
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
104
instructionFrame.setDefaultCloseOperation(
105
WindowConstants.DISPOSE_ON_CLOSE);
106
instructionFrame.setBounds(0,0,500,500);
107
instructionFrame.add(mainPanel);
108
instructionFrame.pack();
109
instructionFrame.setVisible(true);
110
});
111
}
112
113
private static void openFile() throws IOException {
114
if (!Desktop.isDesktopSupported()) {
115
System.out.println("java.awt.Desktop is not supported on this"+
116
" platform.");
117
return;
118
}
119
120
Desktop desktop = Desktop.getDesktop();
121
if (!desktop.isSupported(Desktop.Action.OPEN)) {
122
System.out.println("Action.OPEN is not supported on this" +
123
" platform.");
124
return;
125
}
126
file = File.createTempFile("Read Me File", ".txt");
127
testFrame = new JFrame("Test Frame");
128
JPanel testButtonPanel = new JPanel(new FlowLayout());
129
final JButton openFileByLocalPathButton = new
130
JButton("OpenFileByLocalPath");
131
final JButton openFileByUNCPathButton = new
132
JButton("OpenFileByUNCPath");
133
openFileByLocalPathButton.addActionListener((e) -> {
134
try {
135
desktop.open(file);
136
} catch (IOException ioException) {
137
}
138
});
139
140
SwingUtilities.invokeLater(()->{
141
testButtonPanel.add(openFileByLocalPathButton);
142
testButtonPanel.add(openFileByUNCPathButton);
143
testFrame.setDefaultCloseOperation(
144
WindowConstants.DISPOSE_ON_CLOSE);
145
testFrame.setBounds(600,0,1000,200);
146
testFrame.add(testButtonPanel);
147
testFrame.pack();
148
testFrame.setVisible(true);
149
});
150
151
// Test opening of the file with Windows UNC pathname.
152
String uncFilePath = "\\\\127.0.0.1\\" +
153
file.getAbsolutePath().replace(':', '$');
154
File uncFile = new File(uncFilePath);
155
if (!uncFile.exists()) {
156
throw new RuntimeException(String.format("File "+
157
"with UNC pathname '%s' does not exist.", uncFilePath));
158
}
159
openFileByUNCPathButton.addActionListener((e) -> {
160
try {
161
desktop.open(uncFile);
162
} catch (IOException ioException) {
163
}
164
});
165
}
166
167
public static void main(String[] args) throws Exception {
168
if (!validatePlatform()) {
169
System.out.println("This test is only for MS Windows OS.");
170
return;
171
}
172
countDownLatch = new CountDownLatch(1);
173
OpenByUNCPathNameTest openByUNCPathNameTest =
174
new OpenByUNCPathNameTest();
175
176
openByUNCPathNameTest.createInstructionUI();
177
openByUNCPathNameTest.openFile();
178
countDownLatch.await(15, TimeUnit.MINUTES);
179
180
if(!testPassed) {
181
throw new RuntimeException("Test failed!");
182
}
183
}
184
}
185
186