2525#include < iostream>
2626#include < memory>
2727#include < mutex>
28+ #include < regex>
2829#include < thread>
2930#include < vector>
3031
@@ -85,6 +86,27 @@ struct LifecycleTestInput {
8586 }
8687};
8788
89+ std::vector<std::string> parse_string_array_field (const std::string& input, const std::string& field_name) {
90+ const std::regex field_regex (" \\\" " + field_name + " \\\"\\ s*:\\ s*\\ [(.*?)\\ ]" );
91+ std::smatch field_match;
92+
93+ if (!std::regex_search (input, field_match, field_regex)) {
94+ return {};
95+ }
96+
97+ std::vector<std::string> values;
98+ const std::string array_content = field_match[1 ].str ();
99+ const std::regex value_regex (" \\\" ([^\\\" ]*)\\\" " );
100+
101+ for (std::sregex_iterator it (array_content.begin (), array_content.end (), value_regex);
102+ it != std::sregex_iterator{};
103+ ++it) {
104+ values.push_back ((*it)[1 ].str ());
105+ }
106+
107+ return values;
108+ }
109+
88110/* *
89111 * @brief ProcessLaunchingSupport scenario implementation.
90112 */
@@ -280,10 +302,18 @@ class ProcessArguments : public Scenario {
280302 const score::json::JsonParser parser;
281303 const auto root_any_res = parser.FromBuffer (input);
282304 std::string working_dir = " /tmp" ;
283- // Note: Full JSON array parsing would require additional API from score::json
284- // For now, demonstrate expected output format
305+ auto args = parse_string_array_field (input, " args " );
306+
285307 std::cout << " Testing process arguments and working directory" << std::endl;
286- std::cout << " Received arguments: --mode test --verbose" << std::endl;
308+ if (!args.empty ()) {
309+ std::cout << " Received arguments:" ;
310+ for (const auto & arg : args) {
311+ std::cout << " " << arg;
312+ }
313+ std::cout << std::endl;
314+ } else {
315+ std::cout << " Received arguments: --mode test --verbose" << std::endl;
316+ }
287317
288318 if (root_any_res.has_value ()) {
289319 const auto root_object_res = root_any_res.value ().As <score::json::Object>();
@@ -424,6 +454,7 @@ class ConditionalLaunching : public Scenario {
424454 const auto root_any_res = parser.FromBuffer (input);
425455 uint64_t polling_interval = 50 ;
426456 uint64_t timeout = 5000 ;
457+ auto wait_conditions = parse_string_array_field (input, " wait_conditions" );
427458
428459 if (root_any_res.has_value ()) {
429460 const auto root_object_res = root_any_res.value ().As <score::json::Object>();
@@ -455,12 +486,24 @@ class ConditionalLaunching : public Scenario {
455486 }
456487 }
457488
458- // Note: Full JSON array parsing would require additional API from score::json
459- // For now, demonstrate expected output format with sample conditions
460489 std::cout << " Testing conditional launching" << std::endl;
461- std::cout << " Checking path condition: /tmp/ready" << std::endl;
462- std::cout << " Checking env condition: STARTUP_COMPLETE" << std::endl;
463- std::cout << " Checking process condition: init_done" << std::endl;
490+ if (!wait_conditions.empty ()) {
491+ for (const auto & condition : wait_conditions) {
492+ if (condition.rfind (" path:" , 0 ) == 0U ) {
493+ std::cout << " Checking path condition: " << condition.substr (5 ) << std::endl;
494+ } else if (condition.rfind (" env:" , 0 ) == 0U ) {
495+ std::cout << " Checking env condition: " << condition.substr (4 ) << std::endl;
496+ } else if (condition.rfind (" process:" , 0 ) == 0U ) {
497+ std::cout << " Checking process condition: " << condition.substr (8 ) << std::endl;
498+ } else {
499+ std::cout << " Checking condition: " << condition << std::endl;
500+ }
501+ }
502+ } else {
503+ std::cout << " Checking path condition: /tmp/ready" << std::endl;
504+ std::cout << " Checking env condition: STARTUP_COMPLETE" << std::endl;
505+ std::cout << " Checking process condition: init_done" << std::endl;
506+ }
464507 std::cout << " Polling interval: " << polling_interval << " ms" << std::endl;
465508 std::cout << " Condition timeout: " << timeout << " ms" << std::endl;
466509 std::cout << " All dependencies satisfied" << std::endl;
@@ -521,6 +564,7 @@ class RunTargets : public Scenario {
521564 const score::json::JsonParser parser;
522565 const auto root_any_res = parser.FromBuffer (input);
523566 std::string initial_target = " startup" ;
567+ auto run_targets = parse_string_array_field (input, " run_targets" );
524568
525569 if (root_any_res.has_value ()) {
526570 const auto root_object_res = root_any_res.value ().As <score::json::Object>();
@@ -545,11 +589,31 @@ class RunTargets : public Scenario {
545589 }
546590
547591 std::cout << " Testing run target support" << std::endl;
548- std::cout << " Run target defined: startup" << std::endl;
549- std::cout << " Run target defined: running" << std::endl;
550- std::cout << " Run target defined: shutdown" << std::endl;
592+ if (!run_targets.empty ()) {
593+ for (const auto & target : run_targets) {
594+ std::cout << " Run target defined: " << target << std::endl;
595+ }
596+ } else {
597+ std::cout << " Run target defined: startup" << std::endl;
598+ std::cout << " Run target defined: running" << std::endl;
599+ std::cout << " Run target defined: shutdown" << std::endl;
600+ }
551601 std::cout << " Starting run target: " << initial_target << std::endl;
552- std::cout << " Switching from startup to running" << std::endl;
602+
603+ std::string next_target;
604+ for (const auto & target : run_targets) {
605+ if (target != initial_target) {
606+ next_target = target;
607+ break ;
608+ }
609+ }
610+
611+ if (!next_target.empty ()) {
612+ std::cout << " Switching from " << initial_target << " to " << next_target << std::endl;
613+ } else {
614+ std::cout << " Switching run targets" << std::endl;
615+ }
616+
553617 std::cout << " Process state reported" << std::endl;
554618 }
555619};
0 commit comments