void test_str_ncpy() { const char *src = "foo"; char dest[80]; char *result, *expected_result; dest[60] = 'X'; check_unsigned_int(sizeof(dest), 80); check_char(dest[60], 'X'); result = str_ncpy(dest, src, sizeof(dest)); check_strs(dest, src, "1"); check_ptrs(result, dest, "2"); check_chars(dest[60], '\0', "should null-out rest of buffer"); expected_result = strncpy(dest, src, sizeof(dest)); check_strs(dest, src, "3"); check_ptrs(result, expected_result, "4"); }
void check_token(const char *input, unsigned int input_size, unsigned int *pos, const char *expected_result, unsigned int expected_pos) { char result[80]; lex_look_ahead(input, input_size, pos, result, sizeof(result)); check_unsigned_ints(*pos, expected_pos, "expected pos"); check_strs(result, expected_result, "token"); }
void test_lex_look_ahead_n_1() { const char *input = "foo= 2;int b;"; unsigned int len, pos; char result[80]; len = strlen(input); pos = 0; lex_look_ahead_n(input, len, &pos, 2, result, sizeof(result)); check_strs(result, "=", "test_lex_look_ahead_n_1"); }
void check_expected_calls(ecc_context *ctx, const char *test_name, const char **expected_calls, unsigned int count) { mock_data *data = (mock_data *)ctx->data; unsigned int i, len; char buf[10000]; sprintf(buf, "%s:\nexpected_calls {\n", test_name); for (i = 0; i < count; i++) { len = strlen(buf); sprintf(&buf[len], "%d:\t%s\n", i, expected_calls[i]); } len = strlen(buf); sprintf(&buf[len], "}\n"); len = strlen(buf); ctx->to_string(ctx, &buf[len], sizeof(buf) - len); check_unsigned_ints(data->calls, count, buf); for (i = 0; i < count; i++) { check_strs(data->call[i], expected_calls[i], buf); } }