Skip to content

Commit 73a5edb

Browse files
committed
Switch testProductResolverIndexHelper to catch2
1 parent a904771 commit 73a5edb

File tree

3 files changed

+232
-269
lines changed

3 files changed

+232
-269
lines changed

DataFormats/Provenance/test/BuildFile.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<use name="catch2"/>
99
</bin>
1010

11-
<bin name="testProductResolverIndexHelper" file="testRunner.cpp productResolverIndexHelper_t.cppunit.cc">
11+
<bin name="testProductResolverIndexHelper" file="productResolverIndexHelper_t.cpp">
1212
<use name="DataFormats/TestObjects"/>
13-
<use name="cppunit"/>
13+
<use name="catch2"/>
1414
<use name="DataFormats/Provenance"/>
1515
</bin>
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* productResolverIndexHelper_t.cppunit.cc
3+
*/
4+
#define CATCH_CONFIG_MAIN
5+
#include <catch.hpp>
6+
7+
#include "DataFormats/Provenance/interface/EventID.h"
8+
#include "DataFormats/Provenance/interface/ProductID.h"
9+
#include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
10+
#include "DataFormats/TestObjects/interface/ToyProducts.h"
11+
12+
#include "FWCore/Utilities/interface/Exception.h"
13+
#include "FWCore/Utilities/interface/ProductKindOfType.h"
14+
#include "FWCore/Utilities/interface/TypeID.h"
15+
16+
#include <iostream>
17+
#include <iomanip>
18+
19+
using namespace edm;
20+
21+
22+
23+
24+
25+
26+
TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
27+
TypeID typeID_ProductID(typeid(ProductID));
28+
TypeID typeID_EventID(typeid(EventID));
29+
30+
SECTION("CreateEmpty") {
31+
edm::ProductResolverIndexHelper helper;
32+
helper.setFrozen("processA");
33+
34+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
35+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
36+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
37+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
38+
39+
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
40+
REQUIRE(matches.numberOfMatches() == 0);
41+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
42+
REQUIRE(matches.numberOfMatches() == 0);
43+
44+
TypeID typeID(typeid(ProductID));
45+
REQUIRE_THROWS_AS(helper.insert(typeID, "labelA", "instanceA", "processA"), cms::Exception);
46+
}
47+
48+
SECTION("OneEntry") {
49+
edm::ProductResolverIndexHelper helper;
50+
51+
TypeID typeIDProductID(typeid(ProductID));
52+
helper.insert(typeIDProductID, "labelA", "instanceA", "processA");
53+
54+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
55+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
56+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
57+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
58+
59+
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
60+
REQUIRE(matches.numberOfMatches() == 0);
61+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
62+
REQUIRE(matches.numberOfMatches() == 0);
63+
64+
helper.setFrozen("processA");
65+
66+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA");
67+
REQUIRE(matches.numberOfMatches() == 2);
68+
edm::ProductResolverIndex indexEmptyProcess = matches.index(0);
69+
edm::ProductResolverIndex indexWithProcess = matches.index(1);
70+
REQUIRE_THROWS_AS(matches.index(2), cms::Exception);
71+
REQUIRE(indexEmptyProcess < 2);
72+
REQUIRE(indexWithProcess < 2);
73+
REQUIRE(indexEmptyProcess != indexWithProcess);
74+
75+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == indexEmptyProcess);
76+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == indexEmptyProcess);
77+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", 0) == indexEmptyProcess);
78+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == indexWithProcess);
79+
80+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instance", "processA") == ProductResolverIndexInvalid);
81+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceAX", "processA") == ProductResolverIndexInvalid);
82+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "label", "instanceA", "processA") == ProductResolverIndexInvalid);
83+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelAX", "instanceA", "processA") == ProductResolverIndexInvalid);
84+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "process") == ProductResolverIndexInvalid);
85+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processAX") == ProductResolverIndexInvalid);
86+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_EventID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
87+
88+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
89+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
90+
91+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
92+
REQUIRE(matches.numberOfMatches() == 2);
93+
REQUIRE(matches.index(0) == indexEmptyProcess);
94+
REQUIRE(matches.index(1) == indexWithProcess);
95+
96+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_EventID);
97+
REQUIRE(matches.numberOfMatches() == 0);
98+
99+
matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_ProductID);
100+
REQUIRE(matches.numberOfMatches() == 0);
101+
102+
matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA");
103+
REQUIRE(matches.numberOfMatches() == 0);
104+
105+
{
106+
auto indexToModules = helper.indiciesForModulesInProcess("processA");
107+
REQUIRE(indexToModules.size() == 1);
108+
REQUIRE(indexToModules.count("labelA") == 1);
109+
auto const& range = indexToModules.equal_range("labelA");
110+
REQUIRE(std::get<2>(range.first->second) == indexWithProcess);
111+
}
112+
113+
{
114+
auto indexToModules = helper.indiciesForModulesInProcess("processNotHere");
115+
REQUIRE(indexToModules.size() == 0);
116+
}
117+
}
118+
119+
SECTION("ManyEntries") {
120+
edm::ProductResolverIndexHelper helper;
121+
122+
TypeID typeIDProductID(typeid(ProductID));
123+
TypeID typeIDEventID(typeid(EventID));
124+
TypeID typeIDVectorInt(typeid(std::vector<int>));
125+
TypeID typeIDSetInt(typeid(std::set<int>));
126+
TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
127+
128+
helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC"); // 0, 1, 2
129+
helper.insert(typeIDVectorInt, "label", "instance", "process"); // 3, 4, 5
130+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB"); // 6, 7
131+
helper.insert(typeIDEventID, "label", "instanceB", "processB"); // 8, 9
132+
helper.insert(typeIDEventID, "labelX", "instanceB", "processB"); // 10, 11
133+
helper.insert(typeIDEventID, "labelB", "instance", "processB"); // 12, 13
134+
helper.insert(typeIDEventID, "labelB", "instanceX", "processB"); // 14, 15
135+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB1"); // 16, 5
136+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB3"); // 17, 5
137+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB2"); // 18, 5
138+
helper.insert(typeIDProductID, "label", "instance", "process"); // 19, 20
139+
helper.insert(typeIDEventID, "label", "instance", "process"); // 21, 22
140+
helper.insert(typeIDProductID, "labelA", "instanceA", "processA"); // 23, 24
141+
REQUIRE_THROWS_AS(helper.insert(typeIDProductID, "labelA", "instanceA", "processA"), cms::Exception); // duplicate
142+
143+
helper.insert(typeIDSetInt, "labelC", "instanceC", "processC"); // 25, 26
144+
145+
helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC"); // 27, 28, 29, 30
146+
147+
helper.setFrozen("processC");
148+
149+
TypeID typeID_int(typeid(int));
150+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processC") == ProductResolverIndexAmbiguous);
151+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processQ") == ProductResolverIndexInvalid);
152+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC") == 2);
153+
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_int);
154+
REQUIRE(matches.numberOfMatches() == 4);
155+
REQUIRE(matches.index(0) == 5);
156+
REQUIRE(matches.index(1) == 3);
157+
REQUIRE(matches.index(2) == 2);
158+
REQUIRE(matches.index(3) == ProductResolverIndexAmbiguous);
159+
160+
TypeID typeID_vint(typeid(std::vector<int>));
161+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", "processC") == 0);
162+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC") == 1);
163+
164+
TypeID typeID_sint(typeid(std::set<int>));
165+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC", "processC") == 25);
166+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC") == 26);
167+
168+
TypeID typeID_Simple(typeid(edmtest::Simple));
169+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC") == 30);
170+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC", "processC") == 27);
171+
172+
TypeID typeID_SimpleDerived(typeid(edmtest::SimpleDerived));
173+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC") == 29);
174+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC", "processC") == 27);
175+
176+
TypeID typeID_VSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
177+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC") == 28);
178+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC", "processC") == 27);
179+
180+
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_EventID, "labelB", "instanceB");
181+
REQUIRE(matches.numberOfMatches() == 5);
182+
ProductResolverIndex indexEmptyProcess = matches.index(0);
183+
ProductResolverIndex indexB = matches.index(1);
184+
ProductResolverIndex indexB1 = matches.index(2);
185+
ProductResolverIndex indexB2 = matches.index(3);
186+
ProductResolverIndex indexB3 = matches.index(4);
187+
REQUIRE_THROWS_AS(matches.index(5), cms::Exception);
188+
REQUIRE(indexEmptyProcess == 7);
189+
REQUIRE(indexB == 6);
190+
REQUIRE(indexB1 == 16);
191+
REQUIRE(indexB2 == 18);
192+
REQUIRE(indexB3 == 17);
193+
194+
REQUIRE(std::string(matches.moduleLabel(4)) == "labelB");
195+
REQUIRE(std::string(matches.productInstanceName(4)) == "instanceB");
196+
REQUIRE(std::string(matches.processName(4)) == "processB3");
197+
REQUIRE(std::string(matches.processName(0)) == "");
198+
199+
matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_Simple);
200+
REQUIRE(matches.numberOfMatches() == 2);
201+
ProductResolverIndex indexC = matches.index(1);
202+
REQUIRE_THROWS_AS(matches.index(2), cms::Exception);
203+
REQUIRE(indexC == 27);
204+
205+
{
206+
auto indexToModules = helper.indiciesForModulesInProcess("processA");
207+
REQUIRE(indexToModules.size() == 1);
208+
}
209+
{
210+
auto indexToModules = helper.indiciesForModulesInProcess("processB");
211+
REQUIRE(indexToModules.size() == 5);
212+
}
213+
{
214+
auto indexToModules = helper.indiciesForModulesInProcess("processB1");
215+
REQUIRE(indexToModules.size() == 1);
216+
}
217+
{
218+
auto indexToModules = helper.indiciesForModulesInProcess("processB2");
219+
REQUIRE(indexToModules.size() == 1);
220+
}
221+
{
222+
auto indexToModules = helper.indiciesForModulesInProcess("processB3");
223+
REQUIRE(indexToModules.size() == 1);
224+
}
225+
{
226+
auto indexToModules = helper.indiciesForModulesInProcess("processC");
227+
REQUIRE(indexToModules.size() == 3);
228+
}
229+
}
230+
}

0 commit comments

Comments
 (0)