[Libreoffice-commits] core.git: 2 commits - sc/CppunitTest_sc_ucalc.mk sc/inc sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Mon Feb 3 08:44:35 PST 2014


 sc/CppunitTest_sc_ucalc.mk       |    1 
 sc/inc/document.hxx              |    2 +
 sc/inc/table.hxx                 |    1 
 sc/qa/unit/ucalc.hxx             |    4 ++
 sc/qa/unit/ucalc_column.cxx      |   70 +++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/document.cxx |    9 +++++
 sc/source/core/data/table2.cxx   |   19 ++++++++++
 7 files changed, 106 insertions(+)

New commits:
commit fc5eefc903529d1c3548c680b3077eee4e2c7a73
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Feb 3 11:47:10 2014 -0500

    Add test code to exercise ScColumn::HasEditCells().
    
    Change-Id: Ibacf3585a6d15d541a50cb7bb50905d34a7d598b

diff --git a/sc/CppunitTest_sc_ucalc.mk b/sc/CppunitTest_sc_ucalc.mk
index 20001e5..c4d48d8 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 972a96c..6ffcc69 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 22720e7..2b38473 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 84f5470..48234e5 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 0000000..0959ee1
--- /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 eab2594..bbd3ce2 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 d8cfbfe..af4587d 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))
commit e753233e2e8af04048a17c7163ff5d9d3ffbbf3d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Feb 3 10:29:41 2014 -0500

    This test was not being run.  Let's run it.
    
    Change-Id: If79d82cca3b2a854dddda2995b737afd8c5dc328

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 005e0c5..84f5470 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -409,6 +409,7 @@ public:
     CPPUNIT_TEST(testSharedFormulasCopyPaste);
     CPPUNIT_TEST(testSharedFormulaInsertColumn);
     CPPUNIT_TEST(testFormulaPosition);
+    CPPUNIT_TEST(testMixData);
     CPPUNIT_TEST(testJumpToPrecedentsDependents);
     CPPUNIT_TEST(testSetBackgroundColor);
     CPPUNIT_TEST(testRenameTable);


More information about the Libreoffice-commits mailing list