220N/A/*
2362N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
220N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
220N/A *
220N/A * This code is free software; you can redistribute it and/or modify it
220N/A * under the terms of the GNU General Public License version 2 only, as
220N/A * published by the Free Software Foundation.
220N/A *
220N/A * This code is distributed in the hope that it will be useful, but WITHOUT
220N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
220N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
220N/A * version 2 for more details (a copy is included in the LICENSE file that
220N/A * accompanied this code).
220N/A *
220N/A * You should have received a copy of the GNU General Public License version
220N/A * 2 along with this work; if not, write to the Free Software Foundation,
220N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
220N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
220N/A */
220N/A
220N/A/**
220N/A * @test
220N/A * @bug 4931668
220N/A * @summary Tests XEmbed server/client functionality
220N/A * @author Denis Mikhalkin: area=awt.xembed
220N/A * @compile JavaClient.java TesterClient.java TestXEmbedServer.java
220N/A * @run main/timeout=6000 RunTestXEmbed
220N/A */
220N/A
220N/Aimport java.awt.Rectangle;
220N/Aimport java.lang.reflect.Method;
220N/Aimport java.util.logging.*;
220N/Aimport java.util.*;
220N/Aimport java.io.*;
220N/A
220N/Apublic class RunTestXEmbed extends TestXEmbedServer {
220N/A private static final Logger log = Logger.getLogger("test.xembed");
220N/A private Method test;
220N/A private boolean passed = false;
220N/A public RunTestXEmbed(Method test) {
220N/A super(false);
220N/A this.test = test;
220N/A }
220N/A
220N/A public Process startClient(Rectangle bounds[], long window) {
220N/A try {
220N/A String java_home = System.getProperty("java.home");
220N/A StringBuilder buf = new StringBuilder();
220N/A for (int i = 0; i < bounds.length; i++) {
220N/A buf.append(" " + bounds[i].x);
220N/A buf.append(" " + bounds[i].y);
220N/A buf.append(" " + bounds[i].width);
220N/A buf.append(" " + bounds[i].height);
220N/A }
220N/A Map envs = System.getenv();
220N/A String enva[] = new String[envs.size()];
220N/A int ind = 0;
220N/A Iterator iter = envs.entrySet().iterator();
220N/A while (iter.hasNext()) {
220N/A Map.Entry entry = (Map.Entry)iter.next();
220N/A if (!"AWT_TOOLKIT".equals(entry.getKey())) {
220N/A enva[ind++] = entry.getKey() + "=" + entry.getValue();
220N/A } else {
220N/A enva[ind++] = "AWT_TOOLKIT=sun.awt.X11.XToolkit";
220N/A }
220N/A }
220N/A Process proc = Runtime.getRuntime().exec(java_home +
220N/A "/bin/java -Dawt.toolkit=sun.awt.X11.XToolkit TesterClient "
220N/A + test.getName() + " " + window + buf,
220N/A enva);
220N/A System.err.println("Test for " + test.getName() + " has started.");
220N/A log.fine("Test for " + test.getName() + " has started.");
220N/A new InputReader(proc.getInputStream());
220N/A new InputReader(proc.getErrorStream());
220N/A try {
220N/A passed = (proc.waitFor() == 0);
220N/A } catch (InterruptedException ie) {
220N/A }
220N/A log.fine("Test for " + test.getName() + " has finished.");
220N/A File logFile = new File("java3.txt");
220N/A if (logFile.exists()) {
220N/A logFile.renameTo(new File(test.getName() + ".txt"));
220N/A }
220N/A return proc;
220N/A } catch (IOException ex1) {
220N/A ex1.printStackTrace();
220N/A }
220N/A return null;
220N/A }
220N/A
220N/A public static void main(String[] args) throws Throwable {
220N/A if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
220N/A return;
220N/A }
220N/A
220N/A // Enabled XEmbed
220N/A System.setProperty("sun.awt.xembedserver", "true");
220N/A
220N/A if (args.length == 1) {
220N/A Class cl = Class.forName("sun.awt.X11.XEmbedServerTester");
220N/A Method meth = cl.getMethod(args[0], new Class[0]);
220N/A System.err.println("Performing single test " + args[0]);
220N/A boolean res = performTest(meth);
220N/A if (!res) {
220N/A System.err.println("Test " + args[0] + " has failed");
220N/A } else {
220N/A System.err.println("Test " + args[0] + " has passed");
220N/A }
220N/A } else {
220N/A Class cl = Class.forName("sun.awt.X11.XEmbedServerTester");
220N/A Method[] meths = cl.getMethods();
220N/A LinkedList failed = new LinkedList();
220N/A for (int i = 0; i < meths.length; i++) {
220N/A Method meth = meths[i];
220N/A if (meth.getReturnType() == Void.TYPE && meth.getName().startsWith("test") && meth.getParameterTypes().length == 0) {
220N/A System.err.println("Performing " + meth.getName());
220N/A boolean res = performTest(meth);
220N/A if (!res) {
220N/A failed.add(meth);
220N/A }
220N/A }
220N/A }
220N/A log.info("Testing finished.");
220N/A if (failed.size() != 0) {
220N/A System.err.println("Some tests have failed:");
220N/A Iterator iter = failed.iterator();
220N/A while(iter.hasNext()) {
220N/A Method meth = (Method)iter.next();
220N/A System.err.println(meth.getName());
220N/A }
220N/A throw new RuntimeException("TestFAILED: some of the testcases are failed");
220N/A } else {
220N/A System.err.println("All PASSED");
220N/A }
220N/A }
220N/A }
220N/A
220N/A private static boolean performTest(Method meth) {
220N/A RunTestXEmbed test = new RunTestXEmbed(meth);
220N/A test.addClient();
220N/A test.dispose();
220N/A return test.isPassed();
220N/A }
220N/A
220N/A public boolean isPassed() {
220N/A return passed;
220N/A }
220N/A}
220N/A
220N/Aclass InputReader extends Thread {
220N/A private InputStream stream;
220N/A public InputReader(InputStream stream) {
220N/A this.stream = stream;
220N/A start();
220N/A }
220N/A public void run() {
220N/A while (!interrupted()) {
220N/A try {
220N/A int inp = stream.read();
220N/A if (inp != -1) {
220N/A System.out.write(inp);
220N/A } else {
220N/A try {
220N/A Thread.sleep(100);
220N/A } catch (Exception iie) {
220N/A }
220N/A }
220N/A } catch (IOException ie) {
220N/A break;
220N/A }
220N/A }
220N/A }
220N/A}