summaryrefslogtreecommitdiffstats
path: root/testfiles/src/style-elem-test.cpp
blob: c003e7b7ccf8b69a1a7e55f4a55846bacaa10aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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 <gtest/gtest.h>
#include <doc-per-case-test.h>

#include <src/style.h>
#include <src/object/sp-root.h>
#include <src/object/sp-style-elem.h>

using namespace Inkscape;
using namespace Inkscape::XML;

class ObjectTest: public DocPerCaseTest {
public:
    ObjectTest() {
        char const *docString = "\
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>\
<style id='style01'>\
rect { fill: red; opacity:0.5; }\
#id1, #id2 { fill: red; stroke: #c0c0c0; }\
.cls1 { fill: red; opacity:1.0; }\
</style>\
<style id='style02'>\
rect { fill: green; opacity:1.0; }\
#id3, #id4 { fill: green; stroke: #606060; }\
.cls2 { fill: green; opacity:0.5; }\
</style>\
</svg>";
        doc = SPDocument::createNewDocFromMem(docString, static_cast<int>(strlen(docString)), false);
    }

    ~ObjectTest() override {
        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<SPStyleElem *>(doc->getObjectById("style01"));
    ASSERT_TRUE(one != nullptr);

    for(auto style: one->styles) {
        EXPECT_EQ(style->fill.get_value(), Glib::ustring("#ff0000"));
    }

    SPStyleElem *two = dynamic_cast<SPStyleElem *>(doc->getObjectById("style02"));
    ASSERT_TRUE(one != nullptr);

    for(auto style: two->styles) {
        EXPECT_EQ(style->fill.get_value(), Glib::ustring("#008000"));
    }
}