@@ -170,6 +170,127 @@ START_TEST(test_util_appinfo_set) {
170170}
171171END_TEST
172172
173+ START_TEST (test_util_expr_substitute ) {
174+ apr_byte_t rc = FALSE;
175+ apr_pool_t * pool = oidc_test_pool_get ();
176+ const char * input = "match 292 numbers" ;
177+ const char * regexp = "^.* ([0-9]+).*$" ;
178+ const char * replace = "$1" ;
179+ char * output = NULL ;
180+ char * error_str = NULL ;
181+
182+ rc = oidc_util_regexp_substitute (pool , input , "$$$$$**@@" , replace , & output , & error_str );
183+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_substitute returned TRUE" );
184+ ck_assert_ptr_nonnull (error_str );
185+
186+ error_str = NULL ;
187+ rc = oidc_util_regexp_substitute (
188+ pool ,
189+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
190+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
191+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ,
192+ regexp , replace , & output , & error_str );
193+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_substitute returned TRUE" );
194+ ck_assert_ptr_nonnull (error_str );
195+
196+ error_str = NULL ;
197+ rc = oidc_util_regexp_substitute (pool , "" , "" , "" , & output , & error_str );
198+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_substitute returned TRUE" );
199+ ck_assert_ptr_nonnull (error_str );
200+
201+ error_str = NULL ;
202+ rc = oidc_util_regexp_substitute (pool , input , regexp , replace , & output , & error_str );
203+ ck_assert_msg (rc == TRUE, "oidc_util_regexp_substitute returned FALSE" );
204+ ck_assert_ptr_null (error_str );
205+ ck_assert_str_eq (output , "292" );
206+ }
207+ END_TEST
208+
209+ START_TEST (test_util_expr_first_match ) {
210+ apr_byte_t rc = FALSE;
211+ apr_pool_t * pool = oidc_test_pool_get ();
212+ const char * input = "12345 hello" ;
213+ const char * regexp = "^([0-9]+)\\s+([a-z]+)$" ;
214+ ;
215+ char * output = NULL ;
216+ char * error_str = NULL ;
217+
218+ rc = oidc_util_regexp_first_match (pool , input , "$$$$$**@@" , & output , & error_str );
219+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_first_match returned TRUE" );
220+ ck_assert_ptr_nonnull (error_str );
221+
222+ error_str = NULL ;
223+ rc = oidc_util_regexp_first_match (pool , "abc" , regexp , & output , & error_str );
224+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_first_match returned TRUE" );
225+ ck_assert_ptr_nonnull (error_str );
226+
227+ error_str = NULL ;
228+ rc = oidc_util_regexp_first_match (pool , "abc abc" , regexp , & output , & error_str );
229+ ck_assert_msg (rc == FALSE, "oidc_util_regexp_first_match returned TRUE" );
230+ ck_assert_ptr_nonnull (error_str );
231+
232+ error_str = NULL ;
233+ rc = oidc_util_regexp_first_match (pool , input , regexp , & output , & error_str );
234+ ck_assert_msg (rc == TRUE, "oidc_util_regexp_first_match returned FALSE" );
235+ ck_assert_ptr_null (error_str );
236+ ck_assert_str_eq (output , "12345" );
237+ }
238+ END_TEST
239+
240+ START_TEST (test_util_expr_parse ) {
241+ char * rv = NULL ;
242+ cmd_parms * cmd = oidc_test_cmd_get ("" );
243+ oidc_apr_expr_t * expr = NULL ;
244+
245+ // NB: stub only
246+
247+ expr = NULL ;
248+ rv = oidc_util_apr_expr_parse (cmd , NULL , & expr , FALSE);
249+ ck_assert_ptr_null (rv );
250+ ck_assert_ptr_null (expr );
251+
252+ // expr = NULL;
253+ // rv = oidc_util_apr_expr_parse(cmd, "% ||| true)", &expr, FALSE);
254+ // ck_assert_ptr_nonnull(rv);
255+ // ck_assert_ptr_null(expr);
256+
257+ expr = NULL ;
258+ rv = oidc_util_apr_expr_parse (cmd , "" , & expr , TRUE);
259+ ck_assert_ptr_null (rv );
260+ ck_assert_ptr_nonnull (expr );
261+ }
262+ END_TEST
263+
264+ START_TEST (test_util_expr_exec ) {
265+ const char * result = NULL ;
266+ char * rv = NULL ;
267+ cmd_parms * cmd = oidc_test_cmd_get ("" );
268+ request_rec * r = oidc_test_request_get ();
269+ oidc_apr_expr_t * expr = NULL ;
270+
271+ // NB: stub only
272+ expr = NULL ;
273+ rv = oidc_util_apr_expr_parse (cmd , "true" , & expr , FALSE);
274+ ck_assert_ptr_null (rv );
275+ ck_assert_ptr_nonnull (expr );
276+
277+ // NB: stub only
278+ result = oidc_util_apr_expr_exec (r , expr , TRUE);
279+ ck_assert_ptr_nonnull (result );
280+ ck_assert_str_eq (result , "stub.c" );
281+
282+ // NB: stub only
283+ result = oidc_util_apr_expr_exec (r , expr , FALSE);
284+ ck_assert_ptr_null (result );
285+
286+ // NB: stub only
287+ expr = NULL ;
288+ rv = oidc_util_apr_expr_parse (cmd , "#" , & expr , FALSE);
289+ ck_assert_ptr_nonnull (rv );
290+ ck_assert_ptr_null (expr );
291+ }
292+ END_TEST
293+
173294int main (void ) {
174295 TCase * core = tcase_create ("base64" );
175296 tcase_add_checked_fixture (core , oidc_test_setup , oidc_test_teardown );
@@ -180,6 +301,11 @@ int main(void) {
180301
181302 tcase_add_test (core , test_util_appinfo_set );
182303
304+ tcase_add_test (core , test_util_expr_substitute );
305+ tcase_add_test (core , test_util_expr_first_match );
306+ tcase_add_test (core , test_util_expr_parse );
307+ tcase_add_test (core , test_util_expr_exec );
308+
183309 Suite * s = suite_create ("util" );
184310 suite_add_tcase (s , core );
185311
0 commit comments