test_namespace.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "test.h"
  2. #include "namespace.h"
  3. static int
  4. test_namespace()
  5. {
  6. LSUP_NSMap *nsm = LSUP_nsmap_new();
  7. ASSERT (nsm != NULL, "Error creating namespace map!");
  8. EXPECT_PASS (
  9. LSUP_nsmap_add (nsm, "dc", "http://purl.org/dc/elements/1.1/"));
  10. EXPECT_PASS (LSUP_nsmap_add (nsm, "dcterms", "http://purl.org/dc/terms/"));
  11. // Look up prefix.
  12. EXPECT_STR_EQ (
  13. LSUP_nsmap_get_ns (nsm, "dc"), "http://purl.org/dc/elements/1.1/");
  14. EXPECT_STR_EQ (
  15. LSUP_nsmap_get_ns (nsm, "dcterms"), "http://purl.org/dc/terms/");
  16. // Prefixes longer than 7 chars are truncated.
  17. EXPECT_STR_EQ (
  18. LSUP_nsmap_get_ns (nsm, "dctermsxx"), "http://purl.org/dc/terms/");
  19. ASSERT (LSUP_nsmap_get_ns (nsm, "none") == NULL, "Non-existent NS found!");
  20. // Lookup NS.
  21. EXPECT_STR_EQ (
  22. LSUP_nsmap_get_pfx (nsm, "http://purl.org/dc/elements/1.1/"), "dc");
  23. EXPECT_STR_EQ (
  24. LSUP_nsmap_get_pfx (nsm, "http://purl.org/dc/terms/"), "dcterms");
  25. // Normalize and denormalize URIs.
  26. char *fq_uri, *pfx_uri;
  27. fq_uri = "http://purl.org/dc/elements/1.1/title";
  28. EXPECT_PASS (LSUP_nsmap_denormalize_uri (nsm, fq_uri, &pfx_uri));
  29. EXPECT_STR_EQ (pfx_uri, "dc:title");
  30. fq_uri = NULL;
  31. EXPECT_PASS (LSUP_nsmap_normalize_uri (nsm, pfx_uri, &fq_uri));
  32. EXPECT_STR_EQ (fq_uri, "http://purl.org/dc/elements/1.1/title");
  33. free (fq_uri);
  34. ASSERT (
  35. LSUP_nsmap_normalize_uri (nsm, "dctermsxxtitle", &fq_uri)
  36. == LSUP_NORESULT, "Wrong RC for normalizing long ns!");
  37. EXPECT_STR_EQ (fq_uri, "dctermsxxtitle");
  38. free (fq_uri);
  39. ASSERT (
  40. LSUP_nsmap_normalize_uri (nsm, "bogus:ns:123", &fq_uri)
  41. == LSUP_NORESULT, "Wrong RC for normalizing non-existent ns!");
  42. EXPECT_STR_EQ (fq_uri, "bogus:ns:123");
  43. free (fq_uri);
  44. ASSERT (
  45. LSUP_nsmap_normalize_uri (nsm, "bogus", &fq_uri)
  46. == LSUP_NORESULT, "Wrong RC for normalizing non-prefixed URI!");
  47. EXPECT_STR_EQ (fq_uri, "bogus");
  48. free (fq_uri);
  49. EXPECT_PASS (LSUP_nsmap_remove (nsm, "dc"));
  50. ASSERT (
  51. LSUP_nsmap_remove (nsm, "none") == LSUP_NOACTION,
  52. "Wrong result for removal of non-existent prefix!");
  53. ASSERT (LSUP_nsmap_get_ns (nsm, "dc") == NULL, "Deleted NS found!");
  54. LSUP_nsmap_free (nsm);
  55. free (pfx_uri);
  56. return 0;
  57. }
  58. int namespace_tests()
  59. {
  60. RUN (test_namespace);
  61. return 0;
  62. }