/* ====================================================================
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 org.apache.poi.ss.formula.eval;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.functions.TestMathX;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LocaleUtil;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import junit.framework.AssertionFailedError;
/**
* Tests formulas and operators as loaded from a test data spreadsheet.
* This class does not test implementors of Function and OperationEval in
* isolation. Much of the evaluation engine (i.e. HSSFFormulaEvaluator, ...) gets
* exercised as well. Tests for bug fixes and specific/tricky behaviour can be found in the
* corresponding test class (TestXxxx) of the target (Xxxx) implementor,
* where execution can be observed more easily.
*/
@RunWith(Parameterized.class)
public final class TestFormulasFromSpreadsheet {
private static HSSFWorkbook workbook;
private static Sheet sheet;
private static HSSFFormulaEvaluator evaluator;
private static Locale userLocale;
/**
* This class defines constants for navigating around the test data spreadsheet used for these tests.
*/
private static interface SS {
/**
* Name of the test spreadsheet (found in the standard test data folder)
*/
String FILENAME = "FormulaEvalTestData.xls";
/**
* Row (zero-based) in the test spreadsheet where the operator examples start.
*/
int START_OPERATORS_ROW_INDEX = 22; // Row '23'
/**
* Row (zero-based) in the test spreadsheet where the function examples start.
*/
int START_FUNCTIONS_ROW_INDEX = 95; // Row '96'
/**
* Index of the column that contains the function names
*/
int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
/**
* Used to indicate when there are no more functions left
*/
String FUNCTION_NAMES_END_SENTINEL = "";
/**
* Index of the column where the test values start (for each function)
*/
short COLUMN_INDEX_FIRST_TEST_VALUE = 3; // Column 'D'
/**
* Each function takes 4 rows in the test spreadsheet
*/
int NUMBER_OF_ROWS_PER_FUNCTION = 4;
}
@Parameter(value = 0)
public String targetFunctionName;
@Parameter(value = 1)
public int formulasRowIdx;
@Parameter(value = 2)
public int expectedValuesRowIdx;
@AfterClass
public static void closeResource() throws Exception {
LocaleUtil.setUserLocale(userLocale);
workbook.close();
}
@Parameters(name="{0}")
public static Collection