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