2015-09-09 15:08:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/frame/XComponentLoader.hpp>
|
|
|
|
|
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <sfx2/objsh.hxx>
|
2015-09-14 15:43:17 +02:00
|
|
|
#include <sfx2/lokhelper.hxx>
|
2015-09-09 15:08:26 +03:00
|
|
|
#include <test/unoapi_test.hxx>
|
|
|
|
|
|
|
|
#include "../../inc/lib/init.hxx"
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
using namespace desktop;
|
|
|
|
|
|
|
|
class DesktopLOKTest : public UnoApiTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DesktopLOKTest() : UnoApiTest("/desktop/qa/data/")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DesktopLOKTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setUp() SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
UnoApiTest::setUp();
|
|
|
|
mxDesktop.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void tearDown() SAL_OVERRIDE
|
|
|
|
{
|
|
|
|
closeDoc();
|
|
|
|
UnoApiTest::tearDown();
|
|
|
|
};
|
|
|
|
|
|
|
|
LibLODocument_Impl* loadDoc(const char* pName);
|
|
|
|
void closeDoc();
|
|
|
|
|
|
|
|
void testGetStyles();
|
2015-09-10 11:31:48 +03:00
|
|
|
void testGetFonts();
|
2015-09-14 15:43:17 +02:00
|
|
|
void testCreateView();
|
2015-09-09 15:08:26 +03:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DesktopLOKTest);
|
2015-09-14 15:56:34 +02:00
|
|
|
CPPUNIT_TEST(testGetStyles);
|
|
|
|
CPPUNIT_TEST(testGetFonts);
|
|
|
|
CPPUNIT_TEST(testCreateView);
|
2015-09-09 15:08:26 +03:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
uno::Reference<lang::XComponent> mxComponent;
|
|
|
|
};
|
|
|
|
|
|
|
|
LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName)
|
|
|
|
{
|
|
|
|
OUString aFileURL;
|
|
|
|
createFileURL(OUString::createFromAscii(pName), aFileURL);
|
|
|
|
mxComponent = loadFromDesktop(aFileURL, "com.sun.star.text.TextDocument");
|
|
|
|
if (!mxComponent.is())
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(false);
|
|
|
|
}
|
|
|
|
return new LibLODocument_Impl(mxComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopLOKTest::closeDoc()
|
|
|
|
{
|
|
|
|
if (mxComponent.is())
|
|
|
|
{
|
|
|
|
closeDocument(mxComponent);
|
|
|
|
mxComponent.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopLOKTest::testGetStyles()
|
|
|
|
{
|
|
|
|
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
|
|
|
|
boost::property_tree::ptree aTree;
|
2015-09-10 09:21:45 +03:00
|
|
|
char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:StyleApply");
|
2015-09-09 15:08:26 +03:00
|
|
|
std::stringstream aStream(pJSON);
|
|
|
|
boost::property_tree::read_json(aStream, aTree);
|
|
|
|
CPPUNIT_ASSERT( aTree.size() > 0 );
|
2015-09-10 09:21:45 +03:00
|
|
|
CPPUNIT_ASSERT( aTree.get_child("commandName").get_value<std::string>() == ".uno:StyleApply" );
|
2015-09-09 15:08:26 +03:00
|
|
|
|
2015-09-10 09:21:45 +03:00
|
|
|
boost::property_tree::ptree aValues = aTree.get_child("commandValues");
|
|
|
|
CPPUNIT_ASSERT( aValues.size() > 0 );
|
|
|
|
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
|
2015-09-09 15:08:26 +03:00
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT( rPair.second.size() > 0);
|
|
|
|
if (rPair.first != "CharacterStyles" &&
|
|
|
|
rPair.first != "ParagraphStyles" &&
|
|
|
|
rPair.first != "FrameStyles" &&
|
|
|
|
rPair.first != "PageStyles" &&
|
|
|
|
rPair.first != "NumberingStyles" &&
|
|
|
|
rPair.first != "CellStyles" &&
|
|
|
|
rPair.first != "ShapeStyles")
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL("Unknown style family: " + rPair.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closeDoc();
|
|
|
|
}
|
|
|
|
|
2015-09-10 11:31:48 +03:00
|
|
|
void DesktopLOKTest::testGetFonts()
|
|
|
|
{
|
|
|
|
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
|
|
|
|
boost::property_tree::ptree aTree;
|
|
|
|
char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:CharFontName");
|
|
|
|
std::stringstream aStream(pJSON);
|
|
|
|
boost::property_tree::read_json(aStream, aTree);
|
|
|
|
CPPUNIT_ASSERT( aTree.size() > 0 );
|
|
|
|
CPPUNIT_ASSERT( aTree.get_child("commandName").get_value<std::string>() == ".uno:CharFontName" );
|
|
|
|
|
|
|
|
boost::property_tree::ptree aValues = aTree.get_child("commandValues");
|
|
|
|
CPPUNIT_ASSERT( aValues.size() > 0 );
|
|
|
|
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aValues)
|
|
|
|
{
|
|
|
|
// check that we have font sizes available for each font
|
|
|
|
CPPUNIT_ASSERT( rPair.second.size() > 0);
|
|
|
|
}
|
|
|
|
closeDoc();
|
|
|
|
}
|
|
|
|
|
2015-09-14 15:43:17 +02:00
|
|
|
void DesktopLOKTest::testCreateView()
|
|
|
|
{
|
|
|
|
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
|
|
|
|
|
2015-09-15 09:31:49 +02:00
|
|
|
int nId = pDocument->m_pDocumentClass->createView(pDocument);
|
2015-09-14 15:43:17 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
|
2015-09-15 09:31:49 +02:00
|
|
|
|
|
|
|
pDocument->m_pDocumentClass->destroyView(pDocument, nId);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
|
2015-09-14 15:43:17 +02:00
|
|
|
closeDoc();
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|