1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 
27 import lib.MultiMethodTest;
28 
29 import com.sun.star.awt.XPatternField;
30 
31 /**
32 * Testing <code>com.sun.star.awt.XPatternField</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> setMasks()</code></li>
36 *  <li><code> getMasks()</code></li>
37 *  <li><code> setString()</code></li>
38 *  <li><code> getString()</code></li>
39 *  <li><code> setStrictFormat()</code></li>
40 *  <li><code> isStrictFormat()</code></li>
41 * </ul> <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.awt.XPatternField
44 */
45 public class _XPatternField extends MultiMethodTest {
46 
47     public XPatternField oObj = null ;
48     private String editMask = null ;
49     private String literalMask = null ;
50     private String string = null ;
51     private boolean strict = false ;
52 
53     /**
54     * Sets masks to new values then gets them and compare. <p>
55     * Has <b> OK </b> status if set and get masks are equal. <p>
56     * The following method tests are to be completed successfully before :
57     * <ul>
58     *  <li> <code> getMasks </code> </li>
59     * </ul>
60     */
61     public void _setMasks() {
62         requiredMethod("getMasks()") ;
63 
64         boolean result = true ;
65         String newEdit = editMask == null ? "ccc" : editMask + "ccc" ;
66         String newLiteral = literalMask == null ? " " : literalMask + " " ;
67         oObj.setMasks(newEdit, newLiteral) ;
68 
69         String[] edit = new String[1] ;
70         String[] literal = new String[1] ;
71         oObj.getMasks(edit, literal) ;
72 
73         result &= newEdit.equals(edit[0]) ;
74         result &= newLiteral.equals(literal[0]) ;
75 
76         tRes.tested("setMasks()", result) ;
77     }
78 
79     /**
80     * Gets masks and stores them. <p>
81     * Has <b> OK </b> status if no runtime exceptions occured.
82     */
83     public void _getMasks() {
84 
85         boolean result = true ;
86         String[] edit = new String[1] ;
87         String[] literal = new String[1] ;
88         oObj.getMasks(edit, literal) ;
89 
90         log.println("Edit mask = '" + edit[0] + "', literal = '" +
91             literal[0] + "'") ;
92 
93         editMask = edit[0] ;
94         literalMask = literal[0] ;
95 
96         tRes.tested("getMasks()", result) ;
97     }
98 
99     /**
100     * Sets new string and then get it for verification. <p>
101     * Has <b> OK </b> status if get and set strings are equal. <p>
102     * The following method tests are to be completed successfully before :
103     * <ul>
104     *  <li> <code> getString </code> </li>
105     *  <li> <code> setMasks </code> : mask must be set for new string
106     *   would be valid. </li>
107     * </ul>
108     */
109     public void _setString() {
110         requiredMethod("setMasks()") ;
111         requiredMethod("getString()") ;
112 
113         boolean result = true ;
114         String newString = string = "abc" ;
115         oObj.setString(newString) ;
116         String getString = oObj.getString() ;
117 
118         result = newString.equals(getString) ;
119 
120         if (!result) {
121             log.println("Was '" + string + "', Set '" + newString
122                 + "', Get '" + getString + "'") ;
123         }
124 
125         tRes.tested("setString()", result) ;
126     }
127 
128     /**
129     * Gets current string and stores it. <p>
130     * Has <b> OK </b> status if no runtime exceptions occured
131     */
132     public void _getString() {
133 
134         boolean result = true ;
135         string = oObj.getString() ;
136 
137         tRes.tested("getString()", result) ;
138     }
139 
140     /**
141     * Sets new strict state then checks it. <p>
142     * Has <b> OK </b> status if the state was changed.
143     * The following method tests are to be completed successfully before :
144     * <ul>
145     *  <li> <code> isStrictFormat </code> </li>
146     * </ul>
147     */
148     public void _setStrictFormat() {
149         requiredMethod("isStrictFormat()") ;
150 
151         boolean result = true ;
152         oObj.setStrictFormat(!strict) ;
153 
154         result = oObj.isStrictFormat() == !strict ;
155 
156         tRes.tested("setStrictFormat()", result) ;
157     }
158 
159     /**
160     * Gets the current strict state and stores it. <p>
161     * Has <b> OK </b> status if no runtime exceptions occured.
162     */
163     public void _isStrictFormat() {
164 
165         boolean result = true ;
166         strict = oObj.isStrictFormat() ;
167 
168         tRes.tested("isStrictFormat()", result) ;
169     }
170 }
171 
172 
173