Path: blob/master/test/jdk/java/awt/FileDialog/FileNameOverrideTest/FileNameOverrideTest.java
41152 views
/*1* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24test25@bug 626065926@summary File Name set programmatically in FileDialog is overridden during navigation, XToolkit27@author [email protected] area=awt.filedialog28@library ../../regtesthelpers29@build Sysout30@run applet/manual=yesno FileNameOverrideTest.html31*/3233import test.java.awt.regtesthelpers.Sysout;3435import java.applet.Applet;36import java.awt.*;37import java.awt.event.ActionEvent;38import java.awt.event.ActionListener;39import java.io.File;40import java.io.IOException;4142public class FileNameOverrideTest extends Applet implements ActionListener {43private final static String fileName = "input";44private final static String clickDirName = "Directory for double click";45private final static String dirPath = ".";46private Button showBtn;47private FileDialog fd;4849public void init() {50this.setLayout(new GridLayout(1, 1));5152fd = new FileDialog(new Frame(), "Open");5354showBtn = new Button("Show File Dialog");55showBtn.addActionListener(this);56add(showBtn);5758try {59File tmpFileUp = new File(dirPath + File.separator + fileName);60File tmpDir = new File(dirPath + File.separator + clickDirName);61File tmpFileIn = new File(tmpDir.getAbsolutePath() + File.separator + fileName);62tmpDir.mkdir();63tmpFileUp.createNewFile();64tmpFileIn.createNewFile();65} catch (IOException ex) {66throw new RuntimeException("Cannot create test folder", ex);67}6869String[] instructions = {70"1) Click on 'Show File Dialog' button. A file dialog will come up.",71"2) Double-click on '" + clickDirName + "' and click OK.",72"3) See result of the test below"73};74Sysout.createDialogWithInstructions(instructions);75}//End init()7677public void start() {78setSize(200, 200);79show();80}// start()8182public void actionPerformed(ActionEvent e) {83if (e.getSource() == showBtn) {84fd.setFile(fileName);85fd.setDirectory(dirPath);86fd.setVisible(true);87String output = fd.getFile();88if (fileName.equals(output)) {89Sysout.println("TEST PASSED");90} else {91Sysout.println("TEST FAILED (output file - " + output + ")");92}93}94}95}// class ManualYesNoTest969798