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
b4bc6521
Kaydet (Commit)
b4bc6521
authored
Kas 05, 2014
tarafından
Luboš Luňák
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
make it possible to check mailmerge output files in unittests
Change-Id: Ifa54445c8f46bb2ed5539870c5fce1a2e62beef7
üst
f373aa0b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
22 deletions
+65
-22
swmodeltestbase.hxx
sw/qa/extras/inc/swmodeltestbase.hxx
+44
-11
mailmerge.cxx
sw/qa/extras/mailmerge/mailmerge.cxx
+21
-11
No files found.
sw/qa/extras/inc/swmodeltestbase.hxx
Dosyayı görüntüle @
b4bc6521
...
...
@@ -182,6 +182,8 @@ protected:
utl
::
TempFile
maTempFile
;
bool
mbExported
;
///< Does maTempFile already contain something useful?
sal_Int16
nCurOutputType
;
OUString
mailMergeOutputURL
;
OUString
mailMergeOutputPrefix
;
protected
:
virtual
OUString
getTestName
()
{
return
OUString
();
}
...
...
@@ -612,6 +614,25 @@ protected:
calcLayout
();
}
/**
Loads number-th document from mail merge. Requires file output from mail merge.
*/
void
loadMailMergeDocument
(
int
number
)
{
assert
(
nCurOutputType
==
text
::
MailMergeType
::
FILE
);
if
(
mxComponent
.
is
())
mxComponent
->
dispose
();
OUString
name
=
mailMergeOutputPrefix
+
OUString
::
number
(
number
)
+
".odt"
;
// Output name early, so in the case of a hang, the name of the hanging input file is visible.
std
::
cout
<<
name
<<
","
;
mnStartTime
=
osl_getGlobalTimer
();
mxComponent
=
loadFromDesktop
(
mailMergeOutputURL
+
"/"
+
name
,
"com.sun.star.text.TextDocument"
);
CPPUNIT_ASSERT
(
mxComponent
.
is
());
OString
name2
=
OUStringToOString
(
name
,
RTL_TEXTENCODING_UTF8
);
if
(
mustCalcLayoutOf
(
name2
.
getStr
()))
calcLayout
();
}
void
reload
(
const
char
*
pFilter
,
const
char
*
filename
)
{
uno
::
Reference
<
frame
::
XStorable
>
xStorable
(
mxComponent
,
uno
::
UNO_QUERY
);
...
...
@@ -692,8 +713,25 @@ protected:
if
(
!
mbExported
)
return
0
;
return
parseExportInternal
(
maTempFile
.
GetURL
(),
rStreamName
);
}
/**
* Like parseExport(), but for given mail merge document.
*/
xmlDocPtr
parseMailMergeExport
(
int
number
,
const
OUString
&
rStreamName
=
OUString
(
"word/document.xml"
))
{
if
(
nCurOutputType
!=
text
::
MailMergeType
::
FILE
)
return
0
;
OUString
name
=
mailMergeOutputPrefix
+
OUString
::
number
(
number
)
+
".odt"
;
return
parseExportInternal
(
mailMergeOutputURL
+
"/"
+
name
,
rStreamName
);
}
xmlDocPtr
parseExportInternal
(
const
OUString
&
url
,
const
OUString
&
rStreamName
)
{
// Read the XML stream we're interested in.
uno
::
Reference
<
packages
::
zip
::
XZipFileAccess2
>
xNameAccess
=
packages
::
zip
::
ZipFileAccess
::
createWithURL
(
comphelper
::
getComponentContext
(
m_xSFactory
),
maTempFile
.
GetURL
()
);
uno
::
Reference
<
packages
::
zip
::
XZipFileAccess2
>
xNameAccess
=
packages
::
zip
::
ZipFileAccess
::
createWithURL
(
comphelper
::
getComponentContext
(
m_xSFactory
),
url
);
uno
::
Reference
<
io
::
XInputStream
>
xInputStream
(
xNameAccess
->
getByName
(
rStreamName
),
uno
::
UNO_QUERY
);
boost
::
shared_ptr
<
SvStream
>
pStream
(
utl
::
UcbStreamHelper
::
CreateStream
(
xInputStream
,
true
));
...
...
@@ -783,7 +821,7 @@ protected:
}
virtual
void
initMailMergeJobAndArgs
(
const
char
*
filename
,
const
char
*
tablename
,
const
OUString
&
aDBName
,
const
OUString
&
aPrefix
,
const
OUString
&
aWorkDir
)
const
OUString
&
aPrefix
,
const
OUString
&
aWorkDir
,
bool
file
)
{
uno
::
Reference
<
task
::
XJob
>
xJob
(
getMultiServiceFactory
()
->
createInstance
(
"com.sun.star.text.MailMerge"
),
uno
::
UNO_QUERY_THROW
);
mxJob
.
set
(
xJob
);
...
...
@@ -793,7 +831,7 @@ protected:
mSeqMailMergeArgs
.
realloc
(
seq_id
);
seq_id
=
0
;
mSeqMailMergeArgs
[
seq_id
++
]
=
beans
::
NamedValue
(
OUString
(
UNO_NAME_OUTPUT_TYPE
),
uno
::
Any
(
text
::
MailMergeType
::
SHELL
)
);
mSeqMailMergeArgs
[
seq_id
++
]
=
beans
::
NamedValue
(
OUString
(
UNO_NAME_OUTPUT_TYPE
),
uno
::
Any
(
file
?
text
::
MailMergeType
::
FILE
:
text
::
MailMergeType
::
SHELL
)
);
mSeqMailMergeArgs
[
seq_id
++
]
=
beans
::
NamedValue
(
OUString
(
UNO_NAME_DOCUMENT_URL
),
uno
::
Any
(
(
OUString
(
getURLFromSrc
(
mpTestDocumentPath
)
+
OUString
::
createFromAscii
(
filename
))
)
)
);
mSeqMailMergeArgs
[
seq_id
++
]
=
beans
::
NamedValue
(
OUString
(
UNO_NAME_DATA_SOURCE_NAME
),
uno
::
Any
(
aDBName
)
);
...
...
@@ -810,8 +848,6 @@ protected:
{
uno
::
Any
res
=
mxJob
->
execute
(
mSeqMailMergeArgs
);
OUString
aCurOutputURL
;
OUString
aCurFileNamePrefix
;
const
beans
::
NamedValue
*
pArguments
=
mSeqMailMergeArgs
.
getConstArray
();
bool
bOk
=
true
;
sal_Int32
nArgs
=
mSeqMailMergeArgs
.
getLength
();
...
...
@@ -822,9 +858,9 @@ protected:
// all error checking was already done by the MM job execution
if
(
rName
==
UNO_NAME_OUTPUT_URL
)
bOk
&=
rValue
>>=
aCur
OutputURL
;
bOk
&=
rValue
>>=
mailMerge
OutputURL
;
else
if
(
rName
==
UNO_NAME_FILE_NAME_PREFIX
)
bOk
&=
rValue
>>=
aCurFileName
Prefix
;
bOk
&=
rValue
>>=
mailMergeOutput
Prefix
;
else
if
(
rName
==
UNO_NAME_OUTPUT_TYPE
)
bOk
&=
rValue
>>=
nCurOutputType
;
}
...
...
@@ -839,10 +875,7 @@ protected:
else
{
CPPUNIT_ASSERT
(
res
==
true
);
mxMMComponent
=
loadFromDesktop
(
aCurOutputURL
+
"/"
+
aCurFileNamePrefix
+
"0.odt"
,
"com.sun.star.text.TextDocument"
);
CPPUNIT_ASSERT
(
mxMMComponent
.
is
());
calcLayout
();
loadMailMergeDocument
(
0
);
}
}
};
...
...
sw/qa/extras/mailmerge/mailmerge.cxx
Dosyayı görüntüle @
b4bc6521
...
...
@@ -44,7 +44,7 @@ class MMTest : public SwModelTestBase
* The 'verify' method actually has to execute the mail merge by
* calling executeMailMerge() after modifying the job arguments.
*/
void
executeMailMergeTest
(
const
char
*
filename
,
const
char
*
datasource
,
const
char
*
tablename
=
0
)
void
executeMailMergeTest
(
const
char
*
filename
,
const
char
*
datasource
,
const
char
*
tablename
,
bool
file
)
{
header
();
preTest
(
filename
);
...
...
@@ -55,18 +55,19 @@ class MMTest : public SwModelTestBase
const
OUString
aWorkDir
=
aTempDir
.
GetURL
();
const
OUString
aURI
(
getURLFromSrc
(
mpTestDocumentPath
)
+
OUString
::
createFromAscii
(
datasource
)
);
OUString
aDBName
=
registerDBsource
(
aURI
,
aPrefix
,
aWorkDir
);
initMailMergeJobAndArgs
(
filename
,
tablename
,
aDBName
,
aPrefix
,
aWorkDir
);
initMailMergeJobAndArgs
(
filename
,
tablename
,
aDBName
,
aPrefix
,
aWorkDir
,
file
);
postTest
(
filename
);
verify
();
finish
();
::
utl
::
removeTree
(
aWorkDir
);
nCurOutputType
=
0
;
}
};
#define DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename, BaseClass) \
#define DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename,
file,
BaseClass) \
class TestName : public BaseClass { \
protected: \
virtual OUString getTestName() SAL_OVERRIDE { return OUString::createFromAscii(#TestName); } \
...
...
@@ -76,17 +77,22 @@ class MMTest : public SwModelTestBase
CPPUNIT_TEST_SUITE_END(); \
\
void MailMerge() { \
executeMailMergeTest(filename, datasource, tablename); \
executeMailMergeTest(filename, datasource, tablename
, file
); \
} \
void verify() SAL_OVERRIDE; \
}; \
CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
void TestName::verify()
#define DECLARE_DFLT_MAILMERGE_TEST(TestName, filename, datasource, tablename) \
DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename, MMTest)
// Will generate the resulting document in mxMMDocument.
#define DECLARE_SHELL_MAILMERGE_TEST(TestName, filename, datasource, tablename) \
DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename, false, MMTest)
DECLARE_DFLT_MAILMERGE_TEST
(
testMultiPageAnchoredDraws
,
"multiple-page-anchored-draws.odt"
,
"4_v01.ods"
,
"Tabelle1"
)
// Will generate documents as files, use loadMailMergeDocument().
#define DECLARE_FILE_MAILMERGE_TEST(TestName, filename, datasource, tablename) \
DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename, true, MMTest)
DECLARE_SHELL_MAILMERGE_TEST
(
testMultiPageAnchoredDraws
,
"multiple-page-anchored-draws.odt"
,
"4_v01.ods"
,
"Tabelle1"
)
{
executeMailMerge
();
...
...
@@ -117,19 +123,19 @@ DECLARE_DFLT_MAILMERGE_TEST(testMultiPageAnchoredDraws, "multiple-page-anchored-
}
}
DECLARE_
DFLT
_MAILMERGE_TEST
(
testMissingDefaultLineColor
,
"missing-default-line-color.ott"
,
"one-empty-address.ods"
,
"one-empty-address"
)
DECLARE_
FILE
_MAILMERGE_TEST
(
testMissingDefaultLineColor
,
"missing-default-line-color.ott"
,
"one-empty-address.ods"
,
"one-empty-address"
)
{
executeMailMerge
();
// The document was created by LO version which didn't write out the default value for line color
// (see XMLGraphicsDefaultStyle::SetDefaults()).
uno
::
Reference
<
drawing
::
XDrawPageSupplier
>
xDrawPageSupplier
(
mx
MM
Component
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
drawing
::
XDrawPageSupplier
>
xDrawPageSupplier
(
mxComponent
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
container
::
XIndexAccess
>
xDraws
(
xDrawPageSupplier
->
getDrawPage
(),
uno
::
UNO_QUERY
);
uno
::
Reference
<
beans
::
XPropertySet
>
xPropertySet
(
xDraws
->
getByIndex
(
0
),
uno
::
UNO_QUERY
);
// Lines do not have a line color.
CPPUNIT_ASSERT
(
!
xPropertySet
->
getPropertySetInfo
()
->
hasPropertyByName
(
"LineColor"
));
SwXTextDocument
*
pTxtDoc
=
dynamic_cast
<
SwXTextDocument
*>
(
mx
MM
Component
.
get
());
SwXTextDocument
*
pTxtDoc
=
dynamic_cast
<
SwXTextDocument
*>
(
mxComponent
.
get
());
CPPUNIT_ASSERT
(
pTxtDoc
);
uno
::
Reference
<
lang
::
XMultiServiceFactory
>
xFact
(
mx
MM
Component
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
lang
::
XMultiServiceFactory
>
xFact
(
mxComponent
,
uno
::
UNO_QUERY
);
uno
::
Reference
<
beans
::
XPropertySet
>
xDefaults
(
xFact
->
createInstance
(
"com.sun.star.drawing.Defaults"
),
uno
::
UNO_QUERY
);
CPPUNIT_ASSERT
(
xDefaults
.
is
());
uno
::
Reference
<
beans
::
XPropertySetInfo
>
xInfo
(
xDefaults
->
getPropertySetInfo
());
...
...
@@ -138,6 +144,10 @@ DECLARE_DFLT_MAILMERGE_TEST(testMissingDefaultLineColor, "missing-default-line-c
xDefaults
->
getPropertyValue
(
"LineColor"
)
>>=
lineColor
;
// And the default value is black (wasn't copied properly by mailmerge).
CPPUNIT_ASSERT_EQUAL
(
COL_BLACK
,
lineColor
);
// And check that the resulting file has the proper default.
xmlDocPtr
pXmlDoc
=
parseMailMergeExport
(
0
,
"styles.xml"
);
CPPUNIT_ASSERT_EQUAL
(
OUString
(
"graphic"
),
getXPath
(
pXmlDoc
,
"/office:document-styles/office:styles/style:default-style[1]"
,
"family"
));
CPPUNIT_ASSERT_EQUAL
(
OUString
(
"#000000"
),
getXPath
(
pXmlDoc
,
"/office:document-styles/office:styles/style:default-style[1]/style:graphic-properties"
,
"stroke-color"
));
}
#endif
...
...
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