From db722f5b79ef1517f0b6e9a96968ad257dffc6f9 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 12 Nov 2018 19:25:05 -0500 Subject: Add capability to get style rulesets as SPStyle objects --- testfiles/CMakeLists.txt | 1 + testfiles/src/style-elem-test.cpp | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 testfiles/src/style-elem-test.cpp (limited to 'testfiles') diff --git a/testfiles/CMakeLists.txt b/testfiles/CMakeLists.txt index 1b793cb10..d19d64dce 100644 --- a/testfiles/CMakeLists.txt +++ b/testfiles/CMakeLists.txt @@ -21,6 +21,7 @@ set(TEST_SOURCES sp-object-test object-set-test object-style-test + style-elem-test style-test sp-gradient-test object-test) diff --git a/testfiles/src/style-elem-test.cpp b/testfiles/src/style-elem-test.cpp new file mode 100644 index 000000000..443c547ac --- /dev/null +++ b/testfiles/src/style-elem-test.cpp @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Test the API to the style element, access, read and write functions. + *//* + * + * Authors: + * Martin Owens + * + * Copyright (C) 2018 Authors + * + * Released under GNU GPL version 2 or later, 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 sp-style-element objects created in document. + */ +TEST_F(ObjectTest, StyleElems) { + ASSERT_TRUE(doc != nullptr); + ASSERT_TRUE(doc->getRoot() != nullptr); + + SPRoot *root = doc->getRoot(); + ASSERT_TRUE(root->getRepr() != nullptr); + + SPStyleElem *one = dynamic_cast(doc->getObjectById("style01")); + ASSERT_TRUE(one != nullptr); + + std::vector styles = one->getStyles(); + + for(auto style: styles) { + EXPECT_EQ(style->fill.get_value(), Glib::ustring("#ff0000")); + } + + SPStyleElem *two = dynamic_cast(doc->getObjectById("style02")); + ASSERT_TRUE(one != nullptr); + + std::vector styles_two = two->getStyles(); + + for(auto style: styles_two) { + EXPECT_EQ(style->fill.get_value(), Glib::ustring("#008000")); + } +} -- cgit v1.2.3