1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* -*- 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 <test/unoapi_test.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objsh.hxx>
#include <utility>
using namespace css;
using namespace css::uno;
UnoApiTest::UnoApiTest(OUString path)
: mbSkipValidation(false)
, m_aBaseString(std::move(path))
{
}
void UnoApiTest::setUp()
{
test::BootstrapFixture::setUp();
mxDesktop
= css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()));
CPPUNIT_ASSERT_MESSAGE("no desktop!", mxDesktop.is());
SfxApplication::GetOrCreate();
}
void UnoApiTest::tearDown()
{
if (mxComponent.is())
{
mxComponent->dispose();
mxComponent.clear();
}
test::BootstrapFixture::tearDown();
}
OUString UnoApiTest::createFileURL(std::u16string_view aFileBase)
{
return m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase;
}
OUString UnoApiTest::loadFromURL(std::u16string_view aFileBase)
{
OUString aFileName = createFileURL(aFileBase);
mxComponent = loadFromDesktop(aFileName);
return aFileName;
}
uno::Any UnoApiTest::executeMacro(const OUString& rScriptURL,
const uno::Sequence<uno::Any>& rParams)
{
uno::Any aRet;
uno::Sequence<sal_Int16> aOutParamIndex;
uno::Sequence<uno::Any> aOutParam;
ErrCode result = SfxObjectShell::CallXScript(mxComponent, rScriptURL, rParams, aRet,
aOutParamIndex, aOutParam);
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, result);
return aRet;
}
utl::TempFileNamed UnoApiTest::save(const OUString& rFilter)
{
utl::TempFileNamed aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence aArgs{ comphelper::makePropertyValue("FilterName", rFilter) };
css::uno::Reference<frame::XStorable> xStorable(mxComponent, css::uno::UNO_QUERY_THROW);
xStorable->storeToURL(aTempFile.GetURL(), aArgs);
mxComponent->dispose();
mxComponent.clear();
if (!mbSkipValidation)
{
if (rFilter == "Office Open XML Text")
validate(aTempFile.GetFileName(), test::OOXML);
else if (rFilter == "Calc Office Open XML")
validate(aTempFile.GetFileName(), test::OOXML);
else if (rFilter == "Impress Office Open XML")
validate(aTempFile.GetFileName(), test::OOXML);
else if (rFilter == "writer8")
validate(aTempFile.GetFileName(), test::ODF);
else if (rFilter == "calc8")
validate(aTempFile.GetFileName(), test::ODF);
else if (rFilter == "impress8")
validate(aTempFile.GetFileName(), test::ODF);
else if (rFilter == "draw8")
validate(aTempFile.GetFileName(), test::ODF);
else if (rFilter == "OpenDocument Text Flat XML")
validate(aTempFile.GetFileName(), test::ODF);
else if (rFilter == "MS Word 97")
validate(aTempFile.GetFileName(), test::MSBINARY);
else if (rFilter == "MS Excel 97")
validate(aTempFile.GetFileName(), test::MSBINARY);
else if (rFilter == "MS PowerPoint 97")
validate(aTempFile.GetFileName(), test::MSBINARY);
}
return aTempFile;
}
void UnoApiTest::saveAndReload(const OUString& rFilter)
{
utl::TempFileNamed aTempFile = save(rFilter);
mxComponent = loadFromDesktop(aTempFile.GetURL());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|