test_dres.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "test.h"
  2. #include "namespace.h"
  3. static int
  4. test_dres_create()
  5. {
  6. char
  7. *ttl1 = "<urn:s:1> <urn:p:2> <urn:o:2> , <urn:o:1> ; "
  8. "<urn:p:1> <urn:o:1> . "
  9. "<urn:s:2> <urn:p:1> <urn:o:1> . ",
  10. *ttl2 = "<urn:s:20> <urn:p:10> <urn:o:10> . "
  11. "<urn:s:10> <urn:p:10> <urn:o:10> ; "
  12. "<urn:p:20> <urn:o:20> , <urn:o:10> . ";
  13. LSUP_Graph *data[3] = {NULL};
  14. FILE *input;
  15. char *err;
  16. size_t ct;
  17. input = fmemopen (ttl1, strlen (ttl1), "r");
  18. ttl_codec.decode_graph(input, data, &ct, &err);
  19. LSUP_graph_set_uri (data[0], LSUP_iriref_new ("#usr1", NULL));
  20. fclose(input);
  21. input = fmemopen (ttl2, strlen (ttl2), "r");
  22. ttl_codec.decode_graph(input, data + 1, &ct, &err);
  23. LSUP_graph_set_uri (data[1], LSUP_iriref_new ("#usr2", NULL));
  24. fclose(input);
  25. free(err);
  26. // Create resource.
  27. LSR_Dres *rsrc;
  28. EXPECT_PASS (LSR_dres_new_multi (data, &rsrc));
  29. // Free input handles before using the resource to ensure that these
  30. // pointers are not being referenced by the resource.
  31. LSUP_graph_free (data[0]);
  32. LSUP_graph_free (data[1]);
  33. LSUP_Graph *md_gr = LSR_dres_metadata (rsrc);
  34. ASSERT (md_gr != NULL, "Error retrieving metadata graph!");
  35. ASSERT (
  36. LSUP_term_equals (
  37. LSUP_graph_uri (md_gr), LSUP_graph_uri (rsrc->admin_data)),
  38. "Metadata function URI is incorrect!");
  39. ASSERT (sizeof(md_gr) > 0, "No metadata found for resource!");
  40. LSUP_Term
  41. *rsrc_urn = LSR_dres_urn (rsrc),
  42. *main_urn = LSR_id_to_urn (rsrc->id, "__main"),
  43. *admin_urn = LSR_id_to_urn (rsrc->id, "__admin"),
  44. *usr1_urn = LSR_id_to_urn (rsrc->id, "usr1"),
  45. *usr2_urn = LSR_id_to_urn (rsrc->id, "usr2");
  46. // TODO tests:
  47. // * Existence of admin graph
  48. // * Existence of main graph
  49. // * Existence of user graphs
  50. // * Linkage of main, admin, and user graphs
  51. // * Size of user graphs
  52. // * Spot-test triples in user graphs
  53. ASSERT (
  54. LSUP_term_equals (main_urn, LSUP_graph_uri (rsrc->main_data)),
  55. "Main graph URI is incorrect!");
  56. ASSERT (
  57. LSUP_term_equals (admin_urn, LSUP_graph_uri (md_gr)),
  58. "Admin graph URI is incorrect!");
  59. LSUP_Term *t1 = LSUP_iriref_new ("foaf:topic", LSUP_default_nsm);
  60. LSUP_Triple *test_spo = LSUP_triple_new (main_urn, t1, rsrc_urn);
  61. /*
  62. ASSERT (
  63. LSUP_graph_contains (rsrc->main_data, test_spo),
  64. "Main data missing topic triple!");
  65. */
  66. // TODO
  67. LSUP_term_free (usr2_urn);
  68. LSUP_term_free (usr1_urn);
  69. LSUP_term_free (admin_urn);
  70. LSUP_term_free (main_urn);
  71. LSUP_term_free (rsrc_urn);
  72. LSUP_graph_free (md_gr);
  73. // Store for next test before freeing.
  74. EXPECT_PASS (LSR_dres_store (rsrc));
  75. LSR_dres_free (rsrc);
  76. return 0;
  77. }
  78. static int
  79. test_dres_get ()
  80. {
  81. return 0;
  82. }
  83. int dres_tests()
  84. {
  85. RUN (test_dres_create);
  86. RUN (test_dres_get);
  87. return 0;
  88. }