FontFile.java revision 1121
1121N/A/*
1121N/A * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
1121N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1121N/A *
1121N/A * This code is free software; you can redistribute it and/or modify it
1121N/A * under the terms of the GNU General Public License version 2 only, as
1121N/A * published by the Free Software Foundation.
1121N/A *
1121N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1121N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1121N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1121N/A * version 2 for more details (a copy is included in the LICENSE file that
1121N/A * accompanied this code).
1121N/A *
1121N/A * You should have received a copy of the GNU General Public License version
1121N/A * 2 along with this work; if not, write to the Free Software Foundation,
1121N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1121N/A *
1121N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1121N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1121N/A * have any questions.
1121N/A */
1121N/A
1121N/A/*
1121N/A * @test
1121N/A * @bug 6652929
1121N/A * @summary verify handling of File.getPath()
1121N/A */
1121N/A
1121N/Aimport java.awt.*;
1121N/Aimport java.io.*;
1121N/A
1121N/Apublic class FontFile {
1121N/A public static void main(String[] args) throws Exception {
1121N/A String sep = System.getProperty("file.separator");
1121N/A String fname = ".." + sep + "A.ttf";
1121N/A String dir = System.getProperty("test.src");
1121N/A if (dir != null) {
1121N/A fname = dir + sep + fname;
1121N/A }
1121N/A final String name = fname;
1121N/A System.out.println("Will try to access " + name);
1121N/A if (!(new File(name)).canRead()) {
1121N/A System.out.println("File not available : can't run test");
1121N/A return;
1121N/A }
1121N/A System.out.println("File is available. Verify no access under SM");
1121N/A
1121N/A System.setSecurityManager(new SecurityManager());
1121N/A
1121N/A
1121N/A // Check cannot read file.
1121N/A try {
1121N/A new FileInputStream(name);
1121N/A throw new Error("Something wrong with test environment");
1121N/A } catch (SecurityException exc) {
1121N/A // Good.
1121N/A }
1121N/A
1121N/A try {
1121N/A Font font = Font.createFont(Font.TRUETYPE_FONT,
1121N/A new File("nosuchfile") {
1121N/A private boolean read;
1121N/A @Override public String getPath() {
1121N/A if (read) {
1121N/A return name;
1121N/A } else {
1121N/A read = true;
1121N/A return "somefile";
1121N/A }
1121N/A }
1121N/A @Override public boolean canRead() {
1121N/A return true;
1121N/A }
1121N/A }
1121N/A );
1121N/A System.err.println(font.getFontName());
1121N/A throw new RuntimeException("No expected exception");
1121N/A } catch (IOException e) {
1121N/A System.err.println("Test passed.");
1121N/A }
1121N/A }
1121N/A}