• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2/*
3Copyright © 2001-2004 World Wide Web Consortium,
4(Massachusetts Institute of Technology, European Research Consortium
5for Informatics and Mathematics, Keio University). All
6Rights Reserved. This work is distributed under the W3C® Software License [1] in the
7hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
10[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
11*/
12
13
14
15   /**
16    *  Gets URI that identifies the test.
17    *  @return uri identifier of test
18    */
19function getTargetURI() {
20      return "http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodecomparedocumentposition19";
21   }
22
23var docsLoaded = -1000000;
24var builder = null;
25
26//
27//   This function is called by the testing framework before
28//      running the test suite.
29//
30//   If there are no configuration exceptions, asynchronous
31//        document loading is started.  Otherwise, the status
32//        is set to complete and the exception is immediately
33//        raised when entering the body of the test.
34//
35function setUpPage() {
36   setUpPageStatus = 'running';
37   try {
38     //
39     //   creates test document builder, may throw exception
40     //
41     builder = createConfiguredBuilder();
42       setImplementationAttribute("coalescing", false);
43       setImplementationAttribute("namespaceAware", true);
44
45      docsLoaded = 0;
46
47      var docRef = null;
48      if (typeof(this.doc) != 'undefined') {
49        docRef = this.doc;
50      }
51      docsLoaded += preload(docRef, "doc", "hc_staff");
52
53       if (docsLoaded == 1) {
54          setUpPageStatus = 'complete';
55       }
56    } catch(ex) {
57    	catchInitializationError(builder, ex);
58        setUpPageStatus = 'complete';
59    }
60}
61
62
63
64//
65//   This method is called on the completion of
66//      each asychronous load started in setUpTests.
67//
68//   When every synchronous loaded document has completed,
69//      the page status is changed which allows the
70//      body of the test to be executed.
71function loadComplete() {
72    if (++docsLoaded == 1) {
73        setUpPageStatus = 'complete';
74    }
75}
76
77
78/**
79*
80	The method compareDocumentPosition compares a node with this node with regard to their position in the
81	document and according to the document order.
82
83	Using compareDocumentPosition check if the document position of the first CDATASection node
84	of the second element whose localName is name compared with the second CDATASection node
85	is PRECEDING and is FOLLOWING vice versa.
86
87* @author IBM
88* @author Jenny Hsu
89* @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#Node3-compareDocumentPosition
90*/
91function nodecomparedocumentposition19() {
92   var success;
93    if(checkInitialization(builder, "nodecomparedocumentposition19") != null) return;
94    var doc;
95      var elemList;
96      var elemStrong;
97      var cdata1;
98      var cdata2;
99      var aNode;
100      var cdata1Position;
101      var cdata2Position;
102
103      var docRef = null;
104      if (typeof(this.doc) != 'undefined') {
105        docRef = this.doc;
106      }
107      doc = load(docRef, "doc", "hc_staff");
108      elemList = doc.getElementsByTagNameNS("*","strong");
109      elemStrong = elemList.item(1);
110      cdata2 = elemStrong.lastChild;
111
112      aNode = cdata2.previousSibling;
113
114      cdata1 = aNode.previousSibling;
115
116      cdata1Position = cdata1.compareDocumentPosition(cdata2);
117      assertEquals("nodecomparedocumentposition19_cdata2Follows",4,cdata1Position);
118       cdata2Position = cdata2.compareDocumentPosition(cdata1);
119      assertEquals("nodecomparedocumentposition_cdata1Precedes",2,cdata2Position);
120
121}
122
123
124
125
126function runTest() {
127   nodecomparedocumentposition19();
128}
129