(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / Test / System.Xml / nist_dom / fundamental / Text / Text.cs
blob0fd6fb9c248aa23848edc5a635ad6b868d4a1ba0
1 //**************************************************************************
2 //
3 //
4 // National Institute Of Standards and Technology
5 // DTS Version 1.0
6 //
7 // Text Interface
8 //
9 // Written by: Carmelo Montanez
10 // Modified by: Mary Brady
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
13 // Mainsoft Corporation (c) 2003-2004
14 //**************************************************************************
15 using System;
16 using System.Xml;
18 using nist_dom;
19 using NUnit.Framework;
21 namespace nist_dom.fundamental
23 [TestFixture]
24 public class TextTest : Assertion
26 public static int i = 2;
28 public testResults[] RunTests()
30 testResults[] tests = new testResults[] {core0001T(), core0002T(), core0003T(),core0004T(),
31 core0005T(), core0006T(), core0007T(), core0008T(),
32 core0009T()};
34 return tests;
37 //------------------------ test case core-0001T ------------------------
39 // Testing feature - If there is no markup inside an Element or Attr node
40 // content, then the text is contained in a single object
41 // implementing the Text interface that is the only child
42 // of the element.
44 // Testing approach - Retrieve the textual data from the second child of the
45 // third employee. That Text node contains a block of
46 // multiple text lines without markup, so they should be
47 // treated as a single Text node. The "nodeValue" attribute
48 // should contain the combination of the two lines.
49 //
50 // Semantic Requirements: 1
52 //----------------------------------------------------------------------------
54 [Test]
55 public void core0001T()
57 string computedValue = "";
58 string expectedValue = "Roger\n Jones";
59 System.Xml.XmlNode testNode = null;
60 System.Xml.XmlCharacterData testNodeData = null;
62 testResults results = new testResults("Core0001T");
63 try
65 results.description = "If there is no markup language in a block of text, " +
66 "then the content of the text is contained into " +
67 "an object implementing the Text interface that is " +
68 "the only child of the element.";
70 // Retrieve the second child of the second employee and access its
71 // textual data.
73 testNode = util.nodeObject(util.THIRD,util.SECOND);
74 testNode.Normalize();
75 testNodeData = (System.Xml.XmlCharacterData)testNode.FirstChild;
76 computedValue = testNodeData.Value;
78 catch(System.Exception ex)
80 computedValue = "Exception " + ex.Message;
84 // Write out results
86 results.expected = expectedValue;
87 results.actual = computedValue;
89 AssertEquals (results.expected, results.actual);
92 //------------------------ End test case core-0001T --------------------------
94 //-------------------------- test case core-0002T ----------------------------
96 // Testing feature - If there is markup inside the Text element content,
97 // then the text is parsed into a list of elements and text
98 // that forms the list of children of the element.
100 // Testing approach - Retrieve the textual data from the last child of the
101 // third employee. That node is composed of two
102 // EntityReferences nodes and two Text nodes. After the
103 // content of the node is parsed, the "address" Element
104 // should contain four children with each one of the
105 // EntityReferences containing one child in turn.
107 // Semantic Requirements: 2
109 //----------------------------------------------------------------------------
111 [Test]
112 public void core0002T()
114 string computedValue = "";
115 string expectedValue = "1900 Dallas Road Dallas, Texas\n 98554";
116 System.Xml.XmlNode testNode = null;
117 System.Xml.XmlNode textBlock1 = null;
118 System.Xml.XmlNode textBlock2 = null;
119 System.Xml.XmlNode textBlock3 = null;
120 System.Xml.XmlNode textBlock4 = null;
122 testResults results = new testResults("Core0002T");
125 results.description = "If there is markup language in the content of the " +
126 "element then the content is parsed into a " +
127 "list of elements and Text that are the children of " +
128 "the element";
130 // This last child of the second employee should now have four children,
131 // two Text nodes and two EntityReference nodes. Retrieve each one of them
132 // and in the case of EntityReferences retrieve their respective children.
134 testNode = util.nodeObject(util.SECOND,util.SIXTH);
135 textBlock1 = testNode.ChildNodes.Item(util.FIRST).FirstChild;
136 textBlock2 = testNode.ChildNodes.Item(util.SECOND);
137 textBlock3 = testNode.ChildNodes.Item(util.THIRD).FirstChild;
138 textBlock4 = testNode.ChildNodes.Item(util.FOURTH);
140 computedValue += textBlock1.Value;
141 computedValue += textBlock2.Value;
142 computedValue += textBlock3.Value;
143 computedValue += textBlock4.Value;
145 catch(System.Exception ex)
147 computedValue = "Exception " + ex.Message;
151 // Write out results
153 results.expected = expectedValue;
154 results.actual = computedValue;
156 AssertEquals (results.expected, results.actual);
159 //------------------------ End test case core-0002 --------------------------
161 //-------------------------- test case core-0003T ---------------------------
163 // Testing feature - The "splitText(offset)" method breaks the Text node
164 // into two Text nodes at the specified offset keeping
165 // each node as siblings in the tree.
167 // Testing approach - Retrieve the textual data from the second child of the
168 // third employee and invoke its "splitText(offset)" method.
169 // The method splits the Text node into two new sibling
170 // Text Nodes keeping both of them in the tree. This test
171 // checks the "nextSibling" attribute of the original node
172 // to ensure that the two nodes are indeed siblings.
174 // Semantic Requirements: 3
176 //----------------------------------------------------------------------------
178 [Test]
179 public void core0003T()
181 string computedValue = "";
182 string expectedValue = "Jones";
183 System.Xml.XmlText oldTextNode = null;
184 System.Xml.XmlNode testNode = null;
186 testResults results = new testResults("Core0003T");
189 results.description = "The \"splitText(offset)\" method breaks the Text node " +
190 "into two Text nodes at the specified offset, keeping each " +
191 "node in the tree as siblings.";
193 // Retrieve the targeted data.
195 testNode = util.nodeObject(util.THIRD,util.SECOND);
196 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
198 // Split the two lines of text into two different Text nodes.
200 oldTextNode.SplitText(util.EIGHT);
201 computedValue = oldTextNode.NextSibling.Value;
203 catch(System.Exception ex)
205 computedValue = "Exception " + ex.Message;
209 // Write out results
211 results.expected = expectedValue;
212 results.actual = computedValue;
214 util.resetData();
216 AssertEquals (results.expected, results.actual);
219 //------------------------ End test case core-0003T --------------------------
221 //-------------------------- test case core-0004T ---------------------------
223 // Testing feature - After The "splitText(offset)" method breaks the Text node
224 // into two Text nodes, the original node contains all the
225 // content up to the offset point.
227 // Testing approach - Retrieve the textual data from the second child
228 // of the third employee and invoke the "splitText(offset)"
229 // method. The original Text node should contain all the
230 // content up to the offset point. The "nodeValue"
231 // attribute is invoke to check that indeed the original
232 // node now contains the first five characters
234 // Semantic Requirements: 4
236 //----------------------------------------------------------------------------
238 [Test]
239 public void core0004T()
241 string computedValue = "";
242 string expectedValue = "Roger";
243 System.Xml.XmlText oldTextNode = null;
244 System.Xml.XmlNode testNode = null;
246 testResults results = new testResults("Core0004T");
249 results.description = "After the \"splitText(offset)\" method is invoked, the " +
250 "original Text node contains all of the content up to the " +
251 "offset point.";
253 // Retrieve targeted data.
255 testNode = util.nodeObject(util.THIRD,util.SECOND);
256 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
258 // Split the two lines of text into two different Text nodes.
260 oldTextNode.SplitText(util.SIXTH);
261 computedValue = oldTextNode.Value;
263 catch(System.Exception ex)
265 computedValue = "Exception " + ex.Message;
269 // Write out results
271 results.expected = expectedValue;
272 results.actual = computedValue;
274 util.resetData();
276 AssertEquals (results.expected, results.actual);
279 //------------------------ End test case core-0004T --------------------------
281 //-------------------------- test case core-0005T ---------------------------
283 // Testing feature - After The "splitText(offset)" method breaks the Text node
284 // into two Text nodes, the new Text node contains all the
285 // content at and after the offset point.
287 // Testing approach - Retrieve the textual data from the second child of the
288 // third employee and invoke the "splitText(offset)" method.
289 // The new Text node should contain all the content at
290 // and after the offset point. The "nodeValue" attribute
291 // is invoked to check that indeed the new node now
292 // contains the first characters at and after position
293 // seven (starting from 0).
295 // Semantic Requirements: 5
297 //----------------------------------------------------------------------------
299 [Test]
300 public void core0005T()
302 string computedValue = "";
303 string expectedValue = " Jones";
304 System.Xml.XmlText oldTextNode = null;
305 System.Xml.XmlText newTextNode = null;
306 System.Xml.XmlNode testNode = null;
308 testResults results = new testResults("Core0005T");
311 results.description = "After the \"splitText(offset)\" method is invoked, the " +
312 "new Text node contains all of the content from the offset " +
313 "point to the end of the text.";
315 // Retrieve the targeted data.
317 testNode = util.nodeObject(util.THIRD,util.SECOND);
318 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
320 // Split the two lines of text into two different Text nodes.
322 newTextNode = oldTextNode.SplitText(util.SEVENTH);
323 computedValue = newTextNode.Value;
325 catch(System.Exception ex)
327 computedValue = "Exception " + ex.Message;
331 // Write out results
333 results.expected = expectedValue;
334 results.actual = computedValue;
336 util.resetData();
338 AssertEquals (results.expected, results.actual);
341 //------------------------ End test case core-0005T --------------------------
343 //-------------------------- test case core-0006T ---------------------------
345 // Testing feature - The "splitText(offset)" method returns the new Text
346 // node.
348 // Testing approach - Retrieve the textual data from the last child of the
349 // first employee and invoke its "splitText(offset)" method.
350 // The method should return the new Text node. The offset
351 // value used for this test is 30. The "nodeValue"
352 // attribute is invoked to check that indeed the new node
353 // now contains the characters at and after postion 30
354 // (counting from 0).
356 // Semantic Requirements: 6
358 //----------------------------------------------------------------------------
360 [Test]
361 public void core0006T()
363 string computedValue = "";
364 string expectedValue = "98551";
365 System.Xml.XmlText oldTextNode = null;
366 System.Xml.XmlText newTextNode = null;
367 System.Xml.XmlNode testNode = null;
369 testResults results = new testResults("Core0006T");
372 results.description = "The \"splitText(offset)\" method returns the " +
373 "new Text node.";
375 // Retrieve the targeted data.
377 testNode = util.nodeObject(util.FIRST,util.SIXTH);
378 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
380 // Split the two lines of text into two different Text nodes.
382 newTextNode = oldTextNode.SplitText(30);
383 computedValue = newTextNode.Value;
385 catch(System.Exception ex)
387 computedValue = "Exception " + ex.Message;
390 // Write out results
392 results.expected = expectedValue;
393 results.actual = computedValue;
395 util.resetData();
397 AssertEquals (results.expected, results.actual);
400 //------------------------ End test case core-0006T --------------------------
402 //-------------------------- test case core-0007T ---------------------------
404 // Testing feature - The "splitText(offset)" method raises an INDEX_SIZE_ERR
405 // Exception if the specified offset is negative.
407 // Testing approach - Retrieve the textual data from the second child of
408 // the third employee and invoke its "splitText(offset)"
409 // method with "offset" equals to a negative number. It
410 // should raise the desired exception.
412 // Semantic Requirements: 7
414 //----------------------------------------------------------------------------
416 [Test]
417 public void core0007T()
419 string computedValue = "";
420 System.Xml.XmlText oldTextNode = null;
421 System.Xml.XmlText newTextNode = null;
422 System.Xml.XmlNode testNode = null;
423 string expectedValue = "System.ArgumentOutOfRangeException";//util.INDEX_SIZE_ERR;
425 testResults results = new testResults("Core0007T");
428 results.description = "The \"splitText(offset)\" method raises an " +
429 "INDEX_SIZE_ERR Exception if the specified " +
430 "offset is negative.";
433 // Retrieve the targeted data
435 testNode = util.nodeObject(util.THIRD,util.SECOND);
436 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
438 // Call the "spitText(offset)" method with "offset" equal to a negative
439 // number should raise an exception.
441 try
443 oldTextNode.SplitText(-69);
445 catch(System.Exception ex)
447 computedValue = ex.GetType ().FullName;
450 catch(System.Exception ex)
452 computedValue = "Exception " + ex.Message;
455 results.expected = expectedValue;
456 results.actual = computedValue;
458 util.resetData();
460 AssertEquals (results.expected, results.actual);
462 //------------------------ End test case core-0007T --------------------------
464 //-------------------------- test case core-0008T ----------------------------
466 // Testing feature - The "splitText(offset)" method raises an
467 // ArgumentOutOfRangeException if the specified offset is greater than the
468 // number of 16-bit units in the Text node.
470 // Testing approach - Retrieve the textual data from the second child of
471 // third employee and invoke its "splitText(offset)"
472 // method with "offset" greater than the number of
473 // characters in the Text node. It should raise the
474 // desired exception.
476 // Semantic Requirements: 7
478 //----------------------------------------------------------------------------
480 [Test]
481 public void core0008T()
483 string computedValue = "";
484 System.Xml.XmlText oldTextNode = null;
485 System.Xml.XmlNode testNode = null;
486 string expectedValue = "System.ArgumentOutOfRangeException";
488 testResults results = new testResults("Core0008T");
491 results.description = "The \"splitText(offset)\" method raises an " +
492 "ArgumentOutOfRangeException if the specified " +
493 "offset is greater than the number of 16-bit units " +
494 "in the Text node.";
496 // Retrieve the targeted data.
498 testNode = util.nodeObject(util.THIRD,util.SECOND);
499 oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
501 // Call the "spitText(offset)" method with "offset" greater than the numbers
502 // of characters in the Text node, it should raise an exception.
504 try
506 oldTextNode.SplitText(300);
508 catch(System.Exception ex)
510 computedValue = ex.GetType().ToString();
513 catch(System.Exception ex)
515 computedValue = "Exception " + ex.Message;
518 results.expected = expectedValue;
519 results.actual = computedValue;
521 util.resetData();
523 AssertEquals (results.expected, results.actual);
525 //------------------------ End test case core-0008T --------------------------
527 //-------------------------- test case core-0009T ----------------------------
529 // Testing feature - The "splitText(offset)" method raises a
530 // NO_MODIFICATION_ALLOWED_ERR Exception if
531 // the node is readonly.
533 // Testing approach - Retrieve the textual data from the first EntityReference
534 // inside the last child of the second employee and invoke
535 // its splitText(offset) method. Descendants of
536 // EntityReference nodes are readonly and therefore the
537 // desired exception should be raised.
539 // Semantic Requirements: 8
541 //----------------------------------------------------------------------------
543 [Test]
544 public void core0009T()
546 string computedValue = "";
547 System.Xml.XmlNode testNode = null;
548 System.Xml.XmlText readOnlyText = null;
549 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
551 testResults results = new testResults("Core0009T");
554 results.description = "The \"splitText(offset)\" method raises a " +
555 "NO_MODIFICATION_ALLOWED_ERR Exception if the " +
556 "node is readonly.";
558 // Attempt to modify descendants of an EntityReference node should raise
559 // an exception.
561 testNode = util.nodeObject(util.SECOND,util.SIXTH);
562 readOnlyText = (System.Xml.XmlText)testNode.ChildNodes.Item(util.FIRST).FirstChild;
564 try
566 readOnlyText.SplitText(5);
568 catch(ArgumentException ex)
570 computedValue = ex.GetType ().FullName;
574 catch(System.Exception ex)
576 computedValue = "Exception " + ex.Message;
579 results.expected = expectedValue;
580 results.actual = computedValue;
582 util.resetData();
584 AssertEquals (results.expected, results.actual);
587 //------------------------ End test case core-0009T --------------------------