Test(Player, lifespan_check_positive) { player_t *pl = player_create(); chrono_init(&pl->p_lifespan, 0); player_lifespan_check(pl, 1); cr_expect_str_eq(pl->p_queued_msgs->l_end->n_data, "quit"); }
Test(test_str_format, hex_string__two_bytes__perfect) { gchar expected_output[5] = "4041"; gchar output[5]; gchar input[2] = "@A"; format_hex_string(input, sizeof(input), output, sizeof(output)); cr_expect_str_eq(output, expected_output, "format_hex_string output does not match with two bytes!"); }
Test(test_str_format, hex_string_with_delimiter__single_byte__perfect) { gchar expected_output[3] = "40"; gchar output[3]; gchar input[1] = "@"; format_hex_string_with_delimiter(input, sizeof(input), output, sizeof(output), ' '); cr_expect_str_eq(output, expected_output, "format_hex_string_with_delimiter output does not match!"); }
Test(test_str_format, hex_string_with_delimiter__two_bytes__perfect) { gchar expected_output[6] = "40 41"; gchar output[6]; gchar input[2] = "@A"; format_hex_string_with_delimiter(input, sizeof(input), output, sizeof(output), ' '); cr_expect_str_eq(output, expected_output, "format_hex_string_with_delimiter output does not match in case of two bytes!"); }
void assert_if_tokenizer_concatenated_result_not_match(STRTOK_R_FUN tokenizer, const char *delim, const char *input, const char *expected) { gchar *token; gchar *saveptr; gchar *result = (char *)g_malloc(strlen(input)+1); gchar *raw_string; gchar *result_ref = NULL; int result_idx = 0; int token_length; raw_string = g_strdup(input); for (token = tokenizer(raw_string, delim, &saveptr); token; token = tokenizer(NULL, delim, &saveptr)) { token_length = strlen(token); memcpy(result + result_idx, token, token_length); result_idx += token_length; } result[result_idx] = '\0'; if (result_idx) result_ref = result; if (NULL == expected) cr_assert_null(result_ref); else cr_expect_str_eq(result_ref, expected, "strtok return value mismatch"); g_free(raw_string); g_free(result); }