/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_deserialize, test_deserialize_ds) /* *INDENT-ON* */ { /* given */ char *actual_result; /* when */ actual_result = mc_deserialize_str (data->input_char_prefix, data->input_string, &error); /* then */ mctest_assert_str_eq (actual_result, data->expected_result); g_free (actual_result); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_deserialize_incorrect, test_deserialize_incorrect_ds) /* *INDENT-ON* */ { /* given */ char *actual_result; /* when */ actual_result = mc_deserialize_str (data->input_char_prefix, data->input_string, &error); /* then */ mctest_assert_null (actual_result); mctest_assert_int_eq (error->code, data->expected_error_code); mctest_assert_str_eq (error->message, data->expected_error_string); }
mc_config_t * mc_deserialize_config (const char *data, GError ** error) { char *current_group = NULL, *current_param = NULL, *current_value = NULL; size_t current_position = 0; mc_config_t *ret_data = mc_config_init (NULL); enum automat_status { WAIT_GROUP, WAIT_PARAM, WAIT_VALUE } current_status = WAIT_GROUP; while (data != NULL) { if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL)) current_status = WAIT_PARAM; switch (current_status) { case WAIT_GROUP: g_free (current_group); current_group = mc_deserialize_str ('g', data, error); if (current_group == NULL) prepend_error_and_exit (); data = go_to_end_of_serialized_string (data, current_group, ¤t_position); current_status = WAIT_PARAM; break; case WAIT_PARAM: g_free (current_param); current_param = mc_deserialize_str ('p', data, error); if (current_param == NULL) { g_free (current_group); prepend_error_and_exit (); } data = go_to_end_of_serialized_string (data, current_param, ¤t_position); current_status = WAIT_VALUE; break; case WAIT_VALUE: current_value = mc_deserialize_str ('v', data, error); if (current_param == NULL) { g_free (current_group); g_free (current_param); prepend_error_and_exit (); } mc_config_set_string (ret_data, current_group, current_param, current_value); data = go_to_end_of_serialized_string (data, current_value, ¤t_position); g_free (current_value); current_status = WAIT_GROUP; break; } } g_free (current_group); g_free (current_param); return ret_data; }