Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-06 10:24:14

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 
0239         std::vector<float> outputs = jpm.GetParameterValue<std::vector<float>>("test");
0240         REQUIRE(outputs == std::vector<float>{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         jpm.GetParameter<std::vector<std::string>>("test", vals);
0247         auto stringification = jpm.Stringify(vals);
0248 
0249         REQUIRE(stringification == "phi-fmod(phi\\,5),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0250 
0251         REQUIRE(vals[0] == "phi-fmod(phi,5)");
0252         REQUIRE(vals[1] == "theta-fmod(theta,10)");
0253         REQUIRE(vals[2] == "omega-fmod(omega,15)");
0254     }
0255     SECTION("Writing a vector of functions with commas") {
0256         std::vector<std::string> inputs;
0257         inputs.emplace_back("phi-fmod(phi,5)");
0258         inputs.emplace_back("theta-fmod(theta,10)");
0259         inputs.emplace_back("omega-fmod(omega,15)");
0260         std::vector<std::string> temp1 = inputs;
0261 
0262 
0263         jpm.SetDefaultParameter("test", inputs);
0264         auto stringified = jpm.Stringify(inputs);
0265         std::vector<std::string> mangled_inputs;
0266         jpm.Parse(stringified, mangled_inputs);
0267         REQUIRE(inputs == mangled_inputs);
0268 
0269         std::vector<std::string> outputs;
0270         auto param = jpm.GetParameter("test", outputs);
0271         REQUIRE(param->GetValue() == "phi-fmod(phi\\,5),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0272         REQUIRE(inputs.size()==3);
0273 
0274         std::vector<std::string> temp2;
0275         jpm.Parse(jpm.Stringify(temp1), temp2);
0276         REQUIRE(temp2 == outputs);
0277     }
0278     SECTION("ParseVectorOfStrings") {
0279 
0280         auto s1 = "This,is,a,test"; // Should have 4 elements in vector
0281         std::vector<std::string> v1;
0282         jpm.Parse(s1, v1);
0283         REQUIRE(v1.size() == 4);
0284         REQUIRE(v1.at(0) == "This");
0285 
0286         auto s2 = "This\\,is,a\\,test"; // Should have 2 elements in vector
0287         std::vector<std::string> v2;
0288         jpm.Parse(s2, v2);
0289         REQUIRE(v2.size() == 2);
0290         REQUIRE(v2.at(0) == "This,is");
0291         
0292         auto s3 = "This\\,is,a\\\\,test"; // Should have 2 elements in vector
0293         std::vector<std::string> v3;
0294         jpm.Parse(s3, v3);
0295         REQUIRE(v3.size() == 2);
0296         REQUIRE(v3.at(1) == "a\\,test");
0297     }
0298     SECTION("StringifyVectorOfStrings") {
0299 
0300         std::vector<std::string> v1 {"This", "is", "a", "test"};
0301         auto s1 = jpm.Stringify(v1);
0302         REQUIRE(s1 == "This,is,a,test");
0303 
0304         std::vector<std::string> v2 {"This,is", "a,test"};
0305         auto s2 = jpm.Stringify(v2);
0306         REQUIRE(s2 == "This\\,is,a\\,test");
0307         
0308         std::vector<std::string> v3 {"This,is", "a\\,test"};
0309         auto s3 = jpm.Stringify(v3);
0310         REQUIRE(s3 == "This\\,is,a\\\\,test");
0311     }
0312 }
0313 
0314 TEST_CASE("JParameterManager::RegisterParameter") {
0315 
0316     JParameterManager jpm;
0317 
0318     SECTION("Set/Get") {
0319         int x_default = 44;
0320         auto x_actual = jpm.RegisterParameter("testing:dummy_var", x_default);
0321         REQUIRE(x_actual == x_default);
0322     }
0323 
0324     SECTION("Set/Get templated float") {
0325         auto y_actual = jpm.RegisterParameter("testing:dummy_var2", 22.0);
0326         REQUIRE(y_actual == 22.0);
0327     }
0328 
0329     SECTION("Set/Get default") {
0330         jpm.SetParameter("testing:dummy_var", 22);
0331         auto x_actual = jpm.RegisterParameter("testing:dummy_var", 44);  // this should set the default value to 44 while keeping value at 22
0332         auto x_default_str = jpm.FindParameter("testing:dummy_var")->GetDefault();
0333         int x_default;
0334         jpm.Parse<int>(x_default_str,x_default);
0335         REQUIRE(x_actual == 22);
0336         REQUIRE(x_default == 44);
0337     }
0338 
0339 }
0340 
0341 TEST_CASE("JParameterManager_ArrayParams") {
0342     JParameterManager jpm;
0343 
0344     SECTION("Reading a array of strings") {
0345         jpm.SetParameter("test", "simple,whitespace in middle, also with whitespace padding ");
0346         std::array<std::string,3> vals;
0347         jpm.GetParameter<std::array<std::string,3>>("test", vals); 
0348         REQUIRE(vals[0] == "simple");
0349         REQUIRE(vals[1] == "whitespace in middle");
0350         REQUIRE(vals[2] == " also with whitespace padding ");
0351     }
0352     SECTION("Writing an array of strings") {
0353         std::array<std::string,3> inputs = {"first", "second one" , " third one "};
0354         jpm.SetDefaultParameter("test", inputs);
0355         std::array<std::string,3> outputs;
0356         auto param = jpm.GetParameter("test", outputs);
0357         REQUIRE(param->GetValue() == "first,second one, third one ");
0358     }
0359     SECTION("Reading a array of ints") {
0360         jpm.SetParameter("test", "1,2, 3 ");
0361         std::array<int32_t,3> vals;
0362         jpm.GetParameter("test", vals);
0363 
0364         REQUIRE(vals[0] == 1);
0365         REQUIRE(vals[1] == 2);
0366         REQUIRE(vals[2] == 3);
0367     }
0368     SECTION("Writing a array of ints") {
0369         std::array<int32_t,3> inputs = {22,49,42};
0370         jpm.SetDefaultParameter("test", inputs);
0371         std::array<std::string,3> outputs;
0372         auto param = jpm.GetParameter("test", outputs);
0373         REQUIRE(param->GetValue() == "22,49,42");
0374     }
0375     SECTION("Reading a array of floats") {
0376         jpm.SetParameter("test", "1,2,3");
0377         std::array<float,3> vals;
0378         jpm.GetParameter("test", vals);
0379 
0380         REQUIRE(vals[0] == 1.0f);
0381         REQUIRE(vals[1] == 2.0f);
0382         REQUIRE(vals[2] == 3.0f);
0383     }
0384     SECTION("Writing a array of floats") {
0385         std::array<float,3> inputs = {22.0,49.2,42.0};
0386         jpm.SetDefaultParameter("test", inputs);
0387 
0388         std::array<float,3> outputs = jpm.GetParameterValue<std::array<float,3>>("test");
0389         REQUIRE(outputs == std::array<float,3>{22.0, 49.2, 42.0});
0390     }
0391     SECTION("Reading a array of functions with commas") {
0392         // As of Mon Jan 27, JParameterManager does not allow an escape key to prevent splitting on the next comma)
0393         jpm.SetParameter("test", "theta-fmod(phi-fmod(phi\\,5)\\,7),theta-fmod(theta\\,10),omega-fmod(omega\\,15)"); // Issue #380 (Feature request)
0394         std::array<std::string, 3> vals;
0395         jpm.GetParameter("test", vals);
0396 
0397         REQUIRE(vals[0] == "theta-fmod(phi-fmod(phi,5),7)");
0398         REQUIRE(vals[1] == "theta-fmod(theta,10)");
0399         REQUIRE(vals[2] == "omega-fmod(omega,15)");
0400     }
0401     SECTION("Writing a array of functions with commas") {
0402         std::array<std::string, 3> inputs = {
0403             "theta-fmod(phi-fmod(phi,5),7)",
0404             "theta-fmod(theta,10)",
0405             "omega-fmod(omega,15)"
0406         };
0407 
0408         jpm.SetDefaultParameter("test", inputs);
0409         std::array<std::string,3> outputs;
0410 
0411         auto param = jpm.GetParameter("test", outputs);
0412 
0413         REQUIRE(outputs == inputs);
0414         REQUIRE(param->GetValue() == "theta-fmod(phi-fmod(phi\\,5)\\,7),theta-fmod(theta\\,10),omega-fmod(omega\\,15)");
0415     }
0416     SECTION("ParseArrayOfStrings") {
0417 
0418         auto s1 = "This,is,a,test"; // Should have 4 elements in vector
0419         std::array<std::string,4> v1;
0420         jpm.Parse(s1, v1);
0421         REQUIRE(v1.size() == 4);
0422         REQUIRE(v1.at(0) == "This");
0423 
0424         auto s2 = "This\\,is,a\\,test"; // Should have 2 elements in vector
0425         std::array<std::string, 2> v2;
0426         jpm.Parse(s2, v2);
0427         REQUIRE(v2.size() == 2);
0428         REQUIRE(v2.at(0) == "This,is");
0429 
0430         auto s3 = "This\\,is,a\\\\,test"; // Should have 2 elements in vector
0431         std::array<std::string, 2> v3;
0432         jpm.Parse(s3, v3);
0433         REQUIRE(v3.size() == 2);
0434         REQUIRE(v3.at(1) == "a\\,test");
0435     }
0436     SECTION("StringifyArrayOfStrings") {
0437 
0438         std::array<std::string, 4> v1 {"This", "is", "a", "test"};
0439         auto s1 = jpm.Stringify(v1);
0440         REQUIRE(s1 == "This,is,a,test");
0441 
0442         std::array<std::string, 2> v2 {"This,is", "a,test"};
0443         auto s2 = jpm.Stringify(v2);
0444         REQUIRE(s2 == "This\\,is,a\\,test");
0445 
0446         std::array<std::string, 2> v3 {"This,is", "a\\,test"};
0447         auto s3 = jpm.Stringify(v3);
0448         REQUIRE(s3 == "This\\,is,a\\\\,test");
0449     }
0450 }
0451 
0452 TEST_CASE("JParameterManagerFloatingPointRoundTrip") {
0453     JParameterManager jpm;
0454 
0455     SECTION("Integer") {
0456         const std::string testValString = jpm.Stringify(123);
0457         REQUIRE(testValString == "123");
0458         int testValParsed;
0459         jpm.Parse<int>(testValString, testValParsed);
0460         REQUIRE(testValParsed == 123);
0461     }
0462 
0463     SECTION("Double requiring low precision") {
0464         const double testVal = 123;
0465         const std::string testValString = jpm.Stringify(testVal);
0466         REQUIRE(testValString == "123");
0467         double testValParsed;
0468         jpm.Parse<double>(testValString, testValParsed);
0469         REQUIRE(testValParsed == 123.0);
0470     }
0471 
0472     SECTION("Double requiring low precision, with extra zeros") {
0473         const double testVal = 123.0;
0474         const std::string testValString = jpm.Stringify(testVal);
0475         REQUIRE(testValString == "123");
0476         double testValParsed;
0477         jpm.Parse<double>(testValString, testValParsed);
0478         REQUIRE(testValParsed == 123.0);
0479     }
0480 
0481     SECTION("Double requiring high precision") {
0482         const double testVal = 123.0001;
0483         const std::string testValString = jpm.Stringify(testVal);
0484         std::cout << "High-precision double stringified to " << testValString << std::endl;
0485         // REQUIRE(testValString == "123.0001");
0486         double testValParsed;
0487         jpm.Parse<double>(testValString, testValParsed);
0488         REQUIRE(testValParsed == 123.0001);
0489     }
0490 
0491     SECTION("Float requiring high precision") {
0492         const float testVal = 123.0001f;
0493         const std::string testValString = jpm.Stringify(testVal);
0494         std::cout << "High-precision float stringified to " << testValString << std::endl;
0495         // REQUIRE(testValString == "123.0001");
0496         float testValParsed;
0497         jpm.Parse<float>(testValString, testValParsed);
0498         REQUIRE(testValParsed == 123.0001f);
0499     }
0500 
0501     SECTION("Float requiring low precision") {
0502         const float testVal = 123.0f;
0503         const std::string testValString = jpm.Stringify(testVal);
0504         REQUIRE(testValString == "123");
0505         float testValParsed;
0506         jpm.Parse<float>(testValString, testValParsed);
0507         REQUIRE(testValParsed == 123.0f);
0508     }
0509 
0510 }
0511 
0512 
0513 TEST_CASE("JParameterManagerIssue233") {
0514     JParameterManager jpm;
0515     double x = 0.0;
0516     jpm.SetDefaultParameter("x", x, "Description");
0517     // This should NOT print out a warning about losing equality with itself after stringification
0518 
0519     // We reproduce the logic inside SetDefaultParameter here so that CI can catch regressions
0520     std::string x_stringified = JParameterManager::Stringify(x);
0521     double x_roundtrip;
0522     JParameterManager::Parse(x_stringified, x_roundtrip);
0523     REQUIRE(JParameterManager::Equals(x_roundtrip, x));
0524 }
0525 
0526 
0527 TEST_CASE("JParameterManager_Issue217StringsWithWhitespace") {
0528     JParameterManager jpm;
0529     SECTION("Reading a array of strings") {
0530         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");
0531         std::string vals;
0532         jpm.GetParameter<std::string>("test", vals); 
0533         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");
0534     }
0535 }
0536 
0537 
0538 enum class Mood {Good, Bad, Mediocre};
0539 TEST_CASE("JParameterManager_CompileTimeErrorForParseAndStringify") {
0540 
0541     int x;
0542     JParameterManager::Parse("22", x);
0543     // Uncomment these to test compile-time error message
0544     //Mood m;
0545     //JParameterManager::Parse("Mediocre", m);
0546     //JParameterManager::Stringify(m);
0547 }
0548 
0549 
0550 TEST_CASE("JParameterManager_Strictness") {
0551     JParameterManager sut;
0552     sut.SetParameter("jana:parameter_strictness", 2);
0553     sut.SetParameter("jana:unused", 22);
0554     bool exception_found = false;
0555     try {
0556         sut.PrintParameters();
0557     }
0558     catch (JException& e) {
0559         exception_found = true;
0560     }
0561     REQUIRE(exception_found == true);
0562 }
0563 
0564 
0565 
0566 TEST_CASE("JParameterManager_ConflictingDefaults") {
0567 
0568     int x1 = 3;
0569     int x2 = 4;
0570     int x3 = 3;
0571     int x4 = 4;
0572 
0573     JParameterManager sut;
0574     sut.SetLogger(JLogger());
0575 
0576     // Simulate a FactorySet containing two JFactories, each of which declares the same parameter with different default values
0577     auto p1 = sut.SetDefaultParameter("my_param_name", x1, "Tests how conflicting defaults are handled");
0578     REQUIRE(p1->HasDefault() == true);
0579     REQUIRE(p1->IsDefault() == true);
0580     REQUIRE(p1->GetDefault() == "3"); // Should be the _latest_ default found
0581     REQUIRE(p1->GetValue() == "3"); // Should be the _latest_ default value
0582     REQUIRE(x1 == 3);
0583     auto p2 = sut.SetDefaultParameter("my_param_name", x2, "Tests how conflicting defaults are handled");
0584     REQUIRE(p2->HasDefault() == true);
0585     REQUIRE(p2->IsDefault() == true);
0586     REQUIRE(p2->GetDefault() == "4"); // Should be the _latest_ default found
0587     REQUIRE(p2->GetValue() == "4"); // Should be the _latest_ default value
0588     REQUIRE(x2 == 4);
0589     
0590     // Simulate a _second_ FactorySet containing fresh instances of the same two JFactories, 
0591     auto p3 = sut.SetDefaultParameter("my_param_name", x3, "Tests how conflicting defaults are handled");
0592     REQUIRE(p3->HasDefault() == true);
0593     REQUIRE(p3->IsDefault() == true);
0594     REQUIRE(p3->GetDefault() == "3"); // Should be the _latest_ default found
0595     REQUIRE(p3->GetValue() == "3"); // Should be the _latest_ default value
0596     REQUIRE(x3 == 3);
0597     auto p4 = sut.SetDefaultParameter("my_param_name", x4, "Tests how conflicting defaults are handled");
0598     REQUIRE(p4->HasDefault() == true);
0599     REQUIRE(p4->IsDefault() == true);
0600     REQUIRE(p4->GetDefault() == "4"); // Should be the _latest_ default value found
0601     REQUIRE(p4->GetValue() == "4"); // Should be the _latest_ default value
0602     REQUIRE(x4 == 4);
0603 
0604     sut.PrintParameters(2,1);
0605 }
0606 
0607 
0608 
0609 
0610 
0611 
0612 
0613