Kaydet (Commit) 7476ad63 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

First (?) performance regression unit test against clearing of a sheet.

I screwed this up earlier which made this operation take almost 50 seconds
to complete. It should finish in 0.00001 seconds or less.  The test checks
against 1 second, which should be enough of a buffer for slower machines.

Change-Id: I9923033045111c75a0740b6bb30a518fe93e01d2
üst 0fb3bfca
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/time.h>
#include "scdll.hxx" #include "scdll.hxx"
#include "formulacell.hxx" #include "formulacell.hxx"
...@@ -91,6 +92,16 @@ using ::std::vector; ...@@ -91,6 +92,16 @@ using ::std::vector;
namespace { namespace {
double getTimeDiff(const TimeValue& t1, const TimeValue& t2)
{
double tv1 = t1.Seconds;
double tv2 = t2.Seconds;
tv1 += t1.Nanosec / 1000000000.0;
tv2 += t2.Nanosec / 1000000000.0;
return tv1 - tv2;
}
class Test : public test::BootstrapFixture { class Test : public test::BootstrapFixture {
public: public:
Test(); Test();
...@@ -98,6 +109,12 @@ public: ...@@ -98,6 +109,12 @@ public:
virtual void setUp(); virtual void setUp();
virtual void tearDown(); virtual void tearDown();
/**
* Basic performance regression test. Pick some actions that *should* take
* only a fraction of a second to complete, and make sure they stay that
* way.
*/
void testPerf();
void testCollator(); void testCollator();
void testRangeList(); void testRangeList();
void testInput(); void testInput();
...@@ -265,6 +282,7 @@ public: ...@@ -265,6 +282,7 @@ public:
void testCondFormatINSDEL(); void testCondFormatINSDEL();
CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testPerf);
CPPUNIT_TEST(testCollator); CPPUNIT_TEST(testCollator);
CPPUNIT_TEST(testRangeList); CPPUNIT_TEST(testRangeList);
CPPUNIT_TEST(testInput); CPPUNIT_TEST(testInput);
...@@ -448,6 +466,29 @@ void Test::tearDown() ...@@ -448,6 +466,29 @@ void Test::tearDown()
BootstrapFixture::tearDown(); BootstrapFixture::tearDown();
} }
void Test::testPerf()
{
CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (0, "foo"));
TimeValue aTimeBefore, aTimeAfter;
// Clearing an already empty sheet should finish in a fraction of a
// second. Flag failure if it takes more than one second. Clearing 100
// columns should be large enough to flag if something goes wrong.
osl_getSystemTime(&aTimeBefore);
clearRange(m_pDoc, ScRange(0,0,0,99,MAXROW,0));
osl_getSystemTime(&aTimeAfter);
double diff = getTimeDiff(aTimeAfter, aTimeBefore);
if (diff >= 1.0)
{
std::ostringstream os;
os << "Clearing an empty sheet took " << diff << " seconds. It should be instant.";
CPPUNIT_FAIL(os.str().c_str());
}
m_pDoc->DeleteTab(0);
}
void Test::testCollator() void Test::testCollator()
{ {
OUString s1("A"); OUString s1("A");
...@@ -1732,6 +1773,17 @@ void Test::testCellBroadcaster() ...@@ -1732,6 +1773,17 @@ void Test::testCellBroadcaster()
CPPUNIT_ASSERT_MESSAGE("Deleted reference check in B3 failed.", CPPUNIT_ASSERT_MESSAGE("Deleted reference check in B3 failed.",
checkDeletedRefToken(*m_pDoc, ScAddress(1,2,0))); checkDeletedRefToken(*m_pDoc, ScAddress(1,2,0)));
// Clear everything again
clearRange(m_pDoc, ScRange(0,0,0,10,100,0));
m_pDoc->SetString(ScAddress(1,0,0), "=A1"); // B1 references A1.
m_pDoc->SetValue(ScAddress(0,0,0), 12.3);
CPPUNIT_ASSERT_EQUAL(12.3, m_pDoc->GetValue(ScAddress(1,0,0)));
// Clear the entire column A.
clearRange(m_pDoc, ScRange(0,0,0,0,MAXROW,0));
CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(1,0,0)));
m_pDoc->DeleteTab(0); m_pDoc->DeleteTab(0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment