Line data Source code
1 : #include "artdaq-core/Data/ContainerFragmentLoader.hh"
2 : #include "artdaq-core/Plugins/FragmentNameHelper.hh"
3 :
4 : #define BOOST_TEST_MODULE(FragmentNameHelper_t)
5 : #include <cetlib/quiet_unit_test.hpp>
6 :
7 : BOOST_AUTO_TEST_SUITE(FragmentNameHelper_test)
8 :
9 2 : BOOST_AUTO_TEST_CASE(FNH_Construct)
10 : {
11 5 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
12 1 : auto names = helper->GetAllProductInstanceNames();
13 1 : BOOST_REQUIRE(names.size() > 0);
14 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
15 :
16 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
17 1 : }
18 :
19 2 : BOOST_AUTO_TEST_CASE(FNH_ExtraTypesInConstructor)
20 : {
21 1 : auto extraType = std::make_pair(artdaq::Fragment::FirstUserFragmentType, "Test");
22 :
23 7 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {extraType});
24 1 : auto names = helper->GetAllProductInstanceNames();
25 1 : BOOST_REQUIRE(names.size() > 0);
26 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
27 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType), "Test");
28 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType + 2), "testunidentified");
29 :
30 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
31 2 : }
32 :
33 2 : BOOST_AUTO_TEST_CASE(FNH_ExtraTypesOverwriteInConstructor)
34 : {
35 1 : auto extraType = std::make_pair(artdaq::Fragment::DataFragmentType, "Test");
36 :
37 7 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {extraType});
38 1 : auto names = helper->GetAllProductInstanceNames();
39 1 : BOOST_REQUIRE(names.size() > 0);
40 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Test");
41 :
42 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
43 2 : }
44 :
45 2 : BOOST_AUTO_TEST_CASE(FNH_ExtraTypesMethod)
46 : {
47 5 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
48 1 : auto names = helper->GetAllProductInstanceNames();
49 1 : BOOST_REQUIRE(names.size() > 0);
50 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
51 :
52 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
53 :
54 3 : helper->AddExtraType(artdaq::Fragment::FirstUserFragmentType, "Test");
55 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::FirstUserFragmentType), "Test");
56 1 : }
57 :
58 2 : BOOST_AUTO_TEST_CASE(FNH_ExtraTypesOverwriteMethod)
59 : {
60 5 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
61 1 : auto names = helper->GetAllProductInstanceNames();
62 1 : BOOST_REQUIRE(names.size() > 0);
63 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
64 :
65 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
66 :
67 3 : helper->AddExtraType(artdaq::Fragment::DataFragmentType, "Test");
68 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Test");
69 1 : }
70 :
71 2 : BOOST_AUTO_TEST_CASE(FNH_DecodeFragment)
72 : {
73 5 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
74 1 : auto names = helper->GetAllProductInstanceNames();
75 1 : BOOST_REQUIRE(names.size() > 0);
76 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
77 :
78 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
79 :
80 1 : artdaq::Fragment frag(1, 2, artdaq::Fragment::DataFragmentType, 3);
81 :
82 1 : auto res = helper->GetInstanceNameForFragment(frag);
83 1 : BOOST_REQUIRE_EQUAL(res.first, true);
84 1 : BOOST_REQUIRE_EQUAL(res.second, "Data");
85 :
86 1 : frag.setUserType(artdaq::Fragment::FirstUserFragmentType + 2);
87 1 : res = helper->GetInstanceNameForFragment(frag);
88 1 : BOOST_REQUIRE_EQUAL(res.first, false);
89 1 : BOOST_REQUIRE_EQUAL(res.second, "testunidentified");
90 1 : }
91 :
92 2 : BOOST_AUTO_TEST_CASE(FNH_DecodeContainerFragment)
93 : {
94 5 : auto helper = artdaq::makeNameHelper("Artdaq", "testunidentified", {});
95 1 : auto names = helper->GetAllProductInstanceNames();
96 1 : BOOST_REQUIRE(names.size() > 0);
97 1 : BOOST_REQUIRE_EQUAL(helper->GetInstanceNameForType(artdaq::Fragment::DataFragmentType), "Data");
98 :
99 1 : BOOST_REQUIRE_EQUAL(helper->GetUnidentifiedInstanceName(), "testunidentified");
100 :
101 1 : artdaq::Fragment frag;
102 1 : artdaq::ContainerFragmentLoader cfl(frag, artdaq::Fragment::DataFragmentType);
103 1 : auto res = helper->GetInstanceNameForFragment(frag);
104 1 : BOOST_REQUIRE_EQUAL(res.first, true);
105 1 : BOOST_REQUIRE_EQUAL(res.second, "ContainerData");
106 1 : }
107 :
108 : BOOST_AUTO_TEST_SUITE_END()
|