Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 08:51:57

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 
0006 #include <JANA/Services/JParameterManager.h>
0007 #include <string>
0008 #include <vector>
0009 #include "catch.hpp"
0010 
0011 TEST_CASE("JParameterManager::SetDefaultParameter") {
0012 
0013     JParameterManager jpm;
0014 
0015 
0016    SECTION("Multiple calls to SetDefaultParameter with same defaults succeed") {
0017 
0018         jpm.SetParameter("testing:dummy_var", 22);
0019 
0020         int x = 44;
0021         jpm.SetDefaultParameter("testing:dummy_var", x);
0022         REQUIRE(x == 22);
0023 
0024         int y = 44;
0025         jpm.SetDefaultParameter("testing:dummy_var", y);
0026         REQUIRE(y == 22);
0027     }
0028 
0029 
0030     SECTION("Multiple calls to SetDefaultParameter with same defaults succeed, float") {
0031 
0032         float x = 1.1;
0033         jpm.SetDefaultParameter("small_float", x);
0034         float y = 1.1;
0035         jpm.SetDefaultParameter("small_float", y);
0036         float temp;
0037         jpm.Parse<float>(jpm.Stringify(1.1f), temp);
0038         REQUIRE(jpm.Equals(temp, 1.1f));
0039         jpm.Parse<float>(jpm.Stringify(1.1f), temp);
0040         REQUIRE(!jpm.Equals(temp, 1.10001f));
0041 
0042         float v = 1.1e20f;
0043         jpm.SetDefaultParameter("large_float", v);
0044         float w = 1.1e20f;
0045 
0046         jpm.SetDefaultParameter("large_float", w);
0047         jpm.Parse<float>(jpm.Stringify(1.1e20f), temp);
0048         REQUIRE(jpm.Equals(temp, 1.1e20f));
0049         jpm.Parse<float>(jpm.Stringify(1.1e20f), temp);
0050         REQUIRE(!jpm.Equals(temp, 1.100001e20f));
0051 
0052         double xx = 1.1;
0053         jpm.SetDefaultParameter("small_double", xx);
0054         double yy = 1.1;
0055         jpm.SetDefaultParameter("small_double", yy);
0056         
0057         double tempD;
0058         jpm.Parse<double>(jpm.Stringify(1.1), tempD);
0059         REQUIRE(jpm.Equals(tempD, 1.1));
0060         jpm.Parse<double>(jpm.Stringify(1.1), tempD);
0061         REQUIRE(!jpm.Equals(tempD, 1.100001));
0062 
0063         double vv = 1.1e50;
0064         jpm.SetDefaultParameter("large_double", vv);
0065         double ww = 1.1e50;
0066         jpm.SetDefaultParameter("large_double", ww);
0067 
0068         jpm.Parse<double>(jpm.Stringify(1.1e20), tempD);
0069         REQUIRE(jpm.Equals(tempD, 1.1e20));
0070         REQUIRE(!jpm.Equals(tempD, 1.1000000001e20));
0071     }
0072 
0073 
0074     SECTION("Multiple calls to SetDefaultParameter with different defaults") {
0075 
0076         // If set, the user provided value overrides ALL default values
0077 
0078         jpm.SetParameter("testing:dummy_var", 22);
0079 
0080         int x = 44;
0081         jpm.SetDefaultParameter("testing:dummy_var", x);
0082         REQUIRE(x == 22);
0083 
0084         int y = 77;
0085         jpm.SetDefaultParameter("testing:dummy_var", y);
0086         REQUIRE(x == 22);
0087 
0088 
0089         // If no value set and there are two conflicting defaults, use the _local_ one
0090         int z = 44;
0091         jpm.SetDefaultParameter("testing:dummy_var_2", z);
0092         REQUIRE(z == 44);
0093 
0094         int zz = 77;
0095         jpm.SetDefaultParameter("testing:dummy_var_2", zz);
0096         REQUIRE(zz == 77);
0097     }
0098 
0099     SECTION("Multiple calls to check strings with spaces") {
0100 
0101         // basic string test
0102         std::string x = "MyStringValue";
0103         jpm.SetDefaultParameter("testing:dummy_var", x);
0104         REQUIRE(x == "MyStringValue");
0105 
0106         // string with spaces
0107         std::string y = "My String Value With Spaces";
0108         auto p = jpm.SetDefaultParameter("testing:dummy_var2", y);
0109         REQUIRE(p->GetValue() == "My String Value With Spaces");
0110 
0111         // Stringify returns identical string
0112         REQUIRE( jpm.Stringify("My String Value With Spaces") == "My String Value With Spaces" );
0113 
0114         // Parse returns identical string
0115         std::string z = "My String Value With Spaces";
0116         std::string testString;
0117         jpm.Parse<std::string>(z,testString);
0118         REQUIRE( testString == "My String Value With Spaces" );
0119     }
0120 }
0121 
0122 
0123 TEST_CASE("JParameterManagerBoolTests") {
0124     JParameterManager jpm;
0125 
0126     SECTION("'0' parses to false") {
0127         jpm.SetParameter("test_param", "0");
0128         bool val = jpm.GetParameterValue<bool>("test_param");
0129         REQUIRE(val == false);
0130     }
0131 
0132     SECTION("'1' parses to true") {
0133         jpm.SetParameter("test_param", "1");
0134         bool val = jpm.GetParameterValue<bool>("test_param");
0135         REQUIRE(val == true);
0136     }
0137 
0138     SECTION("'off' parses to false") {
0139         jpm.SetParameter("test_param", "off");
0140         bool val = jpm.GetParameterValue<bool>("test_param");
0141         REQUIRE(val == false);
0142     }
0143 
0144     SECTION("'on' parses to true") {
0145         jpm.SetParameter("test_param", "on");
0146         bool val = jpm.GetParameterValue<bool>("test_param");
0147         REQUIRE(val == true);
0148     }
0149 
0150     SECTION("'true' parses to true") {
0151         jpm.SetParameter("test_param", "true");
0152         bool val = jpm.GetParameterValue<bool>("test_param");
0153         REQUIRE(val == true);
0154     }
0155 
0156     SECTION("'false' parses to false") {
0157         jpm.SetParameter("test_param", "false");
0158         bool val = jpm.GetParameterValue<bool>("test_param");
0159         REQUIRE(val == false);
0160     }
0161 
0162     SECTION("Parsing anything else as bool throws an exception") {
0163         jpm.SetParameter("test_param", "maybe");
0164         CHECK_THROWS(jpm.GetParameterValue<bool>("test_param"));
0165     }
0166 
0167     SECTION("Stringify still works") {
0168         jpm.SetParameter("test_param", false);
0169         std::string val = jpm.GetParameterValue<std::string>("test_param");
0170         REQUIRE(val == "0");
0171 
0172         jpm.SetParameter("test_param", true);
0173         val = jpm.GetParameterValue<std::string>("test_param");
0174         REQUIRE(val == "1");
0175     }
0176 }
0177 
0178 TEST_CASE("JParameterManager_VectorParams") {
0179     JParameterManager jpm;
0180 
0181     SECTION("Reading a vector of strings") {
0182         jpm.SetParameter("test", "simple,whitespace in middle, also with whitespace padding ");
0183         std::vector<std::string> vals;
0184         jpm.GetParameter<std::vector<std::string>>("test", vals);
0185 
0186         REQUIRE(vals[0] == "simple");
0187         REQUIRE(vals[1] == "whitespace in middle");
0188         REQUIRE(vals[2] == " also with whitespace padding ");
0189     }
0190     SECTION("Writing a vector of strings") {
0191         std::vector<std::string> inputs;
0192         inputs.emplace_back("first");
0193         inputs.emplace_back("second one");
0194         inputs.emplace_back(" third one ");
0195 
0196         jpm.SetDefaultParameter("test", inputs);
0197         std::vector<std::string> outputs;
0198         auto param = jpm.GetParameter("test", outputs);
0199         REQUIRE(param->GetValue() == "first,second one, third one ");
0200         REQUIRE(inputs.size()==3); // an additional test to see that the size of the input vector remains the same: Issue #256
0201     }
0202     SECTION("Reading a vector of ints") {
0203         jpm.SetParameter("test", "1,2, 3 ");
0204         std::vector<int32_t> vals;
0205         jpm.GetParameter("test", vals);
0206 
0207         REQUIRE(vals[0] == 1);
0208         REQUIRE(vals[1] == 2);
0209         REQUIRE(vals[2] == 3);
0210     }
0211     SECTION("Writing a vector of ints") {
0212         std::vector<int32_t> inputs;
0213         inputs.emplace_back(22);
0214         inputs.emplace_back(49);
0215         inputs.emplace_back(42);
0216 
0217         jpm.SetDefaultParameter("test", inputs);
0218         std::vector<std::string> outputs;
0219         auto param = jpm.GetParameter("test", outputs);
0220         REQUIRE(param->GetValue() == "22,49,42");
0221     }
0222     SECTION("Reading a vector of floats") {
0223         jpm.SetParameter("test", "1,2,3");
0224         std::vector<float> vals;
0225         jpm.GetParameter("test", vals);
0226 
0227         REQUIRE(vals[0] == 1.0f);
0228         REQUIRE(vals[1] == 2.0f);
0229         REQUIRE(vals[2] == 3.0f);
0230     }
0231     SECTION("Writing a vector of floats") {
0232         std::vector<float> inputs;
0233         inputs.emplace_back(22.0);
0234         inputs.emplace_back(49.2);
0235         inputs.emplace_back(42.0);
0236 
0237         jpm.SetDefaultParameter("test", inputs);
0238         std::vector<float> outputs;
0239         auto param = jpm.GetParameter("test", outputs);
0240         REQUIRE(param->GetValue() == "22,49.2,42");
0241     }
0242     SECTION("Reading a vector of functions with commas") {
0243         // As of Mon Jan 27, JParameterManager does not allow an escape key to prevent splitting on the next comma)
0244         jpm.SetParameter("test", "phi-fmod(phi\\,5),theta-fmod(theta\\,10),omega-fmod(omega\\,15)"); // Issue #380 (Feature request)
0245         std::vector<std::string> vals;
0246         std::cout << "Problem detected" << std::endl;
0247         jpm.GetParameter<std::vector<std::string>>("test", vals);
0248         auto stringification = jpm.Stringify(vals);
0249 
0250         REQUIRE(stringification == "phi-fmod(phi\\,5),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0251 
0252         REQUIRE(vals[0] == "phi-fmod(phi,5)");
0253         REQUIRE(vals[1] == "theta-fmod(theta,10)");
0254         REQUIRE(vals[2] == "omega-fmod(omega,15)");
0255     }
0256     SECTION("Writing a vector of functions with commas") {
0257         std::vector<std::string> inputs;
0258         inputs.emplace_back("phi-fmod(phi,5)");
0259         inputs.emplace_back("theta-fmod(theta,10)");
0260         inputs.emplace_back("omega-fmod(omega,15)");
0261         std::vector<std::string> temp1 = inputs;
0262 
0263 
0264         jpm.SetDefaultParameter("test", inputs);
0265         auto stringified = jpm.Stringify(inputs);
0266         std::vector<std::string> mangled_inputs;
0267         jpm.Parse(stringified, mangled_inputs);
0268         REQUIRE(inputs == mangled_inputs);
0269 
0270         std::vector<std::string> outputs;
0271         auto param = jpm.GetParameter("test", outputs);
0272         REQUIRE(param->GetValue() == "phi-fmod(phi\\,5),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0273         REQUIRE(inputs.size()==3);
0274 
0275         std::vector<std::string> temp2;
0276         jpm.Parse(jpm.Stringify(temp1), temp2);
0277         REQUIRE(temp2 == outputs);
0278     }
0279     SECTION("ParseVectorOfStrings") {
0280 
0281         auto s1 = "This,is,a,test"; // Should have 4 elements in vector
0282         std::vector<std::string> v1;
0283         jpm.Parse(s1, v1);
0284         REQUIRE(v1.size() == 4);
0285         REQUIRE(v1.at(0) == "This");
0286 
0287         auto s2 = "This\\,is,a\\,test"; // Should have 2 elements in vector
0288         std::vector<std::string> v2;
0289         jpm.Parse(s2, v2);
0290         REQUIRE(v2.size() == 2);
0291         REQUIRE(v2.at(0) == "This,is");
0292         
0293         auto s3 = "This\\,is,a\\\\,test"; // Should have 2 elements in vector
0294         std::vector<std::string> v3;
0295         jpm.Parse(s3, v3);
0296         REQUIRE(v3.size() == 2);
0297         REQUIRE(v3.at(1) == "a\\,test");
0298     }
0299     SECTION("StringifyVectorOfStrings") {
0300 
0301         std::vector<std::string> v1 {"This", "is", "a", "test"};
0302         auto s1 = jpm.Stringify(v1);
0303         REQUIRE(s1 == "This,is,a,test");
0304 
0305         std::vector<std::string> v2 {"This,is", "a,test"};
0306         auto s2 = jpm.Stringify(v2);
0307         REQUIRE(s2 == "This\\,is,a\\,test");
0308         
0309         std::vector<std::string> v3 {"This,is", "a\\,test"};
0310         auto s3 = jpm.Stringify(v3);
0311         REQUIRE(s3 == "This\\,is,a\\\\,test");
0312     }
0313 }
0314 
0315 TEST_CASE("JParameterManager::RegisterParameter") {
0316 
0317     JParameterManager jpm;
0318 
0319     SECTION("Set/Get") {
0320         int x_default = 44;
0321         auto x_actual = jpm.RegisterParameter("testing:dummy_var", x_default);
0322         REQUIRE(x_actual == x_default);
0323     }
0324 
0325     SECTION("Set/Get templated float") {
0326         auto y_actual = jpm.RegisterParameter("testing:dummy_var2", 22.0);
0327         REQUIRE(y_actual == 22.0);
0328     }
0329 
0330     SECTION("Set/Get default") {
0331         jpm.SetParameter("testing:dummy_var", 22);
0332         auto x_actual = jpm.RegisterParameter("testing:dummy_var", 44);  // this should set the default value to 44 while keeping value at 22
0333         auto x_default_str = jpm.FindParameter("testing:dummy_var")->GetDefault();
0334         int x_default;
0335         jpm.Parse<int>(x_default_str,x_default);
0336         REQUIRE(x_actual == 22);
0337         REQUIRE(x_default == 44);
0338     }
0339 
0340 }
0341 
0342 TEST_CASE("JParameterManager_ArrayParams") {
0343     JParameterManager jpm;
0344 
0345     SECTION("Reading a array of strings") {
0346         jpm.SetParameter("test", "simple,whitespace in middle, also with whitespace padding ");
0347         std::array<std::string,3> vals;
0348         jpm.GetParameter<std::array<std::string,3>>("test", vals); 
0349         REQUIRE(vals[0] == "simple");
0350         REQUIRE(vals[1] == "whitespace in middle");
0351         REQUIRE(vals[2] == " also with whitespace padding ");
0352     }
0353     SECTION("Writing an array of strings") {
0354         std::array<std::string,3> inputs = {"first", "second one" , " third one "};
0355         jpm.SetDefaultParameter("test", inputs);
0356         std::array<std::string,3> outputs;
0357         auto param = jpm.GetParameter("test", outputs);
0358         REQUIRE(param->GetValue() == "first,second one, third one ");
0359     }
0360     SECTION("Reading a array of ints") {
0361         jpm.SetParameter("test", "1,2, 3 ");
0362         std::array<int32_t,3> vals;
0363         jpm.GetParameter("test", vals);
0364 
0365         REQUIRE(vals[0] == 1);
0366         REQUIRE(vals[1] == 2);
0367         REQUIRE(vals[2] == 3);
0368     }
0369     SECTION("Writing a array of ints") {
0370         std::array<int32_t,3> inputs = {22,49,42};
0371         jpm.SetDefaultParameter("test", inputs);
0372         std::array<std::string,3> outputs;
0373         auto param = jpm.GetParameter("test", outputs);
0374         REQUIRE(param->GetValue() == "22,49,42");
0375     }
0376     SECTION("Reading a array of floats") {
0377         jpm.SetParameter("test", "1,2,3");
0378         std::array<float,3> vals;
0379         jpm.GetParameter("test", vals);
0380 
0381         REQUIRE(vals[0] == 1.0f);
0382         REQUIRE(vals[1] == 2.0f);
0383         REQUIRE(vals[2] == 3.0f);
0384     }
0385     SECTION("Writing a array of floats") {
0386         std::array<float,3> inputs = {22.0,49.2,42.0};
0387         jpm.SetDefaultParameter("test", inputs);
0388         std::array<float,3> outputs;
0389         auto param = jpm.GetParameter("test", outputs);
0390         REQUIRE(param->GetValue() == "22,49.2,42");
0391     }
0392     SECTION("Reading a array of functions with commas") {
0393         // As of Mon Jan 27, JParameterManager does not allow an escape key to prevent splitting on the next comma)
0394         jpm.SetParameter("test", "theta-fmod(phi-fmod(phi\\,5)\\,7),theta-fmod(theta\\,10),omega-fmod(omega\\,15)"); // Issue #380 (Feature request)
0395         std::array<std::string, 3> vals;
0396         jpm.GetParameter("test", vals);
0397 
0398         REQUIRE(vals[0] == "theta-fmod(phi-fmod(phi,5),7)");
0399         REQUIRE(vals[1] == "theta-fmod(theta,10)");
0400         REQUIRE(vals[2] == "omega-fmod(omega,15)");
0401     }
0402     SECTION("Writing a array of functions with commas") {
0403         std::array<std::string, 3> inputs = {
0404             "theta-fmod(phi-fmod(phi,5),7)",
0405             "theta-fmod(theta,10)",
0406             "omega-fmod(omega,15)"
0407         };
0408 
0409         jpm.SetDefaultParameter("test", inputs);
0410         std::array<std::string,3> outputs;
0411 
0412         auto param = jpm.GetParameter("test", outputs);
0413 
0414         REQUIRE(outputs == inputs);
0415         REQUIRE(param->GetValue() == "theta-fmod(phi-fmod(phi\\,5)\\,7),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0416     }
0417     SECTION("ParseArrayOfStrings") {
0418 
0419         auto s1 = "This,is,a,test"; // Should have 4 elements in vector
0420         std::array<std::string,4> v1;
0421         jpm.Parse(s1, v1);
0422         REQUIRE(v1.size() == 4);
0423         REQUIRE(v1.at(0) == "This");
0424 
0425         auto s2 = "This\\,is,a\\,test"; // Should have 2 elements in vector
0426         std::array<std::string, 2> v2;
0427         jpm.Parse(s2, v2);
0428         REQUIRE(v2.size() == 2);
0429         REQUIRE(v2.at(0) == "This,is");
0430 
0431         auto s3 = "This\\,is,a\\\\,test"; // Should have 2 elements in vector
0432         std::array<std::string, 2> v3;
0433         jpm.Parse(s3, v3);
0434         REQUIRE(v3.size() == 2);
0435         REQUIRE(v3.at(1) == "a\\,test");
0436     }
0437     SECTION("StringifyArrayOfStrings") {
0438 
0439         std::array<std::string, 4> v1 {"This", "is", "a", "test"};
0440         auto s1 = jpm.Stringify(v1);
0441         REQUIRE(s1 == "This,is,a,test");
0442 
0443         std::array<std::string, 2> v2 {"This,is", "a,test"};
0444         auto s2 = jpm.Stringify(v2);
0445         REQUIRE(s2 == "This\\,is,a\\,test");
0446 
0447         std::array<std::string, 2> v3 {"This,is", "a\\,test"};
0448         auto s3 = jpm.Stringify(v3);
0449         REQUIRE(s3 == "This\\,is,a\\\\,test");
0450     }
0451 }
0452 
0453 TEST_CASE("JParameterManagerFloatingPointRoundTrip") {
0454     JParameterManager jpm;
0455 
0456     SECTION("Integer") {
0457         const std::string testValString = jpm.Stringify(123);
0458         REQUIRE(testValString == "123");
0459         int testValParsed;
0460         jpm.Parse<int>(testValString, testValParsed);
0461         REQUIRE(testValParsed == 123);
0462     }
0463 
0464     SECTION("Double requiring low precision") {
0465         const double testVal = 123;
0466         const std::string testValString = jpm.Stringify(testVal);
0467         REQUIRE(testValString == "123");
0468         double testValParsed;
0469         jpm.Parse<double>(testValString, testValParsed);
0470         REQUIRE(testValParsed == 123.0);
0471     }
0472 
0473     SECTION("Double requiring low precision, with extra zeros") {
0474         const double testVal = 123.0;
0475         const std::string testValString = jpm.Stringify(testVal);
0476         REQUIRE(testValString == "123");
0477         double testValParsed;
0478         jpm.Parse<double>(testValString, testValParsed);
0479         REQUIRE(testValParsed == 123.0);
0480     }
0481 
0482     SECTION("Double requiring high precision") {
0483         const double testVal = 123.0001;
0484         const std::string testValString = jpm.Stringify(testVal);
0485         std::cout << "High-precision double stringified to " << testValString << std::endl;
0486         // REQUIRE(testValString == "123.0001");
0487         double testValParsed;
0488         jpm.Parse<double>(testValString, testValParsed);
0489         REQUIRE(testValParsed == 123.0001);
0490     }
0491 
0492     SECTION("Float requiring high precision") {
0493         const float testVal = 123.0001f;
0494         const std::string testValString = jpm.Stringify(testVal);
0495         std::cout << "High-precision float stringified to " << testValString << std::endl;
0496         // REQUIRE(testValString == "123.0001");
0497         float testValParsed;
0498         jpm.Parse<float>(testValString, testValParsed);
0499         REQUIRE(testValParsed == 123.0001f);
0500     }
0501 
0502     SECTION("Float requiring low precision") {
0503         const float testVal = 123.0f;
0504         const std::string testValString = jpm.Stringify(testVal);
0505         REQUIRE(testValString == "123");
0506         float testValParsed;
0507         jpm.Parse<float>(testValString, testValParsed);
0508         REQUIRE(testValParsed == 123.0f);
0509     }
0510 
0511 }
0512 
0513 
0514 TEST_CASE("JParameterManagerIssue233") {
0515     JParameterManager jpm;
0516     double x = 0.0;
0517     jpm.SetDefaultParameter("x", x, "Description");
0518     // This should NOT print out a warning about losing equality with itself after stringification
0519 
0520     // We reproduce the logic inside SetDefaultParameter here so that CI can catch regressions
0521     std::string x_stringified = JParameterManager::Stringify(x);
0522     double x_roundtrip;
0523     JParameterManager::Parse(x_stringified, x_roundtrip);
0524     REQUIRE(JParameterManager::Equals(x_roundtrip, x));
0525 }
0526 
0527 
0528 TEST_CASE("JParameterManager_Issue217StringsWithWhitespace") {
0529     JParameterManager jpm;
0530     SECTION("Reading a array of strings") {
0531         jpm.SetParameter("test", "(  abs(fmod(tower_1, 24) - fmod(tower_2, 24))  + min(      abs((sector_1 - sector_2) * (2 * 5) + (floor(tower_1 / 24) - floor(tower_2 / 24)) * 5 + fmod(tile_1, 5) - fmod(tile_2, 5)),      (32 * 2 * 5) - abs((sector_1 - sector_2) * (2 * 5) + (floor(tower_1 / 24) - floor(tower_2 / 24)) * 5 + fmod(tile_1, 5) - fmod(tile_2, 5))    )) == 1");
0532         std::string vals;
0533         jpm.GetParameter<std::string>("test", vals); 
0534         REQUIRE(vals == "(  abs(fmod(tower_1, 24) - fmod(tower_2, 24))  + min(      abs((sector_1 - sector_2) * (2 * 5) + (floor(tower_1 / 24) - floor(tower_2 / 24)) * 5 + fmod(tile_1, 5) - fmod(tile_2, 5)),      (32 * 2 * 5) - abs((sector_1 - sector_2) * (2 * 5) + (floor(tower_1 / 24) - floor(tower_2 / 24)) * 5 + fmod(tile_1, 5) - fmod(tile_2, 5))    )) == 1");
0535     }
0536 }
0537 
0538 
0539 enum class Mood {Good, Bad, Mediocre};
0540 TEST_CASE("JParameterManager_CompileTimeErrorForParseAndStringify") {
0541 
0542     int x;
0543     JParameterManager::Parse("22", x);
0544     // Uncomment these to test compile-time error message
0545     //Mood m;
0546     //JParameterManager::Parse("Mediocre", m);
0547     //JParameterManager::Stringify(m);
0548 }
0549 
0550 
0551 TEST_CASE("JParameterManager_Strictness") {
0552     JParameterManager sut;
0553     sut.SetParameter("jana:parameter_strictness", 2);
0554     sut.SetParameter("jana:unused", 22);
0555     bool exception_found = false;
0556     try {
0557         sut.PrintParameters();
0558     }
0559     catch (JException& e) {
0560         exception_found = true;
0561     }
0562     REQUIRE(exception_found == true);
0563 }
0564 
0565 
0566 
0567 TEST_CASE("JParameterManager_ConflictingDefaults") {
0568 
0569     int x1 = 3;
0570     int x2 = 4;
0571     int x3 = 3;
0572     int x4 = 4;
0573 
0574     JParameterManager sut;
0575     sut.SetLogger(JLogger());
0576 
0577     // Simulate a FactorySet containing two JFactories, each of which declares the same parameter with different default values
0578     auto p1 = sut.SetDefaultParameter("my_param_name", x1, "Tests how conflicting defaults are handled");
0579     REQUIRE(p1->HasDefault() == true);
0580     REQUIRE(p1->IsDefault() == true);
0581     REQUIRE(p1->GetDefault() == "3"); // Should be the _latest_ default found
0582     REQUIRE(p1->GetValue() == "3"); // Should be the _latest_ default value
0583     REQUIRE(x1 == 3);
0584     auto p2 = sut.SetDefaultParameter("my_param_name", x2, "Tests how conflicting defaults are handled");
0585     REQUIRE(p2->HasDefault() == true);
0586     REQUIRE(p2->IsDefault() == true);
0587     REQUIRE(p2->GetDefault() == "4"); // Should be the _latest_ default found
0588     REQUIRE(p2->GetValue() == "4"); // Should be the _latest_ default value
0589     REQUIRE(x2 == 4);
0590     
0591     // Simulate a _second_ FactorySet containing fresh instances of the same two JFactories, 
0592     auto p3 = sut.SetDefaultParameter("my_param_name", x3, "Tests how conflicting defaults are handled");
0593     REQUIRE(p3->HasDefault() == true);
0594     REQUIRE(p3->IsDefault() == true);
0595     REQUIRE(p3->GetDefault() == "3"); // Should be the _latest_ default found
0596     REQUIRE(p3->GetValue() == "3"); // Should be the _latest_ default value
0597     REQUIRE(x3 == 3);
0598     auto p4 = sut.SetDefaultParameter("my_param_name", x4, "Tests how conflicting defaults are handled");
0599     REQUIRE(p4->HasDefault() == true);
0600     REQUIRE(p4->IsDefault() == true);
0601     REQUIRE(p4->GetDefault() == "4"); // Should be the _latest_ default value found
0602     REQUIRE(p4->GetValue() == "4"); // Should be the _latest_ default value
0603     REQUIRE(x4 == 4);
0604 
0605     sut.PrintParameters(2,1);
0606 }
0607 
0608 
0609 
0610 
0611 
0612 
0613 
0614