示例#1
0
        /**
         * Return a collection of functions that POI can evaluate
         *
         * @return names of functions supported by POI
         */

        public static List <string> GetSupportedFunctionNames()
        {
            List <string> lst = new List <string>();

            lst.AddRange(FunctionEval.GetSupportedFunctionNames());
            lst.AddRange(AnalysisToolPak.GetSupportedFunctionNames());
            return(lst);
        }
示例#2
0
        /**
         * @param startRowIndex row index in the spreadsheet where the first function/operator is found
         * @param TestFocusFunctionName name of a single function/operator to Test alone.
         * Typically pass <code>null</code> to Test all functions
         */
        private void ProcessFunctionGroup(int startRowIndex, String testFocusFunctionName)
        {
            HSSFFormulaEvaluator        evaluator = new HSSFFormulaEvaluator(workbook);
            ReadOnlyCollection <String> funcs     = FunctionEval.GetSupportedFunctionNames();
            int rowIndex = startRowIndex;

            while (true)
            {
                IRow   r = sheet.GetRow(rowIndex);
                String targetFunctionName = GetTargetFunctionName(r);
                if (targetFunctionName == null)
                {
                    throw new AssertionException("Test spreadsheet cell empty on row ("
                                                 + (rowIndex + 1) + "). Expected function name or '"
                                                 + SS.FUNCTION_NAMES_END_SENTINEL + "'");
                }
                if (targetFunctionName.Equals(SS.FUNCTION_NAMES_END_SENTINEL))
                {
                    // found end of functions list
                    break;
                }
                if (testFocusFunctionName == null || targetFunctionName.Equals(testFocusFunctionName, StringComparison.CurrentCultureIgnoreCase))
                {
                    // expected results are on the row below
                    IRow expectedValuesRow = sheet.GetRow(rowIndex + 1);
                    if (expectedValuesRow == null)
                    {
                        int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row
                        throw new AssertionException("Missing expected values row for function '"
                                                     + targetFunctionName + " (row " + missingRowNum + ")");
                    }
                    switch (ProcessFunctionRow(evaluator, targetFunctionName, r, expectedValuesRow))
                    {
                    case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break;

                    case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break;

                    default:
                        throw new SystemException("unexpected result");

                    case Result.NO_EVALUATIONS_FOUND:     // do nothing
                        String uname = targetFunctionName.ToUpper();
                        if (startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
                            funcs.Contains(uname))
                        {
                            Debug.WriteLine(uname + ": function is supported but missing test data", "");
                        }
                        break;
                    }
                }
                rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION;
            }
        }
        /**
         * @param startRowIndex row index in the spreadsheet where the first function/operator is found
         * @param testFocusFunctionName name of a single function/operator to test alone.
         * Typically pass <code>null</code> to test all functions
         */
        private void ProcessFunctionGroup(int startRowIndex, string testFocusFunctionName)
        {
            HSSFFormulaEvaluator        evaluator = new HSSFFormulaEvaluator(workbook);
            ReadOnlyCollection <string> funcs     = FunctionEval.GetSupportedFunctionNames();

            int rowIndex = startRowIndex;

            while (true)
            {
                IRow r = sheet.GetRow(rowIndex);

                // only Evaluate non empty row
                if (r != null)
                {
                    string targetFunctionName = GetTargetFunctionName(r);
                    string targetTestName     = GetTargetTestName(r);
                    if (targetFunctionName == null)
                    {
                        throw new AssertFailedException("Test spreadsheet cell empty on row ("
                                                        + (rowIndex + 1) + "). Expected function name or '"
                                                        + SS.FUNCTION_NAMES_END_SENTINEL + "'");
                    }
                    if (targetFunctionName.Equals(SS.FUNCTION_NAMES_END_SENTINEL))
                    {
                        // found end of functions list
                        break;
                    }
                    if (testFocusFunctionName == null || targetFunctionName.Equals(testFocusFunctionName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // expected results are on the row below
                        ICell expectedValueCell = r.GetCell(SS.COLUMN_INDEX_EXPECTED_VALUE);
                        if (expectedValueCell == null)
                        {
                            int missingRowNum = rowIndex + 1;
                            throw new AssertFailedException("Missing expected values cell for function '"
                                                            + targetFunctionName + ", test" + targetTestName + " (row " +
                                                            missingRowNum + ")");
                        }

                        switch (ProcessFunctionRow(evaluator, targetFunctionName, targetTestName, r, expectedValueCell))
                        {
                        case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break;

                        case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break;

                        default:
                            throw new Exception("unexpected result");

                        case Result.NO_EVALUATIONS_FOUND:     // do nothing
                            string uname = targetFunctionName.ToUpper();
                            if (startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
                                funcs.Contains(uname))
                            {
                                logger.Log(POILogger.WARN, uname + ": function is supported but missing test data");
                            }
                            break;
                        }
                    }
                }
                rowIndex++;
            }
        }