-
Notifications
You must be signed in to change notification settings - Fork 305
/
TestFormulaDocs.java
182 lines (157 loc) · 6.63 KB
/
TestFormulaDocs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package fvt.uno.sc.formula;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
import org.openoffice.test.common.Testspace;
import org.openoffice.test.common.Logger;
import org.openoffice.test.uno.UnoApp;
import testlib.uno.SCUtil;
import static testlib.uno.TestUtil.*;
import com.sun.star.beans.PropertyValue;
import com.sun.star.document.MacroExecMode;
import com.sun.star.lang.XComponent;
import com.sun.star.sheet.XSpreadsheet;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheets;
import com.sun.star.table.XCell;
import com.sun.star.uno.Any;
import com.sun.star.text.XText;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XModifiable;
import java.util.logging.Level;
@RunWith(Parameterized.class)
public class TestFormulaDocs {
private String filename;
private String type;
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
// test documents
{"uno/sc/fvt/FormulaTest1.ods", "FormulaTest1.ods"},
{"uno/sc/fvt/StarBasicYearMonthDateHourMinuteSecondTests.ods", "Basic Year Month Date Hour Minute Second Test"},
{"uno/sc/fvt/StarBasicCLng.ods", "Basic Convert to Long Function Test"},
{"uno/sc/fvt/StarBasicTab.ods", "Basic Tab Function Test"},
{"uno/sc/fvt/DGET on formulas.ods", "DGET on formulas Test"},
{"uno/sc/fvt/Basic Line as variable and Line Input.ods", "Basic Line as variable and Line Input Test"},
{"uno/sc/fvt/comment-in-single-line-if-then-else.ods", "Basic comment after single line if statement Test"},
{"uno/sc/fvt/Bug81233ColumnZReference.xml", "Bug 81233 column Z reference wrongly converts to column A"},
{"uno/sc/fvt/Bug100989MergeAcross0AddsExtraEmptyCell.xml", "Bug 100989 ss:MergeCross=\"0\" adds an extra empty cell to the right"},
{"uno/sc/fvt/Bug128554FractionalSecondsIgnored.xml", "Bug 100989 fractional seconds are silently ignored during import"}
});
}
@Rule
public Logger log = Logger.getLogger(this);
static UnoApp unoApp = new UnoApp();
XComponent scComponent = null;
/**
* Clean class after testing
*
* @throws Exception
*/
@AfterClass
public static void afterClass() {
unoApp.close();
}
@Before
public void setUp() throws Exception {
unoApp.close(); // moved here from tearDown because stopping app there causes a late screenshot
unoApp.start();
}
public TestFormulaDocs(String filename, String type) {
this.filename = filename;
this.type = type;
}
// FIXME: only needs a timeout for running tests against AOO41X due to fixes for i112383 and i117960 present in trunk
// haven't been backported to AOO41X yet and causes these tests to hang on an error dialog.
@Test(timeout = 15000)
public void testOneDoc() throws Exception {
// open the spreadsheet document
String sample = Testspace.prepareData(filename);
// enable macros
PropertyValue prop = new PropertyValue();
prop.Name = "MacroExecutionMode";
prop.Value = MacroExecMode.ALWAYS_EXECUTE_NO_WARN;
XSpreadsheetDocument scDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(
XSpreadsheetDocument.class, unoApp.loadDocument(sample, prop));
XSpreadsheet xSheet = SCUtil.getCurrentSheet( scDoc);
// find the "TestID" and "TestOK" markers
int nTestIdCol = -1;
int nTestOkCol = -1;
int nTestRowStart = -1;
for( int y = 0; y < 8; ++y) {
for( int x = 0; x < 26; ++x) {
XCell xCell = xSheet.getCellByPosition( x, y);
XText xText = (XText)UnoRuntime.queryInterface( XText.class, xCell);
String name = xText.getString();
if( name.equals( "TestID")) {
assertTrue( "Multiple rows with TestID marker!", nTestIdCol == -1);
assertTrue( nTestRowStart == -1);
nTestIdCol = x;
nTestRowStart = y + 1;
} else if( name.equals( "TestOK")) {
assertTrue( "Multiple rows with TestOK marker!", nTestOkCol == -1);
assertTrue( "TestID and TestOK marker not in same row!", nTestRowStart == y + 1);
nTestOkCol = x;
}
}
}
assertTrue( "Column \"TestID\" not found!", nTestIdCol >= 0);
assertTrue( "Column \"TestOK\" not found!", nTestOkCol >= 0);
int nTestRowEnd = nTestRowStart + 100; // TODO: get the last row from the sheet
int nTestCount = 0;
int nFailCount = 0;
for( int y = nTestRowStart; y < nTestRowEnd; ++y) {
// get the test id
XCell xCell = xSheet.getCellByPosition( nTestIdCol, y);
XText xText = (XText)UnoRuntime.queryInterface( XText.class, xCell);
String testId = xText.getString();
// ignore rows without test ids
if( testId.length() == 0)
continue;
++nTestCount;
// get and check the test result
xCell = xSheet.getCellByPosition( nTestOkCol, y);
String testOk = ((XText)UnoRuntime.queryInterface( XText.class, xCell)).getString();
assertTrue( "Test result must be TRUE or FALSE", testOk.equals("TRUE") || testOk.equals("FALSE"));
boolean bOK = testOk.equals("TRUE");
// mark evaluated test results
SCUtil.setProperties( xCell, "CellBackColor", (Integer)(bOK ? 0x00FF00 : 0xFF0000));
// handle failed test cases
if( !bOK) {
++nFailCount;
log.log( Level.SEVERE, "\ttest \""+testId+" failed");
}
}
assertTrue( (""+nFailCount+" of "+nTestCount+" tests failed for " + type), nFailCount==0);
XModifiable modified = (XModifiable)UnoRuntime.queryInterface( XModifiable.class, scDoc);
modified.setModified( false);
SCUtil.closeFile( scDoc);
}
}