test_namespace.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. EXPECT_STR_EQ (
  12. LSUP_nsmap_get (nsm, "dc"), "http://purl.org/dc/elements/1.1/");
  13. EXPECT_STR_EQ (
  14. LSUP_nsmap_get (nsm, "dcterms"), "http://purl.org/dc/terms/");
  15. // Prefixes longer than 7 chars are truncated.
  16. ASSERT (
  17. LSUP_nsmap_get (nsm, "dctermsxxx") == NULL,
  18. "Non-existent NS found!");
  19. ASSERT (LSUP_nsmap_get (nsm, "none") == NULL, "Non-existent NS found!");
  20. char *fq_uri, *pfx_uri;
  21. fq_uri = "http://purl.org/dc/elements/1.1/title";
  22. EXPECT_PASS (LSUP_nsmap_normalize_uri (nsm, fq_uri, &pfx_uri));
  23. EXPECT_STR_EQ (pfx_uri, "dc:title");
  24. fq_uri = NULL;
  25. EXPECT_PASS (LSUP_nsmap_denormalize_uri (nsm, pfx_uri, &fq_uri));
  26. EXPECT_STR_EQ (fq_uri, "http://purl.org/dc/elements/1.1/title");
  27. EXPECT_PASS (LSUP_nsmap_remove (nsm, "dc"));
  28. ASSERT (
  29. LSUP_nsmap_remove (nsm, "none") == LSUP_NOACTION,
  30. "Wrong result for removal of non-existent prefix!");
  31. ASSERT (LSUP_nsmap_get (nsm, "dc") == NULL, "Deleted NS found!");
  32. LSUP_nsmap_free (nsm);
  33. free (fq_uri);
  34. free (pfx_uri);
  35. return 0;
  36. }
  37. int namespace_tests()
  38. {
  39. RUN (test_namespace);
  40. return 0;
  41. }