Kaydet (Commit) b5fb5951 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

change the solver test to explicitly test the available solvers

This changes the lpsolver test to explicitly test the available
linear solvers we have - either CoinMP, LpSolver or both. This
prevents that a newly added solver will be automatically tested
as it can have a different behaviour for the tested input values.

Change-Id: I0c4d2f9c561d1e834ca51196b7b5ecf7d89ba550
Reviewed-on: https://gerrit.libreoffice.org/34813Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst f31477bb
......@@ -26,15 +26,18 @@ class LpSolverTest: public test::BootstrapFixture
{
uno::Reference<sheet::XSpreadsheetDocument> m_xDocument;
void test();
void testSolver(const uno::Reference<sheet::XSolver>& xSolver);
void testLpSolver();
void testCoinMPSolver();
void testSolver(OUString const & rName);
public:
virtual void setUp() override;
virtual void tearDown() override;
CPPUNIT_TEST_SUITE(LpSolverTest);
CPPUNIT_TEST(test);
CPPUNIT_TEST(testLpSolver);
CPPUNIT_TEST(testCoinMPSolver);
CPPUNIT_TEST_SUITE_END();
};
......@@ -54,44 +57,25 @@ void LpSolverTest::tearDown()
test::BootstrapFixture::tearDown();
}
void LpSolverTest::test()
void LpSolverTest::testLpSolver()
{
uno::Reference<container::XContentEnumerationAccess> xEnAc(
m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
uno::Reference<container::XEnumeration> xEnum = xEnAc->
createContentEnumeration( "com.sun.star.sheet.Solver" );
CPPUNIT_ASSERT(xEnum.is());
sal_Int32 nCount = 0;
while (xEnum->hasMoreElements())
{
uno::Reference<uno::XInterface> xIntFac;
xEnum->nextElement() >>= xIntFac;
CPPUNIT_ASSERT(xIntFac.is());
uno::Reference<lang::XServiceInfo> xInfo(xIntFac, uno::UNO_QUERY_THROW);
const OUString sName(xInfo->getImplementationName());
uno::Reference<sheet::XSolver> xSolver(m_xContext->getServiceManager()->
createInstanceWithContext(sName, m_xContext), uno::UNO_QUERY_THROW);
testSolver(xSolver);
uno::Reference<sheet::XSolverDescription> xDesc(xSolver, uno::UNO_QUERY_THROW);
const OString sMessage("Empty description for " +
OUStringToOString(sName, RTL_TEXTENCODING_UTF8));
CPPUNIT_ASSERT_MESSAGE(sMessage.getStr(), !xDesc->getComponentDescription().isEmpty());
++nCount;
}
sal_Int32 nExpected = 0;
#ifdef ENABLE_COINMP
++nExpected;
#endif
#ifdef ENABLE_LPSOLVE
++nExpected;
testSolver("com.sun.star.comp.Calc.LpsolveSolver");
#endif
}
void LpSolverTest::testCoinMPSolver()
{
#ifdef ENABLE_COINMP
testSolver("com.sun.star.comp.Calc.CoinMPSolver");
#endif
CPPUNIT_ASSERT_EQUAL(nExpected, nCount);
}
void LpSolverTest::testSolver(const uno::Reference<sheet::XSolver>& xSolver)
void LpSolverTest::testSolver(OUString const & rName)
{
uno::Reference<sheet::XSolver> xSolver(m_xContext->getServiceManager()->
createInstanceWithContext(rName, m_xContext), uno::UNO_QUERY_THROW);
table::CellAddress aObjective(0, 0, 0);
// "changing cells" - unknown variables
......@@ -117,6 +101,10 @@ void LpSolverTest::testSolver(const uno::Reference<sheet::XSolver>& xSolver)
uno::Sequence<double> aSolution = xSolver->getSolution();
CPPUNIT_ASSERT_EQUAL(aSolution.getLength(), aVariables.getLength());
CPPUNIT_ASSERT_EQUAL(aSolution[0], (double)5.0);
uno::Reference<sheet::XSolverDescription> xDesc(xSolver, uno::UNO_QUERY_THROW);
const OString sMessage("Empty description for " + OUStringToOString(rName, RTL_TEXTENCODING_UTF8));
CPPUNIT_ASSERT_MESSAGE(sMessage.getStr(), !xDesc->getComponentDescription().isEmpty());
}
CPPUNIT_TEST_SUITE_REGISTRATION(LpSolverTest);
......
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