12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #include "test.h"
- #include "codec/codec_ttl.h"
- #define TERM_CT 10
- #define W3C_POS_TEST_CT 30
- #define W3C_NEG_TEST_CT 14
- #define W3C_TEST_BASE "http://www.w3.org/2001/sw/DataAccess/df1/tests/"
- /// Positive test suite from W3C.
- int
- test_w3c_pos()
- {
- char test_fname[36], out_fname[36];
- LSUP_Graph *gr;
- size_t ct;
- char *err;
- char ch;
- for (int i = 0; i <= W3C_POS_TEST_CT; i++) {
- #if 1
- // Tests 14÷16 with 10K triples is quite long. Skip them temporarily.
- // TODO use a switch based on env var.
- if (i > 12 && i <17) continue;
- #endif
- size_t nt_ct = 0;
- sprintf (test_fname, "test/assets/ttl/test-%02d.ttl", i);
- sprintf (out_fname, "test/assets/ttl/test-%02d.out", i);
- FILE *test_stream = fopen (test_fname, "r");
- FILE *out_stream = fopen (out_fname, "r");
- log_info ("Testing %s", test_fname);
- while ((ch=fgetc (out_stream)) != EOF) {
- if (ch == '\n') nt_ct++;
- }
- EXPECT_PASS (codec.decode_graph (test_stream, &gr, &ct, &err));
- EXPECT_INT_EQ (LSUP_graph_size (gr), nt_ct); // Just count NT lines.
- LSUP_graph_free (gr);
- fclose (test_stream);
- fclose (out_stream);
- free (err);
- }
- return 0;
- }
- /// Negative test suite from W3C.
- int
- test_w3c_neg()
- {
- char test_fname[36];
- LSUP_Graph *gr;
- size_t ct;
- char *err;
- for (int i = 0; i <= W3C_NEG_TEST_CT; i++) {
- sprintf (test_fname, "test/assets/ttl/bad-%02d.ttl", i);
- FILE *test_stream = fopen (test_fname, "r");
- log_info ("Testing %s", test_fname);
- LSUP_rc rc = codec.decode_graph (test_stream, &gr, &ct, &err);
- log_info ("rc: %d", rc);
- ASSERT (rc == LSUP_PARSE_ERR, "Bad test did not raise a parse error!");
- fclose (test_stream);
- free (err);
- }
- return 0;
- }
- int codec_ttl_tests()
- {
- LSUP_Term **terms = init_terms();
- init_triples (terms);
- codec = ttl_codec;
- //RUN (test_encode_ttl_graph);
- RUN (test_decode_nt_graph);
- RUN (test_decode_nt_bad_graph);
- RUN (test_w3c_pos);
- RUN (test_w3c_neg);
- free_terms(terms);
- return 0;
- }
|