assets.h 2.0 KB

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