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  */
25 package fvt.gui.formula.catalog;
26 
27 import static org.junit.Assert.*;
28 import static testlib.gui.UIMap.*;
29 
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.openoffice.test.common.Logger;
35 import org.openoffice.test.vcl.widgets.VclDialog;
36 
37 import testlib.gui.AppTool;
38 
39 
40 public class SymbolsFromCatalog {
41 
42 	@Rule
43 	public Logger log = Logger.getLogger(this);
44 
45 	@Before
setUp()46 	public void setUp() throws Exception {
47 		app.start(true);
48 		AppTool.newFormula();
49 		// Click catalog button
50 		mathCatalogButton.click();
51 		// Select "Special", click "Edit" button
52 		mathSymbolsDlgListbox.select(2);
53 		mathSymbolsDlgEditButton.click();
54 	}
55 
56 	@After
tearDown()57 	public void tearDown() throws Exception {
58 		AppTool.close();
59 		app.stop();
60 	}
61 
62 	/**
63 	 * Test add custom symbols from Catalog->Symbols
64 	 *
65 	 * @throws Exception
66 	 */
67 	@Test
testAddSymbolFromCatalog()68 	public void testAddSymbolFromCatalog() throws Exception {
69 
70 		// Choose a symbol which is not in the list, click "Add" and "OK"
71 		String selectedSymbol;
72 		boolean bSelectSymbolNotInList;
73 		int nListCount;
74 		int nIndex = 1;
75 		do {
76 			mathEditSymbolsDlgViewControl.click(100 * nIndex, 10);
77 			// risk:after 6 or 7 circles, this will click out of ViewControl
78 			selectedSymbol = mathEditSymbolsDlgSymbol.getText();
79 			nIndex++;
80 			// Find if the selected symbol is already in the list
81 			bSelectSymbolNotInList = false;
82 			nListCount = mathEditSymbolsDlgSymbol.getItemCount();
83 			for (int i = 0; i < nListCount; i++) {
84 				if (selectedSymbol.equals(mathEditSymbolsDlgSymbol
85 						.getItemText(i))) {
86 					bSelectSymbolNotInList = true;
87 					break;
88 				}
89 			}
90 		} while (bSelectSymbolNotInList);
91 		mathEditSymbolsDlgAdd.click();
92 		mathEditSymbolsDlg.ok();
93 
94 		// Verify if the symbol is added to Symbol set
95 		mathSymbolsDlgEditButton.click();
96 		bSelectSymbolNotInList = false;
97 		nListCount = mathEditSymbolsDlgSymbol.getItemCount();
98 		for (int i = 0; i < nListCount; i++) {
99 			if (selectedSymbol.equals(mathEditSymbolsDlgSymbol.getItemText(i))) {
100 				bSelectSymbolNotInList = true;
101 				break;
102 			}
103 		}
104 		assertTrue("Symbol is not added to Symbol set", bSelectSymbolNotInList);
105 	}
106 
107 	/**
108 	 * Test modify font of custom symbols from Catalog->Symbols
109 	 *
110 	 * @throws Exception
111 	 */
112 	@Test
testModifySymbolFontFromCatalog()113 	public void testModifySymbolFontFromCatalog() throws Exception {
114 
115 		// Modify the font of selected symbol
116 		int oldSymbolFontIndex = mathEditSymbolsDlgFont.getSelIndex();
117 		int modifiedSymbolFondIndex = (oldSymbolFontIndex + 1 == mathEditSymbolsDlgFont
118 				.getItemCount()) ? 0 : (oldSymbolFontIndex + 1);
119 		mathEditSymbolsDlgFont.select(modifiedSymbolFondIndex);
120 		// select the next font of old font
121 		String modifiedSymbolFont = mathEditSymbolsDlgFont.getSelText();
122 		String selectedSymbol = mathEditSymbolsDlgSymbol.getText();
123 		mathEditSymbolsDlgModify.click();
124 		mathEditSymbolsDlg.ok();
125 
126 		// Verify if the font of symbol is modified successfully
127 		mathSymbolsDlgEditButton.click();
128 		mathEditSymbolsDlgSymbol.select(selectedSymbol);
129 		assertEquals("Font of symbol is not modified successfully",
130 				modifiedSymbolFont, mathEditSymbolsDlgFont.getSelText());
131 	}
132 
133 	/**
134 	 * Test modify typeface of custom symbols from Catalog->Symbols
135 	 *
136 	 * @throws Exception
137 	 */
138 	@Test
testModifySymbolTypefaceFromCatalog()139 	public void testModifySymbolTypefaceFromCatalog() throws Exception {
140 
141 		// Modify the typeface of selected symbol
142 		int oldSymbolTypefaceIndex = mathEditSymbolsDlgTypeface.getSelIndex();
143 		int modifiedSymbolTypefaceIndex = (oldSymbolTypefaceIndex + 1 == mathEditSymbolsDlgTypeface
144 				.getItemCount()) ? 0 : (oldSymbolTypefaceIndex + 1);
145 		mathEditSymbolsDlgTypeface.select(modifiedSymbolTypefaceIndex);
146 		// select the next typeface of old typeface
147 		String modifiedSymbolTypeface = mathEditSymbolsDlgTypeface.getSelText();
148 		String selectedSymbol = mathEditSymbolsDlgSymbol.getText();
149 		mathEditSymbolsDlgModify.click();
150 		mathEditSymbolsDlg.ok();
151 
152 		// Verify if the typeface of symbol is modified successfully
153 		mathSymbolsDlgEditButton.click();
154 		mathEditSymbolsDlgSymbol.select(selectedSymbol);
155 		assertEquals("Typeface of symbol is not modified successfully",
156 				modifiedSymbolTypeface, mathEditSymbolsDlgTypeface.getSelText());
157 	}
158 
159 	/**
160 	 * Test delete custom symbols from Catalog->Symbols
161 	 *
162 	 * @throws Exception
163 	 */
164 	@Test
testDeleteSymbolFromCatalog()165 	public void testDeleteSymbolFromCatalog() throws Exception {
166 
167 		// Delete the selected symbol
168 		String selectedSymbol = mathEditSymbolsDlgSymbol.getText();
169 		mathEditSymbolsDlgDelete.click();
170 		mathEditSymbolsDlg.ok();
171 		// Verify if the selected symbol is deleted successfully
172 		mathSymbolsDlgEditButton.click();
173 		boolean isDeleted = true;
174 		for (int i = 0; i < mathEditSymbolsDlgSymbol.getItemCount(); i++) {
175 			if (selectedSymbol.equals(mathEditSymbolsDlgSymbol.getItemText(i))) {
176 				isDeleted = false;
177 				break;
178 			}
179 		}
180 		assertTrue("Symbol is not deleted successfully", isDeleted);
181 	}
182 
183 }
184