Commit f1b8dc07 authored by Laurent Montel's avatar Laurent Montel 😁

Add more autotest

parent 27100a11
add_definitions( -DGRANTLEEBUILDER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
ecm_add_tests(texthtmlbuildertest.cpp
NAME_PREFIX "kpimtextedit-grantleebuilder-"
LINK_LIBRARIES KF5::PimTextEdit Qt5::Test Qt5::Widgets Grantlee5::TextDocument
......
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12" height="12" id="svg3049">
<defs id="defs3051">
<linearGradient id="linearGradient4234">
<stop style="stop-color:#232629;stop-opacity:1" offset="0" id="stop4236"/>
<stop style="stop-color:#b3b3b3;stop-opacity:1" offset="1" id="stop4238"/>
</linearGradient>
<style id="current-color-scheme">
.ColorScheme-Text{color:#232629}.ColorScheme-Background{color:#eff0f1}.ColorScheme-Highlight{color:#3daee9}.ColorScheme-ViewText{color:#31363b}.ColorScheme-ViewBackground{color:#fcfcfc}.ColorScheme-ViewHover{color:#93cee9}.ColorScheme-ViewFocus{color:#3daee9}.ColorScheme-ButtonText{color:#31363b}.ColorScheme-ButtonBackground{color:#eff0f1}.ColorScheme-ButtonHover{color:#93cee9}.ColorScheme-ButtonFocus{color:#3daee9}
</style>
<linearGradient xlink:href="#linearGradient4234" id="linearGradient4240" x1="422.714" y1="546.791" x2="432.714" y2="536.791" gradientUnits="userSpaceOnUse"/>
</defs>
<g id="layer1">
<path style="fill:url(#linearGradient4240);fill-opacity:1;stroke:none;stroke-width:.1;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" id="rect4232" d="M422.714 536.791H432.714V546.791H422.714z" transform="translate(-421.714 -535.79)"/>
</g>
</svg>
......@@ -721,3 +721,71 @@ void TextHTMLBuilderTest::testNewlinesThroughQTextCursor()
delete doc;
}
void TextHTMLBuilderTest::testInsertImage()
{
auto doc = new QTextDocument(this);
QTextCursor cursor(doc);
cursor.movePosition(QTextCursor::Start);
cursor.insertText(QStringLiteral("Foo"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("Bar"));
const QString imagePath = QStringLiteral(GRANTLEEBUILDER_DIR "/object-fill.svg");
const QImage image(imagePath);
QString imageNameToAdd = QStringLiteral("imagename");
doc->addResource(QTextDocument::ImageResource, QUrl(imageNameToAdd), image);
cursor.insertImage(imageNameToAdd);
auto hb = new KPIMTextEdit::TextHTMLBuilder();
auto md = new KPIMTextEdit::MarkupDirector(hb);
md->processDocument(doc);
auto result = hb->getResult();
auto regex = QRegularExpression(
QStringLiteral("^<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">Foo</p>\\n<p>&nbsp;<p>&nbsp;<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">Bar<img src=\"imagename\" /></p>\\n$"));
QVERIFY(regex.match(result).hasMatch());
delete md;
delete hb;
delete doc;
}
void TextHTMLBuilderTest::testInsertImageWithSize()
{
auto doc = new QTextDocument(this);
QTextCursor cursor(doc);
cursor.movePosition(QTextCursor::Start);
cursor.insertText(QStringLiteral("Foo"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("\n"));
cursor.insertText(QStringLiteral("Bar"));
const QString imagePath = QStringLiteral(GRANTLEEBUILDER_DIR "/object-fill.svg");
const QImage image(imagePath);
QString imageNameToAdd = QStringLiteral("imagename");
doc->addResource(QTextDocument::ImageResource, QUrl(imageNameToAdd), image);
QTextImageFormat format;
format.setName(imageNameToAdd);
format.setWidth(100);
format.setHeight(120);
cursor.insertImage(format);
auto hb = new KPIMTextEdit::TextHTMLBuilder();
auto md = new KPIMTextEdit::MarkupDirector(hb);
md->processDocument(doc);
auto result = hb->getResult();
auto regex = QRegularExpression(
QStringLiteral("^<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">Foo</p>\\n<p>&nbsp;<p>&nbsp;<p style=\"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;\">Bar<img src=\"imagename\" width=\"100\" height=\"120\" /></p>\\n$"));
QVERIFY(regex.match(result).hasMatch());
delete md;
delete hb;
delete doc;
}
......@@ -54,6 +54,8 @@ private Q_SLOTS:
void testHorizontalRule();
void testNewlines();
void testNewlinesThroughQTextCursor();
void testInsertImage();
void testInsertImageWithSize();
};
#endif // TEXTHTMLBUILDERTEST_H
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