From 62bb88ade14ea7e39f6de60e02c7d6f943d922e9 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 11 Oct 2018 11:06:24 -0400 Subject: Add new object-style test to test cascading and precidence. --- testfiles/src/object-style-test.cpp | 131 ++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 testfiles/src/object-style-test.cpp (limited to 'testfiles/src/object-style-test.cpp') diff --git a/testfiles/src/object-style-test.cpp b/testfiles/src/object-style-test.cpp new file mode 100644 index 000000000..b23bc5e66 --- /dev/null +++ b/testfiles/src/object-style-test.cpp @@ -0,0 +1,131 @@ +/* + * Combination style and object testing for cascading and flags. + * + * Authors: + * Martin Owens + * + * Copyright (C) 2018 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include + +#include +#include +#include + +using namespace Inkscape; +using namespace Inkscape::XML; + +class ObjectTest: public DocPerCaseTest { +public: + ObjectTest() { + char const *docString = "\ +\ +\ +\ + \ + \ + \ + \ +\ +"; + doc = SPDocument::createNewDocFromMem(docString, static_cast(strlen(docString)), false); + } + + ~ObjectTest() { + doc->doUnref(); + } + + SPDocument *doc; +}; + +TEST_F(ObjectTest, Styles) { + ASSERT_TRUE(doc != nullptr); + ASSERT_TRUE(doc->getRoot() != nullptr); + + SPRoot *root = doc->getRoot(); + ASSERT_TRUE(root->getRepr() != nullptr); + ASSERT_TRUE(root->hasChildren()); + + SPRect *one = dynamic_cast(doc->getObjectById("one")); + ASSERT_TRUE(one != nullptr); + + // TODO: Fix when Inkscape preserves colour names (i.e. 'red') + EXPECT_EQ(one->style->fill.get_value(), Glib::ustring("#ff0000")); + EXPECT_EQ(one->style->stroke.get_value(), Glib::ustring("#008000")); + EXPECT_EQ(one->style->opacity.get_value(), Glib::ustring("0.5")); + EXPECT_EQ(one->style->stroke_width.get_value(), Glib::ustring("2px")); + + SPRect *two = dynamic_cast(doc->getObjectById("two")); + ASSERT_TRUE(two != nullptr); + + EXPECT_EQ(two->style->fill.get_value(), Glib::ustring("#808080")); + EXPECT_EQ(two->style->stroke.get_value(), Glib::ustring("#008000")); + EXPECT_EQ(two->style->opacity.get_value(), Glib::ustring("0.5")); + EXPECT_EQ(two->style->stroke_width.get_value(), Glib::ustring("4px")); + + SPRect *three = dynamic_cast(doc->getObjectById("three")); + ASSERT_TRUE(three != nullptr); + + EXPECT_EQ(three->style->fill.get_value(), Glib::ustring("#cccccc")); + EXPECT_EQ(three->style->stroke.get_value(), Glib::ustring("")); + EXPECT_EQ(three->style->opacity.get_value(), Glib::ustring("1")); + EXPECT_EQ(three->style->stroke_width.get_value(), Glib::ustring("2px")); + + SPRect *four = dynamic_cast(doc->getObjectById("four")); + ASSERT_TRUE(four != nullptr); + + EXPECT_EQ(four->style->fill.get_value(), Glib::ustring("#d0d0d0")); + EXPECT_EQ(four->style->stroke.get_value(), Glib::ustring("#ff0000")); + EXPECT_EQ(four->style->opacity.get_value(), Glib::ustring("0.5")); + EXPECT_EQ(four->style->stroke_width.get_value(), Glib::ustring("2px")); +} + +TEST_F(ObjectTest, StyleSource) { + ASSERT_TRUE(doc != nullptr); + ASSERT_TRUE(doc->getRoot() != nullptr); + + SPRoot *root = doc->getRoot(); + ASSERT_TRUE(root->getRepr() != nullptr); + ASSERT_TRUE(root->hasChildren()); + + SPRect *one = dynamic_cast(doc->getObjectById("one")); + ASSERT_TRUE(one != nullptr); + + EXPECT_EQ(one->style->fill.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(one->style->stroke.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(one->style->opacity.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(one->style->stroke_width.style_src, SP_STYLE_SRC_STYLE_PROP); + + SPRect *two = dynamic_cast(doc->getObjectById("two")); + ASSERT_TRUE(two != nullptr); + + EXPECT_EQ(two->style->fill.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(two->style->stroke.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(two->style->opacity.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(two->style->stroke_width.style_src, SP_STYLE_SRC_STYLE_PROP); + + SPRect *three = dynamic_cast(doc->getObjectById("three")); + ASSERT_TRUE(three != nullptr); + + EXPECT_EQ(three->style->fill.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(three->style->stroke.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(three->style->opacity.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(three->style->stroke_width.style_src, SP_STYLE_SRC_STYLE_PROP); + + SPRect *four = dynamic_cast(doc->getObjectById("four")); + ASSERT_TRUE(four != nullptr); + + EXPECT_EQ(four->style->fill.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(four->style->stroke.style_src, SP_STYLE_SRC_STYLE_PROP); + EXPECT_EQ(four->style->opacity.style_src, SP_STYLE_SRC_STYLE_SHEET); + EXPECT_EQ(four->style->stroke_width.style_src, SP_STYLE_SRC_STYLE_PROP); + +} -- cgit v1.2.3