summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej@ahunt.org>2015-06-01 18:10:29 +0100
committerAndrzej Hunt <andrzej@ahunt.org>2015-10-20 18:18:38 +0200
commit2d94190ce6361cb2bc76ef1900e556969bc46927 (patch)
tree9e327b4eb4730bfbeb8d57bb9c48007c3434431c
parentc6dc5114d7d84670e77f3b3a7b851946c6000a11 (diff)
Add tests for output unit verification.
Change-Id: Ia273a64fdbb5e1fe57f41679e9d77e0df78987de
-rw-r--r--sc/qa/unit/units.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/sc/qa/unit/units.cxx b/sc/qa/unit/units.cxx
index 4e9c2f903fa6..e2ad7cc50b7d 100644
--- a/sc/qa/unit/units.cxx
+++ b/sc/qa/unit/units.cxx
@@ -205,6 +205,14 @@ void UnitsTest::testUnitVerification() {
setNumberFormatUnit(address, "m");
mpDoc->SetValue(address, 1);
+ // 6th column: header annotation for output verification
+ address = ScAddress(5, 0, 0);
+ mpDoc->SetString(address, "foobar [cm]");
+
+ // 7th column: another header annotation
+ address = ScAddress(6, 0, 0);
+ mpDoc->SetString(address, "foobar (cm/s)");
+
ScFormulaCell* pCell;
ScTokenArray* pTokens;
@@ -359,6 +367,52 @@ void UnitsTest::testUnitVerification() {
pTokens = pCell->GetCode();
CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::ERROR_INPUT_INCOMPATIBLE);
}
+
+
+ // Test output unit verification (i.e. using header annotations)
+
+ // header in [cm], cell with cm
+ address = ScAddress(5, 1, 0);
+ mpDoc->SetFormula(address, "=A1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+
+
+ // header in [cm], cell with 100*cm
+ address.IncRow();
+ mpDoc->SetFormula(address, "=100*A1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::ERROR_OUTPUT_SCALING);
+
+ // header in [cm], cell with kg
+ address.IncRow();
+ mpDoc->SetFormula(address, "=B1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::ERROR_OUTPUT_INCOMPATIBLE);
+
+ // header in [cm], cell with m
+ address.IncRow();
+ mpDoc->SetFormula(address, "=E1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::ERROR_OUTPUT_SCALING);
+
+ // header in [cm], cell with 100*m
+ address.IncRow();
+ mpDoc->SetFormula(address, "=100*E1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
+
+ // header in (cm/s), formula resulting in cm/s
+ address = ScAddress(6, 1, 0);
+ mpDoc->SetFormula(address, "=A1/C1");
+ pCell = mpDoc->GetFormulaCell(address);
+ pTokens = pCell->GetCode();
+ CPPUNIT_ASSERT(mpUnitsImpl->verifyFormula(pTokens, address, mpDoc) == FormulaStatus::VERIFIED);
}
void UnitsTest::testUnitFromFormatStringExtraction() {