|
@@ -56,6 +56,52 @@ static nt_str end_nt[TERM_CT] = {
|
|
"",
|
|
"",
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+// Start NT document. It may have comments and junk whitespace.
|
|
|
|
+static char *start_doc = (
|
|
|
|
+ "<urn:local:s1> <http://example.org/p1> \"hello\" . # Comment here.\n"
|
|
|
|
+ "<urn:local:s1> <http://example.org/p1>\"hello\"@es-ES .\n"
|
|
|
|
+ "# Some comments\n# To make it a bit \n #less boring.\n"
|
|
|
|
+ "<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"
|
|
|
|
+ "_:bn1 <http://example.org/p1> "
|
|
|
|
+ "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\\'literal\\\'\\t.\""
|
|
|
|
+ " .\n"
|
|
|
|
+ "# FREE WHITESPACE!\n\n\n\n\n\n\n \n\n\n\n"
|
|
|
|
+);
|
|
|
|
+
|
|
|
|
+// End result NT document as it should be produced by the NT codec.
|
|
|
|
+// Lines should not be checked in strict order.
|
|
|
|
+static char *end_doc[6] = {
|
|
|
|
+ "<urn:local:s1> <http://example.org/p1> \"hello\" .\n",
|
|
|
|
+ "<urn:local:s1> <http://example.org/p1> \"hello\"@es-ES .\n",
|
|
|
|
+ "<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",
|
|
|
|
+ "_:bn1 <http://example.org/p1> "
|
|
|
|
+ "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\\'literal\\\'\\t.\" .\n",
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+static LSUP_Triple trp[8];
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+init_triples(LSUP_Term **terms)
|
|
|
|
+{
|
|
|
|
+ memset (trp, 0, sizeof (LSUP_Triple) * 8); // Last NULL is a sentinel
|
|
|
|
+
|
|
|
|
+ LSUP_triple_init (trp + 0, terms[0], terms[1], terms[2]);
|
|
|
|
+ LSUP_triple_init (trp + 1, terms[0], terms[1], terms[3]);
|
|
|
|
+ LSUP_triple_init (trp + 2, terms[0], terms[1], terms[4]);
|
|
|
|
+ LSUP_triple_init (trp + 3, terms[0], terms[1], terms[7]);
|
|
|
|
+ LSUP_triple_init (trp + 4, terms[7], terms[1], terms[4]);
|
|
|
|
+ LSUP_triple_init (trp + 5, terms[7], terms[1], terms[5]);
|
|
|
|
+ LSUP_triple_init (trp + 6, terms[7], terms[1], terms[6]);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
static void
|
|
static void
|
|
free_terms (LSUP_Term **terms)
|
|
free_terms (LSUP_Term **terms)
|
|
@@ -103,22 +149,9 @@ test_encode_nt_term()
|
|
|
|
|
|
static int test_encode_nt_graph()
|
|
static int test_encode_nt_graph()
|
|
{
|
|
{
|
|
- LSUP_Term **terms = init_terms();
|
|
|
|
-
|
|
|
|
LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MEM);
|
|
LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MEM);
|
|
if (!gr) return LSUP_MEM_ERR;
|
|
if (!gr) return LSUP_MEM_ERR;
|
|
|
|
|
|
- LSUP_Triple trp[8];
|
|
|
|
- memset (trp, 0, sizeof (LSUP_Triple) * 8); // Last NULL is a sentinel
|
|
|
|
-
|
|
|
|
- LSUP_triple_init (trp + 0, terms[0], terms[1], terms[2]);
|
|
|
|
- LSUP_triple_init (trp + 1, terms[0], terms[1], terms[3]);
|
|
|
|
- LSUP_triple_init (trp + 2, terms[0], terms[1], terms[4]);
|
|
|
|
- LSUP_triple_init (trp + 3, terms[0], terms[1], terms[7]);
|
|
|
|
- LSUP_triple_init (trp + 4, terms[7], terms[1], terms[4]);
|
|
|
|
- LSUP_triple_init (trp + 5, terms[7], terms[1], terms[5]);
|
|
|
|
- LSUP_triple_init (trp + 6, terms[7], terms[1], terms[6]);
|
|
|
|
-
|
|
|
|
size_t ins;
|
|
size_t ins;
|
|
LSUP_graph_add_trp (gr, trp, &ins);
|
|
LSUP_graph_add_trp (gr, trp, &ins);
|
|
|
|
|
|
@@ -138,25 +171,11 @@ static int test_encode_nt_graph()
|
|
LSUP_graph_free (gr);
|
|
LSUP_graph_free (gr);
|
|
//printf("Serialized graph: %s\n", out);
|
|
//printf("Serialized graph: %s\n", out);
|
|
|
|
|
|
- // Triples must not be checked in strict order.
|
|
|
|
- char *test_out[6] = {
|
|
|
|
- "<urn:local:s1> <http://example.org/p1> \"hello\" .\n",
|
|
|
|
- "<urn:local:s1> <http://example.org/p1> \"hello\"@es-ES .\n",
|
|
|
|
- "<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",
|
|
|
|
- "_:bn1 <http://example.org/p1> "
|
|
|
|
- "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\\'literal\\\'\\t.\""
|
|
|
|
- " .\n",
|
|
|
|
- };
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
for (int i = 0; i < 6; i++)
|
|
- ASSERT (strstr (out, test_out[i]) != NULL, test_out[i]);
|
|
|
|
|
|
+ ASSERT (strstr (out, end_doc[i]) != NULL, end_doc[i]);
|
|
|
|
|
|
free (out);
|
|
free (out);
|
|
|
|
|
|
- free_terms(terms);
|
|
|
|
-
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -173,10 +192,40 @@ test_decode_nt_term()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+static int
|
|
|
|
+test_decode_nt_graph()
|
|
|
|
+{
|
|
|
|
+ FILE *input = fmemopen ((void *)start_doc, strlen (start_doc), "r");
|
|
|
|
+
|
|
|
|
+ LSUP_Graph *gr;
|
|
|
|
+ size_t ct;
|
|
|
|
+ EXPECT_PASS (nt_codec.gr_decoder (input, &gr, &ct));
|
|
|
|
+
|
|
|
|
+ fclose (input);
|
|
|
|
+
|
|
|
|
+ EXPECT_INT_EQ (ct, 6);
|
|
|
|
+ EXPECT_INT_EQ (LSUP_graph_size (gr), 6);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 7; i++)
|
|
|
|
+ EXPECT_INT_EQ (LSUP_graph_contains (gr, trp + i), 1);
|
|
|
|
+
|
|
|
|
+ LSUP_graph_free (gr);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
int codec_nt_tests()
|
|
int codec_nt_tests()
|
|
{
|
|
{
|
|
|
|
+ LSUP_Term **terms = init_terms();
|
|
|
|
+ init_triples (terms);
|
|
|
|
+
|
|
RUN (test_encode_nt_term);
|
|
RUN (test_encode_nt_term);
|
|
RUN (test_encode_nt_graph);
|
|
RUN (test_encode_nt_graph);
|
|
RUN (test_decode_nt_term);
|
|
RUN (test_decode_nt_term);
|
|
|
|
+ RUN (test_decode_nt_graph);
|
|
|
|
+
|
|
|
|
+ free_terms(terms);
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|