001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui.propertyeditors;
043:
044: import org.netbeans.jellytools.properties.FontProperty;
045: import org.netbeans.jellytools.properties.PropertySheetOperator;
046:
047: import org.netbeans.jellytools.properties.editors.FontCustomEditorOperator;
048:
049: import org.netbeans.junit.NbTestSuite;
050:
051: /**
052: * Tests of Font Property Editor.
053: *
054: * @author Marian.Mirilovic@Sun.Com
055: */
056: public class PropertyType_Font extends PropertyEditorsTest {
057:
058: public String propertyName_L;
059: public String propertyValue_L;
060: public String propertyValueExpectation_L;
061:
062: public boolean waitDialog = false;
063:
064: /** Creates a new instance of PropertyType_Font */
065: public PropertyType_Font(String testName) {
066: super (testName);
067: }
068:
069: public void setUp() {
070: propertyName_L = "Font";
071: super .setUp();
072: }
073:
074: public static NbTestSuite suite() {
075: NbTestSuite suite = new NbTestSuite();
076: suite.addTest(new PropertyType_Font("verifyCustomizer"));
077: suite.addTest(new PropertyType_Font("testCustomizerCancel"));
078: suite.addTest(new PropertyType_Font("testCustomizerOk"));
079: suite.addTest(new PropertyType_Font(
080: "testCustomizerOkUnknownSize"));
081: suite.addTest(new PropertyType_Font("testCustomizerInvalid"));
082: return suite;
083: }
084:
085: public void testCustomizerOk() {
086: propertyValue_L = "Monospaced, 10, Bold";
087: propertyValueExpectation_L = "Monospaced 10 Bold";
088: waitDialog = false;
089: setByCustomizerOk(propertyName_L, true);
090: }
091:
092: public void testCustomizerOkUnknownSize() {
093: propertyValue_L = "Monospaced, 13, Bold";
094: propertyValueExpectation_L = "Monospaced 13 Bold";
095: waitDialog = false;
096: setByCustomizerOk(propertyName_L, true);
097: }
098:
099: public void testCustomizerCancel() {
100: propertyValue_L = "Monospaced, 100, Bold";
101: propertyValueExpectation_L = "Monospaced 100 Bold";
102: waitDialog = false;
103: setByCustomizerCancel(propertyName_L, false);
104: }
105:
106: public void testCustomizerInvalid() {
107: propertyValue_L = "Monospaced, xx, Bold Italic";
108: propertyValueExpectation_L = "Monospaced xx Bold Italic";
109: waitDialog = false;
110: setByCustomizerOk(propertyName_L, false);
111: }
112:
113: public void verifyCustomizer() {
114: verifyCustomizer(propertyName_L);
115: }
116:
117: public void setCustomizerValue() {
118: FontCustomEditorOperator customizer = new FontCustomEditorOperator(
119: propertyCustomizer);
120:
121: int index1, index2, index3;
122: index1 = propertyValue_L.indexOf(", ");
123:
124: if (index1 > 0) {
125: customizer.setFontName(propertyValue_L.substring(0, index1)
126: .trim());
127: index2 = propertyValue_L.indexOf(", ", index1 + 1);
128:
129: if (index2 > 0) {
130: customizer.setFontSize(propertyValue_L.substring(
131: index1 + 1, index2).trim());
132: customizer.setFontStyle(propertyValue_L.substring(
133: index2 + 1).trim());
134: }
135: }
136:
137: }
138:
139: public void verifyPropertyValue(boolean expectation) {
140: verifyExpectationValue(propertyName_L, expectation,
141: propertyValueExpectation_L, propertyValue_L, waitDialog);
142: }
143:
144: public String getValue(String propertyName) {
145: String returnValue;
146: PropertySheetOperator propertiesTab = new PropertySheetOperator(
147: propertiesWindow);
148:
149: returnValue = new FontProperty(propertiesTab, propertyName_L)
150: .getValue();
151: err.println("GET VALUE = [" + returnValue + "].");
152:
153: // hack for color poperty, this action expects, that right value is displayed as tooltip
154: // returnValue = new Property(propertiesTab, propertyName_L).valueButtonOperator().getToolTipText();
155: // err.println("GET VALUE TOOLTIP = [" + returnValue + "].");
156:
157: return returnValue;
158: }
159:
160: public void verifyCustomizerLayout() {
161: FontCustomEditorOperator customizer = new FontCustomEditorOperator(
162: propertyCustomizer);
163: customizer.verify();
164: customizer.btOK();
165: customizer.btCancel();
166: }
167:
168: /** Test could be executed internaly in Forte without XTest
169: * @param args arguments from command line
170: */
171: public static void main(String[] args) {
172: //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Font.class));
173: junit.textui.TestRunner.run(suite());
174: }
175:
176: }
|