#include "test.h" #include "codec_nt.h" static int test_encode_nt_term() { LSUP_Term *uri1 = LSUP_uri_new ("urn:local:s1"); LSUP_Term *uri2 = LSUP_uri_new ("http://example.org/p1"); LSUP_Term *lit1 = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, NULL); LSUP_Term *lit2 = LSUP_term_new ( LSUP_TERM_LITERAL, "hello", NULL, "en-US"); LSUP_Term *lit3 = LSUP_term_new ( LSUP_TERM_LITERAL, "hello", "http://www.w3.org/2001/XMLSchema#string", "es-ES"); LSUP_Term *lit4 = LSUP_term_new ( LSUP_TERM_LITERAL, "25", "http://www.w3.org/2001/XMLSchema#integer", NULL); LSUP_Term *lit5 = LSUP_term_new ( LSUP_TERM_LITERAL, "This \\is\\ a \"multi-line\"\n'literal'\t.", NULL, NULL); LSUP_Term *bnode1 = LSUP_term_new (LSUP_TERM_BNODE, "bn1", NULL, NULL); LSUP_Term *undef1 = LSUP_term_new ( LSUP_TERM_UNDEFINED, "bogus", NULL, NULL); LSUP_Term *undef2 = TERM_DUMMY; LSUP_NSMap *nsm = LSUP_nsmap_new(); LSUP_nsmap_add (nsm, "local", "urn:local:"); LSUP_nsmap_add (nsm, "ext", "http://example.org"); char *out; EXPECT_PASS (nt_codec.term_encoder (uri1, NULL, &out)); EXPECT_STR_EQ (out, ""); free (out); EXPECT_PASS (nt_codec.term_encoder (uri1, nsm, &out)); EXPECT_STR_EQ (out, ""); free (out); EXPECT_PASS (nt_codec.term_encoder (uri2, NULL, &out)); EXPECT_STR_EQ (out, ""); free (out); EXPECT_PASS (nt_codec.term_encoder (lit1, NULL, &out)); EXPECT_STR_EQ (out, "\"hello\""); free (out); EXPECT_PASS (nt_codec.term_encoder (lit2, NULL, &out)); EXPECT_STR_EQ (out, "\"hello\"@en-US"); free (out); EXPECT_PASS (nt_codec.term_encoder (lit3, NULL, &out)); EXPECT_STR_EQ ( out, "\"hello\"@es-ES"); free (out); EXPECT_PASS (nt_codec.term_encoder (lit4, NULL, &out)); EXPECT_STR_EQ ( out, "\"25\"^^http://www.w3.org/2001/XMLSchema#integer"); free (out); EXPECT_PASS (nt_codec.term_encoder (lit5, NULL, &out)); EXPECT_STR_EQ ( out, "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\'literal\\'\\t.\""); free (out); EXPECT_PASS (nt_codec.term_encoder (bnode1, NULL, &out)); EXPECT_STR_EQ (out, "_:bn1"); free (out); EXPECT_INT_EQ (nt_codec.term_encoder (undef1, NULL, &out), LSUP_VALUE_ERR); ASSERT (out == NULL, "Encoding of undefined term should be NULL!"); free (out); EXPECT_INT_EQ (nt_codec.term_encoder (undef2, NULL, &out), LSUP_VALUE_ERR); ASSERT (out == NULL, "Encoding of undefined term should be NULL!"); free (out); LSUP_term_free (uri1); LSUP_term_free (uri2); LSUP_term_free (lit1); LSUP_term_free (lit2); LSUP_term_free (lit3); LSUP_term_free (lit4); LSUP_term_free (lit5); LSUP_term_free (bnode1); LSUP_term_free (undef1); LSUP_term_free (undef2); return 0; } int codec_nt_tests() { RUN (test_encode_nt_term); return 0; }