1b5975d6bSopenharmony_ciFrom 653f8eb0203485c7ffb0eeae81e6e30437d18529 Mon Sep 17 00:00:00 2001 2b5975d6bSopenharmony_ciFrom: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net> 3b5975d6bSopenharmony_ciDate: Fri, 9 Sep 2022 18:43:47 +0200 4b5975d6bSopenharmony_ciSubject: [PATCH] tests/regex: Perform more tests both with and without 5b5975d6bSopenharmony_ci optimizations 6b5975d6bSopenharmony_ci 7b5975d6bSopenharmony_ci--- 8b5975d6bSopenharmony_ci glib/tests/regex.c | 101 +++++++++++++++++++++++++++++++++++++++++---- 9b5975d6bSopenharmony_ci 1 file changed, 93 insertions(+), 8 deletions(-) 10b5975d6bSopenharmony_ci 11b5975d6bSopenharmony_cidiff --git a/glib/tests/regex.c b/glib/tests/regex.c 12b5975d6bSopenharmony_ciindex 2052ba0204..9803d49659 100644 13b5975d6bSopenharmony_ci--- a/glib/tests/regex.c 14b5975d6bSopenharmony_ci+++ b/glib/tests/regex.c 15b5975d6bSopenharmony_ci@@ -173,7 +173,24 @@ test_match_simple (gconstpointer d) 16b5975d6bSopenharmony_ci data->compile_opts = _compile_opts; \ 17b5975d6bSopenharmony_ci data->match_opts = _match_opts; \ 18b5975d6bSopenharmony_ci data->expected = _expected; \ 19b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/match-%s/%d", _name, ++total); \ 20b5975d6bSopenharmony_ci+ total++; \ 21b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 22b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-%s-optimized/%d", _name, total); \ 23b5975d6bSopenharmony_ci+ else \ 24b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-%s/%d", _name, total); \ 25b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_match_simple, g_free); \ 26b5975d6bSopenharmony_ci+ g_free (path); \ 27b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestMatchData)); \ 28b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 29b5975d6bSopenharmony_ci+ { \ 30b5975d6bSopenharmony_ci+ data->compile_opts &= ~G_REGEX_OPTIMIZE; \ 31b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-%s/%d", _name, total); \ 32b5975d6bSopenharmony_ci+ } \ 33b5975d6bSopenharmony_ci+ else \ 34b5975d6bSopenharmony_ci+ { \ 35b5975d6bSopenharmony_ci+ data->compile_opts |= G_REGEX_OPTIMIZE; \ 36b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-%s-optimized/%d", _name, total); \ 37b5975d6bSopenharmony_ci+ } \ 38b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_match_simple, g_free); \ 39b5975d6bSopenharmony_ci g_free (path); \ 40b5975d6bSopenharmony_ci } 41b5975d6bSopenharmony_ci@@ -361,7 +378,24 @@ test_match (gconstpointer d) 42b5975d6bSopenharmony_ci data->start_position = _start_position; \ 43b5975d6bSopenharmony_ci data->match_opts2 = _match_opts2; \ 44b5975d6bSopenharmony_ci data->expected = _expected; \ 45b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/match/%d", ++total); \ 46b5975d6bSopenharmony_ci+ total++; \ 47b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 48b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-optimized/%d", total); \ 49b5975d6bSopenharmony_ci+ else \ 50b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/%d", total); \ 51b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_match, g_free); \ 52b5975d6bSopenharmony_ci+ g_free (path); \ 53b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestMatchData)); \ 54b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 55b5975d6bSopenharmony_ci+ { \ 56b5975d6bSopenharmony_ci+ data->compile_opts &= ~G_REGEX_OPTIMIZE; \ 57b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/%d", total); \ 58b5975d6bSopenharmony_ci+ } \ 59b5975d6bSopenharmony_ci+ else \ 60b5975d6bSopenharmony_ci+ { \ 61b5975d6bSopenharmony_ci+ data->compile_opts |= G_REGEX_OPTIMIZE; \ 62b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match-optimized/%d", total); \ 63b5975d6bSopenharmony_ci+ } \ 64b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_match, g_free); \ 65b5975d6bSopenharmony_ci g_free (path); \ 66b5975d6bSopenharmony_ci } 67b5975d6bSopenharmony_ci@@ -580,6 +614,7 @@ typedef struct { 68b5975d6bSopenharmony_ci const gchar *pattern; 69b5975d6bSopenharmony_ci const gchar *string; 70b5975d6bSopenharmony_ci gint start_position; 71b5975d6bSopenharmony_ci+ GRegexCompileFlags compile_flags; 72b5975d6bSopenharmony_ci GRegexMatchFlags match_opts; 73b5975d6bSopenharmony_ci gint expected_count; 74b5975d6bSopenharmony_ci } TestMatchCountData; 75b5975d6bSopenharmony_ci@@ -592,7 +627,8 @@ test_match_count (gconstpointer d) 76b5975d6bSopenharmony_ci GMatchInfo *match_info; 77b5975d6bSopenharmony_ci gint count; 78b5975d6bSopenharmony_ci 79b5975d6bSopenharmony_ci- regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL); 80b5975d6bSopenharmony_ci+ regex = g_regex_new (data->pattern, data->compile_flags, 81b5975d6bSopenharmony_ci+ G_REGEX_MATCH_DEFAULT, NULL); 82b5975d6bSopenharmony_ci 83b5975d6bSopenharmony_ci g_assert (regex != NULL); 84b5975d6bSopenharmony_ci 85b5975d6bSopenharmony_ci@@ -617,7 +653,14 @@ test_match_count (gconstpointer d) 86b5975d6bSopenharmony_ci data->start_position = _start_position; \ 87b5975d6bSopenharmony_ci data->match_opts = _match_opts; \ 88b5975d6bSopenharmony_ci data->expected_count = _expected_count; \ 89b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/match/count/%d", ++total); \ 90b5975d6bSopenharmony_ci+ data->compile_flags = G_REGEX_DEFAULT; \ 91b5975d6bSopenharmony_ci+ total++; \ 92b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/count/%d", total); \ 93b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_match_count, g_free); \ 94b5975d6bSopenharmony_ci+ g_free (path); \ 95b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestMatchCountData)); \ 96b5975d6bSopenharmony_ci+ data->compile_flags |= G_REGEX_OPTIMIZE; \ 97b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/count-optimized/%d", total); \ 98b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_match_count, g_free); \ 99b5975d6bSopenharmony_ci g_free (path); \ 100b5975d6bSopenharmony_ci } 101b5975d6bSopenharmony_ci@@ -656,7 +699,24 @@ test_partial (gconstpointer d) 102b5975d6bSopenharmony_ci data->compile_opts = _compile_opts; \ 103b5975d6bSopenharmony_ci data->match_opts = _match_opts; \ 104b5975d6bSopenharmony_ci data->expected = _expected; \ 105b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/match/partial/%d", ++total); \ 106b5975d6bSopenharmony_ci+ total++; \ 107b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 108b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/partial-optimized/%d", total); \ 109b5975d6bSopenharmony_ci+ else \ 110b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/partial%d", total); \ 111b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_partial, g_free); \ 112b5975d6bSopenharmony_ci+ g_free (path); \ 113b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestMatchData)); \ 114b5975d6bSopenharmony_ci+ if (data->compile_opts & G_REGEX_OPTIMIZE) \ 115b5975d6bSopenharmony_ci+ { \ 116b5975d6bSopenharmony_ci+ data->compile_opts &= ~G_REGEX_OPTIMIZE; \ 117b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/partial%d", total); \ 118b5975d6bSopenharmony_ci+ } \ 119b5975d6bSopenharmony_ci+ else \ 120b5975d6bSopenharmony_ci+ { \ 121b5975d6bSopenharmony_ci+ data->compile_opts |= G_REGEX_OPTIMIZE; \ 122b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/partial-optimized/%d", total); \ 123b5975d6bSopenharmony_ci+ } \ 124b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_partial, g_free); \ 125b5975d6bSopenharmony_ci g_free (path); \ 126b5975d6bSopenharmony_ci } 127b5975d6bSopenharmony_ci@@ -666,6 +726,7 @@ test_partial (gconstpointer d) 128b5975d6bSopenharmony_ci typedef struct { 129b5975d6bSopenharmony_ci const gchar *pattern; 130b5975d6bSopenharmony_ci const gchar *string; 131b5975d6bSopenharmony_ci+ GRegexCompileFlags compile_flags; 132b5975d6bSopenharmony_ci gint start_position; 133b5975d6bSopenharmony_ci gint sub_n; 134b5975d6bSopenharmony_ci const gchar *expected_sub; 135b5975d6bSopenharmony_ci@@ -682,7 +743,7 @@ test_sub_pattern (gconstpointer d) 136b5975d6bSopenharmony_ci gchar *sub_expr; 137b5975d6bSopenharmony_ci gint start = UNTOUCHED, end = UNTOUCHED; 138b5975d6bSopenharmony_ci 139b5975d6bSopenharmony_ci- regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL); 140b5975d6bSopenharmony_ci+ regex = g_regex_new (data->pattern, data->compile_flags, G_REGEX_MATCH_DEFAULT, NULL); 141b5975d6bSopenharmony_ci 142b5975d6bSopenharmony_ci g_assert (regex != NULL); 143b5975d6bSopenharmony_ci 144b5975d6bSopenharmony_ci@@ -712,7 +773,14 @@ test_sub_pattern (gconstpointer d) 145b5975d6bSopenharmony_ci data->expected_sub = _expected_sub; \ 146b5975d6bSopenharmony_ci data->expected_start = _expected_start; \ 147b5975d6bSopenharmony_ci data->expected_end = _expected_end; \ 148b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/match/subpattern/%d", ++total); \ 149b5975d6bSopenharmony_ci+ data->compile_flags = G_REGEX_DEFAULT; \ 150b5975d6bSopenharmony_ci+ total++; \ 151b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/subpattern/%d", total); \ 152b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_sub_pattern, g_free); \ 153b5975d6bSopenharmony_ci+ g_free (path); \ 154b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestSubData)); \ 155b5975d6bSopenharmony_ci+ data->compile_flags = G_REGEX_OPTIMIZE; \ 156b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/match/subpattern-optimized/%d", total); \ 157b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_sub_pattern, g_free); \ 158b5975d6bSopenharmony_ci g_free (path); \ 159b5975d6bSopenharmony_ci } 160b5975d6bSopenharmony_ci@@ -1246,7 +1314,24 @@ test_replace (gconstpointer d) 161b5975d6bSopenharmony_ci data->expected = _expected; \ 162b5975d6bSopenharmony_ci data->compile_flags = _compile_flags; \ 163b5975d6bSopenharmony_ci data->match_flags = _match_flags; \ 164b5975d6bSopenharmony_ci- path = g_strdup_printf ("/regex/replace/%d", ++total); \ 165b5975d6bSopenharmony_ci+ total++; \ 166b5975d6bSopenharmony_ci+ if (data->compile_flags & G_REGEX_OPTIMIZE) \ 167b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/replace-optimized/%d", total); \ 168b5975d6bSopenharmony_ci+ else \ 169b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/replace/%d", total); \ 170b5975d6bSopenharmony_ci+ g_test_add_data_func_full (path, data, test_replace, g_free); \ 171b5975d6bSopenharmony_ci+ g_free (path); \ 172b5975d6bSopenharmony_ci+ data = g_memdup2 (data, sizeof (TestReplaceData)); \ 173b5975d6bSopenharmony_ci+ if (data->compile_flags & G_REGEX_OPTIMIZE) \ 174b5975d6bSopenharmony_ci+ { \ 175b5975d6bSopenharmony_ci+ data->compile_flags &= ~G_REGEX_OPTIMIZE; \ 176b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/replace/%d", total); \ 177b5975d6bSopenharmony_ci+ } \ 178b5975d6bSopenharmony_ci+ else \ 179b5975d6bSopenharmony_ci+ { \ 180b5975d6bSopenharmony_ci+ data->compile_flags |= G_REGEX_OPTIMIZE; \ 181b5975d6bSopenharmony_ci+ path = g_strdup_printf ("/regex/replace-optimized/%d", total); \ 182b5975d6bSopenharmony_ci+ } \ 183b5975d6bSopenharmony_ci g_test_add_data_func_full (path, data, test_replace, g_free); \ 184b5975d6bSopenharmony_ci g_free (path); \ 185b5975d6bSopenharmony_ci } 186b5975d6bSopenharmony_ci-- 187b5975d6bSopenharmony_ciGitLab 188b5975d6bSopenharmony_ci 189