@@ -170,7 +170,7 bool DataSourceItem::operator==(const DataSourceItem &other) | |||||
170 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { |
|
170 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { | |
171 | // Compares contents of items' children |
|
171 | // Compares contents of items' children | |
172 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), |
|
172 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), | |
173 | std::cbegin(other.impl->m_Children), |
|
173 | std::cbegin(other.impl->m_Children), std::cend(other.impl->m_Children), | |
174 | [](const auto &itemChild, const auto &otherChild) { |
|
174 | [](const auto &itemChild, const auto &otherChild) { | |
175 | return *itemChild == *otherChild; |
|
175 | return *itemChild == *otherChild; | |
176 | }); |
|
176 | }); |
@@ -1,5 +1,7 | |||||
1 | #include <DataSource/DataSourceItem.h> |
|
1 | #include <DataSource/DataSourceItem.h> | |
2 |
|
2 | |||
|
3 | #include "DataSourceItemBuilder.h" | |||
|
4 | ||||
3 | #include <QObject> |
|
5 | #include <QObject> | |
4 | #include <QtTest> |
|
6 | #include <QtTest> | |
5 |
|
7 | |||
@@ -43,7 +45,140 void TestDataSourceItem::testMerge_data() | |||||
43 | QTest::addColumn<std::shared_ptr<DataSourceItem> >("dest"); |
|
45 | QTest::addColumn<std::shared_ptr<DataSourceItem> >("dest"); | |
44 | QTest::addColumn<std::shared_ptr<DataSourceItem> >("expectedResult"); |
|
46 | QTest::addColumn<std::shared_ptr<DataSourceItem> >("expectedResult"); | |
45 |
|
47 | |||
46 | /// @todo ALX: adds test cases |
|
48 | QTest::newRow("merge (basic case)") << DataSourceItemBuilder{} | |
|
49 | .root("A2") | |||
|
50 | .node("- B2") | |||
|
51 | .product("-- P2") | |||
|
52 | .end() // P2 | |||
|
53 | .end() // B2 | |||
|
54 | .end() // A2 | |||
|
55 | .build() | |||
|
56 | << DataSourceItemBuilder{} | |||
|
57 | .root("A1") | |||
|
58 | .node("- B1") | |||
|
59 | .product("-- P1") | |||
|
60 | .end() // P1 | |||
|
61 | .end() // B1 | |||
|
62 | .end() // A1 | |||
|
63 | .build() | |||
|
64 | << DataSourceItemBuilder{} | |||
|
65 | .root("A1") | |||
|
66 | .node("- B1") | |||
|
67 | .product("-- P1") | |||
|
68 | .end() // P1 | |||
|
69 | .end() // B1 | |||
|
70 | .node("- B2") | |||
|
71 | .product("-- P2") | |||
|
72 | .end() // P2 | |||
|
73 | .end() // B2 | |||
|
74 | .end() // A1 | |||
|
75 | .build(); | |||
|
76 | ||||
|
77 | QTest::newRow("merge (some of the source and destination trees are identical)") | |||
|
78 | << DataSourceItemBuilder{} | |||
|
79 | .root("A2") | |||
|
80 | .node("- B1") | |||
|
81 | .node("-- C1") | |||
|
82 | .product("--- P2") | |||
|
83 | .end() // P2 | |||
|
84 | .end() // C1 | |||
|
85 | .node("-- C2") | |||
|
86 | .end() // C2 | |||
|
87 | .end() // B1 | |||
|
88 | .end() // A2 | |||
|
89 | .build() | |||
|
90 | << DataSourceItemBuilder{} | |||
|
91 | .root("A1") | |||
|
92 | .node("- B1") | |||
|
93 | .node("-- C1") | |||
|
94 | .product("--- P1") | |||
|
95 | .end() // P1 | |||
|
96 | .end() // C1 | |||
|
97 | .end() // B1 | |||
|
98 | .end() // A1 | |||
|
99 | .build() | |||
|
100 | << DataSourceItemBuilder{} | |||
|
101 | .root("A1") | |||
|
102 | .node("- B1") | |||
|
103 | .node("-- C1") | |||
|
104 | .product("--- P1") | |||
|
105 | .end() // P1 | |||
|
106 | .product("--- P2") | |||
|
107 | .end() // P2 | |||
|
108 | .end() // C1 | |||
|
109 | .node("-- C2") | |||
|
110 | .end() // C2 | |||
|
111 | .end() // B1 | |||
|
112 | .end() // A1 | |||
|
113 | .build(); | |||
|
114 | ||||
|
115 | QTest::newRow("merge (products with the same name and tree are kept)") | |||
|
116 | << DataSourceItemBuilder{} | |||
|
117 | .root("A2") | |||
|
118 | .node("- B1") | |||
|
119 | .node("-- C1") | |||
|
120 | .product({{"name", "--- P1"}, {"from", "source"}}) | |||
|
121 | .end() // P1 | |||
|
122 | .end() // C1 | |||
|
123 | .end() // B1 | |||
|
124 | .end() // A2 | |||
|
125 | .build() | |||
|
126 | << DataSourceItemBuilder{} | |||
|
127 | .root("A1") | |||
|
128 | .node("- B1") | |||
|
129 | .node("-- C1") | |||
|
130 | .product({{"name", "--- P1"}, {"from", "dest"}}) | |||
|
131 | .end() // P1 | |||
|
132 | .end() // C1 | |||
|
133 | .end() // B1 | |||
|
134 | .end() // A1 | |||
|
135 | .build() | |||
|
136 | << DataSourceItemBuilder{} | |||
|
137 | .root("A1") | |||
|
138 | .node("- B1") | |||
|
139 | .node("-- C1") | |||
|
140 | .product({{"name", "--- P1"}, {"from", "dest"}}) | |||
|
141 | .end() // P1 (dest) | |||
|
142 | .product({{"name", "--- P1"}, {"from", "source"}}) | |||
|
143 | .end() // P1 (source) | |||
|
144 | .end() // C1 | |||
|
145 | .end() // B1 | |||
|
146 | .end() // A1 | |||
|
147 | .build(); | |||
|
148 | ||||
|
149 | QTest::newRow("merge (for same nodes, metadata of dest node are kept)") | |||
|
150 | << DataSourceItemBuilder{} | |||
|
151 | .root("A2") | |||
|
152 | .node("- B1") | |||
|
153 | .node({{"name", "-- C1"}, {"from", "source"}}) | |||
|
154 | .product("--- P2") | |||
|
155 | .end() // P1 | |||
|
156 | .end() // C1 | |||
|
157 | .end() // B1 | |||
|
158 | .end() // A2 | |||
|
159 | .build() | |||
|
160 | << DataSourceItemBuilder{} | |||
|
161 | .root("A1") | |||
|
162 | .node("- B1") | |||
|
163 | .node({{"name", "-- C1"}, {"from", "dest"}}) | |||
|
164 | .product("--- P1") | |||
|
165 | .end() // P1 | |||
|
166 | .end() // C1 | |||
|
167 | .end() // B1 | |||
|
168 | .end() // A1 | |||
|
169 | .build() | |||
|
170 | << DataSourceItemBuilder{} | |||
|
171 | .root("A1") | |||
|
172 | .node("- B1") | |||
|
173 | .node({{"name", "-- C1"}, {"from", "dest"}}) | |||
|
174 | .product("--- P1") | |||
|
175 | .end() // P1 | |||
|
176 | .product("--- P2") | |||
|
177 | .end() // P2 | |||
|
178 | .end() // C1 (dest) | |||
|
179 | .end() // B1 | |||
|
180 | .end() // A1 | |||
|
181 | .build(); | |||
47 | } |
|
182 | } | |
48 |
|
183 | |||
49 | void TestDataSourceItem::testMerge() |
|
184 | void TestDataSourceItem::testMerge() |
General Comments 0
You need to be logged in to leave comments.
Login now