test_codec_nt.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "test.h"
  2. #include "codec_nt.h"
  3. static int
  4. test_encode_nt_term()
  5. {
  6. LSUP_Term *uri1 = LSUP_uri_new ("urn:local:s1");
  7. LSUP_Term *uri2 = LSUP_uri_new ("http://example.org/p1");
  8. LSUP_Term *lit1 = LSUP_term_new (LSUP_TERM_LITERAL, "hello", NULL, NULL);
  9. LSUP_Term *lit2 = LSUP_term_new (
  10. LSUP_TERM_LITERAL, "hello", NULL, "en-US");
  11. LSUP_Term *lit3 = LSUP_term_new (
  12. LSUP_TERM_LITERAL, "hello",
  13. "http://www.w3.org/2001/XMLSchema#string", "es-ES");
  14. LSUP_Term *lit4 = LSUP_term_new (
  15. LSUP_TERM_LITERAL, "25",
  16. "http://www.w3.org/2001/XMLSchema#integer", NULL);
  17. LSUP_Term *lit5 = LSUP_term_new (
  18. LSUP_TERM_LITERAL, "This \\is\\ a \"multi-line\"\n'literal'\t.",
  19. NULL, NULL);
  20. LSUP_Term *bnode1 = LSUP_term_new (LSUP_TERM_BNODE, "bn1", NULL, NULL);
  21. LSUP_Term *undef1 = LSUP_term_new (
  22. LSUP_TERM_UNDEFINED, "bogus", NULL, NULL);
  23. LSUP_Term *undef2 = TERM_DUMMY;
  24. LSUP_NSMap *nsm = LSUP_nsmap_new();
  25. LSUP_nsmap_add (nsm, "local", "urn:local:");
  26. LSUP_nsmap_add (nsm, "ext", "http://example.org");
  27. char *out;
  28. EXPECT_PASS (nt_codec.term_encoder (uri1, NULL, &out));
  29. EXPECT_STR_EQ (out, "<urn:local:s1>");
  30. free (out);
  31. EXPECT_PASS (nt_codec.term_encoder (uri1, nsm, &out));
  32. EXPECT_STR_EQ (out, "<urn:local:s1>");
  33. free (out);
  34. EXPECT_PASS (nt_codec.term_encoder (uri2, NULL, &out));
  35. EXPECT_STR_EQ (out, "<http://example.org/p1>");
  36. free (out);
  37. EXPECT_PASS (nt_codec.term_encoder (lit1, NULL, &out));
  38. EXPECT_STR_EQ (out, "\"hello\"");
  39. free (out);
  40. EXPECT_PASS (nt_codec.term_encoder (lit2, NULL, &out));
  41. EXPECT_STR_EQ (out, "\"hello\"@en-US");
  42. free (out);
  43. EXPECT_PASS (nt_codec.term_encoder (lit3, NULL, &out));
  44. EXPECT_STR_EQ (
  45. out, "\"hello\"@es-ES");
  46. free (out);
  47. EXPECT_PASS (nt_codec.term_encoder (lit4, NULL, &out));
  48. EXPECT_STR_EQ (
  49. out, "\"25\"^^http://www.w3.org/2001/XMLSchema#integer");
  50. free (out);
  51. EXPECT_PASS (nt_codec.term_encoder (lit5, NULL, &out));
  52. EXPECT_STR_EQ (
  53. out,
  54. "\"This \\\\is\\\\ a \\\"multi-line\\\"\\n\\'literal\\'\\t.\"");
  55. free (out);
  56. EXPECT_PASS (nt_codec.term_encoder (bnode1, NULL, &out));
  57. EXPECT_STR_EQ (out, "_:bn1");
  58. free (out);
  59. EXPECT_INT_EQ (nt_codec.term_encoder (undef1, NULL, &out), LSUP_VALUE_ERR);
  60. ASSERT (out == NULL, "Encoding of undefined term should be NULL!");
  61. free (out);
  62. EXPECT_INT_EQ (nt_codec.term_encoder (undef2, NULL, &out), LSUP_VALUE_ERR);
  63. ASSERT (out == NULL, "Encoding of undefined term should be NULL!");
  64. free (out);
  65. LSUP_term_free (uri1);
  66. LSUP_term_free (uri2);
  67. LSUP_term_free (lit1);
  68. LSUP_term_free (lit2);
  69. LSUP_term_free (lit3);
  70. LSUP_term_free (lit4);
  71. LSUP_term_free (lit5);
  72. LSUP_term_free (bnode1);
  73. LSUP_term_free (undef1);
  74. LSUP_term_free (undef2);
  75. return 0;
  76. }
  77. int codec_nt_tests()
  78. {
  79. RUN (test_encode_nt_term);
  80. return 0;
  81. }