diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-01-19 17:28:43 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-01-19 19:04:23 -0500 |
commit | 0f947f73a0e815182c5b652ea639bd0e6e7750ea (patch) | |
tree | eb4cf5872cc7e45ff339170cd5be0842f9698d69 /sc/qa | |
parent | 71b9ef7c10c19d79628c2e860f82f66a736b7342 (diff) |
Check the content of datapilot table output during the unit test run.
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 85 |
1 files changed, 74 insertions, 11 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 6fbac67729ff..7e9556a5104d 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -83,6 +83,8 @@ #define MDDS_HASH_CONTAINER_STLPORT 1 #include <mdds/mixed_type_matrix.hpp> +#define UCALC_DEBUG_OUTPUT 0 + using namespace ::com::sun::star; using ::rtl::OUString; using ::rtl::OUStringBuffer; @@ -113,8 +115,12 @@ public: maMatrix.set_string(row, col, new OUString(aStr)); } - void print() +#if UCALC_DEBUG_OUTPUT + void print(const char* header) const { + if (header) + cout << header << endl; + MatrixType::size_pair_type ns = maMatrix.size(); vector<sal_Int32> aColWidths(ns.second, 0); @@ -135,7 +141,7 @@ public: for (size_t col = 0; col < ns.second; ++col) { aBuf.appendAscii("-"); - for (size_t i = 0; i < aColWidths[col]; ++i) + for (sal_Int32 i = 0; i < aColWidths[col]; ++i) aBuf.append(sal_Unicode('-')); aBuf.appendAscii("-+"); } @@ -160,6 +166,38 @@ public: cout << aSep << endl; } } +#else + void print(const char*) const {} +#endif + + /** + * Print nested string array which can be copy-n-pasted into the test code + * for content verification. + */ + void printArray() const + { +#if UCALC_DEBUG_OUTPUT + MatrixType::size_pair_type ns = maMatrix.size(); + for (size_t row = 0; row < ns.first; ++row) + { + cout << " { "; + for (size_t col = 0; col < ns.second; ++col) + { + const OUString* p = maMatrix.get_string(row, col); + if (p->getLength()) + cout << "\"" << *p << "\""; + else + cout << "0"; + if (col < ns.second - 1) + cout << ", "; + } + cout << " }"; + if (row < ns.first - 1) + cout << ","; + cout << endl; + } +#endif + } void clear() { maMatrix.clear(); } void resize(size_t rows, size_t cols) { maMatrix.resize(rows, cols); } @@ -461,6 +499,7 @@ void Test::testDataPilot() m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("Data"))); m_pDoc->InsertTab(1, OUString(RTL_CONSTASCII_USTRINGPARAM("Table"))); + // Dimension definition struct { const char* pName; sheet::DataPilotFieldOrientation eOrient; } aFields[] = { @@ -469,6 +508,7 @@ void Test::testDataPilot() { "Score", sheet::DataPilotFieldOrientation_DATA } }; + // Raw data struct { const char* pName; const char* pGroup; int nScore; } aData[] = { @@ -480,6 +520,19 @@ void Test::testDataPilot() { "Frank", "C", 15 }, }; + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][5] = { + { "Sum - Score", "Group", 0, 0, 0 }, + { "Name", "A", "B", "C", "Total Result" }, + { "Andy", "30", 0, 0, "30" }, + { "Bruce", "20", 0, 0, "20" }, + { "Charlie", 0, "45", 0, "45" }, + { "David", 0, "12", 0, "12" }, + { "Edward", 0, 0, "8", "8" }, + { "Frank", 0, 0, "15", "15" }, + { "Total Result", "50", "57", "23", "130" } + }; + sal_uInt32 nFieldCount = SAL_N_ELEMENTS(aFields); sal_uInt32 nDataCount = SAL_N_ELEMENTS(aData); @@ -503,7 +556,6 @@ void Test::testDataPilot() CPPUNIT_ASSERT_MESSAGE("Unexpected data range.", nCol2 == static_cast<SCCOL>(nFieldCount - 1) && nRow2 == static_cast<SCROW>(nDataCount)); -#if 0 SheetPrinter printer(nRow2 - nRow1 + 1, nCol2 - nCol1 + 1); for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow) { @@ -514,9 +566,8 @@ void Test::testDataPilot() printer.set(nRow, nCol, aVal); } } - printer.print(); + printer.print("Data sheet content"); printer.clear(); -#endif ScSheetSourceDesc aSheetDesc; aSheetDesc.aSourceRange = ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0); @@ -613,23 +664,35 @@ void Test::testDataPilot() CPPUNIT_ASSERT_MESSAGE("Table overflow!?", !bOverFlow); pDPObj->Output(aOutRange.aStart); -#if 0 aOutRange = pDPObj->GetOutRange(); const ScAddress& s = aOutRange.aStart; const ScAddress& e = aOutRange.aEnd; printer.resize(e.Row() - s.Row() + 1, e.Col() - s.Col() + 1); - for (SCROW nRow = s.Row(); nRow <= e.Row(); ++nRow) + SCROW nOutRowSize = SAL_N_ELEMENTS(aOutputCheck); + SCCOL nOutColSize = SAL_N_ELEMENTS(aOutputCheck[0]); + CPPUNIT_ASSERT_MESSAGE("Row size of the table output is not as expected.", + nOutRowSize == (e.Row()-s.Row()+1)); + CPPUNIT_ASSERT_MESSAGE("Column size of the table output is not as expected.", + nOutColSize == (e.Col()-s.Col()+1)); + for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow) { - for (SCCOL nCol = s.Col(); nCol <= e.Col(); ++nCol) + for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol) { String aVal; - m_pDoc->GetString(nCol, nRow, s.Tab(), aVal); + m_pDoc->GetString(nCol + s.Col(), nRow + s.Row(), s.Tab(), aVal); printer.set(nRow, nCol, aVal); + const char* p = aOutputCheck[nRow][nCol]; + if (p) + { + OUString aCheckVal = OUString::createFromAscii(p); + CPPUNIT_ASSERT_MESSAGE("Unexpected cell content.", aCheckVal.equals(aVal)); + } + else + CPPUNIT_ASSERT_MESSAGE("Empty cell expected.", aVal.Len() == 0); } } - printer.print(); + printer.print("DataPilot table output"); printer.clear(); -#endif // Now, delete the datapilot object. pDPs->FreeTable(pDPObj); |