test_namespace.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. ASSERT (LSUP_nsmap_get_ns (nsm, "dctermsxx"), "http://purl.org/dc/terms/");
  18. ASSERT (LSUP_nsmap_get_ns (nsm, "none") == NULL, "Non-existent NS found!");
  19. // Lookup NS.
  20. EXPECT_STR_EQ (
  21. LSUP_nsmap_get_pfx (nsm, "http://purl.org/dc/elements/1.1/"), "dc");
  22. EXPECT_STR_EQ (
  23. LSUP_nsmap_get_pfx (nsm, "http://purl.org/dc/terms/"), "dcterms");
  24. // Normalize and denormalize URIs.
  25. char *fq_uri, *pfx_uri;
  26. fq_uri = "http://purl.org/dc/elements/1.1/title";
  27. EXPECT_PASS (LSUP_nsmap_denormalize_uri (nsm, fq_uri, &pfx_uri));
  28. EXPECT_STR_EQ (pfx_uri, "dc:title");
  29. fq_uri = NULL;
  30. EXPECT_PASS (LSUP_nsmap_normalize_uri (nsm, pfx_uri, &fq_uri));
  31. EXPECT_STR_EQ (fq_uri, "http://purl.org/dc/elements/1.1/title");
  32. EXPECT_PASS (LSUP_nsmap_remove (nsm, "dc"));
  33. ASSERT (
  34. LSUP_nsmap_remove (nsm, "none") == LSUP_NOACTION,
  35. "Wrong result for removal of non-existent prefix!");
  36. ASSERT (LSUP_nsmap_get_ns (nsm, "dc") == NULL, "Deleted NS found!");
  37. LSUP_nsmap_free (nsm);
  38. free (fq_uri);
  39. free (pfx_uri);
  40. return 0;
  41. }
  42. int namespace_tests()
  43. {
  44. RUN (test_namespace);
  45. return 0;
  46. }