triples.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef _TEST_ASSETS_H
  2. #define _TEST_ASSETS_H
  3. #include "term.h"
  4. #define NUM_TRP 10
  5. LSUP_Triple *create_triples()
  6. {
  7. LSUP_Triple *trp;
  8. // Leave 1 spare NULL as a sentinel
  9. trp = calloc (NUM_TRP + 1, sizeof (LSUP_Triple));
  10. if (!trp) abort();
  11. trp[0].s = LSUP_uri_new ("urn:s:0");
  12. trp[0].p = LSUP_uri_new ("urn:p:0");
  13. trp[0].o = LSUP_uri_new ("urn:o:0");
  14. trp[1].s = LSUP_uri_new ("urn:s:1");
  15. trp[1].p = LSUP_uri_new ("urn:p:1");
  16. trp[1].o = LSUP_uri_new ("urn:o:1");
  17. trp[2].s = LSUP_uri_new ("urn:s:2");
  18. trp[2].p = LSUP_uri_new ("urn:p:2");
  19. trp[2].o = LSUP_uri_new ("urn:o:2");
  20. trp[3].s = LSUP_uri_new ("urn:s:0");
  21. trp[3].p = LSUP_uri_new ("urn:p:1");
  22. trp[3].o = LSUP_uri_new ("urn:o:2");
  23. trp[4].s = LSUP_uri_new ("urn:s:0");
  24. trp[4].p = LSUP_uri_new ("urn:p:2");
  25. trp[4].o = LSUP_term_new (LSUP_TERM_LITERAL, "String 1", NULL);
  26. trp[5].s = LSUP_uri_new ("urn:s:0");
  27. trp[5].p = LSUP_uri_new ("urn:p:5");
  28. trp[5].o = LSUP_term_new(LSUP_TERM_LITERAL, "String 1", "xsd:string");
  29. trp[6].s = LSUP_uri_new ("urn:s:1");
  30. trp[6].p = LSUP_uri_new ("urn:p:6");
  31. trp[6].o = LSUP_term_new(LSUP_TERM_LT_LITERAL, "String 1", "es-ES");
  32. // Unique triple from reused pointers. Do not double-free.
  33. trp[7].s = trp[0].s; // <urn:s:0>
  34. trp[7].p = trp[2].p; // <urn:p:2>
  35. trp[7].o = trp[5].o; // "String 1"^^xsd:string
  36. // Duplicate of trp[7]. Do not double-free.
  37. trp[8].s = trp[0].s;
  38. trp[8].p = trp[2].p;
  39. trp[8].o = trp[5].o;
  40. // Duplicate of trp[7] from different pointers with same value.
  41. // Do not double-free.
  42. trp[9].s = trp[5].s;
  43. trp[9].p = trp[4].p;
  44. trp[9].o = trp[5].o;
  45. return trp;
  46. }
  47. void free_triples (LSUP_Triple *trp)
  48. {
  49. // Last three triples are second pointers.
  50. for (int i=0; i < NUM_TRP - 3; i++) {
  51. LSUP_term_free (trp[i].s);
  52. LSUP_term_free (trp[i].p);
  53. LSUP_term_free (trp[i].o);
  54. }
  55. free (trp);
  56. }
  57. #endif