Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
96aecd7f
Kaydet (Commit)
96aecd7f
authored
Tem 27, 2015
tarafından
Eike Rathke
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
TableRef: add unit tests
Change-Id: Ic635188f9ebefcfd49f71c3d61405e5f4765d940
üst
e2281331
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
0 deletions
+128
-0
ucalc.hxx
sc/qa/unit/ucalc.hxx
+2
-0
ucalc_formula.cxx
sc/qa/unit/ucalc_formula.cxx
+126
-0
No files found.
sc/qa/unit/ucalc.hxx
Dosyayı görüntüle @
96aecd7f
...
...
@@ -182,6 +182,7 @@ public:
void
testMatrixOp
();
void
testFuncRangeOp
();
void
testFuncFORMULA
();
void
testFuncTableRef
();
void
testExternalRef
();
void
testExternalRefFunctions
();
...
...
@@ -510,6 +511,7 @@ public:
CPPUNIT_TEST
(
testMatrixOp
);
CPPUNIT_TEST
(
testFuncRangeOp
);
CPPUNIT_TEST
(
testFuncFORMULA
);
CPPUNIT_TEST
(
testFuncTableRef
);
CPPUNIT_TEST
(
testExternalRef
);
CPPUNIT_TEST
(
testExternalRefFunctions
);
CPPUNIT_TEST
(
testCopyToDocument
);
...
...
sc/qa/unit/ucalc_formula.cxx
Dosyayı görüntüle @
96aecd7f
...
...
@@ -5366,4 +5366,130 @@ void Test::testFuncFORMULA()
m_pDoc->DeleteTab(0);
}
void Test::testFuncTableRef()
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
m_pDoc->InsertTab(0, "Sheet1");
{
ScDBCollection* pDBs = m_pDoc->GetDBCollection();
CPPUNIT_ASSERT_MESSAGE("Failed to fetch DB collection object.", pDBs);
// Insert "table" database range definition for A1:B4, with default
// HasHeader=true and HasTotals=false.
ScDBData* pData = new ScDBData( "table", 0,0,0, 1,3);
bool bInserted = pDBs->getNamedDBs().insert(pData);
CPPUNIT_ASSERT_MESSAGE( "Failed to insert \"table\" database range.", bInserted);
}
{
// Populate "table" database range with headers and data in A1:B4
const char* aData[][2] = {
{ "Header1", "Header2" },
{ "1", "2" },
{ "4", "8" },
{ "16", "32" }
};
ScAddress aPos(0,0,0);
ScRange aRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
CPPUNIT_ASSERT(aRange.aStart == aPos);
}
// Named expressions that use Table structured references.
/* TODO: should the item/header separator really be equal to the parameter
* separator, thus be locale dependent and ';' semicolon here, or should it
* be a fixed ',' comma instead? */
struct {
const char* pName;
const char* pExpr;
const char* pCounta; // expected result when used in row 2 (first data row) as argument to COUNTA()
const char* pSum3; // expected result when used in row 3 (second data row) as argument to SUM().
const char* pSum4; // expected result when used in row 4 (third data row) as argument to SUM().
const char* pSumX; // expected result when used in row 5 (non-intersecting) as argument to SUM().
} aNames[] = {
{ "all", "table[[#All]]", "8", "63", "63", "63" },
{ "data_implicit", "table[]", "6", "63", "63", "63" },
{ "data", "table[[#Data]]", "6", "63", "63", "63" },
{ "headers", "table[[#Headers]]", "2", "0", "0", "0" },
{ "header1", "table[[Header1]]", "3", "21", "21", "21" },
{ "header2", "table[[Header2]]", "3", "42", "42", "42" },
{ "data_header1", "table[[#Data];[Header1]]", "3", "21", "21", "21" },
{ "data_header2", "table[[#Data];[Header2]]", "3", "42", "42", "42" },
{ "this_row", "table[[#This Row]]", "2", "12", "48", "#VALUE!" },
{ "this_row_header1", "table[[#This Row];[Header1]]", "1", "4", "16", "#VALUE!" },
{ "this_row_header2", "table[[#This Row];[Header2]]", "1", "8", "32", "#VALUE!" },
{ "this_row_range_header_1_to_2", "table[[#This Row];[Header1]:[Header2]]", "2", "12", "48", "#VALUE!" }
};
{
// Insert named expressions.
ScRangeName* pGlobalNames = m_pDoc->GetRangeName();
CPPUNIT_ASSERT_MESSAGE("Failed to obtain global named expression object.", pGlobalNames);
for (size_t i = 0, n = SAL_N_ELEMENTS(aNames); i < n; ++i)
{
// Choose base position that does not intersect with the database
// range definition to test later use of [#This Row] results in
// proper rows.
ScRangeData* pName = new ScRangeData(
m_pDoc, OUString::createFromAscii(aNames[i].pName), OUString::createFromAscii(aNames[i].pExpr),
ScAddress(2,4,0), RT_NAME, formula::FormulaGrammar::GRAM_NATIVE);
bool bInserted = pGlobalNames->insert(pName);
CPPUNIT_ASSERT_MESSAGE(
OString("Failed to insert named expression "+ OString(aNames[i].pName) +".").getStr(), bInserted);
}
}
// Use the named expressions in COUNTA() formulas, on row 2 that intersects.
for (size_t i = 0, n = SAL_N_ELEMENTS(aNames); i < n; ++i)
{
OUString aFormula( "=COUNTA(" + OUString::createFromAscii( aNames[i].pName) + ")");
ScAddress aPos(3+i,1,0);
m_pDoc->SetString( aPos, aFormula);
// For easier "debugability" have position and formula in assertion.
OUString aPrefix( aPos.Format(SCA_VALID) + " " + aFormula + " : ");
CPPUNIT_ASSERT_EQUAL( aPrefix + OUString::createFromAscii( aNames[i].pCounta),
aPrefix + m_pDoc->GetString( aPos));
}
// Use the named expressions in SUM() formulas, on row 3 that intersects.
for (size_t i = 0, n = SAL_N_ELEMENTS(aNames); i < n; ++i)
{
OUString aFormula( "=SUM(" + OUString::createFromAscii( aNames[i].pName) + ")");
ScAddress aPos(3+i,2,0);
m_pDoc->SetString( aPos, aFormula);
// For easier "debugability" have position and formula in assertion.
OUString aPrefix( aPos.Format(SCA_VALID) + " " + aFormula + " : ");
CPPUNIT_ASSERT_EQUAL( aPrefix + OUString::createFromAscii( aNames[i].pSum3),
aPrefix + m_pDoc->GetString( aPos));
}
// Use the named expressions in SUM() formulas, on row 4 that intersects.
for (size_t i = 0, n = SAL_N_ELEMENTS(aNames); i < n; ++i)
{
OUString aFormula( "=SUM(" + OUString::createFromAscii( aNames[i].pName) + ")");
ScAddress aPos(3+i,3,0);
m_pDoc->SetString( aPos, aFormula);
// For easier "debugability" have position and formula in assertion.
OUString aPrefix( aPos.Format(SCA_VALID) + " " + aFormula + " : ");
CPPUNIT_ASSERT_EQUAL( aPrefix + OUString::createFromAscii( aNames[i].pSum4),
aPrefix + m_pDoc->GetString( aPos));
}
// Use the named expressions in SUM() formulas, on row 5 that does not intersect.
for (size_t i = 0, n = SAL_N_ELEMENTS(aNames); i < n; ++i)
{
OUString aFormula( "=SUM(" + OUString::createFromAscii( aNames[i].pName) + ")");
ScAddress aPos(3+i,4,0);
m_pDoc->SetString( aPos, aFormula);
// For easier "debugability" have position and formula in assertion.
OUString aPrefix( aPos.Format(SCA_VALID) + " " + aFormula + " : ");
CPPUNIT_ASSERT_EQUAL( aPrefix + OUString::createFromAscii( aNames[i].pSumX),
aPrefix + m_pDoc->GetString( aPos));
}
m_pDoc->DeleteTab(0);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment