assets.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. CRITICAL(trp = malloc(NUM_TRP * sizeof(LSUP_Triple)));
  9. // These constitute overall 10 individual triples, 8 unique.
  10. LSUP_uri_new("urn:s:0", trp[0].s);
  11. LSUP_uri_new("urn:p:0", trp[0].p);
  12. LSUP_uri_new("urn:o:0", trp[0].o);
  13. LSUP_uri_new("urn:s:1", trp[1].s);
  14. LSUP_uri_new("urn:p:1", trp[1].p);
  15. LSUP_uri_new("urn:o:1", trp[1].o);
  16. LSUP_uri_new("urn:s:2", trp[2].s);
  17. LSUP_uri_new("urn:p:2", trp[2].p);
  18. LSUP_uri_new("urn:o:2", trp[2].o);
  19. LSUP_uri_new("urn:s:0", trp[3].s);
  20. LSUP_uri_new("urn:p:1", trp[3].p);
  21. LSUP_uri_new("urn:o:2", trp[3].o);
  22. LSUP_uri_new("urn:s:0", trp[4].s);
  23. LSUP_uri_new("urn:p:2", trp[4].p);
  24. LSUP_term_new(LSUP_TERM_LITERAL, "String 1", NULL, NULL, trp[4].o);
  25. LSUP_uri_new("urn:s:0", trp[5].s);
  26. LSUP_uri_new("urn:p:5", trp[5].p);
  27. LSUP_term_new(
  28. LSUP_TERM_LITERAL, "String 1", "xsd:string", NULL, trp[5].o);
  29. LSUP_uri_new("urn:s:1", trp[6].s);
  30. LSUP_uri_new("urn:p:6", trp[6].p);
  31. LSUP_term_new(
  32. LSUP_TERM_LITERAL, "String 1", "xsd:string", "es-ES", trp[6].o);
  33. // Let's reuse 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