summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-02-03 11:47:10 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-02-03 11:49:21 -0500
commitfc5eefc903529d1c3548c680b3077eee4e2c7a73 (patch)
tree33e1d5506c7f6067d6dfcf90adcd6b896d2e7f76
parente753233e2e8af04048a17c7163ff5d9d3ffbbf3d (diff)
Add test code to exercise ScColumn::HasEditCells().
Change-Id: Ibacf3585a6d15d541a50cb7bb50905d34a7d598b
-rw-r--r--sc/CppunitTest_sc_ucalc.mk1
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/inc/table.hxx1
-rw-r--r--sc/qa/unit/ucalc.hxx3
-rw-r--r--sc/qa/unit/ucalc_column.cxx70
-rw-r--r--sc/source/core/data/document.cxx9
-rw-r--r--sc/source/core/data/table2.cxx19
7 files changed, 105 insertions, 0 deletions
diff --git a/sc/CppunitTest_sc_ucalc.mk b/sc/CppunitTest_sc_ucalc.mk
index 20001e51276f..c4d48d814422 100644
--- a/sc/CppunitTest_sc_ucalc.mk
+++ b/sc/CppunitTest_sc_ucalc.mk
@@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_ucalc))
$(eval $(call gb_CppunitTest_add_exception_objects,sc_ucalc, \
sc/qa/unit/ucalc \
+ sc/qa/unit/ucalc_column \
sc/qa/unit/ucalc_formula \
sc/qa/unit/ucalc_pivottable \
sc/qa/unit/ucalc_sharedformula \
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 972a96c508fa..6ffcc69cbc6b 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -802,6 +802,8 @@ public:
SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr );
+ SC_DLLPUBLIC bool HasEditText( const ScRange& rRange ) const;
+
/**
* Call this if you are not sure whether to put this as an edit text or a
* simple text.
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 22720e746b48..2b384739f30d 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -329,6 +329,7 @@ public:
void SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText );
void SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditText, const SfxItemPool* pEditPool );
+ bool HasEditText( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
void SetEmptyCell( SCCOL nCol, SCROW nRow );
void SetFormula(
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 84f54708fcef..48234e5c94a3 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -311,6 +311,8 @@ public:
void testImportStream();
+ void testColumnFindEditCells();
+
CPPUNIT_TEST_SUITE(Test);
#if CALC_TEST_PERF
CPPUNIT_TEST(testPerf);
@@ -433,6 +435,7 @@ public:
CPPUNIT_TEST(testCondFormatInsertCol);
CPPUNIT_TEST(testCondCopyPaste);
CPPUNIT_TEST(testImportStream);
+ CPPUNIT_TEST(testColumnFindEditCells);
CPPUNIT_TEST_SUITE_END();
private:
diff --git a/sc/qa/unit/ucalc_column.cxx b/sc/qa/unit/ucalc_column.cxx
new file mode 100644
index 000000000000..0959ee1d47b9
--- /dev/null
+++ b/sc/qa/unit/ucalc_column.cxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <ucalc.hxx>
+#include <editutil.hxx>
+#include <cellvalue.hxx>
+
+void Test::testColumnFindEditCells()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ bool bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,MAXROW,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
+ bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,0,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
+ bRes = m_pDoc->HasEditText(ScRange(0,0,0,0,10,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", !bRes);
+
+ ScFieldEditEngine& rEE = m_pDoc->GetEditEngine();
+ rEE.SetText("Test");
+ m_pDoc->SetEditText(ScAddress(0,0,0), rEE.CreateTextObject());
+ const EditTextObject* pObj = m_pDoc->GetEditText(ScAddress(0,0,0));
+ CPPUNIT_ASSERT_MESSAGE("There should be an edit cell here.", pObj);
+
+ ScRange aRange(0,0,0,0,0,0);
+ bRes = m_pDoc->HasEditText(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There is an edit cell here.", bRes);
+
+ aRange.aStart.SetRow(1);
+ aRange.aEnd.SetRow(1);
+ bRes = m_pDoc->HasEditText(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+
+ aRange.aStart.SetRow(2);
+ aRange.aEnd.SetRow(4);
+ bRes = m_pDoc->HasEditText(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+
+ aRange.aStart.SetRow(0);
+ aRange.aEnd.SetRow(MAXROW);
+ bRes = m_pDoc->HasEditText(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn be an edit cell in specified range.", bRes);
+
+ m_pDoc->SetString(ScAddress(0,0,0), "Test");
+ m_pDoc->SetValue(ScAddress(0,2,0), 1.0);
+ ScRefCellValue aCell;
+ aCell.assign(*m_pDoc, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_MESSAGE("This should be a string cell.", aCell.meType == CELLTYPE_STRING);
+ aCell.assign(*m_pDoc, ScAddress(0,1,0));
+ CPPUNIT_ASSERT_MESSAGE("This should be an empty cell.", aCell.meType == CELLTYPE_NONE);
+ aCell.assign(*m_pDoc, ScAddress(0,2,0));
+ CPPUNIT_ASSERT_MESSAGE("This should be a numeric cell.", aCell.meType == CELLTYPE_VALUE);
+ aCell.assign(*m_pDoc, ScAddress(0,3,0));
+ CPPUNIT_ASSERT_MESSAGE("This should be an empty cell.", aCell.meType == CELLTYPE_NONE);
+
+ aRange.aStart.SetRow(1);
+ aRange.aEnd.SetRow(1);
+ bRes = m_pDoc->HasEditText(aRange);
+ CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", !bRes);
+
+ m_pDoc->DeleteTab(0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index eab25945fddc..bbd3ce2bf538 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3210,6 +3210,15 @@ void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr )
maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject());
}
+bool ScDocument::HasEditText( const ScRange& rRange ) const
+{
+ const ScTable* pTab = FetchTable(rRange.aStart.Tab());
+ if (!pTab)
+ return false;
+
+ return pTab->HasEditText(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
+}
+
void ScDocument::SetTextCell( const ScAddress& rPos, const OUString& rStr )
{
if (!TableExists(rPos.Tab()))
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d8cfbfe3efe5..af4587d0faa9 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1347,6 +1347,25 @@ void ScTable::SetEditText( SCCOL nCol, SCROW nRow, const EditTextObject& rEditTe
aCol[nCol].SetEditText(nRow, rEditText, pEditPool);
}
+bool ScTable::HasEditText( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
+{
+ if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol2 < nCol1)
+ return false;
+
+ if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow2 < nRow1)
+ return false;
+
+ SCROW nFirst = -1;
+ for (SCCOL i = nCol1; i <= nCol2; ++i)
+ {
+ const ScColumn& rCol = aCol[i];
+ if (const_cast<ScColumn&>(rCol).HasEditCells(nRow1, nRow2, nFirst))
+ return true;
+ }
+
+ return false;
+}
+
void ScTable::SetEmptyCell( SCCOL nCol, SCROW nRow )
{
if (!ValidColRow(nCol, nRow))