summaryrefslogtreecommitdiff
path: root/sc/qa/unit
diff options
context:
space:
mode:
authorLaurent Godard <lgodard.libre@laposte.net>2013-08-30 17:19:11 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-09-04 09:12:49 +0000
commit673881b8fbdc3e0b66d7042221ff9532a49fc044 (patch)
tree3f519e217b4a6fe6f927b56e697031f75fa5625a /sc/qa/unit
parent9beb480833a4ba66033953327b7163495390dedf (diff)
calc export test on cell values, strings & formulas
Change-Id: I5e55da683423a461638b2235e25d5556fd77221a Reviewed-on: https://gerrit.libreoffice.org/5698 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc/qa/unit')
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx80
1 files changed, 80 insertions, 0 deletions
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index c26d11550e97..bd69cc1fe409 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -29,6 +29,8 @@
#include "formulacell.hxx"
#include "tokenarray.hxx"
#include "editutil.hxx"
+#include "scopetools.hxx"
+#include "cellvalue.hxx"
#include "svx/svdoole2.hxx"
#include "tabprotection.hxx"
@@ -64,6 +66,8 @@ public:
void testNamedRangeBugfdo62729();
void testRichTextExportODS();
+ void testCellValuesExportODS();
+
void testInlineArrayXLS();
void testEmbeddedChartXLS();
void testFormulaReferenceXLS();
@@ -81,6 +85,7 @@ public:
CPPUNIT_TEST(testMiscRowHeightExport);
CPPUNIT_TEST(testNamedRangeBugfdo62729);
CPPUNIT_TEST(testRichTextExportODS);
+ CPPUNIT_TEST(testCellValuesExportODS);
CPPUNIT_TEST(testInlineArrayXLS);
CPPUNIT_TEST(testEmbeddedChartXLS);
CPPUNIT_TEST(testFormulaReferenceXLS);
@@ -564,6 +569,81 @@ void ScExportTest::testRichTextExportODS()
xNewDocSh3->DoClose();
}
+void ScExportTest::testCellValuesExportODS()
+{
+ // Start with an empty document
+ ScDocShellRef xOrigDocSh = loadDoc("empty.", ODS);
+ ScDocument* pDoc = xOrigDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.", pDoc->GetTableCount() > 0);
+
+ // set a value double
+ pDoc->SetValue(ScAddress(0,0,0), 2.0); // A1
+
+ // set a formula
+ pDoc->SetValue(ScAddress(2,0,0), 3.0); // C1
+ pDoc->SetValue(ScAddress(3,0,0), 3); // D1
+ pDoc->SetString(ScAddress(4,0,0), "=10*C1/4"); // E1
+ pDoc->SetValue(ScAddress(5,0,0), 3.0); // F1
+ pDoc->SetString(ScAddress(7,0,0), "=SUM(C1:F1)"); //H1
+
+ // set a string
+ pDoc->SetString(ScAddress(0,2,0), "a simple line"); //A3
+
+ // set a digit string
+ pDoc->SetString(ScAddress(0,4,0), "'12"); //A5
+ // set a contiguous value
+ pDoc->SetValue(ScAddress(0,5,0), 12.0); //A6
+ // set acontiguous string
+ pDoc->SetString(ScAddress(0,6,0), "a string"); //A7
+ // set a contiguous formula
+ pDoc->SetString(ScAddress(0,7,0), "=$A$6"); //A8
+
+ // save and reload
+ ScDocShellRef xNewDocSh = saveAndReload(xOrigDocSh, ODS);
+ xOrigDocSh->DoClose();
+ CPPUNIT_ASSERT(xNewDocSh.Is());
+ pDoc = xNewDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.", pDoc->GetTableCount() > 0);
+
+ // check value
+ CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(2,0,0));
+ CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(3,0,0));
+ CPPUNIT_ASSERT_EQUAL(7.5, pDoc->GetValue(4,0,0));
+ CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(5,0,0));
+
+ // check formula
+ if (!checkFormula(*pDoc, ScAddress(4,0,0), "10*C1/4"))
+ CPPUNIT_FAIL("Wrong formula =10*C1/4");
+ if (!checkFormula(*pDoc, ScAddress(7,0,0), "SUM(C1:F1)"))
+ CPPUNIT_FAIL("Wrong formula =SUM(C1:F1)");
+ CPPUNIT_ASSERT_EQUAL(16.5, pDoc->GetValue(7,0,0));
+
+ // check string
+ ScRefCellValue aCell;
+ aCell.assign(*pDoc, ScAddress(0,2,0));
+ CPPUNIT_ASSERT_EQUAL( CELLTYPE_STRING, aCell.meType );
+
+ // check for an empty cell
+ aCell.assign(*pDoc, ScAddress(0,3,0));
+ CPPUNIT_ASSERT_EQUAL( CELLTYPE_NONE, aCell.meType);
+
+ // check a digit string
+ aCell.assign(*pDoc, ScAddress(0,4,0));
+ CPPUNIT_ASSERT_EQUAL( CELLTYPE_STRING, aCell.meType);
+
+ //check contiguous values
+ CPPUNIT_ASSERT_EQUAL( 12.0, pDoc->GetValue(0,5,0) );
+ CPPUNIT_ASSERT_EQUAL( OUString("a string"), pDoc->GetString(0,6,0) );
+ if (!checkFormula(*pDoc, ScAddress(0,7,0), "$A$6"))
+ CPPUNIT_FAIL("Wrong formula =$A$6");
+ CPPUNIT_ASSERT_EQUAL( pDoc->GetValue(0,5,0), pDoc->GetValue(0,7,0) );
+
+ xNewDocSh->DoClose();
+}
+
namespace {
void checkMatrixRange(ScDocument& rDoc, const ScRange& rRange)