aodl /AODLTest/ListTests.cs

Language C# Lines 139
MD5 Hash 09f079cff4d3e96ac49264d27e9202ed
Repository https://bitbucket.org/chrisc/aodl View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
 * 
 * Use is subject to license terms.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
 * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ************************************************************************/

using System;
using System.Xml;
using NUnit.Framework;
using AODL.TextDocument;
using AODL.TextDocument.Style;
using AODL.TextDocument.Content;
using AODL.TextDocument.Style.Properties;

namespace AODLTest
{
	[TestFixture]
	public class ListTests
	{
		private TextDocument _td;

		[SetUp]
		public void Init()
		{
			this._td	= new TextDocument();
			this._td.New();
		}

		[Test]
		public void NumberedListTest()
		{
			List li				= new List(this._td, "L1", ListStyles.Number, "L1P1");
			Assert.IsNotNull(li.Node, "Node object must exist!");

			//Console.WriteLine(li.Node.OuterXml);

			Assert.IsNotNull(li.Style, "Style object must exist!");

			Assert.AreEqual(li.Style.GetType().Name, "ListStyle", "Must be a ListStyle type");

			//Console.WriteLine(li.Style.Node.OuterXml);

			Assert.IsNotNull(((ListStyle)li.Style).ListlevelStyles, "ListLevelStyleCollection must exist!");

			Assert.IsTrue(((ListStyle)li.Style).ListlevelStyles.Count == 10, "Must exist exactly 10 ListLevelStyle objects!");

			Assert.IsNotNull(((ListStyle)li.Style).ListlevelStyles[1].ListlevelProperties, "ListLevelProperties object must exist!");
		}

		[Test]
		public void BulletListTest()
		{
			List li				= new List(this._td, "L1", ListStyles.Bullet, "L1P1");

			Assert.IsNotNull(li.Node, "Node must exist!");

			Assert.IsNotNull(li.Style, "Style must exist!");

			Assert.IsTrue(((ListStyle)li.Style).ListlevelStyles.Count == 10, "Must exist exactly 10 ListLevelStyle objects!");

			Assert.IsNotNull(((ListStyle)li.Style).ListlevelStyles[1].TextProperties, "TextProperties object must exist, this is an bullet list which needs this propertie!");
		}

		[Test]
		public void ListItemTest()
		{
			List li				= new List(this._td, "L1", ListStyles.Bullet, "L1P1");

			Assert.IsNotNull(li.ParagraphStyle, "ParagraphStyle object must exist!");

			ListItem lit		= new ListItem(li);

			Assert.IsNotNull(lit.Paragraph, "Paragraph object must exist!");

			Assert.AreEqual(lit.Paragraph.Stylename, "L1P1", "Must be equal all ListItems reference to the same ParagraphStyle, to this one of their List!");

			lit.Paragraph.TextContent.Add(new SimpleText(lit, "Hello"));

			Assert.IsTrue(lit.Paragraph.TextContent.Count == 1, "Must be one!");

			li.Content.Add(lit);

			this._td.Content.Add(li);

			this._td.SaveTo("list.odt");
		}

		[Test]
		public void InnerListTest()
		{
			List li				= new List(this._td, "L1", ListStyles.Bullet, "L1P1");
			ListItem lit		= new ListItem(li);
			lit.Paragraph.TextContent.Add(new SimpleText(lit, "Hello"));
			li.Content.Add(lit);
			
			//The ListItem will become a inner list !!
			lit					= new ListItem(li);
			lit.Paragraph.TextContent.Add(new SimpleText(lit, "Hello Again"));

			//Inner List - see the constrctor usage !
			List liinner		= new List(this._td, li);

			Assert.IsNull(liinner.Style, "Style must be null! The inner list inherited his style from the outer list!");

			ListItem litinner	= new ListItem(liinner);
			litinner.Paragraph.TextContent.Add(new SimpleText(lit, "Hello i'm in the inner list"));
			liinner.Content.Add(litinner);

			//Add the inner list to ListItem lit
			lit.Content.Add(liinner);

			//Add the ListItem with inner list inside
			li.Content.Add(lit);

			//Add the whole list to the document
			this._td.Content.Add(li);

			this._td.SaveTo("innerlist.odt");			
		}
	}
}

Back to Top