From 8c72ab48bf150da05435d93991e1e9c9f47ce4fd Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sat, 12 Aug 2017 20:09:18 +0200 Subject: external data: add a test that shows that cropping to DB area works Change-Id: Ic883a5f625d54bf8cc95785a9ab1a83f0c8aa2ec --- sc/qa/unit/dataproviders_test.cxx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sc/qa/unit/dataproviders_test.cxx b/sc/qa/unit/dataproviders_test.cxx index 737362618845..11dd5f97c49e 100644 --- a/sc/qa/unit/dataproviders_test.cxx +++ b/sc/qa/unit/dataproviders_test.cxx @@ -29,9 +29,11 @@ public: virtual void tearDown() override; void testCSVImport(); + void testDataLargerThanDB(); CPPUNIT_TEST_SUITE(ScDataProvidersTest); CPPUNIT_TEST(testCSVImport); + CPPUNIT_TEST(testDataLargerThanDB); CPPUNIT_TEST_SUITE_END(); private: @@ -67,6 +69,34 @@ void ScDataProvidersTest::testCSVImport() CPPUNIT_ASSERT_EQUAL(OUString("test3"), m_pDoc->GetString(2, 1, 0)); } +void ScDataProvidersTest::testDataLargerThanDB() +{ + ScDBData* pDBData = new ScDBData("testDB", 0, 0, 0, 1, 1); + bool bInserted = m_pDoc->GetDBCollection()->getNamedDBs().insert(pDBData); + CPPUNIT_ASSERT(bInserted); + + OUString aFileURL; + createFileURL("test1.", "csv", aFileURL); + sc::ExternalDataSource aDataSource(aFileURL, "org.libreoffice.calc.csv", m_pDoc); + aDataSource.setDBData(pDBData); + + + m_pDoc->GetExternalDataMapper().insertDataSource(aDataSource); + auto& rDataSources = m_pDoc->GetExternalDataMapper().getDataSources(); + CPPUNIT_ASSERT(!rDataSources.empty()); + + rDataSources[0].refresh(m_pDoc, true); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(0, 0, 0)); + CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(1, 0, 0)); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 0, 0)); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(3, 0, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("test1"), m_pDoc->GetString(0, 1, 0)); + CPPUNIT_ASSERT_EQUAL(OUString("test2"), m_pDoc->GetString(1, 1, 0)); + CPPUNIT_ASSERT_EQUAL(OUString(), m_pDoc->GetString(2, 1, 0)); +} + ScDataProvidersTest::ScDataProvidersTest() : ScBootstrapFixture( "/sc/qa/unit/data/dataprovider" ), m_pDoc(nullptr) -- cgit