<commit_before>// SPDX-License-Identifier: GPL-2.1-or-later
/*
 * Copyright (C) 2020 <NAME> <<EMAIL>>
 */

static inline void send_keypress(gp_widget *widget, int value, char ascii)
{
	gp_event ev_down = {
		.type = GP_EV_KEY,
		.code = GP_EV_KEY_DOWN,
		.key = {.key = value,
			.ascii = ascii}
	};

	gp_event ev_up = {
		.type = GP_EV_KEY,
		.code = GP_EV_KEY_UP,
		.key = {.key = value,
			.ascii = ascii}
	};

	gp_widget_ops_event(widget, NULL, &ev_down);
	gp_widget_ops_event(widget, NULL, &ev_up);
}

static int ascii_to_keys[] = {
	GP_KEY_A, GP_KEY_B, GP_KEY_C, GP_KEY_D, GP_KEY_E, GP_KEY_F, GP_KEY_G,
	GP_KEY_H, GP_KEY_I, GP_KEY_K, GP_KEY_L, GP_KEY_M, GP_KEY_N, GP_KEY_O,
	GP_KEY_P, GP_KEY_Q, GP_KEY_R, GP_KEY_S, GP_KEY_T, GP_KEY_U, GP_KEY_V,
	GP_KEY_W, GP_KEY_X, GP_KEY_Y, GP_KEY_Z,
};

static int ascii_to_key(char ch)
{
	if (ch == ' ')
		return GP_KEY_SPACE;

	if (ch < 'a' || ch > 'z')
		return -1;

	return ascii_to_keys[ch - 'a'];
}

static inline void type_string(gp_widget *widget, const char *ch)
{
	while (*ch) {
		int key = ascii_to_key(*ch);

		if (key < 0)
			continue;

		tst_msg("Sending keypress %i (%c)", key, *ch);

		send_keypress(widget, key, *ch);
		ch++;
	}
}
<commit_msg>test: widgets: Initialize event state.<commit_after>// SPDX-License-Identifier: GPL-2.1-or-later
/*
 * Copyright (C) 2020-2021 <NAME> <<EMAIL>>
 */

static inline void send_keypress(gp_widget *widget, int value, char ascii)
{
	gp_events_state st = {};

	gp_event ev_down = {
		.type = GP_EV_KEY,
		.code = GP_EV_KEY_DOWN,
		.key = {.key = value, .ascii = ascii},
		.st = &st,
	};

	gp_event ev_up = {
		.type = GP_EV_KEY,
		.code = GP_EV_KEY_UP,
		.key = {.key = value, .ascii = ascii},
		.st = &st,
	};

	gp_widget_ops_event(widget, NULL, &ev_down);
	gp_widget_ops_event(widget, NULL, &ev_up);
}

static int ascii_to_keys[] = {
	GP_KEY_A, GP_KEY_B, GP_KEY_C, GP_KEY_D, GP_KEY_E, GP_KEY_F, GP_KEY_G,
	GP_KEY_H, GP_KEY_I, GP_KEY_K, GP_KEY_L, GP_KEY_M, GP_KEY_N, GP_KEY_O,
	GP_KEY_P, GP_KEY_Q, GP_KEY_R, GP_KEY_S, GP_KEY_T, GP_KEY_U, GP_KEY_V,
	GP_KEY_W, GP_KEY_X, GP_KEY_Y, GP_KEY_Z,
};

static int ascii_to_key(char ch)
{
	if (ch == ' ')
		return GP_KEY_SPACE;

	if (ch < 'a' || ch > 'z')
		return -1;

	return ascii_to_keys[ch - 'a'];
}

static inline void type_string(gp_widget *widget, const char *ch)
{
	while (*ch) {
		int key = ascii_to_key(*ch);

		if (key < 0)
			continue;

		tst_msg("Sending keypress %i (%c)", key, *ch);

		send_keypress(widget, key, *ch);
		ch++;
	}
}

{'fraction_non_alphanumeric': 0.1554571083366895, 'fraction_numerical': 0.008054772452678213, 'mean_word_length': 3.9383697813121272, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1168068', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1162, 'n_words': 246}