From f20dac7df4bab6fe5954c330880ebb4512b5d2c0 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 8 Aug 2014 11:29:05 -0400 Subject: bnc#885548: Write test for this. Change-Id: Ifbd4502a5e49dfbb60301b935291ed0ce65da706 --- sc/inc/scmod.hxx | 2 +- sc/qa/unit/subsequent_export-test.cxx | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) (limited to 'sc') diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx index 1e68839bc401..df6bbfe1a6f2 100644 --- a/sc/inc/scmod.hxx +++ b/sc/inc/scmod.hxx @@ -198,7 +198,7 @@ SC_DLLPUBLIC void SetAppOptions ( const ScAppOptions& rO svtools::ColorConfig& GetColorConfig(); SvtAccessibilityOptions& GetAccessOptions(); SvtCTLOptions& GetCTLOptions(); - SvtUserOptions& GetUserOptions(); + SC_DLLPUBLIC SvtUserOptions& GetUserOptions(); void ModifyOptions( const SfxItemSet& rOptSet ); diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index d1e1842d2ed8..0be4d5e2f2d8 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -32,6 +32,7 @@ #include "editutil.hxx" #include "scopetools.hxx" #include "cellvalue.hxx" +#include "docfunc.hxx" #include #include #include @@ -49,6 +50,8 @@ #include #include #include +#include +#include #include @@ -1481,8 +1484,64 @@ void ScExportTest::testTrackChangesSimpleXLSX() return true; } + bool checkRevisionUserAndTime( ScDocument& rDoc, const OUString& rOwnerName ) + { + ScChangeTrack* pCT = rDoc.GetChangeTrack(); + if (!pCT) + { + cerr << "Change track instance doesn't exist." << endl; + return false; + } + + ScChangeAction* pAction = pCT->GetLast(); + if (pAction->GetUser() != "Kohei Yoshida") + { + cerr << "Wrong user name." << endl; + return false; + } + + DateTime aDT = pAction->GetDateTimeUTC(); + if (aDT.GetYear() != 2014 || aDT.GetMonth() != 7 || aDT.GetDay() != 11) + { + cerr << "Wrong time stamp." << endl; + return false; + } + + // Insert a new record to make sure the user and date-time are correct. + rDoc.SetString(ScAddress(1,8,0), "New String"); + ScCellValue aEmpty; + pCT->AppendContent(ScAddress(1,8,0), aEmpty); + pAction = pCT->GetLast(); + if (!pAction) + { + cerr << "Failed to retrieve last revision." << endl; + return false; + } + + if (rOwnerName != pAction->GetUser()) + { + cerr << "Wrong user name." << endl; + return false; + } + + DateTime aDTNew = pAction->GetDateTimeUTC(); + if (aDTNew <= aDT) + { + cerr << "Time stamp of the new revision should be more recent than that of the last revision." << endl; + return false; + } + + return true; + } + } aTest; + SvtUserOptions& rUserOpt = SC_MOD()->GetUserOptions(); + rUserOpt.SetToken(USER_OPT_FIRSTNAME, "Export"); + rUserOpt.SetToken(USER_OPT_LASTNAME, "Test"); + + OUString aOwnerName = rUserOpt.GetFirstName() + " " + rUserOpt.GetLastName(); + // First, test the xls variant. ScDocShellRef xDocSh = loadDoc("track-changes/simple-cell-changes.", XLS); @@ -1506,6 +1565,9 @@ void ScExportTest::testTrackChangesSimpleXLSX() pAction->GetDescription(aDesc, pDoc); CPPUNIT_ASSERT_EQUAL(OUString("Cell B2 changed from '' to '1'"), aDesc); + bGood = aTest.checkRevisionUserAndTime(*pDoc, aOwnerName); + CPPUNIT_ASSERT_MESSAGE("Check revision and time failed after reload (xls).", bGood); + xDocSh2->DoClose(); // Now, test the xlsx variant the same way. @@ -1522,6 +1584,9 @@ void ScExportTest::testTrackChangesSimpleXLSX() bGood = aTest.check(*pDoc); CPPUNIT_ASSERT_MESSAGE("Check after reload failed (xlsx).", bGood); + bGood = aTest.checkRevisionUserAndTime(*pDoc, aOwnerName); + CPPUNIT_ASSERT_MESSAGE("Check revision and time failed after reload (xlsx).", bGood); + xDocSh2->DoClose(); } -- cgit