Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : 3 : #include "emergency-action.h" 4 : #include "tests.h" 5 : 6 1 : static void test_parse_emergency_action(void) { 7 : EmergencyAction x; 8 : 9 1 : log_info("/* %s */", __func__); 10 : 11 1 : assert_se(parse_emergency_action("none", false, &x) == 0); 12 1 : assert_se(x == EMERGENCY_ACTION_NONE); 13 1 : assert_se(parse_emergency_action("reboot", false, &x) == -EOPNOTSUPP); 14 1 : assert_se(parse_emergency_action("reboot-force", false, &x) == -EOPNOTSUPP); 15 1 : assert_se(parse_emergency_action("reboot-immediate", false, &x) == -EOPNOTSUPP); 16 1 : assert_se(parse_emergency_action("poweroff", false, &x) == -EOPNOTSUPP); 17 1 : assert_se(parse_emergency_action("poweroff-force", false, &x) == -EOPNOTSUPP); 18 1 : assert_se(parse_emergency_action("poweroff-immediate", false, &x) == -EOPNOTSUPP); 19 1 : assert_se(x == EMERGENCY_ACTION_NONE); 20 1 : assert_se(parse_emergency_action("exit", false, &x) == 0); 21 1 : assert_se(x == EMERGENCY_ACTION_EXIT); 22 1 : assert_se(parse_emergency_action("exit-force", false, &x) == 0); 23 1 : assert_se(x == EMERGENCY_ACTION_EXIT_FORCE); 24 1 : assert_se(parse_emergency_action("exit-forcee", false, &x) == -EINVAL); 25 : 26 1 : assert_se(parse_emergency_action("none", true, &x) == 0); 27 1 : assert_se(x == EMERGENCY_ACTION_NONE); 28 1 : assert_se(parse_emergency_action("reboot", true, &x) == 0); 29 1 : assert_se(x == EMERGENCY_ACTION_REBOOT); 30 1 : assert_se(parse_emergency_action("reboot-force", true, &x) == 0); 31 1 : assert_se(x == EMERGENCY_ACTION_REBOOT_FORCE); 32 1 : assert_se(parse_emergency_action("reboot-immediate", true, &x) == 0); 33 1 : assert_se(x == EMERGENCY_ACTION_REBOOT_IMMEDIATE); 34 1 : assert_se(parse_emergency_action("poweroff", true, &x) == 0); 35 1 : assert_se(x == EMERGENCY_ACTION_POWEROFF); 36 1 : assert_se(parse_emergency_action("poweroff-force", true, &x) == 0); 37 1 : assert_se(x == EMERGENCY_ACTION_POWEROFF_FORCE); 38 1 : assert_se(parse_emergency_action("poweroff-immediate", true, &x) == 0); 39 1 : assert_se(parse_emergency_action("exit", true, &x) == 0); 40 1 : assert_se(parse_emergency_action("exit-force", true, &x) == 0); 41 1 : assert_se(parse_emergency_action("exit-forcee", true, &x) == -EINVAL); 42 1 : assert_se(x == EMERGENCY_ACTION_EXIT_FORCE); 43 1 : } 44 : 45 1 : int main(int argc, char **argv) { 46 1 : test_setup_logging(LOG_INFO); 47 : 48 1 : test_parse_emergency_action(); 49 : 50 1 : return EXIT_SUCCESS; 51 : }