Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
e60a60f5
Kaydet (Commit)
e60a60f5
authored
Ara 02, 2016
tarafından
David Tardon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
refactor
Change-Id: I0cc034e7521de7911a9f5dfe8bc405971d175754
üst
675a74d5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
430 additions
and
218 deletions
+430
-218
StaticLibrary_writerperfect_filtertestbase.mk
writerperfect/StaticLibrary_writerperfect_filtertestbase.mk
+2
-0
WpftFilterFixture.cxx
writerperfect/qa/unit/WpftFilterFixture.cxx
+47
-0
WpftFilterFixture.hxx
writerperfect/qa/unit/WpftFilterFixture.hxx
+82
-0
WpftFilterTestBase.cxx
writerperfect/qa/unit/WpftFilterTestBase.cxx
+6
-169
WpftFilterTestBase.hxx
writerperfect/qa/unit/WpftFilterTestBase.hxx
+2
-49
WpftLoader.cxx
writerperfect/qa/unit/WpftLoader.cxx
+194
-0
WpftLoader.hxx
writerperfect/qa/unit/WpftLoader.hxx
+97
-0
No files found.
writerperfect/StaticLibrary_writerperfect_filtertestbase.mk
Dosyayı görüntüle @
e60a60f5
...
...
@@ -29,7 +29,9 @@ $(eval $(call gb_StaticLibrary_use_libraries,writerperfect_filtertestbase,\
))
$(eval $(call gb_StaticLibrary_add_exception_objects,writerperfect_filtertestbase,\
writerperfect/qa/unit/WpftFilterFixture \
writerperfect/qa/unit/WpftFilterTestBase \
writerperfect/qa/unit/WpftLoader \
))
# vim: set noet sw=4 ts=4:
writerperfect/qa/unit/WpftFilterFixture.cxx
0 → 100644
Dosyayı görüntüle @
e60a60f5
/* -*- 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 "WpftFilterFixture.hxx"
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>
#include <com/sun/star/frame/theDesktop.hpp>
namespace
document
=
com
::
sun
::
star
::
document
;
namespace
frame
=
com
::
sun
::
star
::
frame
;
namespace
uno
=
com
::
sun
::
star
::
uno
;
namespace
writerperfect
{
namespace
test
{
void
WpftFilterFixture
::
setUp
()
{
::
test
::
BootstrapFixture
::
setUp
();
m_xDesktop
=
frame
::
theDesktop
::
get
(
m_xContext
);
const
uno
::
Reference
<
document
::
XTypeDetection
>
xTypeDetection
(
m_xFactory
->
createInstanceWithContext
(
"com.sun.star.document.TypeDetection"
,
m_xContext
),
uno
::
UNO_QUERY_THROW
);
m_xTypeMap
.
set
(
xTypeDetection
,
uno
::
UNO_QUERY_THROW
);
}
void
WpftFilterFixture
::
tearDown
()
{
m_xDesktop
->
terminate
();
::
test
::
BootstrapFixture
::
tearDown
();
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
writerperfect/qa/unit/WpftFilterFixture.hxx
0 → 100644
Dosyayı görüntüle @
e60a60f5
/* -*- 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/.
*/
#ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERFIXTURE_HXX
#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERFIXTURE_HXX
#include "config_writerperfect.h"
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <rtl/ustring.hxx>
#include <test/bootstrapfixture.hxx>
#define REQUIRE_VERSION(major, minor, micro, req_major, req_minor, req_micro) \
(major) > (req_major) || \
((major) == (req_major) && \
((minor) > (req_minor) \
|| ((minor) == (req_minor) && ((micro) >= (req_micro)))))
#define REQUIRE_EBOOK_VERSION(major, minor, micro) \
REQUIRE_VERSION(EBOOK_VERSION_MAJOR, EBOOK_VERSION_MINOR, EBOOK_VERSION_MICRO, major, minor, micro)
#define REQUIRE_ETONYEK_VERSION(major, minor, micro) \
REQUIRE_VERSION(ETONYEK_VERSION_MAJOR, ETONYEK_VERSION_MINOR, ETONYEK_VERSION_MICRO, major, minor, micro)
#define REQUIRE_MWAW_VERSION(major, minor, micro) \
REQUIRE_VERSION(MWAW_VERSION_MAJOR, MWAW_VERSION_MINOR, MWAW_VERSION_MICRO, major, minor, micro)
#define REQUIRE_STAROFFICE_VERSION(major, minor, micro) \
REQUIRE_VERSION(STAROFFICE_VERSION_MAJOR, STAROFFICE_VERSION_MINOR, STAROFFICE_VERSION_MICRO, major, minor, micro)
#define REQUIRE_WPS_VERSION(major, minor, micro) \
REQUIRE_VERSION(WPS_VERSION_MAJOR, WPS_VERSION_MINOR, WPS_VERSION_MICRO, major, minor, micro)
namespace
com
{
namespace
sun
{
namespace
star
{
namespace
container
{
class
XNameAccess
;
}
namespace
frame
{
class
XDesktop2
;
}
}
}
}
namespace
writerperfect
{
namespace
test
{
class
WpftFilterFixture
:
public
::
test
::
BootstrapFixture
{
public
:
virtual
void
setUp
()
override
;
virtual
void
tearDown
()
override
;
protected
:
css
::
uno
::
Reference
<
css
::
frame
::
XDesktop2
>
m_xDesktop
;
css
::
uno
::
Reference
<
css
::
container
::
XNameAccess
>
m_xTypeMap
;
};
}
}
#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERFIXTURE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
writerperfect/qa/unit/WpftFilterTestBase.cxx
Dosyayı görüntüle @
e60a60f5
...
...
@@ -7,38 +7,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/NoSuchElementException.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>
#include <com/sun/star/frame/theDesktop.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/ucb/XContent.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <tools/urlobj.hxx>
#include "WpftFilterTestBase.hxx"
#include <
ucbhelper/content.hxx
>
#include <
com/sun/star/document/XFilter.hpp
>
#include "Wpft
FilterTestBase
.hxx"
#include "Wpft
Loader
.hxx"
namespace
beans
=
com
::
sun
::
star
::
beans
;
namespace
container
=
com
::
sun
::
star
::
container
;
namespace
document
=
com
::
sun
::
star
::
document
;
namespace
frame
=
com
::
sun
::
star
::
frame
;
namespace
io
=
com
::
sun
::
star
::
io
;
namespace
lang
=
com
::
sun
::
star
::
lang
;
namespace
ucb
=
com
::
sun
::
star
::
ucb
;
namespace
uno
=
com
::
sun
::
star
::
uno
;
namespace
util
=
com
::
sun
::
star
::
util
;
namespace
writerperfect
{
...
...
@@ -47,126 +22,17 @@ namespace test
WpftFilterTestBase
::
WpftFilterTestBase
(
const
rtl
::
OUString
&
rFactoryURL
)
:
::
test
::
FiltersTest
()
,
::
test
::
Bootstrap
Fixture
()
,
WpftFilter
Fixture
()
,
m_aFactoryURL
(
rFactoryURL
)
,
m_xDesktop
()
,
m_xFilter
()
,
m_xTypeMap
()
,
m_pOptionalMap
(
nullptr
)
{
}
void
WpftFilterTestBase
::
setUp
()
{
::
test
::
BootstrapFixture
::
setUp
();
m_xDesktop
=
frame
::
theDesktop
::
get
(
m_xContext
);
const
uno
::
Reference
<
document
::
XTypeDetection
>
xTypeDetection
(
m_xFactory
->
createInstanceWithContext
(
"com.sun.star.document.TypeDetection"
,
m_xContext
),
uno
::
UNO_QUERY_THROW
);
m_xTypeMap
.
set
(
xTypeDetection
,
uno
::
UNO_QUERY_THROW
);
}
void
WpftFilterTestBase
::
tearDown
()
{
m_xDesktop
->
terminate
();
::
test
::
BootstrapFixture
::
tearDown
();
}
bool
WpftFilterTestBase
::
load
(
const
OUString
&
,
const
OUString
&
rURL
,
const
OUString
&
,
SfxFilterFlags
,
SotClipboardFormatId
,
unsigned
int
)
{
if
(
m_pOptionalMap
)
{
// first check if this test file is supported by the used version of the library
const
INetURLObject
aUrl
(
rURL
);
const
WpftOptionalMap_t
::
const_iterator
it
(
m_pOptionalMap
->
find
(
aUrl
.
getName
()));
if
((
it
!=
m_pOptionalMap
->
end
())
&&
!
it
->
second
)
return
true
;
// skip the file
}
// create an empty frame
const
uno
::
Reference
<
lang
::
XComponent
>
xDoc
(
m_xDesktop
->
loadComponentFromURL
(
m_aFactoryURL
,
"_blank"
,
0
,
uno
::
Sequence
<
beans
::
PropertyValue
>
()),
uno
::
UNO_QUERY_THROW
);
// Find the model and frame. We need them later.
uno
::
Reference
<
frame
::
XFrame
>
xFrame
(
xDoc
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
frame
::
XModel
>
xModel
(
xDoc
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
frame
::
XController
>
xController
(
xDoc
,
uno
::
UNO_QUERY
);
if
(
xFrame
.
is
())
{
xController
=
xFrame
->
getController
();
xModel
=
xController
->
getModel
();
}
else
if
(
xModel
.
is
())
{
xController
=
xModel
->
getCurrentController
();
xFrame
=
xController
->
getFrame
();
}
else
if
(
xController
.
is
())
{
xFrame
=
xController
->
getFrame
();
xModel
=
xController
->
getModel
();
}
if
(
!
xFrame
.
is
()
||
!
xModel
.
is
())
throw
uno
::
RuntimeException
();
bool
result
=
false
;
// try to import the document (and load it into the prepared frame)
try
{
const
uno
::
Reference
<
document
::
XImporter
>
xImporter
(
m_xFilter
,
uno
::
UNO_QUERY_THROW
);
xImporter
->
setTargetDocument
(
xDoc
);
uno
::
Sequence
<
beans
::
PropertyValue
>
aDescriptor
(
3
);
ucbhelper
::
Content
aContent
(
rURL
,
uno
::
Reference
<
ucb
::
XCommandEnvironment
>
(),
m_xContext
);
aDescriptor
[
0
].
Name
=
"URL"
;
aDescriptor
[
0
].
Value
<<=
rURL
;
aDescriptor
[
1
].
Name
=
"InputStream"
;
aDescriptor
[
1
].
Value
<<=
aContent
.
openStream
();
aDescriptor
[
2
].
Name
=
"UCBContent"
;
aDescriptor
[
2
].
Value
<<=
aContent
.
get
();
const
uno
::
Reference
<
document
::
XExtendedFilterDetection
>
xDetector
(
m_xFilter
,
uno
::
UNO_QUERY_THROW
);
const
rtl
::
OUString
aTypeName
(
xDetector
->
detect
(
aDescriptor
));
if
(
aTypeName
.
isEmpty
())
throw
lang
::
IllegalArgumentException
();
impl_detectFilterName
(
aDescriptor
,
aTypeName
);
xModel
->
lockControllers
();
result
=
m_xFilter
->
filter
(
aDescriptor
);
xModel
->
unlockControllers
();
}
catch
(
const
uno
::
Exception
&
)
{
// ignore
}
// close the opened document
try
{
uno
::
Reference
<
util
::
XCloseable
>
xCloseable
(
xFrame
,
uno
::
UNO_QUERY
);
if
(
xCloseable
.
is
())
xCloseable
->
close
(
true
);
else
xDoc
->
dispose
();
}
catch
(
const
uno
::
Exception
&
)
{
// ignore
}
return
result
;
const
WpftLoader
aLoader
(
rURL
,
m_xFilter
,
m_aFactoryURL
,
m_xDesktop
,
m_xTypeMap
,
m_xContext
);
return
aLoader
.
getDocument
().
is
();
}
void
WpftFilterTestBase
::
doTest
(
const
rtl
::
OUString
&
rFilter
,
const
rtl
::
OUString
&
rPath
)
...
...
@@ -183,35 +49,6 @@ void WpftFilterTestBase::doTest(const rtl::OUString &rFilter, const rtl::OUStrin
m_pOptionalMap
=
nullptr
;
}
void
WpftFilterTestBase
::
impl_detectFilterName
(
uno
::
Sequence
<
beans
::
PropertyValue
>
&
rDescriptor
,
const
rtl
::
OUString
&
rTypeName
)
{
const
sal_Int32
nDescriptorLen
=
rDescriptor
.
getLength
();
for
(
sal_Int32
n
=
0
;
nDescriptorLen
!=
n
;
++
n
)
{
if
(
"FilterName"
==
rDescriptor
[
n
].
Name
)
return
;
}
uno
::
Sequence
<
beans
::
PropertyValue
>
aTypes
;
if
(
m_xTypeMap
->
getByName
(
rTypeName
)
>>=
aTypes
)
{
for
(
sal_Int32
n
=
0
;
aTypes
.
getLength
()
!=
n
;
++
n
)
{
rtl
::
OUString
aFilterName
;
if
((
"PreferredFilter"
==
aTypes
[
n
].
Name
)
&&
(
aTypes
[
n
].
Value
>>=
aFilterName
))
{
rDescriptor
.
realloc
(
nDescriptorLen
+
1
);
rDescriptor
[
nDescriptorLen
].
Name
=
"FilterName"
;
rDescriptor
[
nDescriptorLen
].
Value
<<=
aFilterName
;
return
;
}
}
}
throw
container
::
NoSuchElementException
();
}
}
}
...
...
writerperfect/qa/unit/WpftFilterTestBase.hxx
Dosyayı görüntüle @
e60a60f5
...
...
@@ -10,39 +10,15 @@
#ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX
#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTFILTERTESTBASE_HXX
#include "config_writerperfect.h"
#include <unordered_map>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <rtl/ustring.hxx>
#include <test/bootstrapfixture.hxx>
#include <unotest/filters-test.hxx>
#define REQUIRE_VERSION(major, minor, micro, req_major, req_minor, req_micro) \
(major) > (req_major) || \
((major) == (req_major) && \
((minor) > (req_minor) \
|| ((minor) == (req_minor) && ((micro) >= (req_micro)))))
#define REQUIRE_EBOOK_VERSION(major, minor, micro) \
REQUIRE_VERSION(EBOOK_VERSION_MAJOR, EBOOK_VERSION_MINOR, EBOOK_VERSION_MICRO, major, minor, micro)
#define REQUIRE_ETONYEK_VERSION(major, minor, micro) \
REQUIRE_VERSION(ETONYEK_VERSION_MAJOR, ETONYEK_VERSION_MINOR, ETONYEK_VERSION_MICRO, major, minor, micro)
#define REQUIRE_MWAW_VERSION(major, minor, micro) \
REQUIRE_VERSION(MWAW_VERSION_MAJOR, MWAW_VERSION_MINOR, MWAW_VERSION_MICRO, major, minor, micro)
#define REQUIRE_STAROFFICE_VERSION(major, minor, micro) \
REQUIRE_VERSION(STAROFFICE_VERSION_MAJOR, STAROFFICE_VERSION_MINOR, STAROFFICE_VERSION_MICRO, major, minor, micro)
#define REQUIRE_WPS_VERSION(major, minor, micro) \
REQUIRE_VERSION(WPS_VERSION_MAJOR, WPS_VERSION_MINOR, WPS_VERSION_MICRO, major, minor, micro)
#include "WpftFilterFixture.hxx"
namespace
com
{
...
...
@@ -50,26 +26,10 @@ namespace sun
{
namespace
star
{
namespace
beans
{
struct
PropertyValue
;
}
namespace
container
{
class
XNameAccess
;
}
namespace
document
{
class
XFilter
;
}
namespace
frame
{
class
XDesktop2
;
}
namespace
ucb
{
class
XSimpleFileAccess
;
}
}
}
}
...
...
@@ -83,14 +43,11 @@ typedef std::unordered_map<rtl::OUString, bool, rtl::OUStringHash> WpftOptionalM
class
WpftFilterTestBase
:
public
::
test
::
FiltersTest
,
public
::
test
::
Bootstrap
Fixture
,
public
WpftFilter
Fixture
{
public
:
explicit
WpftFilterTestBase
(
const
rtl
::
OUString
&
rFactoryURL
);
virtual
void
setUp
()
override
;
virtual
void
tearDown
()
override
;
protected
:
void
doTest
(
const
rtl
::
OUString
&
rFilter
,
const
rtl
::
OUString
&
rPath
);
void
doTest
(
const
rtl
::
OUString
&
rFilter
,
const
rtl
::
OUString
&
rPath
,
const
WpftOptionalMap_t
&
rOptionalMap
);
...
...
@@ -99,13 +56,9 @@ private:
virtual
bool
load
(
const
OUString
&
,
const
OUString
&
rURL
,
const
OUString
&
,
SfxFilterFlags
,
SotClipboardFormatId
,
unsigned
int
)
override
;
void
impl_detectFilterName
(
css
::
uno
::
Sequence
<
css
::
beans
::
PropertyValue
>
&
rDescriptor
,
const
rtl
::
OUString
&
rTypeName
);
private
:
const
rtl
::
OUString
m_aFactoryURL
;
css
::
uno
::
Reference
<
css
::
frame
::
XDesktop2
>
m_xDesktop
;
css
::
uno
::
Reference
<
css
::
document
::
XFilter
>
m_xFilter
;
css
::
uno
::
Reference
<
css
::
container
::
XNameAccess
>
m_xTypeMap
;
const
WpftOptionalMap_t
*
m_pOptionalMap
;
};
...
...
writerperfect/qa/unit/WpftLoader.cxx
0 → 100644
Dosyayı görüntüle @
e60a60f5
/* -*- 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 "WpftLoader.hxx"
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/NoSuchElementException.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XDesktop2.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/XContent.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <ucbhelper/content.hxx>
namespace
beans
=
com
::
sun
::
star
::
beans
;
namespace
container
=
com
::
sun
::
star
::
container
;
namespace
document
=
com
::
sun
::
star
::
document
;
namespace
frame
=
com
::
sun
::
star
::
frame
;
namespace
lang
=
com
::
sun
::
star
::
lang
;
namespace
ucb
=
com
::
sun
::
star
::
ucb
;
namespace
uno
=
com
::
sun
::
star
::
uno
;
namespace
util
=
com
::
sun
::
star
::
util
;
namespace
writerperfect
{
namespace
test
{
WpftLoader
::
WpftLoader
(
const
rtl
::
OUString
&
rURL
,
const
css
::
uno
::
Reference
<
css
::
document
::
XFilter
>
&
rxFilter
,
const
rtl
::
OUString
&
rFactoryURL
,
const
css
::
uno
::
Reference
<
css
::
frame
::
XDesktop2
>
&
rxDesktop
,
const
css
::
uno
::
Reference
<
css
::
container
::
XNameAccess
>
&
rxTypeMap
,
const
css
::
uno
::
Reference
<
css
::
uno
::
XComponentContext
>
&
rxContext
)
:
m_aURL
(
rURL
)
,
m_aFactoryURL
(
rFactoryURL
)
,
m_xFilter
(
rxFilter
)
,
m_xDesktop
(
rxDesktop
)
,
m_xTypeMap
(
rxTypeMap
)
,
m_xContext
(
rxContext
)
{
if
(
!
impl_load
())
impl_dispose
();
}
WpftLoader
::~
WpftLoader
()
{
try
{
impl_dispose
();
}
catch
(...)
{
}
}
const
css
::
uno
::
Reference
<
css
::
lang
::
XComponent
>
&
WpftLoader
::
getDocument
()
const
{
return
m_xDoc
;
}
bool
WpftLoader
::
impl_load
()
{
// create an empty frame
m_xDoc
.
set
(
m_xDesktop
->
loadComponentFromURL
(
m_aFactoryURL
,
"_blank"
,
0
,
uno
::
Sequence
<
beans
::
PropertyValue
>
()),
uno
::
UNO_QUERY_THROW
);
// Find the model and frame. We need them later.
m_xFrame
.
set
(
m_xDoc
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
frame
::
XModel
>
xModel
(
m_xDoc
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
frame
::
XController
>
xController
(
m_xDoc
,
uno
::
UNO_QUERY
);
if
(
m_xFrame
.
is
())
{
xController
=
m_xFrame
->
getController
();
xModel
=
xController
->
getModel
();
}
else
if
(
xModel
.
is
())
{
xController
=
xModel
->
getCurrentController
();
m_xFrame
=
xController
->
getFrame
();
}
else
if
(
xController
.
is
())
{
m_xFrame
=
xController
->
getFrame
();
xModel
=
xController
->
getModel
();
}
if
(
!
m_xFrame
.
is
()
||
!
xModel
.
is
())
throw
uno
::
RuntimeException
();
// try to import the document (and load it into the prepared frame)
try
{
const
uno
::
Reference
<
document
::
XImporter
>
xImporter
(
m_xFilter
,
uno
::
UNO_QUERY_THROW
);
xImporter
->
setTargetDocument
(
m_xDoc
);
uno
::
Sequence
<
beans
::
PropertyValue
>
aDescriptor
(
3
);
ucbhelper
::
Content
aContent
(
m_aURL
,
uno
::
Reference
<
ucb
::
XCommandEnvironment
>
(),
m_xContext
);
aDescriptor
[
0
].
Name
=
"URL"
;
aDescriptor
[
0
].
Value
<<=
m_aURL
;
aDescriptor
[
1
].
Name
=
"InputStream"
;
aDescriptor
[
1
].
Value
<<=
aContent
.
openStream
();
aDescriptor
[
2
].
Name
=
"UCBContent"
;
aDescriptor
[
2
].
Value
<<=
aContent
.
get
();
const
uno
::
Reference
<
document
::
XExtendedFilterDetection
>
xDetector
(
m_xFilter
,
uno
::
UNO_QUERY_THROW
);
const
rtl
::
OUString
aTypeName
(
xDetector
->
detect
(
aDescriptor
));
if
(
aTypeName
.
isEmpty
())
throw
lang
::
IllegalArgumentException
();
impl_detectFilterName
(
aDescriptor
,
aTypeName
);
xModel
->
lockControllers
();
const
bool
bLoaded
=
m_xFilter
->
filter
(
aDescriptor
);
xModel
->
unlockControllers
();
return
bLoaded
;
}
catch
(
const
uno
::
Exception
&
)
{
// ignore
}
return
false
;
}
void
WpftLoader
::
impl_dispose
()
{
// close the opened document
uno
::
Reference
<
util
::
XCloseable
>
xCloseable
(
m_xFrame
,
uno
::
UNO_QUERY
);
if
(
xCloseable
.
is
())
xCloseable
->
close
(
true
);
else
if
(
m_xDoc
.
is
())
m_xDoc
->
dispose
();
m_xDoc
.
clear
();
m_xFrame
.
clear
();
}
void
WpftLoader
::
impl_detectFilterName
(
uno
::
Sequence
<
beans
::
PropertyValue
>
&
rDescriptor
,
const
rtl
::
OUString
&
rTypeName
)
{
const
sal_Int32
nDescriptorLen
=
rDescriptor
.
getLength
();
for
(
sal_Int32
n
=
0
;
nDescriptorLen
!=
n
;
++
n
)
{
if
(
"FilterName"
==
rDescriptor
[
n
].
Name
)
return
;
}
uno
::
Sequence
<
beans
::
PropertyValue
>
aTypes
;
if
(
m_xTypeMap
->
getByName
(
rTypeName
)
>>=
aTypes
)
{
for
(
sal_Int32
n
=
0
;
aTypes
.
getLength
()
!=
n
;
++
n
)
{
rtl
::
OUString
aFilterName
;
if
((
"PreferredFilter"
==
aTypes
[
n
].
Name
)
&&
(
aTypes
[
n
].
Value
>>=
aFilterName
))
{
rDescriptor
.
realloc
(
nDescriptorLen
+
1
);
rDescriptor
[
nDescriptorLen
].
Name
=
"FilterName"
;
rDescriptor
[
nDescriptorLen
].
Value
<<=
aFilterName
;
return
;
}
}
}
throw
container
::
NoSuchElementException
();
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
writerperfect/qa/unit/WpftLoader.hxx
0 → 100644
Dosyayı görüntüle @
e60a60f5
/* -*- 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/.
*/
#ifndef INCLUDED_WRITERPERFECT_QA_UNIT_WPFTLOADER_HXX
#define INCLUDED_WRITERPERFECT_QA_UNIT_WPFTLOADER_HXX
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <rtl/ustring.hxx>
namespace
com
{
namespace
sun
{
namespace
star
{
namespace
beans
{
struct
PropertyValue
;
}
namespace
container
{
class
XNameAccess
;
}
namespace
document
{
class
XFilter
;
}
namespace
frame
{
class
XDesktop2
;
class
XFrame
;
}
namespace
lang
{
class
XComponent
;
}
namespace
uno
{
class
XComponentContext
;
}
}
}
}
namespace
writerperfect
{
namespace
test
{
class
WpftLoader
{
public
:
WpftLoader
(
const
rtl
::
OUString
&
rURL
,
const
css
::
uno
::
Reference
<
css
::
document
::
XFilter
>
&
rxFilter
,
const
rtl
::
OUString
&
rFactoryURL
,
const
css
::
uno
::
Reference
<
css
::
frame
::
XDesktop2
>
&
rxDesktop
,
const
css
::
uno
::
Reference
<
css
::
container
::
XNameAccess
>
&
rxTypeMap
,
const
css
::
uno
::
Reference
<
css
::
uno
::
XComponentContext
>
&
rxContext
);
WpftLoader
(
const
WpftLoader
&
)
=
delete
;
WpftLoader
&
operator
=
(
const
WpftLoader
&
)
=
delete
;
~
WpftLoader
();
const
css
::
uno
::
Reference
<
css
::
lang
::
XComponent
>
&
getDocument
()
const
;
private
:
bool
impl_load
();
void
impl_dispose
();
void
impl_detectFilterName
(
css
::
uno
::
Sequence
<
css
::
beans
::
PropertyValue
>
&
rDescriptor
,
const
rtl
::
OUString
&
rTypeName
);
private
:
const
rtl
::
OUString
m_aURL
;
const
rtl
::
OUString
m_aFactoryURL
;
const
css
::
uno
::
Reference
<
css
::
document
::
XFilter
>
m_xFilter
;
const
css
::
uno
::
Reference
<
css
::
frame
::
XDesktop2
>
m_xDesktop
;
const
css
::
uno
::
Reference
<
css
::
container
::
XNameAccess
>
m_xTypeMap
;
const
css
::
uno
::
Reference
<
css
::
uno
::
XComponentContext
>
m_xContext
;
css
::
uno
::
Reference
<
css
::
lang
::
XComponent
>
m_xDoc
;
css
::
uno
::
Reference
<
css
::
frame
::
XFrame
>
m_xFrame
;
};
}
}
#endif // INCLUDED_WRITERPERFECT_QA_UNIT_WPFTLOADER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment