//************************************************************************** // // // National Institute Of Standards and Technology // DTS Version 1.0 // // Text Interface //************************************************************************** var i = 2; function Text() { var tests = new Array (core0001T(), core0002T(), core0003T(),core0004T(), core0005T(), core0006T(), core0007T(), core0008T(), core0009T()); return tests; } //------------------------ test case core-0001T ------------------------ // // Testing feature - If there is no markup inside an Element or Attr node // content, then the text is contained in a single object // implementing the Text interface that is the only child // of the element. // // Testing approach - Retrieve the textual data from the second child of the // third employee. That Text node contains a block of // multiple text lines without markup, so they should be // treated as a single Text node. The "nodeValue" attribute // should contain the combination of the two lines. // // Semantic Requirements: 1 // // Last modification date - March 30, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0001T() { var computedValue = ""; var expectedValue = "Roger\n Jones" var testNode = ""; var testNodeData = ""; results = new testResults("Core0001T"); results.description = "If there is no markup language in a block of text, " + "then the content of the text is contained into " + "an object implementing the Text interface that is " + "the only child of the element."; // // Retrieve the second child of the second employee and access its // textual data. // testNode = new nodeObject(THIRD,SECOND); testNode.node.normalize(); testNodeData = testNode.node.firstChild; computedValue = testNodeData.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; return results; } //------------------------ End test case core-0001T -------------------------- // //-------------------------- test case core-0002T ---------------------------- // // Testing feature - If there is markup inside the Text element content, // then the text is parsed into a list of elements and text // that forms the list of children of the element. // // Testing approach - Retrieve the textual data from the last child of the // third employee. That node is composed of two // EntityReferences nodes and two Text nodes. After the // content of the node is parsed, the "address" Element // should contain four children with each one of the // EntityReferences containing one child in turn. // // Semantic Requirements: 2 // // Last modification date - March 31, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0002T() { var computedValue = ""; var expectedValue = "1900 Dallas Road Dallas, Texas\n 98554"; var testNode = ""; var textBlock1 = ""; var textBlock2 = ""; var textBlock3 = ""; var textBlock4 = ""; results = new testResults("Core0002T"); results.description = "If there is markup language in the content of the " + "element then the content is parsed into a " + "list of elements and Text that are the children of " + "the element"; // // This last child of the second employee should now have four children, // two Text nodes and two EntityReference nodes. Retrieve each one of them // and in the case of EntityReferences retrieve their respective children. // testNode = new nodeObject(SECOND,SIXTH); textBlock1 = testNode.node.childNodes(FIRST).firstChild; textBlock2 = testNode.node.childNodes(SECOND); textBlock3 = testNode.node.childNodes(THIRD).firstChild; textBlock4 = testNode.node.childNodes(FOURTH); computedValue += textBlock1.nodeValue; computedValue += textBlock2.nodeValue; computedValue += textBlock3.nodeValue; computedValue += textBlock4.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; return results; } //------------------------ End test case core-0002 -------------------------- // //-------------------------- test case core-0003T --------------------------- // // Testing feature - The "splitText(offset)" method breaks the Text node // into two Text nodes at the specified offset keeping // each node as siblings in the tree. // // Testing approach - Retrieve the textual data from the second child of the // third employee and invoke its "splitText(offset)" method. // The method splits the Text node into two new sibling // Text Nodes keeping both of them in the tree. This test // checks the "nextSibling" attribute of the original node // to ensure that the two nodes are indeed siblings. // // Semantic Requirements: 3 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0003T() { var computedValue = ""; var expectedValue = "Jones"; var oldTextNode = ""; var testNode = ""; results = new testResults("Core0003T"); results.description = "The \"splitText(offset)\" method breaks the Text node " + "into two Text nodes at the specified offset, keeping each " + "node in the tree as siblings."; // // Retrieve the targeted data. // testNode = new nodeObject(THIRD,SECOND); oldTextNode = testNode.node.firstChild; // // Split the two lines of text into two different Text nodes. // oldTextNode.splitText(EIGHT); computedValue = oldTextNode.nextSibling.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0003T -------------------------- // //-------------------------- test case core-0004T --------------------------- // // Testing feature - After The "splitText(offset)" method breaks the Text node // into two Text nodes, the original node contains all the // content up to the offset point. // // Testing approach - Retrieve the textual data from the second child // of the third employee and invoke the "splitText(offset)" // method. The original Text node should contain all the // content up to the offset point. The "nodeValue" // attribute is invoke to check that indeed the original // node now contains the first five characters // // Semantic Requirements: 4 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0004T() { var computedValue = ""; var expectedValue = "Roger"; var oldTextNode = ""; var testNode = ""; results = new testResults("Core0004T"); results.description = "After the \"splitText(offset)\" method is invoked, the " + "original Text node contains all of the content up to the " + "offset point."; // // Retrieve targeted data. // testNode = new nodeObject(THIRD,SECOND); oldTextNode = testNode.node.firstChild; // // Split the two lines of text into two different Text nodes. // oldTextNode.splitText(SIXTH); computedValue = oldTextNode.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0004T -------------------------- // //-------------------------- test case core-0005T --------------------------- // // Testing feature - After The "splitText(offset)" method breaks the Text node // into two Text nodes, the new Text node contains all the // content at and after the offset point. // // Testing approach - Retrieve the textual data from the second child of the // third employee and invoke the "splitText(offset)" method. // The new Text node should contain all the content at // and after the offset point. The "nodeValue" attribute // is invoked to check that indeed the new node now // contains the first characters at and after position // seven (starting from 0). // // Semantic Requirements: 5 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0005T() { var computedValue = ""; var expectedValue = " Jones"; var oldTextNode = ""; var newTextNode; var testNode = ""; results = new testResults("Core0005T"); results.description = "After the \"splitText(offset)\" method is invoked, the " + "new Text node contains all of the content from the offset " + "point to the end of the text."; // // Retrieve the targeted data. // testNode = new nodeObject(THIRD,SECOND); oldTextNode = testNode.node.firstChild; // // Split the two lines of text into two different Text nodes. // newTextNode = oldTextNode.splitText(SEVENTH); computedValue = newTextNode.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0005T -------------------------- // //-------------------------- test case core-0006T --------------------------- // // Testing feature - The "splitText(offset)" method returns the new Text // node. // // Testing approach - Retrieve the textual data from the last child of the // first employee and invoke its "splitText(offset)" method. // The method should return the new Text node. The offset // value used for this test is 30. The "nodeValue" // attribute is invoked to check that indeed the new node // now contains the characters at and after postion 30 // (counting from 0). // // Semantic Requirements: 6 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0006T() { var computedValue = ""; var expectedValue = "98551"; var oldTextNode = ""; var newTextNode = ""; var testNode = ""; results = new testResults("Core0006T"); results.description = "The \"splitText(offset)\" method returns the " + "new Text node."; // // Retrieve the targeted data. // testNode = new nodeObject(FIRST,SIXTH); oldTextNode = testNode.node.firstChild; // // Split the two lines of text into two different Text nodes. // newTextNode = oldTextNode.splitText(30); computedValue = newTextNode.nodeValue; // // Write out results // results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0006T -------------------------- // //-------------------------- test case core-0007T --------------------------- // // Testing feature - The "splitText(offset)" method raises an INDEX_SIZE_ERR // DOMException if the specified offset is negative. // // Testing approach - Retrieve the textual data from the second child of // the third employee and invoke its "splitText(offset)" // method with "offset" equals to a negative number. It // should raise the desired exception. // // Semantic Requirements: 7 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0007T() { var computedValue = ""; var oldTextNode = ""; var newTextNode = ""; var testNode = ""; var expectedValue = INDEX_SIZE_ERR; results = new testResults("Core0007T"); results.description = "The \"splitText(offset)\" method raises an " + "INDEX_SIZE_ERR DOMException if the specified " + "offset is negative."; // // Retrieve the targeted data // testNode = new nodeObject(THIRD,SECOND); oldTextNode = testNode.node.firstChild; // // Call the "spitText(offset)" method with "offset" equal to a negative // number should raise an exception. // try { oldTextNode.splitText(-69); } catch(DOMException) { computedValue = DOMException.description; } results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0007T -------------------------- // //-------------------------- test case core-0008T ---------------------------- // // Testing feature - The "splitText(offset)" method raises an INDEX_SIZE_ERR // DOMException if the specified offset is greater than the // number of 16-bit units in the Text node. // // Testing approach - Retrieve the textual data from the second child of // third employee and invoke its "splitText(offset)" // method with "offset" greater than the number of // characters in the Text node. It should raise the // desired exception. // // Semantic Requirements: 7 // // Last modification date - March 2, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0008T() { var computedValue = ""; var oldTextNode = ""; var testNode = ""; var expectedValue = INDEX_SIZE_ERR; results = new testResults("Core0008T"); results.description = "The \"splitText(offset)\" method raises an " + "INDEX_SIZE_ERR exception if the specified " + "offset is greater than the number of 16-bit units " + "in the Text node."; // // Retrieve the targeted data. // testNode = new nodeObject(THIRD,SECOND); oldTextNode = testNode.node.firstChild; // // Call the "spitText(offset)" method with "offset" greater than the numbers // of characters in the Text node, it should raise an exception. try { oldTextNode.splitText(300); } catch(DOMException) { computedValue = DOMException.description; } results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0008T -------------------------- // //-------------------------- test case core-0009T ---------------------------- // // Testing feature - The "splitText(offset)" method raises a // NO_MODIFICATION_ALLOWED_ERR DOMException if // the node is readonly. // // Testing approach - Retrieve the textual data from the first EntityReference // inside the last child of the second employee and invoke // its splitText(offset) method. Descendants of // EntityReference nodes are readonly and therefore the // desired exception should be raised. // // Semantic Requirements: 8 // // Last modification date - April 6, 1999 // // Written by: Carmelo Montanez //---------------------------------------------------------------------------- function core0009T() { var computedValue = ""; var testNode = ""; var readOnlyText = ""; var expectedValue = NO_MODIFICATION_ALLOWED_ERR; results = new testResults("Core0009T"); results.description = "The \"splitText(offset)\" method raises a " + "NO_MODIFICATION_ALLOWED_ERR DOMException if the " + "node is readonly."; // // Attempt to modify descendants of an EntityReference node should raise // an exception. // testNode = new nodeObject(SECOND,SIXTH); readOnlyText = testNode.node.childNodes(FIRST).firstChild; try { readOnlyText.splitText(5); } catch(DOMException) { computedValue = DOMException.description; } results.expected = expectedValue; results.actual = computedValue; resetData(); return results; } //------------------------ End test case core-0009T --------------------------