/tests/test-document.vala

http://libgdom3.googlecode.com/ · Vala · 69 lines · 59 code · 10 blank · 0 comment · 8 complexity · 5bc56386f13c0297ee6e3a1630b73f0b MD5 · raw file

  1. using DOM;
  2. class DocumentTest:TestMan {
  3. Document doc;
  4. Element e1_ref;
  5. Element e2_ref;
  6. Element e1;
  7. Element e2;
  8. DocumentTest () {
  9. base("/DOM/Document");
  10. doc = new Document();
  11. e1 = doc.createElement("e");
  12. e2 = doc.createElement("e");
  13. add ("getElementById/setId", () => {
  14. e1.setAttribute("id", "e1");
  15. e1_ref = doc.getElementById("e1");
  16. assert(e1_ref == e1);
  17. });
  18. add ("getElementById/changeId", () => {
  19. e1.setAttribute("id", "e1new");
  20. e1_ref = doc.getElementById("e1");
  21. assert(e1_ref == null);
  22. e1_ref = doc.getElementById("e1new");
  23. assert(e1_ref == e1);
  24. });
  25. add ("getElementById/conflictId", () => {
  26. e2.setAttribute("id", "e1new");
  27. e1_ref = doc.getElementById("e1new");
  28. assert(e1_ref == e1);
  29. });
  30. add ("getElementbyId/resolveConflictId", () => {
  31. e2.setAttribute("id", "e2");
  32. e2_ref = doc.getElementById("e2");
  33. assert(e2_ref == e2);
  34. });
  35. add ("new/withElement", () => {
  36. Document d = new Document.full(null, "root", null);
  37. assert(d.documentElement != null);
  38. assert(d.documentElement.nodeName == "root");
  39. });
  40. add ("insertBefore/doubleElements", () => {
  41. Document d = new Document.full(null, "root", null);
  42. assert(d.documentElement != null);
  43. bool caught = false;
  44. try {
  45. d.appendChild(d.createElement("e"));
  46. } catch (DOM.Exception.HIERARCHY_REQUEST_ERR e) {
  47. Test.message("%s", e.message);
  48. caught = true;
  49. }
  50. assert(caught);
  51. });
  52. }
  53. public static int main(string[] args) {
  54. Test.init(ref args);
  55. TestMan c = new DocumentTest();
  56. c.run();
  57. return 0;
  58. }
  59. }