/* * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test @bug 8055197 @summary TextField should replace new line with space character @run main EOLTest */ import java.awt.Frame; import java.awt.TextField; public class EOLTest { private Frame mainFrame; private TextField textField; private String testStrEOL; private boolean isTestFail; private int testFailCount; StringBuilder testFailMessage; private String expectedString = "Row1 Row2"; public EOLTest() { mainFrame = new Frame(); mainFrame.setSize(200, 200); mainFrame.setVisible(true); testFailMessage = new StringBuilder(); testStrEOL = "Row1" + System.getProperty("line.separator") + "Row2"; } private void testConstructor1() { textField = new TextField(testStrEOL); textField.setSize(200, 100); mainFrame.add(textField); checkTest(); mainFrame.remove(textField); textField = null; } private void testConstructor2() { textField = new TextField(30); textField.setSize(200, 100); mainFrame.add(textField); textField.setText(testStrEOL); checkTest(); mainFrame.remove(textField); textField = null; } private void testConstructor3() { textField = new TextField(testStrEOL, 30); textField.setSize(200, 100); mainFrame.add(textField); checkTest(); mainFrame.remove(textField); textField = null; } private void testSetText() { textField = new TextField(); textField.setSize(200, 100); textField.setText(testStrEOL); mainFrame.add(textField); checkTest(); mainFrame.remove(textField); textField = null; } private void checkTest() { if (!textField.getText().equals(expectedString)) { testFailMessage.append("TestFail line : "); testFailMessage.append(Thread.currentThread().getStackTrace()[2]. getLineNumber()); testFailMessage.append(" TextArea string : \""); testFailMessage.append(textField.getText()); testFailMessage.append("\" does not match expected string : \""); testFailMessage.append(expectedString).append("\""); testFailMessage.append(System.getProperty("line.separator")); testFailCount++; isTestFail = true; } } private void checkFailures() { if (isTestFail) { testFailMessage.insert(0, "Test Fail count : " + testFailCount + System.getProperty("line.separator")); dispose(); throw new RuntimeException(testFailMessage.toString()); } } private void dispose() { if (mainFrame != null) { mainFrame.dispose(); } } public static void main(String[] args) { EOLTest testEOL = new EOLTest(); testEOL.testConstructor1(); testEOL.testConstructor2(); testEOL.testConstructor3(); testEOL.testSetText(); testEOL.checkFailures(); testEOL.dispose(); } }