test_desc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "test.h"
  2. #include "namespace.h"
  3. static int
  4. test_desc_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_Desc *rsrc;
  28. EXPECT_PASS (LSR_desc_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_desc_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_desc_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. // TODO
  60. LSUP_term_free (usr2_urn);
  61. LSUP_term_free (usr1_urn);
  62. LSUP_term_free (admin_urn);
  63. LSUP_term_free (main_urn);
  64. LSUP_term_free (rsrc_urn);
  65. LSUP_graph_free (md_gr);
  66. // Store for next test before freeing.
  67. EXPECT_PASS (LSR_desc_store (rsrc));
  68. LSR_desc_free (rsrc);
  69. return 0;
  70. }
  71. static int
  72. test_desc_get ()
  73. {
  74. return 0;
  75. }
  76. int desc_tests()
  77. {
  78. RUN (test_desc_create);
  79. RUN (test_desc_get);
  80. return 0;
  81. }