|
@@ -3,6 +3,8 @@
|
|
|
|
|
|
#define TERM_CT 10
|
|
|
|
|
|
+typedef char nt_str[64];
|
|
|
+
|
|
|
static LSUP_Term **
|
|
|
init_terms (void)
|
|
|
{
|
|
@@ -12,8 +14,7 @@ init_terms (void)
|
|
|
terms[2] = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, NULL);
|
|
|
terms[3] = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, "en-US");
|
|
|
terms[4] = LSUP_term_new (
|
|
|
- LSUP_TERM_LITERAL, "hello",
|
|
|
- "http://www.w3.org/2001/XMLSchema#string", "es-ES");
|
|
|
+ LSUP_TERM_LITERAL, "hello", DEFAULT_DTYPE, "es-ES");
|
|
|
terms[5] = LSUP_term_new (
|
|
|
LSUP_TERM_LITERAL, "25",
|
|
|
"http://www.w3.org/2001/XMLSchema#integer", NULL);
|
|
@@ -27,6 +28,34 @@ init_terms (void)
|
|
|
return terms;
|
|
|
}
|
|
|
|
|
|
+// Starting NT term strings. They may have comments and junk whitespace.
|
|
|
+static nt_str start_nt[TERM_CT] = {
|
|
|
+ "<urn:local:s1>",
|
|
|
+ "<http://example.org/p1> ",
|
|
|
+ "\"hello\"^^http://www.w3.org/2001/XMLSchema#string",
|
|
|
+ "\"hello\" @en-US",
|
|
|
+ "\"hello\"@es-ES # Does \"Hello\" in Spanish mean \"hola\"?",
|
|
|
+ "\"25\" ^^<http://www.w3.org/2001/XMLSchema#integer> ",
|
|
|
+ "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\'literal\\'\\t.\"",
|
|
|
+ "_:bn1",
|
|
|
+ "This is nothing.",
|
|
|
+ "",
|
|
|
+};
|
|
|
+
|
|
|
+// End result NT term strings, as they should be produced by the NT codec.
|
|
|
+static nt_str end_nt[TERM_CT] = {
|
|
|
+ "<urn:local:s1>",
|
|
|
+ "<http://example.org/p1>",
|
|
|
+ "\"hello\"",
|
|
|
+ "\"hello\"@en-US",
|
|
|
+ "\"hello\"@es-ES",
|
|
|
+ "\"25\"^^<http://www.w3.org/2001/XMLSchema#integer>",
|
|
|
+ "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\'literal\\'\\t.\"",
|
|
|
+ "_:bn1",
|
|
|
+ "",
|
|
|
+ "",
|
|
|
+};
|
|
|
+
|
|
|
|
|
|
static void
|
|
|
free_terms (LSUP_Term **terms)
|
|
@@ -37,6 +66,7 @@ free_terms (LSUP_Term **terms)
|
|
|
free (terms);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
static int
|
|
|
test_encode_nt_term()
|
|
|
{
|
|
@@ -47,34 +77,15 @@ test_encode_nt_term()
|
|
|
LSUP_nsmap_add (nsm, "ext", "http://example.org");
|
|
|
|
|
|
char *out = NULL;
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[0], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "<urn:local:s1>");
|
|
|
|
|
|
+ // Test that passing a NS map has no effect.
|
|
|
EXPECT_PASS (nt_codec.term_encoder (terms[0], nsm, &out));
|
|
|
- EXPECT_STR_EQ (out, "<urn:local:s1>");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[1], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "<http://example.org/p1>");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[2], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "\"hello\"");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[3], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "\"hello\"@en-US");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[4], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "\"hello\"@es-ES");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[5], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "\"25\"^^http://www.w3.org/2001/XMLSchema#integer");
|
|
|
-
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[6], NULL, &out));
|
|
|
- EXPECT_STR_EQ (
|
|
|
- out,
|
|
|
- "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\'literal\\'\\t.\"");
|
|
|
+ EXPECT_STR_EQ (out, end_nt[0]);
|
|
|
|
|
|
- EXPECT_PASS (nt_codec.term_encoder (terms[7], NULL, &out));
|
|
|
- EXPECT_STR_EQ (out, "_:bn1");
|
|
|
+ for (int i = 0; i < TERM_CT - 2; i++) {
|
|
|
+ EXPECT_PASS (nt_codec.term_encoder (terms[i], NULL, &out));
|
|
|
+ EXPECT_STR_EQ (out, end_nt[i]);
|
|
|
+ }
|
|
|
|
|
|
EXPECT_INT_EQ (nt_codec.term_encoder (terms[8], NULL, &out), LSUP_VALUE_ERR);
|
|
|
ASSERT (out == NULL, "Encoding of undefined term should be NULL!");
|
|
@@ -134,13 +145,13 @@ static int test_encode_nt_graph()
|
|
|
"<urn:local:s1> <http://example.org/p1> _:bn1 .\n",
|
|
|
"_:bn1 <http://example.org/p1> \"hello\"@es-ES .\n",
|
|
|
"_:bn1 <http://example.org/p1> "
|
|
|
- "\"25\"^^http://www.w3.org/2001/XMLSchema#integer .\n",
|
|
|
+ "\"25\"^^<http://www.w3.org/2001/XMLSchema#integer> .\n",
|
|
|
"_:bn1 <http://example.org/p1> "
|
|
|
"\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\\'literal\\\'\\t.\""
|
|
|
" .\n",
|
|
|
};
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
- ASSERT (strstr (out, test_out[i]) != NULL, "String not found!");
|
|
|
+ ASSERT (strstr (out, test_out[i]) != NULL, test_out[i]);
|
|
|
|
|
|
free (out);
|
|
|
|
|
@@ -150,9 +161,22 @@ static int test_encode_nt_graph()
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int
|
|
|
+test_decode_nt_term()
|
|
|
+{
|
|
|
+ for (int i = 0; i < TERM_CT - 2; i++) {
|
|
|
+ LSUP_Term *term;
|
|
|
+ EXPECT_PASS (nt_codec.term_decoder (start_nt[i], NULL, &term));
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int codec_nt_tests()
|
|
|
{
|
|
|
RUN (test_encode_nt_term);
|
|
|
RUN (test_encode_nt_graph);
|
|
|
+ RUN (test_decode_nt_term);
|
|
|
return 0;
|
|
|
}
|