void test_matching() { stringlist_type * s1 = stringlist_alloc_new(); stringlist_type * s2 = stringlist_alloc_new(); stringlist_append_copy(s1 , "AAA"); stringlist_append_copy(s1 , "ABC" ); stringlist_append_copy(s1 , "123"); stringlist_append_copy(s1 , "ABC:123"); stringlist_select_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 4 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); stringlist_select_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 4 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); stringlist_append_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 8 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 4 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 5 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 6 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 7 )); stringlist_select_matching_elements( s2 , s1 , "*B*"); test_assert_int_equal( 2 , stringlist_get_size( s2 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 1 )); stringlist_free( s2 ); stringlist_free( s1 ); }
int stringlist_select_matching_elements(stringlist_type * target , const stringlist_type * src , const char * pattern) { stringlist_clear( target ); return stringlist_append_matching_elements( target , src , pattern ); }