From e4a018e667abfb1fa4f2b7f36dcbfb9f80f9d92b Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Mon, 12 Feb 2024 15:39:20 -0600 Subject: [PATCH] Added test for PSet description wildcard with plugin Also changed the unit test to use catch2. --- FWCore/ParameterSet/test/BuildFile.xml | 5 - ... => test_catch_ParameterSetDescription.cc} | 1306 +++++++---------- 2 files changed, 536 insertions(+), 775 deletions(-) rename FWCore/ParameterSet/test/{parameterSetDescription_t.cc => test_catch_ParameterSetDescription.cc} (60%) diff --git a/FWCore/ParameterSet/test/BuildFile.xml b/FWCore/ParameterSet/test/BuildFile.xml index f46a56b75d474..af77e27b94d1c 100644 --- a/FWCore/ParameterSet/test/BuildFile.xml +++ b/FWCore/ParameterSet/test/BuildFile.xml @@ -2,11 +2,6 @@ - - - - - diff --git a/FWCore/ParameterSet/test/parameterSetDescription_t.cc b/FWCore/ParameterSet/test/test_catch_ParameterSetDescription.cc similarity index 60% rename from FWCore/ParameterSet/test/parameterSetDescription_t.cc rename to FWCore/ParameterSet/test/test_catch_ParameterSetDescription.cc index f6a888284cdc8..af7e9eb2891cf 100644 --- a/FWCore/ParameterSet/test/parameterSetDescription_t.cc +++ b/FWCore/ParameterSet/test/test_catch_ParameterSetDescription.cc @@ -2,6 +2,8 @@ // Test code for the ParameterSetDescription and ParameterDescription // classes. +#include "catch.hpp" + #include "DataFormats/Provenance/interface/EventID.h" #include "DataFormats/Provenance/interface/LuminosityBlockID.h" #include "FWCore/ParameterSet/interface/AllowedLabelsDescription.h" @@ -34,22 +36,38 @@ namespace testParameterSetDescription { edm::ParameterSet& pset, bool exists, bool validates) { - assert(node.exists(pset) == exists); - assert(node.partiallyExists(pset) == exists); - assert(node.howManyXORSubNodesExist(pset) == (exists ? 1 : 0)); + CHECK(node.exists(pset) == exists); + CHECK(node.partiallyExists(pset) == exists); + CHECK(node.howManyXORSubNodesExist(pset) == (exists ? 1 : 0)); if (validates) { psetDesc.validate(pset); } else { - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } } - void testWildcards() { + struct TestPluginBase { + virtual ~TestPluginBase() = default; + }; + + struct ATestPlugin : public TestPluginBase { + static void fillPSetDescription(edm::ParameterSetDescription& iPS) { iPS.add("anInt", 5); } + }; + + struct BTestPlugin : public TestPluginBase { + static void fillPSetDescription(edm::ParameterSetDescription& iPS) { iPS.add("aDouble", 0.5); } + }; + + using TestPluginFactory = edmplugin::PluginFactory; + +} // namespace testParameterSetDescription + +using TestPluginFactory = testParameterSetDescription::TestPluginFactory; + +using testParameterSetDescription::testDesc; + +TEST_CASE("test ParameterSetDescription", "[ParameterSetDescription]") { + SECTION("testWildcards") { { edm::ParameterSetDescription set; edm::ParameterWildcard w("*", edm::RequireZeroOrMore, true); @@ -117,20 +135,10 @@ namespace testParameterSetDescription { edm::ParameterWildcard w("*", edm::RequireAtLeastOne, true); set.addNode(w); set.add("testTypeChecking1", 11); - try { - set.add("testTypeChecking2", 11.0); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } + REQUIRE_THROWS_AS(set.add("testTypeChecking2", 11.0), edm::Exception); } - try { - edm::ParameterWildcard wrong("a*", edm::RequireZeroOrMore, true); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } + REQUIRE_THROWS_AS(edm::ParameterWildcard("a*", edm::RequireZeroOrMore, true), edm::Exception); edm::ParameterSet nestedPset; nestedPset.addUntrackedParameter("n1", 1); @@ -293,11 +301,9 @@ namespace testParameterSetDescription { pset.addParameter>("nested2", nestedVPset); testDesc(w, set, pset, true, true); } - - return; } - void testWildcardWithExceptions() { + SECTION("testWildcardWithExceptions") { { edm::ParameterSetDescription set; @@ -347,77 +353,62 @@ namespace testParameterSetDescription { // --------------------------------------------------------------------------------- - void testAllowedValues() { + SECTION("testAllowedValues") { // Duplicate case values not allowed edm::ParameterSetDescription psetDesc; psetDesc.ifValue(edm::ParameterDescription("sswitch", "a", true), edm::allowedValues("a", "h", "z")); } - void testSwitch() { + SECTION("testSwitch") { // Duplicate case values not allowed edm::ParameterSetDescription psetDesc; - try { - psetDesc.ifValue(edm::ParameterDescription("oiswitch", 1, true), - 0 >> edm::ParameterDescription("oivalue", 100, true) or - 1 >> (edm::ParameterDescription("oivalue1", 101.0, true) and - edm::ParameterDescription("oivalue2", 101.0, true)) or - 1 >> edm::ParameterDescription("oivalue", "102", true)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.ifValue(edm::ParameterDescription("oiswitch", 1, true), + 0 >> edm::ParameterDescription("oivalue", 100, true) or + 1 >> (edm::ParameterDescription("oivalue1", 101.0, true) and + edm::ParameterDescription("oivalue2", 101.0, true)) or + 1 >> edm::ParameterDescription("oivalue", "102", true)), + edm::Exception); // Types used in case parameters cannot duplicate type already used in a wildcard edm::ParameterSetDescription psetDesc1; edm::ParameterWildcard w("*", edm::RequireAtLeastOne, true); psetDesc1.addNode(w); - try { - psetDesc1.ifValue(edm::ParameterDescription("oiswitch", 1, true), - 0 >> edm::ParameterDescription("oivalue", 100, true) or - 1 >> (edm::ParameterDescription("oivalue1", 101.0, true) and - edm::ParameterDescription("oivalue2", 101.0, true)) or - 2 >> edm::ParameterDescription("oivalue", "102", true)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc1.ifValue(edm::ParameterDescription("oiswitch", 1, true), + 0 >> edm::ParameterDescription("oivalue", 100, true) or + 1 >> (edm::ParameterDescription("oivalue1", 101.0, true) and + edm::ParameterDescription("oivalue2", 101.0, true)) or + 2 >> edm::ParameterDescription("oivalue", "102", true)), + edm::Exception); // Types used in the switch parameter cannot duplicate type already used in a wildcard edm::ParameterSetDescription psetDesc2; edm::ParameterWildcard w1("*", edm::RequireAtLeastOne, true); psetDesc2.addNode(w1); - try { - psetDesc2.ifValue(edm::ParameterDescription("aswitch", 1, true), - 1 >> (edm::ParameterDescription("avalue1", 101, true) and - edm::ParameterDescription("avalue2", 101, true)) or - 2 >> edm::ParameterDescription("avalue", "102", true)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.ifValue(edm::ParameterDescription("aswitch", 1, true), + 1 >> (edm::ParameterDescription("avalue1", 101, true) and + edm::ParameterDescription("avalue2", 101, true)) or + 2 >> edm::ParameterDescription("avalue", "102", true)), + edm::Exception); // Type used in the switch parameter cannot duplicate type in a case wildcard edm::ParameterSetDescription psetDesc3; - try { - psetDesc3.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))), + edm::Exception); // Type used in a parameter cannot duplicate type in a case wildcard edm::ParameterSetDescription psetDesc4; psetDesc4.add("testunsigned", 1U); - try { - psetDesc4.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc4.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))), + edm::Exception); // No problem is wildcard type and parameter type are the same for different cases. edm::ParameterSetDescription psetDesc5; @@ -429,51 +420,39 @@ namespace testParameterSetDescription { // The switch parameter label cannot be the same as a label that already exists edm::ParameterSetDescription psetDesc6; psetDesc6.add("xswitch", 1U); - try { - psetDesc6.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc6.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))), + edm::Exception); // Case labels cannot be the same as a label that already exists edm::ParameterSetDescription psetDesc7; psetDesc7.add("xvalue1", 1U); - try { - psetDesc7.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc7.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))), + edm::Exception); // Case labels cannot be the same as a switch label edm::ParameterSetDescription psetDesc8; - try { - psetDesc8.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xswitch", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc8.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xswitch", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))), + edm::Exception); // Parameter set switch value must be one of the defined cases edm::ParameterSetDescription psetDesc9; - try { - psetDesc9.ifValue(edm::ParameterDescription("xswitch", 1, true), - 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or - 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and - edm::ParameterDescription("xvalue2", 101.0, true))); - edm::ParameterSet pset; - pset.addParameter("xswitch", 5); - psetDesc9.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + + psetDesc9.ifValue(edm::ParameterDescription("xswitch", 1, true), + 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or + 1 >> (edm::ParameterDescription("xvalue1", 101.0, true) and + edm::ParameterDescription("xvalue2", 101.0, true))); + edm::ParameterSet pset; + pset.addParameter("xswitch", 5); + REQUIRE_THROWS_AS(psetDesc9.validate(pset), edm::Exception); edm::ParameterSwitch pswitch(edm::ParameterDescription("xswitch", 1, true), 0 >> edm::ParameterWildcard("*", edm::RequireAtLeastOne, true) or @@ -489,7 +468,7 @@ namespace testParameterSetDescription { // --------------------------------------------------------------------------------- - void testXor() { + SECTION("testXor") { edm::ParameterSetDescription psetDesc1; std::unique_ptr node1( edm::ParameterDescription("x1", 101.0, true) xor @@ -504,28 +483,20 @@ namespace testParameterSetDescription { pset2.addParameter("x1", 11.0); pset2.addParameter("x2", 12.0); - assert(node1->exists(pset1) == false); - assert(node1->partiallyExists(pset1) == false); - assert(node1->howManyXORSubNodesExist(pset1) == 0); + CHECK(node1->exists(pset1) == false); + CHECK(node1->partiallyExists(pset1) == false); + CHECK(node1->howManyXORSubNodesExist(pset1) == 0); - assert(node1->exists(pset2) == false); - assert(node1->partiallyExists(pset2) == false); - assert(node1->howManyXORSubNodesExist(pset2) == 4); + CHECK(node1->exists(pset2) == false); + CHECK(node1->partiallyExists(pset2) == false); + CHECK(node1->howManyXORSubNodesExist(pset2) == 4); // 0 of the options existing should fail validation psetDesc1.addNode(std::move(node1)); - try { - psetDesc1.validate(pset1); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc1.validate(pset1), edm::Exception); // More than one of the options existing should also fail - try { - psetDesc1.validate(pset2); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc1.validate(pset2), edm::Exception); // One of the labels cannot already exist in the description edm::ParameterSetDescription psetDesc2; @@ -536,11 +507,7 @@ namespace testParameterSetDescription { edm::ParameterDescription("x1", 101.0, true) xor (edm::ParameterDescription("xvalue1", 101.0, true) or edm::ParameterDescription("x2", 101.0, true))); - try { - psetDesc2.addNode(std::move(node2)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.addNode(std::move(node2)), edm::Exception); // One of the labels cannot already exist in the description, other order edm::ParameterSetDescription psetDesc3; @@ -551,11 +518,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("xvalue1", 101.0, true) or edm::ParameterDescription("x2", 101.0, true))); psetDesc3.addNode(std::move(node3)); - try { - psetDesc3.add("xvalue1", 1U); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.add("xvalue1", 1U), edm::Exception); // A parameter cannot use the same type as a wildcard edm::ParameterSetDescription psetDesc4; @@ -568,11 +531,7 @@ namespace testParameterSetDescription { psetDesc4.addNode(std::move(node4)); edm::ParameterWildcard w4("*", edm::RequireAtLeastOne, true); - try { - psetDesc4.addNode(w4); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc4.addNode(w4), edm::Exception); // A parameter cannot use the same type as a wildcard edm::ParameterSetDescription psetDesc5; @@ -586,16 +545,12 @@ namespace testParameterSetDescription { psetDesc5.addNode(std::move(node5)); edm::ParameterDescription n5("z5", edm::RequireAtLeastOne, true); - try { - psetDesc5.addNode(n5); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc5.addNode(n5), edm::Exception); } // --------------------------------------------------------------------------------- - void testOr() { + SECTION("testOr") { edm::ParameterSetDescription psetDesc1; std::unique_ptr node1(edm::ParameterDescription("x1", 101.0, true) or (edm::ParameterDescription("x2", 101.0, true) and @@ -613,13 +568,13 @@ namespace testParameterSetDescription { pset2.addParameter("x4", 14.0); pset2.addParameter("x5", 15.0); - assert(node1->exists(pset1) == false); - assert(node1->partiallyExists(pset1) == false); - assert(node1->howManyXORSubNodesExist(pset1) == 0); + CHECK(node1->exists(pset1) == false); + CHECK(node1->partiallyExists(pset1) == false); + CHECK(node1->howManyXORSubNodesExist(pset1) == 0); - assert(node1->exists(pset2) == true); - assert(node1->partiallyExists(pset2) == true); - assert(node1->howManyXORSubNodesExist(pset2) == 1); + CHECK(node1->exists(pset2) == true); + CHECK(node1->partiallyExists(pset2) == true); + CHECK(node1->howManyXORSubNodesExist(pset2) == 1); // 0 of the options existing should fail validation psetDesc1.addNode(std::move(node1)); @@ -635,11 +590,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) and edm::ParameterDescription("x3", 101.0, true)) or edm::ParameterDescription("x4", 101.0, true)); - try { - psetDesc2.addNode(std::move(node2)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.addNode(std::move(node2)), edm::Exception); // One of the labels cannot already exist in the description, other order edm::ParameterSetDescription psetDesc3; @@ -649,11 +600,7 @@ namespace testParameterSetDescription { edm::ParameterDescription("x4", 101.0, true)); psetDesc3.addNode(std::move(node3)); - try { - psetDesc3.add("x1", 1U); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.add("x1", 1U), edm::Exception); // Put the duplicate labels in different nodes of the "or" expression edm::ParameterSetDescription psetDesc4; @@ -661,11 +608,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) and edm::ParameterDescription("x3", 101.0, true)) or edm::ParameterDescription("x1", 101.0, true)); - try { - psetDesc4.addNode(std::move(node4)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc4.addNode(std::move(node4)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter @@ -675,11 +618,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) and edm::ParameterDescription("x3", 101U, true)) or edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc5.addNode(std::move(node5)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc5.addNode(std::move(node5)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -690,11 +629,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101U, true) and edm::ParameterDescription("x3", 101U, true)) or edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc6.addNode(std::move(node6)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc6.addNode(std::move(node6)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -704,16 +639,12 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101U, true) and edm::ParameterDescription("x3", 101U, true)) or edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc7.addNode(std::move(node7)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc7.addNode(std::move(node7)), edm::Exception); } // --------------------------------------------------------------------------------- - void testAnd() { + SECTION("testAnd") { edm::ParameterSetDescription psetDesc1; std::unique_ptr node1(edm::ParameterDescription("x1", 101.0, true) and (edm::ParameterDescription("x2", 101.0, true) or @@ -734,17 +665,17 @@ namespace testParameterSetDescription { edm::ParameterSet pset3; pset3.addParameter("x3", 13.0); - assert(node1->exists(pset1) == false); - assert(node1->partiallyExists(pset1) == false); - assert(node1->howManyXORSubNodesExist(pset1) == 0); + CHECK(node1->exists(pset1) == false); + CHECK(node1->partiallyExists(pset1) == false); + CHECK(node1->howManyXORSubNodesExist(pset1) == 0); - assert(node1->exists(pset2) == true); - assert(node1->partiallyExists(pset2) == true); - assert(node1->howManyXORSubNodesExist(pset2) == 1); + CHECK(node1->exists(pset2) == true); + CHECK(node1->partiallyExists(pset2) == true); + CHECK(node1->howManyXORSubNodesExist(pset2) == 1); - assert(node1->exists(pset3) == false); - assert(node1->partiallyExists(pset3) == true); - assert(node1->howManyXORSubNodesExist(pset3) == 0); + CHECK(node1->exists(pset3) == false); + CHECK(node1->partiallyExists(pset3) == true); + CHECK(node1->howManyXORSubNodesExist(pset3) == 0); psetDesc1.addNode(std::move(node1)); psetDesc1.validate(pset1); @@ -758,11 +689,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) or edm::ParameterDescription("x3", 101.0, true)) and edm::ParameterDescription("x4", 101.0, true)); - try { - psetDesc2.addNode(std::move(node2)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.addNode(std::move(node2)), edm::Exception); // One of the labels cannot already exist in the description, other order edm::ParameterSetDescription psetDesc3; @@ -772,11 +699,7 @@ namespace testParameterSetDescription { edm::ParameterDescription("x4", 101.0, true)); psetDesc3.addNode(std::move(node3)); - try { - psetDesc3.add("x1", 1U); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.add("x1", 1U), edm::Exception); // Put the duplicate labels in different nodes of the "and" expression edm::ParameterSetDescription psetDesc4; @@ -784,11 +707,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) or edm::ParameterDescription("x3", 101.0, true)) and edm::ParameterDescription("x1", 101.0, true)); - try { - psetDesc4.addNode(std::move(node4)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc4.addNode(std::move(node4)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter @@ -798,11 +717,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) or edm::ParameterDescription("x3", 101U, true)) and edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc5.addNode(std::move(node5)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc5.addNode(std::move(node5)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -813,11 +728,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101U, true) or edm::ParameterDescription("x3", 101U, true)) and edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc6.addNode(std::move(node6)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc6.addNode(std::move(node6)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -827,16 +738,12 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101U, true) or edm::ParameterDescription("x3", 101U, true)) and edm::ParameterDescription("x1", 101U, true)); - try { - psetDesc7.addNode(std::move(node7)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc7.addNode(std::move(node7)), edm::Exception); } // --------------------------------------------------------------------------------- - void testIfExists() { + SECTION("testIfExists") { edm::ParameterSetDescription psetDesc1; std::unique_ptr node1( std::make_unique(edm::ParameterDescription("x1", 101.0, true), @@ -866,29 +773,29 @@ namespace testParameterSetDescription { pset4.addParameter("x2", 15.0); pset4.addParameter("x3", 16.0); - assert(node1->exists(pset1) == true); - assert(node1->partiallyExists(pset1) == true); - assert(node1->howManyXORSubNodesExist(pset1) == 1); - assert(node1a->exists(pset1) == true); - assert(node1b->exists(pset1) == true); - - assert(node1->exists(pset2) == true); - assert(node1->partiallyExists(pset2) == true); - assert(node1->howManyXORSubNodesExist(pset2) == 1); - assert(node1a->exists(pset2) == true); - assert(node1b->exists(pset2) == true); - - assert(node1->exists(pset3) == false); - assert(node1->partiallyExists(pset3) == false); - assert(node1->howManyXORSubNodesExist(pset3) == 0); - assert(node1a->exists(pset3) == false); - assert(node1b->exists(pset3) == false); - - assert(node1->exists(pset4) == false); - assert(node1->partiallyExists(pset4) == false); - assert(node1->howManyXORSubNodesExist(pset4) == 0); - assert(node1a->exists(pset4) == false); - assert(node1b->exists(pset4) == false); + CHECK(node1->exists(pset1) == true); + CHECK(node1->partiallyExists(pset1) == true); + CHECK(node1->howManyXORSubNodesExist(pset1) == 1); + CHECK(node1a->exists(pset1) == true); + CHECK(node1b->exists(pset1) == true); + + CHECK(node1->exists(pset2) == true); + CHECK(node1->partiallyExists(pset2) == true); + CHECK(node1->howManyXORSubNodesExist(pset2) == 1); + CHECK(node1a->exists(pset2) == true); + CHECK(node1b->exists(pset2) == true); + + CHECK(node1->exists(pset3) == false); + CHECK(node1->partiallyExists(pset3) == false); + CHECK(node1->howManyXORSubNodesExist(pset3) == 0); + CHECK(node1a->exists(pset3) == false); + CHECK(node1b->exists(pset3) == false); + + CHECK(node1->exists(pset4) == false); + CHECK(node1->partiallyExists(pset4) == false); + CHECK(node1->howManyXORSubNodesExist(pset4) == 0); + CHECK(node1a->exists(pset4) == false); + CHECK(node1b->exists(pset4) == false); psetDesc1.addNode(std::move(node1)); psetDesc1.validate(pset1); @@ -904,11 +811,7 @@ namespace testParameterSetDescription { (edm::ParameterDescription("x2", 101.0, true) and edm::ParameterDescription("x3", 101.0, true)))); - try { - psetDesc2.addNode(std::move(node2)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.addNode(std::move(node2)), edm::Exception); // One of the labels cannot already exist in the description, other order edm::ParameterSetDescription psetDesc3; @@ -918,11 +821,7 @@ namespace testParameterSetDescription { edm::ParameterDescription("x3", 101.0, true)))); psetDesc3.addNode(std::move(node3)); - try { - psetDesc3.add("x1", 1U); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.add("x1", 1U), edm::Exception); // Put the duplicate labels in different nodes of the "and" expression edm::ParameterSetDescription psetDesc4; @@ -930,11 +829,7 @@ namespace testParameterSetDescription { std::make_unique(edm::ParameterDescription("x1", 101.0, true), (edm::ParameterDescription("x2", 101.0, true) and edm::ParameterDescription("x1", 101.0, true)))); - try { - psetDesc4.addNode(std::move(node4)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc4.addNode(std::move(node4)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter @@ -943,11 +838,7 @@ namespace testParameterSetDescription { edm::ParameterDescription("x1", 101.0, true), (edm::ParameterDescription("x2", 101U, true) and edm::ParameterWildcard("*", edm::RequireAtLeastOne, true)))); - try { - psetDesc5.addNode(std::move(node5)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc5.addNode(std::move(node5)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -957,11 +848,7 @@ namespace testParameterSetDescription { std::make_unique(edm::ParameterWildcard("*", edm::RequireAtLeastOne, true), (edm::ParameterDescription("x2", 101U, true) and edm::ParameterDescription("x3", 102U, true)))); - try { - psetDesc6.addNode(std::move(node6)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc6.addNode(std::move(node6)), edm::Exception); // A type used in a wildcard should not be the same as a type // used for another parameter node @@ -971,16 +858,12 @@ namespace testParameterSetDescription { std::make_unique(edm::ParameterDescription("x1", 11.0, true), (edm::ParameterDescription("x2", 101U, true) and edm::ParameterDescription("x3", 102U, true)))); - try { - psetDesc7.addNode(std::move(node7)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc7.addNode(std::move(node7)), edm::Exception); } // --------------------------------------------------------------------------------- - void testAllowedLabels() { + SECTION("testAllowedLabels") { { std::unique_ptr node( std::make_unique>("allowedLabels", true)); @@ -991,13 +874,13 @@ namespace testParameterSetDescription { std::vector labels; pset.addParameter>("allowedLabels", labels); - assert(node->exists(emptyPset) == false); - assert(node->partiallyExists(emptyPset) == false); - assert(node->howManyXORSubNodesExist(emptyPset) == 0); + CHECK(node->exists(emptyPset) == false); + CHECK(node->partiallyExists(emptyPset) == false); + CHECK(node->howManyXORSubNodesExist(emptyPset) == 0); - assert(node->exists(pset) == true); - assert(node->partiallyExists(pset) == true); - assert(node->howManyXORSubNodesExist(pset) == 1); + CHECK(node->exists(pset) == true); + CHECK(node->partiallyExists(pset) == true); + CHECK(node->howManyXORSubNodesExist(pset) == 1); } { @@ -1007,11 +890,7 @@ namespace testParameterSetDescription { std::unique_ptr node( std::make_unique>("x1", true)); - try { - psetDesc.addNode(std::move(node)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.addNode(std::move(node)), edm::Exception); } { @@ -1021,11 +900,7 @@ namespace testParameterSetDescription { psetDesc.addWildcard>("*"); std::unique_ptr node( std::make_unique>("x1", true)); - try { - psetDesc.addNode(std::move(node)); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.addNode(std::move(node)), edm::Exception); } { edm::ParameterSet pset; @@ -1038,11 +913,7 @@ namespace testParameterSetDescription { psetDesc.labelsFrom("allowedLabelsA"); // nestedPset is an illegal parameter - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); std::vector labels; labels.push_back(std::string("nestedPset")); @@ -1060,11 +931,7 @@ namespace testParameterSetDescription { psetDesc.labelsFrom("allowedLabelsA", edm::ParameterSetDescription()); // Now it should fail because the description says the nested ParameterSet // should be empty, but it has parameter "x" - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } // Now include "x" in the description and it should once again pass validation @@ -1086,11 +953,7 @@ namespace testParameterSetDescription { edm::ParameterSetDescription psetDesc; psetDesc.labelsFrom(std::string("allowedLabelsA"), edm::ParameterSetDescription()); - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } { edm::ParameterSetDescription psetDesc; @@ -1116,11 +979,7 @@ namespace testParameterSetDescription { psetDesc.labelsFrom>("allowedLabelsC"); // nestedVPSet is an illegal parameter - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); std::vector labels; labels.push_back(std::string("nestedVPSet")); @@ -1137,11 +996,7 @@ namespace testParameterSetDescription { psetDesc.labelsFrom>("allowedLabelsC", edm::ParameterSetDescription()); // Now it should fail because the description says the contained vector // should have empty ParameterSets, but the ParameterSets have parameter "y" - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } // Now include "y" in the description and it should once again pass validation @@ -1164,11 +1019,7 @@ namespace testParameterSetDescription { edm::ParameterSetDescription psetDesc; psetDesc.labelsFrom>(std::string("allowedLabelsC"), edm::ParameterSetDescription()); - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } { edm::ParameterSetDescription psetDesc; @@ -1179,120 +1030,75 @@ namespace testParameterSetDescription { } // --------------------------------------------------------------------------------- - void testNoDefault() { + SECTION("testNoDefault") { edm::ParameterSetDescription psetDesc; psetDesc.add("x"); edm::ParameterSet pset; - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); pset.addParameter("x", 1); psetDesc.validate(pset); psetDesc.addVPSet("y", edm::ParameterSetDescription()); - try { - psetDesc.validate(pset); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc.validate(pset), edm::Exception); } // --------------------------------------------------------------------------------- - void testWrongTrackiness() { + SECTION("testWrongTrackiness") { edm::ParameterSet pset1; pset1.addParameter("test1", 1); edm::ParameterSetDescription psetDesc1; psetDesc1.addUntracked("test1", 1); - try { - psetDesc1.validate(pset1); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc1.validate(pset1), edm::Exception); edm::ParameterSet pset2; pset2.addParameter("test2", edm::ParameterSet()); edm::ParameterSetDescription psetDesc2; psetDesc2.addUntracked("test2", edm::ParameterSetDescription()); - try { - psetDesc2.validate(pset2); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.validate(pset2), edm::Exception); edm::ParameterSet pset3; pset3.addParameter>("test3", std::vector()); edm::ParameterSetDescription psetDesc3; psetDesc3.addVPSetUntracked("test3", edm::ParameterSetDescription()); - try { - psetDesc3.validate(pset3); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.validate(pset3), edm::Exception); } // --------------------------------------------------------------------------------- - void testWrongType() { + SECTION("testWrongType") { edm::ParameterSet pset1; pset1.addParameter("test1", 1); edm::ParameterSetDescription psetDesc1; psetDesc1.add("test1", 1); - try { - psetDesc1.validate(pset1); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc1.validate(pset1), edm::Exception); edm::ParameterSet pset2; pset2.addParameter("test2", 1); edm::ParameterSetDescription psetDesc2; psetDesc2.add("test2", edm::ParameterSetDescription()); - try { - psetDesc2.validate(pset2); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc2.validate(pset2), edm::Exception); edm::ParameterSet pset3; pset3.addParameter("test3", 1); edm::ParameterSetDescription psetDesc3; psetDesc3.addVPSetUntracked("test3", edm::ParameterSetDescription()); - try { - psetDesc3.validate(pset3); - assert(0); - } catch (edm::Exception const&) { /* There should be an exception */ - } + REQUIRE_THROWS_AS(psetDesc3.validate(pset3), edm::Exception); } // --------------------------------------------------------------------------------- - struct TestPluginBase { - virtual ~TestPluginBase() = default; - }; - - struct ATestPlugin : public TestPluginBase { - static void fillPSetDescription(edm::ParameterSetDescription& iPS) { iPS.add("anInt", 5); } - }; - - struct BTestPlugin : public TestPluginBase { - static void fillPSetDescription(edm::ParameterSetDescription& iPS) { iPS.add("aDouble", 0.5); } - }; - - using TestPluginFactory = edmplugin::PluginFactory; - - void testPlugin() { - edmplugin::PluginManager::configure(edmplugin::standard::config()); + SECTION("testPlugin") { + static std::once_flag flag; + std::call_once(flag, []() { edmplugin::PluginManager::configure(edmplugin::standard::config()); }); { edm::ParameterSetDescription desc; desc.addNode(edm::PluginDescription("type", true)); @@ -1323,7 +1129,7 @@ namespace testParameterSetDescription { edm::ParameterSet pset1; pset1.addParameter("type", "ATestPlugin"); desc.validate(pset1); - assert(pset1.getParameter("anInt") == 5); + CHECK(pset1.getParameter("anInt") == 5); } { @@ -1333,8 +1139,8 @@ namespace testParameterSetDescription { edm::ParameterSet pset1; desc.validate(pset1); - assert(pset1.getParameter("anInt") == 5); - assert(pset1.getParameter("type") == "ATestPlugin"); + CHECK(pset1.getParameter("anInt") == 5); + CHECK(pset1.getParameter("type") == "ATestPlugin"); } { @@ -1347,11 +1153,25 @@ namespace testParameterSetDescription { pset1.addParameter("anInt", 3); pset1.addParameter("NotRight", 3); - try { - desc.validate(pset1); - assert(false); - } catch (edm::Exception const& iException) { - } + REQUIRE_THROWS_AS(desc.validate(pset1), edm::Exception); + } + + SECTION("wildcard") { + //embedded with wildcard + edm::ParameterSetDescription desc; + desc.addNode(edm::PluginDescription("type", true)); + edm::ParameterWildcard w("*", edm::RequireExactlyOne, true, desc); + + edm::ParameterSetDescription top; + top.addNode(w); + + edm::ParameterSet pset1; + pset1.addParameter("type", "ATestPlugin"); + + edm::ParameterSet psetTop; + psetTop.addParameter("foo", pset1); + + top.validate(psetTop); } { @@ -1362,11 +1182,7 @@ namespace testParameterSetDescription { edm::ParameterSet pset1; pset1.addParameter("anInt", 3); - try { - desc.validate(pset1); - assert(false); - } catch (edm::Exception const& iException) { - } + REQUIRE_THROWS_AS(desc.validate(pset1), edm::Exception); } { @@ -1377,419 +1193,369 @@ namespace testParameterSetDescription { edm::ParameterSet pset1; pset1.addParameter("type", "ZTestPlugin"); - try { - desc.validate(pset1); - assert(false); - } catch (cms::Exception const& iException) { - //std::cout <("testname", std::string("testvalue")); - { - edm::ParameterSetDescription psetDesc; - assert(!psetDesc.anythingAllowed()); - assert(!psetDesc.isUnknown()); - assert(psetDesc.begin() == psetDesc.end()); + // Expect this to throw, parameter not in description + REQUIRE_THROWS_AS(psetDesc.validate(params), edm::Exception); - edm::ParameterSet params; - psetDesc.validate(params); + psetDesc.setAllowAnything(); + CHECK(psetDesc.anythingAllowed()); - params.addParameter("testname", std::string("testvalue")); + psetDesc.validate(params); - // Expect this to throw, parameter not in description - try { + psetDesc.add("testInt", 11); psetDesc.validate(params); - assert(0); - } catch (edm::Exception const&) { - // OK + CHECK(params.exists("testInt")); } - psetDesc.setAllowAnything(); - assert(psetDesc.anythingAllowed()); + { + edm::ParameterSetDescription psetDesc; - psetDesc.validate(params); + edm::ParameterSet params; + params.addParameter("testname", std::string("testvalue")); + psetDesc.setUnknown(); + CHECK(psetDesc.isUnknown()); - psetDesc.add("testInt", 11); - psetDesc.validate(params); - assert(params.exists("testInt")); - } + psetDesc.validate(params); + } + + { + // Test this type separately because I do not know how to + // add an entry into a ParameterSet without FileInPath pointing + // at a real file. + edm::ParameterSetDescription psetDesc; + edm::ParameterDescriptionBase* par = psetDesc.add("fileInPath", edm::FileInPath()); + CHECK(par->type() == edm::k_FileInPath); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("FileInPath")); + } - { edm::ParameterSetDescription psetDesc; + edm::ParameterSet pset; - edm::ParameterSet params; - params.addParameter("testname", std::string("testvalue")); - psetDesc.setUnknown(); - assert(psetDesc.isUnknown()); + psetDesc.reserve(2); + + int a = 1; + edm::ParameterDescriptionBase* par = psetDesc.add(std::string("ivalue"), a); + CHECK(par->exists(pset) == false); + CHECK(par->partiallyExists(pset) == false); + CHECK(par->howManyXORSubNodesExist(pset) == 0); + pset.addParameter("ivalue", a); + CHECK(par != 0); + CHECK(par->label() == std::string("ivalue")); + CHECK(par->type() == edm::k_int32); + CHECK(par->isTracked() == true); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("int32")); + CHECK(par->exists(pset) == true); + CHECK(par->partiallyExists(pset) == true); + CHECK(par->howManyXORSubNodesExist(pset) == 1); + + edm::ParameterSet psetWrongTrackiness; + psetWrongTrackiness.addUntrackedParameter("ivalue", a); + REQUIRE_THROWS_AS(psetDesc.validate(psetWrongTrackiness), edm::Exception); + + edm::ParameterSet psetWrongType; + psetWrongType.addUntrackedParameter("ivalue", 1U); + REQUIRE_THROWS_AS(psetDesc.validate(psetWrongType), edm::Exception); + + edm::ParameterSetDescription::const_iterator parIter = psetDesc.begin(); + CHECK(parIter->node().operator->() == par); + + unsigned b = 2; + par = psetDesc.add("uvalue", b); + pset.addParameter("uvalue", b); + CHECK(par != 0); + CHECK(par->label() == std::string("uvalue")); + CHECK(par->type() == edm::k_uint32); + CHECK(par->isTracked() == true); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("uint32")); + + parIter = psetDesc.begin(); + ++parIter; + CHECK(parIter->node().operator->() == par); + + long long c = 3; + par = psetDesc.addUntracked(std::string("i64value"), c); + pset.addUntrackedParameter("i64value", c); + CHECK(par != 0); + CHECK(par->label() == std::string("i64value")); + CHECK(par->type() == edm::k_int64); + CHECK(par->isTracked() == false); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("int64")); + + unsigned long long d = 4; + par = psetDesc.addUntracked("u64value", d); + pset.addUntrackedParameter("u64value", d); + CHECK(par != 0); + CHECK(par->label() == std::string("u64value")); + CHECK(par->type() == edm::k_uint64); + CHECK(par->isTracked() == false); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("uint64")); + + double e = 5; + par = psetDesc.addOptional(std::string("dvalue"), e); + pset.addParameter("dvalue", e); + CHECK(par != 0); + CHECK(par->label() == std::string("dvalue")); + CHECK(par->type() == edm::k_double); + CHECK(par->isTracked() == true); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("double")); + + bool f = true; + par = psetDesc.addOptional("bvalue", f); + pset.addParameter("bvalue", f); + CHECK(par != 0); + CHECK(par->label() == std::string("bvalue")); + CHECK(par->type() == edm::k_bool); + CHECK(par->isTracked() == true); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("bool")); + + std::string g; + par = psetDesc.addOptionalUntracked(std::string("svalue"), g); + pset.addUntrackedParameter("svalue", g); + CHECK(par != 0); + CHECK(par->label() == std::string("svalue")); + CHECK(par->type() == edm::k_stringRaw); + CHECK(par->isTracked() == false); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("string")); + + edm::EventID h; + par = psetDesc.addOptionalUntracked("evalue", h); + pset.addUntrackedParameter("evalue", h); + CHECK(par != 0); + CHECK(par->label() == std::string("evalue")); + CHECK(par->type() == edm::k_EventID); + CHECK(par->isTracked() == false); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("EventID")); + + edm::LuminosityBlockID i; + par = psetDesc.add("lvalue", i); + pset.addParameter("lvalue", i); + CHECK(par->type() == edm::k_LuminosityBlockID); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("LuminosityBlockID")); + + edm::InputTag j; + par = psetDesc.add("input", j); + pset.addParameter("input", j); + CHECK(par->type() == edm::k_InputTag); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("InputTag")); + + edm::ESInputTag k; + par = psetDesc.add("esinput", k); + pset.addParameter("esinput", k); + CHECK(par->type() == edm::k_ESInputTag); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("ESInputTag")); + + std::vector v1; + par = psetDesc.add>("v1", v1); + pset.addParameter>("v1", v1); + CHECK(par->type() == edm::k_vint32); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vint32")); + + std::vector v2; + par = psetDesc.add>("v2", v2); + pset.addParameter>("v2", v2); + CHECK(par->type() == edm::k_vuint32); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vuint32")); + + std::vector v3; + par = psetDesc.add>("v3", v3); + pset.addParameter>("v3", v3); + CHECK(par->type() == edm::k_vint64); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vint64")); + + std::vector v4; + par = psetDesc.add>("v4", v4); + pset.addParameter>("v4", v4); + CHECK(par->type() == edm::k_vuint64); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vuint64")); + + std::vector v5; + par = psetDesc.add>("v5", v5); + pset.addParameter>("v5", v5); + CHECK(par->type() == edm::k_vdouble); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vdouble")); + + std::vector v6; + par = psetDesc.add>("v6", v6); + pset.addParameter>("v6", v6); + CHECK(par->type() == edm::k_vstringRaw); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("vstring")); + + std::vector v7; + par = psetDesc.add>("v7", v7); + pset.addParameter>("v7", v7); + CHECK(par->type() == edm::k_VEventID); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("VEventID")); + + std::vector v8; + par = psetDesc.add>("v8", v8); + pset.addParameter>("v8", v8); + CHECK(par->type() == edm::k_VLuminosityBlockID); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("VLuminosityBlockID")); + + std::vector v9; + par = psetDesc.add>("v9", v9); + pset.addParameter>("v9", v9); + CHECK(par->type() == edm::k_VInputTag); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("VInputTag")); + + std::vector v11; + par = psetDesc.add>("v11", v11); + pset.addParameter>("v11", v11); + CHECK(par->type() == edm::k_VESInputTag); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("VESInputTag")); + + edm::ParameterSetDescription m; + par = psetDesc.add("psetDesc", m); + CHECK(par->exists(pset) == false); + CHECK(par->partiallyExists(pset) == false); + CHECK(par->howManyXORSubNodesExist(pset) == 0); + edm::ParameterSet p1; + pset.addParameter("psetDesc", p1); + CHECK(par->type() == edm::k_PSet); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("PSet")); + CHECK(par->exists(pset) == true); + CHECK(par->partiallyExists(pset) == true); + CHECK(par->howManyXORSubNodesExist(pset) == 1); + + edm::ParameterSetDescription v10; + par = psetDesc.addVPSet("psetVectorDesc", v10); + CHECK(par->exists(pset) == false); + CHECK(par->partiallyExists(pset) == false); + CHECK(par->howManyXORSubNodesExist(pset) == 0); + std::vector vp1; + pset.addParameter>("psetVectorDesc", vp1); + CHECK(par->type() == edm::k_VPSet); + CHECK(edm::parameterTypeEnumToString(par->type()) == std::string("VPSet")); + CHECK(par->exists(pset) == true); + CHECK(par->partiallyExists(pset) == true); + CHECK(par->howManyXORSubNodesExist(pset) == 1); - psetDesc.validate(params); - } + psetDesc.validate(pset); - { - // Test this type separately because I do not know how to - // add an entry into a ParameterSet without FileInPath pointing - // at a real file. - edm::ParameterSetDescription psetDesc; - edm::ParameterDescriptionBase* par = psetDesc.add("fileInPath", edm::FileInPath()); - assert(par->type() == edm::k_FileInPath); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("FileInPath")); - } + // Add a ParameterSetDescription nested in a ParameterSetDescription nested in + // a vector in the top level ParameterSetDescription to see if the nesting is + // working properly. - edm::ParameterSetDescription psetDesc; - edm::ParameterSet pset; - - psetDesc.reserve(2); - - int a = 1; - edm::ParameterDescriptionBase* par = psetDesc.add(std::string("ivalue"), a); - assert(par->exists(pset) == false); - assert(par->partiallyExists(pset) == false); - assert(par->howManyXORSubNodesExist(pset) == 0); - pset.addParameter("ivalue", a); - assert(par != 0); - assert(par->label() == std::string("ivalue")); - assert(par->type() == edm::k_int32); - assert(par->isTracked() == true); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("int32")); - assert(par->exists(pset) == true); - assert(par->partiallyExists(pset) == true); - assert(par->howManyXORSubNodesExist(pset) == 1); - - edm::ParameterSet psetWrongTrackiness; - psetWrongTrackiness.addUntrackedParameter("ivalue", a); - try { - psetDesc.validate(psetWrongTrackiness); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } + edm::ParameterSet nest2; + nest2.addParameter("intLevel2a", 1); + nest2.addUntrackedParameter("intLevel2b", 1); + nest2.addParameter("intLevel2e", 1); + nest2.addUntrackedParameter("intLevel2f", 1); - edm::ParameterSet psetWrongType; - psetWrongType.addUntrackedParameter("ivalue", 1U); - try { - psetDesc.validate(psetWrongType); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } + edm::ParameterSet nest1; + nest1.addParameter("intLevel1a", 1); + nest1.addParameter("nestLevel1b", nest2); - edm::ParameterSetDescription::const_iterator parIter = psetDesc.begin(); - assert(parIter->node().operator->() == par); - - unsigned b = 2; - par = psetDesc.add("uvalue", b); - pset.addParameter("uvalue", b); - assert(par != 0); - assert(par->label() == std::string("uvalue")); - assert(par->type() == edm::k_uint32); - assert(par->isTracked() == true); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("uint32")); - - parIter = psetDesc.begin(); - ++parIter; - assert(parIter->node().operator->() == par); - - long long c = 3; - par = psetDesc.addUntracked(std::string("i64value"), c); - pset.addUntrackedParameter("i64value", c); - assert(par != 0); - assert(par->label() == std::string("i64value")); - assert(par->type() == edm::k_int64); - assert(par->isTracked() == false); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("int64")); - - unsigned long long d = 4; - par = psetDesc.addUntracked("u64value", d); - pset.addUntrackedParameter("u64value", d); - assert(par != 0); - assert(par->label() == std::string("u64value")); - assert(par->type() == edm::k_uint64); - assert(par->isTracked() == false); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("uint64")); - - double e = 5; - par = psetDesc.addOptional(std::string("dvalue"), e); - pset.addParameter("dvalue", e); - assert(par != 0); - assert(par->label() == std::string("dvalue")); - assert(par->type() == edm::k_double); - assert(par->isTracked() == true); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("double")); - - bool f = true; - par = psetDesc.addOptional("bvalue", f); - pset.addParameter("bvalue", f); - assert(par != 0); - assert(par->label() == std::string("bvalue")); - assert(par->type() == edm::k_bool); - assert(par->isTracked() == true); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("bool")); - - std::string g; - par = psetDesc.addOptionalUntracked(std::string("svalue"), g); - pset.addUntrackedParameter("svalue", g); - assert(par != 0); - assert(par->label() == std::string("svalue")); - assert(par->type() == edm::k_stringRaw); - assert(par->isTracked() == false); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("string")); - - edm::EventID h; - par = psetDesc.addOptionalUntracked("evalue", h); - pset.addUntrackedParameter("evalue", h); - assert(par != 0); - assert(par->label() == std::string("evalue")); - assert(par->type() == edm::k_EventID); - assert(par->isTracked() == false); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("EventID")); - - edm::LuminosityBlockID i; - par = psetDesc.add("lvalue", i); - pset.addParameter("lvalue", i); - assert(par->type() == edm::k_LuminosityBlockID); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("LuminosityBlockID")); - - edm::InputTag j; - par = psetDesc.add("input", j); - pset.addParameter("input", j); - assert(par->type() == edm::k_InputTag); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("InputTag")); - - edm::ESInputTag k; - par = psetDesc.add("esinput", k); - pset.addParameter("esinput", k); - assert(par->type() == edm::k_ESInputTag); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("ESInputTag")); - - std::vector v1; - par = psetDesc.add>("v1", v1); - pset.addParameter>("v1", v1); - assert(par->type() == edm::k_vint32); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vint32")); - - std::vector v2; - par = psetDesc.add>("v2", v2); - pset.addParameter>("v2", v2); - assert(par->type() == edm::k_vuint32); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vuint32")); - - std::vector v3; - par = psetDesc.add>("v3", v3); - pset.addParameter>("v3", v3); - assert(par->type() == edm::k_vint64); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vint64")); - - std::vector v4; - par = psetDesc.add>("v4", v4); - pset.addParameter>("v4", v4); - assert(par->type() == edm::k_vuint64); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vuint64")); - - std::vector v5; - par = psetDesc.add>("v5", v5); - pset.addParameter>("v5", v5); - assert(par->type() == edm::k_vdouble); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vdouble")); - - std::vector v6; - par = psetDesc.add>("v6", v6); - pset.addParameter>("v6", v6); - assert(par->type() == edm::k_vstringRaw); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("vstring")); - - std::vector v7; - par = psetDesc.add>("v7", v7); - pset.addParameter>("v7", v7); - assert(par->type() == edm::k_VEventID); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("VEventID")); - - std::vector v8; - par = psetDesc.add>("v8", v8); - pset.addParameter>("v8", v8); - assert(par->type() == edm::k_VLuminosityBlockID); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("VLuminosityBlockID")); - - std::vector v9; - par = psetDesc.add>("v9", v9); - pset.addParameter>("v9", v9); - assert(par->type() == edm::k_VInputTag); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("VInputTag")); - - std::vector v11; - par = psetDesc.add>("v11", v11); - pset.addParameter>("v11", v11); - assert(par->type() == edm::k_VESInputTag); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("VESInputTag")); - - edm::ParameterSetDescription m; - par = psetDesc.add("psetDesc", m); - assert(par->exists(pset) == false); - assert(par->partiallyExists(pset) == false); - assert(par->howManyXORSubNodesExist(pset) == 0); - edm::ParameterSet p1; - pset.addParameter("psetDesc", p1); - assert(par->type() == edm::k_PSet); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("PSet")); - assert(par->exists(pset) == true); - assert(par->partiallyExists(pset) == true); - assert(par->howManyXORSubNodesExist(pset) == 1); - - edm::ParameterSetDescription v10; - par = psetDesc.addVPSet("psetVectorDesc", v10); - assert(par->exists(pset) == false); - assert(par->partiallyExists(pset) == false); - assert(par->howManyXORSubNodesExist(pset) == 0); - std::vector vp1; - pset.addParameter>("psetVectorDesc", vp1); - assert(par->type() == edm::k_VPSet); - assert(edm::parameterTypeEnumToString(par->type()) == std::string("VPSet")); - assert(par->exists(pset) == true); - assert(par->partiallyExists(pset) == true); - assert(par->howManyXORSubNodesExist(pset) == 1); - - psetDesc.validate(pset); - - // Add a ParameterSetDescription nested in a ParameterSetDescription nested in - // a vector in the top level ParameterSetDescription to see if the nesting is - // working properly. - - edm::ParameterSet nest2; - nest2.addParameter("intLevel2a", 1); - nest2.addUntrackedParameter("intLevel2b", 1); - nest2.addParameter("intLevel2e", 1); - nest2.addUntrackedParameter("intLevel2f", 1); - - edm::ParameterSet nest1; - nest1.addParameter("intLevel1a", 1); - nest1.addParameter("nestLevel1b", nest2); - - std::vector vPset; - vPset.push_back(edm::ParameterSet()); - vPset.push_back(nest1); - - pset.addUntrackedParameter>("nestLevel0", vPset); - - std::vector testDescriptions; - testDescriptions.push_back(psetDesc); - testDescriptions.push_back(psetDesc); - testDescriptions.push_back(psetDesc); - - for (int ii = 0; ii < 3; ++ii) { - edm::ParameterSetDescription nestLevel2; + std::vector vPset; + vPset.push_back(edm::ParameterSet()); + vPset.push_back(nest1); + + pset.addUntrackedParameter>("nestLevel0", vPset); - // for the first test do not put a parameter in the description - // so there will be an extra parameter in the ParameterSet and - // validation should fail. - if (ii > 0) - nestLevel2.add("intLevel2a", 1); + std::vector testDescriptions; + testDescriptions.push_back(psetDesc); + testDescriptions.push_back(psetDesc); + testDescriptions.push_back(psetDesc); - // for the next test validation should pass + for (int ii = 0; ii < 3; ++ii) { + edm::ParameterSetDescription nestLevel2; - // For the last test add an extra required parameter in the - // description that is not in the ParameterSet. - if (ii == 2) - nestLevel2.add("intLevel2extra", 11); + // for the first test do not put a parameter in the description + // so there will be an extra parameter in the ParameterSet and + // validation should fail. + if (ii > 0) + nestLevel2.add("intLevel2a", 1); + + // for the next test validation should pass + + // For the last test add an extra required parameter in the + // description that is not in the ParameterSet. + if (ii == 2) + nestLevel2.add("intLevel2extra", 11); + + nestLevel2.addUntracked("intLevel2b", 1); + nestLevel2.addOptional("intLevel2c", 1); + nestLevel2.addOptionalUntracked("intLevel2d", 1); + nestLevel2.addOptional("intLevel2e", 1); + nestLevel2.addOptionalUntracked("intLevel2f", 1); + + edm::ParameterSetDescription nestLevel1; + nestLevel1.add("intLevel1a", 1); + nestLevel1.add("nestLevel1b", nestLevel2); + + testDescriptions[ii].addVPSetUntracked("nestLevel0", nestLevel1); + } + + // Now run the validation and make sure we get the expected results + REQUIRE_THROWS_AS(testDescriptions[0].validate(pset), edm::Exception); + + // This one should pass validation with no exception + testDescriptions[1].validate(pset); + + // This validation should also pass and it should insert + // the missing parameter into the ParameterSet + testDescriptions[2].validate(pset); + + std::vector const& vpset = pset.getUntrackedParameterSetVector("nestLevel0"); + edm::ParameterSet const& psetInPset = vpset[1].getParameterSet("nestLevel1b"); + CHECK(psetInPset.getParameter("intLevel2extra") == 11); + + // One more iteration, this time the purpose is to + // test the parameterSetDescription accessors. + edm::ParameterSetDescription nestLevel2; + par = nestLevel2.add("intLevel2a", 1); + par->setComment("testComment"); + CHECK(par->parameterSetDescription() == 0); + edm::ParameterDescriptionBase const& constParRef = *par; + CHECK(constParRef.parameterSetDescription() == 0); nestLevel2.addUntracked("intLevel2b", 1); nestLevel2.addOptional("intLevel2c", 1); nestLevel2.addOptionalUntracked("intLevel2d", 1); nestLevel2.addOptional("intLevel2e", 1); nestLevel2.addOptionalUntracked("intLevel2f", 1); + nestLevel2.setAllowAnything(); edm::ParameterSetDescription nestLevel1; - nestLevel1.add("intLevel1a", 1); - nestLevel1.add("nestLevel1b", nestLevel2); + par = nestLevel1.add("intLevel1a", 1); + par->setComment("testComment1"); + par = nestLevel1.add("nestLevel1b", nestLevel2); + CHECK(par->parameterSetDescription() != 0); + CHECK(par->parameterSetDescription()->begin()->node()->comment() == std::string("testComment")); + edm::ParameterDescriptionBase const& constParRef2 = *par; + CHECK(constParRef2.parameterSetDescription() != 0); + CHECK(constParRef2.parameterSetDescription()->begin()->node()->comment() == std::string("testComment")); + + CHECK(par->parameterSetDescription()->anythingAllowed() == true); + CHECK(constParRef2.parameterSetDescription()->anythingAllowed() == true); + + par = psetDesc.addVPSetUntracked("nestLevel0", nestLevel1); + CHECK(par->parameterSetDescription() != 0); + CHECK(par->parameterSetDescription()->begin()->node()->comment() == std::string("testComment1")); + edm::ParameterDescriptionBase const& constParRef3 = *par; + CHECK(constParRef3.parameterSetDescription() != 0); + CHECK(constParRef3.parameterSetDescription()->begin()->node()->comment() == std::string("testComment1")); - testDescriptions[ii].addVPSetUntracked("nestLevel0", nestLevel1); + psetDesc.validate(pset); } +} // namespace testParameterSetDescription - // Now run the validation and make sure we get the expected results - try { - testDescriptions[0].validate(pset); - assert(0); - } catch (edm::Exception const&) { - // There should be an exception - } +EDM_REGISTER_VALIDATED_PLUGINFACTORY(TestPluginFactory, "TestPluginFWCoreParameterSet"); - // This one should pass validation with no exception - testDescriptions[1].validate(pset); - - // This validation should also pass and it should insert - // the missing parameter into the ParameterSet - testDescriptions[2].validate(pset); - - std::vector const& vpset = pset.getUntrackedParameterSetVector("nestLevel0"); - edm::ParameterSet const& psetInPset = vpset[1].getParameterSet("nestLevel1b"); - assert(psetInPset.getParameter("intLevel2extra") == 11); - - // One more iteration, this time the purpose is to - // test the parameterSetDescription accessors. - edm::ParameterSetDescription nestLevel2; - par = nestLevel2.add("intLevel2a", 1); - par->setComment("testComment"); - assert(par->parameterSetDescription() == 0); - edm::ParameterDescriptionBase const& constParRef = *par; - assert(constParRef.parameterSetDescription() == 0); - - nestLevel2.addUntracked("intLevel2b", 1); - nestLevel2.addOptional("intLevel2c", 1); - nestLevel2.addOptionalUntracked("intLevel2d", 1); - nestLevel2.addOptional("intLevel2e", 1); - nestLevel2.addOptionalUntracked("intLevel2f", 1); - nestLevel2.setAllowAnything(); - - edm::ParameterSetDescription nestLevel1; - par = nestLevel1.add("intLevel1a", 1); - par->setComment("testComment1"); - par = nestLevel1.add("nestLevel1b", nestLevel2); - assert(par->parameterSetDescription() != 0); - assert(par->parameterSetDescription()->begin()->node()->comment() == std::string("testComment")); - edm::ParameterDescriptionBase const& constParRef2 = *par; - assert(constParRef2.parameterSetDescription() != 0); - assert(constParRef2.parameterSetDescription()->begin()->node()->comment() == std::string("testComment")); - - assert(par->parameterSetDescription()->anythingAllowed() == true); - assert(constParRef2.parameterSetDescription()->anythingAllowed() == true); - - par = psetDesc.addVPSetUntracked("nestLevel0", nestLevel1); - assert(par->parameterSetDescription() != 0); - assert(par->parameterSetDescription()->begin()->node()->comment() == std::string("testComment1")); - edm::ParameterDescriptionBase const& constParRef3 = *par; - assert(constParRef3.parameterSetDescription() != 0); - assert(constParRef3.parameterSetDescription()->begin()->node()->comment() == std::string("testComment1")); - - psetDesc.validate(pset); - - testParameterSetDescription::testWildcards(); - testParameterSetDescription::testWildcardWithExceptions(); - testParameterSetDescription::testSwitch(); - testParameterSetDescription::testAllowedValues(); - testParameterSetDescription::testXor(); - testParameterSetDescription::testOr(); - testParameterSetDescription::testAnd(); - testParameterSetDescription::testIfExists(); - testParameterSetDescription::testAllowedLabels(); - testParameterSetDescription::testNoDefault(); - testParameterSetDescription::testWrongTrackiness(); - testParameterSetDescription::testWrongType(); - testParameterSetDescription::testPlugin(); - - return 0; -} catch (cms::Exception const& e) { - std::cerr << e.explainSelf() << std::endl; - return 1; -} catch (std::exception const& e) { - std::cerr << e.what() << std::endl; - return 1; -} +DEFINE_EDM_VALIDATED_PLUGIN(TestPluginFactory, testParameterSetDescription::ATestPlugin, "ATestPlugin"); +DEFINE_EDM_VALIDATED_PLUGIN(TestPluginFactory, testParameterSetDescription::BTestPlugin, "BTestPlugin");