static int rasqal_join_rowsource_finish(rasqal_rowsource* rowsource, void *user_data) { rasqal_join_rowsource_context* con; con = (rasqal_join_rowsource_context*)user_data; if(con->left_row) rasqal_free_row(con->left_row); if(con->left) rasqal_free_rowsource(con->left); if(con->right) rasqal_free_rowsource(con->right); if(con->right_map) RASQAL_FREE(int, con->right_map); if(con->expr) rasqal_free_expression(con->expr); if(con->rc_map) rasqal_free_row_compatible(con->rc_map); RASQAL_FREE(rasqal_join_rowsource_context, con); return 0; }
int main(int argc, char *argv[]) { const char *program = rasqal_basename(argv[0]); rasqal_rowsource *rowsource = NULL; rasqal_rowsource *left_rs = NULL; rasqal_rowsource *right_rs = NULL; rasqal_world* world = NULL; rasqal_query* query = NULL; raptor_sequence* seq = NULL; int failures = 0; int vars_count; rasqal_variables_table* vt; raptor_sequence* vars_seq = NULL; rasqal_row_compatible* rc_map = NULL; int i; world = rasqal_new_world(); rasqal_world_open(world); query = rasqal_new_query(world, "sparql", NULL); vt = query->vars_table; /* 3 variables and 4 rows */ vars_count = 3; seq = rasqal_new_row_sequence(world, vt, compatible_data_abc_rows, vars_count, &vars_seq); if(!seq) { fprintf(stderr, "%s: failed to create left sequence of %d vars\n", program, vars_count); failures++; goto tidy; } left_rs = rasqal_new_rowsequence_rowsource(world, query, vt, seq, vars_seq); if(!left_rs) { fprintf(stderr, "%s: failed to create left rowsource\n", program); failures++; goto tidy; } /* vars_seq and seq are now owned by left_rs */ vars_seq = seq = NULL; /* 3 variables and 4 rows */ vars_count = 3; seq = rasqal_new_row_sequence(world, vt, compatible_data_abcd_rows, vars_count, &vars_seq); if(!seq) { fprintf(stderr, "%s: failed to create right sequence of %d rows\n", program, vars_count); failures++; goto tidy; } right_rs = rasqal_new_rowsequence_rowsource(world, query, vt, seq, vars_seq); if(!right_rs) { fprintf(stderr, "%s: failed to create right rowsource\n", program); failures++; goto tidy; } /* vars_seq and seq are now owned by right_rs */ vars_seq = seq = NULL; rc_map = rasqal_new_row_compatible(vt, left_rs, right_rs); if(!rc_map) { fprintf(stderr, "%s: failed to create row compatible\n", program); failures++; goto tidy; } rasqal_print_row_compatible(stderr, rc_map); #ifdef RASQAL_DEBUG fputs("\n", stderr); #endif for(i = 0; i < EXPECTED_ROWS_COUNT; i++) { rasqal_row *left_row = rasqal_rowsource_read_row(left_rs); rasqal_row *right_row = rasqal_rowsource_read_row(right_rs); int expected = expected_compatible_results[i]; int compatible; if(!left_row) { fprintf(stderr, "%s: FAILED left rowsource ended early at row #%d\n", program, i); failures++; goto tidy; } if(!right_row) { fprintf(stderr, "%s: FAILED right rowsource ended early at row #%d\n", program, i); failures++; goto tidy; } compatible = rasqal_row_compatible_check(rc_map, left_row, right_row); RASQAL_DEBUG4("%s: compatible check for row #%d returned %d\n", program, i, compatible); if(compatible != expected) { fprintf(stderr, "%s: FAILED compatible check for row #%d returned %d expected %d\n", program, i, compatible, expected); failures++; } #ifdef RASQAL_DEBUG fputs("\n", stderr); #endif if(left_row) rasqal_free_row(left_row); if(right_row) rasqal_free_row(right_row); } tidy: if(rc_map) rasqal_free_row_compatible(rc_map); if(seq) raptor_free_sequence(seq); if(left_rs) rasqal_free_rowsource(left_rs); if(right_rs) rasqal_free_rowsource(right_rs); if(rowsource) rasqal_free_rowsource(rowsource); if(query) rasqal_free_query(query); if(world) rasqal_free_world(world); return failures; }