/** * librdf_new_node_from_typed_counted_literal: * @world: redland world object * @value: literal string value * @value_len: literal string value length * @xml_language: literal XML language (or NULL, empty string) * @xml_language_len: literal XML language length (not used if @xml_language is NULL) * @datatype_uri: URI of typed literal datatype or NULL * * Constructor - create a new typed literal #librdf_node object. * * Only one of @xml_language or @datatype_uri may be given. If both * are given, NULL is returned. If @xml_language is the empty string, * it is the equivalent to NULL. * * Return value: new #librdf_node object or NULL on failure **/ librdf_node* librdf_new_node_from_typed_counted_literal(librdf_world *world, const unsigned char *value, size_t value_len, const char *xml_language, size_t xml_language_len, librdf_uri *datatype_uri) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, librdf_world, NULL); librdf_world_open(world); return raptor_new_term_from_counted_literal(world->raptor_world_ptr, value, value_len, datatype_uri, (const unsigned char*)xml_language, (unsigned char)xml_language_len); }
/** * raptor_new_term_from_literal: * @world: raptor world * @literal: UTF-8 encoded literal string (or NULL for empty literal) * @datatype: literal datatype URI (or NULL) * @language: literal language (or NULL) * * Constructor - create a new literal statement term * * Takes copies of the passed in @literal, @datatype, @language * * Only one of @language or @datatype may be given. If both are * given, NULL is returned. If @language is the empty string, it is * the equivalent to NULL. * * Return value: new term or NULL on failure */ raptor_term* raptor_new_term_from_literal(raptor_world* world, const unsigned char* literal, raptor_uri* datatype, const unsigned char* language) { size_t literal_len = 0; unsigned char language_len = 0; RAPTOR_CHECK_CONSTRUCTOR_WORLD(world); raptor_world_open(world); if(literal) literal_len = strlen((const char*)literal); if(language) language_len = strlen((const char*)language); return raptor_new_term_from_counted_literal(world, literal, literal_len, datatype, language, language_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; }