diff options
author | Tobias Deiminger <haxtibal@posteo.de> | 2019-07-01 23:23:01 +0200 |
---|---|---|
committer | Tobias Deiminger <haxtibal@posteo.de> | 2019-07-01 23:23:01 +0200 |
commit | ccfaa9dc0f8929d9ec49d8f49ad017cdd06ee5cb (patch) | |
tree | 34de9454be398d68eb4f545e87b8007c2497d1fb | |
parent | 68b74ab18016520f755bf8bc35e9804fe378ad91 (diff) |
Add unit test for class DefaultAppearance
-rw-r--r-- | qt5/tests/check_annotations.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp index 20b33f21..00026f05 100644 --- a/qt5/tests/check_annotations.cpp +++ b/qt5/tests/check_annotations.cpp @@ -7,6 +7,7 @@ #include <poppler-qt5.h> +#include "poppler/Annot.h" #include "goo/GooString.h" #include "goo/gstrtod.h" @@ -21,6 +22,7 @@ private slots: void checkHighlightFromAndToQuads(); void checkUTF16LEAnnot(); void checkNonMarkupAnnotations(); + void checkDefaultAppearance(); }; /* Is .5f sufficient for 16 bit color channel roundtrip trough save and load on all architectures? */ @@ -172,6 +174,44 @@ void TestAnnotations::checkNonMarkupAnnotations() QCOMPARE(annots.size(), 17); } +void TestAnnotations::checkDefaultAppearance() +{ + std::unique_ptr<GooString> roundtripString; + { + GooString daString{ "/Helv 10 Tf 0.1 0.2 0.3 rg" }; + const DefaultAppearance da { &daString }; + QCOMPARE( da.getFontPtSize(), 10. ); + QVERIFY( da.getFontName().isName() ); + QCOMPARE( da.getFontName().getName(), "Helv" ); + const AnnotColor* color = da.getFontColor(); + QVERIFY( color ); + QCOMPARE( color->getSpace(), AnnotColor::colorRGB ); + QCOMPARE( color->getValues()[0], 0.1 ); + QCOMPARE( color->getValues()[1], 0.2 ); + QCOMPARE( color->getValues()[2], 0.3 ); + roundtripString.reset( da.toAppearanceString() ); + } + { + /* roundtrip through parse/generate/parse shall preserve values */ + const DefaultAppearance da { roundtripString.get() }; + QCOMPARE( da.getFontPtSize(), 10. ); + QVERIFY( da.getFontName().isName() ); + QCOMPARE( da.getFontName().getName(), "Helv" ); + const AnnotColor* color = da.getFontColor(); + QVERIFY( color ); + QCOMPARE( color->getSpace(), AnnotColor::colorRGB ); + QCOMPARE( color->getValues()[0], 0.1 ); + QCOMPARE( color->getValues()[1], 0.2 ); + QCOMPARE( color->getValues()[2], 0.3 ); + } + { + /* parsing bad DA strings must not cause crash */ + GooString daString{ "/ % Tf 1 2 rg" }; + const DefaultAppearance da { &daString }; + QVERIFY( !da.getFontName().isName() ); + } +} + QTEST_GUILESS_MAIN(TestAnnotations) |