test_codec_ttl.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "test.h"
  2. #include "codec/codec_ttl.h"
  3. #define TERM_CT 10
  4. #define W3C_POS_TEST_CT 30
  5. #define W3C_NEG_TEST_CT 14
  6. #define W3C_TEST_BASE "http://www.w3.org/2001/sw/DataAccess/df1/tests/"
  7. /// Positive test suite from W3C.
  8. int
  9. test_w3c_pos()
  10. {
  11. char test_fname[36], out_fname[36];
  12. LSUP_Graph *gr;
  13. size_t ct;
  14. char *err;
  15. char ch;
  16. for (int i = 0; i <= W3C_POS_TEST_CT; i++) {
  17. #if 1
  18. // Tests 14÷16 with 10K triples is quite long. Skip them temporarily.
  19. // TODO use a switch based on env var.
  20. if (i > 12 && i <17) continue;
  21. #endif
  22. size_t nt_ct = 0;
  23. sprintf (test_fname, "test/assets/ttl/test-%02d.ttl", i);
  24. sprintf (out_fname, "test/assets/ttl/test-%02d.out", i);
  25. FILE *test_stream = fopen (test_fname, "r");
  26. FILE *out_stream = fopen (out_fname, "r");
  27. log_info ("Testing %s", test_fname);
  28. while ((ch=fgetc (out_stream)) != EOF) {
  29. if (ch == '\n') nt_ct++;
  30. }
  31. EXPECT_PASS (codec.decode_graph (test_stream, &gr, &ct, &err));
  32. EXPECT_INT_EQ (LSUP_graph_size (gr), nt_ct); // Just count NT lines.
  33. }
  34. return 0;
  35. }
  36. /// Negative test suite from W3C.
  37. int
  38. test_w3c_neg()
  39. {
  40. return 0;
  41. }
  42. int codec_ttl_tests()
  43. {
  44. LSUP_Term **terms = init_terms();
  45. init_triples (terms);
  46. codec = ttl_codec;
  47. //RUN (test_encode_ttl_graph);
  48. //RUN (test_decode_ttl_graph);
  49. //RUN (test_decode_ttl_bad_graph);
  50. RUN (test_w3c_pos);
  51. //RUN (test_w3c_neg);
  52. free_terms(terms);
  53. return 0;
  54. }