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