19 #include <gtest/gtest.h> 30 int8_t max_state_value = packml_msgs::State::COMPLETE + 1;
32 SCOPED_TRACE(
"StatusActionEmptyTest");
35 SCOPED_TRACE(
"StatusActionCorrectSize");
62 EXPECT_EQ(
false, light.
active_);
64 EXPECT_EQ(packml_stacklight::Light::Value::UNDEFINED, light.
current_);
70 EXPECT_EQ(
false, buzzer.
active_);
79 EXPECT_EQ(packml_stacklight::Button::Value::UNDEFINED, button.
current_);
84 int8_t max_light_value = packml_stacklight::Light::Value::BLUE + 1;
86 std::vector<packml_stacklight::Action>::iterator action_it;
89 EXPECT_EQ(max_light_value, action_it->light_vec_.size());
95 int8_t max_button_value = packml_stacklight::Button::Value::RESET + 1;
97 std::vector<packml_stacklight::Action>::iterator action_it;
100 EXPECT_EQ(max_button_value, action_it->button_vec_.size());
106 for (int8_t state = packml_msgs::State::UNDEFINED; state <= packml_msgs::State::COMPLETE; state++)
108 std::vector<packml_stacklight::Light>::iterator light_it;
109 std::vector<packml_stacklight::Button>::iterator button_it;
110 packml_msgs::State temp;
117 case packml_msgs::State::ABORTING:
118 case packml_msgs::State::ABORTED:
121 if (light_it->current_ == packml_stacklight::Light::Value::RED ||
122 light_it->current_ == packml_stacklight::Light::Value::BLUE)
124 EXPECT_EQ(
true, light_it->active_);
125 EXPECT_EQ(
true, light_it->flashing_);
129 EXPECT_EQ(
false, light_it->active_);
135 if (button_it->current_ == packml_stacklight::Button::Value::RESET)
137 EXPECT_EQ(
true, button_it->light_.active_);
138 EXPECT_EQ(
true, button_it->light_.flashing_);
139 EXPECT_EQ(packml_stacklight::Light::Value::BLUE, button_it->light_.current_);
143 EXPECT_EQ(
false, button_it->light_.active_);
150 case packml_msgs::State::CLEARING:
153 if (light_it->current_ == packml_stacklight::Light::Value::RED ||
154 light_it->current_ == packml_stacklight::Light::Value::BLUE)
156 EXPECT_EQ(
true, light_it->active_);
157 EXPECT_EQ(
true, light_it->flashing_);
161 EXPECT_EQ(
false, light_it->active_);
167 EXPECT_EQ(
false, button_it->light_.active_);
173 case packml_msgs::State::STOPPING:
174 case packml_msgs::State::STOPPED:
177 if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
179 EXPECT_EQ(
true, light_it->active_);
180 EXPECT_EQ(
true, light_it->flashing_);
182 else if (light_it->current_ == packml_stacklight::Light::Value::RED)
184 EXPECT_EQ(
true, light_it->active_);
185 EXPECT_EQ(
false, light_it->flashing_);
189 EXPECT_EQ(
false, light_it->active_);
195 EXPECT_EQ(
false, button_it->light_.active_);
201 case packml_msgs::State::RESETTING:
204 if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
206 EXPECT_EQ(
true, light_it->active_);
207 EXPECT_EQ(
true, light_it->flashing_);
211 EXPECT_EQ(
false, light_it->active_);
217 EXPECT_EQ(
false, button_it->light_.active_);
223 case packml_msgs::State::IDLE:
226 if (light_it->current_ == packml_stacklight::Light::Value::GREEN ||
227 light_it->current_ == packml_stacklight::Light::Value::BLUE)
229 EXPECT_EQ(
true, light_it->active_);
230 EXPECT_EQ(
true, light_it->flashing_);
234 EXPECT_EQ(
false, light_it->active_);
240 if (button_it->current_ == packml_stacklight::Button::Value::START)
242 EXPECT_EQ(
true, button_it->light_.active_);
243 EXPECT_EQ(
true, button_it->light_.flashing_);
244 EXPECT_EQ(packml_stacklight::Light::Value::GREEN, button_it->light_.current_);
248 EXPECT_EQ(
false, button_it->light_.active_);
255 case packml_msgs::State::STARTING:
256 case packml_msgs::State::UNHOLDING:
259 if (light_it->current_ == packml_stacklight::Light::Value::GREEN)
261 EXPECT_EQ(
true, light_it->active_);
262 EXPECT_EQ(
false, light_it->flashing_);
264 else if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
266 EXPECT_EQ(
true, light_it->active_);
267 EXPECT_EQ(
true, light_it->flashing_);
271 EXPECT_EQ(
false, light_it->active_);
277 if (button_it->current_ == packml_stacklight::Button::Value::START)
279 EXPECT_EQ(
true, button_it->light_.active_);
280 EXPECT_EQ(
false, button_it->light_.flashing_);
281 EXPECT_EQ(packml_stacklight::Light::Value::GREEN, button_it->light_.current_);
285 EXPECT_EQ(
false, button_it->light_.active_);
293 case packml_msgs::State::EXECUTE:
296 if (light_it->current_ == packml_stacklight::Light::Value::GREEN)
298 EXPECT_EQ(
true, light_it->active_);
299 EXPECT_EQ(
false, light_it->flashing_);
301 else if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
303 EXPECT_EQ(
true, light_it->active_);
304 EXPECT_EQ(
true, light_it->flashing_);
308 EXPECT_EQ(
false, light_it->active_);
314 if (button_it->current_ == packml_stacklight::Button::Value::START)
316 EXPECT_EQ(
true, button_it->light_.active_);
317 EXPECT_EQ(
false, button_it->light_.flashing_);
318 EXPECT_EQ(packml_stacklight::Light::Value::GREEN, button_it->light_.current_);
322 EXPECT_EQ(
false, button_it->light_.active_);
329 case packml_msgs::State::HOLDING:
330 case packml_msgs::State::HELD:
333 if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
335 EXPECT_EQ(
true, light_it->active_);
336 EXPECT_EQ(
false, light_it->flashing_);
340 EXPECT_EQ(
false, light_it->active_);
346 EXPECT_EQ(
false, button_it->light_.active_);
352 case packml_msgs::State::SUSPENDING:
353 case packml_msgs::State::SUSPENDED:
357 if (light_it->current_ == packml_stacklight::Light::Value::AMBER)
359 EXPECT_EQ(
true, light_it->active_);
360 EXPECT_EQ(
true, light_it->flashing_);
362 else if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
364 EXPECT_EQ(
true, light_it->active_);
365 EXPECT_EQ(
true, light_it->flashing_);
369 EXPECT_EQ(
false, light_it->active_);
375 if (button_it->current_ == packml_stacklight::Button::Value::START)
377 EXPECT_EQ(
true, button_it->light_.active_);
378 EXPECT_EQ(
false, button_it->light_.flashing_);
379 EXPECT_EQ(packml_stacklight::Light::Value::GREEN, button_it->light_.current_);
383 EXPECT_EQ(
false, button_it->light_.active_);
390 case packml_msgs::State::UNSUSPENDING:
393 if (light_it->current_ == packml_stacklight::Light::Value::GREEN)
395 EXPECT_EQ(
true, light_it->active_);
396 EXPECT_EQ(
false, light_it->flashing_);
398 else if (light_it->current_ == packml_stacklight::Light::Value::BLUE)
400 EXPECT_EQ(
true, light_it->active_);
401 EXPECT_EQ(
true, light_it->flashing_);
405 EXPECT_EQ(
false, light_it->active_);
411 EXPECT_EQ(
false, button_it->light_.active_);
421 EXPECT_EQ(
false, light_it->active_);
426 EXPECT_EQ(
false, button_it->light_.active_);
486 packml_msgs::State temp;
487 temp.val = packml_msgs::State::ABORTING;
496 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
500 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
504 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
508 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
512 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
516 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
518 temp.val = packml_msgs::State::ABORTED;
520 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
526 packml_msgs::State temp;
527 temp.val = packml_msgs::State::STOPPING;
536 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
540 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
544 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
548 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
552 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
556 EXPECT_EQ(packml_stacklight::Flash::Value::OFF, flash);
558 temp.val = packml_msgs::State::STOPPED;
560 EXPECT_EQ(packml_stacklight::Flash::Value::ON, flash);
565 bool pub_all =
false;
566 packml_msgs::State temp;
567 temp.val = packml_msgs::State::UNDEFINED;
574 EXPECT_EQ(
true, pub_all);
578 EXPECT_EQ(
false, pub_all);
582 EXPECT_EQ(
false, pub_all);
586 EXPECT_EQ(
true, pub_all);
590 EXPECT_EQ(
false, pub_all);
594 EXPECT_EQ(
false, pub_all);
599 bool pub_all =
false;
600 packml_msgs::State temp;
601 temp.val = packml_msgs::State::STOPPING;
608 EXPECT_EQ(
true, pub_all);
612 EXPECT_EQ(
false, pub_all);
616 EXPECT_EQ(
true, pub_all);
620 EXPECT_EQ(
false, pub_all);
624 EXPECT_EQ(
false, pub_all);
628 EXPECT_EQ(
true, pub_all);
631 temp.val = packml_msgs::State::STOPPED;
633 EXPECT_EQ(
true, pub_all);
637 EXPECT_EQ(
false, pub_all);
642 packml_msgs::State temp;
643 temp.val = packml_msgs::State::STOPPING;
651 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
656 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
660 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
664 EXPECT_EQ(packml_msgs::State::UNDEFINED, temp.val);
669 packml_msgs::State temp;
670 temp.val = packml_msgs::State::STOPPING;
678 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
683 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
687 EXPECT_EQ(packml_msgs::State::STOPPING, temp.val);
692 packml_msgs::State temp;
693 temp.val = packml_msgs::State::STARTING;
694 int8_t max_light_value = packml_stacklight::Light::Value::BLUE;
695 int8_t max_button_value = packml_stacklight::Button::Value::RESET;
696 int32_t max_map_count = max_light_value + max_button_value + 1;
699 std::map<std::string, uint8_t> temp_map =
getPubMap(action);
700 EXPECT_EQ(max_map_count, temp_map.size());
705 packml_msgs::State temp;
706 temp.val = packml_msgs::State::STARTING;
707 int8_t max_light_value = packml_stacklight::Light::Value::BLUE;
708 int8_t max_button_value = packml_stacklight::Button::Value::RESET;
709 int32_t max_map_count = max_light_value + max_button_value + 1;
711 std::map<std::string, uint8_t> temp_map =
getPubMap(temp);
712 EXPECT_EQ(max_map_count, temp_map.size());
717 packml_msgs::State temp;
718 temp.val = packml_msgs::State::UNDEFINED;
720 std::map<std::string, uint8_t> temp_map =
getPubMap(temp);
721 std::map<std::string, uint8_t>::iterator map_itr;
723 map_itr = temp_map.find(
"UNDEFINED");
724 EXPECT_EQ(temp_map.end(), map_itr);
726 map_itr = temp_map.find(
"UNDEFINED-LIGHT");
727 EXPECT_EQ(temp_map.end(), map_itr);
729 map_itr = temp_map.find(
"UNDEFINED-BUTTON");
730 EXPECT_EQ(temp_map.end(), map_itr);
732 map_itr = temp_map.find(
"red");
733 EXPECT_NE(temp_map.end(), map_itr);
734 temp_map.erase(map_itr);
736 map_itr = temp_map.find(
"amber");
737 EXPECT_NE(temp_map.end(), map_itr);
738 temp_map.erase(map_itr);
740 map_itr = temp_map.find(
"green");
741 EXPECT_NE(temp_map.end(), map_itr);
742 temp_map.erase(map_itr);
744 map_itr = temp_map.find(
"blue");
745 EXPECT_NE(temp_map.end(), map_itr);
746 temp_map.erase(map_itr);
748 map_itr = temp_map.find(
"start");
749 EXPECT_NE(temp_map.end(), map_itr);
750 temp_map.erase(map_itr);
752 map_itr = temp_map.find(
"reset");
753 EXPECT_NE(temp_map.end(), map_itr);
754 temp_map.erase(map_itr);
756 map_itr = temp_map.find(
"buzzer");
757 EXPECT_NE(temp_map.end(), map_itr);
758 temp_map.erase(map_itr);
760 EXPECT_EQ(0, temp_map.size());
765 int main(
int argc,
char** argv)
768 ::testing::InitGoogleTest(&argc, argv);
770 int res = RUN_ALL_TESTS();
std::map< std::string, uint8_t > getPubMap(Action action)
std::vector< Button > button_vec_
double flash_sec_light_off_
void maybeResetState(packml_msgs::State ¤t_state, ros::Time &last_time)
Action getActionFromState(packml_msgs::State current_state)
std::vector< Action > action_vec_
bool getShouldPublish(packml_msgs::State current_state)
double publish_frequency_
double flash_sec_buzzer_off_
std::vector< Light > light_vec_
TEST_F(StacklightTest, LightActionDefault)
double flash_sec_light_on_
Flash::Value getBuzzerFlash(packml_msgs::State current_state)
Flash::Value getLightFlash(packml_msgs::State current_state)
FRIEND_TEST(StacklightTest, LightVectorInit)
int main(int argc, char **argv)
double flash_sec_buzzer_on_