/** * librdf_new_node_from_counted_uri_string: * @world: redland world object * @uri_string: string representing a URI * @len: length of string * * Constructor - create a new #librdf_node object from a counted URI string. * * Return value: a new #librdf_node object or NULL on failure **/ librdf_node* librdf_new_node_from_counted_uri_string(librdf_world *world, const unsigned char *uri_string, size_t len) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, librdf_world, NULL); librdf_world_open(world); return raptor_new_term_from_counted_uri_string(world->raptor_world_ptr, uri_string, len); }
int main(int argc, char *argv[]) { raptor_world *world; const char *program = raptor_basename(argv[0]); int rc = 0; raptor_term* term1 = NULL; /* URI string 1 */ raptor_term* term2 = NULL; /* literal string1 */ raptor_term* term3 = NULL; /* blank node 1 */ raptor_term* term4 = NULL; /* URI string 2 */ raptor_term* term5 = NULL; /* URI string 1 again */ raptor_uri* uri1; unsigned char* uri_str; size_t uri_len; world = raptor_new_world(); if(!world || raptor_world_open(world)) exit(1); /* check a term for NULL URI fails */ term1 = raptor_new_term_from_uri(world, NULL); if(term1) { fprintf(stderr, "%s: raptor_new_uri(NULL) returned object rather than failing\n", program); rc = 1; goto tidy; } /* check a term for non-NULL URI succeeds */ uri1 = raptor_new_uri(world, uri_string1); if(!uri1) { fprintf(stderr, "%s: raptor_new_uri(%s) failed\n", program, uri_string1); rc = 1; goto tidy; } term1 = raptor_new_term_from_uri(world, uri1); if(!term1) { fprintf(stderr, "%s: raptor_new_term_from_uri_string(URI %s) failed\n", program, uri_string1); rc = 1; goto tidy; } raptor_free_uri(uri1); uri1 = NULL; if(term1->type != uri_string1_type) { fprintf(stderr, "%s: raptor term 1 is of type %d expected %d\n", program, term1->type, uri_string1_type); rc = 1; goto tidy; } /* returns a pointer to shared string */ uri_str = raptor_uri_as_counted_string(term1->value.uri, &uri_len); if(!uri_str) { fprintf(stderr, "%s: raptor_uri_as_counted_string term 1 failed\n", program); rc = 1; goto tidy; } if(uri_len != uri_string1_len) { fprintf(stderr, "%s: raptor term 1 URI is of length %d expected %d\n", program, (int)uri_len, (int)uri_string1_len); rc = 1; goto tidy; } /* check an empty literal is created from a NULL literal pointer succeeds */ term2 = raptor_new_term_from_counted_literal(world, NULL, 0, NULL, NULL, 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with all NULLs failed\n", program); rc = 1; goto tidy; } raptor_free_term(term2); /* check an empty literal from an empty language literal pointer succeeds */ term2 = raptor_new_term_from_counted_literal(world, NULL, 0, NULL, (const unsigned char*)"", 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with empty language failed\n", program); rc = 1; goto tidy; } raptor_free_term(term2); /* check a literal with language and datatype fails */ uri1 = raptor_new_uri(world, uri_string1); if(!uri1) { fprintf(stderr, "%s: raptor_new_uri(%s) failed\n", program, uri_string1); rc = 1; goto tidy; } term2 = raptor_new_term_from_counted_literal(world, literal_string1, literal_string1_len, uri1, language1, 0); raptor_free_uri(uri1); uri1 = NULL; if(term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal() with language and datatype returned object rather than failing\n", program); rc = 1; goto tidy; } /* check a literal with no language and no datatype succeeds */ term2 = raptor_new_term_from_counted_literal(world, literal_string1, literal_string1_len, NULL, NULL, 0); if(!term2) { fprintf(stderr, "%s: raptor_new_term_from_counted_literal(%s) failed\n", program, literal_string1); rc = 1; goto tidy; } if(term2->type != literal_string1_type) { fprintf(stderr, "%s: raptor term 2 is of type %d expected %d\n", program, term2->type, literal_string1_type); rc = 1; goto tidy; } /* check a blank node term with NULL id generates a new identifier */ term3 = raptor_new_term_from_counted_blank(world, NULL, 0); if(!term3) { fprintf(stderr, "%s: raptor_new_term_from_counted_blank(NULL) failed\n", program); rc = 1; goto tidy; } if(term3->type != bnodeid1_type) { fprintf(stderr, "%s: raptor term 3 is of type %d expected %d\n", program, term3->type, bnodeid1_type); rc = 1; goto tidy; } raptor_free_term(term3); /* check a blank node term with an identifier succeeds */ term3 = raptor_new_term_from_counted_blank(world, bnodeid1, bnodeid1_len); if(!term3) { fprintf(stderr, "%s: raptor_new_term_from_counted_blank(%s) failed\n", program, bnodeid1); rc = 1; goto tidy; } if(term3->type != bnodeid1_type) { fprintf(stderr, "%s: raptor term 3 is of type %d expected %d\n", program, term3->type, bnodeid1_type); rc = 1; goto tidy; } /* check a different URI term succeeds */ term4 = raptor_new_term_from_counted_uri_string(world, uri_string2, uri_string2_len); if(!term4) { fprintf(stderr, "%s: raptor_new_term_from_counted_uri_string(URI %s) failed\n", program, uri_string2); rc = 1; goto tidy; } if(term4->type != uri_string2_type) { fprintf(stderr, "%s: raptor term 4 is of type %d expected %d\n", program, term4->type, uri_string2_type); rc = 1; goto tidy; } /* returns a pointer to shared string */ uri_str = raptor_uri_as_counted_string(term4->value.uri, &uri_len); if(!uri_str) { fprintf(stderr, "%s: raptor_uri_as_counted_string term 4 failed\n", program); rc = 1; goto tidy; } if(uri_len != uri_string2_len) { fprintf(stderr, "%s: raptor term 4 URI is of length %d expected %d\n", program, (int)uri_len, (int)uri_string2_len); rc = 1; goto tidy; } /* check the same URI term as term1 succeeds */ term5 = raptor_new_term_from_uri_string(world, uri_string1); if(!term5) { fprintf(stderr, "%s: raptor_new_term_from_uri_string(URI %s) failed\n", program, uri_string1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term2)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, literal %s) returned equal, expected not-equal\n", program, uri_string1, literal_string1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term3)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, bnode %s) returned equal, expected not-equal\n", program, uri_string1, bnodeid1); rc = 1; goto tidy; } if(raptor_term_equals(term1, term4)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, URI %s) returned equal, expected not-equal\n", program, uri_string1, uri_string2); rc = 1; goto tidy; } if(!raptor_term_equals(term1, term5)) { fprintf(stderr, "%s: raptor_term_equals (URI %s, URI %s) returned not-equal, expected equal\n", program, uri_string1, uri_string1); rc = 1; goto tidy; } if(term1->value.uri != term5->value.uri) { fprintf(stderr, "%s: term1 and term5 URI objects returned not-equal pointers, expected equal\n", program); /* This is not necessarily a failure if the raptor_uri module has had * the URI interning disabled with * raptor_world_set_flag(world, RAPTOR_WORLD_FLAG_URI_INTERNING, 0) * however this test suite does not do that, so it is a failure here. */ rc = 1; goto tidy; } tidy: if(term1) raptor_free_term(term1); if(term2) raptor_free_term(term2); if(term3) raptor_free_term(term3); if(term4) raptor_free_term(term4); if(term5) raptor_free_term(term5); raptor_free_world(world); return rc; }