test_namespace.c 1.8 KB

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